From d407b17b18513216d2c0266a3c61b00e6a5c5925 Mon Sep 17 00:00:00 2001 From: X512 Date: Fri, 23 Apr 2021 02:15:57 +0900 Subject: [PATCH] kernel: riscv64 patches Change-Id: I8ebcbaa395cbccb50af08fd2f1b049b5cbb949c7 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3883 Reviewed-by: Fredrik Holmqvist Reviewed-by: Adrien Destugues Reviewed-by: X512 --- build/jam/ArchitectureRules | 5 +- .../private/kernel/arch/riscv64/arch_int.h | 40 +++++++++++++ .../private/kernel/arch/riscv64/arch_kernel.h | 29 +++++----- .../kernel/arch/riscv64/arch_kernel_args.h | 8 +-- headers/private/kernel/arch/user_memory.h | 2 + .../private/system/arch/riscv64/arch_config.h | 1 - src/system/boot/arch/riscv64/arch_cpu.cpp | 1 + src/system/kernel/arch/riscv64/arch_asm.S | 56 ------------------- 8 files changed, 62 insertions(+), 80 deletions(-) diff --git a/build/jam/ArchitectureRules b/build/jam/ArchitectureRules index 697b6bfd70..7a5ee4e91c 100644 --- a/build/jam/ArchitectureRules +++ b/build/jam/ArchitectureRules @@ -422,8 +422,9 @@ rule KernelArchitectureSetup architecture case riscv64 : # Kernel lives within any single 2 GiB address space. # Default is medlow (-2GiB / +2GiB) - HAIKU_KERNEL_CCFLAGS += -mcmodel=medany ; - HAIKU_KERNEL_C++FLAGS += -mcmodel=medany ; + HAIKU_KERNEL_CCFLAGS += -mcmodel=medany -fpic ; + HAIKU_KERNEL_C++FLAGS += -mcmodel=medany -fpic ; + HAIKU_KERNEL_PIC_LINKFLAGS = -shared ; case sparc : # The medlow code model is enough (64-bit addresses, programs must diff --git a/headers/private/kernel/arch/riscv64/arch_int.h b/headers/private/kernel/arch/riscv64/arch_int.h index 537e91564b..3fd814d512 100644 --- a/headers/private/kernel/arch/riscv64/arch_int.h +++ b/headers/private/kernel/arch/riscv64/arch_int.h @@ -13,4 +13,44 @@ #define NUM_IO_VECTORS 256 + +static inline void +arch_int_enable_interrupts_inline(void) +{ + // TODO: implement +} + + +static inline int +arch_int_disable_interrupts_inline(void) +{ + // TODO: implement + return 0; +} + + +static inline void +arch_int_restore_interrupts_inline(int oldState) +{ + // TODO: implement +} + + +static inline bool +arch_int_are_interrupts_enabled_inline(void) +{ + // TODO: implement + return false; +} + + +// map the functions to the inline versions +#define arch_int_enable_interrupts() arch_int_enable_interrupts_inline() +#define arch_int_disable_interrupts() arch_int_disable_interrupts_inline() +#define arch_int_restore_interrupts(status) \ + arch_int_restore_interrupts_inline(status) +#define arch_int_are_interrupts_enabled() \ + arch_int_are_interrupts_enabled_inline() + + #endif /* _KERNEL_ARCH_RISCV64_INT_H */ diff --git a/headers/private/kernel/arch/riscv64/arch_kernel.h b/headers/private/kernel/arch/riscv64/arch_kernel.h index 624c1d677a..058eb54c4f 100644 --- a/headers/private/kernel/arch/riscv64/arch_kernel.h +++ b/headers/private/kernel/arch/riscv64/arch_kernel.h @@ -5,9 +5,13 @@ #ifndef _KERNEL_ARCH_RISCV64_KERNEL_H #define _KERNEL_ARCH_RISCV64_KERNEL_H -#include -#warning Review arch_kernel.h +#ifndef _ASSEMBLER +#ifdef __cplusplus +# include +#endif +#endif + // memory layout #define KERNEL_LOAD_BASE 0x80000000 @@ -17,25 +21,22 @@ #if defined(__riscv64__) // Base of the kernel address space. -#define KERNEL_BASE 0xffffff0000000000 -#define KERNEL_SIZE 0x10000000000 -#define KERNEL_TOP (KERNEL_BASE + (KERNEL_SIZE - 1)) +#define KERNEL_BASE (0x0000000000000000 + 0x1000) +#define KERNEL_TOP (0x0000004000000000 - 1) +#define KERNEL_SIZE ((KERNEL_TOP - KERNEL_BASE) + 1) // Kernel physical memory map area. -#define KERNEL_PMAP_BASE 0xffffff0000000000 -#define KERNEL_PMAP_SIZE 0x8000000000 +#define KERNEL_PMAP_BASE 0x0000003000000000 +#define KERNEL_PMAP_SIZE 0x1000000000 // Userspace address space layout. -// There is a 2MB hole just before the end of the bottom half of the address -// space. This means that if userland passes in a buffer that crosses into the -// uncanonical address region, it will be caught through a page fault. -#define USER_BASE 0x100000 +#define USER_BASE 0xffffffc000000000 #define USER_BASE_ANY USER_BASE -#define USER_SIZE (0x800000000000 - (0x200000 + USER_BASE)) +#define USER_SIZE 0x0000004000000000 #define USER_TOP (USER_BASE + (USER_SIZE - 1)) -#define KERNEL_USER_DATA_BASE 0x7f0000000000 -#define USER_STACK_REGION 0x7f0000000000 +#define KERNEL_USER_DATA_BASE (USER_BASE + 0x3000000000) +#define USER_STACK_REGION (USER_BASE + 0x3000000000) #define USER_STACK_REGION_SIZE ((USER_TOP - USER_STACK_REGION) + 1) #else /* ! __riscv64__ */ diff --git a/headers/private/kernel/arch/riscv64/arch_kernel_args.h b/headers/private/kernel/arch/riscv64/arch_kernel_args.h index 9af2c6dab7..c8b888a3dd 100644 --- a/headers/private/kernel/arch/riscv64/arch_kernel_args.h +++ b/headers/private/kernel/arch/riscv64/arch_kernel_args.h @@ -20,19 +20,13 @@ // kernel args typedef struct { - // architecture specific - uint64 phys_pgdir; - uint64 vir_pgdir; - uint64 next_pagetable; - - uint64 virtual_end; - // The virtual ranges we want to keep in the kernel. uint32 num_virtual_ranges_to_keep; addr_range virtual_ranges_to_keep[MAX_VIRTUAL_RANGES_TO_KEEP]; // needed for UEFI, otherwise kernel acpi support can't find ACPI root FixedWidthPointer acpi_root; + FixedWidthPointer fdt; } _PACKED arch_kernel_args; #endif /* KERNEL_ARCH_RISCV64_KERNEL_ARGS_H */ diff --git a/headers/private/kernel/arch/user_memory.h b/headers/private/kernel/arch/user_memory.h index e4dd9f0712..7ac6989295 100644 --- a/headers/private/kernel/arch/user_memory.h +++ b/headers/private/kernel/arch/user_memory.h @@ -15,6 +15,8 @@ # include #elif defined(__M68K__) # include +#elif defined(__riscv) +# include #else extern "C" { diff --git a/headers/private/system/arch/riscv64/arch_config.h b/headers/private/system/arch/riscv64/arch_config.h index 6e22c47143..f23d06da31 100644 --- a/headers/private/system/arch/riscv64/arch_config.h +++ b/headers/private/system/arch/riscv64/arch_config.h @@ -5,7 +5,6 @@ #ifndef _SYSTEM_ARCH_RISCV64_CONFIG_H #define _SYSTEM_ARCH_RISCV64_CONFIG_H -#warning IMPLEMENT _SYSTEM_ARCH_RISCV64_CONFIG_H #define FUNCTION_CALL_PARAMETER_ALIGNMENT_TYPE unsigned int diff --git a/src/system/boot/arch/riscv64/arch_cpu.cpp b/src/system/boot/arch/riscv64/arch_cpu.cpp index 1a35889aff..89eb07bff5 100644 --- a/src/system/boot/arch/riscv64/arch_cpu.cpp +++ b/src/system/boot/arch/riscv64/arch_cpu.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/src/system/kernel/arch/riscv64/arch_asm.S b/src/system/kernel/arch/riscv64/arch_asm.S index 4fa5b032d6..f345a1167b 100644 --- a/src/system/kernel/arch/riscv64/arch_asm.S +++ b/src/system/kernel/arch/riscv64/arch_asm.S @@ -5,62 +5,6 @@ #include -#include .text - - -#warning TODO: Fix overly simplistic IRQ - -/* void arch_int_enable_interrupts(void) */ -FUNCTION(arch_int_enable_interrupts): - li t0, ARCH_SR_SIE - csrrs zero, sstatus, t0 - ret -FUNCTION_END(arch_int_enable_interrupts) - - -/* int arch_int_disable_interrupts(void) - */ -FUNCTION(arch_int_disable_interrupts): - li t0, ARCH_SR_SIE - csrrc zero, sstatus, ARCH_SR_SIE - ret -FUNCTION_END(arch_int_disable_interrupts) - - -/* void arch_int_restore_interrupts(int oldState) - */ -FUNCTION(arch_int_restore_interrupts): - // TODO - ret -FUNCTION_END(arch_int_restore_interrupts) - - -/* bool arch_int_are_interrupts_enabled(void) */ -FUNCTION(arch_int_are_interrupts_enabled): - // TODO - ret -FUNCTION_END(arch_int_are_interrupts_enabled) - - -/* status_t arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *faultHandler) */ -FUNCTION(_arch_cpu_user_memcpy): - // TODO - ret -FUNCTION_END(_arch_cpu_user_memcpy) - - -/* status_t arch_cpu_user_memset(void *to, char c, size_t count, addr_t *faultHandler) */ -FUNCTION(_arch_cpu_user_memset): - // TODO - ret -FUNCTION_END(_arch_cpu_user_memset) - - -/* ssize_t arch_cpu_user_strlcpy(void *to, const void *from, size_t size, addr_t *faultHandler) */ -FUNCTION(_arch_cpu_user_strlcpy): - // TODO - ret -FUNCTION_END(_arch_cpu_user_strlcpy)