summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/arch/i386/sysenter.c8
-rw-r--r--src/kernel/main.c3
-rw-r--r--src/kernel/proc.c21
-rw-r--r--src/kernel/proc.h4
4 files changed, 16 insertions, 20 deletions
diff --git a/src/kernel/arch/i386/sysenter.c b/src/kernel/arch/i386/sysenter.c
index 5712ee3..1d2a333 100644
--- a/src/kernel/arch/i386/sysenter.c
+++ b/src/kernel/arch/i386/sysenter.c
@@ -23,10 +23,6 @@ _Noreturn void sysenter_stage2(void) {
val = _syscall(regs->eax, regs->ebx,
regs->esi, regs->edi, (uintptr_t)regs->ebp);
- if (process_current->state == PS_RUNNING) { // TODO move to _syscall()
- regs_savereturn(&process_current->regs, val);
- process_switch(process_current); // TODO process_resume
- } else {
- process_switch_any();
- }
+ regs_savereturn(&process_current->regs, val);
+ process_switch_any();
}
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 9188370..d1046b2 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -7,6 +7,7 @@
#include <stdint.h>
_Noreturn static void run_init(struct kmain_info *info) {
+ // TODO move all of this to process_seed
struct process *proc = process_seed();
void __user *init_base = (userptr_t)0x200000;
@@ -17,7 +18,7 @@ _Noreturn static void run_init(struct kmain_info *info) {
proc->regs.eip = init_base;
kprintf("switching...\n");
- process_switch(proc);
+ process_switch_any();
}
void kmain(struct kmain_info info) {
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 175377e..bb4509b 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -84,8 +84,7 @@ void process_free(struct process *p) {
kfree(p);
}
-// TODO make process_switch private
-void process_switch(struct process *proc) {
+static _Noreturn void process_switch(struct process *proc) {
assert(proc->state == PS_RUNNING);
if (proc->deathbed) {
process_kill(proc, -1);
@@ -96,13 +95,8 @@ void process_switch(struct process *proc) {
sysexit(proc->regs);
}
-_Noreturn void process_switch_any(void) {
- struct process *found = process_find(PS_RUNNING);
- if (found) process_switch(found);
- process_idle();
-}
-
-_Noreturn void process_idle(void) {
+/** If there are any processes waiting for IRQs, wait with them. Otherwise, shut down */
+static _Noreturn void process_idle(void) {
struct process *procs[16];
size_t len = process_find_multiple(PS_WAITS4IRQ, procs, 16);
@@ -121,6 +115,15 @@ _Noreturn void process_idle(void) {
}
}
+_Noreturn void process_switch_any(void) {
+ if (process_current && process_current->state == PS_RUNNING)
+ process_switch(process_current);
+
+ struct process *found = process_find(PS_RUNNING);
+ if (found) process_switch(found);
+ process_idle();
+}
+
struct process *process_next(struct process *p) {
/* is a weird depth-first search, the search order is:
* 1
diff --git a/src/kernel/proc.h b/src/kernel/proc.h
index 9304f28..3d3459d 100644
--- a/src/kernel/proc.h
+++ b/src/kernel/proc.h
@@ -63,12 +63,8 @@ extern struct process *process_current;
struct process *process_seed(void);
struct process *process_fork(struct process *parent);
void process_free(struct process *);
-_Noreturn void process_switch(struct process *proc);
_Noreturn void process_switch_any(void); // switches to any running process
-/** If there are any processes waiting for IRQs, wait with them. Otherwise, shut down */
-_Noreturn void process_idle(void);
-
/** Used for iterating over all processes */
struct process *process_next(struct process *);