第一步——ring0 --> ring1
(汇编和C的相互调用,见P121. )
r/kernel/kernel.asm ==>
...
extern p_proc_ready ; 这里是怎么在调用的啊???
restart:
mov esp, [p_proc_ready] ; r/include/global.h有EXTERN PROCESS* p_proc_ready,r/include/有如下定义:
; typedef struct s_proc {
; STACK_FRAME regs; /* process registers saved in stack frame */
;
; u16 ldt_sel; /* gdt selector giving ldt base and limit */
; DESCRIPTOR ldts[LDT_SIZE]; /* local descriptors for code and data */
;
; int ticks; /* remained ticks */
; int priority;
;
; u32 pid; /* process id passed in from MM */
; char p_name[16]; /* name of the process */
; }PROCESS;
lldt [esp+P_LDT_SEL] ; 把“内核栈”中一个“进程表”的u16 ldt_sel的内容载入ldtr
lea eax, [esp+P_STACKTOP] ; eax被赋予esp+P_STACKTOP
mov dword [tss+TSS3_S_SP0], eax
restart_reenter:
dec dword [k_reenter]
pop gs
pop fs
pop es
pop ds
popad
add esp, 4
iretd
r/kernel/main.c ==>
#include "proto.h" // 声明了 void restart(); 因此在下面的C代码中可以直接用汇编函数restart (r/kernel/kernel.asm中)
...
PUBLIC int kernel_main(){
restart();
}