source: trunk/tools/profilerfix/cppopa3_fix2.asm@ 8233

Last change on this file since 8233 was 8233, checked in by bird, 23 years ago

Warning.

File size: 5.4 KB
Line 
1; $Id: cppopa3_fix2.asm,v 1.2 2002-04-11 19:56:23 bird Exp $
2;
3; Fix for the DosLoadModule traps in debugee
4; during tracing init.
5;
6;
7; NOTE!!! Currently the address of the doscall1 init proc is
8; HARDCODED.
9;
10;
11; Copyright (c) 2002 knut st. osmundsen (bird@anduin.net)
12;
13; Project Odin Software License can be found in LICENSE.TXT
14;
15
16 .386
17 .model flat
18
19;
20; Defined Constants And Macros
21;
22 large equ
23
24 SEL_FLATMASK equ 01fff0000h
25 SEL_FLAT_SHIFT equ 0dh
26 SEL_LDT_RPL3 equ 07h
27
28;
29; Public symbols
30;
31 public prfLoadModule
32 public fDosCallnited
33
34
35;
36; Externs
37;
38 extrn Dos32LoadModule:PROC
39 extrn DOS16LOADMODULE:far
40
41
42;
43; declare 16-bit data segment..
44;
45CODE16 segment word public 'CODE' use16
46aDoscall1 db 'DOSCALL1',0
47CODE16 ends
48
49
50;
51; 32-bit data segment
52;
53DATA32 segment dword public use32
54 fDosCallnited dd 0
55DATA32 ends
56
57
58;
59; 32-bit code segement.
60;
61CODE32 segment dword public 'CODE' use32
62 assume cs:CODE32
63 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
64
65
66;;
67; Thunks the stack from 16-bits to 32-bits.
68; !The stack has to be 16-bits on entry!
69; @cproto VOID _Optlink ThunkStack16To32(VOID)
70; @returns void
71; Stack is 32-bits!
72; EBP and SS:ESP is thunked
73;
74; @uses EAX, EDX
75; @sketch
76; @status completly implemented.
77; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
78; @remark RING 3 only.
79ThunkStack16To32 PROC NEAR
80 ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
81 movzx esp, sp ; Make sure high end of esp is zero.
82 mov ax, ss ; Find the linary base of the segment addressed by ss.
83 shl eax, SEL_FLAT_SHIFT
84 and eax, SEL_FLATMASK
85 mov ax, sp ; Add the segment offset, which is sp.
86 ; eax is now the linear stack address equal to ss:sp.
87
88 mov dx, seg FLAT:DATA32 ; ALP bug? Can't: push seg FLAT:DATA32
89 ; Have to move it to dx before pushing it.
90 push dx ; Make lss quad word: new ss, new esp
91 push eax
92 lss esp, ss:[esp] ; load new ss and esp values.
93
94 ;
95 ; Fix ebp
96 ; Creates new ebp from high word of esp and low word of ebp.
97 ;
98 mov eax, esp
99 mov ax, bp
100 mov ebp, eax
101
102 ret
103ThunkStack16To32 ENDP
104
105
106;;
107; Thunks the stack from 32-bits to 16-bits.
108; !The stack has to be 32-bits on entry!
109; @cproto VOID _Optlink ThunkStack32To16(VOID)
110; @returns void
111; Stack is 16-bits!
112; EBP and SS:ESP is thunked
113;
114; @uses EAX
115; @sketch
116; @status completly implemented.
117; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
118; @remark RING 3 only.
119ThunkStack32To16 PROC NEAR
120 ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
121
122 ;
123 ; calc LDT selector from linear esp and load new ss:esp.
124 ;
125 mov eax, esp
126 shr eax, SEL_FLAT_SHIFT
127 or ax, SEL_LDT_RPL3 ; ax new ss LDT (RING3).
128 rol eax, 16
129 mov ax, sp
130 push eax
131 lss sp, dword ptr [esp] ; load ss:sp.
132 movzx esp, sp ; Zero upper part of esp.
133 ; Stack is now 16 bits
134 ;
135 ; Fix ebp
136 ;
137 movzx ebp, bp ; Zero upper part of ebp.
138
139 ret
140ThunkStack32To16 ENDP
141
142
143;;
144; APIRET APIENTRY DosLoadModule(PCSZ pszName, ebp +008h
145; ULONG cbName, ebp +00ch
146; PCSZ pszModname, ebp +010h
147; PHMODULE phmod); epb +014h
148prfLoadModule proc near
149 ASSUME ss:NOTHING, ds:FLAT, cs:CODE32
150
151 ;
152 ; Only first tim!
153 ;
154 test fDosCallnited, 0ffh
155 jnz Dos32LoadModule
156 mov fDosCallnited, 0ffh
157
158 ;
159 ; Save registers
160 ;
161 push ebx
162 push ecx
163 push edx
164 push esi
165 push edi
166 push ebp
167
168 ;
169 ; Make stack 16-bit.
170 ;
171 call ThunkStack32To16
172
173
174 ;
175 ; Load DosCall1.DLL. ie. get handle and setup callstack for init.
176 ;
177 jmp far ptr CODE16:prfLoadDosCall1DLL_Thunk16
178CODE32 ends
179CODE16 segment word public 'CODE' use16
180prfLoadDosCall1DLL_Thunk16::
181 ASSUME ss:NOTHING, ds:FLAT, cs:CODE16
182 ;
183 ; Load DosCall1.
184 ;
185 push 0 ; init flag
186 push 0
187
188 push 0 ; handle
189 push 0
190 mov ax, sp
191
192 push 0 ; fail seg
193 push 0 ; fail off
194 push 0 ; fail len
195
196 push cs
197 push offset CODE16:aDoscall1 ; module name.
198
199 push ss
200 push ax ; handle
201 call far ptr DOS16LOADMODULE
202CODE16 ends
203CODE32 segment
204prfLoadDosCall1DLL_Thunk32::
205 mov eax, 01c0209d0h ; hardcoded for now.
206 call dword ptr eax
207 add esp, 08h
208
209
210 ;
211 ; Make stack 32-bit.
212 ;
213 call ThunkStack16To32
214
215 ;
216 ; Restore registers.
217 ;
218 pop ebp
219 pop edi
220 pop esi
221 pop edx
222 pop ecx
223 pop ebx
224 jmp Dos32LoadModule
225prfLoadModule endp
226
227CODE32 ends
228
229;
230; 16-bit code segement.
231;
232CODE16 segment
233 jmp far ptr FLAT:prfLoadDosCall1DLL_Thunk32
234CODE16 ends
235
236 end
Note: See TracBrowser for help on using the repository browser.