ReactOS 0.4.15-dev-5666-gc548b97
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 {
289 {
290 // TODO: Parse the line
291 }
292 fclose(Stream);
293 }
294
295 return TRUE;
296}
Definition: bufpool.h:45
#define BiosDisplayMessage(Format,...)
Definition: dem.h:34
#define DosDisplayMessage(Format,...)
Definition: dem.h:38
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOLEAN DosKRNLInitialize(VOID)
Definition: dos.c:2264
#define SEG_OFF_TO_PTR(seg, off)
Definition: emulator.h:32
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
unsigned int * PULONG
Definition: retypes.h:1
static IStream Stream
Definition: htmldoc.c:1115
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define L(x)
Definition: ntvdm.h:50
DWORD PrevInt13
Definition: dos.h:296
DWORD RomBiosInt13
Definition: dos.h:295
PBIOS_DATA BiosData
Definition: bios.c:42
BOOLEAN DosBuildSysEnvBlock(VOID)
Definition: bios.c:165
#define DOS_CONFIG_PATH
Definition: dos.h:27
struct _BIOS_DATA * PBIOS_DATA
#define BIOS_DATA_SEGMENT
Definition: dos.h:31
VOID WINAPI setSP(USHORT)
Definition: registers.c:351
VOID WINAPI setDS(USHORT)
Definition: registers.c:515
VOID WINAPI setSS(USHORT)
Definition: registers.c:501
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
__wchar_t WCHAR
Definition: xmlstorage.h:180

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}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
signed char * PCHAR
Definition: retypes.h:7
PVOID PVOID PWCHAR PVOID Environment
Definition: env.c:47
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
#define FreeEnvironmentStrings
Definition: bios.c:35
#define SYSTEM_ENV_BLOCK
Definition: dos.h:37
LPSTR WINAPI GetEnvironmentStrings(void)
char * LPSTR
Definition: xmlstorage.h:182

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}
#define SetFilePointer
Definition: compat.h:743
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
PDOS_SDA Sda
Definition: dos.c:48
PDOS_FILE_DESCRIPTOR DosGetHandleFileDescriptor(WORD DosHandle)
Definition: dosfiles.c:173
#define FILE_INFO_DEVICE
Definition: dosfiles.h:16
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
long LONG
Definition: pedump.c:60
WORD LastErrorCode
Definition: dos.h:160
PDOS_DEVICE_NODE DosGetDriverNode(DWORD Driver)
Definition: device.c:305
#define DOS_DEVSTAT_BUSY
Definition: device.h:50
#define DOS_INPUT_HANDLE
Definition: dos.h:42
Definition: dlist.c:348
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
#define FILE_CURRENT
Definition: winbase.h:113
_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

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}
VOID DosPrintCharacter(WORD FileHandle, CHAR Character)
Definition: bios.c:152
#define DOS_OUTPUT_HANDLE
Definition: dos.h:43

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}
WORD DosWriteFile(WORD FileHandle, DWORD Buffer, WORD Count, LPWORD BytesWritten)
Definition: dosfiles.c:915
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
BYTE ByteBuffer
Definition: dos.h:202
#define DOS_DATA_OFFSET(x)
Definition: dos.h:35
#define DOS_DATA_SEGMENT
Definition: dos.h:33
#define MAKELONG(a, b)
Definition: typedefs.h:249
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960

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}
WORD DosReadFile(WORD FileHandle, DWORD Buffer, WORD Count, LPWORD BytesRead)
Definition: dosfiles.c:768
#define FILE_INFO_BINARY
Definition: dosfiles.h:15
#define DPRINT
Definition: sndvol32.h:71
VOID DosEchoCharacter(CHAR Character)
Definition: bios.c:48
@ Echo
Definition: telnetd.h:64
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870

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().