raw_vcpi.asm
来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 2,338 行 · 第 1/5 页
ASM
2,338 行
mov edi,offset MemIntBuffer
mov RealRegsStruc.Real_EAX[edi],eax
mov RealRegsStruc.Real_EDX[edi],edx
mov RealRegsStruc.Real_CS[edi],_cwRaw
mov RealRegsStruc.Real_IP[edi],offset Int67h
mov RealRegsStruc.Real_SS[edi],0
mov RealRegsStruc.Real_SP[edi],0
call RawSimulateFCALL
pop es
pop edi
; endif
pop es
pop ds
pop edi
pop esi
pop ecx
;
rv12_1:
add edi,4096 ;next page table alias.
add esi,4 ;next page dir entry.
dec ecx
jnz rv12_0
rv12_9: ret
VCPIRelExtended endp
if 0
;-------------------------------------------------------------------------------
;
;Call VCPI entry point directly rather than via INT 67h.
;
VCPICall proc near
push ebx
push edi
push ds
push es
push ax
mov ax,KernalDS
mov ds,ax
mov es,ax
pop ax
;
mov edi,offset MemIntBuffer
mov RealRegsStruc.Real_EAX[edi],eax
mov RealRegsStruc.Real_CS[edi],_cwRaw
mov RealRegsStruc.Real_IP[edi],offset Int67h
mov RealRegsStruc.Real_SS[edi],0
mov RealRegsStruc.Real_SP[edi],0
mov bl,67h
call RawSimulateINT
mov eax,RealRegsStruc.Real_EAX[edi]
mov edx,RealRegsStruc.Real_EDX[edi]
;
pop es
pop ds
pop edi
pop ebx
ret
VCPICall endp
endif
;-------------------------------------------------------------------------------
Int67h proc far
int 67h
ret
Int67h endp
;-------------------------------------------------------------------------------
;
;Release real mode int 15 patches.
;
Int15Rel proc far
push ds
mov ax,MainDS
mov ds,ax
assume ds:_cwMain
cmp ProtectedType,1 ;VCPI?
assume ds:_cwRaw
pop ds
jnc rv15_9
push ds
mov ax,MainDS
mov ds,ax
assume ds:_cwMain
cmp XMSPresent,0
assume ds:_cwRaw
pop ds
jnz rv15_9
;
mov esi,offset ITable+((4+4)*7)
mov ecx,8
rv15_0:
push ecx
push esi
cmp d[esi],0
jz rv15_1
mov dx,0[esi]
mov cx,2[esi]
mov bl,15h
push ax
push ebx
push es
mov ax,KernalZero
mov es,ax
movzx ebx,bl
shl ebx,2
pushf
cli
mov es:0[ebx],dx
mov es:2[ebx],cx
popf
pop es
pop ebx
pop ax
rv15_1:
pop esi
pop ecx
sub esi,4+4
dec ecx
jnz rv15_0
rv15_9: ret
Int15Rel endp
;-------------------------------------------------------------------------------
;
;Real to protected mode switch.
;
;On Entry:-
;
;CX:EDX - target stack.
;
RAWReal2Prot proc near
pop w[rv16_Return]
mov d[rv16_ReturnStack],edx ;store return stack.
mov w[rv16_ReturnStack+4],cx
;
mov es,GDTReal
mov BYTE PTR es:[(KernalTS-3)+5],DescPresent+DescPL3+Desc386Tss
sidt IDTSav ;save old IDT value for switch back.
lgdt GDTVal ;Setup GDT &
lidt IDTVal ;IDT.
; pushfd
; pop eax
; mov EFlagsSav,eax
mov eax,cr3
mov CR3Sav,eax
mov eax,cr0
mov CR0Sav,eax
mov eax,VCPI_CR3 ;PageDirLinear
mov cr3,eax ;set page dir address.
; MED 10/15/96
; mov eax,cr0 ;Get machine status &
; or eax,080000001h ;set PM+PG bits.
mov eax,CR0ProtSav ; restore protected mode cr0 status
mov cr0,eax ;/
db 0eah ;Absolute 16-bit jump, to clear
dw rv16_0,KernalCS0 ;instruction pre-fetch & load CS.
rv16_0: mov ax,KernalLDT ;Point to empty LDT descriptor.
lldt ax ;and set LDT.
mov cx,KernalTS ;Get value for task register.
ltr cx ;and set it.
;
;Make our stuff addresable.
;
mov ax,KernalPL0
mov ss,ax ;/
; mov esp,offset tPL0StackSize-4
mov esp,tPL0StackSize-4
mov ax,KernalDS ;Get data descriptor.
mov ds,ax ;/
mov es,ax ;/
mov gs,ax ;/
mov fs,ax
;
cld
clts
;
mov edx,d[rv16_ReturnStack]
mov cx,w[rv16_ReturnStack+4]
call RAWPL02PL3
;
push es
mov ax,KernalZero
mov es,ax
mov esi,GDTLinear
add esi,KernalTS-3
mov BYTE PTR es:[esi+5],DescPresent+DescPL3+Desc386Tss
pop es
;
push w[rv16_Return]
ret
rv16_Return: ;
dw ?
rv16_ReturnStack: ;
df ?
RAWReal2Prot endp
;-------------------------------------------------------------------------------
;
;Protected to real mode switch.
;
;On Entry:-
;
;CX:DX - target stack.
;
RAWProt2Real proc near
pop w[rv17_Return]
mov w[rv17_ReturnSP],dx
mov w[rv17_ReturnSS],cx
mov ax,KernalDS ;Get supervisor data descriptor,
mov ds,ax ;DS,ES,FS,GS,SS must be data with 64k limit
mov es,ax ;expand up, read/write for switch back to real
mov fs,ax ;mode.
mov gs,ax ;/
;
call RAWPL32PL0
mov ax,KernalSwitchPL0
mov ss,ax
;
; MED 10/15/96
mov eax,cr0
mov CR0ProtSav,eax ; save protected mode cr0 status
mov eax,CR0Sav ;Get machine control &
; MED 10/15/96, don't clear emulate math coprocessor bit
; and eax,07FFFFFF2h ;clear PM bit.
and eax,07FFFFFF6h ;clear PM bit.
mov cr0,eax ;/
db 0eah ;Absolute 16-bit jump, to clear
dw rv17_Resume,seg _cwRaw ;instruction pre-fetch & load CS.
rv17_Resume: ;
mov ax,_cwRaw
mov ds,ax
mov ss,w[rv17_ReturnSS]
movzx esp,w[rv17_ReturnSP]
mov eax,CR3Sav
mov cr3,eax
lidt IDTSav ;restore old IDT 0(3ff)
; lgdt GDTSav
; push EFlagsSav
; popfd
;
push w[rv17_Return]
ret
rv17_Return: ;
dw ?
rv17_ReturnSP: ;
dw ?
rv17_ReturnSS: ;
dw ?
RAWProt2Real endp
;-------------------------------------------------------------------------------
;
;Real to protected mode switch.
;
;On Entry:-
;
;CX:EDX - target stack.
;
VCPIReal2Prot proc near
pop w[rv18_Return]
mov d[rv18_ReturnStack],edx
mov w[rv18_ReturnStack+4],cx
mov VCPI_CS,KernalCS0
mov VCPI_EIP,offset rv18_Resume486
mov ax,0de0ch
mov si,seg _cwRaw
movzx esi,si
shl esi,4
add esi,offset VCPI_CR3
int 67h
;
rv18_Resume486: ;Make our stuff addresable.
;
mov ax,KernalPL0
mov ss,ax ;/
; mov esp,offset tPL0StackSize-4
mov esp,tPL0StackSize-4
mov ax,KernalDS ;Get data descriptor.
mov ds,ax ;/
mov es,ax ;/
mov gs,ax ;/
mov fs,ax
;
pushfd
pop eax
and ax,1011111111111111b ;clear NT.
push eax
popfd
cld
;
mov edx,d[rv18_ReturnStack]
mov cx,w[rv18_ReturnStack+4]
call RAWPL02PL3
;
push es
mov ax,KernalZero
mov es,ax
mov esi,GDTLinear
add esi,KernalTS-3
mov BYTE PTR es:[esi+5],DescPresent+DescPL3+Desc386Tss
pop es
;
push w[rv18_Return]
ret
;
rv18_Return: ;
dw ?
rv18_ReturnStack: ;
df ?
;
VCPIReal2Prot endp
;-------------------------------------------------------------------------------
;
;Protected to real mode switch.
;
;On Entry:-
;
;CX:DX - Target stack.
;
VCPIProt2Real proc near
pop w[rv19_Return]
mov w[rv19_ReturnSP],dx
mov w[rv19_ReturnSS],cx
;
mov ax,KernalDS ;Get supervisor data descriptor,
mov ds,ax ;DS,ES,FS,GS,SS must be data with 64k limit
mov es,ax ;expand up, read/write for switch back to real
mov fs,ax ;mode.
mov gs,ax ;/
call RAWPL32PL0
mov ax,KernalSwitchPL0
mov ss,ax
;
movzx ebp,dx
xor eax,eax
push eax
push eax
push eax
push eax
mov ax,cx ;ss
push eax
push ebp ;ESP
pushfd ;EFLags (reserved for)
mov ax,_cwRaw
push eax ;CS
mov ax,offset rv19_Resume
push eax ;EIP
mov ax,KernalZero
mov ds,ax
mov ax,0DE0Ch
assume ds:nothing
call FWORD PTR cs:[VCPI_Entry] ;switch back.
assume ds:_cwRaw
;
rv19_Resume: ;Make stack addresable.
;
mov ax,_cwRaw
mov ds,ax
mov ss,w[rv19_ReturnSS]
movzx esp,w[rv19_ReturnSP]
push w[rv19_Return]
ret
;
rv19_Return: ;
dw ?
rv19_ReturnSP: ;
dw ?
rv19_ReturnSS: ;
dw ?
VCPIProt2Real endp
;-------------------------------------------------------------------------------
RAWPL02PL3 proc near
pop w[rv20_RetAdd]
movzx ecx,cx
push ecx ;SS
push edx ;ESP
pushfd ;EFlags
pop eax
and ax,1000111111111111b ;clear NT & IOPL.
or ax,0011000000000000b ;force IOPL.
push eax
popfd
push eax
xor eax,eax
mov ax,KernalCS
push eax ;CS
mov eax,offset rv20_pl3
push eax ;EIP
db 66h
iretd
;
rv20_pl3: push w[rv20_RetAdd]
ret
rv20_RetAdd: ;
dw ?
RAWPL02PL3 endp
;-------------------------------------------------------------------------------
RawPL32PL0 proc near
pop w[rv21_RetAdd]
push edi
mov edi,GDTLinear
add edi,KernalPL3_2_PL0
and edi,not 7
push es
push ax
mov ax,KernalZero
mov es,ax
mov WORD PTR es:[edi],offset rv21_pl0 ;store low word of limit.
pop ax
pop es
pop edi
db 09ah ;Absolute 16-bit call, to clear
dw rv21_pl0,KernalPL3_2_PL0 ;instruction pre-fetch & load CS.
;
rv21_pl0: push w[rv21_RetAdd]
ret
rv21_RetAdd: ;
dw ?
RawPL32PL0 endp
;-------------------------------------------------------------------------------
;
;Release INT 2F patch.
;
ReleaseINT2F proc near
push ds
mov ax,252fh
lds dx,OldInt2F
int 21h
pop ds
ret
ReleaseINT2F endp
;-------------------------------------------------------------------------------
;
;Intercept for windows init broadcast.
;
Int2FPatch proc near
;
;check if it's an init broadcast that's being allowed.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?