summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/entry.S18
-rw-r--r--sys/kern/init.c21
-rw-r--r--sys/kern/mm/kalloc.c2
-rw-r--r--sys/kern/spinlock.c15
4 files changed, 47 insertions, 9 deletions
diff --git a/sys/kern/entry.S b/sys/kern/entry.S
index fccd80f..03ff76c 100644
--- a/sys/kern/entry.S
+++ b/sys/kern/entry.S
@@ -2,6 +2,7 @@
.globl _start
_start:
+ /* disable interrupts and poging */
csrw satp, zero
csrw sie, zero
csrw sip, zero
@@ -11,33 +12,42 @@ _start:
la gp, __global_pointer$
.option pop
+ /* setup stack */
addi t0, a0, 1
li t1, PAGE_SIZE
la sp, __stack_start
mul t1, t1, t0
add sp, sp, t1
+ /* setup thread pointer */
+ mv tp, a0
+
+ /* the label _boot_hart is shared between threads. only one hart will branch before it is no longer 0 */
li a2, 1
lla a3, _boot_hart
amoswap.w a3, a2, (a3)
- bnez a3, _spin
+ bnez a3, 2f
+ /* clear the bss section */
la a2, __bss_start
la a3, __bss_end
1:
sd zero, (a2)
addi a2, a2, __SIZEOF_POINTER__
blt a2, a3, 1b
-
+2:
call init
-
+ j _spin
_spin:
wfi
j _spin
.section ".data"
-_boot_hart: .word 0
+_boot_hart:
+ .word 0
+
.section ".rodata"
+/* linker imports */
.globl HEAP_START
HEAP_START: .dword __heap_start
diff --git a/sys/kern/init.c b/sys/kern/init.c
index 18feaa3..208df6d 100644
--- a/sys/kern/init.c
+++ b/sys/kern/init.c
@@ -1,20 +1,35 @@
#include <fdt.h>
+#include <mm/kalloc.h>
#include <printf.h>
#include <stdint.h>
-#include <mm/kalloc.h>
+#include <spinlock.h>
extern uint64_t HEAP_START;
void
init(unsigned long hartid, struct fdt_header *fdt)
{
+
printf("booting from hart #%d\n", hartid);
+ asm volatile ("mv tp, %0" : : "r"(hartid));
if (fdt_uint32(fdt->magic) == FDT_HEADER_MAGIC)
printf("found flattened device tree at %p!\n", (uint64_t)fdt);
+ printf("parsing device tree!\n");
+ fdt_walk(fdt);
+
printf("setting up the heap at %p\n", HEAP_START);
kalloc_init();
printf("done!\n");
- printf("printing free pages:\n");
- walkfree();
+ // printf("printing free pages:\n");
+ //walkfree();
+}
+
+/* non boot harts enter here */
+void
+mpinit(unsigned long hartid, struct fdt_header *fdt)
+{
+ unsigned char *uart = (unsigned char*)0x10000000;
+ *uart = hartid + '0';
+ *(uart + 1) = '\n';
}
diff --git a/sys/kern/mm/kalloc.c b/sys/kern/mm/kalloc.c
index f354648..bfd4f3f 100644
--- a/sys/kern/mm/kalloc.c
+++ b/sys/kern/mm/kalloc.c
@@ -46,10 +46,8 @@ kfree(void *p)
void
kalloc_init(void)
{
- printf("1\n");
freenode_t *p = (freenode_t*)HEAP_START;
for (;(unsigned long)p + PAGE_SIZE <= (HEAP_START + 0x100000); p += PAGE_SIZE) {
- printf("freeing page at %p", p);
kfree(p);
}
}
diff --git a/sys/kern/spinlock.c b/sys/kern/spinlock.c
new file mode 100644
index 0000000..a35b8ce
--- /dev/null
+++ b/sys/kern/spinlock.c
@@ -0,0 +1,15 @@
+#include <spinlock.h>
+
+void
+init_locklock(struct spinlock *l, const char *_name)
+{
+ l->name = _name;
+ l->locked = 0;
+ l->cpu = 0;
+}
+
+void
+acquire_lock(struct spinlock *l)
+{
+ asm volatile("csrr sie, zero");
+}