MIT6.828 Fall2018 笔记 - Homework 8: User-level threads
.text
/* Switch from current_thread to next_thread. Make next_thread
* the current_thread, and set next_thread to 0.
* Use eax as a temporary register; it is caller saved.
*/
.globl thread_switch
thread_switch:
/* YOUR CODE HERE */
// 保存当前线程状态至 current_thread
pushal
movl current_thread, %eax
movl %esp, (%eax)
// 切换至 next_thread
movl next_thread, %eax
movl %eax, current_thread
movl $0x0, next_thread
movl (%eax), %esp
popal
// 此时 sp 指向 next_thread 的 eip
ret /* pop return address from stack */
本文到这里就结束了,有疑问欢迎评论哦😉

浙公网安备 33010602011771号