2019-05-31 13:45:59 +00:00
|
|
|
// Physical memory layout
|
2011-08-07 16:30:34 +00:00
|
|
|
|
2019-06-04 18:20:37 +00:00
|
|
|
// qemu -machine virt is set up like this,
|
|
|
|
// based on qemu's hw/riscv/virt.c:
|
|
|
|
//
|
2019-05-31 13:45:59 +00:00
|
|
|
// 00001000 -- boot ROM, provided by qemu
|
2019-06-04 18:20:37 +00:00
|
|
|
// 02000000 -- CLINT
|
2019-06-04 14:43:45 +00:00
|
|
|
// 0C000000 -- PLIC
|
2019-06-13 10:49:02 +00:00
|
|
|
// 10000000 -- uart0
|
|
|
|
// 10001000 -- virtio disk
|
2019-05-31 13:45:59 +00:00
|
|
|
// 80000000 -- boot ROM jumps here in machine mode
|
2019-05-31 15:45:42 +00:00
|
|
|
// -kernel loads the kernel here
|
2019-05-31 13:45:59 +00:00
|
|
|
// unused RAM after 80000000.
|
2011-08-07 16:30:34 +00:00
|
|
|
|
2019-05-31 13:45:59 +00:00
|
|
|
// the kernel uses physical memory thus:
|
|
|
|
// 80000000 -- entry.S, then kernel text and data
|
|
|
|
// end -- start of kernel page allocation area
|
|
|
|
// PHYSTOP -- end RAM used by the kernel
|
2011-08-07 16:30:34 +00:00
|
|
|
|
2019-06-03 18:13:07 +00:00
|
|
|
// qemu puts UART registers here in physical memory.
|
2019-05-31 13:45:59 +00:00
|
|
|
#define UART0 0x10000000L
|
2019-06-03 19:23:12 +00:00
|
|
|
#define UART0_IRQ 10
|
2011-08-07 16:30:34 +00:00
|
|
|
|
2019-06-13 10:57:38 +00:00
|
|
|
// virtio mmio interface
|
2019-06-13 13:40:17 +00:00
|
|
|
#define VIRTIO0 0x10001000
|
|
|
|
#define VIRTIO0_IRQ 1
|
2019-06-13 10:49:02 +00:00
|
|
|
|
2019-06-04 18:20:37 +00:00
|
|
|
// local interrupt controller, which contains the timer.
|
|
|
|
#define CLINT 0x2000000L
|
2019-06-05 15:42:03 +00:00
|
|
|
#define CLINT_MTIMECMP(hartid) (CLINT + 0x4000 + 8*(hartid))
|
2019-07-25 09:35:03 +00:00
|
|
|
#define CLINT_MTIME (CLINT + 0xBFF8) // cycles since boot.
|
2019-06-04 18:20:37 +00:00
|
|
|
|
2019-06-03 18:13:07 +00:00
|
|
|
// qemu puts programmable interrupt controller here.
|
|
|
|
#define PLIC 0x0c000000L
|
2019-06-05 18:05:46 +00:00
|
|
|
#define PLIC_PRIORITY (PLIC + 0x0)
|
|
|
|
#define PLIC_PENDING (PLIC + 0x1000)
|
|
|
|
#define PLIC_MENABLE(hart) (PLIC + 0x2000 + (hart)*0x100)
|
|
|
|
#define PLIC_SENABLE(hart) (PLIC + 0x2080 + (hart)*0x100)
|
|
|
|
#define PLIC_MPRIORITY(hart) (PLIC + 0x200000 + (hart)*0x2000)
|
|
|
|
#define PLIC_SPRIORITY(hart) (PLIC + 0x201000 + (hart)*0x2000)
|
|
|
|
#define PLIC_MCLAIM(hart) (PLIC + 0x200004 + (hart)*0x2000)
|
|
|
|
#define PLIC_SCLAIM(hart) (PLIC + 0x201004 + (hart)*0x2000)
|
2019-06-03 18:13:07 +00:00
|
|
|
|
2019-05-31 13:45:59 +00:00
|
|
|
// the kernel expects there to be RAM
|
|
|
|
// for use by the kernel and user pages
|
|
|
|
// from physical address 0x80000000 to PHYSTOP.
|
|
|
|
#define KERNBASE 0x80000000L
|
2019-06-04 14:43:45 +00:00
|
|
|
#define PHYSTOP (KERNBASE + 128*1024*1024)
|
2019-05-31 13:45:59 +00:00
|
|
|
|
|
|
|
// map the trampoline page to the highest address,
|
|
|
|
// in both user and kernel space.
|
|
|
|
#define TRAMPOLINE (MAXVA - PGSIZE)
|
2019-07-23 16:17:17 +00:00
|
|
|
|
|
|
|
// map kernel stacks beneath the trampoline,
|
|
|
|
// each surrounded by invalid guard pages.
|
2019-07-22 18:54:40 +00:00
|
|
|
#define KSTACK(p) (TRAMPOLINE - ((p)+1)* 2*PGSIZE)
|
|
|
|
|
|
|
|
// User memory layout.
|
|
|
|
// Address zero first:
|
|
|
|
// text
|
|
|
|
// original data and bss
|
|
|
|
// fixed-size stack
|
|
|
|
// expandable heap
|
|
|
|
// ...
|
2020-07-17 20:29:52 +00:00
|
|
|
// TRAPFRAME (p->trapframe, used by the trampoline)
|
2019-07-22 18:54:40 +00:00
|
|
|
// TRAMPOLINE (the same page as in the kernel)
|
|
|
|
#define TRAPFRAME (TRAMPOLINE - PGSIZE)
|