Files
riscv-operating-system-mooc/code/os/06-interrupts/platform.h
2025-04-28 17:10:11 +08:00

67 lines
2.0 KiB
C

#ifndef __PLATFORM_H__
#define __PLATFORM_H__
/*
* QEMU RISC-V Virt machine with 16550a UART and VirtIO MMIO
*/
/*
* maximum number of CPUs
* see https://github.com/qemu/qemu/blob/master/include/hw/riscv/virt.h
* #define VIRT_CPUS_MAX 8
*/
#define MAXNUM_CPU 8
/* used in os.ld */
#define LENGTH_RAM 128*1024*1024
/*
* 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 0x10000000L
/*
* 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 0x00
* #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) * 4)
#define PLIC_MENABLE(hart, id) (PLIC_BASE + 0x2000 + (hart) * 0x80 + ((id) / 32) * 4)
#define PLIC_MTHRESHOLD(hart) (PLIC_BASE + 0x200000 + (hart) * 0x1000)
#define PLIC_MCLAIM(hart) (PLIC_BASE + 0x200004 + (hart) * 0x1000)
#define PLIC_MCOMPLETE(hart) (PLIC_BASE + 0x200004 + (hart) * 0x1000)
#endif /* __PLATFORM_H__ */