|
我在国内人气最旺,高手最多的另外2个linux坛子上问了,没人
回答,呜呜
情景上p373最下面说,新fork的进程指令ip设为ret_from_fork,在switch_to调度到该进程
时,从ret_from_fork到ret_from_sys_call直接转回用户空间里去了。但是根本不是,
父进程switch_to后,就直接切换到被调度到的进程的用户空间去了,而对于fork到的新进
程,switch_to切换到他的系统堆栈,指令切到ret_from_fork,从这里执行到ret_from_s
ys_call,而ret_from_sys_call还要做软中断,信号和任务切换,就是说,对
软中断,信号和任务切换又来了一次!为什么要这样做呢?还是我没弄懂?
还有switch_to为何要在开头push三个寄存器,随后又pop之,啥也没干,更何况进入中断
和系统调用时,这三个寄存器已经push了!
这部分代码看不懂,请高手指点!
ENTRY(ret_from_sys_call)
#ifdef CONFIG_SMP
movl processor(%ebx),%eax
shll $CONFIG_X86_L1_CACHE_SHIFT,%eax
movl SYMBOL_NAME(irq_stat)(,%eax),%ecx # softirq_active
testl SYMBOL_NAME(irq_stat)+4(,%eax),%ecx # softirq_mask
#else
movl SYMBOL_NAME(irq_stat),%ecx # softirq_active
testl SYMBOL_NAME(irq_stat)+4,%ecx # softirq_mask
#endif
jne handle_softirq
ret_with_reschedule:
cmpl $0,need_resched(%ebx)
jne reschedule
cmpl $0,sigpending(%ebx)
jne signal_return
restore_all:
RESTORE_ALL
--
#define switch_to(prev,next,last) do { \
asm volatile("pushl %%esi\n\t" \
"pushl %%edi\n\t" \
"pushl %%ebp\n\t" \
"movl %%esp,%0\n\t" /* save ESP */ \
"movl %3,%%esp\n\t" /* restore ESP */ \
"movl $1f,%1\n\t" /* save EIP */ \
"pushl %4\n\t" /* restore EIP */ \
"jmp __switch_to\n" \
"1:\t" \
"popl %%ebp\n\t" \
"popl %%edi\n\t" \
"popl %%esi\n\t" \
:"=m" (prev->thread.esp),"=m" (prev->thread.eip), \
"=b" (last) \
:"m" (next->thread.esp),"m" (next->thread.eip), \
"a" (prev), "d" (next), \
"b" (prev)); \
} while (0)
|
|