-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.hh
89 lines (81 loc) · 3.14 KB
/
platform.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef KRV_OS_PLATFORM_HH
#define KRV_OS_PLATFORM_HH
#define MAXNUM_CPU 8
/*
* MemoryMap
* see https://github.com/qemu/qemu/blob/master/hw/riscv/virt.c, virt_memmap[]
* 0x00001000 -- boot ROM, provided by qemu
* 0x02000000 -- CLINT
* 0x0C000000 -- PLIC
* 0x10000000 -- UART0
* 0x10001000 -- virtio disk
* 0x80000000 -- boot ROM jumps here in machine mode, where we load our kernel
*/
/* This machine puts UART registers here in physical memory. */
#define UART0 0x10000000
/*
* UART0 interrupt source
* see https://github.com/qemu/qemu/blob/master/include/hw/riscv/virt.h
* enum {
* UART0_IRQ = 10,
* ......
* };
*/
#define UART0_IRQ 10
/*
* This machine puts platform-level interrupt controller (PLIC) here.
* Here only list PLIC registers in Machine mode.
* see https://github.com/qemu/qemu/blob/master/include/hw/riscv/virt.h
* #define VIRT_PLIC_HART_CONFIG "MS"
* #define VIRT_PLIC_NUM_SOURCES 127
* #define VIRT_PLIC_NUM_PRIORITIES 7
* #define VIRT_PLIC_PRIORITY_BASE 0x04
* #define VIRT_PLIC_PENDING_BASE 0x1000
* #define VIRT_PLIC_ENABLE_BASE 0x2000
* #define VIRT_PLIC_ENABLE_STRIDE 0x80
* #define VIRT_PLIC_CONTEXT_BASE 0x200000
* #define VIRT_PLIC_CONTEXT_STRIDE 0x1000
* #define VIRT_PLIC_SIZE(__num_context) \
* (VIRT_PLIC_CONTEXT_BASE + (__num_context) * VIRT_PLIC_CONTEXT_STRIDE)
*/
#define PLIC_BASE 0x0c000000L
#define PLIC_PRIORITY(id) (PLIC_BASE + (id) * 4)
#define PLIC_PENDING(id) (PLIC_BASE + 0x1000 + ((id) / 32))
#define PLIC_MENABLE(hart) (PLIC_BASE + 0x2000 + (hart) * 0x80)
#define PLIC_MTHRESHOLD(hart) (PLIC_BASE + 0x200000 + (hart) * 0x1000)
// The mapped-address are same for riscv-64 and riscv-32
#define PLIC_MCLAIM(hart) (PLIC_BASE + 0x200004 + (hart) * 0x1000)
#define PLIC_MCOMPLETE(hart) (PLIC_BASE + 0x200004 + (hart) * 0x1000)
/*
* The Core Local INTerruptor (CLINT) block holds memory-mapped control and
* status registers associated with software and timer interrupts.
* QEMU-virt reuses sifive configuration for CLINT.
* see https://gitee.com/qemu/qemu/blob/master/include/hw/riscv/sifive_clint.h
* enum {
* SIFIVE_SIP_BASE = 0x0,
* SIFIVE_TIMECMP_BASE = 0x4000,
* SIFIVE_TIME_BASE = 0xBFF8
* };
*
* enum {
* SIFIVE_CLINT_TIMEBASE_FREQ = 10000000
* };
*
* Notice:
* The machine-level MSIP bit of mip register are written by accesses to
* memory-mapped control registers, which are used by remote harts to provide
* machine-mode interprocessor interrupts.
* For QEMU-virt machine, Each msip register is a 32-bit wide WARL register
* where the upper 31 bits are tied to 0. The least significant bit is
* reflected in the MSIP bit of the mip CSR. We can write msip to generate
* machine-mode software interrupts. A pending machine-level software
* interrupt can be cleared by writing 0 to the MSIP bit in mip.
* On reset, each msip register is cleared to zero.
*/
#define CLINT_BASE 0x2000000L
#define CLINT_MSIP(hartid) (CLINT_BASE + 4 * (hartid))
#define CLINT_MTIMECMP(hartid) (CLINT_BASE + 0x4000 + 8 * (hartid))
#define CLINT_MTIME (CLINT_BASE + 0xBFF8) // cycles since boot.
/* 10000000 ticks per-second */
#define CLINT_TIMEBASE_FREQ 10000000
#endif