source: trunk/src/win32k/dev32/devfirst.asm@ 5220

Last change on this file since 5220 was 5220, checked in by bird, 25 years ago

Added x86 functions for clearing and restoring the WP flag in CR0.

File size: 7.8 KB
Line 
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
58CODE16 segment
59 ASSUME CS:CODE16, DS:DATA16, ES:NOTHING, SS:NOTHING
60
61CODE16START 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
179CODE16 ends
180
181
182;
183; all segments have a <segmentname>START label at the start of the segment.
184;
185
186CODE32 segment
187CODE32START 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...
195far_getCS proc far
196 ASSUME DS:nothing, ES:nothing
197 mov ax, cs
198 retf
199far_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
209GetOS2KrnlMTE 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
222GetOS2KrnlMTE 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.
234x86DisableWriteProtect 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.
244x86DisableWriteProtect 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.
258x86RestoreWriteProtect 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.
262x86RWP_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
269x86RWP_end:
270 ret
271x86RestoreWriteProtect endp
272
273
274CODE32 ends
275
276CODE16_INIT segment
277CODE16_INITSTART label byte
278CODE16_INIT ends
279
280DATA16 segment
281DATA16START label byte
282DATA16 ends
283
284DATA16_BSS segment
285DATA16_BSSSTART label byte
286DATA16_BSS ends
287
288DATA16_CONST segment
289DATA16_CONSTSTART label byte
290DATA16_CONST ends
291
292DATA16_INIT segment
293DATA16_INITSTART label byte
294DATA16_INIT ends
295
296DATA32 segment
297DATA32START label byte
298DATA32 ends
299
300BSS32 segment
301BSS32START label byte
302BSS32 ends
303
304CONST32_RO segment
305CONST32_ROSTART label byte
306CONST32_RO ends
307
308_VFT segment
309_VFTSTART LABEL BYTE
310_VFT ends
311
312EH_DATA segment
313EH_DATASTART LABEL BYTE
314EH_DATA ends
315
316END
317
Note: See TracBrowser for help on using the repository browser.