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