6.828: Operating System Engineering (28)

直前エントリで書いたように、とりあえず make qemu-gdb して gdbi386_detect_memory の中身を見てみます。

$ gdb
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
+ target remote localhost:26000
The target architecture is assumed to be i8086
[f000:fff0]    0xffff0: ljmp   $0xf000,$0xe05b
0x0000fff0 in ?? ()
+ symbol-file obj/kern/kernel
(gdb) b i386_detect_memory
Breakpoint 1 at 0xf0100a64: file kern/pmap.c, line 65.
(gdb) c
Continuing.
The target architecture is assumed to be i386
=> 0xf0100a64 <i386_detect_memory>:     push   %ebp

Breakpoint 1, i386_detect_memory () at kern/pmap.c:65
65      {
(gdb) list
60              return mc146818_read(r) | (mc146818_read(r + 1) << 8);
61      }
62
63      void
64      i386_detect_memory(void)
65      {
66              // CMOS tells us how many kilobytes there are
67              basemem = ROUNDDOWN(nvram_read(NVRAM_BASELO)*1024, PGSIZE);
68              extmem = ROUNDDOWN(nvram_read(NVRAM_EXTLO)*1024, PGSIZE);
69
(gdb) 

確認しておきたいのは

  • basemem の値
  • extmem の値
  • maxpa の値
    • EXTPHYSMEM の値
      • これ 0x100000 ですね (inc/memlayout.h)
  • npage の値

ということでかくにん。

(gdb) n
=> 0xf0100a6a <i386_detect_memory+6>:   mov    $0x15,%eax
67              basemem = ROUNDDOWN(nvram_read(NVRAM_BASELO)*1024, PGSIZE);
(gdb) n
=> 0xf0100a81 <i386_detect_memory+29>:  mov    $0x17,%eax
68              extmem = ROUNDDOWN(nvram_read(NVRAM_EXTLO)*1024, PGSIZE);
(gdb) n
=> 0xf0100a98 <i386_detect_memory+52>:  test   %eax,%eax
72              if (extmem)
(gdb) n
=> 0xf0100a9c <i386_detect_memory+56>:  add    $0x100000,%eax
73                      maxpa = EXTPHYSMEM + extmem;
(gdb) n
=> 0xf0100ab2 <i386_detect_memory+78>:  mov    0xf01115a8,%eax
77              npage = maxpa / PGSIZE;
(gdb) n
=> 0xf0100ac2 <i386_detect_memory+94>:  shr    $0xa,%eax
79              cprintf("Physical memory: %dK available, ", (int)(maxpa/1024));
(gdb) 

を、extmem は 0 ではない模様。

(gdb) p/x basemem
$1 = 0xa0000
(gdb) p/x extmem
$2 = 0x3fff000
(gdb) p/x maxpa
$3 = 0x40ff000
(gdb) p/x npage
$4 = 0x40ff
(gdb) 

0x3fff000 に 0x100000 を足して 0x40ff000 なのか。あと PGSIZE は 4096 で define されてるので (inc/mmu.h) 0x1000 なんですね。見事に 12 bits 右 shift だったり。

残り確認事項

  • ROUNDUP とか ROUNDDOWN マクロの理解
  • check_boot_pgdir 手続きの確認

とりあえず ROUNDUP とか ROUNDDOWN はイメージできたカンジ。ROUNDUP は丁度ならそこで、そうでなければ次に、って理解で良いのかな。
あとは check_boot_pgdir 手続きのソースを見つつ、うにまがの Linux ブートプロセスとかを見つつもごもごする方向で。