/* 节选自[include/asm-i386/system.h] */
#define switch_to(prev,next,last) do { \
asm volatile("pushl %%esi\n\t" \
"pushl %%edi\n\t" \
"pushl %%ebp\n\t" \保存esi、edi、ebp寄存器
"movl %%esp,%0\n\t" \esp保存到prev->thread.esp中
"movl %3,%%esp\n\t" \从next->thread.esp恢复esp
"movl $1f,%1\n\t" \在prev->thread.eip中保存"1:"的跳转地址,当prev被再次切换到的时候将从那里开始执行
"pushl %4\n\t" \在栈上保存next->thread.eip,__switch_to()返回时将转到那里执行,即进入next进程的上下文
"jmp __switch_to\n" \跳转到__switch_to(),进一步处理(见下)
"1:\t" \
"popl %%ebp\n\t" \
"popl %%edi\n\t" \
"popl %%esi\n\t" \先恢复上次被切换走时保存的寄存器值,再从switch_to()中返回。
:"=m" (prev->thread.esp), \%0
"=m" (prev->thread.eip),\%1
"=b" (last) \ebx,因为进程切换后,恢复的栈上的prev信息不是刚被切换走的进程描述符,因此此处使用ebx寄存器传递该值给prev
:"m" (next->thread.esp), \%3
"m" (next->thread.eip), \%4
"a" (prev), "d" (next), \eax,edx
"b" (prev)); \ebx
} while (0)
|