aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 07:00:43 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-07 07:00:43 +0300
commit122374c362ba8bb9082385da3c82e264ab594f15 (patch)
tree0123fad5464aaf64f522d48f5069b35b90207aae /src
parent03e12129927b0deba537a11bb5575bef93c57d0f (diff)
downloadkmi-122374c362ba8bb9082385da3c82e264ab594f15.tar.gz
kmi-122374c362ba8bb9082385da3c82e264ab594f15.zip
smp now seems to work
+ Had some minor issues with a wraparound of size_t that effectively meant that some regions were allocated twice. Also, booting should be a bit more reliable now, turned out that the previous iteration of the booting was just accidentally working due to the kernel being placed 'close enough' in RAM to where it was linked to. Fixed by allocating a vmem of O1 that maps the kernel to a 2MiB boundary at boot, pretty nifty.
Diffstat (limited to 'src')
-rw-r--r--src/main.c5
-rw-r--r--src/pmem.c4
-rw-r--r--src/proc.c9
-rw-r--r--src/regions.c5
-rw-r--r--src/tcb.c6
5 files changed, 19 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index aaf4cde..b51c519 100644
--- a/src/main.c
+++ b/src/main.c
@@ -114,9 +114,8 @@ __noreturn void main(unsigned long hart, void *fdt, uintptr_t load_addr)
init_mem(fdt);
- struct vmem *d = direct_mapping();
-
- to_kernelspace(fdt, load_addr, d, ram_base, VM_DMAP);
+ struct vmem *d = init_mapping();
+ to_kernelspace(fdt, load_addr, d, ram_base);
unreachable();
}
diff --git a/src/pmem.c b/src/pmem.c
index fac7731..5516d30 100644
--- a/src/pmem.c
+++ b/src/pmem.c
@@ -397,8 +397,10 @@ static pm_t __maybe_populate_bucket(size_t n, pm_t cont, enum mm_order order,
if (n) {
struct mm_bmap *bmap = (struct mm_bmap *)cont;
- if (populate)
+ if (populate) {
+ memset(bmap, 0, set_size);
bmap->size = n;
+ }
if (first && populate)
__attach_set(bucket, bmap);
diff --git a/src/proc.c b/src/proc.c
index eff962a..93e3aa5 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -59,17 +59,22 @@ 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);
+
+ /** In the init process, can the entry be the callback? Is that too
+ * unergonomic? */
+ t->callback = t->exec;
+
/** \todo start one thread per core, with special handling for init in
* that each thread starts at the entry point of init? */
*proc_fdt = map_fixed_uvmem(t,
(pm_t)fdt, fdt_totalsize(fdt),
- VM_V | VM_R | VM_U);
+ MR_SHARED | VM_V | VM_R | VM_U);
pm_t initrd = (pm_t)__va(get_initrdbase(fdt));
*proc_initrd = map_fixed_uvmem(t,
initrd, get_initrdsize(fdt),
- VM_V | VM_R | VM_U);
+ MR_SHARED | VM_V | VM_R | VM_U);
info("mapped fdt at %lx\n", *proc_fdt);
info("mapped initrd at %lx\n", *proc_initrd);
diff --git a/src/regions.c b/src/regions.c
index 66ee546..f098f4f 100644
--- a/src/regions.c
+++ b/src/regions.c
@@ -316,7 +316,10 @@ struct mem_region *find_free_region(struct mem_region_root *r, size_t size,
vm_t start = align_up(t->start, offset);
size_t qsize = t->end - t->start;
- size_t bsize = t->end - start;
+
+ size_t bsize = 0;
+ if (t->end >= start)
+ bsize = t->end - start;
if (!quick_best && size <= qsize)
quick_best = t;
diff --git a/src/tcb.c b/src/tcb.c
index 27256e9..6915676 100644
--- a/src/tcb.c
+++ b/src/tcb.c
@@ -120,14 +120,14 @@ void free_stack(struct tcb *t)
struct tcb *create_thread(struct tcb *p)
{
- hard_assert(tcbs, 0);
+ assert(tcbs);
vm_t bottom = alloc_page(KERNEL_STACK_PAGE_ORDER);
/* move tcb to top of kernel stack, keeping alignment in check
* (hopefully) */
/** \todo check alignment */
- struct tcb *t = (struct tcb *)align_down(
- bottom + order_size(MM_O0) - sizeof(struct tcb), sizeof(long));
+ bottom = bottom + order_size(MM_O0) - sizeof(struct tcb);
+ struct tcb *t = (struct tcb *)align_down(bottom, sizeof(long));
memset(t, 0, sizeof(struct tcb));
id_t tid = __alloc_tid(t);