asm volatile(
"movl %1,%%esp\n\t"
"pushl %1\n\t"
"pushl %0\n\t"
"ret\n\t"
"popl %%ebp\n\t"
:
: "c" (task[pid].thread.ip),"d" (task[pid].thread.sp)
);
保存恢复进程上下文
asm volatile(
"pushl %%ebp\n\t" //保存当前 ebp
"movl %%esp,%0\n\t" //保存 esp
"movl %2,%%esp\n\t" //载入下一个进程的 esp
"movl $1f,%1\n\t" //保存 eip
"pushl %3\n\t" //
"ret\n\t" //载入 eip
"1:\t" //下一个进程开始执行
"popl %%ebp\n\t" //
: "=m" (prev->thread.sp),"=m" (prev->thread.ip)
: "m" (next->thread.sp),"m" (next->thread.ip)
);
//如果没有正在运行的进程
asm volatile(
"pushl %%ebp\n\t" //保存 ebp
"movl %%esp,%0\n\t" //保存 esp
"movl %2,%%esp\n\t" //载入 esp
"movl %2,%%ebp\n\t" //载入 ebp
"movl $1f,%1\n\t" //保存 eip
"pushl %3\n\t"
"ret\n\t" //载入上下文
: "=m" (prev->thread.sp),"=m" (prev->thread.ip)
: "m" (next->thread.sp),"m" (next->thread.ip)
);
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/luoyhang003/article/details/46827401