diff options
Diffstat (limited to 'arch/riscv')
29 files changed, 0 insertions, 773 deletions
diff --git a/arch/riscv/conf/apos.its b/arch/riscv/conf/apos.its deleted file mode 100644 index da48860..0000000 --- a/arch/riscv/conf/apos.its +++ /dev/null @@ -1,48 +0,0 @@ -/dts-v1/; - -/ { - description = "FUCK"; -#address-cells = <1>; - - images { - kernel { - description = "Garbaggio"; - data = /incbin/("../../../apos.bin"); - type = "kernel"; - arch = "riscv"; - os = "apos"; - compression = "none"; - load = <0x80080000>; - entry = <0x80080000>; - hash-1 { - algo = "sha1"; - }; - }; - - initrd { - description = "Gargabbio initrd"; - data = /incbin/("initrd"); - type = "ramdisk"; - arch = "riscv"; - os = "apos"; - compression = "none"; - load = <0x88300000>; - hash-1 { - algo = "sha1"; - }; - }; - }; - - configurations { - default = "config"; - - config { - description = "Default configuration"; - kernel = "kernel"; - ramdisk = "initrd"; - hash-1 { - algo = "sha1"; - }; - }; - }; -}; diff --git a/arch/riscv/conf/boot.cmd b/arch/riscv/conf/boot.cmd deleted file mode 100644 index a7517fd..0000000 --- a/arch/riscv/conf/boot.cmd +++ /dev/null @@ -1,4 +0,0 @@ -fdt move ${fdt_addr} ${fdt_addr_r} -fdt addr ${fdt_addr_r} -load ${devtype} ${devnum} ${kernel_addr_r} apos.itb -bootm ${kernel_addr_r} ${kernel_addr_r} ${fdt_addr_r} diff --git a/arch/riscv/conf/init b/arch/riscv/conf/init Binary files differdeleted file mode 100755 index f05254f..0000000 --- a/arch/riscv/conf/init +++ /dev/null diff --git a/arch/riscv/conf/init-link.S b/arch/riscv/conf/init-link.S deleted file mode 100644 index ce53e5e..0000000 --- a/arch/riscv/conf/init-link.S +++ /dev/null @@ -1,31 +0,0 @@ -OUTPUT_ARCH(riscv) -ENTRY(_start) - -SECTIONS { - . = ABSOLUTE(PM_KERN_BASE); - __init_start = .; - - /* objcopy only copies these three sections (as far as I'm aware) into the - produces binary, so __init_end should point to the correct location in the - final binary - */ - .text ALIGN(4K) : AT(0) { - *(.init.start) - *(.text*); - } - - .rodata : { - *(.rodata*) - } - - .data : { - *(.data*) - } - - .bss : { - *(.bss*) *(COMMON) - } - - __init_end = . ; - __kernel_size = <KERNEL_SIZE>; -} diff --git a/arch/riscv/conf/initrd b/arch/riscv/conf/initrd Binary files differdeleted file mode 100644 index 90344c1..0000000 --- a/arch/riscv/conf/initrd +++ /dev/null diff --git a/arch/riscv/conf/kernel-link.S b/arch/riscv/conf/kernel-link.S deleted file mode 100644 index d3b1223..0000000 --- a/arch/riscv/conf/kernel-link.S +++ /dev/null @@ -1,26 +0,0 @@ -OUTPUT_ARCH(riscv) -ENTRY(main) - -SECTIONS { - . = ABSOLUTE(VM_KERN); - __kernel_start = .; - - .text ALIGN(4K) : AT(0) { - *(.kernel.start); - *(.text*); - } - - .rodata : { - *(.rodata*) - } - - .data : { - *(.data*) - } - - .bss : { - *(.bss*) *(COMMON) - } - - __kernel_end = .; -} diff --git a/arch/riscv/conf/mkimage.sh b/arch/riscv/conf/mkimage.sh deleted file mode 100755 index 5a22d01..0000000 --- a/arch/riscv/conf/mkimage.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -if [ ! -e fs ]; then - mkdir fs -fi - -if [ ! -e rootfs.img ]; then - virt-make-fs --partition=mbr --type=vfat --size=10M fs rootfs.img -fi - - -SSIZE=$(fdisk -l rootfs.img | awk '$1=="Units:" {print $8}') -OFFSET=$(fdisk -l rootfs.img | awk '$1=="rootfs.img1" {print $2}') -mount -o loop,offset=$((${SSIZE}*${OFFSET})) rootfs.img fs - -# not entirely pleased with this solution, although eventually I should probably -# move `run` out of the kernel repo and into some `aposos` repo with a runtime -# and proper initrd etc. so this is good enough for now -../u-boot-apos/tools/mkimage -f arch/riscv/conf/apos.its fs/apos.itb -../u-boot-apos/tools/mkimage -A riscv -O apos -T script \ - -d arch/riscv/conf/boot.cmd fs/boot.scr - -umount -l fs - -qemu-system-riscv64 -machine virt \ - -kernel ../u-boot-apos/u-boot \ - -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \ - -device virtio-blk-device,drive=hd0 \ - -drive file=rootfs.img,format=raw,id=hd0 \ - -S -s -m 2G \ - -serial stdio diff --git a/arch/riscv/conf/rmimage.sh b/arch/riscv/conf/rmimage.sh deleted file mode 100755 index 8d6457f..0000000 --- a/arch/riscv/conf/rmimage.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -if [ -e fs ]; then - rm -r fs -fi - -if [ -e rootfs.img ]; then - rm rootfs.img -fi diff --git a/arch/riscv/conf/rootfs.fd b/arch/riscv/conf/rootfs.fd deleted file mode 100644 index 59fb5f8..0000000 --- a/arch/riscv/conf/rootfs.fd +++ /dev/null @@ -1,9 +0,0 @@ -label: gpt -label-id: DBD1F99F-BFA3-D448-828F-0B505DF81F17 -device: rootfs.img -unit: sectors -first-lba: 2048 -last-lba: 20446 -sector-size: 512 - -rootfs.img1 : start= 2048, size= 18399, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=B129DB0D-F225-5C48-AA6D-DD8C049FA72C diff --git a/arch/riscv/conf/s.S b/arch/riscv/conf/s.S deleted file mode 100644 index 80a3a11..0000000 --- a/arch/riscv/conf/s.S +++ /dev/null @@ -1,4 +0,0 @@ -.text -.global _start -_start: -ecall diff --git a/arch/riscv/config.h b/arch/riscv/config.h deleted file mode 100644 index 0ef22fa..0000000 --- a/arch/riscv/config.h +++ /dev/null @@ -1,34 +0,0 @@ -#include <apos/sizes.h> - -/* --- START ARCH USER CONFIG VALUES --- */ -/* physical address to which the kernel will be loaded */ -#define RAM_BASE 0x80000000 -#define PM_KERN_BASE (RAM_BASE + SZ_512K) -#define PM_KERN_SIZE (SZ_256K) -#define PM_KERN_TOP (PM_KERN_BASE + PM_KERN_SIZE) -/* --- END ARCH USER CONFIG VALUES --- */ - -/* don't touch >:( */ - -#define PM_STACK_BASE (PM_KERN_BASE + SZ_256K) -#define PM_STACK_SIZE (SZ_256K) -#define PM_STACK_TOP (PM_STACK_BASE + PM_STACK_SIZE) - -#define VM_DMAP (0xffffffc000000000) /* testing for now */ -#define VM_KERN (VM_DMAP + SZ_256K) -#define TMP_PTE (-SZ_2G) -#define ROOT_PTE (0) -#define ROOT_REGION (SZ_4K) - -#define IO_PAGE 511 -#define KSTART_PAGE 256 -#define CSTACK_PAGE 255 - -/* assume Sv39, probably wouldn't be too difficult to use runtime parameters - * instead. First 4K is reserved for NULL, but I suppose it could be mapped - * later if *absolutely* necessary. */ -#define UVMEM_START (SZ_4K) -#define UVMEM_END (SZ_256G - SZ_1G) - -#define PROC_STACK_TOP (SZ_256G) -#define PROC_STACK_BASE (SZ_256G - SZ_1G) diff --git a/arch/riscv/include/csr.h b/arch/riscv/include/csr.h deleted file mode 100644 index b309f0b..0000000 --- a/arch/riscv/include/csr.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef APOS_CSR_H -#define APOS_CSR_H - -#include <apos/utils.h> - -#define SATP_MODE_Sv32 0x80000000 -#define SATP_MODE_Sv39 0x8000000000000000 -#define SATP_MODE_Sv48 0x9000000000000000 - - -/* supervisor CSR registers */ -#define CSR_SSTATUS 0x100 -#define CSR_SIE 0x104 -#define CSR_STVEC 0x105 -#define CSR_SCOUNTEREN 0x106 - -#define CSR_SENVCFG 0x10A - -#define CSR_SSCRATCH 0x140 -#define CSR_SEPC 0x141 -#define CSR_SCAUSE 0x142 -#define CSR_STVAL 0x143 -#define CSR_SIP 0x144 - -#define CSR_SATP 0x180 - -#define CSR_SCONTEXT 0x5A8 - -/* Exception causes */ -#define EXC_INST_MISALIGNED 0 -#define EXC_INST_ACCESS 1 -#define EXC_BREAKPOINT 3 -#define EXC_LOAD_ACCESS 5 -#define EXC_STORE_ACCESS 7 -#define EXC_SYSCALL 8 -#define EXC_INST_PAGE_FAULT 12 -#define EXC_LOAD_PAGE_FAULT 13 -#define EXC_STORE_PAGE_FAULT 15 - -/* status CSR bits */ -#define SSTATUS_SUM (1 << 18) -#define SSTATUS_SPP (1 << 8) - -/* directly lifted from Linux:/arch/riscv/include/asm/asm.h:9-13 */ -#ifdef __ASSEMBLY__ -#define __ASM_STR(x) x -#else -#define __ASM_STR(x) #x -#endif - -#define csr_read(csr, res)\ - __asm__ ("csrr %0, " __ASM_STR(csr) : "=r" (res) : : "memory") - -#define csr_write(csr, val)\ - __asm__ ("csrw " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory") - -#define csr_set(csr, val)\ - __asm__ ("csrs " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory") - -#define csr_clear(csr, val)\ - __asm__ ("csrc " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory") - -#endif /* APOS_CSR_H */ diff --git a/arch/riscv/include/lock.h b/arch/riscv/include/lock.h deleted file mode 100644 index 4f71344..0000000 --- a/arch/riscv/include/lock.h +++ /dev/null @@ -1 +0,0 @@ -#define optional_pause() diff --git a/arch/riscv/include/pages.h b/arch/riscv/include/pages.h deleted file mode 100644 index 362499a..0000000 --- a/arch/riscv/include/pages.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef APOS_RISCV_PAGES_H -#define APOS_RISCV_PAGES_H - -#include <apos/types.h> - -#define MM_KPAGE MM_O0 -#define MM_MPAGE MM_O1 -#define MM_GPAGE MM_O2 -#define MM_TPAGE MM_O3 - -#define MM_KPAGE_SIZE SZ_4K -#define MM_MPAGE_SIZE SZ_2M -#define MM_GPAGE_SIZE SZ_1G -#define MM_TPAGE_SIZE SZ_512G - -typedef uint64_t pm_t; - -#endif /* APOS_RISCV_PAGES_H */ diff --git a/arch/riscv/include/sbi.h b/arch/riscv/include/sbi.h deleted file mode 100644 index 609849d..0000000 --- a/arch/riscv/include/sbi.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef APOS_RISCV_SBI_H - -struct sbiret { - long error; - long value; -}; - -struct sbiret sbi_ecall(int ext, int fid, - unsigned long arg0, unsigned long arg1, unsigned long arg2, - unsigned long arg3, unsigned long arg4, unsigned long arg5); - -#endif /* APOS_RISCV_SBI_H */ diff --git a/arch/riscv/include/tcb.h b/arch/riscv/include/tcb.h deleted file mode 100644 index d1e0717..0000000 --- a/arch/riscv/include/tcb.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef ARCH_RISCV_TCB_H -#define ARCH_RISCV_TCB_H - -struct arch_tcbd { - /* empty for now, but should probably be filled with stuff like register - * saving of something */ -}; - -#endif /* ARCH_RISCV_TCB_H */ diff --git a/arch/riscv/include/vmem.h b/arch/riscv/include/vmem.h deleted file mode 100644 index 228b24b..0000000 --- a/arch/riscv/include/vmem.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef APOS_RISCV_VMAP_H -#define APOS_RISCV_VMAP_H - -#include <apos/types.h> -#include <apos/attrs.h> - -#define VM_V (1 << 0) -#define VM_R (1 << 1) -#define VM_W (1 << 2) -#define VM_X (1 << 3) -#define VM_U (1 << 4) -#define VM_G (1 << 5) -#define VM_A (1 << 6) -#define VM_D (1 << 7) - -enum mm_mode { - Sv48, - Sv39, - Sv32, -}; - -typedef size_t vm_t; -struct __packed vm_branch { - struct vm_branch *leaf[512]; -}; - -#endif /* APOS_RISCV_VMAP_H */ diff --git a/arch/riscv/init/init.c b/arch/riscv/init/init.c deleted file mode 100644 index 23dcadd..0000000 --- a/arch/riscv/init/init.c +++ /dev/null @@ -1,70 +0,0 @@ -#include <apos/types.h> -#include <apos/attrs.h> -#include <apos/utils.h> -#include <apos/vmem.h> -#include <vmem.h> -#include <csr.h> - -/* assume 64 bit for now */ -struct __packed init_vmem { - int *leaf[512]; -}; - -struct init_vmem *root_branch; - -#define to_pte(a, f) (((a) >> 12) << 10 | (f)) - -/* assume Sv39 for now */ -void init_bootmem() -{ - size_t flags = VM_V | VM_X | VM_R | VM_W; - - extern char *__init_start; - root_branch = (struct init_vmem *)align_down((size_t)&__init_start - SZ_4K, SZ_4K); - - /* direct mapping (temp) */ - for(size_t i = 0; i < CSTACK_PAGE; ++i) - root_branch->leaf[i] = (int*)to_pte(SZ_1G * i, flags); - - /* kernel (also sort of direct mapping) */ - flags |= VM_G; - for(size_t i = KSTART_PAGE; i < IO_PAGE; ++i) - root_branch->leaf[i] = (int *)to_pte(RAM_BASE + SZ_1G * (i - 256), flags); - - /* kernel IO, map to 0 for now, will be updated in the future */ - root_branch->leaf[IO_PAGE] = (int *)to_pte(0, flags); - - csr_write(CSR_SATP, SATP_MODE_Sv39 | ((size_t)root_branch >> 12)); -} - -void move_kernel() -{ - extern char *__init_end; - extern char *__kernel_size; - - size_t sz = (size_t)&__kernel_size; - char *src = (char *)&__init_end; - char *dst = (char *)VM_KERN; - for(size_t i = 0; i < sz; ++i) - dst[i] = src[i]; -} - -#define __va_reg(reg)\ -{\ - vm_t reg = 0;\ - __asm__("mv %0, " QUOTE(reg) : "=r" (reg) :: );\ - reg = (vm_t)__va(reg);\ - __asm__("mv " QUOTE(reg) ", %0" :: "rK" (reg) : );\ -} - -void init(void *fdt) -{ - extern char *__init_end; - void (*kernel_main)(void *fdt) = (void (*)(void *))(VM_KERN); - init_bootmem(); - move_kernel(); - __va_reg(sp); - __va_reg(fp); - __va_reg(gp); - kernel_main(__va(fdt)); -} diff --git a/arch/riscv/init/start.S b/arch/riscv/init/start.S deleted file mode 100644 index f9bfb92..0000000 --- a/arch/riscv/init/start.S +++ /dev/null @@ -1,5 +0,0 @@ -.section .init.start -.global _start -_start: -li sp, PM_STACK_TOP -jal init diff --git a/arch/riscv/ipc.txt b/arch/riscv/ipc.txt deleted file mode 100644 index 21d758e..0000000 --- a/arch/riscv/ipc.txt +++ /dev/null @@ -1,7 +0,0 @@ -Current idea: Have a bunch of servers that allow IPC requests. Each IPC request -to a server temporarily maps the server's address space etc. into the calling -functions address space, except for the callstack. Callstack should be a bunch -of 4K pages, so they can easily be mapped to be unreachable by deeper nested -server calls, whereas the normal stack can be mapped to higher order pages to -save a little bit of memory access latency when the client is operating -normally. diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c deleted file mode 100644 index 6ae4ee7..0000000 --- a/arch/riscv/kernel/cpu.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <apos/cpu.h> - -id_t cpu_id() -{ - return 0; /* VERY MUCH TEMP */ -} diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c deleted file mode 100644 index f844dd1..0000000 --- a/arch/riscv/kernel/irq.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <apos/irq.h> -#include <apos/attrs.h> -#include <apos/debug.h> -#include <csr.h> - -void init_irq(void *fdt) -{ - UNUSED(fdt); - csr_write(CSR_STVEC, &handle_irq); - - long s = 0; - csr_read(CSR_SIE, s); - info("CSR_SIE: %lx\n", s); -} - -__aligned(4) void handle_irq() -{ - while(1); -} - -/* very simple for now */ -void enable_irq() -{ - csr_set(CSR_SSTATUS, CSR_SIE); -} - -void disable_irq() -{ - csr_clear(CSR_SSTATUS, CSR_SIE); -} diff --git a/arch/riscv/kernel/main.c b/arch/riscv/kernel/main.c deleted file mode 100644 index 9ce256e..0000000 --- a/arch/riscv/kernel/main.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <apos/utils.h> -#include <csr.h> - -void arch_setup(void *fdt) -{ - UNUSED(fdt); - /* allow supervisor code to touch user pages */ - csr_set(CSR_SSTATUS, SSTATUS_SUM); - /* mark that we want to eventually jump to userspace */ - csr_clear(CSR_SSTATUS, SSTATUS_SPP); -} diff --git a/arch/riscv/kernel/pmem.c b/arch/riscv/kernel/pmem.c deleted file mode 100644 index 45b8eeb..0000000 --- a/arch/riscv/kernel/pmem.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <apos/pmem.h> - -int arch_pmem_conf(void *fdt, size_t *max_order, size_t *base_bits, size_t bits[ORDERS_NUM]) -{ - UNUSED(fdt); - - /* Sv39 for now */ - *max_order = 2; - *base_bits = 12; - /* we can assume bits[] is zeroed out beforehand */ - for(size_t i = 0; i <= *max_order; ++i) - bits[i] = 9; - - return 0; -} diff --git a/arch/riscv/kernel/proc.c b/arch/riscv/kernel/proc.c deleted file mode 100644 index 6120c2d..0000000 --- a/arch/riscv/kernel/proc.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <apos/tcb.h> -#include <apos/elf.h> -#include <csr.h> - -void jump_to_userspace(struct tcb *t, int argc, char **argv) -{ - csr_write(CSR_SEPC, t->entry); - __asm__("mv sp, %0\n" : "=r" (t->proc_stack) :: "memory"); - __asm__("sret\n" ::: "memory"); -} - -void return_to_userspace(struct tcb *t) -{ - /* lol */ -} diff --git a/arch/riscv/kernel/vmem.c b/arch/riscv/kernel/vmem.c deleted file mode 100644 index 1f1f44a..0000000 --- a/arch/riscv/kernel/vmem.c +++ /dev/null @@ -1,182 +0,0 @@ -#include <apos/string.h> -#include <apos/pmem.h> -#include <apos/vmem.h> -#include <apos/mem.h> -#include <apos/debug.h> -#include <apos/cpu.h> -#include <pages.h> -#include <vmem.h> -#include <csr.h> - -#define pte_ppn(pte) (((pm_t)(pte)) >> 10) -#define pte_flags(pte) (((pm_t)(pte)) & 0xff) -#define to_pte(p, f) ((pm_to_pnum(p) << 10) | (f)) -#define pte_addr(pte) __va(pnum_to_paddr(pte_ppn(pte))) -#define pte_paddr(pte) (pnum_to_paddr(pte_ppn(pte))) -#define vm_to_index(a, o) (pm_to_index(a, o)) -#define is_active(pte) (pte_flags(pte) & VM_V) -#define is_leaf(pte) (is_active(pte) && (pte_flags(pte) & ~VM_V)) -#define is_branch(pte) (is_active(pte) && !(pte_flags(pte) & ~VM_V)) - -static pm_t *__find_vmem(struct vm_branch *b, vm_t v, enum mm_order *o) -{ - enum mm_order top = __mm_max_order; - if(o) - *o = MM_O0; - do { - size_t idx = vm_to_index(v, top); - pm_t pte = (pm_t)b->leaf[idx]; - - if(!pte) - return 0; - - if(is_leaf(pte)){ - if(o) - *o = top; - - return (pm_t *)&b->leaf[idx]; - } - - b = (struct vm_branch *)pte_addr(pte); - } while (top--); - - return 0; -} - -int mod_vmem(struct vm_branch *branch, vm_t vaddr, pm_t paddr, uint8_t flags) -{ - pm_t *pte = __find_vmem(branch, vaddr, 0); - if(pte){ - *pte = to_pte((pm_t)__pa(paddr), flags); - return 0; - } - - return -1; -} - -/* huh, should probably add status flags etc. to all my API functions. Damn, I'm - * lazy. */ -int stat_vmem(struct vm_branch *branch, vm_t vaddr, pm_t *paddr, - enum mm_order *order, uint8_t *flags) -{ - pm_t *pte = __find_vmem(branch, vaddr, order); - if(pte){ - if(paddr) - *paddr = (pm_t)pte_addr(*pte); - - if(flags) - *flags = pte_flags(*pte); - - return 0; - } - - return -1; -} - -static struct vm_branch *__create_leaf() -{ - pm_t new_leaf = alloc_page(MM_KPAGE, 0); - memset((void *)new_leaf, 0, sizeof(struct vm_branch)); - return (struct vm_branch *)to_pte((pm_t)__pa(new_leaf), VM_V); -} - -static void __destroy_branch(struct vm_branch *b) -{ - if(!b) - return; - - for(size_t i = 0; i < BASE_PAGE_SIZE / sizeof(pm_t); ++i){ - if(is_branch(b->leaf[i])) - __destroy_branch((struct vm_branch *)pte_addr(b->leaf[i])); - - free_page(MM_KPAGE, (pm_t)pte_addr(b->leaf[i])); - } -} - -void map_vmem(struct vm_branch *branch, - pm_t paddr, vm_t vaddr, uint8_t flags, enum mm_order order) -{ - enum mm_order top = __mm_max_order; - while (top != order) { - size_t idx = vm_to_index(vaddr, top); - - if (!branch->leaf[idx]) - branch->leaf[idx] = __create_leaf(); - - - branch = (struct vm_branch *)pte_addr(branch->leaf[idx]); - top--; - } - - size_t idx = vm_to_index(vaddr, top); - if (is_branch(branch->leaf[idx])) /* something has gone terribly wrong */ - __destroy_branch(branch->leaf[idx]); - - branch->leaf[idx] = (struct vm_branch *)to_pte((pm_t)__pa(paddr), flags); -} - -void unmap_vmem(struct vm_branch *branch, vm_t vaddr) -{ - - pm_t *pte = __find_vmem(branch, vaddr, 0); - if(pte) - *pte = 0; -} - -void flush_tlb() -{ - __asm__("sfence.vma %0\n" :: "rk" (cpu_id()) : "memory"); -} - -void flush_tlb_all() -{ - __asm__("sfence.vma\n" ::: "memory"); -} - -static void start_vmem(struct vm_branch *branch, enum mm_mode m) -{ - branch = (struct vm_branch *)__pa(branch); - - if(m == Sv32) - csr_write(CSR_SATP, SATP_MODE_Sv32 | pm_to_pnum((pm_t)(branch))); - else if (m == Sv39) - csr_write(CSR_SATP, SATP_MODE_Sv39 | pm_to_pnum((pm_t)(branch))); - else - csr_write(CSR_SATP, SATP_MODE_Sv48 | pm_to_pnum((pm_t)(branch))); - - flush_tlb_all(); - /* Sv57 && Sv64 in the future? */ -} - -struct vm_branch *init_vmem(void *fdt) -{ - UNUSED(fdt); - struct vm_branch *b = (struct vm_branch *)alloc_page(MM_KPAGE, 0); - memset(b, 0, MM_KPAGE_SIZE); - - populate_root_branch(b); - /* update which memory branch to use */ - start_vmem(b, Sv39); - return b; -} - -void populate_root_branch(struct vm_branch *b) -{ - size_t flags = VM_V | VM_R | VM_W | VM_X | VM_G; - for(size_t i = KSTART_PAGE; i < IO_PAGE; ++i) - b->leaf[i] = (struct vm_branch *)to_pte(RAM_BASE + SZ_1G * (i - KSTART_PAGE), flags); - - /* map kernel IO to zero for now, this will be overridden later - * (if at all) */ - b->leaf[IO_PAGE] = (struct vm_branch *)to_pte(0, flags); -} - -#ifdef DEBUG -int setup_kernel_io(struct vm_branch *b, vm_t paddr) -{ - /* assume Sv39 for now */ - pm_t gigapage = paddr / MM_GPAGE_SIZE; - b->leaf[IO_PAGE] = (struct vm_branch *)to_pte(gigapage, VM_V | VM_R | VM_W); - return -SZ_1G + paddr - (gigapage * MM_GPAGE_SIZE); -} -#endif diff --git a/arch/riscv/mm.txt b/arch/riscv/mm.txt deleted file mode 100644 index e5c52cb..0000000 --- a/arch/riscv/mm.txt +++ /dev/null @@ -1,93 +0,0 @@ -Ideas for actually working virtual mappings: - -1. Define sensible memory areas, to start with for Sv39 and then that can -probably be extended to Sv48 etc. - -Something like this for Sv39: - -Offset | Size | Purpose ------------------------------------------------- --242 GiB | 256 GiB | Userspace ------------------------------------------------- --246 GiB | 4 GiB | Direct mapping --254 GiB | 8 GiB | vmemmap --255 GiB | 1 GiB | Kernel IO --256 GiB | 1 GiB | Kernel - -(alternate scheme: Kernel vmem is itself a direct mapping?) -(first 256KiB page reserved for whatever, next 256KiB reserved for kernel vma, - next 512KiB reserved for kernel pma?) - -Sv39, final answer: - -First 255 pages are userspace (uvmem), page 255 is reserved for callstack. -Following 255 pages are reserved for kernel 'direct mapping', and the 512th page -is reserved for kernel IO. - -Sv48: - -Offset | Size | Purpose ------------------------------------------------- --58368 GiB | 65536 GiB | Userspace ------------------------------------------------- --60416 GiB | 2048 GiB | Direct mapping --64512 GiB | 4096 GiB | vmemmap --65024 GiB | 512 GiB | Kernel IO --65536 GiB | 512 GiB | Kernel - -Note that tera/giga/etc pages have to be aligned to their corresponding size. -This means that these areas will probably have to be mapped with 2M pages, which -is fine but would've been cool to use top-level PTE's to keep context switch -latencies down. - -(Note: Direct mapping can be something like - inline static __va(pm_t pa) - { - if (__dma_bottom >= pa || __dma_top <= pa) - remap_dma(pa); - return pa + __dma_bottom; - } - ...) - -PTE's can be kept in vmemmap, and the Direct mapping can overlap. - -2. Come up with a somewhat sensible virtual memory management system. Linux uses -rb_trees, which might be a good idea, although I should figure out how to handle -both acuiring and freeing them quickly. - -Maybe keep two separate trees, one for free and one for mapped regions? Free -regions should be ordered by size, to quickly find the best suitable size. -Used/mapped regions should be ordered by address, to quickly find the correct -region. - -struct rb_free_node { - union { - size_t size; - vm_t address; - }; - - struct rb_free_node *pair; - struct rb_free_node *left; - struct rb_free_node *right; -}; - -struct rb_used_node { - vm_t address; - size_t size; - - struct rb_used_node *left; - struct rb_used_node *right; -}; - -My idea: Have two trees made of rb_free_node, one ordered by size and one -ordered by address, with the *pair pointer pointing to the corresponding node in -the other tree. - -When allocating, search up the most suitable free area in the tree ordered by -size, and do the required node modifications. -(remove node completely, split area one or twice, mirror in other tree) - -When freeing, search up the address in the used area, after which insert it into -the free trees and remove it from the used tree. After that, merge adjacent -memory areas in the free trees? Could be done reasonably efficiently, should -start up a test implementation, like with pmem. diff --git a/arch/riscv/proc.txt b/arch/riscv/proc.txt deleted file mode 100644 index 29b2e92..0000000 --- a/arch/riscv/proc.txt +++ /dev/null @@ -1,3 +0,0 @@ -Each thread should obviously have a thread control block (tcb) which lives in -kernelspace and has pointers to virtual memory allocations, along with PID and -other required data. That's about what I can come up with at the moment. diff --git a/arch/riscv/source.mk b/arch/riscv/source.mk deleted file mode 100644 index e50880c..0000000 --- a/arch/riscv/source.mk +++ /dev/null @@ -1,10 +0,0 @@ -KERNEL_LOCAL != echo arch/riscv/kernel/*.[cS] -KERNEL_SOURCES += $(KERNEL_LOCAL) -INIT_SOURCES += arch/riscv/init/*.[cS] - -CLEANUP_CMD := ./arch/riscv/conf/rmimage.sh - -ARCH_FLAGS := -mcmodel=medany - -run: - ./arch/riscv/conf/mkimage.sh |
