⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 raw_vcpi.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;
;The RAW/VCPI specific code.
;
        .386p

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Main (Kernal) section for RAW/VCPI stuff. This holds the mode switch, interrupt
;simulator and low level memory managers etc.
;
_cwRaw  segment para public 'raw kernal' use16
        assume cs:_cwRaw, ds:_cwRaw
;
InWindows       db 0
BreakAddress    dd ?
VMMHandle       dw ?
VMMName db '?:\',128 dup (0)
;
PageStackSize   equ     32
ProposedPresentFlag db 0
ProposedRecentFlag db 0
ProposedPage dd 0
CompareCount dd 0
NoneLockedPages dd 0
RecentMapStack  dd PageStackSize dup (0)
;
PageingPointer  dd 0
SwapFileLength  dd 0
;
FreePages       dd 1
medAllocPages   dd      0
TotalPages      dd 1
TotalPhysical   dd 0
;
RawSelBuffer    db 16 dup (?)
;
_LM_BlockBase   dd ?
_LM_BlockEnd    dd ?
_LM_Needed      dd ?
_LM_Got dd ?
;
MemIntBuffer    db size RealRegsStruc dup (?)
XMSList label byte
        db 32*(2+4+4) dup (0)
XMSTempList     dd 32 dup (0)
XMSTotal        dd 0
ConventionalList label byte
        dw 32*2 dup (0)
ConvTempList    dw 32*2 dup (0)
CONVTotal       dd 0
CONVSavePara    dw 0


IFDEF MAXSAVE
CONVSaveSize    dw      -1
ELSE
CONVSaveSize    dw 32768/16
ENDIF

Int15Table      dd 8*2 dup (0)
Int15Size       dd 0
INT15hTotal     dd ?
INT15hValue     dd ?
INT15hLevel2    dw ?
;
Protected2Real  dw VCPIProt2Real
Real2Protected  dw VCPIReal2Prot
;
A20HandlerCall  dw ?
A20Flag db 0
LowMemory       label dword         ; Set equal to 0000:0080
        dw 00080h
        dw 00000h
HighMemory      label dword
        dw 00090h           ; Set equal to FFFF:0090
        dw 0FFFFh

XMSPresent      db 0
XMSVer3Present  DB      0       ; MED, 09/10/99

XMSControl      dd ?
XMSBlockSize    dw ?
XMSUMBUsed      dw 0

IFDEF PERMBIG1
Big1Flag        DB      1
ELSE
Big1Flag        DB      0
ENDIF

;
VCPI_CR3        dd 0            ;CR3
VCPI_pGDT       dd ?            ;Pointer to GDT descriptor.
VCPI_pIDT       dd ?            ;Pointer to IDT descriptor.
VCPI_LDT        dw 0    ;LDTR
VCPI_TR dw 0                    ;TR
VCPI_EIP        dd 0    ;CS:EIP client entry point.
VCPI_CS dw 0            ;/
;
VCPI_GDT        df 0            ;GDTR
VCPI_IDT        df 0    ;IDTR
;
VCPI_Entry      dd ?
        dw VCPI_0
;
VCPI_SP dw ?,?
;
GDTVal  df ?
GDTSav  df ?
IDTVal  df 0
IDTSav  df ?
CR0Sav  dd ?
CR3Sav  dd ?

CR0ProtSav      DD      ?       ; MED 10/15/96

;EFlagsSav      dd ?
;
IDTReal dw ?            ;Real mode segment for IDT.
GDTReal dw ?            ;Real mode segment for GDT.
GDTLinear       dd ?,?,-1
MDTLinear       dd ?,?
LDTReal dw ?
LDTLinear       dd ?
LDTStart        dw 0
KernalTSSReal   dw ?            ;Real mode segment for kernal TSS.
PageDIRReal     dw ?            ;Real mode segment for page directory.
PageDirLinear   dd ?,-1,?
PageAliasReal   dw ?            ;Real mode segment for page table alias.
PageAliasLinear dd ?,-1,?
Page1stReal     dw ?            ;Real mode segment for 1st page table entry.
Page1stLinear   dd ?,-1,?
PageDETLinear   dd 0,-1,?
;
LinearEntry     dd ?,?,?
LinearBase      dd ?
LinearLimit     dd ?
;
PageBufferReal  dw ?
PageBufferLinear dd ?
PageInt db size v86CallStruc dup (0)
;
RawSystemFlags  dw 0,0
;
Int2CallCheck   db 8 dup (0)            ;00-07
        db 8 dup (8)            ;08-0F

;; MED 02/16/96, force INT15h to be treated as hardware interrupt
        db 8 dup (0)            ;10-17
;       db      0,0,0,0,0,15h-19,0,0    ;10-17

        db 0,0,0,0,1ch-16,0,0,0 ;18-1F
        db 0,0,0,23h-17,24h-18,0,0,0    ;20-27
        db 70h-28h dup (0)              ;28-6F
        db 8 dup ((70h-8))              ;70-77
        db 100h-78h dup (0)     ;78-FF
;
LastCallBack    dw ?
CallBackTable   db size CallBackStruc*MaxCallBacks dup (0)
ALLCallBack     dw ?
ALLICallBack    dw ?
CallBackList    label byte
ICallBackList   label byte
;; MED 02/16/96
        rept 16+3
;       rept 16+4

        call    RawICallBack
        endm
        rept 16 ;MaxCallBacks
        call    RawCallBack
        endm
CallBackSize    equ     ($-CallBackList)/MaxCallBacks
;
VDiskSig        db 'VDISK V'
VDiskSigLen     equ     $-VDiskSig
VDiskSigVec     equ     19h
VDiskSigOffs    equ     12h
VDiskLoOffs     equ     2ch
VDiskHiOffs     equ     2eh
;
RawStackPos     dd RawStackTotal
RawStackReal    dw ?
;
RetAdd  dw ?,?
StackAdd        dw ?,?
;
DbgSize2Dr      db 0,0,1,0,3
DbgType2Dr      db 0,1,3
;
Dbg     struc
Dbg_Address     dd 0
Dbg_Size        db 0
Dbg_Type        db 0
Dbg_Flags       db 0
        db 0
Dbg     ends
;
DbgTable        db 4*size Dbg dup (0)
;
MaxMemLin       dd 1021 shl 20
MaxMemPhys      dd -1
;
ExtALLSwitch    db 0
NoPassFlag      DB      0       ; nonzero if not passing real mode hardware interrupts up to protect mode
PreAllocSize    DD      0       ; size of VMM disk preallocation
DesiredVMMName  DB      13 DUP (0)      ; VMM name desired by user via CAUSEWAY e-var
FirstUninitPage DW      0

fCR3Flush       label dword
        dw _fCR3Flush,KernalCS
fPhysicalGetPage label dword
        dw _fPhysicalGetPage,KernalCS
fPhysicalGetPages label dword
        dw _fPhysicalGetPages,KernalCS
fRawSimulateINT label dword
        dw _fRawSimulateINT,KernalCS
fRawSimulateFCALL label dword
        dw _fRawSimulateFCALL,KernalCS
fRawSimulateFCALLI label dword
        dw _fRawSimulateFCALLI,KernalCS



;-------------------------------------------------------------------------------
RawVCPIRealMode proc far
;
;Disable hardware INT call-backs.
;

        pop     d[@@RetAdd]
        ;
        mov     bx,offset CallBackTable ;list of call backs.
;; MED 02/16/96
        mov     cx,16+3         ;number of entries to scan.
;       mov     cx,16+4         ;number of entries to scan.

@@6:    test    CallBackFlags[bx],1     ;in use?
        jz      @@7
        test    CallBackFlags[bx],2     ;interupt?
        jz      @@7
        mov     CallBackFlags[bx],0
        pushm   bx,cx
        mov     cx,w[CallBackReal+2+bx] ;get origional vector value.
        mov     dx,w[CallBackReal+bx]
        mov     bl,CallBackNum[bx]      ;get vector number.
        xor     bh,bh
        shl     bx,2
        mov     es:w[bx+0],dx
        mov     es:w[bx+2],cx
        popm    bx,cx
@@7:    add     bx,size CallBackStruc   ;next entry.
        dec     cx
        jnz     @@6
;
;Move the GDT/LDT back down into conventional memory.
;

        cmp     GDTLinear+8,-1
        jz      @@NoGDTMove
        mov     eax,GDTLinear+8
        mov     GDTLinear,eax
        mov     d[GDTVal+2],eax
        mov     d[VCPI_GDT+2],eax
        mov     ah,1
        int     16h             ;force LDT/GDT re-load.
;
;Check if page 1st is in extended memory and move back to conventional if it is.
;
@@NoGDTMove:

        cmp     Page1stLinear+4,-1
        jz      @@No1stMove
        push    ds
        mov     esi,Page1stLinear
        mov     edi,Page1stLinear+4
        push    es
        pop     ds
        mov     ecx,4096/4
        cld
        db 67h
        rep     movsd
        pop     ds
        mov     eax,Page1stLinear+4
        mov     Page1stLinear,eax
        mov     esi,PageDIRLinear
        mov     eax,0
        mov     ebx,Page1stLinear+8
        and     ebx,not 4095
        or      ebx,111b
        mov     es:[esi+eax*4],ebx
        call    CR3Flush
;
;Check if page dir ALIAS is in extended memory and move back to conventional if
;it is.
;
@@No1stMove:

        cmp     PageALIASLinear+4,-1
        jz      @@NoALIASMove
        push    ds
        mov     esi,PageALIASLinear
        mov     edi,PageALIASLinear+4
        push    es
        pop     ds
        mov     ecx,4096/4
        cld
        db 67h
        rep     movsd
        pop     ds
        mov     eax,PageALIASLinear+4
        mov     PageALIASLinear,eax
        mov     esi,PageDIRLinear
        mov     eax,1023
        mov     ebx,PageALIASLinear+8
        and     ebx,not 4095
        or      ebx,111b
        mov     es:[esi+eax*4],ebx
        call    CR3Flush
;
;Check if page DIR is in extended memory and move back to conventional if it is.
;
@@NoALIASMove:

        cmp     PageDIRLinear+4,-1
        jz      @@NoDIRMove
        push    ds
        mov     esi,PageDIRLinear
        mov     edi,PageDIRLinear+4
        push    es
        pop     ds
        mov     ecx,4096/4
        cld
        db 67h
        rep     movsd
        pop     ds
        mov     eax,PageDIRLinear+4
        mov     PageDIRLinear,eax
        mov     eax,PageDIRLinear+8
        mov     VCPI_CR3,eax
        call    CR3Flush
;
;Release VCPI memory.
;
@@NoDIRMove:

; MED 10/31/95
; switch to PL0 and set IDT to point to benign memory
;  so stupid Ensoniq VIVO driver can punch holes in the IDT without
;  causing an exception.
; Then switch back to PL3
        mov     WORD PTR [IDTVal],03ffh
        mov     eax,PageBufferLinear
        mov     DWORD PTR [IDTVal+2],eax
        pushad
        mov     DWORD PTR [@@StackAdd],esp
        mov     WORD PTR [@@StackAdd+4],ss
        call    RAWPL32PL0
        lidt    FWORD PTR [IDTVal]
        mov     edx,DWORD PTR [@@StackAdd]
        mov     cx,WORD PTR [@@StackAdd+4]
        call    RAWPL02PL3
        popad

        call    VCPIRelExtended ;release VCPI memory.

;Release XMS memory.
;

        call    RAWRelXMS       ;release XMS memory.
;
;Release INT 15h memory.
;

        call    Int15Rel        ;release int 15 vectors.
;
;Restore A20 state.
;

        call    A20Handler
;
;Switch back to real mode.
;

        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           ;/
        ;
        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:  mov     ax,KernalSwitchPL0
        mov     ss,ax
        ;
        mov     ax,MainDS
        mov     ds,ax
        assume ds:_cwMain
        cmp     ProtectedType,1 ;VCPI?
        mov     ax,KernalDS
        mov     ds,ax
        assume ds:_cwRaw
        jz      @@VCPI
;
;Use raw mode to switch back.
;
@@RAW:  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 @@RAW0,seg _cwRaw    ;instruction pre-fetch & load CS.
@@RAW0: mov     ax,_cwRaw               ;set everything up for real mode again.
        mov     ds,ax           ;/
        mov     es,ax           ;/
        mov     fs,ax
        mov     gs,ax
        mov     ax,_cwStack
        mov     ss,ax           ;/
        mov     esp,offset _cwStackEnd-4
        mov     eax,CR3Sav
        mov     cr3,eax
        lidt    IDTSav          ;restore old IDT 0(3ff)
        lgdt    GDTSav
;       push    EFlagsSav
;       popfd
        jmp     @@InReal
;
;Use VCPI mode to switch back.
;
@@VCPI: xor     eax,eax
        mov     ax,_cwRaw
        push    eax             ;GS
        push    eax             ;FS
        push    eax             ;DS
        push    eax             ;ES
        mov     ax,_cwStack
        push    eax             ;SS
        mov     ax,offset _cwStackEnd-4
        push    eax             ;ESP
        push    eax             ;EFLags (reserved for)
        xor     eax,eax
        mov     ax,_cwRaw
        push    eax             ;CS
        mov     ax,offset @@VCPI0
        push    eax             ;EIP
        mov     ax,KernalZero
        mov     es,ax
        xor     esi,esi
        mov     si,_cwRaw
        shl     esi,4
        add     esi,offset @@Call5
        mov     ax,w[VCPI_Entry+4]
        mov     es:[esi+4],ax
        mov     eax,d[VCPI_Entry]
        mov     es:[esi],eax
        mov     ax,KernalZero
        mov     ds,ax
        mov     ax,0DE0Ch
        assume ds:nothing
        call    cs:f[@@Call5]   ;switch back.
        assume ds:_cwRaw
@@Call5:        ;
        df ?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -