18e0b14cd070ca3163118680f5e77dff874a400e
[reactos.git] / 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 0x8FFE
31 #define SYSTEM_PSP 0x08
32 #define SYSTEM_ENV_BLOCK 0x800
33 #define INVALID_DOS_HANDLE 0xFFFF
34 #define DOS_INPUT_HANDLE 0
35 #define DOS_OUTPUT_HANDLE 1
36 #define DOS_ERROR_HANDLE 2
37 #define DOS_SFT_SIZE 255
38 #define SEGMENT_TO_MCB(seg) ((PDOS_MCB)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
39 #define SEGMENT_TO_PSP(seg) ((PDOS_PSP)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
40 #define UMB_START_SEGMENT 0xC000
41 #define UMB_END_SEGMENT 0xDFFF
42 #define DOS_ALLOC_HIGH 0x40
43 #define DOS_ALLOC_HIGH_LOW 0x80
44 #define DOS_CMDLINE_LENGTH 127
45 #define DOS_DIR_LENGTH 64
46 #define NUM_DRIVES ('Z' - 'A' + 1)
47 #define DOS_CHAR_ATTRIBUTE 0x07
48
49 enum DOS_ALLOC_STRATEGY
50 {
51 DOS_ALLOC_FIRST_FIT,
52 DOS_ALLOC_BEST_FIT,
53 DOS_ALLOC_LAST_FIT
54 };
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 #pragma pack(push, 1)
64
65 typedef struct _DOS_MCB
66 {
67 CHAR BlockType;
68 WORD OwnerPsp;
69 WORD Size;
70 BYTE Unused[3];
71 CHAR Name[8];
72 } DOS_MCB, *PDOS_MCB;
73
74 typedef struct _DOS_FCB
75 {
76 BYTE DriveNumber;
77 CHAR FileName[8];
78 CHAR FileExt[3];
79 WORD BlockNumber;
80 WORD RecordSize;
81 DWORD FileSize;
82 WORD LastWriteDate;
83 WORD LastWriteTime;
84 BYTE Reserved[8];
85 BYTE BlockRecord;
86 BYTE RecordNumber[3];
87 } DOS_FCB, *PDOS_FCB;
88
89 typedef struct _DOS_PSP
90 {
91 BYTE Exit[2];
92 WORD LastParagraph;
93 BYTE Reserved0[6];
94 DWORD TerminateAddress;
95 DWORD BreakAddress;
96 DWORD CriticalAddress;
97 WORD ParentPsp;
98 BYTE HandleTable[20];
99 WORD EnvBlock;
100 DWORD LastStack;
101 WORD HandleTableSize;
102 DWORD HandleTablePtr;
103 DWORD PreviousPsp;
104 DWORD Reserved1;
105 WORD DosVersion;
106 BYTE Reserved2[14];
107 BYTE FarCall[3];
108 BYTE Reserved3[9];
109 DOS_FCB Fcb;
110 BYTE CommandLineSize;
111 CHAR CommandLine[DOS_CMDLINE_LENGTH];
112 } DOS_PSP, *PDOS_PSP;
113
114 typedef struct _DOS_INPUT_BUFFER
115 {
116 BYTE MaxLength;
117 BYTE Length;
118 CHAR Buffer[ANYSIZE_ARRAY];
119 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
120
121 typedef struct _DOS_DRIVER_HEADER
122 {
123 DWORD NextDriver;
124 WORD Attributes;
125 WORD StrategyEntry;
126 WORD InterruptEntry;
127 CHAR DeviceName[8];
128 } DOS_DRIVER_HEADER, *PDOS_DRIVER_HEADER;
129
130 typedef struct _DOS_FIND_FILE_BLOCK
131 {
132 CHAR DriveLetter;
133 CHAR Pattern[11];
134 UCHAR AttribMask;
135 DWORD Unused;
136 HANDLE SearchHandle;
137
138 /* The following part of the structure is documented */
139 UCHAR Attributes;
140 WORD FileTime;
141 WORD FileDate;
142 DWORD FileSize;
143 CHAR FileName[13];
144 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK;
145
146 typedef struct _DOS_EXEC_PARAM_BLOCK
147 {
148 /* Input variables */
149 WORD Environment;
150 DWORD CommandLine;
151 DWORD FirstFcb;
152 DWORD SecondFcb;
153
154 /* Output variables */
155 DWORD StackLocation;
156 DWORD EntryPoint;
157 } DOS_EXEC_PARAM_BLOCK, *PDOS_EXEC_PARAM_BLOCK;
158
159 #pragma pack(pop)
160
161 /* FUNCTIONS ******************************************************************/
162
163 extern CALLBACK16 DosContext;
164 #define RegisterDosInt32(IntNumber, IntHandler) \
165 do { \
166 DosContext.NextOffset += RegisterInt32(MAKELONG(DosContext.NextOffset, \
167 DosContext.Segment), \
168 (IntNumber), (IntHandler), NULL); \
169 } while(0);
170
171 /*
172 * DOS BIOS Functions
173 * See bios.c
174 */
175 CHAR DosReadCharacter(VOID);
176 BOOLEAN DosCheckInput(VOID);
177 VOID DosPrintCharacter(CHAR Character);
178
179 BOOLEAN DosBIOSInitialize(VOID);
180
181
182 /*
183 * DOS Kernel Functions
184 * See dos.c
185 */
186 BOOL IsConsoleHandle(HANDLE hHandle);
187 HANDLE DosGetRealHandle(WORD DosHandle);
188 WORD DosReadFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesRead);
189 WORD DosWriteFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesWritten);
190
191 VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WORD Environment);
192 DWORD DosLoadExecutable(
193 IN DOS_EXEC_TYPE LoadType,
194 IN LPCSTR ExecutablePath,
195 IN LPCSTR CommandLine,
196 IN PVOID Environment,
197 OUT PDWORD StackLocation OPTIONAL,
198 OUT PDWORD EntryPoint OPTIONAL
199 );
200 WORD DosCreateProcess(
201 DOS_EXEC_TYPE LoadType,
202 LPCSTR ProgramName,
203 PDOS_EXEC_PARAM_BLOCK Parameters
204 );
205 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode);
206 BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
207
208 VOID WINAPI DosInt20h(LPWORD Stack);
209 VOID WINAPI DosInt21h(LPWORD Stack);
210 VOID WINAPI DosBreakInterrupt(LPWORD Stack);
211 VOID WINAPI DosInt2Fh(LPWORD Stack);
212
213 BOOLEAN DosKRNLInitialize(VOID);
214
215 #endif // _DOS_H_
216
217 /* EOF */