ReactOS  0.4.14-dev-342-gdc047f9
bios.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "int32.h"
#include "../dem.h"
#include "dos.h"
#include "dosfiles.h"
#include "handle.h"
#include "memory.h"
#include "bios/bios.h"
Include dependency graph for bios.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define FreeEnvironmentStrings   FreeEnvironmentStringsA
 

Functions

VOID DosEchoCharacter (CHAR Character)
 
CHAR DosReadCharacter (WORD FileHandle, BOOLEAN Echo)
 
BOOLEAN DosCheckInput (VOID)
 
VOID DosPrintCharacter (WORD FileHandle, CHAR Character)
 
BOOLEAN DosBuildSysEnvBlock (VOID)
 
BOOLEAN DosBIOSInitialize (VOID)
 

Variables

PBIOS_DATA BiosData
 

Macro Definition Documentation

◆ FreeEnvironmentStrings

#define FreeEnvironmentStrings   FreeEnvironmentStringsA

Definition at line 35 of file bios.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file bios.c.

Function Documentation

◆ DosBIOSInitialize()

BOOLEAN DosBIOSInitialize ( VOID  )

setBP(0x091E); // DOS base stack pointer relic value

Definition at line 221 of file bios.c.

222 {
223  FILE *Stream;
224  WCHAR Buffer[256];
225 
226  /* Set the data segment */
228 
229  /* Initialize the global DOS BIOS data area */
231 
232  /* Initialize the DOS BIOS stack */
233  // FIXME: Add a block of fixed size for the stack in BIOS/DOS_DATA instead!
234  setSS(0x0F00);
235  setSP(0x0FF0);
237 
238  /*
239  * Initialize the INT 13h (BIOS Disk Services) handler chain support.
240  *
241  * The INT 13h handler chain is some functionality that allows DOS
242  * to insert disk filter drivers in between the (hooked) INT 13h handler
243  * and its original handler.
244  * Typically, those are:
245  * - filter for detecting disk changes (for floppy disks),
246  * - filter for tracking formatting calls and correcting DMA boundary errors,
247  * - a possible filter to work around a bug in a particular version of PC-AT's
248  * IBM's ROM BIOS (on systems with model byte FCh and BIOS date "01/10/84" only)
249  * (see http://www.ctyme.com/intr/rb-4453.htm for more details).
250  *
251  * This functionality is known to be used by some legitimate programs,
252  * by Windows 3.x, as well as some illegitimate ones (aka. virii).
253  *
254  * See extra information about this support in dos.h
255  */
256  // FIXME: Should be done by the DOS BIOS
259 // RegisterDosInt32(0x13, DosInt13h); // Unused at the moment!
260 
261  //
262  // HERE: Do all hardware initialization needed for DOS
263  //
264 
265  /*
266  * SysInit part...
267  */
268 
269  /* Initialize the DOS kernel (DosInit) */
270  if (!DosKRNLInitialize())
271  {
272  BiosDisplayMessage("Failed to load the DOS kernel! Exiting...\n");
273  return FALSE;
274  }
275 
276  /* DOS kernel loading succeeded, we can finish the initialization */
277 
278  /* Build the system master (pre-) environment block (inherited by the shell) */
279  if (!DosBuildSysEnvBlock())
280  {
281  DosDisplayMessage("An error occurred when setting up the system environment block.\n");
282  }
283 
284  /* TODO: Read CONFIG.NT/SYS */
286  if (Stream != NULL)
287  {
288  while (fgetws(Buffer, ARRAYSIZE(Buffer), Stream))
289  {
290  // TODO: Parse the line
291  }
292  fclose(Stream);
293  }
294 
295  return TRUE;
296 }
#define TRUE
Definition: types.h:120
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
struct _BIOS_DATA * PBIOS_DATA
VOID WINAPI setDS(USHORT)
Definition: registers.c:515
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define DosDisplayMessage(Format,...)
Definition: dem.h:37
#define SEG_OFF_TO_PTR(seg, off)
Definition: emulator.h:28
VOID WINAPI setSP(USHORT)
Definition: registers.c:351
VOID WINAPI setSS(USHORT)
Definition: registers.c:501
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
BOOLEAN DosKRNLInitialize(VOID)
Definition: dos.c:2253
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
DWORD PrevInt13
Definition: dos.h:287
#define BIOS_DATA_SEGMENT
Definition: dos.h:31
unsigned int * PULONG
Definition: retypes.h:1
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
BOOLEAN DosBuildSysEnvBlock(VOID)
Definition: bios.c:165
#define DOS_CONFIG_PATH
Definition: dos.h:27
DWORD RomBiosInt13
Definition: dos.h:286
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
Definition: fltkernel.h:1092
PBIOS_DATA BiosData
Definition: bios.c:42
#define BiosDisplayMessage(Format,...)
Definition: dem.h:33

Referenced by DosStart().

◆ DosBuildSysEnvBlock()

BOOLEAN DosBuildSysEnvBlock ( VOID  )

Definition at line 165 of file bios.c.

166 {
167  LPSTR SourcePtr, Environment;
169 
170  /*
171  * Get the environment strings
172  *
173  * NOTE: On non-STANDALONE builds, this corresponds to the VDM environment
174  * as created by BaseVDM for NTVDM. On STANDALONE builds this is the Win32
175  * environment. In this last case we need to convert it to a proper VDM env.
176  */
177  SourcePtr = Environment = GetEnvironmentStrings();
178  if (Environment == NULL) return FALSE;
179 
180  /* Fill the DOS system environment block */
181  while (*SourcePtr)
182  {
183  /*
184  * - Ignore environment strings starting with a '=',
185  * they describe current directories.
186  * - Ignore also the WINDIR environment variable since
187  * DOS apps should ignore that we started from ReactOS.
188  * - Upper-case the environment names, not their values.
189  */
190  if (*SourcePtr != '=' && _strnicmp(SourcePtr, "WINDIR", 6) != 0)
191  {
192  PCHAR Delim = NULL;
193 
194  /* Copy the environment string */
195  strcpy(DestPtr, SourcePtr);
196 
197  /* Upper-case the environment name */
198  Delim = strchr(DestPtr, '='); // Find the '=' delimiter
199  if (Delim) *Delim = '\0'; // Temporarily replace it by NULL
200  _strupr(DestPtr); // Upper-case
201  if (Delim) *Delim = '='; // Restore the delimiter
202 
203  DestPtr += strlen(SourcePtr);
204 
205  /* NULL-terminate the environment string */
206  *(DestPtr++) = '\0';
207  }
208 
209  /* Move to the next string */
210  SourcePtr += strlen(SourcePtr) + 1;
211  }
212  /* NULL-terminate the environment block */
213  *DestPtr = '\0';
214 
215  /* Free the memory allocated for environment strings */
217 
218  return TRUE;
219 }
signed char * PCHAR
Definition: retypes.h:7
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:45
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define SYSTEM_ENV_BLOCK
Definition: dos.h:37
#define FreeEnvironmentStrings
Definition: bios.c:35
char * LPSTR
Definition: xmlstorage.h:182
#define SEG_OFF_TO_PTR(seg, off)
Definition: emulator.h:28
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
smooth NULL
Definition: ftsmooth.c:416
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
LPSTR WINAPI GetEnvironmentStrings(void)
char * strchr(const char *String, int ch)
Definition: utclib.c:501
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388

Referenced by DosBIOSInitialize().

◆ DosCheckInput()

BOOLEAN DosCheckInput ( VOID  )

Definition at line 120 of file bios.c.

121 {
123 
124  if (Descriptor == NULL)
125  {
126  /* Invalid handle */
127  Sda->LastErrorCode = ERROR_INVALID_HANDLE; // ERROR_FILE_NOT_FOUND
128  return FALSE;
129  }
130 
131  if (Descriptor->DeviceInfo & FILE_INFO_DEVICE)
132  {
133  WORD Result;
135 
136  if (!Node->InputStatusRoutine) return FALSE;
137 
138  Result = Node->InputStatusRoutine(Node);
139  return !(Result & DOS_DEVSTAT_BUSY);
140  }
141  else
142  {
143  DWORD FileSizeHigh;
144  DWORD FileSize = GetFileSize(Descriptor->Win32Handle, &FileSizeHigh);
145  LONG LocationHigh = 0;
146  DWORD Location = SetFilePointer(Descriptor->Win32Handle, 0, &LocationHigh, FILE_CURRENT);
147 
148  return ((Location != FileSize) || (LocationHigh != FileSizeHigh));
149  }
150 }
WORD LastErrorCode
Definition: dos.h:151
#define DOS_INPUT_HANDLE
Definition: dos.h:42
#define FILE_CURRENT
Definition: winbase.h:113
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PDOS_FILE_DESCRIPTOR DosGetHandleFileDescriptor(WORD DosHandle)
Definition: dosfiles.c:173
#define FILE_INFO_DEVICE
Definition: dosfiles.h:16
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
PDOS_SDA Sda
Definition: dos.c:48
#define DOS_DEVSTAT_BUSY
Definition: device.h:50
PDOS_DEVICE_NODE DosGetDriverNode(DWORD Driver)
Definition: device.c:305
Definition: dlist.c:348
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by DosInt21h().

◆ DosEchoCharacter()

VOID DosEchoCharacter ( CHAR  Character)

Definition at line 48 of file bios.c.

49 {
50  switch (Character)
51  {
52  case '\0':
53  {
54  /* Nothing */
55  break;
56  }
57 
58  case '\b':
59  {
60  /* Erase the character */
64  break;
65  }
66 
67  default:
68  {
69  /*
70  * Check if this is a special character
71  * NOTE: \r and \n are handled by the underlying driver!
72  */
73  if (Character < 0x20 && Character != '\r' && Character != '\n')
74  {
76  Character += 'A' - 1;
77  }
78 
79  /* Echo the character */
81  }
82  }
83 }
#define DOS_OUTPUT_HANDLE
Definition: dos.h:43
VOID DosPrintCharacter(WORD FileHandle, CHAR Character)
Definition: bios.c:152

Referenced by DosReadCharacter(), DosReadFile(), and DosReadLineBuffered().

◆ DosPrintCharacter()

VOID DosPrintCharacter ( WORD  FileHandle,
CHAR  Character 
)

Definition at line 152 of file bios.c.

153 {
155 
156  Sda->ByteBuffer = Character;
157 
158  /* Use the file writing function */
161  1,
162  &BytesWritten);
163 }
#define DOS_DATA_OFFSET(x)
Definition: dos.h:35
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
BYTE ByteBuffer
Definition: dos.h:193
HANDLE FileHandle
Definition: stats.c:38
#define MAKELONG(a, b)
Definition: typedefs.h:248
#define DOS_DATA_SEGMENT
Definition: dos.h:33
unsigned short WORD
Definition: ntddk_ex.h:93
PDOS_SDA Sda
Definition: dos.c:48
WORD DosWriteFile(WORD FileHandle, DWORD Buffer, WORD Count, LPWORD BytesWritten)
Definition: dosfiles.c:915

Referenced by DosCharPrint(), DosControlBreak(), DosEchoCharacter(), and DosInt21h().

◆ DosReadCharacter()

CHAR DosReadCharacter ( WORD  FileHandle,
BOOLEAN  Echo 
)

Definition at line 85 of file bios.c.

86 {
89  WORD OldDeviceInfo;
90 
91  /* Find the standard input descriptor and switch it to binary mode */
93  if (Descriptor)
94  {
95  OldDeviceInfo = Descriptor->DeviceInfo;
96  Descriptor->DeviceInfo |= FILE_INFO_BINARY;
97  }
98 
99  Sda->ByteBuffer = '\0';
100  DPRINT("DosReadCharacter\n");
101 
102  /* Use the file reading function */
105  1,
106  &BytesRead);
107 
108  /* Check if we should echo and the file is actually the CON device */
109  if (Echo && Descriptor && Descriptor->DeviceInfo & FILE_INFO_DEVICE)
110  {
111  /* Echo the character */
113  }
114 
115  /* Restore the old mode and return the character */
116  if (Descriptor) Descriptor->DeviceInfo = OldDeviceInfo;
117  return Sda->ByteBuffer;
118 }
#define DOS_DATA_OFFSET(x)
Definition: dos.h:35
BYTE ByteBuffer
Definition: dos.h:193
WORD DosReadFile(WORD FileHandle, DWORD Buffer, WORD Count, LPWORD BytesRead)
Definition: dosfiles.c:768
#define FILE_INFO_BINARY
Definition: dosfiles.h:15
HANDLE FileHandle
Definition: stats.c:38
#define MAKELONG(a, b)
Definition: typedefs.h:248
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PDOS_FILE_DESCRIPTOR DosGetHandleFileDescriptor(WORD DosHandle)
Definition: dosfiles.c:173
#define DOS_DATA_SEGMENT
Definition: dos.h:33
#define FILE_INFO_DEVICE
Definition: dosfiles.h:16
unsigned short WORD
Definition: ntddk_ex.h:93
PDOS_SDA Sda
Definition: dos.c:48
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
Definition: telnetd.h:64
VOID DosEchoCharacter(CHAR Character)
Definition: bios.c:48
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by DosInt21h().

Variable Documentation

◆ BiosData

PBIOS_DATA BiosData

Definition at line 42 of file bios.c.

Referenced by DosBIOSInitialize(), DosInt2Fh(), PciScanBus(), and PPBridge_SaveCurrentSettings().