linux内核代码分析之asm.s

该文件主要是定义了CPU异常产生的中断函数的调用
分成2类:
 1. 带返回错误码的中断调用
 2. 不带返回错误码的中断调用
分别对应的符号为:
 1. error_code:
 2. no_error_code:

.globl _divide_error,_debug,_nmi,_int3,_overflow,_bounds,_invalid_op
.globl _double_fault,_coprocessor_segment_overrun
.globl _invalid_TSS,_segment_not_present,_stack_segment
.globl _general_protection,_coprocessor_error,_irq13,_reserved

除零
_divide_error:
 函数地址入栈
 函数原型 void do_divide_error(esp , error_code)
 pushl $_do_divide_error

 无返回错误码的中断调用
 
no_error_code:
 将eax的值保存在栈上,将中断处理函数的地址保存在eax寄存器中
 xchgl %eax,(%esp)
 以下寄存器入栈保存
 pushl %ebx
 pushl %ecx
 pushl %edx
 pushl %edi
 pushl %esi
 pushl %ebp
 push %ds
 push %es
 push %fs
 函数参数入栈,遵循c语言参数入栈顺序 
 pushl $0
 lea 44(%esp),%edx
 pushl %edx
 将内核代码段和数据段的选择符放入edx寄存器中
 movl $0x10,%edx
 重新加载各个段寄存器
 mov %dx,%ds
 mov %dx,%es
 mov %dx,%fs
 进行内核态的函数调用
 call *%eax
 函数调用结束,恢复各个寄存器
 addl $8,%esp
 pop %fs
 pop %es
 pop %ds
 popl %ebp
 popl %esi
 popl %edi
 popl %edx
 popl %ecx
 popl %ebx
 popl %eax
 中断返回
 iret

一下是定义的一些中断调用
_debug:
 pushl $_do_int3  # _do_debug
 jmp no_error_code

_nmi:
 pushl $_do_nmi
 jmp no_error_code

_int3:
 pushl $_do_int3
 jmp no_error_code

_overflow:
 pushl $_do_overflow
 jmp no_error_code

_bounds:
 pushl $_do_bounds
 jmp no_error_code

_invalid_op:
 pushl $_do_invalid_op
 jmp no_error_code

_coprocessor_segment_overrun:
 pushl $_do_coprocessor_segment_overrun
 jmp no_error_code

_reserved:
 pushl $_do_reserved
 jmp no_error_code

_irq13:
 pushl %eax
 xorb %al,%al
 outb %al,$0xF0
 movb $0x20,%al
 outb %al,$0x20
 jmp 1f
1: jmp 1f
1: outb %al,$0xA0
 popl %eax
 jmp _coprocessor_error

双出错故障,函数原型,void do_double_fault(esp , error_code)
_double_fault:
 pushl $_do_double_fault
 带错误码的返回
error_code:
 将error code存放在eax中,将eax的值保存在栈上
 xchgl %eax,4(%esp)  
 将函数地址保存在ebx中,ebx的值保存在栈上
 xchgl %ebx,(%esp)  
 各个寄存器入栈保存
 pushl %ecx
 pushl %edx
 pushl %edi
 pushl %esi
 pushl %ebp
 push %ds
 push %es
 push %fs
 调用函数参数,入栈保存
 pushl %eax   
 lea 44(%esp),%eax
 将错误码压入栈中  
 pushl %eax
 用内核代码段和数据段选择符初始化eax
 movl $0x10,%eax
 重新加载各个段寄存器
 mov %ax,%ds
 mov %ax,%es
 mov %ax,%fs
 在内核态中进行调用
 call *%ebx
 恢复各个寄存器
 addl $8,%esp
 pop %fs
 pop %es
 pop %ds
 popl %ebp
 popl %esi
 popl %edi
 popl %edx
 popl %ecx
 popl %ebx
 将错误码出栈,保存在eax中
 popl %eax
 中断返回
 iret

定义几种带返回值的中断处理程序
_invalid_TSS:
 pushl $_do_invalid_TSS
 jmp error_code

_segment_not_present:
 pushl $_do_segment_not_present
 jmp error_code

_stack_segment:
 pushl $_do_stack_segment
 jmp error_code

_general_protection:
 pushl $_do_general_protection
 jmp error_code

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值