[NTVDM]
[reactos.git] / reactos / subsystems / 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.h
5 * PURPOSE: VDM DOS 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
16 /**/ #include "callback.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
51 enum DOS_ALLOC_STRATEGY
52 {
53 DOS_ALLOC_FIRST_FIT,
54 DOS_ALLOC_BEST_FIT,
55 DOS_ALLOC_LAST_FIT
56 };
57
58 typedef enum
59 {
60 DOS_LOAD_AND_EXECUTE = 0x00,
61 DOS_LOAD_ONLY = 0x01,
62 DOS_LOAD_OVERLAY = 0x03
63 } DOS_EXEC_TYPE;
64
65 #pragma pack(push, 1)
66
67 typedef struct _DOS_MCB
68 {
69 CHAR BlockType;
70 WORD OwnerPsp;
71 WORD Size;
72 BYTE Unused[3];
73 CHAR Name[8];
74 } DOS_MCB, *PDOS_MCB;
75
76 typedef struct _DOS_FCB
77 {
78 BYTE DriveNumber;
79 CHAR FileName[8];
80 CHAR FileExt[3];
81 WORD BlockNumber;
82 WORD RecordSize;
83 DWORD FileSize;
84 WORD LastWriteDate;
85 WORD LastWriteTime;
86 BYTE Reserved[8];
87 BYTE BlockRecord;
88 BYTE RecordNumber[3];
89 } DOS_FCB, *PDOS_FCB;
90
91 typedef struct _DOS_PSP
92 {
93 BYTE Exit[2];
94 WORD LastParagraph;
95 BYTE Reserved0[6];
96 DWORD TerminateAddress;
97 DWORD BreakAddress;
98 DWORD CriticalAddress;
99 WORD ParentPsp;
100 BYTE HandleTable[20];
101 WORD EnvBlock;
102 DWORD LastStack;
103 WORD HandleTableSize;
104 DWORD HandleTablePtr;
105 DWORD PreviousPsp;
106 DWORD Reserved1;
107 WORD DosVersion;
108 BYTE Reserved2[14];
109 BYTE FarCall[3];
110 BYTE Reserved3[9];
111 DOS_FCB Fcb;
112 BYTE CommandLineSize;
113 CHAR CommandLine[DOS_CMDLINE_LENGTH];
114 } DOS_PSP, *PDOS_PSP;
115
116 typedef struct _DOS_INPUT_BUFFER
117 {
118 BYTE MaxLength;
119 BYTE Length;
120 CHAR Buffer[ANYSIZE_ARRAY];
121 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
122
123 typedef struct _DOS_DRIVER_HEADER
124 {
125 DWORD NextDriver;
126 WORD Attributes;
127 WORD StrategyEntry;
128 WORD InterruptEntry;
129 CHAR DeviceName[8];
130 } DOS_DRIVER_HEADER, *PDOS_DRIVER_HEADER;
131
132 typedef struct _DOS_FIND_FILE_BLOCK
133 {
134 CHAR DriveLetter;
135 CHAR Pattern[11];
136 UCHAR AttribMask;
137 DWORD Unused;
138 HANDLE SearchHandle;
139
140 /* The following part of the structure is documented */
141 UCHAR Attributes;
142 WORD FileTime;
143 WORD FileDate;
144 DWORD FileSize;
145 CHAR FileName[13];
146 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK;
147
148 typedef struct _DOS_EXEC_PARAM_BLOCK
149 {
150 /* Input variables */
151 WORD Environment;
152 DWORD CommandLine;
153 DWORD FirstFcb;
154 DWORD SecondFcb;
155
156 /* Output variables */
157 DWORD StackLocation;
158 DWORD EntryPoint;
159 } DOS_EXEC_PARAM_BLOCK, *PDOS_EXEC_PARAM_BLOCK;
160
161 #pragma pack(pop)
162
163 /* FUNCTIONS ******************************************************************/
164
165 extern CALLBACK16 DosContext;
166 #define RegisterDosInt32(IntNumber, IntHandler) \
167 do { \
168 DosContext.NextOffset += RegisterInt32(MAKELONG(DosContext.NextOffset, \
169 DosContext.Segment), \
170 (IntNumber), (IntHandler), NULL); \
171 } while(0);
172
173 /*
174 * DOS BIOS Functions
175 * See bios.c
176 */
177 CHAR DosReadCharacter(WORD FileHandle);
178 BOOLEAN DosCheckInput(VOID);
179 VOID DosPrintCharacter(WORD FileHandle, CHAR Character);
180
181 BOOLEAN DosBIOSInitialize(VOID);
182
183
184 /*
185 * DOS Kernel Functions
186 * See dos.c
187 */
188 BOOL IsConsoleHandle(HANDLE hHandle);
189 WORD DosOpenHandle(HANDLE Handle);
190 HANDLE DosGetRealHandle(WORD DosHandle);
191
192 WORD DosCreateFile(LPWORD Handle, LPCSTR FilePath, WORD Attributes);
193 WORD DosOpenFile(LPWORD Handle, LPCSTR FilePath, BYTE AccessMode);
194 WORD DosReadFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesRead);
195 WORD DosWriteFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesWritten);
196 WORD DosSeekFile(WORD FileHandle, LONG Offset, BYTE Origin, LPDWORD NewOffset);
197 BOOL DosFlushFileBuffers(WORD FileHandle);
198
199 VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WORD Environment);
200 DWORD DosLoadExecutable(
201 IN DOS_EXEC_TYPE LoadType,
202 IN LPCSTR ExecutablePath,
203 IN LPCSTR CommandLine,
204 IN PVOID Environment,
205 OUT PDWORD StackLocation OPTIONAL,
206 OUT PDWORD EntryPoint OPTIONAL
207 );
208 WORD DosCreateProcess(
209 DOS_EXEC_TYPE LoadType,
210 LPCSTR ProgramName,
211 PDOS_EXEC_PARAM_BLOCK Parameters
212 );
213 DWORD DosStartProcess(IN LPCSTR ExecutablePath,
214 IN LPCSTR CommandLine,
215 IN PVOID Environment);
216 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode);
217 BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
218
219 VOID WINAPI DosInt20h(LPWORD Stack);
220 VOID WINAPI DosInt21h(LPWORD Stack);
221 VOID WINAPI DosBreakInterrupt(LPWORD Stack);
222 VOID WINAPI DosInt2Fh(LPWORD Stack);
223
224 BOOLEAN DosKRNLInitialize(VOID);
225
226 #endif // _DOS_H_
227
228 /* EOF */