Jos-hw4

13 篇文章 0 订阅
1. Turn in: the output of print-stack with the valid part of the stack marked. Write a short

(3-5 word) comment next to each non-zero value explaining what it is.
<bochs:5> print-stack
Stack address size 4
 | STACK 0x00007bcc [0x00007d9f]     -> the return address of call function cmain() in bootblock.asm
 | STACK 0x00007bd0 [0x00000000]
 | STACK 0x00007bd4 [0x00000000]
 | STACK 0x00007bd8 [0x00000000]
 | STACK 0x00007bdc [0x00000000]
 | STACK 0x00007be0 [0x00000000]
 | STACK 0x00007be4 [0x00000000]
 | STACK 0x00007be8 [0x00000000]
 | STACK 0x00007bec [0x00010094]  --> local variable
 | STACK 0x00007bf0 [0x00000000]
 | STACK 0x00007bf4 [0x00000000]
 | STACK 0x00007bf8 [0x00000000]  --> ebp address
 | STACK 0x00007bfc [0x00007c49]
 | STACK 0x00007c00 [0xc031fcfa]
 | STACK 0x00007c04 [0xc08ed88e]
 | STACK 0x00007c08 [0x00bcd08e]
Others are local variables in cmain()

Reference in regs:

eax: 0x00101450 1053776
ecx: 0x00000000 0
edx: 0x000001f0 496
ebx: 0x00010094 65684
esp: 0x00007bcc 31692
ebp: 0x00007bf8 31736
esi: 0x000e0000 917504
edi: 0x0000ffac 65452
eip: 0x00101450


2. Now look at kernel.asm for the instructions in main0 that read:

(The addresses and constants might be different for you. Look for the moves into %esp and %ebp).
Which lines in main.c do these instructions correspond to?

 39   // switch to bootstrap processor's stack
 40   asm volatile("movl %0, %%esp" : : "r" (cpus[0].mpstack + MPSTACK - 32));
 41   asm volatile("movl %0, %%ebp" : : "r" (cpus[0].mpstack + MPSTACK));

3.  Turn in: answers to the following questions. Look at the assembly for the call to
lapic_init that immediately follows the stack switch. Where does the bcpu argument
come from? What would have happened if the compiler had instead chosen to save bcpu
on the stack before those four assembly instructions? Would the code still work? Why or
why not?

it's the return value of mp_bcpu(),

1756   1014d2:       89 04 24                mov    %eax,(%esp)

If not SMP, the code will still works without stack switch.

Without optimization, the result is more clear, before calling lapic_init,

2184   101b6e:       e8 5e 08 00 00          call   1023d1 <mp_bcpu>
2185   101b73:       89 45 f0                mov    %eax,-0x10(%ebp)
2186   101b76:       8b 45 f0                mov    -0x10(%ebp),%eax
2187   101b79:       89 04 24                mov    %eax,(%esp)
2188   101b7c:       e8 16 fa ff ff          call   101597 <lapic_init     >

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值