📄 raw_vcpi.asm
字号:
@@VCPI0: mov ax,_cwStack
mov ss,ax
mov esp,offset _cwStackEnd-4
mov ax,_cwRaw
mov ds,ax
mov es,ax ;/
mov fs,ax
mov gs,ax
;
;We're back in real mode so remove any patches.
;
@@InReal: cmp w[OldInt2F+2],0
jz @@ir0
push ds
mov ax,252fh
lds dx,OldInt2F
int 21h
pop ds
@@ir0: ;
cmp VMMHandle,0 ;Any VMM file?
jz @@v0
mov bx,VMMHandle ;close VMM file.
mov ax,3e00h
int 21h
mov dx,offset VMMName ;delete VMM file.
mov ah,41h
int 21h
@@v0: ;
;
;Go back to _cwMain/Init caller.
;
push d[@@RetAdd]
retf
@@RetAdd: ;
dd 0
; MED 10/31/96
@@StackAdd:
df ?
RawVCPIRealMode endp
;-------------------------------------------------------------------------------
_fRawSimulateINT proc far
call RawSimulateINT
ret
_fRawSimulateINT endp
;-------------------------------------------------------------------------------
_fRawSimulateINT2 proc far
call RawSimulateINT2
ret
_fRawSimulateINT2 endp
;-------------------------------------------------------------------------------
_fRawSimulateFCall proc far
call RawSimulateFCALL
ret
_fRawSimulateFCall endp
;-------------------------------------------------------------------------------
_fRawSimulateFCall2 proc far
call RawSimulateFCALL2
ret
_fRawSimulateFCall2 endp
;-------------------------------------------------------------------------------
_fRawSimulateFCallI proc far
call RawSimulateFCALLI
ret
_fRawSimulateFCallI endp
;-------------------------------------------------------------------------------
;
;Allocate a page of physical memory.
;
_fPhysicalGetPage proc far
xor eax,eax
mov ax,cs
push eax
mov eax,offset @@0
push eax
mov ax,DpmiEmuCS
push eax
mov eax,offset _ffPhysicalGetPage
push eax
db 66h
retf
@@0: ret
_fPhysicalGetPage endp
;-------------------------------------------------------------------------------
;
;Find out how many physical page of memory are free.
;
_fPhysicalGetPages proc far
xor eax,eax
mov ax,cs
push eax
mov eax,offset @@0
push eax
mov ax,DpmiEmuCS
push eax
mov eax,offset _ffPhysicalGetPages
push eax
db 66h
retf
@@0: ret
_fPhysicalGetPages endp
;-------------------------------------------------------------------------------
;
;Switch 2 PL0, flush CR3 value then switch back to PL3.
;
_fCR3Flush proc far
call CR3Flush
ret
_fCR3Flush endp
;-------------------------------------------------------------------------------
;
;Switch 2 PL0, flush CR3 value then switch back to PL3.
;
CR3Flush proc near
pushf
cli
pushad
mov d[@@StackAdd],esp
mov w[@@StackAdd+4],ss
call RAWPL32PL0
;
; mov eax,cr3
mov eax,VCPI_CR3
mov cr3,eax ;flush page cache.
;
mov edx,d[@@StackAdd]
mov cx,w[@@StackAdd+4]
call RAWPL02PL3
popad
popf
ret
@@StackAdd: ;
df ?
CR3Flush endp
;-------------------------------------------------------------------------------
Int15PatchTable dw Int15Patch0,Int15Patch1,Int15Patch2,Int15Patch3
dw Int15Patch4,Int15Patch5,Int15Patch6,Int15Patch7
Int15Patch0: push esi
mov si,offset ITable+0
jmp Int15Patch
Int15Patch1: push esi
mov si,offset ITable+8
jmp Int15Patch
Int15Patch2: push esi
mov si,offset ITable+16
jmp Int15Patch
Int15Patch3: push esi
mov si,offset ITable+24
jmp Int15Patch
Int15Patch4: push esi
mov si,offset ITable+32
jmp Int15Patch
Int15Patch5: push esi
mov si,offset ITable+40
jmp Int15Patch
Int15Patch6: push esi
mov si,offset ITable+48
jmp Int15Patch
Int15Patch7: push esi
mov si,offset ITable+56
jmp Int15Patch
;
assume ds:nothing
Int15Patch: cmp ah,88h ;get memory size?
jnz Checke801h
mov eax,cs:4[si]
Int15PatchRet:
pop esi
iret
Checke801h:
cmp ax,0e801h
jnz Int15Old
xor bx,bx
mov eax,cs:4[si] ; get 32-bit memory size 1K pages
cmp eax,3c00h
jbe E801Done ; <16M memory, ax/cx hold proper return value
mov ebx,eax
mov eax,3c00h ; ax holds 1K memory between 1M and 16M
sub ebx,eax ; ebx holds 1K pages of high memory
shr ebx,6 ; convert 1K to 64K
E801Done:
mov cx,ax
mov dx,bx
jmp Int15PatchRet
;
Int15Old: mov esi,cs:[si]
mov cs:d[Int15Jump],esi
pop esi
jmp cs:d[Int15Jump] ;pass to old handler.
assume ds:_cwRaw
Int15Jump dd ?
ILevel dw 0
ITable dd 8*2 dup (0)
;-------------------------------------------------------------------------------
;
;Release any XMS we claimed.
;
RAWRelXMS proc far
cmp XMSPresent,0
jz @@Done
;
push ds
pop es
mov edi,offset MemIntBuffer
;
mov si,offset XMSList ;+2 ;list of handles.
mov cx,32
@@0: or cx,cx
jz @@Done
cmp d[si+2],0
jz @@1
pushm cx,si
mov dx,[si]
mov ah,0dh
push dx
push ax
mov ax,w[XMSControl]
mov [edi].v86CallIP,ax
mov ax,w[XMSControl+2]
mov [edi].v86CallCS,ax
pop ax
mov [edi].v86CallEAX,eax
mov [edi].v86CallEDX,edx
mov [edi].v86CallSS,0
mov [edi].v86CallSP,0
call RawSimulateFCALL ;un-lock it first.
pop dx
mov ah,0ah
push ax
mov ax,w[XMSControl]
mov [edi].v86CallIP,ax
mov ax,w[XMSControl+2]
mov [edi].v86CallCS,ax
pop ax
mov [edi].v86CallEAX,eax
mov [edi].v86CallEDX,edx
mov [edi].v86CallSS,0
mov [edi].v86CallSP,0
call RawSimulateFCALL ;un-lock it first.
popm cx,si
@@1: add si,2+4+4
dec cx
jmp @@0
;
@@Done: ret
RAWRelXMS endp
;-------------------------------------------------------------------------------
;
;Release any VCPI memory aquired.
;
VCPIRelExtended proc far
push ds
mov ax,MainCS
mov ds,ax
assume ds:_cwMain
cmp ProtectedType,1
assume ds:_cwRaw
pop ds
jnz @@9
;
cmp PageDETLinear,0
jz @@NoDET
;
;Release DET pages.
;
mov ax,KernalZero
mov es,ax
mov ecx,1024
mov esi,PageDETLinear
@@d0:
test es:d[esi],1 ;present?
jz @@d1
test es:d[esi],1 shl 10 ;VCPI bit set?
jz @@d1
pushm ecx,esi,edi,ds,es
mov edx,es:[esi]
and edx,0FFFFFFFFh-4095
and es:d[esi],0FFFFFFFFh-1 ;mark as no longer present.
call CR3Flush
pushm edi,es
push ds
pop es
mov ax,0DE05h ;free 4k page.
; mov bl,67h
mov edi,offset MemIntBuffer
mov Real_EAX[edi],eax
mov Real_EDX[edi],edx
mov Real_CS[edi],_cwRaw
mov Real_IP[edi],offset Int67h
mov Real_SS[edi],0
mov Real_SP[edi],0
call RawSimulateFCALL
popm edi,es
; mov ax,0DE05h ;free 4k page.
; call VCPICall
popm ecx,esi,edi,ds,es
@@d1: add esi,4
dec ecx
jnz @@d0
;
@@NoDET:
;Release normal memory.
;
mov ax,KernalZero
mov es,ax
mov esi,PageDirLinear
mov ecx,1022
mov edi,1024*4096*1023 ;base of page alias's.
@@0:
test es:d[esi],1 ;Page table present?
jz @@1
pushm ecx,esi,edi
mov ecx,1024
@@2:
test es:d[edi],1 ;Page present?
jz @@3
test es:d[edi],1 shl 10 ;VCPI bit set?
jz @@3
; MED 11/05/96
cmp esi,PageDirLinear ; see if 0th page table
jne notzeroth ; no
mov eax,edi
sub eax,1024*4096*1023
cmp ax,FirstUninitPage ; see if below first uninitialized page table
jb @@3 ; yes, not our entry to mess with
notzeroth:
pushm ecx,esi,edi,ds,es
mov edx,es:[edi]
and es:d[edi],0FFFFFFFFh-1 ;mark as no longer present.
and edx,0FFFFFFFFh-4095
call CR3Flush
; mov ax,0DE05h ;free 4k page.
; call VCPICall
; if 0
pushm edi,es
push ds
pop es
mov ax,0DE05h ;free 4k page.
; mov bl,67h
mov edi,offset MemIntBuffer
mov Real_EAX[edi],eax
mov Real_EDX[edi],edx
mov Real_CS[edi],_cwRaw
mov Real_IP[edi],offset Int67h
mov Real_SS[edi],0
mov Real_SP[edi],0
call RawSimulateFCALL
popm edi,es
; endif
popm ecx,esi,edi,ds,es
@@3:
add edi,4
dec ecx
jnz @@2
popm ecx,esi,edi
test es:d[esi],1 shl 10 ;VCPI bit set?
jz @@1
pushm ecx,esi,edi,ds,es
mov edx,es:[esi]
and edx,0FFFFFFFFh-4095
and es:d[esi],0FFFFFFFFh-1 ;mark as no longer present.
call CR3Flush
; mov ax,0DE05h ;free 4k page.
; call VCPICall
; if 0
pushm edi,es
push ds
pop es
mov ax,0DE05h ;free 4k page.
; mov bl,67h
mov edi,offset MemIntBuffer
mov Real_EAX[edi],eax
mov Real_EDX[edi],edx
mov Real_CS[edi],_cwRaw
mov Real_IP[edi],offset Int67h
mov Real_SS[edi],0
mov Real_SP[edi],0
call RawSimulateFCALL
popm edi,es
; endif
popm ecx,esi,edi,ds,es
;
@@1:
add edi,4096 ;next page table alias.
add esi,4 ;next page dir entry.
dec ecx
jnz @@0
@@9: ret
VCPIRelExtended endp
if 0
;-------------------------------------------------------------------------------
;
;Call VCPI entry point directly rather than via INT 67h.
;
VCPICall proc near
pushm ebx,edi,ds,es
push ax
mov ax,KernalDS
mov ds,ax
mov es,ax
pop ax
;
mov edi,offset MemIntBuffer
mov Real_EAX[edi],eax
mov Real_CS[edi],_cwRaw
mov Real_IP[edi],offset Int67h
mov Real_SS[edi],0
mov Real_SP[edi],0
mov bl,67h
call RawSimulateINT
mov eax,Real_EAX[edi]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -