5214edcfa659f4e8777154d65fb1be3bfe3a9379
[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 /* 16 MB of EMS memory */
54 #define EMS_TOTAL_PAGES 1024
55
56 typedef enum
57 {
58 DOS_LOAD_AND_EXECUTE = 0x00,
59 DOS_LOAD_ONLY = 0x01,
60 DOS_LOAD_OVERLAY = 0x03
61 } DOS_EXEC_TYPE;
62
63 typedef enum
64 {
65 DOS_SFT_ENTRY_NONE,
66 DOS_SFT_ENTRY_WIN32,
67 DOS_SFT_ENTRY_DEVICE
68 } DOS_SFT_ENTRY_TYPE;
69
70 typedef struct _DOS_SFT_ENTRY
71 {
72 DOS_SFT_ENTRY_TYPE Type;
73 WORD RefCount;
74
75 union
76 {
77 HANDLE Handle;
78 PDOS_DEVICE_NODE DeviceNode;
79 };
80 } DOS_SFT_ENTRY, *PDOS_SFT_ENTRY;
81
82 #pragma pack(push, 1)
83
84 typedef struct _DOS_FCB
85 {
86 BYTE DriveNumber;
87 CHAR FileName[8];
88 CHAR FileExt[3];
89 WORD BlockNumber;
90 WORD RecordSize;
91 DWORD FileSize;
92 WORD LastWriteDate;
93 WORD LastWriteTime;
94 BYTE Reserved[8];
95 BYTE BlockRecord;
96 BYTE RecordNumber[3];
97 } DOS_FCB, *PDOS_FCB;
98
99 typedef struct _DOS_PSP
100 {
101 BYTE Exit[2];
102 WORD LastParagraph;
103 BYTE Reserved0[6];
104 DWORD TerminateAddress;
105 DWORD BreakAddress;
106 DWORD CriticalAddress;
107 WORD ParentPsp;
108 BYTE HandleTable[20];
109 WORD EnvBlock;
110 DWORD LastStack;
111 WORD HandleTableSize;
112 DWORD HandleTablePtr;
113 DWORD PreviousPsp;
114 DWORD Reserved1;
115 WORD DosVersion;
116 BYTE Reserved2[14];
117 BYTE FarCall[3];
118 BYTE Reserved3[9];
119 DOS_FCB Fcb;
120 BYTE CommandLineSize;
121 CHAR CommandLine[DOS_CMDLINE_LENGTH];
122 } DOS_PSP, *PDOS_PSP;
123
124 typedef struct _DOS_INPUT_BUFFER
125 {
126 BYTE MaxLength;
127 BYTE Length;
128 CHAR Buffer[ANYSIZE_ARRAY];
129 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
130
131 typedef struct _DOS_DRIVER_HEADER
132 {
133 DWORD NextDriver;
134 WORD Attributes;
135 WORD StrategyEntry;
136 WORD InterruptEntry;
137 CHAR DeviceName[8];
138 } DOS_DRIVER_HEADER, *PDOS_DRIVER_HEADER;
139
140 typedef struct _DOS_FIND_FILE_BLOCK
141 {
142 CHAR DriveLetter;
143 CHAR Pattern[11];
144 UCHAR AttribMask;
145 DWORD Unused;
146 HANDLE SearchHandle;
147
148 /* The following part of the structure is documented */
149 UCHAR Attributes;
150 WORD FileTime;
151 WORD FileDate;
152 DWORD FileSize;
153 CHAR FileName[13];
154 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK;
155
156 typedef struct _DOS_EXEC_PARAM_BLOCK
157 {
158 /* Input variables */
159 WORD Environment;
160 DWORD CommandLine;
161 DWORD FirstFcb;
162 DWORD SecondFcb;
163
164 /* Output variables */
165 DWORD StackLocation;
166 DWORD EntryPoint;
167 } DOS_EXEC_PARAM_BLOCK, *PDOS_EXEC_PARAM_BLOCK;
168
169 typedef struct _DOS_COUNTRY_CODE_BUFFER
170 {
171 WORD TimeFormat;
172 WORD CurrencySymbol;
173 WORD ThousandSep;
174 WORD DecimalSep;
175 } DOS_COUNTRY_CODE_BUFFER, *PDOS_COUNTRY_CODE_BUFFER;
176
177 #pragma pack(pop)
178
179 /* VARIABLES ******************************************************************/
180
181 extern BOOLEAN DoEcho;
182 extern WORD CurrentPsp;
183 extern WORD DosLastError;
184
185 /* FUNCTIONS ******************************************************************/
186
187 extern CALLBACK16 DosContext;
188 #define RegisterDosInt32(IntNumber, IntHandler) \
189 do { \
190 DosContext.NextOffset += RegisterInt32(MAKELONG(DosContext.NextOffset, \
191 DosContext.Segment), \
192 (IntNumber), (IntHandler), NULL); \
193 } while(0);
194
195 /*
196 * DOS BIOS Functions
197 * See bios.c
198 */
199 CHAR DosReadCharacter(WORD FileHandle);
200 BOOLEAN DosCheckInput(VOID);
201 VOID DosPrintCharacter(WORD FileHandle, CHAR Character);
202
203 BOOLEAN DosBIOSInitialize(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 */