raw_vcpi.asm
来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 2,338 行 · 第 1/5 页
ASM
2,338 行
;
cmp ax,1605h
jnz rv23_exit
or bx,bx
jnz rv23_ret
or si,si
jnz rv23_ret
or cx,cx
jnz rv23_ret
test dx,1
jnz rv23_ret
;
push ds
push cs
pop ds
inc InWindows
pop ds
jmp rv23_ret
;
;check if it's an exit broadcast.
;
rv23_exit: cmp ax,1606h
jnz rv23_ret
test dx,1
jnz rv23_ret
;
push ds
push cs
pop ds
dec InWindows
pop ds
;
;Let previous handlers have a go at it.
;
rv23_ret: assume ds:nothing
jmp DWORD PTR cs:[OldInt2F]
assume ds:_cwRaw
if 0
push ax
push dx
push ds
push cs
pop ds
mov dx,offset WinMessage
mov ah,9
int 21h
pop ds
mov ax,4cffh
int 21h
rv23_Old: jmp DWORD PTR cs:[OldInt2F]
assume ds:_cwRaw
endif
if 0
WinMessage db 'Cannot run Windows in enhanced mode while a CauseWay application is active.',13,10
db 'Run Windows in standard mode or remove the CauseWay application.',13,10,'$'
endif
OldInt2F dd 0
Int2FPatch endp
;-------------------------------------------------------------------------------
;
;Simulate real mode interupt.
;
;On Entry:-
;
;ES:EDI - Parameter table.
;BL - Interupt number.
;
;On Exit:-
;
;Parameter table updated.
;
RAWSimulateInt proc near
push cx
push bx
mov bh,0
mov cx,0
jmp RAWSimulate
RAWSimulateInt endp
;-------------------------------------------------------------------------------
;
;Simulate real mode interupt.
;
;On Entry:-
;
;ES:EDI - Parameter table.
;SS:EBP - Stacked parameters.
;CX - stacked word count.
;BL - Interupt number.
;
;On Exit:-
;
;Parameter table updated.
;
RAWSimulateInt2 proc near
push cx
push bx
mov bh,0
jmp RAWSimulate
RAWSimulateInt2 endp
;-------------------------------------------------------------------------------
;
;Simulate real mode far call.
;
;On Entry:-
;
;ES:EDI - Parameter table.
;
;On Exit:-
;
;Parameter table updated.
;
RAWSimulateFCALL proc near
push cx
push bx
mov bh,1
mov cx,0
jmp RawSimulate
RAWSimulateFCALL endp
;-------------------------------------------------------------------------------
;
;Simulate real mode far call.
;
;On Entry:-
;
;ES:EDI - Parameter table.
;SS:EBP - Stacked parameters.
;CX - stacked word count.
;
;On Exit:-
;
;Parameter table updated.
;
RAWSimulateFCALL2 proc near
push cx
push bx
mov bh,1
jmp RawSimulate
RAWSimulateFCALL2 endp
;-------------------------------------------------------------------------------
;
;Simulate real mode far call with IRET stack frame.
;
;On Entry:-
;
;ES:EDI - Parameter table.
;SS:EBP - Stacked parameters.
;CX - stacked word count.
;
;On Exit:-
;
;Parameter table updated.
;
RAWSimulateFCALLI proc near
push cx
push bx
mov bh,2
jmp RawSimulate
RAWSimulateFCALLI endp
;-------------------------------------------------------------------------------
;
;Simulate either a real mode INT or far call.
;
RawSimulate proc near
pushf ;Preserve IF state.
cli ;Stop INTs interfering.
cld ;make sure direction is right.
pushad
push ds
push es
push fs
push gs
mov ax,KernalDS ;make our data addresable.
mov ds,ax ;/
mov ax,KernalZero
mov fs,ax
push d[rv29_tVCPI_SP]
push d[rv29_IntAdd]
push w[rv29_CallAdd]
push w[rv29_ourstack]
mov w[rv29_ourstack],0
;
;setup the real mode stack.
;
mov ax,es:RealRegsStruc.Real_SP[edi] ;check if stack is being
or ax,es:RealRegsStruc.Real_SS[edi] ;supplied.
jnz rv29_GotStack
;
;Caller isn't supplying a stack so we will.
;
mov eax,RawStackPos
sub RawStackPos,RawStackDif ;update for re-entry.
mov es:RealRegsStruc.Real_SP[edi],ax
xor esi,esi
mov si,RawStackReal
mov es:RealRegsStruc.Real_SS[edi],si
or w[rv29_ourstack],-1
;
;Point to the real mode stack.
;
rv29_GotStack: movzx esi,es:RealRegsStruc.Real_SS[edi]
movzx eax,es:RealRegsStruc.Real_SP[edi]
sub eax,(4+4)+(4+4)
mov w[rv29_tVCPI_SP+2],si
mov w[rv29_tVCPI_SP],ax
mov edx,esi
shl esi,4
add esi,eax
;
;Store current stack pointer on v86 stack.
;
xor eax,eax
mov ax,ss
mov fs:[esi+4],eax
mov eax,esp
test BYTE PTR RawSystemFlags,1
jz rv29_noextendstack
movzx eax,ax
rv29_noextendstack: mov fs:[esi+0],eax
;
;Store table address on v86 stack.
;
xor eax,eax
mov ax,es
mov fs:[esi+12],eax
mov fs:[esi+8],edi
;
;Copy stacked parameters.
;
or cx,cx
jz rv29_NoStacked
movzx eax,cx
shl eax,1
add ebp,eax
rv29_copystack0: sub ebp,2
sub esi,2
mov ax,[ebp]
mov fs:[esi],ax
dec cx
jnz rv29_copystack0
;
;Put flags onto the real mode stack.
;
rv29_NoStacked: mov ebp,esp
test BYTE PTR RawSystemFlags,1
jz rv29_Its32
movzx ebp,bp
rv29_Its32: mov ax,[ebp+(2+4+4)+(2+2+2+2)+(4+4+4+4+4+4+4+4)+2]
or bh,bh ;int or far?
jnz rv29_NoIF
and ax,1111110011111111b ;clear Trap and INT flag.
rv29_NoIF: sub esi,2
mov fs:[esi],ax
;
;See if the CS:IP is supplied or needs fetching.
;
or bh,bh
jz rv29_IsInt
;
mov cx,es:RealRegsStruc.Real_CS[edi]
shl ecx,16
mov cx,es:RealRegsStruc.Real_IP[edi]
mov w[rv29_calladd],offset rv29_fcall
cmp bh,2
jnz rv29_notint
mov w[rv29_calladd],offset rv29_fcalli
jmp rv29_notint
;
rv29_IsInt: ;See if this is a busy interrupt call back.
;
xor bh,bh
mov bp,bx
shl bp,2
mov al,[Int2CallCheck+bx]
or al,al
jz rv29_c3
sub bl,al
shl bx,3 ;*8
mov ax,bx
shl bx,1 ;*16
add bx,ax ;*24
add bx,offset CallBackTable
test CallBackStruc.CallBackFlags[bx],128 ;this entry in use?
jz rv29_c3
mov ecx,CallBackStruc.CallBackReal[bx]
jmp rv29_c2
;
rv29_c3: ;Get interupt address to put on stack.
;
mov ecx,DWORD PTR fs:[bp]
;
rv29_c2: mov w[rv29_calladd],offset rv29_int
;
rv29_NotInt: sub esi,4
mov fs:[esi],ecx
;
;Copy register values onto real mode stack.
;
sub esi,4+4+4+4+4+4+4+4+2+2+2+2+2+2 ;extra +2 for movsD
push esi
push edi
push ds
push es
xchg esi,edi
push es
push fs
pop es
pop ds
mov ecx,(4+4+4+4+4+4+4+4+2+2+2+2+2+2)/4
rep movs d[edi],[esi]
pop es
pop ds
pop edi
pop esi
;
;Get ss:sp values again.
;
mov ecx,edx
mov eax,ecx
shl eax,4
mov edx,esi
sub edx,eax
;
;Switch back to v86 mode.
;
call w[Protected2Real]
;
;Fetch registers off the stack.
;
assume ds:nothing
popad
pop WORD PTR cs:[rv29_IntAdd] ;lose dummy.
pop es
pop ds
pop fs
pop gs
pop WORD PTR cs:[rv29_IntAdd] ;lose dummy.
;
pop DWORD PTR cs:[rv29_IntAdd]
jmp WORD PTR cs:[rv29_calladd]
;
rv29_fcall: popf
call DWORD PTR cs:[rv29_IntAdd]
jmp rv29_Back
;
rv29_fcalli: ;
rv29_int: call DWORD PTR cs:[rv29_IntAdd]
;
rv29_Back: pushf
cli
cld
pop WORD PTR cs:[rv29_IntAdd]
and WORD PTR cs:[rv29_IntAdd],0000110011010101b
;
;Switch back to old stack.
;
mov ss,WORD PTR cs:[rv29_tVCPI_SP+2]
mov sp,WORD PTR cs:[rv29_tVCPI_SP]
;
;Save all registers.
;
push WORD PTR cs:[rv29_IntAdd] ;save dummy.
push gs
push fs
push ds
push es
push WORD PTR cs:[rv29_IntAdd] ;save flags.
pushad
;
;Make our data addresable again and store stack values.
;
mov ax,_cwRaw
mov ds,ax
assume ds:_cwRaw
mov w[rv29_tVCPI_SP],sp
mov w[rv29_tVCPI_SP+2],ss
mov bp,sp
;
;Retrieve protected mode stack address.
;
mov edx,d[bp+(4+4+4+4+4+4+4+4)+(2+2+2+2+2)+(2)]
mov cx,w[bp+4+(4+4+4+4+4+4+4+4)+(2+2+2+2+2)+(2)]
;
;switch back to protected mode.
;
call w[Real2Protected]
;
mov ax,KernalZero ;/
mov fs,ax ;/
;
;Retreive v86 stack address.
;
movzx esi,w[rv29_tVCPI_SP+2]
shl esi,4
movzx eax,w[rv29_tVCPI_SP]
add esi,eax
;
;Retrieve table address.
;
les edi,fs:[esi+(4+4+4+4+4+4+4+4)+(2+2+2+2+2)+(2)+(4+4)]
;
;Copy new register values into table.
;
push esi
push edi
push ds
push fs
pop ds
mov ecx,(4+4+4+4+4+4+4+4+2+2+2+2+2+2)/4
rep movs d[edi],[esi]
pop ds
pop edi
pop esi
mov bx,[esp+(2+2+2+2)+(4+4+4+4+4+4+4+4)+(4+4+2)+2]
and bx,1111001100101010b
or es:RealRegsStruc.Real_Flags[edi],bx
;
cmp w[rv29_ourstack],0
jz rv29_nostackadjust
add RawStackPos,RawStackDif ;update for re-entry.
rv29_nostackadjust:
pop w[rv29_ourstack]
pop w[rv29_CallAdd]
pop d[rv29_IntAdd]
pop d[rv29_tVCPI_SP]
;
pop gs
pop fs
pop es
pop ds
popad
popf
clc
;
pop bx
pop cx
ret
rv29_IntAdd: ;
dd ?
rv29_CallAdd: ;
dw ?
rv29_tVCPI_SP: ;
dd ?
rv29_ourstack: ;
dw 0
RAWSimulate endp
;-------------------------------------------------------------------------------
RAWCallBack proc near
pushf
cli
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?