中断,异常,系统调用,进程切换时的堆栈变化和寄存器保存

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lovelycheng/article/details/78359955
 1. 中断,异常,系统调用相同:
 
  CPU自动压入:

  ss            运行级别提升时需切换堆栈,因此多压入用户态的栈段ss,
  esp           运行级别提升时需切换堆栈,因此多压入用户态的堆栈指针esp,
  eflag
  cs
  eip
  error code

  程序压入部分压入如下寄存器:

  es
  ds
  ebp
  edi
  esi
  edx
  ecx
  ebx

  但是压入的方法各不相同,见entry.S。#define SAVE_ALL,和pt_reg的关系?

  a. 异常:
ENTRY(divide_error)
    pushl$0            #no error code  Wood: 当没有硬件错误码时,在栈中垫上一个空值。
    pushl $do_divide_error    # 压入返回地址
    ALIGN
error_code:
    pushl %ds
    pushl %eax
    xorl %eax, %eax
    pushl %ebp
    pushl %edi
    pushl %esi
    pushl %edx
    decl %eax            # eax = -1
    pushl %ecx
    pushl %ebx
    cld
    movl %es, %ecx
    movl ES(%esp),%edi        # get the functionaddress   ES = 0x20 得到异常高级处理函数地址,见 pushl $do_divide_error
    movl ORIG_EAX(%esp), %edx    # getthe error code,ORIG_EAX    = 0x24,到硬件错误码,见pushl$0,如果CPU压入,则这里不需要压入。这里是为高层函数准备第二个参数error code,因为高层函数全部是fastcall类型的函数
    movl %eax, ORIG_EAX(%esp)   # 把-1存在原来放硬件错误码的地方,这个值用来把0x80异常与其他异常隔离开。?????
    movl %ecx, ES(%esp)         #把 %es的值存入原来放异常高级处理函数地址的位置。
    movl $(__USER_DS), %ecx
    movl %ecx, %ds
    movl %ecx, %es
    movl%esp,%eax           # pt_regs pointer,当前栈指针,这里是为高层函数准备第一个参数pt_regs,因为高层函数全部是fastcall类型的函数
    call *%edi
    jmp ret_from_exception

ENTRY(page_fault)
    pushl $do_page_fault
    jmp error_code

  b. 中断:


2. 进程切换

更新中:

猜你喜欢

转载自blog.csdn.net/lovelycheng/article/details/78359955
今日推荐