📄 interrup.asm
字号:
mov eax,[esp+(4+4+4)+(0)]
sub ebx,2
mov [ebx],ax ;EIP
jmp @@iUse0
;
@@iUse32: mov eax,[esp+(4+4+4)+(4+4+4+4)]
sub ebx,4
mov [ebx],eax ;SS
mov eax,[esp+(4+4+4)+(4+4+4)]
sub ebx,4
mov [ebx],eax ;ESP
mov eax,[esp+(4+4+4)+(4+4)]
sub ebx,4
mov [ebx],eax ;EFlags
mov eax,[esp+(4+4+4)+(4)]
sub ebx,4
mov [ebx],eax ;CS
mov eax,[esp+(4+4+4)+(0)]
sub ebx,4
mov [ebx],eax ;EIP
;
@@iUse0: ;Put new details into current stack.
;
mov eax,offset @@Int
mov [esp+(4+4+4)+(0)],eax ;EIP
xor eax,eax
mov ax,DpmiEmuCS
mov [esp+(4+4+4)+(4)],eax ;CS
pushfd
pop eax
mov [esp+(4+4+4)+(4+4)],eax ;EFlags
mov [esp+(4+4+4)+(4+4+4)],ebx ;ESP
xor eax,eax
mov ax,KernalSS
mov [esp+(4+4+4)+(4+4+4+4)],eax ;SS
popm eax,ebx,ds
assume ds:_cwDPMIEMU
iretd
;
@@Int: ;Now switch back to origional stack.
;
assume ds:nothing
push cs:ExceptionIndex ;need to know the INT number.
pushm eax,ebx,esi,ds
test cs:DpmiEmuSystemFlags,1
jz @@i2Use32
xor ebx,ebx
mov ax,ss
mov ds,ax
mov bx,sp
lss sp,[ebx+(4+4+4+4+4)+(2+2+2)] ;get origional stack again.
mov ax,[ebx+(4+4+4+4+4)+(2+2)] ;get flags.
push ax
mov ax,[ebx+(4+4+4+4+4)+(2)] ;get CS
push ax
mov ax,[ebx+(4+4+4+4+4)+(0)] ;get IP
push ax
xor eax,eax
mov ax,[ebx+(4+4+4+4+4)+(2+2)] ;get flags again.
and ax,1111110011111111b ;lose IF & TF
push eax ;int handler flags.
jmp @@i2Use0
;
@@i2Use32: mov ax,ss
mov ds,ax
mov ebx,esp
lss esp,[ebx+(4+4+4+4+4)+(4+4+4)] ;get origional stack again.
mov eax,[ebx+(4+4+4+4+4)+(4+4)] ;get flags.
push eax
mov eax,[ebx+(4+4+4+4+4)+(4)] ;get CS
push eax
mov eax,[ebx+(4+4+4+4+4)+(0)] ;get IP
push eax
mov eax,[ebx+(4+4+4+4+4)+(4+4)] ;get flags again.
and ax,1111110011111111b ;lose IF & TF
push eax ;int handler flags.
;
@@i2Use0: mov eax,[ebx+(4+4+4+4)] ;get INT index.
shl eax,1
mov esi,eax
shl eax,1
add esi,eax ;*6 for index into table.
add esi,offset InterruptTable
xor eax,eax
mov ax,cs:[esi+4] ;get int handler CS
push eax
mov eax,cs:[esi] ;get INT handler EIP.
push eax
mov eax,[ebx+(4+4+4)] ;EAX
push eax
mov eax,[ebx+(4+4)] ;EBX
push eax
mov eax,[ebx+(4)] ;ESI
push eax
mov eax,[ebx+(0)] ;DS
push eax
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
add RawStackPos,RawStackDif
assume ds:_cwDPMIEMU
popm eax,ebx,esi,ds
iretd ;pass control to INT handler.
IntStack endp
;-------------------------------------------------------------------------------
;
;Either we were already on the system stack or we have an exception or hardware
;interupt on our hands. Either way we need to switch to another piece of the
;system stack to make sure we're using a legitimate one.
;
KernalStack 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
;
@@Update: ;Put old details onto new stack.
;
test cs:DpmiEmuSystemFlags,1
jz @@Use32
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
mov eax,[esp+(4+4+4)+(0)]
sub ebx,2
mov [ebx],ax ;EIP
jmp @@Use0
;
@@Use32: mov eax,[esp+(4+4+4)+(4+4+4+4)]
sub ebx,4
mov [ebx],eax ;SS
mov eax,[esp+(4+4+4)+(4+4+4)]
sub ebx,4
mov [ebx],eax ;ESP
mov eax,[esp+(4+4+4)+(4+4)]
sub ebx,4
mov [ebx],eax ;EFlags
mov eax,[esp+(4+4+4)+(4)]
sub ebx,4
mov [ebx],eax ;CS
mov eax,[esp+(4+4+4)+(0)]
sub ebx,4
mov [ebx],eax ;EIP
;
@@Use0: ;Put new details into current stack.
;
mov eax,offset IntDispatch
mov [esp+(4+4+4)+(0)],eax ;EIP
xor eax,eax
mov ax,DpmiEmuCS
mov [esp+(4+4+4)+(4)],eax ;CS
pushfd
pop eax
mov [esp+(4+4+4)+(4+4)],eax ;EFlags
mov [esp+(4+4+4)+(4+4+4)],ebx ;ESP
xor eax,eax
mov ax,KernalSS
mov [esp+(4+4+4)+(4+4+4+4)],eax ;SS
popm eax,ebx,ds
assume ds:_cwDPMIEMU
;
;Pass control to interupt dispatcher.
;
iretd
KernalStack endp
;-------------------------------------------------------------------------------
;
;Direct control to exception or interupt handler.
;
IntDispatch proc near
pushm eax,esi,edi,ds
mov ax,DpmiEmuDS
mov ds,ax
and w[ExceptionFlags],1111110011111111b
mov esi,ExceptionIndex ;Get the exception number.
add esi,esi ;*2
mov eax,esi
add esi,esi ;*4
add esi,eax ;*6
test ExceptionFlags,65536
jnz @@Excep
;
;Dispatch normal interrupt.
;
add esi,offset InterruptTable
test DpmiEmuSystemFlags,1
jz @@Use32Bit14
mov eax,[esi]
mov d[@@Call2],eax
mov ax,[esi+4]
mov w[@@Call2+4],ax
mov eax,offset @@Resume
mov w[@@Call20],ax
mov w[@@Call20+2],cs
popm eax,esi,edi,ds
assume ds:nothing
push cs:w[ExceptionFlags] ;EFlags before entry.
push cs:w[@@Call20+2] ;CS
push cs:w[@@Call20] ;EIP
jmp cs:f[@@Call2]
assume ds:_cwDPMIEMU
;
@@Use32Bit14: mov eax,[esi]
mov d[@@Call2],eax
mov ax,[esi+4]
mov w[@@Call2+4],ax
mov d[@@Call20],offset @@Resume
mov w[@@Call20+4],cs
popm eax,esi,edi,ds
assume ds:nothing
push cs:d[ExceptionFlags] ;EFlags before entry.
push cs:d[@@Call20+4] ;CS
push cs:d[@@Call20] ;EIP
jmp cs:f[@@Call2]
assume ds:_cwDPMIEMU
;
;; MED 08/13/96
; nop ; make debugger EIP adjustment from debug int benign?
@@Resume: ;Return from normal int.
;
pushfd
cli ;stop interupts interfering.
pushm eax,ebx,ds
mov ax,ss
mov ds,ax
mov ebx,esp
assume ds:nothing
test cs:DpmiEmuSystemFlags,1
assume ds:_cwDPMIEMU
jz @@Use32
;
movzx ebx,bx
lss sp,d[ebx+(4+4+4+4)+(2+2+2)] ;get old stack address.
and w[ebx+(4+4+4+4)+(2+2)],0000011100000000b ;retain IF & TF.
and w[ebx+(4+4+4)],1111100011111111b ;lose IF & TF.
mov ax,[ebx+(4+4+4)]
or ax,[ebx+(4+4+4+4)+(2+2)]
push ax ;EFlags.
mov ax,[ebx+(4+4+4+4)+(2)]
push ax ;CS
mov ax,[ebx+(4+4+4+4)+(0)]
push ax ;EIP
mov eax,[ebx+(4+4)]
push eax ;EAX
mov eax,[ebx+(4)]
push eax ;EBX
mov eax,[ebx+(0)]
push eax ;DS
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
add RawStackPos,RawStackDif ;update next stack.
assume ds:_cwDPMIEMU
popm eax,ebx,ds
db 66h
iret
;
@@Use32: lss esp,f[ebx+(4+4+4+4)+(4+4+4)] ;get old stack address.
and w[ebx+(4+4+4+4)+(4+4)],0000011100000000b ;retain IF & TF.
and w[ebx+(4+4+4)],1111100011111111b ;lose IF & TF.
mov eax,[ebx+(4+4+4)]
or eax,[ebx+(4+4+4+4)+(4+4)]
push eax ;EFlags.
mov eax,[ebx+(4+4+4+4)+(4)]
push eax ;CS
mov eax,[ebx+(4+4+4+4)+(0)]
push eax ;EIP
mov eax,[ebx+(4+4)]
push eax ;EAX
mov eax,[ebx+(4)]
push eax ;EBX
mov eax,[ebx+(0)]
push eax ;DS
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
add RawStackPos,RawStackDif ;update next stack.
assume ds:_cwDPMIEMU
popm eax,ebx,ds
iretd
;
@@Excep: ;Dispatch exception.
;
add esi,offset ExceptionTable
test DpmiEmuSystemFlags,1
jz @@eUse32Bit14
mov eax,[esi]
mov d[@@Call2],eax
mov ax,[esi+4]
mov w[@@Call2+4],ax
mov eax,offset @@ResumeExp
mov w[@@Call20],ax
mov w[@@Call20+2],cs
popm eax,esi,edi,ds
assume ds:nothing
push cs:w[ExceptionCode] ;EFlags before entry.
push cs:w[@@Call20+2] ;CS
push cs:w[@@Call20] ;EIP
jmp cs:f[@@Call2]
assume ds:_cwDPMIEMU
;
@@eUse32Bit14: mov eax,[esi]
mov d[@@Call2],eax
mov ax,[esi+4]
mov w[@@Call2+4],ax
mov d[@@Call20],offset @@ResumeExp
mov w[@@Call20+4],cs
popm eax,esi,edi,ds
assume ds:nothing
push cs:d[ExceptionCode] ;EFlags before entry.
push cs:d[@@Call20+4] ;CS
push cs:d[@@Call20] ;EIP
jmp cs:f[@@Call2]
assume ds:_cwDPMIEMU
;
@@ResumeExp: ;Return from exception.
;
cli
assume ds:nothing
test cs:DpmiEmuSystemFlags,1
assume ds:_cwDPMIEMU
jz @@ExpUse32
;
add sp,2
pushfd
pushm eax,ebx,ds
mov ax,ss
mov ds,ax
mov ebx,esp
movzx ebx,bx
lss sp,d[ebx+(4+4+4+4)+(2+2+2)] ;get old stack address.
mov ax,[ebx+(4+4+4+4)+(2+2)]
push ax ;EFlags.
mov ax,[ebx+(4+4+4+4)+(2)]
push ax ;CS
mov ax,[ebx+(4+4+4+4)+(0)]
push ax ;EIP
mov eax,[ebx+(4+4)]
push eax ;EAX
mov eax,[ebx+(4)]
push eax ;EBX
mov eax,[ebx+(0)]
push eax ;DS
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
add RawStackPos,RawStackDif ;update next stack.
assume ds:_cwDPMIEMU
popm eax,ebx,ds
db 66h
iret
;
@@ExpUse32: add esp,4
pushfd
pushm eax,ebx,ds
mov ax,ss
mov ds,ax
mov ebx,esp
lss esp,f[ebx+(4+4+4+4)+(4+4+4)] ;get old stack address.
mov eax,[ebx+(4+4+4+4)+(4+4)]
push eax ;EFlags.
mov eax,[ebx+(4+4+4+4)+(4)]
push eax ;CS
mov eax,[ebx+(4+4+4+4)+(0)]
push eax ;EIP
mov eax,[ebx+(4+4)]
push eax ;EAX
mov eax,[ebx+(4)]
push eax ;EBX
mov eax,[ebx+(0)]
push eax ;DS
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
add RawStackPos,RawStackDif ;update next stack.
assume ds:_cwDPMIEMU
popm eax,ebx,ds
iretd
;
@@Call2 df 0,0
@@Call20 df 0,0
IntDispatch endp
;-------------------------------------------------------------------------------
;
;Handle an INT nn instruction by retrieving registers from the stack and
;reflect to real mode.
;
IntNN386 proc far
sub esp,4+4
pushm ds,es,fs,gs
sub esp,10*2
pushad
;
mov ax,DpmiEmuDS ;make our data addresable.
mov ds,ax ;/
mov ebp,esp
test DpmiEmuSystemFlags,1
jz @@Use32Bit19
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -