📄 interrup.asm
字号:
pop eax
add ebx,offset ExceptionTable
;
cmp al,14 ;Special case for 14
; jnz @@Normal
je Special14 ; MED 01/17/96
cmp al,20h
jc @@Normal
stc ; flag error
pop eax
mov ax,8021h ; flag invalid value
push eax
jmp @@GotVect ; don't set vector
Special14:
cmp w[OldExcep14+4],0 ;Virtual memory active?
jz @@Normal
;
;Vector 14 and VMM is still installed.
;
mov d[OldExcep14],edx
mov w[OldExcep14+4],cx
jmp @@GotVect
@@Normal: ;
clc ; MED 01/17/96, flag no error
mov [ebx],edx ;set offset.
mov [ebx+4],cx ;set segment selector.
@@GotVect: ;
; popm eax,ebx,ecx,edx,esi,edi,ebp,ds,es,fs,gs
pop eax
pop ebp
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop gs
pop fs
pop es
pop ds
ret
RawSetEVector endp
;-------------------------------------------------------------------------------
;
;Allocate a real mode call back address.
;
;On Entry:-
;
;DS:ESI - Protected mode code.
;ES:EDI - Real mode register structure.
;
;On Exit:-
;
;Carry set on error, else,
;
;CX:DX - Real mode address allocated.
;
RAWGetCallBack proc near
call RAWCopyCheck
;
pushm eax,ebx,esi,edi,ebp,ds,es
mov ax,ds
push ax
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
pop ax
;
;;MED 02/16/96
mov ebx,offset CallBackTable+((size CallBackStruc)*(16+3))
mov ecx,MaxCallBacks-(16+3)
mov edx,16+3
; mov ebx,offset CallBackTable+((size CallBackStruc)*(16+4))
; mov ecx,MaxCallBacks-(16+4)
; mov edx,16+4
@@0: test CallBackFlags[ebx],1 ;this one in use?
jz @@1
add ebx,size CallBackStruc
inc edx
dec ecx
jnz @@0
jmp @@9
;
@@1: pushad
xor eax,eax
mov cx,1
int 31h
mov w[CallBackStackSel+ebx],ax
popad
jc @@9
pushad
mov bx,w[CallBackStackSel+ebx]
mov eax,8
xor ecx,ecx
or edx,-1
int 31h
popad
;
mov w[CallBackProt+4+ebx],ax ;store protected mode code address.
mov d[CallBackProt+0+ebx],esi ;/
mov w[CallBackRegs+4+ebx],es ;store register table address.
mov d[CallBackRegs+0+ebx],edi ;/
mov ax,CallBackSize
mul dx
mov esi,offset CallBackList
movzx eax,ax
add esi,eax ;index list of calls.
mov CallBackOff[ebx],si ;store call back address.
mov CallBackFlags[ebx],1 ;flag this entry in use.
mov ax,_cwRaw
mov cx,ax ;get real mode code seg.
mov dx,si ;get real mode offset.
clc
jmp @@10
;
@@9: stc
@@10: popm eax,ebx,esi,edi,ebp,ds,es
ret
assume ds:_cwDPMIEMU
RAWGetCallBack endp
;-------------------------------------------------------------------------------
;
;Release a previously allocated real mode call back address.
;
;On Entry:-
;
;CX:DX - Real mode call back address.
;
RAWRelCallBack proc near
call RAWCopyCheck
;
pushad
pushm ds,es,fs,gs
push ax
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
pop ax
;
mov esi,offset CallBackTable
mov ebx,MaxCallBacks
@@0: test CallBackFlags[esi],1
jz @@1
cmp dx,CallBackOff[esi]
jnz @@1
mov CallBackFlags[esi],0
mov bx,CallBackStackSel[esi]
mov ax,1
int 31h
clc
jmp @@2
;
@@1: add esi,size CallBackStruc
dec ebx
jnz @@0
stc
;
@@2: popm ds,es,fs,gs
popad
ret
assume ds:_cwDPMIEMU
RAWRelCallBack endp
;-------------------------------------------------------------------------------
;
;Need to retrieve the interupt number.
;
IntHandler proc near
pushm ds,eax
mov ax,DpmiEmuDS ;make our data addresable.
mov ds,ax ;/
movzx esp,sp ;our stack never >64k.
mov eax,[esp+(4+4)] ;get return address.
sub eax,offset InterruptHandler
shr eax,3 ;convert it to an interrupt number.
mov ExceptionIndex,eax ;/
;
;Check if this is an exception or interrupt (any error code)
;
cmp esp,tPL0StackSize-4-((4+4)+(4)+(4)+(4+4+4)+(4+4))
; | | | | |
; EAX:DS --------------------/ | | | |
; | | | |
; Return address -----------------/ | | |
; | | |
; Error code -------------------------/ | |
; | |
; EIP:CS:Eflags ----------------------------/ |
; |
; ESP:SS ------------------------------------------/
;
jnz @@NoCode
and w[esp+(4+4)+(4)+(4)+(4+4)],0011111111010101b
; MED 12/02/95
; check if Exception Index is 0dh
; if so and instruction at CS:EIP is:
; mov eax,cr0 [0f 20 c0] or
; mov cr0,eax [0f 22 c0] or
; mov eax,cr3 [0f 20 d8] or
; mov cr3,eax [0f 22 d8]
; then emulate it here and return
; MED 11/12/98, emulate RDMSR [0f 32]
; MED 04/05/99, emulate WBINVD [0f 09]
; WRMSR [0f 30]
; mov eax,cr4 [0f 20 e0]
; mov cr4,eax [0f 22 e0]
; MED 05/02/2000, mov ebx,cr4 [0f 20 e3]
; mov eax,cr2 [0f 20 d0]
push ds
cmp eax,0dh
jne mednoem ; not a GPF
mov ax,ss:[esp+(4+4)+(4)+(4+4)+4] ; ax==original CS
; verr ax ; check for looping lockup invalid value
; jnz mednoem
mov ds,ax
mov eax,ss:[esp+(4+4)+(4)+(4)+4] ; eax==original EIP
cmp BYTE PTR ds:[eax],0fh ; first opcode byte
jne mednoem ; no match
cmp WORD PTR ds:[eax+1],0c020h ; mov eax,cr0
jne med2
mov eax,cr0
mov ss:[esp+4],eax ; update original eax with cr0 value
jmp medemu
med2:
cmp WORD PTR ds:[eax+1],0c022h ; move cr0,eax
jne med3 ; no match
mov eax,ss:[esp+4] ; get original eax value
mov cr0,eax ; update cr0 value with original eax
jmp medemu
med3:
cmp WORD PTR ds:[eax+1],0d820h ; mov eax,cr3
jne med4
mov eax,cr3
mov ss:[esp+4],eax ; update original eax with cr3 value
jmp medemu
med4:
cmp WORD PTR ds:[eax+1],0d822h ; move cr3,eax
jne med5 ; no match
mov eax,ss:[esp+4] ; get original eax value
mov cr3,eax ; update cr3 value with original eax
jmp medemu
med5:
cmp WORD PTR ds:[eax+1],0e022h ; move cr4,eax
jne med6 ; no match
mov eax,ss:[esp+4] ; get original eax value
.586
mov cr4,eax ; update cr4 value with original eax
jmp medemu
med6:
cmp WORD PTR ds:[eax+1],0e020h ; mov eax,cr4
jne med7
.586
mov eax,cr4
mov ss:[esp+4],eax ; update original eax with cr4 value
jmp medemu
med7:
cmp BYTE PTR ds:[eax+1],9 ; WBINVD
jne med8
.586
wbinvd
mov eax,2
jmp medemu2
med8:
cmp BYTE PTR ds:[eax+1],30h ; WRMSR
jne med9
.586
mov eax,ss:[esp+4] ; get original eax value
wrmsr
mov eax,2
jmp medemu2
med9:
cmp BYTE PTR ds:[eax+1],32h ; RDMSR
jne med10
; push eax
.586
rdmsr
; DB 0fh ; RDMSR instruction
; DB 32h
; mov ss:[esp+8],eax ; update original eax value
; pop eax
mov ss:[esp+4],eax ; update original eax value
mov eax,2
jmp medemu2
med10:
cmp WORD PTR ds:[eax+1],0e320h ; mov ebx,cr4
jne med11 ; no match
.586
mov ebx,cr4
jmp medemu
med11:
cmp WORD PTR ds:[eax+1],0d020h ; mov eax,cr2
jne mednoem
mov eax,cr2
mov ss:[esp+4],eax ; update original eax with cr2 value
; jmp medemu
medemu:
mov eax,3
medemu2:
add ss:[esp+(4+4)+(4)+(4)+4],eax ; adjust EIP past emulated instruction
pop ds
popm ds,eax ; restore original ds,eax
add esp,8 ; flush return address and error code off stack
iretd
mednoem:
pop ds
mov eax,[esp+(4+4)+(4)] ;get error code.
mov ExceptionCode,eax ;/
mov eax,[esp+(4+4)+(4)+(4)+(4+4)] ;Get flags.
or eax,65536
mov ExceptionFlags,eax ;Let dispatch know its an exception.
mov eax,cr2 ;Grab this now to save more PL
mov ExceptionCR2,eax ;switches for page faults.
popm ds,eax
add esp,4 ;skip error code.
jmp @@SortedCode2
@@NoCode: and w[esp+(4+4)+(4)+(4+4)],0011111111010101b
mov eax,[esp+(4+4)+(4)+(4+4)] ;Get flags.
and eax,not 65536
mov ExceptionFlags,eax
cmp ExceptionIndex,0
jz @@ForceException
cmp ExceptionIndex,1 ;int 1
jnz @@SortedCode
@@ForceException:
; or ExceptionFlags,65535 ;force an exception.
or ExceptionFlags,65536 ;force an exception.
@@SortedCode: popm ds,eax
@@SortedCode2: add esp,4 ;skip return address.
;
;Check which stack we should switch back to.
;
pushm ds,eax
cmp w[esp+(4+4)+(4+4+4)+(4)],KernalSS
jz KernalStack ;Already on system stack?
mov ax,DpmiEmuDS
mov ds,ax
test ExceptionFlags,65536 ;exception?
jnz KernalStack
;
push ebx
mov ebx,ExceptionIndex
mov ax,KernalDS ;make our data addresable.
mov ds,ax
assume ds:_cwRaw
cmp b[ebx+Int2CallCheck],0 ;Hardware INT?
pop ebx
assume ds:_cwDPMIEMU
jnz KernalStack
jmp IntStack
IntHandler endp
;-------------------------------------------------------------------------------
;
;It's a user stack and its not an exception or hardware interupt so switch back
;to the origional stack via a system stack to allow re-entrancy if origional
;stack needs to be fetched from disk.
;
IntStack proc near
popm ds,eax
;
;Get new stack address.
;
pushm eax,ebx,ds
mov ax,KernalDS ;make our data addresable.
mov ds,ax
assume ds:_cwRaw
mov ebx,RawStackPos ;get next stack address.
sub RawStackPos,RawStackDif
mov ax,KernalSS
mov ds,ax
assume ds:nothing
;
;Put old details onto new stack.
;
test cs:DpmiEmuSystemFlags,1
jz @@iUse32
mov eax,[esp+(4+4+4)+(4+4+4+4)]
sub ebx,2
mov [ebx],ax ;SS
mov eax,[esp+(4+4+4)+(4+4+4)]
sub ebx,2
mov [ebx],ax ;ESP
mov eax,[esp+(4+4+4)+(4+4)]
sub ebx,2
mov [ebx],ax ;EFlags
mov eax,[esp+(4+4+4)+(4)]
sub ebx,2
mov [ebx],ax ;CS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -