From a3c174ee4c08d1d5e7a89ce187f52e3c0807a7eb Mon Sep 17 00:00:00 2001 From: stefan Date: Sun, 23 Apr 2023 17:00:14 -0400 Subject: memory detection --- sys/include/asm.h | 6 ++++++ sys/include/dev.h | 32 +++++++++++++++++++++++++++++++- sys/include/kalloc.h | 2 +- sys/include/sbi.h | 8 ++++++++ sys/include/vm.h | 6 ++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 sys/include/vm.h (limited to 'sys/include') diff --git a/sys/include/asm.h b/sys/include/asm.h index 0995f88..d345712 100644 --- a/sys/include/asm.h +++ b/sys/include/asm.h @@ -53,4 +53,10 @@ read_tp(void) return x; } +static inline void +csrw_satp(uint64_t x) +{ + asm volatile("csrw satp, %0" : : "r"(x)); +} + #endif /* _ASM_H */ diff --git a/sys/include/dev.h b/sys/include/dev.h index b8bfef8..657c04c 100644 --- a/sys/include/dev.h +++ b/sys/include/dev.h @@ -2,7 +2,37 @@ #define _DEV_H #include +#include -void dev_init(struct fdt_header* fdt); +enum { DT_MMUTYPE_SV32, DT_MMUTYPE_SV39, DT_MMUTYPE_SV48 }; + +struct _reg { + fdt64_t address; + fdt64_t size; +}; +/* unflattend device tree */ +struct devicetree { + const char *compat; + const char *model; + int nproc; + /* main cpu, monitor/alternative cores will be ignored for now */ + struct { + short mmu_type; + const char *isa; + unsigned int freq; + } cpu; + struct { + uintptr_t origin; + uintptr_t size; + } memory; + struct { + unsigned int freq; + const char *compat; + int interrupt; + struct _reg reg; + } uart; +}; + +struct devicetree dev_init(struct fdt_header* fdt); #endif /* _DEV_H */ diff --git a/sys/include/kalloc.h b/sys/include/kalloc.h index 10adbda..5553d94 100644 --- a/sys/include/kalloc.h +++ b/sys/include/kalloc.h @@ -7,7 +7,7 @@ void *kzalloc(void); void kfree(void *); -void kalloc_init(void); +void kalloc_init(size_t); void walkfree(void); diff --git a/sys/include/sbi.h b/sys/include/sbi.h index 94c3749..86ca295 100644 --- a/sys/include/sbi.h +++ b/sys/include/sbi.h @@ -1,6 +1,8 @@ #ifndef _SBI_H #define _SBI_H +#include + struct sbiret { long err; long val; @@ -58,6 +60,12 @@ sbi_console_putchar(int c) sbi_ecall(1, 0, c, 0, 0, 0, 0, 0); } +static inline void +sbi_debug_console_write_byte(uint8_t byte) +{ + sbi_ecall(0x4442434E, 0x2, 'c', 0, 0, 0, 0, 0); +} + static inline void sbi_shutdown(void) { diff --git a/sys/include/vm.h b/sys/include/vm.h new file mode 100644 index 0000000..1883ea7 --- /dev/null +++ b/sys/include/vm.h @@ -0,0 +1,6 @@ +#ifndef _VM_H +#define _VM_H + +void vminit(void); + +#endif /* _VM_H */ -- cgit v1.2.3