官方说明
The Assignment
Add code to the kernel to create a new kernel mode thread. The kernel mode thread should print out ”Hello from xxx” where xxx is your name. It should then call the keyboard input routine Wait For Key() repeatly (and echo each character entered) until the termination character (control-d) is entered.
Hints
-
This project will not require much code to be written. However, it may take some time to get things set up and debugged.
-
Execution of the GeekOS kernel begins in the Main() function in the source file src/geekos/main.c.
-
To start a new kernel mode thread you use the
Start_Kernel_Thread()
function. Look at the
comments before the definition of this function in src/geekos/kthread.c.
文档给了很多提示,比如在你需要开启一个内核级线程,你需要函数Start_Kernel_Thread()
,而这个函数就在文件src/geekos/kthread.c中,先不忙看Start_Kernel_Thread()
这个函数,看看Main()
函数都做了些什么。
/*
* Kernel C code entry point.
* Initializes kernel subsystems, mounts filesystems,
* and spawns init process.
*/
void Main(struct Boot_Info* bootInfo)
{
Init_BSS();
Init_Screen();
Init_Mem(bootInfo);
Init_CRC32();
Init_TSS();
Init_Interrupts();
Init_Scheduler();
Init_Traps();
Init_Timer();
Init_Keyboard();
Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT));
Print("Welcome to GeekOS!\n");
Set_Current_Attr(ATTRIB(BLACK, GRAY));
TODO("Start a kernel thread to echo pressed keys and print counts");
/* Now this thread is done. */
Exit(0);
}
从第一个函数开始,Init_BSS()