d82bb1a74c645ab6e714865f042ae8d718e201b9
[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 #pragma pack(push, 1)
57
58 typedef struct _DOS_MCB
59 {
60 CHAR BlockType;
61 WORD OwnerPsp;
62 WORD Size;
63 BYTE Unused[3];
64 CHAR Name[8];
65 } DOS_MCB, *PDOS_MCB;
66
67 typedef struct _DOS_FCB
68 {
69 BYTE DriveNumber;
70 CHAR FileName[8];
71 CHAR FileExt[3];
72 WORD BlockNumber;
73 WORD RecordSize;
74 DWORD FileSize;
75 WORD LastWriteDate;
76 WORD LastWriteTime;
77 BYTE Reserved[8];
78 BYTE BlockRecord;
79 BYTE RecordNumber[3];
80 } DOS_FCB, *PDOS_FCB;
81
82 typedef struct _DOS_PSP
83 {
84 BYTE Exit[2];
85 WORD LastParagraph;
86 BYTE Reserved0[6];
87 DWORD TerminateAddress;
88 DWORD BreakAddress;
89 DWORD CriticalAddress;
90 WORD ParentPsp;
91 BYTE HandleTable[20];
92 WORD EnvBlock;
93 DWORD LastStack;
94 WORD HandleTableSize;
95 DWORD HandleTablePtr;
96 DWORD PreviousPsp;
97 DWORD Reserved1;
98 WORD DosVersion;
99 BYTE Reserved2[14];
100 BYTE FarCall[3];
101 BYTE Reserved3[9];
102 DOS_FCB Fcb;
103 BYTE CommandLineSize;
104 CHAR CommandLine[DOS_CMDLINE_LENGTH];
105 } DOS_PSP, *PDOS_PSP;
106
107 typedef struct _DOS_INPUT_BUFFER
108 {
109 BYTE MaxLength;
110 BYTE Length;
111 CHAR Buffer[ANYSIZE_ARRAY];
112 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
113
114 typedef struct _DOS_DRIVER_HEADER
115 {
116 DWORD NextDriver;
117 WORD Attributes;
118 WORD StrategyEntry;
119 WORD InterruptEntry;
120 CHAR DeviceName[8];
121 } DOS_DRIVER_HEADER, *PDOS_DRIVER_HEADER;
122
123 typedef struct _DOS_FIND_FILE_BLOCK
124 {
125 CHAR DriveLetter;
126 CHAR Pattern[11];
127 UCHAR AttribMask;
128 DWORD Unused;
129 HANDLE SearchHandle;
130
131 /* The following part of the structure is documented */
132 UCHAR Attributes;
133 WORD FileTime;
134 WORD FileDate;
135 DWORD FileSize;
136 CHAR FileName[13];
137 } DOS_FIND_FILE_BLOCK, *PDOS_FIND_FILE_BLOCK;
138
139 #pragma pack(pop)
140
141 /* FUNCTIONS ******************************************************************/
142
143 extern CALLBACK16 DosContext;
144 #define RegisterDosInt32(IntNumber, IntHandler) \
145 do { \
146 DosContext.NextOffset += RegisterInt32(MAKELONG(DosContext.NextOffset, \
147 DosContext.Segment), \
148 (IntNumber), (IntHandler), NULL); \
149 } while(0);
150
151 /*
152 * DOS BIOS Functions
153 * See bios.c
154 */
155 CHAR DosReadCharacter(VOID);
156 BOOLEAN DosCheckInput(VOID);
157 VOID DosPrintCharacter(CHAR Character);
158
159 BOOLEAN DosBIOSInitialize(VOID);
160
161
162 /*
163 * DOS Kernel Functions
164 * See dos.c
165 */
166 BOOL IsConsoleHandle(HANDLE hHandle);
167 HANDLE DosGetRealHandle(WORD DosHandle);
168 WORD DosReadFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesRead);
169 WORD DosWriteFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesWritten);
170
171 VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WORD Environment);
172 BOOLEAN DosCreateProcess(LPCSTR CommandLine, WORD EnvBlock);
173 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode);
174 BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
175
176 VOID WINAPI DosInt20h(LPWORD Stack);
177 VOID WINAPI DosInt21h(LPWORD Stack);
178 VOID WINAPI DosBreakInterrupt(LPWORD Stack);
179 VOID WINAPI DosInt2Fh(LPWORD Stack);
180
181 BOOLEAN DosKRNLInitialize(VOID);
182
183 #endif // _DOS_H_
184
185 /* EOF */