From 4f4d9fdc89c27aa3346467a24b621954f4564d3b Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 29 Dec 2021 23:23:36 +0200 Subject: Refactoring + Mainly just moving stuff out or arch/riscv/ that should be handled in common/ + Prepared separate process stack/call stack for server callbacks, rest to be implemeted soon ish --- include/apos/arch.h | 6 ++++++ include/apos/conf.h | 9 +++++++++ include/apos/debug.h | 14 ++++++++------ include/apos/elf.h | 2 +- include/apos/irq.h | 2 ++ include/apos/mem.h | 2 +- include/apos/pmem.h | 15 +++++++++++---- include/apos/proc.h | 4 ++-- include/apos/tcb.h | 2 +- include/apos/vmem.h | 23 ++++++++++++++++------- include/libfdt.h | 7 ++++--- 11 files changed, 61 insertions(+), 25 deletions(-) create mode 100644 include/apos/arch.h create mode 100644 include/apos/conf.h (limited to 'include') diff --git a/include/apos/arch.h b/include/apos/arch.h new file mode 100644 index 0000000..b846876 --- /dev/null +++ b/include/apos/arch.h @@ -0,0 +1,6 @@ +#ifndef APOS_ARCH_H +#define APOS_ARCH_H + +void arch_setup(void *fdt); + +#endif /* APOS_ARCH_H */ diff --git a/include/apos/conf.h b/include/apos/conf.h new file mode 100644 index 0000000..844ce37 --- /dev/null +++ b/include/apos/conf.h @@ -0,0 +1,9 @@ +#ifndef APOS_CONF_H +#define APOS_CONF_H + +#include + +extern size_t __proc_stack_size; +extern size_t __call_stack_size; + +#endif /* APOS_CONF_H */ diff --git a/include/apos/debug.h b/include/apos/debug.h index 5830c45..1a3265f 100644 --- a/include/apos/debug.h +++ b/include/apos/debug.h @@ -2,26 +2,28 @@ #define APOS_DEBUG_H #include +#include #ifdef DEBUG -enum serial_dev_t { +enum serial_dev { /* only the NS16550A and compatible at the moment */ NS16550A, }; -struct dbg_info_t { - void *dbg_ptr; - enum serial_dev_t dev; +struct dbg_info { + pm_t dbg_ptr; + enum serial_dev dev; }; void __fmt(1, 2) dbg(const char *fmt, ...); -void dbg_init(void *pt, enum serial_dev_t dev); -struct dbg_info_t dbg_from_fdt(void *fdt); +void setup_dbg(pm_t pt, enum serial_dev dev); +struct dbg_info dbg_from_fdt(void *fdt); #else #define dbg(...) #define dbg_init(...) +#define dbg_from_fdt(...) #endif /* DEBUG */ diff --git a/include/apos/elf.h b/include/apos/elf.h index df07b7f..4fe74d1 100644 --- a/include/apos/elf.h +++ b/include/apos/elf.h @@ -184,6 +184,6 @@ __packed struct section64_header { #define program_header_prop(c, e, p) (c == ELFCLASS64 ? program64_header(e)->p : program32_header(e)->p) #define section_header_prop(c, e, p) (c == ELFCLASS64 ? section64_header(e)->p : section32_header(e)->p) -vm_t prepare_proc(struct tcb *t, vm_t p); +vm_t load_elf(struct tcb *t, vm_t b); #endif /* APOS_ELF_H */ diff --git a/include/apos/irq.h b/include/apos/irq.h index 958b25f..3ce6556 100644 --- a/include/apos/irq.h +++ b/include/apos/irq.h @@ -1,6 +1,8 @@ #ifndef APOS_IRQ_H #define APOS_IRQ_H +void init_irq(void *fdt); +void handle_irq(); void enable_irq(); void disable_irq(); diff --git a/include/apos/mem.h b/include/apos/mem.h index 0b3bffd..e935fe4 100644 --- a/include/apos/mem.h +++ b/include/apos/mem.h @@ -37,7 +37,7 @@ extern size_t __mm_page_shift; extern size_t __mm_max_order; void init_mem(size_t max_order, size_t shifts[10], size_t page_shift); -enum mm_mode_t get_mmode(void *fdt); +enum mm_mode get_mmode(void *fdt); #define BASE_PAGE_SIZE (__o_size(BASE_PAGE)) #define BASE_PAGE (MM_O0) diff --git a/include/apos/pmem.h b/include/apos/pmem.h index 01d89ce..2850f22 100644 --- a/include/apos/pmem.h +++ b/include/apos/pmem.h @@ -4,7 +4,8 @@ #include #include -enum mm_order_t { +#define ORDERS_NUM 10 +enum mm_order { MM_O0, MM_O1, MM_O2, @@ -20,12 +21,18 @@ enum mm_order_t { typedef size_t pm_t; typedef ssize_t pnum_t; +/* arch */ +int arch_pmem_conf(void *fdt, size_t *max_order, size_t *base_bits, size_t bits[ORDERS_NUM]); + +/* common */ void update_pmap(pm_t offset); -void free_page(enum mm_order_t order, pm_t paddr); -void mark_used(enum mm_order_t order, pm_t paddr); -pm_t alloc_page(enum mm_order_t order, pm_t offset); +void free_page(enum mm_order order, pm_t paddr); +void mark_used(enum mm_order order, pm_t paddr); +pm_t alloc_page(enum mm_order order, pm_t offset); pm_t populate_pmap(pm_t ram_base, size_t ram_size, pm_t cont); pm_t probe_pmap(pm_t ram_base, size_t ram_size); +void init_pmem(void *fdt); + #endif /* APOS_PMEM_H */ diff --git a/include/apos/proc.h b/include/apos/proc.h index 6f272b1..f835394 100644 --- a/include/apos/proc.h +++ b/include/apos/proc.h @@ -4,7 +4,7 @@ #include #include -void jump_to_userspace(struct tcb *t, vm_t bin, int argc, char **argv); -vm_t setup_call_stack(struct tcb *t, vm_t start, size_t bytes); +void jump_to_userspace(struct tcb *t, int argc, char **argv); +void init_proc(void *fdt, struct vm_branch *b); #endif /* APOS_PROC_H */ diff --git a/include/apos/tcb.h b/include/apos/tcb.h index 1d85e8b..0a07d7b 100644 --- a/include/apos/tcb.h +++ b/include/apos/tcb.h @@ -31,7 +31,7 @@ struct tcb { vm_t entry; - struct vm_branch_t *b_r; + struct vm_branch *b_r; }; void threads_insert(struct tcb *t); diff --git a/include/apos/vmem.h b/include/apos/vmem.h index 93d2ed7..87a3aa6 100644 --- a/include/apos/vmem.h +++ b/include/apos/vmem.h @@ -39,13 +39,22 @@ struct sp_mem { */ /* defined by arch */ -void map_vmem(struct vm_branch_t *branch, - pm_t paddr, vm_t vaddr, uint8_t flags, enum mm_order_t order); +void map_vmem(struct vm_branch *branch, + pm_t paddr, vm_t vaddr, uint8_t flags, enum mm_order order); -void unmap_vmem(struct vm_branch_t *branch, vm_t vaddr); -int mod_vmem(struct vm_branch_t *branch, vm_t vaddr, pm_t paddr, uint8_t flags); -int stat_vmem(struct vm_branch_t *branch, vm_t vaddr, pm_t *paddr, - enum mm_order_t *order, uint8_t *flags); +void unmap_vmem(struct vm_branch *branch, vm_t vaddr); +int mod_vmem(struct vm_branch *branch, vm_t vaddr, pm_t paddr, uint8_t flags); +int stat_vmem(struct vm_branch *branch, vm_t vaddr, pm_t *paddr, + enum mm_order *order, uint8_t *flags); + +int setup_kernel_io(struct vm_branch *b, vm_t paddr); +void populate_root_branch(struct vm_branch *b); +struct vm_branch *init_vmem(void *fdt); + +void flush_tlb(); +void flush_tlb_all(); + +/* defined in common */ int sp_mem_init(struct sp_reg_root *r, vm_t start, size_t nums); @@ -57,7 +66,7 @@ vm_t alloc_uvmem(struct tcb *r, size_t size, uint8_t flags); vm_t alloc_fixed_uvmem(struct tcb *r, vm_t start, size_t size, uint8_t flags); void free_uvmem(struct tcb *r, vm_t a); -vm_t map_fill_region(struct vm_branch_t *b, vm_t start, size_t bytes, uint8_t flags); +vm_t map_fill_region(struct vm_branch *b, vm_t start, size_t bytes, uint8_t flags); size_t uvmem_size(); void set_uvmem_size(size_t s); diff --git a/include/libfdt.h b/include/libfdt.h index aa95bd3..304abb7 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -1,15 +1,16 @@ #ifndef APOS_LIBFDT_H #define APOS_LIBFDT_H #include "../dtc/libfdt/libfdt.h" +#include /* apos additions, implementation can be found in common/fdt.c */ -struct cell_info_t { +struct cell_info { uint32_t size_cells; uint32_t addr_cells; }; -struct cell_info_t get_cellinfo(void *fdt, int offset); -struct cell_info_t get_reginfo(void *fdt, const char *path); +struct cell_info get_cellinfo(void *fdt, int offset); +struct cell_info get_reginfo(void *fdt, const char *path); #if defined(DEBUG) void __dbg_fdt(void *fdt, int node_offset, int depth); -- cgit v1.3