📄 raw_vcpi.asm
字号:
mov edx,Real_EDX[edi]
;
popm ebx,edi,ds,es
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 @@9
push ds
mov ax,MainDS
mov ds,ax
assume ds:_cwMain
cmp XMSPresent,0
assume ds:_cwRaw
pop ds
jnz @@9
;
mov esi,offset ITable+((4+4)*7)
mov ecx,8
@@0: pushm ecx,esi
cmp d[esi],0
jz @@1
mov dx,0[esi]
mov cx,2[esi]
mov bl,15h
pushm ax,ebx,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
popm ax,ebx,es
@@1: popm ecx,esi
sub esi,4+4
dec ecx
jnz @@0
@@9: ret
Int15Rel endp
;-------------------------------------------------------------------------------
;
;Real to protected mode switch.
;
;On Entry:-
;
;CX:EDX - target stack.
;
RAWReal2Prot proc near
pop w[@@Return]
mov d[@@ReturnStack],edx ;store return stack.
mov w[@@ReturnStack+4],cx
;
mov es,GDTReal
mov es:b[(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 @@0,KernalCS0 ;instruction pre-fetch & load CS.
@@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 ax,KernalDS ;Get data descriptor.
mov ds,ax ;/
mov es,ax ;/
mov gs,ax ;/
mov fs,ax
;
cld
clts
;
mov edx,d[@@ReturnStack]
mov cx,w[@@ReturnStack+4]
call RAWPL02PL3
;
push es
mov ax,KernalZero
mov es,ax
mov esi,GDTLinear
add esi,KernalTS-3
mov es:b[esi+5],DescPresent+DescPL3+Desc386Tss
pop es
;
push w[@@Return]
ret
@@Return: ;
dw ?
@@ReturnStack: ;
df ?
RAWReal2Prot endp
;-------------------------------------------------------------------------------
;
;Protected to real mode switch.
;
;On Entry:-
;
;CX:DX - target stack.
;
RAWProt2Real proc near
pop w[@@Return]
mov w[@@ReturnSP],dx
mov w[@@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 @@Resume,seg _cwRaw ;instruction pre-fetch & load CS.
@@Resume: ;
mov ax,_cwRaw
mov ds,ax
mov ss,w[@@ReturnSS]
movzx esp,w[@@ReturnSP]
mov eax,CR3Sav
mov cr3,eax
lidt IDTSav ;restore old IDT 0(3ff)
; lgdt GDTSav
; push EFlagsSav
; popfd
;
push w[@@Return]
ret
@@Return: ;
dw ?
@@ReturnSP: ;
dw ?
@@ReturnSS: ;
dw ?
RAWProt2Real endp
;-------------------------------------------------------------------------------
;
;Real to protected mode switch.
;
;On Entry:-
;
;CX:EDX - target stack.
;
VCPIReal2Prot proc near
pop w[@@Return]
mov d[@@ReturnStack],edx
mov w[@@ReturnStack+4],cx
mov VCPI_CS,KernalCS0
mov VCPI_EIP,offset @@Resume486
mov ax,0de0ch
mov si,seg _cwRaw
movzx esi,si
shl esi,4
add esi,offset VCPI_CR3
int 67h
;
@@Resume486: ;Make our stuff addresable.
;
mov ax,KernalPL0
mov ss,ax ;/
mov esp,offset 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[@@ReturnStack]
mov cx,w[@@ReturnStack+4]
call RAWPL02PL3
;
push es
mov ax,KernalZero
mov es,ax
mov esi,GDTLinear
add esi,KernalTS-3
mov es:b[esi+5],DescPresent+DescPL3+Desc386Tss
pop es
;
push w[@@Return]
ret
;
@@Return: ;
dw ?
@@ReturnStack: ;
df ?
;
VCPIReal2Prot endp
;-------------------------------------------------------------------------------
;
;Protected to real mode switch.
;
;On Entry:-
;
;CX:DX - Target stack.
;
VCPIProt2Real proc near
pop w[@@Return]
mov w[@@ReturnSP],dx
mov w[@@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 @@Resume
push eax ;EIP
mov ax,KernalZero
mov ds,ax
mov ax,0DE0Ch
assume ds:nothing
call cs:f[VCPI_Entry] ;switch back.
assume ds:_cwRaw
;
@@Resume: ;Make stack addresable.
;
mov ax,_cwRaw
mov ds,ax
mov ss,w[@@ReturnSS]
movzx esp,w[@@ReturnSP]
push w[@@Return]
ret
;
@@Return: ;
dw ?
@@ReturnSP: ;
dw ?
@@ReturnSS: ;
dw ?
VCPIProt2Real endp
;-------------------------------------------------------------------------------
RAWPL02PL3 proc near
pop w[@@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 @@pl3
push eax ;EIP
db 66h
iretd
;
@@pl3: push w[@@RetAdd]
ret
@@RetAdd: ;
dw ?
RAWPL02PL3 endp
;-------------------------------------------------------------------------------
RawPL32PL0 proc near
pop w[@@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 es:w[edi],offset @@pl0 ;store low word of limit.
pop ax
pop es
pop edi
db 09ah ;Absolute 16-bit call, to clear
dw @@pl0,KernalPL3_2_PL0 ;instruction pre-fetch & load CS.
;
@@pl0: push w[@@RetAdd]
ret
@@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.
;
cmp ax,1605h
jnz @@exit
or bx,bx
jnz @@ret
or si,si
jnz @@ret
or cx,cx
jnz @@ret
test dx,1
jnz @@ret
;
pushm ds,cs
pop ds
inc InWindows
pop ds
jmp @@ret
;
;check if it's an exit broadcast.
;
@@exit: cmp ax,1606h
jnz @@ret
test dx,1
jnz @@ret
;
pushm ds,cs
pop ds
dec InWindows
pop ds
;
;Let previous handlers have a go at it.
;
@@ret: assume ds:nothing
jmp cs:d[OldInt2F]
assume ds:_cwRaw
if 0
pushm ax,dx,ds,cs
pop ds
mov dx,offset WinMessage
mov ah,9
int 21h
pop ds
mov ax,4cffh
int 21h
@@Old: jmp cs:d[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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -