📄 sd.asm
字号:
mov ax,001Fh ; disable mouse driver
int 33h
cli
cld
push ds
pop es
mov ds:__datasel,ds ; set up selectors
mov ds:__zerosel,fs ; DOS/32A defines DS=ES=CS=0
mov ds:__savedstack,esp
add ds:__savedstack,56
mov ax,0400h
int 31h
mov __cputype,cl
mov ax,0E00h
int 31h
shr al,4
mov __fputype,al
mov edi,offs _registers
lea esi,[esp+52]
mov ecx,14
@@l1: mov eax,[esi] ; copy general & segment regs into buf
sub esi,4
mov [edi],eax
add edi,4
loop @@l1
mov eax,cr0
mov _cr0,eax
mov eax,cr2
mov _cr2,eax
mov eax,cr3
mov _cr3,eax
mov eax,[esp+60]
mov _eip,eax
mov eax,[esp+56]
mov _efl,eax
mov esi,offs _registers ; copy new regs into old regs
mov edi,offs _old_registers
mov ecx,19
rep movsd
call clearkeytab
xor ecx,ecx
xor edx,edx
; mov al,08h
; mov ecx,seg crt16
; mov edx,offs 0
; call fword ptr __api_off
mov ax,0204h ; get INT vectors
mov bl,10h
int 31h
mov _old_int10sel,ecx
mov _old_int10off,edx
mov bl,21h
int 31h
mov _old_int21sel,ecx
mov _old_int21off,edx
mov bl,31h
int 31h
mov _old_int31sel,ecx
mov _old_int31off,edx
mov bl,33h
int 31h
mov _old_int33sel,ecx
mov _old_int33off,edx
mov ax,0205h
mov bl,21h
mov cx,cs
mov edx,offs _int21 ; INT 21h
int 31h
mov ax,0205h
mov bl,31h
mov cx,cs
mov edx,offs _int31 ; INT 31h
int 31h
mov ax,0205h
mov bl,10h
mov cx,cs
mov edx,offs _int10 ; INT 10h
int 31h
mov ax,0205h
mov bl,33h
mov cx,cs
mov edx,offs _int33 ; INT 33h
int 31h
mov ax,0204h ; get IRQ vectors
mov bl,09h
int 31h
mov _old_int9sel,ecx
mov _old_int9off,edx
mov bl,0Ah
int 31h
mov _old_intAsel,ecx
mov _old_intAoff,edx
mov ax,0204h
mov bl,0Bh
int 31h
mov _old_intBsel,ecx
mov _old_intBoff,edx
mov ax,0204h
mov bl,0Ch
int 31h
mov _old_intCsel,ecx
mov _old_intCoff,edx
mov ax,0204h
mov bl,0Dh
int 31h
mov _old_intDsel,ecx
mov _old_intDoff,edx
mov ax,0204h
mov bl,0Eh
int 31h
mov _old_intEsel,ecx
mov _old_intEoff,edx
; mov ax,0205h
; mov cx,cs
; mov bl,9
; mov edx,offs _int09
; int 31h
mov ax,0203h ; install INT handlers
mov cx,cs
mov bl,0
mov edx,offs _int00 ; divide by zero
int 31h
mov bl,1
mov edx,offs _int01 ; INT 01h (trap)
int 31h
mov bl,3
mov edx,offs _int03 ; INT 03h (breakpnt)
int 31h
mov bl,4
mov edx,offs _int04 ; INTO
int 31h
mov bl,5
mov edx,offs _int05 ; bound
int 31h
mov bl,6
mov edx,offs _int06 ; invalid op
int 31h
mov bl,0Ah
mov edx,offs _int0A
int 31h
mov bl,0Bh
mov edx,offs _int0B
int 31h
mov bl,0Ch
mov edx,offs _int0C
int 31h
mov bl,0Dh
mov edx,offs _int0D
int 31h
mov bl,0Eh
mov edx,offs _int0E
int 31h
@@dpmi: clr eax ; initialize DEBUG REGISTERS
mov dr0,eax ; clear DR0-DR7: linear addresses
mov dr1,eax
mov dr2,eax
mov dr3,eax
mov dr6,eax ; clear DR6: bits T,S,D and breakpoint matches
mov dr7,eax ; setup DR7: disable all breakpoints
mov _dr0,eax
mov _dr1,eax
mov _dr2,eax
mov _dr3,eax
mov _dr7,eax
xor wptr _dr7,0300h
mov old_video_mode,ax
mov _data_addr,eax
mov _stack_addr,eax
mov _current_window,eax
mov eax,_eip ; setup variables
mov _code_addr,eax
mov _data_override,3
mov _cpu_xpos,1
mov _cpu_ypos,1
mov _cpu_xptr,0
mov _mem_xpos,14
mov _mem_ypos,39
mov _stk_xpos,62
mov _stk_ypos,30
mov _reg_xpos,1
mov _reg_ypos,32
mov _reg_ldat,12
mov _reg_xptr,0
mov __buffer,offset __screen2
mov _system_block,offset __screen
mov _vgastate_buf,offset __vgastatebuf
mov _svgastate_buf,offset __svgastatebuf
mov _vgastate_set,0 ; set no VGA save/restore
mov _svgastate_set,0 ; set no SVGA save/restore
mov ax,1C00h
mov cx,0007h
int 10h
cmp al,1Ch
jnz @@verr
cmp ebx,4096/64
ja @@verr
mov _vgastate_set,1
mov ax,4F04h
mov cx,000Fh
mov dx,0000h
int 10h
cmp ax,004Fh
jnz @@verr
cmp ebx,4096/64
ja @@verr
mov _svgastate_set,1
@@verr: mov byte ptr ds:@debug@,90h ; replace RET with NOP
pop gs fs ss es ds ; return to caller
add esp,4
sti
popad
popfd
ret
;-----------------------------------------------------------------------------
_exit: cli
cld
mov al,36h ; reprogram PIT to DOS freq
out 43h,al
mov al,00h
out 40h,al
out 40h,al
clr eax
mov dr6,eax
mov dr7,eax ; reset hardware breakpoints
mov ds,cs:__datasel
mov es,cs:__datasel
mov ss,cs:__datasel
mov esp,cs:__savedstack
and old_video_mode,7F7Fh
cmp old_video_mode,0003h
jnz @@l1
call restore_video ; raw exit to DOS
call restore_state
xor eax,eax
int 33h
mov ax,4C00h
int 21h
@@l1: mov ax,0003h
int 10h
call restore_state
xor eax,eax
int 33h
mov ax,4C00h
int 21h
jmp $
;-----------------------------------------------------------------------------
_abort: cli
cld
mov ax,4CFFh
int 21h
jmp $
;-----------------------------------------------------------------------------
Align 4
_int21: cld
push ds es
pushad
cmp cs:__history_bufon,0
jz @@l1
mov dx,cs
mov ax,[esp+2Ch]
cmp ax,dx
jz @@l1
cmp ax,cs:__kernel_codesel
jz @@l1
cmp ax,cs:__client_codesel
jz @@l1
mov ds,cs:__datasel
mov edx,__history_bufptr
imul edx,40h
cmp edx,__history_bufsize
jb @@1
xor edx,edx
mov __history_bufptr,edx
@@1: add edx,__history_bufbase
mov eax,__history_bufnum
inc __history_bufnum
inc __history_bufptr
mov [edx+00h],ax ; 00h - NUM
mov ax,0021h
mov [edx+02h],ax ; 02h - INT
mov eax,[esp+20h+8+8]
mov [edx+04h],eax ; 04h - EFL
mov eax,[esp+20h+8+0]
sub eax,2
mov [edx+08h],eax ; 08h - EIP
mov eax,[esp+1Ch]
mov [edx+0Ch],eax ; 0Ch - EAX
mov eax,[esp+10h]
mov [edx+10h],eax ; 10h - EBX
mov eax,[esp+18h]
mov [edx+14h],eax ; 14h - ECX
mov eax,[esp+14h]
mov [edx+18h],eax ; 18h - EDX
mov eax,[esp+04h]
mov [edx+1Ch],eax ; 1Ch - ESI
mov eax,[esp+00h]
mov [edx+20h],eax ; 20h - EDI
mov eax,[esp+08h]
mov [edx+24h],eax ; 24h - EBP
mov eax,esp
add eax,20h+14h
mov [edx+28h],eax ; 28h - ESP
mov ax,[esp+20h+8+4]
mov [edx+2Ch],ax ; 2Ch - CS
mov ax,[esp+24h]
mov [edx+30h],ax ; 30h - DS
mov [edx+32h],es ; 32h - ES
mov [edx+34h],ss ; 34h - SS
mov [edx+36h],fs ; 36h - FS
mov [edx+38h],gs ; 38h - GS
mov ds,[esp+24h]
@@l1: popad
pushad
cmp ah,4Ch
jz @__4Ch
popad
pop es ds
jmp fword ptr cs:_old_int21off
@__4Ch: mov ax,cs
cmp ax,[esp+2Ch]
jnz _terminated
mov ax,0205h
mov bl,21h
mov ecx,cs:_old_int21sel
mov edx,cs:_old_int21off
int 31h
mov bl,31h
mov ecx,cs:_old_int31sel
mov edx,cs:_old_int31off
int 31h
mov bl,10h
mov ecx,cs:_old_int10sel
mov edx,cs:_old_int10off
int 31h
mov bl,33h
mov ecx,cs:_old_int33sel
mov edx,cs:_old_int33off
int 31h
popad
pop es ds
jmp fword ptr cs:_old_int21off
_terminated:
mov ds,cs:__datasel
mov __history_bufon,0
mov eax,[esp+20h+8+0]
sub eax,2
mov [esp+20h+8+0],eax
popad
pop es ds
push es ss ds fs gs
pushad
call save_state
mov al,4Ch
jmp _exception
;-----------------------------------------------------------------------------
Align 4
_int31: cld
push ds es
pushad
cmp cs:__history_bufon,0
jz @@l1
mov dx,cs
mov ax,[esp+2Ch]
cmp ax,dx
jz @@l1
cmp ax,cs:__kernel_codesel
jz @@l1
cmp ax,cs:__client_codesel
jz @@l1
mov ds,cs:__datasel
mov edx,__history_bufptr
imul edx,40h
cmp edx,__history_bufsize
jb @@1
xor edx,edx
mov __history_bufptr,edx
@@1: add edx,__history_bufbase
mov eax,__history_bufnum
inc __history_bufnum
inc __history_bufptr
mov [edx+00h],ax ; 00h - NUM
mov ax,0031h
mov [edx+02h],ax ; 02h - INT
mov eax,[esp+20h+8+8]
mov [edx+04h],eax ; 04h - EFL
mov eax,[esp+20h+8+0]
sub eax,2
mov [edx+08h],eax ; 08h - EIP
mov eax,[esp+1Ch]
mov [edx+0Ch],eax ; 0Ch - EAX
mov eax,[esp+10h]
mov [edx+10h],eax ; 10h - EBX
mov eax,[esp+18h]
mov [edx+14h],eax ; 14h - ECX
mov eax,[esp+14h]
mov [edx+18h],eax ; 18h - EDX
mov eax,[esp+04h]
mov [edx+1Ch],eax ; 1Ch - ESI
mov eax,[esp+00h]
mov [edx+20h],eax ; 20h - EDI
mov eax,[esp+08h]
mov [edx+24h],eax ; 24h - EBP
mov eax,esp
add eax,20h+14h
mov [edx+28h],eax ; 28h - ESP
mov ax,[esp+20h+8+4]
mov [edx+2Ch],ax ; 2Ch - CS
mov ax,[esp+24h]
mov [edx+30h],ax ; 30h - DS
mov [edx+32h],es ; 32h - ES
mov [edx+34h],ss ; 34h - SS
mov [edx+36h],fs ; 36h - FS
mov [edx+38h],gs ; 38h - GS
mov ds,[esp+24h]
@@l1: popad
pushad
popad
pop es ds
jmp fword ptr cs:_old_int31off
;-----------------------------------------------------------------------------
Align 4
_int10: cld
push ds es
pushad
cmp cs:__history_bufon,0
jz @@l1
mov dx,cs
mov ax,[esp+2Ch]
cmp ax,dx
jz @@l1
cmp ax,cs:__kernel_codesel
jz @@l1
cmp ax,cs:__client_codesel
jz @@l1
mov ds,cs:__datasel
mov edx,__history_bufptr
imul edx,40h
cmp edx,__history_bufsize
jb @@1
xor edx,edx
mov __history_bufptr,edx
@@1: add edx,__history_bufbase
mov eax,__history_bufnum
inc __history_bufnum
inc __history_bufptr
mov [edx+00h],ax ; 00h - NUM
mov ax,0010h
mov [edx+02h],ax ; 02h - INT
mov eax,[esp+20h+8+8]
mov [edx+04h],eax ; 04h - EFL
mov eax,[esp+20h+8+0]
sub eax,2
mov [edx+08h],eax ; 08h - EIP
mov eax,[esp+1Ch]
mov [edx+0Ch],eax ; 0Ch - EAX
mov eax,[esp+10h]
mov [edx+10h],eax ; 10h - EBX
mov eax,[esp+18h]
mov [edx+14h],eax ; 14h - ECX
mov eax,[esp+14h]
mov [edx+18h],eax ; 18h - EDX
mov eax,[esp+04h]
mov [edx+1Ch],eax ; 1Ch - ESI
mov eax,[esp+00h]
mov [edx+20h],eax ; 20h - EDI
mov eax,[esp+08h]
mov [edx+24h],eax ; 24h - EBP
mov eax,esp
add eax,20h+14h
mov [edx+28h],eax ; 28h - ESP
mov ax,[esp+20h+8+4]
mov [edx+2Ch],ax ; 2Ch - CS
mov ax,[esp+24h]
mov [edx+30h],ax ; 30h - DS
mov [edx+32h],es ; 32h - ES
mov [edx+34h],ss ; 34h - SS
mov [edx+36h],fs ; 36h - FS
mov [edx+38h],gs ; 38h - GS
mov ds,[esp+24h]
@@l1: popad
pushad
popad
pop es ds
jmp fword ptr cs:_old_int10off
;-----------------------------------------------------------------------------
Align 4
_int33: cld
push ds es
pushad
cmp cs:__history_bufon,0
jz @@l1
mov dx,cs
mov ax,[esp+2Ch]
cmp ax,dx
jz @@l1
cmp ax,cs:__kernel_codesel
jz @@l1
cmp ax,cs:__client_codesel
jz @@l1
mov ds,cs:__datasel
mov edx,__history_bufptr
imul edx,40h
cmp edx,__history_bufsize
jb @@1
xor edx,edx
mov __history_bufptr,edx
@@1: add edx,__history_bufbase
mov eax,__history_bufnum
inc __history_bufnum
inc __history_bufptr
mov [edx+00h],ax ; 00h - NUM
mov ax,0033h
mov [edx+02h],ax ; 02h - INT
mov eax,[esp+20h+8+8]
mov [edx+04h],eax ; 04h - EFL
mov eax,[esp+20h+8+0]
sub eax,2
mov [edx+08h],eax ; 08h - EIP
mov eax,[esp+1Ch]
mov [edx+0Ch],eax ; 0Ch - EAX
mov eax,[esp+10h]
mov [edx+10h],eax ; 10h - EBX
mov eax,[esp+18h]
mov [edx+14h],eax ; 14h - ECX
mov eax,[esp+14h]
mov [edx+18h],eax ; 18h - EDX
mov eax,[esp+04h]
mov [edx+1Ch],eax ; 1Ch - ESI
mov eax,[esp+00h]
mov [edx+20h],eax ; 20h - EDI
mov eax,[esp+08h]
mov [edx+24h],eax ; 24h - EBP
mov eax,esp
add eax,20h+14h
mov [edx+28h],eax ; 28h - ESP
mov ax,[esp+20h+8+4]
mov [edx+2Ch],ax ; 2Ch - CS
mov ax,[esp+24h]
mov [edx+30h],ax ; 30h - DS
mov [edx+32h],es ; 32h - ES
mov [edx+34h],ss ; 34h - SS
mov [edx+36h],fs ; 36h - FS
mov [edx+38h],gs ; 38h - GS
mov ds,[esp+24h]
@@l1: popad
pushad
popad
pop es ds
jmp fword ptr cs:_old_int33off
_critical_error_handler:
push es ss ds fs gs
pushad
call save_state
mov eax,cs:_eax
push ds es ecx esi edi
mov ds,cs:__datasel
mov es,cs:__datasel
mov esi,offs _old_registers
mov edi,offs _registers
mov ecx,19
rep movsd
pop edi esi ecx es ds
jmp _exception
Align 4
__datasel dw 0
__zerosel dw 0
__savedstack dd 0
.DATA
;屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -