diff options
author | Marvin Borner | 2020-05-12 23:53:02 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-12 23:53:02 +0200 |
commit | 3624343800de35b9058c11186dc02dd20d98aedf (patch) | |
tree | db9e2408a3d440bcc02f4b7e12ef597642fdaafc | |
parent | 3b16ca421aad772e0f40716e2fc66215d322f7f7 (diff) |
Added scheduler spinlocking
I don't think it's needed though, ints are disabled anyway
-rw-r--r-- | src/kernel/io/io.c | 16 | ||||
-rw-r--r-- | src/kernel/io/io.h | 10 | ||||
-rw-r--r-- | src/kernel/tasks/process.c | 11 | ||||
-rw-r--r-- | src/kernel/tasks/userspace.c | 5 | ||||
-rw-r--r-- | src/userspace/programs/sh.c | 4 |
5 files changed, 32 insertions, 14 deletions
diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c index dfd9efa..fd7cd46 100644 --- a/src/kernel/io/io.c +++ b/src/kernel/io/io.c @@ -36,6 +36,14 @@ int interrupts_enabled() return (cpu_flags() & 0x200) == 0x200; } +void interrupts_print() +{ + if (interrupts_enabled()) + log(GRN "Interrupts are enabled!" RES); + else + log(RED "Interrupts are disabled!" RES); +} + void cli() { asm volatile("cli"); @@ -66,14 +74,6 @@ void outl(u16 port, u32 data) asm volatile("outl %0, %1" ::"a"(data), "Nd"(port)); } -void spinlock(int *ptr) -{ - int prev; - do - asm volatile("lock xchgl %0,%1" : "=a"(prev) : "m"(*ptr), "a"(1)); - while (prev); -} - void init_serial() { outb(0x3f8 + 1, 0x00); diff --git a/src/kernel/io/io.h b/src/kernel/io/io.h index ba5e7c1..2d078f1 100644 --- a/src/kernel/io/io.h +++ b/src/kernel/io/io.h @@ -25,6 +25,7 @@ u16 inw(u16 port); u32 inl(u16 port); int interrupts_enabled(); +void interrupts_print(); void cli(); void sti(); void hlt(); @@ -61,4 +62,13 @@ void init_serial(); */ void serial_put(char ch); +// Spinlock +static inline void spinlock(int *ptr) +{ + int prev; + do + asm volatile("lock xchgl %0,%1" : "=a"(prev) : "m"(*ptr), "a"(1)); + while (prev); +} + #endif
\ No newline at end of file diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index 45c9937..ebb7a81 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -22,11 +22,15 @@ extern u32 stack_hold; void scheduler(struct regs *regs) { + static int locked = 0; + spinlock(&locked); + serial_put('.'); if (quantum == 0 || current_proc->state != PROC_RUNNING) { quantum = 42; // For next process } else { quantum--; + locked = 0; return; } @@ -45,13 +49,14 @@ void scheduler(struct regs *regs) while (current_proc->state == PROC_ASLEEP) { current_proc = current_proc->next; if (current_proc == NULL) { - //warn("No next process!"); + warn("No next process!"); current_proc = root; } } memcpy(regs, ¤t_proc->registers, sizeof(struct regs)); paging_switch_directory(current_proc->cr3); + locked = 0; } void process_force_switch() @@ -66,7 +71,7 @@ void process_init(struct process *proc) log("Initializing process %d", pid); root = proc; root->pid = pid++; - root->next = NULL; + root->next = proc; root->state = PROC_RUNNING; current_proc = root; @@ -85,6 +90,8 @@ void process_print_tree() info("%s with PID %d (state: %s)", proc->name, proc->pid, proc->state == PROC_RUNNING ? "running" : "sleeping"); proc = proc->next; + if (proc->pid == 1) + break; } serial_put('\n'); } diff --git a/src/kernel/tasks/userspace.c b/src/kernel/tasks/userspace.c index e9fd2f0..3164965 100644 --- a/src/kernel/tasks/userspace.c +++ b/src/kernel/tasks/userspace.c @@ -22,14 +22,11 @@ u32 spawn_child(struct process *child) void userspace_enter(struct process *proc) { proc_bottom = proc; - proc->next = NULL; hl_eip = proc->registers.eip; hl_esp = proc->registers.esp; paging_switch_directory(proc->cr3); - current_proc = proc; - - debug("Jumping to userspace!"); + //debug("Jumping to userspace!"); jump_userspace(); } diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c index d1ae1f8..2575c26 100644 --- a/src/userspace/programs/sh.c +++ b/src/userspace/programs/sh.c @@ -28,6 +28,10 @@ int interrupts_enabled() void main() { printf("Shell started\n"); + if (interrupts_enabled()) + printf("INTs enabled :)\n"); + else + printf("INTs disabled :(\n"); //syscall_map(MAP_KEYBOARD, (u32)&test); |