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

线程调用, 栈到底是如何变化的 #8

Open
misakar opened this issue Dec 18, 2016 · 1 comment
Open

线程调用, 栈到底是如何变化的 #8

misakar opened this issue Dec 18, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@misakar
Copy link
Member

misakar commented Dec 18, 2016

  • 函数调用栈
  • 各个特权级下的栈
  • PCB中的栈

这么多栈, 分别是什么概念? 函数call, ret, 特权级变化时,这些栈是在哪里并如何改变的?

@misakar misakar added this to the 1608review milestone Dec 18, 2016
@misakar misakar self-assigned this Dec 18, 2016
@misakar
Copy link
Member Author

misakar commented Dec 21, 2016

  • 线程调用为了执行线程函数需要线程栈, 在uiharu中就是thread->self_kstack
  • 进出中断时的上下文保存和恢复需要中断栈, 在uiharu中就是intr_stack
  • 每个线程有唯一的PCB供操作系统调度, 所以从内核中申请了连续物理页, 在uiharu中就是task_struct

线程栈是直接放在PCB里面的, 可以通过 ((uint32_t)esp & 0xfffff000)直接拿到当前运行线程的PCB(地址空间or页表),很方便.
中断栈位于PCB的顶部, 进入中断处理程序时会将当前上下文环境保存与此.
线程栈被调用时还需要遵循ABI,保存调用环境. 调度器ret的时候,恢复ABI寄存器环境,下一个线程被调度上CPU执行.

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

No branches or pull requests

1 participant