MIT6.828 Fall2018 筆記 - Homework 8: User-level threads

Homework: User-level threadshtml

.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 */
相關文章
相關標籤/搜索