Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.4对于stvec寄存器的描述似乎有误 #29

Open
brick-pid opened this issue Sep 23, 2021 · 2 comments
Open

9.4对于stvec寄存器的描述似乎有误 #29

brick-pid opened this issue Sep 23, 2021 · 2 comments

Comments

@brick-pid
Copy link

9.4对stvec的描述:“STVEC寄存器,它会保存当trap,page fault或者中断发生时,CPU运行的用户程序的程序计数器,这样才能在稍后恢复程序的运行。”
保存触发trap的用户指令的地址好像是SEPC寄存器。STVEC寄存器应该是保存trap handler(uservec、kernelvec)的地址。trap返回时,恢复PC用的应该是SEPC的值吧。

@zwyyy456
Copy link

对的,PC 的值是保存在 sepc 中,stvec 保存的应该是 trampoline.S 的起始地址。

@Aniurm
Copy link

Aniurm commented Nov 9, 2023

确实。教材4.1:

  • stvec: The kernel writes the address of its trap handler here; the RISC-V jumps here to handle a trap.
  • sepc: When a trap occurs, RISC-V saves the program counter here (since the pc is then overwritten with stvec). The sret (return from trap) instruction copies sepc to the pc. The kernel can write to sepc to control where sret goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants