From 8ccd1cfbcfe7cca692caadf0803790e8322b2398 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 27 Sep 2019 15:45:23 -0700 Subject: 5692 - attempt at never leaving kernel mode Doesn't work. Kernel gets kicked back to the Grub prompt(!) --- kernel.soso/process.c | 23 +++++++++++++++-------- kernel.soso/process.h | 3 --- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/kernel.soso/process.c b/kernel.soso/process.c index 7964467b..e1088bd8 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); +static void switchToTask(Thread* current, int mode); static void updateMetrics(Thread* thread) { uint32 seconds = getUptimeSeconds(); @@ -657,10 +657,20 @@ void schedule(TimerInt_Registers* registers) { */ updateMetrics(current); - switchToTask(current); + + if (current->regs.cs != 0x08) { + switchToTask(current, USERMODE); + } + else { + switchToTask(current, KERNELMODE); + } } -static void switchToTask(Thread* 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) { uint32 kesp, eflags; uint16 kss, ss, cs; @@ -672,14 +682,11 @@ static void switchToTask(Thread* current) { cs = current->regs.cs; eflags = (current->regs.eflags | 0x200) & 0xFFFFBFFF; - int oldMode; - if (cs != 0x08) { - oldMode = USERMODE; + if (mode == USERMODE) { kss = current->kstack.ss0; kesp = current->kstack.esp0; } else { - oldMode = KERNELMODE; kss = current->regs.ss; kesp = current->regs.esp; } @@ -708,6 +715,6 @@ static void switchToTask(Thread* current) { "m"(current->regs.eip), \ "m"(current), \ [KMODE] "i"(KERNELMODE), \ - [mode] "g"(oldMode) + [mode] "g"(mode) ); } diff --git a/kernel.soso/process.h b/kernel.soso/process.h index a2979714..ab4e3615 100644 --- a/kernel.soso/process.h +++ b/kernel.soso/process.h @@ -1,9 +1,6 @@ #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