MOS Source Code
Loading...
Searching...
No Matches
riscv64_platform.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3// #include "mos/device/console.h"
6#include "mos/mm/mm.h"
10#include "mos/riscv64/cpu/cpu.h"
13
16
17static u8 uart_buf[MOS_PAGE_SIZE] __aligned(MOS_PAGE_SIZE) = { 0 };
18
20{
21 serial_console_t *const serial_con = container_of(con, serial_console_t, con);
22 serial_con->device.driver_data = (void *) pa_va(0x10000000);
24 return true;
25}
26
29 .ops = &(console_ops_t){ .extra_setup = riscv64_uart_setup },
30 .default_bg = Black,
31 .default_fg = LightBlue,
32 .read.buf = uart_buf,
33 .read.size = MOS_PAGE_SIZE,
34 .name = "riscv_uart1" },
35 .device = { .baudrate_divisor = BAUD_RATE_115200,
36 .char_length = CHAR_LENGTH_8,
37 .parity = PARITY_NONE,
38 .stop_bits = STOP_BITS_1,
39 .driver = &riscv64_uart_driver,
40 .driver_data = NULL },
41};
42
44 .boot_console = &uart_console.con,
45};
46
48{
50
52
53 reg_t sstatus = read_csr(sstatus);
54 sstatus |= SSTATUS_SUM;
55 sstatus |= SSTATUS_FS_INITIAL; // enable sstatus.FS
56 write_csr(sstatus, sstatus);
57 write_csr(sie, SIE_SEIE | SIE_STIE | SIE_SSIE); // enable supervisor interrupts
58}
59
61{
62 // even SV39 supports 1 GB pages
63 const size_t STEP = 1 GB / MOS_PAGE_SIZE;
64 const size_t total_npages = ALIGN_UP(platform_info->max_pfn, STEP);
65
66 for (pfn_t pfn = 0; pfn < total_npages; pfn += STEP)
67 {
68 const ptr_t vaddr = pfn_va(pfn);
69 pml4e_t *pml4e = pml4_entry(platform_info->kernel_mm->pgd.max.next, vaddr);
70
71 // GB pages are at pml3e level
72 const pml3_t pml3 = pml4e_get_or_create_pml3(pml4e);
73 pml3e_t *const pml3e = pml3_entry(pml3, vaddr);
74 platform_pml3e_set_huge(pml3e, pfn);
76 }
77}
78
void platform_pml3e_set_flags(pml3e_t *pml3, vm_flags flags)
Definition mm.c:175
void platform_pml3e_set_huge(pml3e_t *pml3e, pfn_t pfn)
Definition paging.c:250
#define MOS_PAGE_SIZE
Definition autoconf.h:6
@ CONSOLE_CAP_READ
console supports read
Definition console.h:21
@ CONSOLE_CAP_EXTRA_SETUP
extra setup required
Definition console.h:20
@ LightBlue
Definition ansi_colors.h:28
@ Black
Definition ansi_colors.h:19
#define pa_va(pa)
Definition mm.h:80
#define pfn_va(pfn)
Definition mm.h:76
void interrupt_handler_register(u32 irq, irq_serve_t handler, void *data)
Register an interrupt handler.
Definition interrupt.c:38
#define GB
Definition mos_global.h:90
#define __aligned(x)
Definition mos_global.h:27
#define ALIGN_UP(addr, size)
Definition mos_global.h:73
#define container_of(ptr, type, member)
Definition mos_global.h:50
#define NULL
Definition pb_syshdr.h:46
@ VM_GLOBAL
Definition platform.h:48
@ VM_READ
Definition platform.h:41
@ VM_WRITE
Definition platform.h:42
void plic_enable_irq(u32 irq)
Definition plic.c:32
pml3e_t * pml3_entry(pml3_t pml3, ptr_t vaddr)
Definition pml3.c:20
pml3_t pml4e_get_or_create_pml3(pml4e_t *pml4e)
pml4e_t * pml4_entry(pml4_t pml4, ptr_t vaddr)
Definition pml4.c:21
pml3e_t pml4e_t
Definition pml_types.h:72
pml2e_t pml3e_t
Definition pml_types.h:60
#define SIE_SSIE
Definition cpu.h:44
#define read_csr(reg)
Definition cpu.h:23
#define SIE_SEIE
Definition cpu.h:42
#define SIE_STIE
Definition cpu.h:43
#define write_csr(reg, val)
Definition cpu.h:24
const char __riscv64_trap_entry[]
#define SSTATUS_SUM
Definition cpu.h:35
#define SSTATUS_FS_INITIAL
Definition cpu.h:38
#define UART0_IRQ
void platform_startup_setup_kernel_mm()
void platform_startup_late()
static mos_platform_info_t riscv64_platform_info
static bool riscv64_uart_setup(console_t *con)
void platform_startup_early()
mos_platform_info_t *const platform_info
static serial_console_t uart_console
@ STOP_BITS_1
Definition serial.h:31
@ CHAR_LENGTH_8
Definition serial.h:26
@ BAUD_RATE_115200
Definition serial.h:56
@ PARITY_NONE
Definition serial.h:37
bool serial_console_setup(console_t *console)
bool serial_console_irq_handler(u32 irq, void *data)
pgd_t pgd
Definition platform.h:82
mm_context_t * kernel_mm
Definition platform.h:118
serial_device_t device
void * driver_data
Definition serial.h:83
uintn reg_t
Definition types.h:51
unsigned long long pfn_t
Definition types.h:41
unsigned long ptr_t
Definition types.h:25
unsigned char u8
Definition types.h:19
const serial_driver_t riscv64_uart_driver
Definition uart_driver.c:33