From f470eca4ee9455cbefadb90af876acae62607257 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 27 Sep 2019 15:46:41 -0700 Subject: 5693 Undo previous commit. --- kernel.soso/process.c | 23 ++++++++--------------- kernel.soso/process.h | 3 +++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/kernel.soso/process.c b/kernel.soso/process.c index e1088bd8..7964467b 100644 --- a/kernel.soso/process.c +++ b/kernel.soso/process.c @@ -547,7 +547,7 @@ BOOL isProcessValid(Process* process) { return FALSE; } -static void switchToTask(Thread* current, int mode); +static void switchToTask(Thread* current); static void updateMetrics(Thread* thread) { uint32 seconds = getUptimeSeconds(); @@ -657,20 +657,10 @@ void schedule(TimerInt_Registers* registers) { */ updateMetrics(current); - - if (current->regs.cs != 0x08) { - switchToTask(current, USERMODE); - } - else { - switchToTask(current, KERNELMODE); - } + switchToTask(current); } - - -//The mode indicates whether this process was in user mode or kernel mode -//When it was previously interrupted by the scheduler. -static void switchToTask(Thread* current, int mode) { +static void switchToTask(Thread* current) { uint32 kesp, eflags; uint16 kss, ss, cs; @@ -682,11 +672,14 @@ static void switchToTask(Thread* current, int mode) { cs = current->regs.cs; eflags = (current->regs.eflags | 0x200) & 0xFFFFBFFF; - if (mode == USERMODE) { + int oldMode; + if (cs != 0x08) { + oldMode = USERMODE; kss = current->kstack.ss0; kesp = current->kstack.esp0; } else { + oldMode = KERNELMODE; kss = current->regs.ss; kesp = current->regs.esp; } @@ -715,6 +708,6 @@ static void switchToTask(Thread* current, int mode) { "m"(current->regs.eip), \ "m"(current), \ [KMODE] "i"(KERNELMODE), \ - [mode] "g"(mode) + [mode] "g"(oldMode) ); } diff --git a/kernel.soso/process.h b/kernel.soso/process.h index ab4e3615..a2979714 100644 --- a/kernel.soso/process.h +++ b/kernel.soso/process.h @@ -1,6 +1,9 @@ #ifndef PROCESS_H #define PROCESS_H +#define KERNELMODE 0 +#define USERMODE 1 + #define MAX_OPENED_FILES 20 #include "common.h" -- cgit 1.4.1-2-gfad0