1 /* 2 * COPYRIGHT: GPL - See COPYING in the top level directory 3 * PROJECT: ReactOS Virtual DOS Machine 4 * FILE: subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h 5 * PURPOSE: DOS32 Kernel 6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org> 7 */ 8 9 #ifndef _DOS_H_ 10 #define _DOS_H_ 11 12 /* INCLUDES *******************************************************************/ 13 14 #include "device.h" 15 16 /**/ #include "int32.h" /**/ 17 18 /* DEFINES ********************************************************************/ 19 20 // 21 // We are DOS 5.00 (reported by INT 21h, AH=30h) 22 // and DOS 5.50 (reported by INT 21h, AX=3306h) for Windows NT Compatibility 23 // 24 #define DOS_VERSION MAKEWORD(5, 00) 25 #define NTDOS_VERSION MAKEWORD(5, 50) 26 27 #define DOS_CONFIG_PATH L"%SystemRoot%\\system32\\CONFIG.NT" 28 #define DOS_COMMAND_INTERPRETER L"%SystemRoot%\\system32\\COMMAND.COM /k %SystemRoot%\\system32\\AUTOEXEC.NT" 29 30 #define BIOS_CODE_SEGMENT 0x70 31 #define BIOS_DATA_SEGMENT 0x70 32 #define DOS_CODE_SEGMENT 0x80 33 #define DOS_DATA_SEGMENT 0xA5 34 35 #define DOS_DATA_OFFSET(x) FIELD_OFFSET(DOS_DATA, x) 36 37 #define SYSTEM_ENV_BLOCK 0x600 // FIXME: Should be dynamically initialized! 38 39 #define SYSTEM_PSP 0x0008 40 41 #define INVALID_DOS_HANDLE 0xFFFF 42 #define DOS_INPUT_HANDLE 0 43 #define DOS_OUTPUT_HANDLE 1 44 #define DOS_ERROR_HANDLE 2 45 46 #define DOS_SFT_SIZE 255 // Value of the 'FILES=' command; maximum 255 47 #define DOS_DIR_LENGTH 64 48 #define NUM_DRIVES ('Z' - 'A' + 1) 49 #define DOS_CHAR_ATTRIBUTE 0x07 50 51 #pragma pack(push, 1) 52 53 typedef struct _DOS_FCB 54 { 55 BYTE DriveNumber; 56 CHAR FileName[8]; 57 CHAR FileExt[3]; 58 WORD BlockNumber; 59 WORD RecordSize; 60 DWORD FileSize; 61 WORD LastWriteDate; 62 WORD LastWriteTime; 63 BYTE Reserved[8]; 64 BYTE BlockRecord; 65 BYTE RecordNumber[3]; 66 } DOS_FCB, *PDOS_FCB; 67 68 // http://www.ctyme.com/intr/rb-2983.htm 69 typedef struct _DOS_SYSVARS 70 { 71 DWORD OemHandler; 72 WORD Int21hReturn; 73 WORD ShareRetryCount; 74 WORD ShareRetryDelay; 75 DWORD DiskBuffer; 76 WORD UnreadConInput; 77 WORD FirstMcb; 78 79 /* This is where the SYSVARS really start */ 80 DWORD FirstDpb; // 0x00 81 DWORD FirstSft; // 0x04 82 DWORD ActiveClock; // 0x08 83 DWORD ActiveCon; // 0x0c 84 BYTE Reserved0[6]; // 0x10 85 DWORD CurrentDirs; // 0x16 86 BYTE Reserved1[6]; // 0x1a 87 BYTE NumBlockDevices; // 0x20 88 BYTE NumLocalDrives; // 0x21 - Set by LASTDRIVE 89 DOS_DRIVER NullDevice; // 0x22 90 BYTE Reserved2; // 0x34 91 WORD ProgramVersionTable; // 0x35 92 DWORD SetVerTable; // 0x37 93 WORD Reserved3[2]; // 0x3b 94 WORD BuffersNumber; // 0x3f - 'x' parameter in "BUFFERS=x,y" command 95 WORD BuffersLookaheadNumber; // 0x41 - 'y' parameter in "BUFFERS=x,y" command 96 BYTE BootDrive; // 0x43 97 BYTE UseDwordMoves; // 0x44 98 WORD ExtMemSize; // 0x45 99 BYTE Reserved4[0x1C]; // 0x47 100 BYTE UmbLinked; // 0x63 - 0/1: UMB chain (un)linked to MCB chain 101 WORD Reserved5; // 0x64 102 WORD UmbChainStart; // 0x66 - Segment of the first UMB MCB 103 WORD MemAllocScanStart; // 0x68 - Segment where allocation scan starts 104 } DOS_SYSVARS, *PDOS_SYSVARS; 105 106 typedef struct _DOS_CLOCK_TRANSFER_RECORD 107 { 108 WORD NumberOfDays; 109 BYTE Minutes; 110 BYTE Hours; 111 BYTE Hundredths; 112 BYTE Seconds; 113 } DOS_CLOCK_TRANSFER_RECORD, *PDOS_CLOCK_TRANSFER_RECORD; 114 115 typedef struct _DOS_INPUT_BUFFER 116 { 117 BYTE MaxLength; 118 BYTE Length; 119 CHAR Buffer[ANYSIZE_ARRAY]; 120 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER; 121 122 /** 123 * @struct DOS_FIND_FILE_BLOCK 124 * Data block returned in the DTA (Disk Transfer Area) by the 125 * INT 21h, AH=4Eh "Find First File" and the INT 21h, AH=4Fh "Find Next File" 126 * functions. 127 * 128 * @see demFileFindFirst(), demFileFindNext() 129 **/ 130 typedef struct _DOS_FIND_FILE_BLOCK 131 { 132 /* The 21 first bytes (0x00 to 0x14 included) are reserved */ 133 CHAR DriveLetter; 134 CHAR Pattern[11]; 135 UCHAR AttribMask; 136 DWORD Unused; // FIXME: We must NOT store a Win32 handle here! 137 HANDLE SearchHandle; // Instead we should use an ID and helpers to map it to Win32. 138 139 /* The following part of the structure is documented */ 140 UCHAR Attributes; 141 WORD FileTime; 142 WORD FileDate; 143 DWORD FileSize; 144 _Null_terminated_ CHAR FileName[13]; 145 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK; 146 147 // http://www.ctyme.com/intr/rb-3023.htm 148 typedef struct _DOS_SDA 149 { 150 BYTE PrinterEchoFlag; 151 CHAR CurrentSwitchChar; 152 BYTE AllocStrategy; 153 BYTE Unused0[28]; 154 155 /* This is where the SDA really starts */ 156 BYTE ErrorMode; 157 BYTE InDos; 158 BYTE ErrorDrive; 159 BYTE LastErrorLocus; 160 WORD LastErrorCode; 161 BYTE LastErrorAction; 162 BYTE LastErrorClass; 163 DWORD LastErrorPointer; 164 DWORD DiskTransferArea; 165 WORD CurrentPsp; 166 WORD Int23StackPointer; 167 WORD ErrorLevel; 168 BYTE CurrentDrive; 169 BYTE ExtendedBreakFlag; 170 171 /* This part is only valid while in DOS */ 172 WORD LastAX; 173 WORD NetworkPsp; 174 WORD NetworkMachineNumber; 175 WORD FirstFreeMcb; 176 WORD BestFreeMcb; 177 WORD LastFreeMcb; 178 WORD MemorySize; 179 WORD LastSearchDirEntry; 180 BYTE Int24FailFlag; 181 BYTE DirectoryFlag; 182 BYTE CtrlBreakFlag; 183 BYTE AllowFcbBlanks; 184 BYTE Unused1; 185 BYTE DayOfMonth; 186 BYTE Month; 187 WORD Year; 188 WORD NumDays; 189 BYTE DayOfWeek; 190 BYTE ConsoleSwappedFlag; 191 BYTE Int28CallOk; 192 BYTE Int24AbortFlag; 193 DOS_RW_REQUEST Request; 194 DWORD DriverEntryPoint; 195 BYTE Unused2[44]; 196 BYTE PspCopyType; 197 BYTE Unused3; 198 BYTE UserNumber[3]; 199 BYTE OemNumber; 200 WORD ErrorCodeTable; 201 DOS_CLOCK_TRANSFER_RECORD ClockTransferRecord; 202 BYTE ByteBuffer; 203 BYTE Unused4; 204 CHAR FileNameBuffer[256]; 205 BYTE Unused5[53]; 206 CHAR CurrentDirectory[81]; 207 CHAR FcbFilename[12]; 208 CHAR FcbRenameDest[12]; 209 BYTE Unused6[8]; 210 BYTE ExtendedAttribute; 211 BYTE FcbType; 212 BYTE DirSearchAttributes; 213 BYTE FileOpenMode; 214 BYTE FileFound; 215 BYTE DeviceNameFound; 216 BYTE SpliceFlag; 217 BYTE DosCallFlag; 218 BYTE Unused7[5]; 219 BYTE InsertMode; 220 BYTE ParsedFcbExists; 221 BYTE VolumeIDFlag; 222 BYTE TerminationType; 223 BYTE CreateFileFlag; 224 BYTE FileDeletedChar; 225 DWORD CriticalErrorDpb; 226 DWORD UserRegistersStack; 227 WORD Int24StackPointer; 228 BYTE Unused8[14]; 229 DWORD DeviceHeader; 230 DWORD CurrentSft; 231 DWORD CurrentDirPointer; 232 DWORD CallerFcb; 233 WORD SftNumber; 234 WORD TempFileHandle; 235 DWORD JftEntry; 236 WORD FirstArgument; 237 WORD SecondArgument; 238 WORD LastComponent; 239 WORD TransferOffset; 240 BYTE Unused9[38]; 241 DWORD WorkingSft; 242 WORD Int21CallerBX; 243 WORD Int21CallerDS; 244 WORD Unused10; 245 DWORD PrevCallFrame; 246 } DOS_SDA, *PDOS_SDA; 247 248 /* 249 * DOS kernel data structure 250 */ 251 typedef struct _DOS_DATA 252 { 253 DOS_SYSVARS SysVars; 254 BYTE NullDriverRoutine[7]; 255 WORD DosVersion; // DOS version to report to programs (can be different from the true one) 256 DOS_SDA Sda; 257 CHAR CurrentDirectories[NUM_DRIVES][DOS_DIR_LENGTH]; 258 BYTE UnreadConInputBuffer[128]; 259 BYTE DosStack[384]; 260 BYTE Sft[ANYSIZE_ARRAY]; 261 } DOS_DATA, *PDOS_DATA; 262 263 /* 264 * DOS BIOS data structure at segment 70h 265 */ 266 typedef struct _BIOS_DATA 267 { 268 BYTE StartupCode[20]; // 0x00 - 20 bytes: large enough for now! 269 270 /* 271 * INT 13h (BIOS Disk Services) handler chain support. 272 * 273 * RomBiosInt13: The original INT 13h vector (normally from ROM BIOS). 274 * PrevInt13 : The previous INT 13h vector in the handler chain (initially 275 * initialized with the RomBiosInt13 value; each time some 276 * program calls INT 2Fh, AH=13h, PrevInt13 is updated). 277 * 278 * DOS hooks INT 13h with its own code, then (in normal circumstances) calls 279 * PrevInt13, so that when a program calls INT 13h, the DOS hook is first called, 280 * followed by the previous INT 13h (be it the original or some other hooked one). 281 * DOS may call PrevInt13 directly in some internal operations too. 282 * RomBiosInt13 is intended to be the original INT 13h vector that existed 283 * before DOS was loaded. A particular version of PC-AT's IBM's ROM BIOS 284 * (on systems with model byte FCh and BIOS date "01/10/84" only, see 285 * http://www.ctyme.com/intr/rb-4453.htm for more details) had a bug on disk 286 * reads so that it was patched by DOS, and therefore PrevInt13 was the fixed 287 * INT 13 interrupt (for the other cases, a direct call to RomBiosInt13 is done). 288 * 289 * NOTE: For compatibility with some programs (including virii), PrevInt13 should 290 * be at 0070:00B4, see for more details: 291 * http://repo.hackerzvoice.net/depot_madchat/vxdevl/vdat/tuvd0001.htm 292 * http://vxheaven.org/lib/vsm01.html 293 */ 294 BYTE Padding0[0xB0 - /*FIELD_OFFSET(BIOS_DATA, StartupCode)*/ 20]; 295 DWORD RomBiosInt13; // 0xb0 296 DWORD PrevInt13; // 0xb4 297 BYTE Padding1[0x100 - 0xB8]; // 0xb8 298 } BIOS_DATA, *PBIOS_DATA; 299 300 C_ASSERT(sizeof(BIOS_DATA) == 0x100); 301 302 #pragma pack(pop) 303 304 /* VARIABLES ******************************************************************/ 305 306 extern PBIOS_DATA BiosData; 307 extern PDOS_DATA DosData; 308 extern PDOS_SYSVARS SysVars; 309 extern PDOS_SDA Sda; 310 311 /* FUNCTIONS ******************************************************************/ 312 313 extern CALLBACK16 DosContext; 314 #define RegisterDosInt32(IntNumber, IntHandler) \ 315 do { \ 316 ASSERT((0x20 <= IntNumber) && (IntNumber <= 0x2F)); \ 317 RegisterInt32(DosContext.TrampolineFarPtr + \ 318 DosContext.TrampolineSize + \ 319 (IntNumber - 0x20) * Int16To32StubSize, \ 320 (IntNumber), (IntHandler), NULL); \ 321 } while(0); 322 323 VOID ConDrvInitialize(VOID); 324 VOID ConDrvCleanup(VOID); 325 326 /* 327 * DOS BIOS Functions 328 * See bios.c 329 */ 330 CHAR DosReadCharacter(WORD FileHandle, BOOLEAN Echo); 331 BOOLEAN DosCheckInput(VOID); 332 VOID DosPrintCharacter(WORD FileHandle, CHAR Character); 333 334 BOOLEAN DosBIOSInitialize(VOID); 335 336 BOOLEAN DosControlBreak(VOID); 337 VOID DosEchoCharacter(CHAR Character); 338 339 /* 340 * DOS Kernel Functions 341 * See dos.c 342 */ 343 BOOLEAN DosKRNLInitialize(VOID); 344 345 #endif // _DOS_H_ 346 347 /* EOF */ 348