win16thk.asm
来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 342 行 · 第 1/2 页
ASM
342 行
; edi - points to parms on 32-bit stack
;
public __Win16Thunk3_
__Win16Thunk3_ proc far
mov ecx,esp ; save 32-bit sp
mov _SaveSP,ecx ; ...
lss sp,_EntryStackSave ; switch to 16-bit stack
push ecx ; save 32-bit stack pointer
mov si,bx ; get thunk index
shr ebx,16 ; get API function index
add bx,offset _FunctionTable; ...
call cs:__ThunkTable[si] ; call appropriate thunk routine
push eax ; load 16:16 pointer into dx:ax
pop ax ; ...
pop dx ; ...
map2flat:or dx,dx ; check for NULL pointer
je short nullptr ; ...
movzx esi,ax ; save offset
mov bx,dx ; get selector
mov ax,6 ; load function code
int 31h ; get base address of selector
shl ecx,16 ; cx:dx is base
mov cx,dx ; ...
add ecx,esi ; add offset to base
mov eax,ecx ; to get 32-bit flat address
jmp short mapdone ; ...
nullptr:sub eax,eax ; NULL pointer
mapdone:pop ecx ; restore 32-bit stack pointer
mov word ptr _EntryStackSave,SP ; save current sp
mov bx,_DataSelector ; load 32-bit data segment
mov ss,_StackSelector ; switch back to 32-bit stack
mov esp,ecx ; ...
mov ds,bx ; reload ds
mov es,bx ; and es
db 66h ; far return to 32-bit code
ret ; ...
__Win16Thunk3_ endp
;
; __Win16Thunk4 - there are less than 6 parms and they have been preloaded
; into registers. No aliases are required.
; This thunk is the same as __Win16Thunk2 except the return value
; is a pointer.
;
public __Win16Thunk4_
__Win16Thunk4_ proc far
mov _SaveSP,esp ; save 32-bit stack pointer
lss sp,_EntryStackSave ; switch to 16-bit stack
push _SaveSP ; save 32-bit sp
mov bp,bx ; get thunk index
shr ebx,16 ; get API function index
add bx,offset _FunctionTable; ...
call cs:__ThunkTable[bp] ; call appropriate thunk routine
jmp map2flat ; map 16:16 pointer to 32-bit flat
__Win16Thunk4_ endp
GetNestedAliases proc near
push ebx ; save ebx
push edi ; save edi
lea edi,4[ecx] ; get pointer to 32-bit stack
mov cx,es:4[edi] ; get count
push cx ; save it
mov bp,sp ; point to saved registers
nest1:; _loop ; loop
add edi,8 ; - point to next pointer to alias
mov ebx,es:[edi] ; - get pointer
add ebx,es:4[edi] ; - add offset
mov eax,es:[ebx] ; - get enclosed pointer
call Get16Alias ; - get alias for the pointer
pop eax ; - retrieve alias
push eax ; - save it again
mov es:[ebx],eax ; - store alias pointer in structure
dec word ptr [bp] ; - decrement count
jne nest1 ; until e
push _SaveSP ; save 32-bit stack pointer
mov edi,2[bp] ; restore edi
mov ebx,6[bp] ; restore ebx
mov cx,10[bp] ; get return address
jmp cx ; return
GetNestedAliases endp
FreeNestedAliases proc near
pop bp ; save return address
mov esi,eax ; save return value
pop ecx ; get 32-bit stack pointer
lea edi,4[ecx] ; get pointer to 32-bit stack
mov es,_DataSelector ; load 32-bit data segment
mov ecx,es:4[edi] ; get count
lea edi,8[edi+ecx*8] ; point past first alias pushed
nest2:; _loop ; loop
sub edi,8 ; - point to next pointer to alias
mov edx,es:[edi] ; - get pointer
add edx,es:4[edi] ; - add offset
pop eax ; - get alias
pop ebx ; - get old value
mov es:[edx],ebx ; - restore old value
cmp eax,ebx ; - compare them
je short nest3 ; - if different, then
shr eax,16 ; - - get selector
call DPMIFreeAlias_ ; - - free it
mov es,_DataSelector ; - - load 32-bit data segment
nest3: ; - endif
dec cx ; - decrement count
jne nest2 ; until e
mov eax,esi ; restore return value
add sp,12 ; del items saved by GetNestedAliases
jmp bp ; return
FreeNestedAliases endp
;
; __Win16Thunk5 - at least one of the parms is a pointer and requires
; an alias for it. At least one of the pointer parms points to
; a structure that contains a pointer that also needs aliasing.
; edi - points to parms on 32-bit stack
; offset
; pointer
; offset
; pointer
; count
; far return address
;
public __Win16Thunk5_
__Win16Thunk5_ proc far
mov ecx,esp ; save 32-bit sp
mov _SaveSP,ecx ; ...
lss sp,_EntryStackSave ; switch to 16-bit stack
push ecx ; save 32-bit stack pointer
call GetNestedAliases ; get nested aliases
mov si,bx ; get thunk index
shr ebx,16 ; get API function index
add bx,offset _FunctionTable; ...
call cs:__ThunkTable[si] ; call appropriate thunk routine
call FreeNestedAliases ; free nested aliases
pop ecx ; restore 32-bit stack pointer
mov word ptr _EntryStackSave,SP ; save current sp
mov bx,_DataSelector ; load 32-bit data segment
mov ss,_StackSelector ; switch back to 32-bit stack
mov esp,ecx ; ...
mov ds,bx ; reload ds
mov es,bx ; and es
db 66h ; far return to 32-bit code
ret ; ...
__Win16Thunk5_ endp
;
; __Win16Thunk6 - at least one of the parms is a pointer and requires
; an alias for it. At least one of the pointer parms points to
; a structure that contains a pointer that also needs aliasing.
; This thunk is the same as __Win16Thunk5 except the return value
; is a pointer.
; edi - points to parms on 32-bit stack
;
public __Win16Thunk6_
__Win16Thunk6_ proc far
mov ecx,esp ; save 32-bit sp
mov _SaveSP,ecx ; ...
lss sp,_EntryStackSave ; switch to 16-bit stack
push ecx ; save 32-bit stack pointer
mov si,bx ; get thunk index
shr ebx,16 ; get API function index
add bx,offset _FunctionTable; ...
call cs:__ThunkTable[si] ; call appropriate thunk routine
push eax ; load 16:16 pointer into dx:ax
pop ax ; ...
pop dx ; ...
jmp map2flat ; map 16:16 pointer to 32-bit flat
__Win16Thunk6_ endp
_TEXT ends
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?