美文网首页
Pintos源码学习进度(4)

Pintos源码学习进度(4)

作者: speakspeak | 来源:发表于2019-05-13 09:02 被阅读0次

1.中断函数

intr_get_level / intr_set_level

    ①获得中断的状态, on还是off

    ②设置中断的状态,on还是off

intr_enable  /  intr_disable

    ①打开中断

    ②关闭中断

intr_init

    ①创建IDT表(interrupt descriptor table)

    ②对每个中断赋予名字

intr_register_int   /   intr_register_ext   

    ①调用register_handler使得中断函数与中断号相互关联 

intr_yield_on_return   

    中断返回时,直接将当前进程yield

intr_context

    判断当前是否在外部中断中执行

2.中断执行过程

    ①发生系统中断,CPU自动将esp,eip,flags,cs,ss寄存器放入堆栈。

    ②CPU通过IDT计算出中断号所对应的intr_stub,并且将ebp, error_code, 以及中断号压如堆栈

    ③进入intr_entry函数,将intr_frame中的其他寄存器压入堆栈, 并跳转到intr_handler函数中

    ④根据中断号找到中断函数,并运行中断函数.

3.intr_frame结构

```

    struct intr_frame

  {

    /* Pushed by intr_entry in intr-stubs.S.

      These are the interrupted task's saved registers. */

    uint32_t edi;              /* Saved EDI. */

    uint32_t esi;              /* Saved ESI. */

    uint32_t ebp;              /* Saved EBP. */

    uint32_t esp_dummy;        /* Not used. */

    uint32_t ebx;              /* Saved EBX. */

    uint32_t edx;              /* Saved EDX. */

    uint32_t ecx;              /* Saved ECX. */

    uint32_t eax;              /* Saved EAX. */

    uint16_t gs, :16;          /* Saved GS segment register. */

    uint16_t fs, :16;          /* Saved FS segment register. */

    uint16_t es, :16;          /* Saved ES segment register. */

    uint16_t ds, :16;          /* Saved DS segment register. */

    /* Pushed by intrNN_stub in intr-stubs.S. */

    uint32_t vec_no;            /* Interrupt vector number. */

    /* Sometimes pushed by the CPU,

      otherwise for consistency pushed as 0 by intrNN_stub.

      The CPU puts it just under `eip', but we move it here. */

    uint32_t error_code;        /* Error code. */

    /* Pushed by intrNN_stub in intr-stubs.S.

      This frame pointer eases interpretation of backtraces. */

    void *frame_pointer;        /* Saved EBP (frame pointer). */

    /* Pushed by the CPU.

      These are the interrupted task's saved registers. */

    void (*eip) (void);        /* Next instruction to execute. */

    uint16_t cs, :16;          /* Code segment for eip. */

    uint32_t eflags;            /* Saved CPU flags. */

    void *esp;                  /* Saved stack pointer. */

    uint16_t ss, :16;          /* Data segment for esp. */

  };

```

相关文章

网友评论

      本文标题:Pintos源码学习进度(4)

      本文链接:https://www.haomeiwen.com/subject/ibnqaqtx.html