MIT6.828 Fall2018 笔记 - Homework 8: User-level threads

Homework: 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 */
posted @ 2020-05-09 00:16  hyuuko  阅读(217)  评论(0编辑  收藏  举报