MIT 6.828 Lab1 在下的一些心得筆記.

352 views
Skip to first unread message

Hawx

unread,
Mar 18, 2012, 1:27:41 PM3/18/12
to 星系統社群

Ben

unread,
Mar 18, 2012, 1:41:59 PM3/18/12
to julu...@googlegroups.com
 非常好的心得,感謝分享。

Mars Cheng

unread,
Mar 22, 2012, 2:27:40 AM3/22/12
to julu...@googlegroups.com
大家好

我最近也在作lab1,有個問題想請教一下,在ex3的部份,由於kernel image放在第二個sector,所以loader要從第二個sector開始讀才對,這點作者在book-rev6.pdf page 86也有提到。

但是程式碼卻似乎是從第一個sector開始去讀?我有遺漏什麼嗎?

void
bootmain(void)
{
    struct Proghdr *ph, *eph;

    // read 1st page off disk
    readseg((uint32_t) ELFHDR, SECTSIZE*8, 0); 

    // is this a valid ELF?
    if (ELFHDR->e_magic != ELF_MAGIC)
        goto bad;

    // load each program segment (ignores ph flags)
    ph = (struct Proghdr *) ((uint8_t *) ELFHDR + ELFHDR->e_phoff);
    eph = ph + ELFHDR->e_phnum;


Ben <ben...@gmail.com> 於 2012年3月19日上午1:41 寫道:
 非常好的心得,感謝分享。

Mars Cheng

unread,
Mar 22, 2012, 2:41:46 AM3/22/12
to julu...@googlegroups.com
嗯...我看到了,原來是在:

void
readseg(uint32_t pa, uint32_t count, uint32_t offset)
{
    uint32_t end_pa;

    end_pa = pa + count;

    // round down to sector boundary
    pa &= ~(SECTSIZE - 1);

    // translate from bytes to sectors, and kernel starts at sector 1
    offset = (offset / SECTSIZE) + 1;

Jim Huang

unread,
Mar 22, 2012, 2:48:24 AM3/22/12
to julu...@googlegroups.com
在 2012年3月22日下午2:41,Mars Cheng <rebor...@gmail.com> 寫道:
> 嗯...我看到了,原來是在:
> void readseg(uint32_t pa, uint32_t count, uint32_t offset) {
> uint32_t end_pa;
> end_pa = pa + count;
> // round down to sector boundary
> pa &= ~(SECTSIZE - 1);
> // translate from bytes to sectors, and kernel starts at sector 1
> offset = (offset / SECTSIZE) + 1;

所以這是英文語意的問題,first != 1

Interesting!

Reply all
Reply to author
Forward
0 new messages