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

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

Initial hacking, hardcoded doscall1.dll init.

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