????????????????????й??????????????????????????????O(∩_∩)O~

????switch_to??A?????л???B???????裺

????step1???????????????????????

[prev] "a" (prev)
[next] "d" (next)

????????

????eax <== prev_A ?? eax <==%p(%ebp_A)

????edx <== next_A ?? edx <==%n(%ebp_A)

????????prev??next????A?????????????

????step2?????????A??ebp??eflags

pushfl
pushl %ebp

??????????????esp????A?????У????????????????????浽A???????????С?

????step3?????浱?esp??A??????????????У?

"movl %%esp??%[prev_sp] "    /* save    ESP   */

??????????????? prev_A->thread.sp <== esp_A

?????????switch_to???prev?????A?????????????????????

????step4????next??????B???????????????????B?л??????????esp_B??

"movl %[next_sp]??%%esp " /* restore ESP */

???????????????esp_B <== next_A->thread.sp

?????????A?????е?next?????B??????????????

???????????????CPU?????е?????????B??????????esp??????B???????????????????ebp??????A???????????????????о???????????A?е?????????????next???????%n(%ebp_A)?????next_A???????B?????????????

????step5???????1??????????浽A????????????ip??

"movl $1f??%[prev_ip] "    /* save    EIP   */

???????????????prev_A->thread.ip <== %1f????A?????′α?switch_to????????????????????С????巽???????汻?л???????B?????????

????step6?????????????浽???????????__switch_to()??????__switch_to()?????????????????л???

"pushl %[next_ip] "    /* restore EIP   */
"jmp __switch_to "    /* regparm call  */

?????????????B???switch_to??????????[next_ip]?????????????1f??????????????B??????????????б?switch_to??????????[next_ip]???????ret_ftom_fork???ο?copy_thread()???????????????????????call __switch_to????jmp?????call???????????????仰????(???1??)???????__switch_to()??????ret??????????????????ret??ret_from_fork??

?????????????????__switch_to()??????????????prev_A??д????%eax?????????switch_to??????eax??????????????prev_A??????????????????????????A????????????“???”????????????????step8?н???????

????step7????__switch_to()??????????1???????濪???У????ebp??B????????????B??eflags??

"popl %%ebp "        /* restore EBP   */
"popfl "            /* restore flags */

?????????__switch_to()????????????????У????????????B?????switch_to??????????????????????ebp_B??flags_B????????л????????

????????????ebp????????B??????????????????prev??next???????????????A???????е????????B???????е?(B??α??л??????????????????????????????B?????prev??next?????)?????prev == %p(%ebp_B)??????B??α??л??????????λ????????B????????????????????????????switch_to???????????????У??? context_switch()??????switch_to?????????prev?????????B??????????????B????????????????л???????????context_switch()??switch_to????????У????????finish_task_switch(this_rq()?? prev)?????????????????????л??????????????????????????A?????????????B?????У?????last?????á?

????step8????eaxд??last??????B?????б????????prev?????

"=a" (last)  ??  last_B <== %eax

????????context_switch()?п????????switch_to????????

????switch_to(prev?? next?? prev)??

????????????????last???????prev???????switch_to??????????prev_B???????A??????????????

????????last??????????????A????е?A???????????????????????B?????С?

?????????switch_to??????????A?????У????????B????????????????ε????У?????A?????????????switch_to(C?? A)???????????????A??ε???????????????A?????context_switch()??switch_to???????????У??????????????prev_A?????C?????????????