summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kernel/paging.c10
-rw-r--r--src/kernel/task.c12
-rw-r--r--src/kernel/window.c97
3 files changed, 64 insertions, 55 deletions
diff --git a/src/kernel/paging.c b/src/kernel/paging.c
index 4672788..0432ab6 100644
--- a/src/kernel/paging.c
+++ b/src/kernel/paging.c
@@ -132,7 +132,8 @@ void init_paging() {
__attribute__ ((pure))
void *vma_to_pma(void *pd, const void *vma) {
- return (void *)(((uint32_t *)(((uint32_t *)pd)[(uint32_t)vma >> 22] & PE_ADDR_MASK))[((uint32_t)vma >> 12) % 1024] & PE_ADDR_MASK) + (uint32_t)vma % 4096;
+ //this is maybe not good - in the case where pd is zero, vma is returned unconsted. hopefully this doesn't become a problem.
+ return pd ? (void *)(((uint32_t *)(((uint32_t *)pd)[(uint32_t)vma >> 22] & PE_ADDR_MASK))[((uint32_t)vma >> 12) % 1024] & PE_ADDR_MASK) + (uint32_t)vma % 4096 : (void *)(uint32_t)vma;
}
void switch_to_kernel_cr3() {
@@ -143,7 +144,8 @@ void switch_to_kernel_cr3() {
}
void switch_to_task_cr3() {
- asm volatile (
- "mov %0, %%cr3"
- : : "a" (active_task->page_directory));
+ if (active_task->page_directory)
+ asm volatile (
+ "mov %0, %%cr3"
+ : : "a" (active_task->page_directory));
} \ No newline at end of file
diff --git a/src/kernel/task.c b/src/kernel/task.c
index e2412e1..8d8de86 100644
--- a/src/kernel/task.c
+++ b/src/kernel/task.c
@@ -86,12 +86,12 @@ void advance_active_task() {
}
void make_sure_tasks() {
- for (uint8_t n = 0; n < MAX_TASKS; ++n)
- if (tasks[n].page_directory)
- return;
- logf(LOG_INFO, "No tasks, halting.");
- while (1)
- asm("hlt");
+ while (1) {
+ for (uint8_t n = 0; n < MAX_TASKS; ++n)
+ if (tasks[n].page_directory)
+ return;
+ tmp_halt();
+ }
}
//IPC stuff isn't fully implemented, or tested in this version.
diff --git a/src/kernel/window.c b/src/kernel/window.c
index c251077..74273fb 100644
--- a/src/kernel/window.c
+++ b/src/kernel/window.c
@@ -289,63 +289,70 @@ void on_action(struct window_action packet) {
if (packet.action_type == NOT_READY)
return;
- if (top_window) {
- if (packet.action_type == KEY_DOWN)
- for (uint8_t i = 0; i < N_WM_ACTIONS; ++i)
- if (fuzzy_key_match(keybinds[i], packet.as_key)) {
- switch_to_kernel_cr3();
- struct window *old_top, *old_bottom;
- switch (i) {
- case WM_SHUFFLE_UP:
- if (!top_window->below)
- break;
- old_top = top_window;
- old_bottom = bottom_window;
- top_window = old_top->below;
- top_window->above = 0;
- old_top->below = 0;
- old_top->above = old_bottom;
- old_bottom->below = old_top;
- bottom_window = old_top;
- paint_and_above(bottom_window->above);
+ if (packet.action_type == KEY_DOWN)
+ for (uint8_t i = 0; i < N_WM_ACTIONS; ++i)
+ if (fuzzy_key_match(keybinds[i], packet.as_key)) {
+ switch_to_kernel_cr3();
+ struct window *old_top, *old_bottom;
+ switch (i) {
+ case WM_SHUFFLE_UP:
+ if (!top_window || !top_window->below)
break;
- case WM_SHUFFLE_DOWN:
- if (!top_window->below)
- break;
- old_top = top_window;
- old_bottom = bottom_window;
- bottom_window = old_bottom->above;
- bottom_window->below = 0;
- old_bottom->above = 0;
- old_bottom->below = old_top;
- old_top->above = old_bottom;
- top_window = old_bottom;
- paint_and_above(top_window);
+ old_top = top_window;
+ old_bottom = bottom_window;
+ top_window = old_top->below;
+ top_window->above = 0;
+ old_top->below = 0;
+ old_top->above = old_bottom;
+ old_bottom->below = old_top;
+ bottom_window = old_top;
+ paint_and_above(bottom_window->above);
+ break;
+ case WM_SHUFFLE_DOWN:
+ if (!top_window || !top_window->below)
break;
- case WM_MOVE_LEFT:
+ old_top = top_window;
+ old_bottom = bottom_window;
+ bottom_window = old_bottom->above;
+ bottom_window->below = 0;
+ old_bottom->above = 0;
+ old_bottom->below = old_top;
+ old_top->above = old_bottom;
+ top_window = old_bottom;
+ paint_and_above(top_window);
+ break;
+ case WM_MOVE_LEFT:
+ if (top_window) {
--top_window->xpos;
paint_all();
- break;
- case WM_MOVE_RIGHT:
+ }
+ break;
+ case WM_MOVE_RIGHT:
+ if (top_window) {
++top_window->xpos;
paint_all();
- break;
- case WM_MOVE_UP:
+ }
+ break;
+ case WM_MOVE_UP:
+ if (top_window) {
--top_window->ypos;
paint_all();
- break;
- case WM_MOVE_DOWN:
+ }
+ break;
+ case WM_MOVE_DOWN:
+ if (top_window) {
++top_window->ypos;
paint_all();
- break;
- case WM_RUN_COMMAND:
- if (!try_elf_run(drives, run_command, run_command_pass, 0))
- PANIC("Couldn't run program listed in " RUN_COMMAND_FILE ".");
}
- switch_to_task_cr3();
- return;
+ break;
+ case WM_RUN_COMMAND:
+ if (!try_elf_run(drives, run_command, run_command_pass, 0))
+ PANIC("Couldn't run program listed in " RUN_COMMAND_FILE ".");
}
+ switch_to_task_cr3();
+ return;
+ }
+ if (top_window)
send_action(top_window, packet);
- }
} \ No newline at end of file