MIT6.828-HW1-boot xv6

重点感谢大佬博客

以下是info reg的结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(gdb) info reg
eax 0x0 0
ecx 0x0 0
edx 0x1f0 496
ebx 0x10094 65684
esp 0x7bdc 0x7bdc
ebp 0x7bf8 0x7bf8
esi 0x10094 65684
edi 0x0 0
eip 0x10000c 0x10000c
eflags 0x46 [ PF ZF ]
cs 0x8 8
ss 0x10 16
ds 0x10 16
es 0x10 16
fs 0x0 0
gs 0x0 0

以下是从$esp开始,向上展示24字

1
2
3
4
5
6
7
(gdb) x/24x $esp
0x7bdc: 0x00007d87 0x00000000 0x00000000 0x00000000
0x7bec: 0x00000000 0x00000000 0x00000000 0x00000000
0x7bfc: 0x00007c4d 0x8ec031fa 0x8ec08ed8 0xa864e4d0
0x7c0c: 0xb0fa7502 0xe464e6d1 0x7502a864 0xe6dfb0fa
0x7c1c: 0x16010f60 0x200f7c78 0xc88366c0 0xc0220f01
0x7c2c: 0x087c31ea 0x10b86600 0x8ed88e00 0x66d08ec0

如何理解stack里的内容?

  1. 这个展示word的顺序是往右地址在变大
  2. 一直记住栈是向小的方向增长的
  3. bootblock.asm里的mov $0x7c00,%esp,告诉我们栈从0x7c00开始增长,所以0x7bfc那一行的第一个数字就是真正在栈里的第一个数
  4. 需要注意到bootblock.asm里,有以下代码,所以我们可以知道0x7bfc那一行的第一个数字表示的是push进去的bootmain返回地址
    1
    2
    3
    4
    5
    6
    7
    call    bootmain
    7c48: e8 f0 00 00 00 call 7d3d <bootmain>

    # If bootmain returns (it shouldn't), trigger a Bochs
    # breakpoint if running under Bochs, then loop.
    movw $0x8a00, %ax # 0x8a00 -> port 0x8a00
    7c4d: 66 b8 00 8a mov $0x8a00,%ax
  5. 接下来看bootmain函数的部分内容,可以看到在call bootmain之后便将ebppush入栈,相关知识见Lab1gcc calling convention for JOS。故我们可以得知,0x7bec那一行的最右边的数字0表示的是ebp的值,相关证据如下(我在0x7c43的地方打了断点,并展示寄存器的值,可以看到在没有call bootmain之前,ebp的值就是0,这与JOS中的entry.S里的movl $0x0,%ebp # nuke frame pointer原理应该是类似的吧?我猜的)
    1
    2
    3
    4
    5
    6
    7
    8
    00007d3d <bootmain>:
    {
    7d3d: 55 push %ebp
    7d3e: 89 e5 mov %esp,%ebp
    7d40: 57 push %edi
    7d41: 56 push %esi
    7d42: 53 push %ebx
    7d43: 83 ec 10 sub $0x10,%esp
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    Thread 1 hit Breakpoint 1, 0x00007c43 in ?? ()
    (gdb) info reg
    eax 0x0 0
    ecx 0x0 0
    edx 0x80 128
    ebx 0x0 0
    esp 0x6f20 0x6f20
    ebp 0x0 0x0
    esi 0x0 0
    edi 0x0 0
    eip 0x7c43 0x7c43
    eflags 0x6 [ PF ]
    cs 0x8 8
    ss 0x10 16
    ds 0x10 16
    es 0x10 16
    fs 0x0 0
    gs 0x0 0
  6. 至于0x7bdc那一行的第一个数字0x7d87,原理和7dfc类似
    1
    2
    3
    4
      entry();
    7d81: ff 15 18 00 01 00 call *0x10018
    }
    7d87: 8d 65 f4 lea -0xc(%ebp),%esp
    这样这个HW就算是做完了

MIT6.828-HW1-boot xv6
http://bugeater.space/2024/01/27/MIT6-828-HW1/
Author
BugEater
Posted on
January 27, 2024
Licensed under