← 返回首页
学习思考

Traps

Traps and Sytem calls

There are three kinds of event which cause the CPU to set aside ordinary execution of instructions and force a transfer of control to special code that handles the event. We use trap as a generic term for these situations

Trap’s process

💡
Kernel code (assembler or C) that processes a trap is often called a handler; the first handler instructions are usually written in assembler (rather than C) and are sometimes called a vector.

RISC-V trap machinery

💡
Note that CPU doesn’t switch to the kernel pgtbl, neither a stack in kernel, and doesn’t save any registers except the PC, which should be done by kernel software.

Traps from user space

💡
A trap may occur while executing in user space if the user program makes a system call (ecall instruction), or does something illegal, or if a device interrupts.

If the trap is a system call, usertrap calls syscall to handle it; if a device interrupt, devintr; otherwise it’s an exception, and the kernel kills the faulting process.

Traps from kernel space

code

本文由 GJJ 创作,内容来源于 Notion 数据库,随时可在 Notion 中编辑更新。 本站由 DeepSeek-v4-flash 辅助构建,项目参考 NotionNext

← 返回首页
61
文章
6
标签
3
分类
962
运行天数