aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 14:34:39 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 14:34:39 +0300
commitd592abd8ccc4026c51e196777031eb65c4acc4de (patch)
treebfcffec608ede13653a21a56a5b731a4178ecda3 /src
parentd1c5e2700add7627e22c49a6021f200f03e8a62b (diff)
downloadkmi-d592abd8ccc4026c51e196777031eb65c4acc4de.tar.gz
kmi-d592abd8ccc4026c51e196777031eb65c4acc4de.zip
misc fixes
+ Align kernel to 2MiB boundary in u-boot + Optimize alignment functions a little bit, should still have to check on real hardware but 'feels' more clean + Add early boot debugging + Put extra cores we aren't ready to account for to sleep if/when they boot. + Make BASE_PAGE_SIZE constant on riscv64/32, helps the compiler with some alignment checks among other things.
Diffstat (limited to 'src')
-rw-r--r--src/debug.c11
-rw-r--r--src/elf.c2
-rw-r--r--src/main.c11
-rw-r--r--src/proc.c5
-rw-r--r--src/regions.c2
5 files changed, 21 insertions, 10 deletions
diff --git a/src/debug.c b/src/debug.c
index 15640b4..9573bbc 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -364,6 +364,12 @@ static size_t __integral_val(ssize_t value, size_t base, size_t flags,
return ret + 1;
}
+/**
+ * Print out a string.
+ *
+ * @param s String to print out.
+ * @return Bytes printed.
+ */
static size_t __puts(const char *s)
{
size_t i = 0;
@@ -747,10 +753,7 @@ void dbg(const char *fmt, ...)
if (is_set(flags, PRECS_FLAG))
i = precision;
- for (; *s && i--;) {
- __putchar(*s++);
- chars_written++;
- }
+ chars_written += __puts(s);
fmt++;
break;
diff --git a/src/elf.c b/src/elf.c
index 5c2f9bd..29c9c09 100644
--- a/src/elf.c
+++ b/src/elf.c
@@ -69,7 +69,7 @@ static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart,
if (!start)
return; /* out of memory or something */
- info("mapped ELF section to %x\n", start);
+ info("mapped ELF section to %lx\n", (long)start);
uint8_t elf_flags = program_header_prop(ei_c, runner, p_flags);
uint8_t uvflags = __elf_to_uvflags(elf_flags);
diff --git a/src/main.c b/src/main.c
index b51c519..f3c5e17 100644
--- a/src/main.c
+++ b/src/main.c
@@ -61,8 +61,6 @@ __noreturn void kernel(void *fdt, uintptr_t load_addr, struct vmem *d)
/* we should be in kernelspace, so use the virtual address of our FDT. */
fdt = __va(fdt);
- /* dbg uses direct mapping at this point */
- init_dbg(fdt);
/* start up debugging in kernel IO */
setup_io_dbg(d);
@@ -105,6 +103,10 @@ __noreturn void main(unsigned long hart, void *fdt, uintptr_t load_addr)
* have to get the function signature right */
(void)hart;
+ /* dbg uses direct mapping at this point, useful for early init asserts
+ * and so on */
+ init_dbg(fdt);
+
/** @todo some kind of lottery? */
pm_t ram_base = __fdt_ram_base(fdt);
pm_t ram_size = __fdt_ram_size(fdt);
@@ -114,6 +116,11 @@ __noreturn void main(unsigned long hart, void *fdt, uintptr_t load_addr)
init_mem(fdt);
+ /* we don't have any debug output just yet but still */
+ /* also this is I guess more of an architecture limitation, should the
+ * whole of main() just be moved to arch? */
+ assert(is_aligned(load_addr, order_size(MM_O1)));
+
struct vmem *d = init_mapping();
to_kernelspace(fdt, load_addr, d, ram_base);
unreachable();
diff --git a/src/proc.c b/src/proc.c
index 3d2d5bd..eaa25d8 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -18,8 +18,6 @@
#include <libfdt.h>
-static vm_t entry;
-
stat_t prepare_proc(struct tcb *t, vm_t bin, vm_t interp)
{
vm_t entry = load_elf(t, bin, interp);
@@ -60,7 +58,8 @@ stat_t init_proc(void *fdt, vm_t *proc_fdt, vm_t *proc_initrd)
/* allocate stacks etc after ELF file to make sure nothing of importance
* clashes */
- prepare_proc(t, get_init_base(fdt), 0);
+ stat_t ret = prepare_proc(t, get_init_base(fdt), 0);
+ assert(ret == OK);
/** In the init process, can the entry be the callback? Is that too
* unergonomic? */
diff --git a/src/regions.c b/src/regions.c
index 60cab23..b57b548 100644
--- a/src/regions.c
+++ b/src/regions.c
@@ -448,6 +448,8 @@ vm_t alloc_fixed_region(struct mem_region_root *r, vm_t start, size_t size,
m = m->next;
else
m = m->prev;
+
+ assert(m);
}
/* if region is already in use, forget it */