lab 1

2018-03-13  本文已影响0人  ZoltanJin

Part 3: The kernel

  • Use QEMU and GDB to trace into the JOS kernel and find where the new virtual-to-physical mapping takes effect. Then examine the Global Descriptor Table (GDT) that the code uses to achieve this effect, and make sure you understand what's going on.
  • What is the first instruction after the new mapping is established that would fail to work properly if the old mapping were still in place? Comment out or otherwise intentionally break the segmentation setup code in kern/entry.S, trace into it, and see if you were right.

Formatted Printing to the console

We have omitted a small fragment of code - the code necessary to print octal numbers using patterns of the form "%o". Find and fill in this code fragment. Remember the octal number should begin with '0'.

  case 'o':
        num = getuint(&ap, lflag);
        putch('0', putdat);
        base = 8;
        goto number;

其中 putch() 函数地功能是向终端输出一个 char 并将一个 counter 加一。模仿 case 'u' ,并依照要求提前输出一个 '0' 。

You need also to add support for the "+" flag, which forces to precede the result with a plus or minus sign (+ or -) even for positive numbers.

// (signed) decimal
    case 'd':
        num = getint(&ap, lflag);
        if ((long long) num < 0) {
            putch('-', putdat);
            num = -(long long) num;
        }else if (plus){
            putch('+', putdat);
        }
        base = 10;              
        goto number;

主要修改了 case 'd' 代码段,因为只有 "%d" 涉及正负号。负的部分已经写好,plus 为一个记录正号出现的 flag,当 reswitch 的前一个循环读到了 '+' 符号,则把 plus 置为 1。

上一篇 下一篇

猜你喜欢

热点阅读