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

📄 raw_vcpi.asm

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:

;-------------------------------------------------------------------------------
;
;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
        pushm   ds,es,fs,gs
        mov     ax,KernalDS             ;make our data addresable.
        mov     ds,ax           ;/
        mov     ax,KernalZero
        mov     fs,ax
        push    d[@@tVCPI_SP]
        push    d[@@IntAdd]
        push    w[@@CallAdd]
        push    w[@@ourstack]
        mov     w[@@ourstack],0
;
;setup the real mode stack.
;
        mov     ax,es:Real_SP[edi]      ;check if stack is being
        or      ax,es:Real_SS[edi]      ;supplied.
        jnz     @@GotStack
;
;Caller isn't supplying a stack so we will.
;
        mov     eax,RawStackPos
        sub     RawStackPos,RawStackDif ;update for re-entry.
        mov     es:Real_SP[edi],ax
        xor     esi,esi
        mov     si,RawStackReal
        mov     es:Real_SS[edi],si
        or      w[@@ourstack],-1
;
;Point to the real mode stack.
;
@@GotStack:     movzx   esi,es:Real_SS[edi]
        movzx   eax,es:Real_SP[edi]
        sub     eax,(4+4)+(4+4)
        mov     w[@@tVCPI_SP+2],si
        mov     w[@@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    RawSystemFlags,1
        jz      @@noextendstack
        movzx   eax,ax
@@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      @@NoStacked
        movzx   eax,cx
        shl     eax,1
        add     ebp,eax
@@copystack0:   sub     ebp,2
        sub     esi,2
        mov     ax,[ebp]
        mov     fs:[esi],ax
        dec     cx
        jnz     @@copystack0
;
;Put flags onto the real mode stack.
;
@@NoStacked:    mov     ebp,esp
        test    RawSystemFlags,1
        jz      @@Its32
        movzx   ebp,bp
@@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     @@NoIF
        and     ax,1111110011111111b    ;clear Trap and INT flag.
@@NoIF: sub     esi,2
        mov     fs:[esi],ax
        ;
        ;See if the CS:IP is supplied or needs fetching.
        ;
        or      bh,bh
        jz      @@IsInt
        ;
        mov     cx,es:Real_CS[edi]
        shl     ecx,16
        mov     cx,es:Real_IP[edi]
        mov     w[@@calladd],offset @@fcall
        cmp     bh,2
        jnz     @@notint
        mov     w[@@calladd],offset @@fcalli
        jmp     @@notint
        ;
@@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      @@c3
        sub     bl,al
        shl     bx,3            ;*8
        mov     ax,bx
        shl     bx,1            ;*16
        add     bx,ax           ;*24
        add     bx,offset CallBackTable
        test    CallBackFlags[bx],128   ;this entry in use?
        jz      @@c3
        mov     ecx,CallBackReal[bx]
        jmp     @@c2
        ;
@@c3:   ;Get interupt address to put on stack.
        ;
        mov     ecx,fs:d[bp]
        ;
@@c2:   mov     w[@@calladd],offset @@int
        ;
@@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
        pushm   esi,edi,ds,es
        xchg    esi,edi
        pushm   es,fs
        popm    ds,es
        mov     ecx,(4+4+4+4+4+4+4+4+2+2+2+2+2+2)/4
        db 67h
        rep     movsd
        popm    esi,edi,ds,es
;
;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     cs:w[@@IntAdd]  ;lose dummy.
        pop     es
        pop     ds
        pop     fs
        pop     gs
        pop     cs:w[@@IntAdd]  ;lose dummy.
        ;
        pop     cs:d[@@IntAdd]
        jmp     cs:w[@@calladd]
        ;
@@fcall:        popf
        call    cs:d[@@IntAdd]
        jmp     @@Back
        ;
@@fcalli:       ;
@@int:  call    cs:d[@@IntAdd]
        ;
@@Back: pushf
        cli
        cld
        pop     cs:w[@@IntAdd]
        and     cs:w[@@IntAdd],0000110011010101b
;
;Switch back to old stack.
;
        mov     ss,cs:w[@@tVCPI_SP+2]
        mov     sp,cs:w[@@tVCPI_SP]
;
;Save all registers.
;
        push    cs:w[@@IntAdd]  ;save dummy.
        push    gs
        push    fs
        push    ds
        push    es
        push    cs:w[@@IntAdd]  ;save flags.
        pushad
;
;Make our data addresable again and store stack values.
;
        mov     ax,_cwRaw
        mov     ds,ax
        assume ds:_cwRaw
        mov     w[@@tVCPI_SP],sp
        mov     w[@@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[@@tVCPI_SP+2]
        shl     esi,4
        movzx   eax,w[@@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.
;

        pushm   esi,edi,ds
        push    fs
        pop     ds
        mov     ecx,(4+4+4+4+4+4+4+4+2+2+2+2+2+2)/4
        db 67h
        rep     movsd
        popm    esi,edi,ds
        mov     bx,[esp+(2+2+2+2)+(4+4+4+4+4+4+4+4)+(4+4+2)+2]
        and     bx,1111001100101010b
        or      es:Real_Flags[edi],bx
        ;
        cmp     w[@@ourstack],0
        jz      @@nostackadjust
        add     RawStackPos,RawStackDif ;update for re-entry.
@@nostackadjust:
        pop     w[@@ourstack]
        pop     w[@@CallAdd]
        pop     d[@@IntAdd]
        pop     d[@@tVCPI_SP]
        ;
        popm    ds,es,fs,gs
        popad
        popf
        clc
        ;
        pop     bx
        pop     cx
        ret
@@IntAdd:       ;
        dd ?
@@CallAdd:      ;
        dw ?
@@tVCPI_SP:     ;
        dd ?
@@ourstack:     ;
        dw 0
RAWSimulate     endp


;-------------------------------------------------------------------------------
RAWCallBack     proc    near
        pushf
        cli
        ;
        ;Check if Windows enhanced mode has been started.
        ;
        assume ds:nothing
        cmp     cs:InWindows,0
        assume ds:_cwRaw
        jz      @@Normal
        popf
        retf
        ;
@@Normal:       pushm   ax,bp,ds
        mov     ax,_cwRaw
        mov     ds,ax
        mov     bp,sp
        mov     ax,[bp+2+2+2+2] ;get return address
        mov     RetAdd,ax
        mov     ax,[bp+2+2+2]   ;get flags
        mov     [bp+2+2+2+2],ax ;ovewrite return address.
        mov     StackAdd,bp
        add     StackAdd,2+2+2+2+2      ;correct for stacked registers.
        mov     StackAdd+2,ss
        popm    ax,bp,ds
        add     sp,2            ;remove local return address.
        ;
        pushm   eax,ebx,ecx,edx,esi,edi,ebp,ds,es,fs,gs
        mov     ax,_cwRaw
        mov     ds,ax           ;make our data addresable.
        mov     es,ax
        mov     fs,ax
        mov     gs,ax
        mov     VCPI_SP,sp
        mov     VCPI_SP+2,ss
        ;
        ;Check if this call back is int &| busy.
        ;
        mov     ax,RetAdd               ;get return address.
        sub     ax,CallBackSize ;back to start of call back entry.
        sub     ax,offset CallBackList  ;offset from start of list.
        xor     dx,dx
        mov     bx,CallBackSize
        div     bx              ;entry number.
        mov     bx,size CallBackStruc
        mul     bx              ;get offset into table.
        mov     bx,offset CallBackTable
        add     bx,ax           ;point to this entry.
        ;
        ;switch to protected mode.
        ;
        mov     cx,KernalSS
        mov     edx,RawStackPos
        sub     RawStackPos,RawStackDif
        call    Real2Protected
        ;
        mov     ax,RetAdd               ;get return address.
        sub     ax,CallBackSize ;back to start of call back entry.
        sub     ax,offset CallBackList  ;offset from start of list.
        jz      @@zero
        xor     dx,dx
        mov     bx,CallBackSize
        div     bx              ;entry number.
@@zero: mov     bx,size CallBackStruc
        mul     bx              ;get offset into table.
        mov     bx,offset CallBackTable
        add     bx,ax           ;point to this entry.
        movzx   esi,w[VCPI_SP+2]        ;point to stacked registers.
        shl     esi,4
        movzx   eax,w[VCPI_SP]
        add     esi,eax
        mov     ax,KernalZero   ;/
        mov     fs,ax           ;/
        ;
        les     edi,CallBackRegs[bx]    ;get register structure.
        mov     ax,fs:[esi]
        mov     es:Real_GS[edi],ax
        mov     ax,fs:[esi+2]
        mov     es:Real_FS[edi],ax
        mov     ax,fs:[esi+4]
        mov     es:Real_ES[edi],ax
        mov     ax,fs:[esi+6]
        mov     es:Real_DS[edi],ax
        mov     eax,fs:[esi+8]
        mov     es:Real_EBP[edi],eax
        mov     eax,fs:[esi+12]
        mov     es:Real_EDI[edi],eax
        mov     eax,fs:[esi+16]
        mov     es:Real_ESI[edi],eax
        mov     eax,fs:[esi+20]
        mov     es:Real_EDX[edi],eax
        mov     eax,fs:[esi+24]
        mov     es:Real_ECX[edi],eax
        mov     eax,fs:[esi+28]
        mov     es:Real_EBX[edi],eax
        mov     eax,fs:[esi+32]
        mov     es:Real_EAX[edi],eax
        mov     ax,fs:[esi+36]
        mov     es:Real_Flags[edi],ax
        mov     ax,RetAdd
        mov     es:Real_IP[edi],ax
        mov     ax,_cwRaw
        mov     es:Real_CS[edi],ax
        mov     ax,StackAdd
        mov     es:Real_SP[edi],ax
        mov     ax,StackAdd+2
        mov     es:Real_SS[edi],ax
        ;
        test    RawSystemFlags,1
        jz      @@Use32Bit12
        mov     ax,w[CallBackProt+4+bx]
        mov     w[@@CallB0+2],ax
        mov     eax,d[CallBackProt+bx]
        mov     w[@@CallB0],ax

⌨️ 快捷键说明

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