aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/core/idt.c3
-rw-r--r--src/kernel/core/kmain.c122
-rw-r--r--src/kernel/core/paging.c1
-rw-r--r--src/kernel/include/thread.h2
-rw-r--r--src/kernel/user/nullfs.c3
5 files changed, 80 insertions, 51 deletions
diff --git a/src/kernel/core/idt.c b/src/kernel/core/idt.c
index 2f244e3..cb02bf9 100644
--- a/src/kernel/core/idt.c
+++ b/src/kernel/core/idt.c
@@ -106,7 +106,6 @@ void idt_irqHandler(registers_t *regs) {
}
outb(0x20, 0x20);
- dbg_printf("IRQ %i\n", regs->err_code);
if (irq_handlers[regs->err_code] != 0) {
irq_handlers[regs->err_code](regs);
}
@@ -114,7 +113,7 @@ void idt_irqHandler(registers_t *regs) {
/* Caled in interrupt.s when a syscall is called */
void idt_syscallHandler(registers_t *regs) {
- dbg_printf("Syscall %i\n", regs->int_no);
+ dbg_printf("Syscall %i (not implemented yet)\n", regs->int_no);
// do nothing, yet.
}
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c
index 57d49e5..774174f 100644
--- a/src/kernel/core/kmain.c
+++ b/src/kernel/core/kmain.c
@@ -27,7 +27,14 @@ void breakpoint_handler(registers_t *regs) {
BOCHS_BREAKPOINT;
}
+void breakpoint_test() {
+ dbg_printf("(BEGIN-TEST 'breakpoint-test)\n");
+ asm volatile("int $0x3"); // test breakpoint
+ dbg_printf("(TEST-OK)\n");
+}
+
void region_test1() {
+ dbg_printf("(BEGIN-TEST 'region-test-1)\n");
void* p = region_alloc(0x1000, "Test region", 0);
dbg_printf("Allocated one-page region: 0x%p\n", p);
dbg_print_region_info();
@@ -52,11 +59,13 @@ void region_test1() {
region_free(s);
dbg_printf("Freed region 0x%p\n", s);
dbg_print_region_info();
+
+ dbg_printf("(TEST-OK)\n");
}
void region_test2() {
// allocate a big region and try to write into it
- dbg_printf("Begin region test 2...");
+ dbg_printf("(BEGIN-TEST 'region-test-2)\n");
const size_t n = 200;
void* p0 = region_alloc(n * PAGE_SIZE, "Test big region", default_allocator_pf_handler);
for (size_t i = 0; i < n; i++) {
@@ -78,13 +87,14 @@ void region_test2() {
frame_free(f, 1);
}
region_free(p0);
- dbg_printf("OK\n");
+
+ dbg_printf("(TEST-OK)\n");
}
void kmalloc_test(void* kernel_data_end) {
+ dbg_printf("(BEGIN-TEST 'kmalloc-test)\n");
// Test kmalloc !
dbg_print_region_info();
- dbg_printf("Begin kmalloc test...\n");
const int m = 200;
uint16_t** ptr = malloc(m * sizeof(uint32_t));
for (int i = 0; i < m; i++) {
@@ -104,55 +114,78 @@ void kmalloc_test(void* kernel_data_end) {
free(ptr);
dbg_printf("Kmalloc test OK.\n");
dbg_print_region_info();
+
+ dbg_printf("(TEST-OK)\n");
}
void test_hashtbl_1() {
+ dbg_printf("(BEGIN-TEST 'test-hashtbl-1)\n");
// hashtable test
hashtbl_t *ht = create_hashtbl(str_key_eq_fun, str_hash_fun, 0, 0);
- hashtbl_add(ht, "test1", "Hello, world [test1]");
- hashtbl_add(ht, "test2", "Hello, world [test2]");
- dbg_printf("ht[test1] = %s\n", hashtbl_find(ht, "test1"));
- dbg_printf("ht[test] = %s\n", hashtbl_find(ht, "test"));
- dbg_printf("ht[test2] = %s\n", hashtbl_find(ht, "test2"));
- dbg_printf("adding test...\n");
- hashtbl_add(ht, "test", "Forever alone");
- dbg_printf("ht[test1] = %s\n", hashtbl_find(ht, "test1"));
- dbg_printf("ht[test] = %s\n", hashtbl_find(ht, "test"));
- dbg_printf("ht[test2] = %s\n", hashtbl_find(ht, "test2"));
- dbg_printf("removing test1...\n");
+ ASSERT(ht != 0);
+
+ ASSERT(hashtbl_add(ht, "test1", "STRTEST1"));
+ ASSERT(hashtbl_add(ht, "test2", "STRTEST2"));
+ ASSERT(hashtbl_find(ht, "test1") != 0 &&
+ strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0);
+ ASSERT(hashtbl_find(ht, "test2") != 0 &&
+ strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(hashtbl_find(ht, "test") == 0);
+
+ ASSERT(hashtbl_add(ht, "test", "Forever alone"));
+ ASSERT(hashtbl_find(ht, "test1") != 0 &&
+ strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0);
+ ASSERT(hashtbl_find(ht, "test2") != 0 &&
+ strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(hashtbl_find(ht, "test") != 0 &&
+ strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0);
+
hashtbl_remove(ht, "test1");
- dbg_printf("ht[test1] = %s\n", hashtbl_find(ht, "test1"));
- dbg_printf("ht[test] = %s\n", hashtbl_find(ht, "test"));
- dbg_printf("ht[test2] = %s\n", hashtbl_find(ht, "test2"));
+ ASSERT(hashtbl_find(ht, "test1") == 0);
+ ASSERT(hashtbl_find(ht, "test2") != 0 &&
+ strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(hashtbl_find(ht, "test") != 0 &&
+ strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0);
+
delete_hashtbl(ht, 0);
+
+ dbg_printf("(TEST-OK)\n");
}
void test_hashtbl_2() {
+ dbg_printf("(BEGIN-TEST 'test-hashtbl-2)\n");
+
hashtbl_t *ht = create_hashtbl(id_key_eq_fun, id_hash_fun, 0, 0);
- hashtbl_add(ht, (void*)12, "Hello, world [12]");
- hashtbl_add(ht, (void*)777, "Hello, world [777]");
- dbg_printf("ht[12] = %s\n", hashtbl_find(ht, (void*)12));
- dbg_printf("ht[144] = %s\n", hashtbl_find(ht, (void*)144));
- dbg_printf("ht[777] = %s\n", hashtbl_find(ht, (void*)777));
- dbg_printf("adding 144...\n");
- hashtbl_add(ht, (void*)144, "Forever alone");
- dbg_printf("ht[12] = %s\n", hashtbl_find(ht, (void*)12));
- dbg_printf("ht[144] = %s\n", hashtbl_find(ht, (void*)144));
- dbg_printf("ht[777] = %s\n", hashtbl_find(ht, (void*)777));
- dbg_printf("removing 12...\n");
+ ASSERT(ht != 0);
+
+ ASSERT(hashtbl_add(ht, (void*)12, "TESTSTR12"));
+ ASSERT(hashtbl_add(ht, (void*)777, "TESTSTR777"));
+
+ ASSERT(hashtbl_find(ht, (void*)12) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0);
+ ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);
+ ASSERT(hashtbl_find(ht, (void*)144) == 0);
+
+ ASSERT(hashtbl_add(ht, (void*)144, "Forever alone"));
+
+ ASSERT(hashtbl_find(ht, (void*)12) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0);
+ ASSERT(hashtbl_find(ht, (void*)144) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0);
+ ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);
+
hashtbl_remove(ht, (void*)12);
- dbg_printf("ht[12] = %s\n", hashtbl_find(ht, (void*)12));
- dbg_printf("ht[144] = %s\n", hashtbl_find(ht, (void*)144));
- dbg_printf("ht[777] = %s\n", hashtbl_find(ht, (void*)777));
+ ASSERT(hashtbl_find(ht, (void*)12) == 0);
+ ASSERT(hashtbl_find(ht, (void*)144) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0);
+ ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);
+
delete_hashtbl(ht, 0);
-}
-void test_thread(void* a) {
- for(int i = 0; i < 120; i++) {
- dbg_printf("b");
- for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx");
- if (i % 8 == 0) yield();
- }
+ dbg_printf("(TEST-OK)\n");
}
void kernel_init_stage2(void* data);
@@ -192,7 +225,8 @@ void kmain(multiboot_info_t *mbd, int32_t mb_magic) {
idt_init(); dbg_printf("IDT set up.\n");
idt_set_ex_handler(EX_BREAKPOINT, breakpoint_handler);
- asm volatile("int $0x3"); // test breakpoint
+
+ breakpoint_test();
size_t total_ram = ((mbd->mem_upper + mbd->mem_lower) * 1024);
dbg_printf("Total ram: %d Kb\n", total_ram / 1024);
@@ -230,14 +264,6 @@ void kernel_init_stage2(void* data) {
test_hashtbl_1();
test_hashtbl_2();
- thread_t *tb = new_thread(test_thread, 0);
- resume_thread(tb, false);
-
- for (int i = 0; i < 120; i++) {
- dbg_printf("a");
- for (int x = 0; x < 100000; x++) asm volatile("xor %%ebx, %%ebx":::"%ebx");
- }
-
// Create devfs
register_nullfs_driver();
fs_t *devfs = make_fs("nullfs", 0, "cd");
@@ -303,7 +329,7 @@ void kernel_init_stage2(void* data) {
// - launch it
// - just return, this thread is done
- PANIC("Reached kmain end! Falling off the edge.");
+ dbg_printf("Reached kmain end! I'll just stop here and do nothing.\n");
}
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/kernel/core/paging.c b/src/kernel/core/paging.c
index 25113ca..44e00fe 100644
--- a/src/kernel/core/paging.c
+++ b/src/kernel/core/paging.c
@@ -91,6 +91,7 @@ void page_fault_handler(registers_t *regs) {
if (regs->eflags & EFLAGS_IF) asm volatile("sti"); // userspace PF handlers should always be preemptible
dbg_printf("Userspace page fault at 0x%p\n", vaddr);
+ dbg_dump_registers(regs);
PANIC("Unhandled userspace page fault");
// not handled yet
// TODO
diff --git a/src/kernel/include/thread.h b/src/kernel/include/thread.h
index 757ba00..b5fa50d 100644
--- a/src/kernel/include/thread.h
+++ b/src/kernel/include/thread.h
@@ -10,7 +10,7 @@
#define KPROC_STACK_SIZE 0x8000 // 8Kb
-#define TASK_SWITCH_FREQUENCY 100 // in herz
+#define TASK_SWITCH_FREQUENCY 50 // in herz
typedef struct saved_context {
uint32_t *esp;
diff --git a/src/kernel/user/nullfs.c b/src/kernel/user/nullfs.c
index c27f923..1685f4c 100644
--- a/src/kernel/user/nullfs.c
+++ b/src/kernel/user/nullfs.c
@@ -165,6 +165,7 @@ bool nullfs_fs_make(fs_handle_t *source, char* opts, fs_t *fs_s) {
}
void nullfs_fs_shutdown(fs_ptr fs) {
+ dbg_printf("Not implemented: nullfs_fs_shutdown. Memory is leaking.\n");
// TODO free all
}
@@ -338,6 +339,8 @@ bool nullfs_d_delete(fs_node_ptr n, const char* file) {
}
bool nullfs_d_move(fs_node_ptr n, const char* old_name, fs_node_t *new_parent, const char *new_name) {
+ dbg_printf("Not implemented: move in nullfs. Failing potentially valid move request.\n");
+
return false; //TODO
}