[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 #define FIRST_MCB_SEGMENT 0x1000
30 #define USER_MEMORY_SIZE (0x9FFE - FIRST_MCB_SEGMENT)
31 #define SYSTEM_PSP 0x08
32 #define SYSTEM_ENV_BLOCK 0x800
33 #define DOS_DATA_SEGMENT 0xA0
34 #define MASTER_SFT_OFFSET 0x100
35
36 #define INVALID_DOS_HANDLE 0xFFFF
37 #define DOS_INPUT_HANDLE 0
38 #define DOS_OUTPUT_HANDLE 1
39 #define DOS_ERROR_HANDLE 2
40
41 #define DOS_SFT_SIZE 255
42 #define SEGMENT_TO_MCB(seg) ((PDOS_MCB)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
43 #define SEGMENT_TO_PSP(seg) ((PDOS_PSP)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
44 #define UMB_START_SEGMENT 0xC000
45 #define UMB_END_SEGMENT 0xDFFF
46 #define DOS_ALLOC_HIGH 0x40
47 #define DOS_ALLOC_HIGH_LOW 0x80
48 #define DOS_CMDLINE_LENGTH 127
49 #define DOS_DIR_LENGTH 64
50 #define NUM_DRIVES ('Z' - 'A' + 1)
51 #define DOS_CHAR_ATTRIBUTE 0x07
52 #define DOS_PROGRAM_NAME_TAG 0x0001
53
54 /* 16 MB of EMS memory */
55 #define EMS_TOTAL_PAGES 1024
56
57 typedef enum
58 {
59 DOS_LOAD_AND_EXECUTE = 0x00,
60 DOS_LOAD_ONLY = 0x01,
61 DOS_LOAD_OVERLAY = 0x03
62 } DOS_EXEC_TYPE;
63
64 #pragma pack(push, 1)
65
66 typedef struct _DOS_FCB
67 {
68 BYTE DriveNumber;
69 CHAR FileName[8];
70 CHAR FileExt[3];
71 WORD BlockNumber;
72 WORD RecordSize;
73 DWORD FileSize;
74 WORD LastWriteDate;
75 WORD LastWriteTime;
76 BYTE Reserved[8];
77 BYTE BlockRecord;
78 BYTE RecordNumber[3];
79 } DOS_FCB, *PDOS_FCB;
80
81 typedef struct _DOS_SYSVARS
82 {
83 DWORD OemHandler;
84 WORD Int21hReturn;
85 WORD ShareRetryCount;
86 WORD ShareRetryDelay;
87 DWORD DiskBuffer;
88 WORD UnreadConInput;
89 WORD FirstMcb;
90
91 /* This is where the SYSVARS really start */
92 DWORD FirstDpb;
93 DWORD FirstSft;
94 DWORD ActiveClock;
95 DWORD ActiveCon;
96 BYTE Reserved0[6];
97 DWORD CurrentDirs;
98 BYTE Reserved1[6];
99 BYTE NumBlockDevices;
100 BYTE NumLocalDrives;
101 DOS_DRIVER NullDevice;
102 BYTE NullDriverRoutine[7];
103 } DOS_SYSVARS, *PDOS_SYSVARS;
104
105 typedef struct _DOS_PSP
106 {
107 BYTE Exit[2];
108 WORD LastParagraph;
109 BYTE Reserved0[6];
110 DWORD TerminateAddress;
111 DWORD BreakAddress;
112 DWORD CriticalAddress;
113 WORD ParentPsp;
114 BYTE HandleTable[20];
115 WORD EnvBlock;
116 DWORD LastStack;
117 WORD HandleTableSize;
118 DWORD HandleTablePtr;
119 DWORD PreviousPsp;
120 DWORD Reserved1;
121 WORD DosVersion;
122 BYTE Reserved2[14];
123 BYTE FarCall[3];
124 BYTE Reserved3[9];
125 DOS_FCB Fcb;
126 BYTE CommandLineSize;
127 CHAR CommandLine[DOS_CMDLINE_LENGTH];
128 } DOS_PSP, *PDOS_PSP;
129
130 typedef struct _DOS_INPUT_BUFFER
131 {
132 BYTE MaxLength;
133 BYTE Length;
134 CHAR Buffer[ANYSIZE_ARRAY];
135 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
136
137 typedef struct _DOS_FIND_FILE_BLOCK
138 {
139 CHAR DriveLetter;
140 CHAR Pattern[11];
141 UCHAR AttribMask;
142 DWORD Unused;
143 HANDLE SearchHandle;
144
145 /* The following part of the structure is documented */
146 UCHAR Attributes;
147 WORD FileTime;
148 WORD FileDate;
149 DWORD FileSize;
150 CHAR FileName[13];
151 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK;
152
153 typedef struct _DOS_EXEC_PARAM_BLOCK
154 {
155 /* Input variables */
156 WORD Environment;
157 DWORD CommandLine;
158 DWORD FirstFcb;
159 DWORD SecondFcb;
160
161 /* Output variables */
162 DWORD StackLocation;
163 DWORD EntryPoint;
164 } DOS_EXEC_PARAM_BLOCK, *PDOS_EXEC_PARAM_BLOCK;
165
166 typedef struct _DOS_COUNTRY_CODE_BUFFER
167 {
168 WORD TimeFormat;
169 WORD CurrencySymbol;
170 WORD ThousandSep;
171 WORD DecimalSep;
172 } DOS_COUNTRY_CODE_BUFFER, *PDOS_COUNTRY_CODE_BUFFER;
173
174 #pragma pack(pop)
175
176 /* VARIABLES ******************************************************************/
177
178 extern BOOLEAN DoEcho;
179 extern WORD CurrentPsp;
180 extern WORD DosLastError;
181 extern PDOS_SYSVARS SysVars;
182
183 /* FUNCTIONS ******************************************************************/
184
185 extern CALLBACK16 DosContext;
186 #define RegisterDosInt32(IntNumber, IntHandler) \
187 do { \
188 DosContext.NextOffset += RegisterInt32(MAKELONG(DosContext.NextOffset, \
189 DosContext.Segment), \
190 (IntNumber), (IntHandler), NULL); \
191 } while(0);
192
193 /*
194 * DOS BIOS Functions
195 * See bios.c
196 */
197 CHAR DosReadCharacter(WORD FileHandle);
198 BOOLEAN DosCheckInput(VOID);
199 VOID DosPrintCharacter(WORD FileHandle, CHAR Character);
200
201 BOOLEAN DosBIOSInitialize(VOID);
202 VOID ConDrvInitialize(VOID);
203 VOID ConDrvCleanup(VOID);
204
205 /*
206 * DOS Kernel Functions
207 * See dos.c
208 */
209
210 VOID DosInitializePsp(
211 WORD PspSegment,
212 LPCSTR CommandLine,
213 WORD ProgramSize,
214 WORD Environment,
215 DWORD ReturnAddress
216 );
217 DWORD DosLoadExecutable(
218 IN DOS_EXEC_TYPE LoadType,
219 IN LPCSTR ExecutablePath,
220 IN LPCSTR CommandLine,
221 IN LPCSTR Environment OPTIONAL,
222 IN DWORD ReturnAddress OPTIONAL,
223 OUT PDWORD StackLocation OPTIONAL,
224 OUT PDWORD EntryPoint OPTIONAL
225 );
226 WORD DosCreateProcess(
227 DOS_EXEC_TYPE LoadType,
228 LPCSTR ProgramName,
229 PDOS_EXEC_PARAM_BLOCK Parameters,
230 DWORD ReturnAddress
231 );
232 DWORD DosStartProcess(
233 IN LPCSTR ExecutablePath,
234 IN LPCSTR CommandLine,
235 IN LPCSTR Environment OPTIONAL
236 );
237 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode, WORD KeepResident);
238 BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
239
240 BOOLEAN DosKRNLInitialize(VOID);
241
242 #endif // _DOS_H_
243
244 /* EOF */