May 12

小插曲

修改MakeFile

和Project0一样,Project1在make depend && make时,也会有错误提示,一步一步来解决:

0.去掉过于严格的编译选项(line 178):

CC_GENERAL_OPTS := $(GENERAL_OPTS) -Werror

改为:

CC_GENERAL_OPTS := $(GENERAL_OPTS)

1.去掉gcc栈保护的选项(line 176):

GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS)

改为:

GENERAL_OPTS := -O -Wall -fno-stack-protector $(EXTRA_C_OPTS)

May 8

官方说明

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

 

  1. This project will not require much code to be written. However, it may take some time to get things set up and debugged.
  2. Execution of the GeekOS kernel begins in the Main() function in the source file src/geekos/main.c.
  3. 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()

 

May 7

搭建实验环境

基本系统安装好后GeekOS实验环境需要安装的组件只有bochs和nasm,直接使用源中的软件包即可:

$ sudo pacman -S bochs nasm

这里下载geekos-0.3软件包。 解压缩后会得到一个geekos-0.3.0目录

开始GeekOS之路

首先试试第一个项目:

 

$ cd ~/workspace/geekos-0.3.0/src/project0/build$
$ make depend
$ make

make后会提示错误:

cc1: warnings being treated as errors
In file included from ../src/geekos/gdt.c:11:
../include/geekos/segment.h:43: error: ‘packed’ attribute ignored for field of type ‘uchar_t’
make: *** [geekos/gdt.o] 错误 1