📄 asm.asm
字号:
;文件名: asm.asm
;说明: 中断的汇编入口
;作者: marsinfan;日期: 2005/12/10
GLOBAL _devide_error_interrupt, _debug_interrupt, _nmi_interrupt, _int3_interrupt
GLOBAL _overflow_interrupt, _bounds_interrupt, _innvalid_opcode_interrupt, _device_not_available_interrupt
GLOBAL _double_fault_interrupt, _coprocessor_segment_overrun_interrupt, _invalid_tss_interrupt, _segment_not_present_interrupt
GLOBAL _stack_segment_interrupt, _general_protection_interrupt, _page_fault_interrupt, _reserved_interrupt
GLOBAL _coprocessor_error_interrupt, _isr_11_wrapper, _isr_12_wrapper, _isr_13_wrapper
GLOBAL _isr_14_wrapper, _isr_15_wrapper, _isr_16_wrapper, _isr_17_wrapper
GLOBAL _isr_18_wrapper, _isr_19_wrapper, _isr_1A_wrapper, _isr_1B_wrapper
GLOBAL _isr_1C_wrapper, _isr_1D_wrapper, _isr_1E_wrapper, _isr_1F_wrapper
GLOBAL _timer_interrupt, _kbd_interrupt, _hd_interrupt
GLOBAL exc_has_error
EXTERN _exc_handler, _timer_handler, _kbd_handler, _hd_handler, _ret_from_sys_call
SEGMENT _TEXT PUBLIC CLASS = CODE USE32
%macro WRAPPER 2
%1:
push eax
mov eax, %2 ; 保存异常号
jmp _exc_common ; 跳转至_exc_common
%endmacro
_exc_common:
push ebp
mov ebp, esp
push ds
push es ; 保存段寄存器
push fs ;
pushad ; 和其他寄存器的值
mov bx, 10h
mov ds, bx
mov es, bx ; 设置数据段寄存器的值
mov ebx, eax
cmp byte [exc_has_error + ebx], 0
je .1
;有错误码
push dword [ss:ebp + 8] ; 错误码
push dword [ss:ebp + 12] ; cs
push dword [ss:ebp + 16] ; eip
push eax ; 异常号
call _exc_handler ; 调用异常处理代码; void _exc_handler (no, cs, ip, error)
add esp, 0x10
popad ; 恢复寄存器
pop fs
pop es
pop ds
pop ebp
pop eax
add esp, 0x04
iretd
.1:
;没有错误码
push dword 0 ; 错误码为0
push dword [ss:ebp + 8] ; cs
push dword [ss:ebp + 12] ; eip
push eax ; 异常号
call _exc_handler ; 调用异常处理代码; void _exc_handler (no, cs, ip, error)
add esp, 0x10
popad ; 恢复寄存器
pop fs
pop es
pop ds
pop ebp
pop eax
iretd
WRAPPER _devide_error_interrupt, 00h ;故障 SIGFPE 当进行除以零的操作时产生
WRAPPER _debug_interrupt, 01h ;陷阱,故障 SIGTRAP 当进行程序单步跟踪调试时,设置了标志寄存器eflag的T标志时产生这个终端
WRAPPER _nmi_interrupt, 02h ;硬件 由不可屏蔽中断NMI产生
WRAPPER _int3_interrupt, 03h ;陷阱 SIGTRAP 由断点指令int3产生,与debug处理相同
WRAPPER _overflow_interrupt, 04h ;陷阱 SIGSEGV eflag的溢出标志OF引起
WRAPPER _bounds_interrupt, 05h ;故障 SIGSEGV 寻址到有效地址以外时引起
WRAPPER _innvalid_opcode_interrupt, 06h ;故障 SIGILL CPU执行时发现一个无效的指令操作码
WRAPPER _device_not_available_interrupt, 07h
WRAPPER _double_fault_interrupt, 08h
WRAPPER _coprocessor_segment_overrun_interrupt, 09h
WRAPPER _invalid_tss_interrupt, 0Ah
WRAPPER _segment_not_present_interrupt, 0Bh
WRAPPER _stack_segment_interrupt, 0Ch
WRAPPER _general_protection_interrupt, 0Dh
WRAPPER _page_fault_interrupt, 0Eh
WRAPPER _reserved_interrupt, 0Fh
WRAPPER _coprocessor_error_interrupt, 10h
WRAPPER _isr_11_wrapper, 11h
WRAPPER _isr_12_wrapper, 12h
WRAPPER _isr_13_wrapper, 13h
WRAPPER _isr_14_wrapper, 14h
WRAPPER _isr_15_wrapper, 15h
WRAPPER _isr_16_wrapper, 16h
WRAPPER _isr_17_wrapper, 17h
WRAPPER _isr_18_wrapper, 18h
WRAPPER _isr_19_wrapper, 19h
WRAPPER _isr_1A_wrapper, 1Ah
WRAPPER _isr_1B_wrapper, 1Bh
WRAPPER _isr_1C_wrapper, 1Ch
WRAPPER _isr_1D_wrapper, 1Dh
WRAPPER _isr_1E_wrapper, 1Eh
WRAPPER _isr_1F_wrapper, 1Fh
_timer_interrupt:
push ds
push es ; 保存段寄存器
push gs
push fs
push ebp
push edi
push esi
push edx
push ecx
push ebx
push eax
mov eax, [esp + 48] ; 获取被中断的cs
mov bx, 10h ;
mov ds, bx ;
mov es, bx ; 设置数据段寄存器的值
and eax, 0x03 ; 获取dpl
push eax ;
call _timer_handler ; 调用时钟中断处理代码
add esp, 4
jmp _ret_from_sys_call;
_kbd_interrupt:
push ds
push es ; 保存段寄存器
push gs
push fs
push ebp
push edi
push esi
push edx
push ecx
push ebx
push eax
mov bx, 10h
mov ds, bx
mov es, bx ; 设置数据段寄存器的值
call _kbd_handler ; 调用键盘处理代码
jmp _ret_from_sys_call;
_hd_interrupt:
push eax
push ds
push es ; 保存段寄存器和
push fs
pushad ; 和其他寄存器的值
mov bx, 10h
mov ds, bx
mov es, bx ; 设置数据段寄存器的值
;mov al, 0x20
;out 0xA0, al
call _hd_handler ; 调用硬盘处理代码
popad ; 恢复寄存器的值
pop fs
pop es
pop ds
pop eax
iretd
SEGMENT _DATA PUBLIC CLASS = DATA
exc_has_error DB 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0
DB 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -