Skip to content

Academic Operating System

Hirochika Asai edited this page Jan 7, 2016 · 11 revisions

Welcome to the aos wiki!

[x86 instructions](x86 instructions)

Physical memory map

Boot monitor

Start    End       Description
----------------------------------------------------------
00000500 00005fff  free
00006000 000061ff  buffer for kernel loader
00006200 00007bff  default stack in boot monitor
00007c00 00007dff  MBR
00007e00 00007fff  free
00008000 00008fff  boot information
00009000 0000ffff  boot monitor (currently 15*512B used)
----------------------------------------------------------
00010000 00078fff  free
00079000 0007ffff  page table (at least 24KiB = 6 * 4KiB)
00080000 000fffff  free or reserved (We don't use here)
----------------------------------------------------------
00100000 00ffffff  reserved for kernel
01000000 01ffffff  for processor flags, tss, stack
----------------------------------------------------------
* managed by the memory allocator below *
----------------------------------------------------------
02000000 --------  free

Kernel

Start    End       Description
----------------------------------------------------------
00000500 00007fff  free
00008000 00008fff  boot information
00009000 0000ffff  free
----------------------------------------------------------
00010000 0002ffff  kernel (128KiB)
00030000 0006ffff  initramfs (256KiB)
00070000 00073fff  trampoline (16KiB)
00074000 00075fff  GDT (8KiB)
00076000 00077fff  IDT (8KiB)
00078000 00078fff  kernel variable (4KiB)
00079000 0007ffff  page table (at least 24KiB = 6 * 4KiB)
00080000 000fffff  free or reserved (We don't use here)
----------------------------------------------------------
00100000 00ffffff  used by kmem
----------------------------------------------------------
01000000 0100ffff  BSP (flags, tss, stack)
01010000 0101ffff  AP #1
....     01ffffff  for application processors
----------------------------------------------------------
* managed by the memory allocator below *
----------------------------------------------------------
02000000 --------  free

Virtual memory

Start    End       Description
----------------------------------------------------------
00000000 3fffffff  Kernel
----------------------------------------------------------
40000000 bfffffff  Userland application
----------------------------------------------------------
c0000000 e7ffffff  Kernel
e8000000 ffffffff  Kernel (for APIC etc.)

At the current version, we don't implement kernel relocation to the higher address space. Therefore, unlike other UNIX-like operating systems, 0-1 GiB are also used by kernel and userland applications use 1-3 GiB space.

Page table (x86-64)

              PDPT        PD
+------+    +------+    +------+
| PML4 |    |      |    | 0-1G | << Pointed from PDPT of any CR3: Shared
+------+    +------+    +------+
                        +------+
                        | 1-2G |
                        +------+
                        +------+
                        | 2-3G |
                        +------+
                        +------+
                        | 3-4G | << Pointed from PDPT of any CR3: Shared
                        +------+

Design of memory allocator

  • Prefixes
  • pmem_ : Physical memory
  • vmem_ : Virtual memory
  • kmem_ : Kernel memory

Dependencies

malloc() --> mmap() --> vmem_page_alloc() --> pmem_page_alloc()
(libc)       (syscall)   | for page table entry
                         v
                        kmalloc()
                         |
                         v
                        kmem_page_alloc() --> pmem_page_alloc()

Clone this wiki locally