1 | ; $Id: startup.inc,v 1.1.1.1 2003/07/02 13:56:56 eleph Exp $
|
---|
2 | ;*
|
---|
3 | ;* Assembly macro and constant definitions
|
---|
4 | ;*
|
---|
5 | ;* (C) 2000-2002 InnoTek Systemberatung GmbH
|
---|
6 | ;* (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | ;*
|
---|
8 | ;* This program is free software; you can redistribute it and/or
|
---|
9 | ;* modify it under the terms of the GNU General Public License as
|
---|
10 | ;* published by the Free Software Foundation; either version 2 of
|
---|
11 | ;* the License, or (at your option) any later version.
|
---|
12 | ;*
|
---|
13 | ;* This program is distributed in the hope that it will be useful,
|
---|
14 | ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | ;* GNU General Public License for more details.
|
---|
17 | ;*
|
---|
18 | ;* You should have received a copy of the GNU General Public
|
---|
19 | ;* License along with this program; if not, write to the Free
|
---|
20 | ;* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
---|
21 | ;* USA.
|
---|
22 | ;*
|
---|
23 |
|
---|
24 |
|
---|
25 | ; MACRO'S
|
---|
26 | ;*******************************************************************************
|
---|
27 | ;enter a 16:32 far function
|
---|
28 | ;*******************************************************************************
|
---|
29 | enter32 MACRO
|
---|
30 | push bp
|
---|
31 | mov bp, sp
|
---|
32 | push ds
|
---|
33 | mov ax, DATA16
|
---|
34 | mov ds, ax
|
---|
35 | ENDM
|
---|
36 | ;*******************************************************************************
|
---|
37 | ;return to 16:32 far caller
|
---|
38 | ;*******************************************************************************
|
---|
39 | ret32 MACRO
|
---|
40 | pop ds
|
---|
41 | pop bp
|
---|
42 | db 66h ; Force next instruction 32-bit
|
---|
43 | ret
|
---|
44 | ENDM
|
---|
45 |
|
---|
46 | enter16 MACRO
|
---|
47 | push bp
|
---|
48 | mov bp, sp
|
---|
49 | ENDM
|
---|
50 | ret16 MACRO
|
---|
51 | pop bp
|
---|
52 | ret
|
---|
53 | ENDM
|
---|
54 |
|
---|
55 |
|
---|
56 | IFDEF KEE
|
---|
57 | ;pushfd/popfd trashed by fucking BUGY KernThunkStackTo32
|
---|
58 | ;fix idea by zuko
|
---|
59 |
|
---|
60 | ;;******************************************************************************
|
---|
61 | ;;Need to preserve fs:ebx!! (all other registers must be saved by the caller)
|
---|
62 | ;;******************************************************************************
|
---|
63 | DevThunkStackTo32 MACRO
|
---|
64 | push stacksel
|
---|
65 | push stackbase
|
---|
66 |
|
---|
67 | push edx
|
---|
68 | mov edx, ss
|
---|
69 | mov stacksel, edx
|
---|
70 | pushfd
|
---|
71 |
|
---|
72 | call KernThunkStackTo32
|
---|
73 | popfd
|
---|
74 | mov stackbase, edx
|
---|
75 | pop edx ;trashed by KernThunkStackTo32
|
---|
76 | xor eax, eax ; mark success
|
---|
77 | ENDM
|
---|
78 | ;;******************************************************************************
|
---|
79 | ;;******************************************************************************
|
---|
80 | DevThunkStackTo32_Int MACRO
|
---|
81 | push eax
|
---|
82 | push edx
|
---|
83 | pushfd
|
---|
84 | call KernThunkStackTo32
|
---|
85 | popfd
|
---|
86 | pop edx ;trashed by KernThunkStackTo32
|
---|
87 | pop eax ;trashed by KernThunkStackTo32
|
---|
88 | ENDM
|
---|
89 | ;;******************************************************************************
|
---|
90 | ;;******************************************************************************
|
---|
91 | DevThunkStackTo16 MACRO
|
---|
92 | push edx
|
---|
93 | push eax
|
---|
94 | pushfd
|
---|
95 | call KernThunkStackTo16
|
---|
96 | popfd
|
---|
97 | pop eax ;trashed by KernThunkStackTo16
|
---|
98 | pop edx ;trashed by KernThunkStackTo16 when called in interrupt context
|
---|
99 |
|
---|
100 | pop stackbase
|
---|
101 | pop stacksel
|
---|
102 | ENDM
|
---|
103 |
|
---|
104 | ;;******************************************************************************
|
---|
105 | ;;******************************************************************************
|
---|
106 | DevThunkStackTo16_Int MACRO
|
---|
107 | push edx
|
---|
108 | push eax
|
---|
109 | pushfd
|
---|
110 | call KernThunkStackTo16
|
---|
111 | popfd
|
---|
112 | pop eax ;trashed by KernThunkStackTo16
|
---|
113 | pop edx ;trashed by KernThunkStackTo16 when called in interrupt context
|
---|
114 | ENDM
|
---|
115 | ;;******************************************************************************
|
---|
116 | ;;******************************************************************************
|
---|
117 |
|
---|
118 | ELSE
|
---|
119 |
|
---|
120 | ;;******************************************************************************
|
---|
121 | ;;Need to preserve fs:ebx!! (all other registers must be saved by the caller)
|
---|
122 | ;;******************************************************************************
|
---|
123 | DevThunkStackTo32 MACRO
|
---|
124 | LOCAL @@stackok, @@stackchangeend
|
---|
125 |
|
---|
126 | ;;;; int 3
|
---|
127 |
|
---|
128 | pushfd
|
---|
129 | cli
|
---|
130 | pop dword ptr [cpuflags]
|
---|
131 |
|
---|
132 | ;check if kernel DS selector DPL == 3; if so, change to 0
|
---|
133 | call FixSelDPL
|
---|
134 |
|
---|
135 | ;allocate private stack
|
---|
136 | push fs
|
---|
137 | call StackAlloc
|
---|
138 | pop fs ;trashed by StackAlloc
|
---|
139 | mov dword ptr [fInitStack], 1
|
---|
140 |
|
---|
141 | cmp eax, 0
|
---|
142 | jne @@stackok
|
---|
143 |
|
---|
144 | IFDEF DEBUG
|
---|
145 | int 3 ;this is very fatal
|
---|
146 | ENDIF
|
---|
147 | call RestoreSelDPL
|
---|
148 | mov eax, -1 ;mark failure
|
---|
149 |
|
---|
150 | push dword ptr [cpuflags]
|
---|
151 | popfd
|
---|
152 | jmp short @@stackchangeend
|
---|
153 |
|
---|
154 | @@stackok:
|
---|
155 | ;stack ptr in eax
|
---|
156 | call dword ptr [intSwitchStack]
|
---|
157 |
|
---|
158 | push dword ptr [cpuflags]
|
---|
159 | popfd
|
---|
160 |
|
---|
161 | mov eax, 0 ;mark success
|
---|
162 | @@stackchangeend:
|
---|
163 | ENDM
|
---|
164 |
|
---|
165 | ;;******************************************************************************
|
---|
166 | ;;******************************************************************************
|
---|
167 | DevThunkStackTo32_Int MACRO
|
---|
168 | LOCAL @@cont32
|
---|
169 |
|
---|
170 | cmp dword ptr [fInitStack], 0
|
---|
171 | je @@cont32
|
---|
172 |
|
---|
173 | ;;;; int 3
|
---|
174 | pushfd
|
---|
175 | cli
|
---|
176 | pop dword ptr [cpuflags]
|
---|
177 |
|
---|
178 | mov dword ptr [tempeax], eax ;save eax
|
---|
179 |
|
---|
180 | pop eax ;pop saved flat stack pointer
|
---|
181 |
|
---|
182 | ;and switch back to our flat stack again
|
---|
183 | call dword ptr [intSwitchStack]
|
---|
184 |
|
---|
185 | mov eax, dword ptr [tempeax] ;restore eax
|
---|
186 | push dword ptr [cpuflags]
|
---|
187 | popfd
|
---|
188 |
|
---|
189 | @@cont32:
|
---|
190 | ENDM
|
---|
191 |
|
---|
192 | ;;******************************************************************************
|
---|
193 | ;;******************************************************************************
|
---|
194 | DevThunkStackTo16 MACRO
|
---|
195 | ;;;; int 3
|
---|
196 |
|
---|
197 | pushfd
|
---|
198 | cli
|
---|
199 | pop dword ptr [cpuflags]
|
---|
200 |
|
---|
201 | mov dword ptr [tempeax], eax ;save eax
|
---|
202 | mov dword ptr [tempesi], esi ;save esi
|
---|
203 |
|
---|
204 | mov esi, esp
|
---|
205 | xor eax, eax ;switch to 16 bits stack
|
---|
206 | call dword ptr [intSwitchStack]
|
---|
207 |
|
---|
208 | mov eax, esi
|
---|
209 | call StackFree
|
---|
210 |
|
---|
211 | call RestoreSelDPL
|
---|
212 |
|
---|
213 | mov eax, dword ptr [tempeax]
|
---|
214 | mov esi, dword ptr [tempesi]
|
---|
215 |
|
---|
216 | push dword ptr [cpuflags]
|
---|
217 | popfd
|
---|
218 |
|
---|
219 | ENDM
|
---|
220 |
|
---|
221 | ;;******************************************************************************
|
---|
222 | ;;******************************************************************************
|
---|
223 | DevThunkStackTo16_Int MACRO
|
---|
224 | LOCAL @@cont16
|
---|
225 |
|
---|
226 | cmp dword ptr [fInitStack], 0
|
---|
227 | je @@cont16
|
---|
228 |
|
---|
229 | ;;;; int 3
|
---|
230 | pushfd
|
---|
231 | cli
|
---|
232 | pop dword ptr [cpuflags]
|
---|
233 |
|
---|
234 | mov dword ptr [tempeax], eax ;save eax
|
---|
235 | mov dword ptr [tempesi], esi ;save esi
|
---|
236 | mov esi, esp
|
---|
237 | xor eax, eax ;switch to 16 bits stack
|
---|
238 | call dword ptr [intSwitchStack]
|
---|
239 | push esi ;flat stack ptr (popped before switching back to flat)
|
---|
240 |
|
---|
241 | mov eax, dword ptr [tempeax]
|
---|
242 | mov esi, dword ptr [tempesi]
|
---|
243 | push dword ptr [cpuflags]
|
---|
244 | popfd
|
---|
245 |
|
---|
246 | @@cont16:
|
---|
247 | ENDM
|
---|
248 |
|
---|
249 | ENDIF ;KEE
|
---|
250 |
|
---|
251 | IFDEF FLATSTACK
|
---|
252 | ;*******************************************************************************
|
---|
253 | ;enter a function that needs to switch to a 16 bits stack
|
---|
254 | ;*******************************************************************************
|
---|
255 | enterKEERM MACRO
|
---|
256 | push ebp
|
---|
257 | mov ebp, esp
|
---|
258 | push ds
|
---|
259 | push es
|
---|
260 | push ebx
|
---|
261 | push ecx
|
---|
262 | push edx
|
---|
263 | push esi
|
---|
264 | push edi
|
---|
265 |
|
---|
266 | ;to access the parameters on the 32 bits stack, once we've switched
|
---|
267 | mov edi, ebp
|
---|
268 |
|
---|
269 | DevThunkStackTo16_Int
|
---|
270 | ENDM
|
---|
271 | ;*******************************************************************************
|
---|
272 | ;switch stack from 16 bits to 32 bits and return
|
---|
273 | ;*******************************************************************************
|
---|
274 | retKEERM MACRO
|
---|
275 | DevThunkStackTo32_Int
|
---|
276 | pop edi
|
---|
277 | pop esi
|
---|
278 | pop edx
|
---|
279 | pop ecx
|
---|
280 | pop ebx
|
---|
281 | pop es
|
---|
282 | pop ds
|
---|
283 | pop ebp
|
---|
284 | ret
|
---|
285 | ENDM
|
---|
286 |
|
---|
287 | ;;******************************************************************************
|
---|
288 | ;;******************************************************************************
|
---|
289 |
|
---|
290 | ENDIF
|
---|
291 |
|
---|
292 | ;Constants and structure definitions
|
---|
293 |
|
---|
294 | DevHlp_VirtToLin EQU 5Bh
|
---|
295 | DevHlp_VMLock EQU 55h
|
---|
296 |
|
---|
297 | ; Status word masks
|
---|
298 | STERR EQU 8000H ; Bit 15 - Error
|
---|
299 | STINTER EQU 0400H ; Bit 10 - Interim character
|
---|
300 | STBUI EQU 0200H ; Bit 9 - Busy
|
---|
301 | STDON EQU 0100H ; Bit 8 - Done
|
---|
302 | STECODE EQU 00FFH ; Error code
|
---|
303 |
|
---|
304 | ; Definition of the request packet header.
|
---|
305 |
|
---|
306 | reqPacket struc
|
---|
307 | reqLenght db ?
|
---|
308 | reqUnit db ?
|
---|
309 | reqCommand db ?
|
---|
310 | reqStatus dw ?
|
---|
311 | reqFlags db ?
|
---|
312 | db 3 dup (?) ; Reserved field
|
---|
313 | reqLink dd ?
|
---|
314 | reqPacket ends
|
---|
315 |
|
---|
316 | rpInitIn struc
|
---|
317 | i_rph db size reqPacket dup (?)
|
---|
318 | i_unit db ?
|
---|
319 | i_devHelp dd ?
|
---|
320 | i_initArgs dd ?
|
---|
321 | i_driveNum db ?
|
---|
322 | rpInitIn ends
|
---|
323 |
|
---|
324 | rpInitOut struc
|
---|
325 | o_rph db size reqPacket dup (?)
|
---|
326 | o_unit db ?
|
---|
327 | o_codeend dw ?
|
---|
328 | o_dataend dw ?
|
---|
329 | o_bpbarray dd ?
|
---|
330 | o_status dw ?
|
---|
331 | rpInitOut ends
|
---|
332 |
|
---|
333 |
|
---|
334 | ; definitions for 16 bits resource manager buffers
|
---|
335 | ; (also in rm.hpp!!)
|
---|
336 | MAXSIZE_RMNodeData EQU 1024
|
---|
337 | MAXSIZE_RMResources EQU 128
|
---|
338 | MAXSIZE_RMHandleList EQU 128
|
---|
339 | MAXSIZE_RMResourceList EQU 256
|
---|