1 | ; $Id: devfirst.asm,v 1.7 2001-02-21 07:44:15 bird Exp $
|
---|
2 | ;
|
---|
3 | ; DevFirst - entrypoint and segment definitions
|
---|
4 | ;
|
---|
5 | ; Copyright (c) 1999 knut st. osmundsen
|
---|
6 | ;
|
---|
7 | ; Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | ;
|
---|
9 | .386p
|
---|
10 |
|
---|
11 | ;
|
---|
12 | ; Include files
|
---|
13 | ;
|
---|
14 | include devsegdf.inc
|
---|
15 | include sas.inc
|
---|
16 |
|
---|
17 | ;
|
---|
18 | ; Exported symbols
|
---|
19 | ;
|
---|
20 | public CODE16START
|
---|
21 | public CODE16_INITSTART
|
---|
22 | public DATA16START
|
---|
23 | public DATA16START
|
---|
24 | public DATA16_BSSSTART
|
---|
25 | public DATA16_CONSTSTART
|
---|
26 | public DATA16_INITSTART
|
---|
27 | public CODE16START
|
---|
28 | public CODE32START
|
---|
29 | public DATA32START
|
---|
30 | public BSS32START
|
---|
31 | public CONST32_ROSTART
|
---|
32 | public _VFTSTART
|
---|
33 | public EH_DATASTART
|
---|
34 |
|
---|
35 |
|
---|
36 | public _strategyAsm0
|
---|
37 | public _strategyAsm1
|
---|
38 | public _CallGetKernelInfo32
|
---|
39 | public _CallElfIOCtl
|
---|
40 | public _CallWin32kIOCtl
|
---|
41 | public _SSToDS_16a
|
---|
42 | public GetOS2KrnlMTE
|
---|
43 | public x86DisableWriteProtect
|
---|
44 | public x86RestoreWriteProtect
|
---|
45 |
|
---|
46 |
|
---|
47 | ;
|
---|
48 | ; Externs
|
---|
49 | ;
|
---|
50 | extrn _TKSSBase16:dword
|
---|
51 | extrn GETKERNELINFO32:FAR
|
---|
52 | extrn ELFIOCTL:FAR
|
---|
53 | extrn WIN32KIOCTL:FAR
|
---|
54 | .286p
|
---|
55 | extrn _strategy:near
|
---|
56 |
|
---|
57 |
|
---|
58 | CODE16 segment
|
---|
59 | ASSUME CS:CODE16, DS:DATA16, ES:NOTHING, SS:NOTHING
|
---|
60 |
|
---|
61 | CODE16START label byte
|
---|
62 |
|
---|
63 | .286p
|
---|
64 | ;$win32ki entry point
|
---|
65 | _strategyAsm0:
|
---|
66 | ; int 3
|
---|
67 | push 0
|
---|
68 | jmp _strategyAsm
|
---|
69 |
|
---|
70 | ;$win32k entry point
|
---|
71 | _strategyAsm1:
|
---|
72 | ; int 3
|
---|
73 | push 1
|
---|
74 | jmp _strategyAsm
|
---|
75 |
|
---|
76 | ;;
|
---|
77 | ; Stub which pushes parameters onto the stack and call the 16-bit C strategy routine.
|
---|
78 | ; @returns returns the return value of strategy(...)
|
---|
79 | ; @author knut st. osmundsen
|
---|
80 | _strategyAsm proc far
|
---|
81 | push es
|
---|
82 | push bx
|
---|
83 | push ds
|
---|
84 | pop es
|
---|
85 | call _strategy
|
---|
86 | pop bx
|
---|
87 | pop es
|
---|
88 | mov word ptr es:[bx+3], ax
|
---|
89 | add sp, 2
|
---|
90 | retf
|
---|
91 | _strategyAsm endp
|
---|
92 |
|
---|
93 |
|
---|
94 | .386p
|
---|
95 | ;;
|
---|
96 | ; Thunk procedure for R0Init32.
|
---|
97 | ; @cproto USHORT NEAR CallGetKernelInfo32(ULONG addressKrnlInfoBuf);
|
---|
98 | ; @returns Same as GetKernelInfo32.
|
---|
99 | ; @param addressKrnlInfoBuf 32-bit pointer to request data on stack.
|
---|
100 | ; @status completely implemented.
|
---|
101 | ; @author knut st. osmundsen
|
---|
102 | _CallGetKernelInfo32 PROC NEAR
|
---|
103 | ASSUME CS:CODE16
|
---|
104 | push ds
|
---|
105 | push word ptr [esp+6] ; push high word.
|
---|
106 | push word ptr [esp+6] ; push low word.
|
---|
107 | call far ptr FLAT:GETKERNELINFO32
|
---|
108 | pop ds
|
---|
109 | ret
|
---|
110 | _CallGetKernelInfo32 ENDP
|
---|
111 |
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 | ;;
|
---|
116 | ; Thunk procedure for .
|
---|
117 | ; @cproto USHORT NEAR CallElfIOCtl(void);
|
---|
118 | ; @returns Same as ElfIOCtl
|
---|
119 | ; @param address of IOCtl request packet (32-bit pointer).
|
---|
120 | ; @status completely implemented.
|
---|
121 | ; @author knut st. osmundsen
|
---|
122 | _CallElfIOCtl PROC NEAR
|
---|
123 | ASSUME CS:CODE16
|
---|
124 | push ds
|
---|
125 | push word ptr [esp+6] ; push high word.
|
---|
126 | push word ptr [esp+6] ; push low word.
|
---|
127 | call far ptr FLAT:ELFIOCTL
|
---|
128 | pop ds
|
---|
129 | retn
|
---|
130 | _CallElfIOCtl ENDP
|
---|
131 |
|
---|
132 | ;;
|
---|
133 | ; Thunk procedure for .
|
---|
134 | ; @cproto USHORT NEAR CallWin32kIOCtl(void);
|
---|
135 | ; @returns Same as Win32kIOCtl
|
---|
136 | ; @param address of IOCtl request packet (32-bit pointer).
|
---|
137 | ; @status completely implemented.
|
---|
138 | ; @author knut st. osmundsen
|
---|
139 | _CallWin32kIOCtl PROC NEAR
|
---|
140 | ASSUME CS:CODE16
|
---|
141 | push ds
|
---|
142 | push word ptr [esp+6] ; push high word.
|
---|
143 | push word ptr [esp+6] ; push low word.
|
---|
144 | call far ptr FLAT:WIN32KIOCTL
|
---|
145 | pop ds
|
---|
146 | retn
|
---|
147 | _CallWin32kIOCtl ENDP
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | ;;
|
---|
152 | ; SSToDS - stack pointer to Flat pointer.
|
---|
153 | ; @cproto extern LIN SSToDS_16a(void NEAR *pStackVar);
|
---|
154 | ; @returns ax:dx makes up a 32-bit flat pointer to stack.
|
---|
155 | ; @param pStackVar Stack pointer which is to be made a flat pointer.
|
---|
156 | ; @equiv SSToDS in 32-bit code.
|
---|
157 | ; @sketch Get Flat CS
|
---|
158 | ; Get TKSSBase address. (FLAT)
|
---|
159 | ; return *TKSSBase + pStackVar.
|
---|
160 | ; @status completely implemented.
|
---|
161 | ; @author knut st. osmundsen
|
---|
162 | ; @remark es is cs, not ds!
|
---|
163 | _SSToDS_16a proc NEAR
|
---|
164 | assume CS:CODE16, DS:DATA16, ES:NOTHING
|
---|
165 | mov edx, ds:_TKSSBase16 ; get pointer held by _TKSSBase16 (pointer to stack base)
|
---|
166 | call far ptr FLAT:far_getCS ; get flat selector.
|
---|
167 | push es
|
---|
168 | mov es, ax
|
---|
169 | assume es:FLAT
|
---|
170 | mov eax, es:[edx] ; get pointer to stack base
|
---|
171 | pop es
|
---|
172 | movzx edx, word ptr ss:[esp + 2] ; 16-bit stack pointer (parameter)
|
---|
173 | add eax, edx ; 32-bit stack pointer in eax
|
---|
174 | mov edx, eax
|
---|
175 | shr edx, 16 ; dx high 16-bit of 32-bit stack pointer.
|
---|
176 | retn
|
---|
177 | _SSToDS_16a endp
|
---|
178 |
|
---|
179 | CODE16 ends
|
---|
180 |
|
---|
181 |
|
---|
182 | ;
|
---|
183 | ; all segments have a <segmentname>START label at the start of the segment.
|
---|
184 | ;
|
---|
185 |
|
---|
186 | CODE32 segment
|
---|
187 | CODE32START label byte
|
---|
188 |
|
---|
189 | ;;
|
---|
190 | ; Gets the current cs.
|
---|
191 | ; @cproto none.
|
---|
192 | ; @returns CS
|
---|
193 | ; @author knut st. osmundsen
|
---|
194 | ; @remark internal method. called from 16-bit code...
|
---|
195 | far_getCS proc far
|
---|
196 | ASSUME DS:nothing, ES:nothing
|
---|
197 | mov ax, cs
|
---|
198 | retf
|
---|
199 | far_getCS endp
|
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 | ;;
|
---|
204 | ; Gets the a 32-bit flat pointer to the OS/2 Kernel MTE.
|
---|
205 | ; @cproto extern PMTE _System GetOS2KrnlMTE(void);
|
---|
206 | ; @returns Pointer to kernel MTE.
|
---|
207 | ; @status completely implemented.
|
---|
208 | ; @author knut st. osmundsen
|
---|
209 | GetOS2KrnlMTE PROC NEAR
|
---|
210 | push es
|
---|
211 |
|
---|
212 | mov ax, SAS_selector ;70h - Read-only SAS selector.
|
---|
213 | mov es, ax
|
---|
214 | xor ebx, ebx
|
---|
215 | assume ebx: PTR SAS
|
---|
216 | mov bx, es:[ebx].SAS_vm_data ;SAS_vm_data (0ch)
|
---|
217 | assume ebx: PTR SAS_vm_section
|
---|
218 | mov eax, es:[ebx].SAS_vm_krnl_mte ;SAS_vm_krnl_mte (0ch)
|
---|
219 |
|
---|
220 | pop es
|
---|
221 | ret
|
---|
222 | GetOS2KrnlMTE ENDP
|
---|
223 |
|
---|
224 |
|
---|
225 | ;;
|
---|
226 | ; Disables the ring-0 write protection.
|
---|
227 | ; It's used to help us write to readonly code segments and objects.
|
---|
228 | ; @cproto extern ULONG _Optlink x86DisableWriteProtect(void);
|
---|
229 | ; @return Previous write protection flag setting.
|
---|
230 | ; @uses eax, edx
|
---|
231 | ; @status completely implemented.
|
---|
232 | ; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
233 | ; @remark Used by importTabInit.
|
---|
234 | x86DisableWriteProtect proc near
|
---|
235 | cli
|
---|
236 | mov edx, cr0 ; Get current cr0
|
---|
237 | test edx, 000010000h ; Test for the WriteProtect flag (bit 16)
|
---|
238 | setnz al
|
---|
239 | movzx eax, al ; Old flag setting in eax (return value)
|
---|
240 | and edx, 0fffeffffh ; Clear the 16th (WP) bit.
|
---|
241 | mov cr0, edx ;
|
---|
242 | sti
|
---|
243 | ret ; return eax holds previous WP value.
|
---|
244 | x86DisableWriteProtect endp
|
---|
245 |
|
---|
246 |
|
---|
247 | ;;
|
---|
248 | ; Restore the WP flag of CR0 to it's previous state.
|
---|
249 | ; The call is intent only to be called with the result from x86DisableWriteProtect,
|
---|
250 | ; and will hence only enable the WP flag.
|
---|
251 | ; @cproto extern ULONG _Optlink x86RestoreWriteProtect(ULONG flWP);
|
---|
252 | ; @return Previous write protection flag setting.
|
---|
253 | ; @param eax - flWP Boolean value. (1 = WP was set, 0 WP was clear)
|
---|
254 | ; @uses eax
|
---|
255 | ; @status completely implemented.
|
---|
256 | ; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
257 | ; @remark Used by importTabInit.
|
---|
258 | x86RestoreWriteProtect proc near
|
---|
259 | test eax, eax ; Check if the flag was previously clear
|
---|
260 | jnz x86RWP_set ; If set Then Set it back.
|
---|
261 | jmp x86RWP_end ; If clear Then nothing to do.
|
---|
262 | x86RWP_set:
|
---|
263 | cli
|
---|
264 | mov eax, cr0 ; Get current cr0.
|
---|
265 | or eax, 000010000h ; The the 16-bit (WP) bit.
|
---|
266 | mov cr0, eax ; Update cr0.
|
---|
267 | sti
|
---|
268 |
|
---|
269 | x86RWP_end:
|
---|
270 | ret
|
---|
271 | x86RestoreWriteProtect endp
|
---|
272 |
|
---|
273 |
|
---|
274 | CODE32 ends
|
---|
275 |
|
---|
276 | CODE16_INIT segment
|
---|
277 | CODE16_INITSTART label byte
|
---|
278 | CODE16_INIT ends
|
---|
279 |
|
---|
280 | DATA16 segment
|
---|
281 | DATA16START label byte
|
---|
282 | DATA16 ends
|
---|
283 |
|
---|
284 | DATA16_BSS segment
|
---|
285 | DATA16_BSSSTART label byte
|
---|
286 | DATA16_BSS ends
|
---|
287 |
|
---|
288 | DATA16_CONST segment
|
---|
289 | DATA16_CONSTSTART label byte
|
---|
290 | DATA16_CONST ends
|
---|
291 |
|
---|
292 | DATA16_INIT segment
|
---|
293 | DATA16_INITSTART label byte
|
---|
294 | DATA16_INIT ends
|
---|
295 |
|
---|
296 | DATA32 segment
|
---|
297 | DATA32START label byte
|
---|
298 | DATA32 ends
|
---|
299 |
|
---|
300 | BSS32 segment
|
---|
301 | BSS32START label byte
|
---|
302 | BSS32 ends
|
---|
303 |
|
---|
304 | CONST32_RO segment
|
---|
305 | CONST32_ROSTART label byte
|
---|
306 | CONST32_RO ends
|
---|
307 |
|
---|
308 | _VFT segment
|
---|
309 | _VFTSTART LABEL BYTE
|
---|
310 | _VFT ends
|
---|
311 |
|
---|
312 | EH_DATA segment
|
---|
313 | EH_DATASTART LABEL BYTE
|
---|
314 | EH_DATA ends
|
---|
315 |
|
---|
316 | END
|
---|
317 |
|
---|