[NTVDM]
[reactos.git] / reactos / subsystems / mvdm / ntvdm / dos / dos32krnl / dos.h
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: 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 SYSTEM_PSP 0x08
31 #define SYSTEM_ENV_BLOCK 0x800
32 #define DOS_CODE_SEGMENT 0x70
33 #define DOS_DATA_SEGMENT 0xA0
34
35 #define DOS_DATA_OFFSET(x) FIELD_OFFSET(DOS_DATA, x)
36
37 #define INVALID_DOS_HANDLE 0xFFFF
38 #define DOS_INPUT_HANDLE 0
39 #define DOS_OUTPUT_HANDLE 1
40 #define DOS_ERROR_HANDLE 2
41
42 #define DOS_SFT_SIZE 255
43 #define DOS_DIR_LENGTH 64
44 #define NUM_DRIVES ('Z' - 'A' + 1)
45 #define DOS_CHAR_ATTRIBUTE 0x07
46
47 #pragma pack(push, 1)
48
49 typedef struct _DOS_FCB
50 {
51 BYTE DriveNumber;
52 CHAR FileName[8];
53 CHAR FileExt[3];
54 WORD BlockNumber;
55 WORD RecordSize;
56 DWORD FileSize;
57 WORD LastWriteDate;
58 WORD LastWriteTime;
59 BYTE Reserved[8];
60 BYTE BlockRecord;
61 BYTE RecordNumber[3];
62 } DOS_FCB, *PDOS_FCB;
63
64 typedef struct _DOS_SYSVARS
65 {
66 DWORD OemHandler;
67 WORD Int21hReturn;
68 WORD ShareRetryCount;
69 WORD ShareRetryDelay;
70 DWORD DiskBuffer;
71 WORD UnreadConInput;
72 WORD FirstMcb;
73
74 /* This is where the SYSVARS really start */
75 DWORD FirstDpb; // 0x00
76 DWORD FirstSft; // 0x04
77 DWORD ActiveClock; // 0x08
78 DWORD ActiveCon; // 0x0c
79 BYTE Reserved0[6]; // 0x10
80 DWORD CurrentDirs; // 0x16
81 BYTE Reserved1[6]; // 0x1a
82 BYTE NumBlockDevices; // 0x20
83 BYTE NumLocalDrives; // 0x21 - Set by LASTDRIVE
84 DOS_DRIVER NullDevice; // 0x22
85 BYTE Reserved2; // 0x34
86 WORD ProgramVersionTable; // 0x35
87 DWORD SetVerTable; // 0x37
88 WORD Reserved3[2]; // 0x3b
89 WORD BuffersNumber; // 0x3f - 'x' parameter in "BUFFERS=x,y" command
90 WORD BuffersLookaheadNumber; // 0x41 - 'y' parameter in "BUFFERS=x,y" command
91 BYTE BootDrive; // 0x43
92 BYTE UseDwordMoves; // 0x44
93 WORD ExtMemSize; // 0x45
94 BYTE Reserved4[0x1C]; // 0x47
95 BYTE ChainUMB; // 0x63 - 0/1: UMB chain (un)linked to MCB chain
96 WORD Reserved5; // 0x64
97 WORD UMBChainStart; // 0x66 - Segment of the first UMB MCB
98 WORD MemAllocScanStart; // 0x68 - Segment where allocation scan starts
99 } DOS_SYSVARS, *PDOS_SYSVARS;
100
101 typedef struct _DOS_CLOCK_TRANSFER_RECORD
102 {
103 WORD NumberOfDays;
104 BYTE Minutes;
105 BYTE Hours;
106 BYTE Hundredths;
107 BYTE Seconds;
108 } DOS_CLOCK_TRANSFER_RECORD, *PDOS_CLOCK_TRANSFER_RECORD;
109
110 typedef struct _DOS_INPUT_BUFFER
111 {
112 BYTE MaxLength;
113 BYTE Length;
114 CHAR Buffer[ANYSIZE_ARRAY];
115 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
116
117 typedef struct _DOS_FIND_FILE_BLOCK
118 {
119 CHAR DriveLetter;
120 CHAR Pattern[11];
121 UCHAR AttribMask;
122 DWORD Unused;
123 HANDLE SearchHandle;
124
125 /* The following part of the structure is documented */
126 UCHAR Attributes;
127 WORD FileTime;
128 WORD FileDate;
129 DWORD FileSize;
130 CHAR FileName[13];
131 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK;
132
133 typedef struct _DOS_SDA
134 {
135 BYTE PrinterEchoFlag;
136 CHAR CurrentSwitchChar;
137 BYTE AllocStrategy;
138 BYTE Unused0[28];
139
140 /* This is where the SDA really starts */
141 BYTE ErrorMode;
142 BYTE InDos;
143 BYTE ErrorDrive;
144 BYTE LastErrorLocus;
145 WORD LastErrorCode;
146 BYTE LastErrorAction;
147 BYTE LastErrorClass;
148 DWORD LastErrorPointer;
149 DWORD DiskTransferArea;
150 WORD CurrentPsp;
151 WORD Int23StackPointer;
152 WORD ErrorLevel;
153 BYTE CurrentDrive;
154 BYTE ExtendedBreakFlag;
155
156 /* This part is only valid while in DOS */
157 WORD LastAX;
158 WORD NetworkPsp;
159 WORD NetworkMachineNumber;
160 WORD FirstFreeMcb;
161 WORD BestFreeMcb;
162 WORD LastFreeMcb;
163 WORD MemorySize;
164 WORD LastSearchDirEntry;
165 BYTE Int24FailFlag;
166 BYTE DirectoryFlag;
167 BYTE CtrlBreakFlag;
168 BYTE AllowFcbBlanks;
169 BYTE Unused1;
170 BYTE DayOfMonth;
171 BYTE Month;
172 WORD Year;
173 WORD NumDays;
174 BYTE DayOfWeek;
175 BYTE ConsoleSwappedFlag;
176 BYTE Int28CallOk;
177 BYTE Int24AbortFlag;
178 DOS_RW_REQUEST Request;
179 DWORD DriverEntryPoint;
180 BYTE Unused2[44];
181 BYTE PspCopyType;
182 BYTE Unused3;
183 BYTE UserNumber[3];
184 BYTE OemNumber;
185 WORD ErrorCodeTable;
186 DOS_CLOCK_TRANSFER_RECORD ClockTransferRecord;
187 BYTE ByteBuffer;
188 BYTE Unused4;
189 CHAR FileNameBuffer[256];
190 BYTE Unused5[53];
191 CHAR CurrentDirectory[81];
192 CHAR FcbFilename[12];
193 CHAR FcbRenameDest[12];
194 BYTE Unused6[8];
195 BYTE ExtendedAttribute;
196 BYTE FcbType;
197 BYTE DirSearchAttributes;
198 BYTE FileOpenMode;
199 BYTE FileFound;
200 BYTE DeviceNameFound;
201 BYTE SpliceFlag;
202 BYTE DosCallFlag;
203 BYTE Unused7[5];
204 BYTE InsertMode;
205 BYTE ParsedFcbExists;
206 BYTE VolumeIDFlag;
207 BYTE TerminationType;
208 BYTE CreateFileFlag;
209 BYTE FileDeletedChar;
210 DWORD CriticalErrorDpb;
211 DWORD UserRegistersStack;
212 WORD Int24StackPointer;
213 BYTE Unused8[14];
214 DWORD DeviceHeader;
215 DWORD CurrentSft;
216 DWORD CurrentDirPointer;
217 DWORD CallerFcb;
218 WORD SftNumber;
219 WORD TempFileHandle;
220 DWORD JftEntry;
221 WORD FirstArgument;
222 WORD SecondArgument;
223 WORD LastComponent;
224 WORD TransferOffset;
225 BYTE Unused9[38];
226 DWORD WorkingSft;
227 WORD Int21CallerBX;
228 WORD Int21CallerDS;
229 WORD Unused10;
230 DWORD PrevCallFrame;
231 } DOS_SDA, *PDOS_SDA;
232
233 typedef struct _DOS_DATA
234 {
235 /*
236 * INT 13h (BIOS Disk Services) handler chain support.
237 *
238 * RomBiosInt13: The original INT 13h vector (normally from ROM BIOS).
239 * PrevInt13 : The previous INT 13h vector in the handler chain (initially
240 * initialized with the RomBiosInt13 value; each time some
241 * program calls INT 2Fh, AH=13h, PrevInt13 is updated).
242 *
243 * DOS hooks INT 13h with its own code, then (in normal circumstances) calls
244 * PrevInt13, so that when a program calls INT 13h, the DOS hook is first called,
245 * followed by the previous INT 13h (be it the original or some other hooked one).
246 * DOS may call PrevInt13 directly in some internal operations too.
247 * RomBiosInt13 is intended to be the original INT 13h vector that existed
248 * before DOS was loaded. A particular version of PC-AT's IBM's ROM BIOS
249 * (on systems with model byte FCh and BIOS date "01/10/84" only, see
250 * http://www.ctyme.com/intr/rb-4453.htm for more details) had a bug on disk
251 * reads so that it was patched by DOS, and therefore PrevInt13 was the fixed
252 * INT 13 interrupt (for the other cases, a direct call to RomBiosInt13 is done).
253 *
254 * NOTE: For compatibility with some programs (including virii), PrevInt13 should
255 * be at 0070:00B4, see for more details:
256 * http://repo.hackerzvoice.net/depot_madchat/vxdevl/vdat/tuvd0001.htm
257 * http://vxheaven.org/lib/vsm01.html
258 */
259 DWORD RomBiosInt13;
260 DWORD PrevInt13; // FIXME: Put it at 0070:00B4
261
262 DOS_SYSVARS SysVars;
263 BYTE NullDriverRoutine[7];
264 WORD DosVersion; // DOS version to report to programs (can be different from the true one)
265 DOS_SDA Sda;
266 CHAR CurrentDirectories[NUM_DRIVES][DOS_DIR_LENGTH];
267 BYTE Sft[ANYSIZE_ARRAY];
268 } DOS_DATA, *PDOS_DATA;
269
270 #pragma pack(pop)
271
272 /* VARIABLES ******************************************************************/
273
274 extern BOOLEAN DoEcho;
275 extern PDOS_DATA DosData;
276 extern PDOS_SYSVARS SysVars;
277 extern PDOS_SDA Sda;
278
279 /* FUNCTIONS ******************************************************************/
280
281 extern CALLBACK16 DosContext;
282 #define RegisterDosInt32(IntNumber, IntHandler) \
283 do { \
284 DosContext.NextOffset += RegisterInt32(MAKELONG(DosContext.NextOffset, \
285 DosContext.Segment), \
286 (IntNumber), (IntHandler), NULL); \
287 } while(0);
288
289 /*
290 * DOS BIOS Functions
291 * See bios.c
292 */
293 CHAR DosReadCharacter(WORD FileHandle);
294 BOOLEAN DosCheckInput(VOID);
295 VOID DosPrintCharacter(WORD FileHandle, CHAR Character);
296
297 BOOLEAN DosBIOSInitialize(VOID);
298 VOID ConDrvInitialize(VOID);
299 VOID ConDrvCleanup(VOID);
300
301 /*
302 * DOS Kernel Functions
303 * See dos.c
304 */
305
306 BOOLEAN DosKRNLInitialize(VOID);
307
308 #endif // _DOS_H_
309
310 /* EOF */