[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
34 #define INVALID_DOS_HANDLE 0xFFFF
35 #define DOS_INPUT_HANDLE 0
36 #define DOS_OUTPUT_HANDLE 1
37 #define DOS_ERROR_HANDLE 2
38
39 #define DOS_SFT_SIZE 255
40 #define SEGMENT_TO_MCB(seg) ((PDOS_MCB)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
41 #define SEGMENT_TO_PSP(seg) ((PDOS_PSP)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
42 #define UMB_START_SEGMENT 0xC000
43 #define UMB_END_SEGMENT 0xDFFF
44 #define DOS_ALLOC_HIGH 0x40
45 #define DOS_ALLOC_HIGH_LOW 0x80
46 #define DOS_CMDLINE_LENGTH 127
47 #define DOS_DIR_LENGTH 64
48 #define NUM_DRIVES ('Z' - 'A' + 1)
49 #define DOS_CHAR_ATTRIBUTE 0x07
50 #define DOS_PROGRAM_NAME_TAG 0x0001
51 #define DEFAULT_JFT_SIZE 20
52
53 typedef enum
54 {
55 DOS_LOAD_AND_EXECUTE = 0x00,
56 DOS_LOAD_ONLY = 0x01,
57 DOS_LOAD_OVERLAY = 0x03
58 } DOS_EXEC_TYPE;
59
60 typedef enum
61 {
62 DOS_SFT_ENTRY_NONE,
63 DOS_SFT_ENTRY_WIN32,
64 DOS_SFT_ENTRY_DEVICE
65 } DOS_SFT_ENTRY_TYPE;
66
67 typedef struct _DOS_SFT_ENTRY
68 {
69 DOS_SFT_ENTRY_TYPE Type;
70 WORD RefCount;
71
72 union
73 {
74 HANDLE Handle;
75 PDOS_DEVICE_NODE DeviceNode;
76 };
77 } DOS_SFT_ENTRY, *PDOS_SFT_ENTRY;
78
79 #pragma pack(push, 1)
80
81 typedef struct _DOS_FCB
82 {
83 BYTE DriveNumber;
84 CHAR FileName[8];
85 CHAR FileExt[3];
86 WORD BlockNumber;
87 WORD RecordSize;
88 DWORD FileSize;
89 WORD LastWriteDate;
90 WORD LastWriteTime;
91 BYTE Reserved[8];
92 BYTE BlockRecord;
93 BYTE RecordNumber[3];
94 } DOS_FCB, *PDOS_FCB;
95
96 typedef struct _DOS_PSP
97 {
98 BYTE Exit[2];
99 WORD LastParagraph;
100 BYTE Reserved0[6];
101 DWORD TerminateAddress;
102 DWORD BreakAddress;
103 DWORD CriticalAddress;
104 WORD ParentPsp;
105 BYTE HandleTable[20];
106 WORD EnvBlock;
107 DWORD LastStack;
108 WORD HandleTableSize;
109 DWORD HandleTablePtr;
110 DWORD PreviousPsp;
111 DWORD Reserved1;
112 WORD DosVersion;
113 BYTE Reserved2[14];
114 BYTE FarCall[3];
115 BYTE Reserved3[9];
116 DOS_FCB Fcb;
117 BYTE CommandLineSize;
118 CHAR CommandLine[DOS_CMDLINE_LENGTH];
119 } DOS_PSP, *PDOS_PSP;
120
121 typedef struct _DOS_INPUT_BUFFER
122 {
123 BYTE MaxLength;
124 BYTE Length;
125 CHAR Buffer[ANYSIZE_ARRAY];
126 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
127
128 typedef struct _DOS_DRIVER_HEADER
129 {
130 DWORD NextDriver;
131 WORD Attributes;
132 WORD StrategyEntry;
133 WORD InterruptEntry;
134 CHAR DeviceName[8];
135 } DOS_DRIVER_HEADER, *PDOS_DRIVER_HEADER;
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
182 /* FUNCTIONS ******************************************************************/
183
184 extern CALLBACK16 DosContext;
185 #define RegisterDosInt32(IntNumber, IntHandler) \
186 do { \
187 DosContext.NextOffset += RegisterInt32(MAKELONG(DosContext.NextOffset, \
188 DosContext.Segment), \
189 (IntNumber), (IntHandler), NULL); \
190 } while(0);
191
192 /*
193 * DOS BIOS Functions
194 * See bios.c
195 */
196 CHAR DosReadCharacter(WORD FileHandle);
197 BOOLEAN DosCheckInput(VOID);
198 VOID DosPrintCharacter(WORD FileHandle, CHAR Character);
199
200 BOOLEAN DosBIOSInitialize(VOID);
201 VOID EmsDrvInitialize(VOID);
202 VOID EmsDrvCleanup(VOID);
203 VOID ConDrvInitialize(VOID);
204 VOID ConDrvCleanup(VOID);
205
206 /*
207 * DOS Kernel Functions
208 * See dos.c
209 */
210 WORD DosOpenHandle(HANDLE Handle);
211 PDOS_SFT_ENTRY DosGetSftEntry(WORD DosHandle);
212
213 WORD DosCreateFileEx(LPWORD Handle,
214 LPWORD CreationStatus,
215 LPCSTR FilePath,
216 BYTE AccessShareModes,
217 WORD CreateActionFlags,
218 WORD Attributes);
219 WORD DosCreateFile(LPWORD Handle,
220 LPCSTR FilePath,
221 DWORD CreationDisposition,
222 WORD Attributes);
223 WORD DosOpenFile(LPWORD Handle,
224 LPCSTR FilePath,
225 BYTE AccessShareModes);
226 WORD DosReadFile(WORD FileHandle,
227 DWORD Buffer,
228 WORD Count,
229 LPWORD BytesRead);
230 WORD DosWriteFile(WORD FileHandle,
231 DWORD Buffer,
232 WORD Count,
233 LPWORD BytesWritten);
234 WORD DosSeekFile(WORD FileHandle,
235 LONG Offset,
236 BYTE Origin,
237 LPDWORD NewOffset);
238 BOOL DosFlushFileBuffers(WORD FileHandle);
239
240 VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WORD Environment);
241 DWORD DosLoadExecutable(
242 IN DOS_EXEC_TYPE LoadType,
243 IN LPCSTR ExecutablePath,
244 IN LPCSTR CommandLine,
245 IN LPCSTR Environment OPTIONAL,
246 OUT PDWORD StackLocation OPTIONAL,
247 OUT PDWORD EntryPoint OPTIONAL
248 );
249 WORD DosCreateProcess(
250 DOS_EXEC_TYPE LoadType,
251 LPCSTR ProgramName,
252 PDOS_EXEC_PARAM_BLOCK Parameters
253 );
254 DWORD DosStartProcess(
255 IN LPCSTR ExecutablePath,
256 IN LPCSTR CommandLine,
257 IN LPCSTR Environment OPTIONAL
258 );
259 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode, WORD KeepResident);
260 BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
261
262 BOOLEAN DosKRNLInitialize(VOID);
263
264 #endif // _DOS_H_
265
266 /* EOF */