[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 "ntvdm.h"
15 #include "device.h"
16
17 /**/ #include "int32.h" /**/
18
19 /* DEFINES ********************************************************************/
20
21 //
22 // We are DOS 5.00 (reported by INT 21h, AH=30h)
23 // and DOS 5.50 (reported by INT 21h, AX=3306h) for Windows NT Compatibility
24 //
25 #define DOS_VERSION MAKEWORD(5, 00)
26 #define NTDOS_VERSION MAKEWORD(5, 50)
27
28 #define DOS_CONFIG_PATH L"%SystemRoot%\\system32\\CONFIG.NT"
29 #define DOS_COMMAND_INTERPRETER L"%SystemRoot%\\system32\\COMMAND.COM /k %SystemRoot%\\system32\\AUTOEXEC.NT"
30 #define FIRST_MCB_SEGMENT 0x1000
31 #define USER_MEMORY_SIZE (0x9FFE - FIRST_MCB_SEGMENT)
32 #define SYSTEM_PSP 0x08
33 #define SYSTEM_ENV_BLOCK 0x800
34
35 #define INVALID_DOS_HANDLE 0xFFFF
36 #define DOS_INPUT_HANDLE 0
37 #define DOS_OUTPUT_HANDLE 1
38 #define DOS_ERROR_HANDLE 2
39
40 #define DOS_SFT_SIZE 255
41 #define SEGMENT_TO_MCB(seg) ((PDOS_MCB)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
42 #define SEGMENT_TO_PSP(seg) ((PDOS_PSP)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
43 #define UMB_START_SEGMENT 0xC000
44 #define UMB_END_SEGMENT 0xDFFF
45 #define DOS_ALLOC_HIGH 0x40
46 #define DOS_ALLOC_HIGH_LOW 0x80
47 #define DOS_CMDLINE_LENGTH 127
48 #define DOS_DIR_LENGTH 64
49 #define NUM_DRIVES ('Z' - 'A' + 1)
50 #define DOS_CHAR_ATTRIBUTE 0x07
51 #define DOS_PROGRAM_NAME_TAG 0x0001
52 #define DEFAULT_JFT_SIZE 20
53
54 typedef enum
55 {
56 DOS_LOAD_AND_EXECUTE = 0x00,
57 DOS_LOAD_ONLY = 0x01,
58 DOS_LOAD_OVERLAY = 0x03
59 } DOS_EXEC_TYPE;
60
61 typedef enum
62 {
63 DOS_SFT_ENTRY_NONE,
64 DOS_SFT_ENTRY_WIN32,
65 DOS_SFT_ENTRY_DEVICE
66 } DOS_SFT_ENTRY_TYPE;
67
68 typedef struct _DOS_SFT_ENTRY
69 {
70 DOS_SFT_ENTRY_TYPE Type;
71 WORD RefCount;
72
73 union
74 {
75 HANDLE Handle;
76 PDOS_DEVICE_NODE DeviceNode;
77 };
78 } DOS_SFT_ENTRY, *PDOS_SFT_ENTRY;
79
80 #pragma pack(push, 1)
81
82 typedef struct _DOS_FCB
83 {
84 BYTE DriveNumber;
85 CHAR FileName[8];
86 CHAR FileExt[3];
87 WORD BlockNumber;
88 WORD RecordSize;
89 DWORD FileSize;
90 WORD LastWriteDate;
91 WORD LastWriteTime;
92 BYTE Reserved[8];
93 BYTE BlockRecord;
94 BYTE RecordNumber[3];
95 } DOS_FCB, *PDOS_FCB;
96
97 typedef struct _DOS_PSP
98 {
99 BYTE Exit[2];
100 WORD LastParagraph;
101 BYTE Reserved0[6];
102 DWORD TerminateAddress;
103 DWORD BreakAddress;
104 DWORD CriticalAddress;
105 WORD ParentPsp;
106 BYTE HandleTable[20];
107 WORD EnvBlock;
108 DWORD LastStack;
109 WORD HandleTableSize;
110 DWORD HandleTablePtr;
111 DWORD PreviousPsp;
112 DWORD Reserved1;
113 WORD DosVersion;
114 BYTE Reserved2[14];
115 BYTE FarCall[3];
116 BYTE Reserved3[9];
117 DOS_FCB Fcb;
118 BYTE CommandLineSize;
119 CHAR CommandLine[DOS_CMDLINE_LENGTH];
120 } DOS_PSP, *PDOS_PSP;
121
122 typedef struct _DOS_INPUT_BUFFER
123 {
124 BYTE MaxLength;
125 BYTE Length;
126 CHAR Buffer[ANYSIZE_ARRAY];
127 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
128
129 typedef struct _DOS_DRIVER_HEADER
130 {
131 DWORD NextDriver;
132 WORD Attributes;
133 WORD StrategyEntry;
134 WORD InterruptEntry;
135 CHAR DeviceName[8];
136 } DOS_DRIVER_HEADER, *PDOS_DRIVER_HEADER;
137
138 typedef struct _DOS_FIND_FILE_BLOCK
139 {
140 CHAR DriveLetter;
141 CHAR Pattern[11];
142 UCHAR AttribMask;
143 DWORD Unused;
144 HANDLE SearchHandle;
145
146 /* The following part of the structure is documented */
147 UCHAR Attributes;
148 WORD FileTime;
149 WORD FileDate;
150 DWORD FileSize;
151 CHAR FileName[13];
152 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK;
153
154 typedef struct _DOS_EXEC_PARAM_BLOCK
155 {
156 /* Input variables */
157 WORD Environment;
158 DWORD CommandLine;
159 DWORD FirstFcb;
160 DWORD SecondFcb;
161
162 /* Output variables */
163 DWORD StackLocation;
164 DWORD EntryPoint;
165 } DOS_EXEC_PARAM_BLOCK, *PDOS_EXEC_PARAM_BLOCK;
166
167 typedef struct _DOS_COUNTRY_CODE_BUFFER
168 {
169 WORD TimeFormat;
170 WORD CurrencySymbol;
171 WORD ThousandSep;
172 WORD DecimalSep;
173 } DOS_COUNTRY_CODE_BUFFER, *PDOS_COUNTRY_CODE_BUFFER;
174
175 #pragma pack(pop)
176
177 /* VARIABLES ******************************************************************/
178
179 extern BOOLEAN DoEcho;
180 extern WORD CurrentPsp;
181 extern WORD DosLastError;
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 EmsDrvInitialize(VOID);
203 VOID EmsDrvCleanup(VOID);
204 VOID ConDrvInitialize(VOID);
205 VOID ConDrvCleanup(VOID);
206
207 /*
208 * DOS Kernel Functions
209 * See dos.c
210 */
211 WORD DosOpenHandle(HANDLE Handle);
212 PDOS_SFT_ENTRY DosGetSftEntry(WORD DosHandle);
213
214 WORD DosCreateFileEx(LPWORD Handle,
215 LPWORD CreationStatus,
216 LPCSTR FilePath,
217 BYTE AccessShareModes,
218 WORD CreateActionFlags,
219 WORD Attributes);
220 WORD DosCreateFile(LPWORD Handle,
221 LPCSTR FilePath,
222 DWORD CreationDisposition,
223 WORD Attributes);
224 WORD DosOpenFile(LPWORD Handle,
225 LPCSTR FilePath,
226 BYTE AccessShareModes);
227 WORD DosReadFile(WORD FileHandle,
228 DWORD Buffer,
229 WORD Count,
230 LPWORD BytesRead);
231 WORD DosWriteFile(WORD FileHandle,
232 DWORD Buffer,
233 WORD Count,
234 LPWORD BytesWritten);
235 WORD DosSeekFile(WORD FileHandle,
236 LONG Offset,
237 BYTE Origin,
238 LPDWORD NewOffset);
239 BOOL DosFlushFileBuffers(WORD FileHandle);
240
241 VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WORD Environment);
242 DWORD DosLoadExecutable(
243 IN DOS_EXEC_TYPE LoadType,
244 IN LPCSTR ExecutablePath,
245 IN LPCSTR CommandLine,
246 IN LPCSTR Environment OPTIONAL,
247 OUT PDWORD StackLocation OPTIONAL,
248 OUT PDWORD EntryPoint OPTIONAL
249 );
250 WORD DosCreateProcess(
251 DOS_EXEC_TYPE LoadType,
252 LPCSTR ProgramName,
253 PDOS_EXEC_PARAM_BLOCK Parameters
254 );
255 DWORD DosStartProcess(
256 IN LPCSTR ExecutablePath,
257 IN LPCSTR CommandLine,
258 IN LPCSTR Environment OPTIONAL
259 );
260 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode, WORD KeepResident);
261 BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
262
263 BOOLEAN DosKRNLInitialize(VOID);
264
265 #endif // _DOS_H_
266
267 /* EOF */