MIT 6.828 JOS lab1启动

 

格式化输出

Exercise 8

Q: Explain the interface between printf.c and console.c. Specifically, what function does console.c export? How is this function used by printf.c?

printf.c用于内核态printf,console.c提供控制台相关I/O操作。前者调用后者中的cputchar()显示字符串内容。

Q:Explain the following from console.c:

1      if (crt_pos >= CRT_SIZE) {
2              int i;
3              memmove(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) * sizeof(uint16_t));
4              for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++)
5                      crt_buf[i] = 0x0700 | ' ';
6              crt_pos -= CRT_COLS;
7      }

如果光标超出屏幕,将屏幕上移一行。

Q:In the call to cprintf(), to what does fmt point? To what does ap point?
List (in order of execution) each call to cons_putc, va_arg, and vcprintf. For cons_putc, list its argument as well. For va_arg, list what ap points to before and after the call. For vcprintf list the values of its two arguments.

fmt指向第一个参数,ap指向第二个参数。
vcprintf(),之后一个字符就一个va_arg()和cons_putc()。va_arg()调用后ap指向剩余参数中的下一个。

Q:Run the following code.

    unsigned int i = 0x00646c72;
    cprintf("H%x Wo%s", 57616, &i);

What is the output? Explain how this output

输出"He110 World"。57616==e110,"rld"因为是Intel是小端。

Q:In the following code, what is going to be printed after 'y='?

    cprintf("x=%d y=%d", 3);

y值是不确定的,因为读取范围超出了。

JOS的栈,及call和ret时的操作。

Exercise 9

Q:Determine where the kernel initializes its stack, and exactly where in memory its stack is located. How does the kernel reserve space for its stack? And at which "end" of this reserved area is the stack pointer initialized to point to?

entry.S中movl $0x0, %ebpmovl $(bootstacktop), %esp初始化栈。栈顶在0xf0110000.

Exercise 10

Q:How many 32-bit words does each recursive nesting level of test_backtrace push on the stack, and what are those words?

对比前后esp,每次入栈8个32-bit字。

Exercise 11

Implement the backtrace function as specified above. Implement the backtrace function as specified above.

    uint32_t ebp, eip, *arg;
    int i, j;

    ebp = read_ebp();
    eip = read_eip();
    for (i = 0; i < STACKFRAME_DEPTH; i++) {
        cprintf("ebp:0x%08x eip:0x%08x args:", ebp, eip);
        arg = (uint32_t *)ebp + 2;
        for (j = 0; j < 4; j++) { 
            cprintf("0x%08x ", arg[j]);
        }       
        cprintf("\n");
        print_debuginfo(eip - 1);
        eip = ((uint32_t *)ebp)[1];
        ebp = ((uint32_t *)ebp)[0];
    } 

Exercise 12

Modify your stack backtrace function to display, for each eip, the function name, source file name, and line number corresponding to that eip.

原理为依据内核ELF的stab符号表来得到相关位置信息,stab有n_strx,n_type,n_other,n_desc,n_value五项。

objdump -G obj/kern/kernel:查看内核总体stab
gcc -pipe -nostdinc -O2 -fno-builtin -I. -MD -Wall -Wno-format -DJOS_KERNEL -gstabs -c -S kern/init.c:生成带stab信息的init.s

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

 

转载于:https://www.cnblogs.com/atlasfly/p/9494154.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值