Fix paging faults when switching/creating tasks
diff --git a/src/kernel/Jmk b/src/kernel/Jmk
index c299cf1..e1dc457 100644
--- a/src/kernel/Jmk
+++ b/src/kernel/Jmk
@@ -13,7 +13,7 @@
depends(initrd, $(ROOT)/boot/initrd, initrd.img)
LDFLAGS += -Tlink.ld -melf_i386
-ASMFLAGS += -felf
+ASMFLAGS += -felf -Fdwarf
QEMUFLAGS = -d cpu_reset
OBJECTS = boot.o \
diff --git a/src/kernel/main.c b/src/kernel/main.c
index ea5200b..1c654bd 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -80,6 +80,7 @@
greet();
spawn_thread(other_thread);
kprintf("thread spawned\n");
+
switch_task();
kprintf("Back in main thread\n");
diff --git a/src/kernel/paging.c b/src/kernel/paging.c
index 809d12c..536fdef 100644
--- a/src/kernel/paging.c
+++ b/src/kernel/paging.c
@@ -100,7 +100,7 @@
}
uint *page_table = kmalloc_a(sizeof(uint[1024]));
- dir[table] = (uint)page_table | 1 | rw << 1 | user << 2;
+ dir[table] = VIRT_TO_PHYS(page_table) | 1 | rw << 1 | user << 2;
return page_table;
}
@@ -130,6 +130,8 @@
// Page number % pages per table
uint page = ((size_t)virt / 0x1000) % 1024;
uint *table = get_or_create_table(dir, (size_t)virt >> 22, false, false);
+ kprintf("table = 0x%x (virt)\n", table);
+ kprintf("dir entry = 0x%x\n", dir[(size_t)virt >> 22]);
alloc_frame(&table[page], false, false);
diff --git a/src/kernel/task.c b/src/kernel/task.c
index 4e71174..82ad5ef 100644
--- a/src/kernel/task.c
+++ b/src/kernel/task.c
@@ -84,7 +84,6 @@
kprintf("base = 0x%x\n", base);
*base = 0;
- kpanic("in spawn_thread\n");
// </TEST>
struct ll_task_i *ll_task = malloc(sizeof(struct ll_task_i));
diff --git a/src/kernel/task_api.s b/src/kernel/task_api.s
index 686ddaa..1678969 100644
--- a/src/kernel/task_api.s
+++ b/src/kernel/task_api.s
@@ -13,13 +13,15 @@
ret
[global _switch_to_task]
+ ;; _switch_to_task(uint page_directory, uint eip, uint ebp, uint esp)
_switch_to_task: ; (page_directory, eip, ebp, esp)
add esp, 4 ; We don't care about the return address
- pop eax ; Instruction pointer
- pop ebp ; Frame pointer
- pop ebx ; Stack pointer
- pop ecx ; Page directory
+ pop ecx ; Page directory
+ pop eax ; eip
+ pop ebp
+ pop ebx ; esp
+
mov esp, ebx ; Reset old stack
mov cr3, ecx ; Set page directory