From 7d5be90d73f2f592a893d61df2bcce0541feaeec Mon Sep 17 00:00:00 2001 From: Pratik Devkota Date: Mon, 21 Jul 2025 16:08:20 +0545 Subject: [PATCH 1/4] fix typo in Scheduler --- 05_Scheduling/02_Scheduler.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_Scheduling/02_Scheduler.md b/05_Scheduling/02_Scheduler.md index 4d9f217..6f975fd 100644 --- a/05_Scheduling/02_Scheduler.md +++ b/05_Scheduling/02_Scheduler.md @@ -184,7 +184,7 @@ For the purpose of our example the scheduler will only have three states for now * READY: The process is in the queue and waiting to be scheduled. * RUNNING: The process is currently running on the cpu. -* DEAD: The process has finished running and should not be scheduled. It's resources can also be cleaned up. +* DEAD: The process has finished running and should not be scheduled. Its resources can also be cleaned up. We'll modify our selection algorithm to take these new states into account: From aa76dbe4c1e637bf31fd7251ce13575e95ad2060 Mon Sep 17 00:00:00 2001 From: Pratik Devkota Date: Mon, 21 Jul 2025 16:28:57 +0545 Subject: [PATCH 2/4] define segment selector values in GDT --- 02_Architecture/04_GDT.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/02_Architecture/04_GDT.md b/02_Architecture/04_GDT.md index 0804bca..299e5d7 100644 --- a/02_Architecture/04_GDT.md +++ b/02_Architecture/04_GDT.md @@ -183,6 +183,16 @@ A simple example is outline just below, for a simple 64-bit long mode setup we'd - Selector 0x18: user code (64-bit, ring 3) - Selector 0x20: user data (64-bit) +For future reference, we should define macros for these selectors. So let's assume we have the following: + +```c +#define NULL_SELECTOR 0x00 +#define KERNEL_CS 0x08 +#define KERNEL_DS 0x10 +#define USER_CS 0x18 +#define USER_DS 0x20 +``` + To create a GDT populated with these entries we'd do something like the following: ```c From f0268f61402e8c5117c0e987d253ae115d9c7fe9 Mon Sep 17 00:00:00 2001 From: Pratik Devkota Date: Mon, 21 Jul 2025 16:29:36 +0545 Subject: [PATCH 3/4] use proper macro for segment selector in "Processes and Threads" --- 05_Scheduling/03_Processes_And_Threads.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/05_Scheduling/03_Processes_And_Threads.md b/05_Scheduling/03_Processes_And_Threads.md index 93ece5c..1bc9e49 100644 --- a/05_Scheduling/03_Processes_And_Threads.md +++ b/05_Scheduling/03_Processes_And_Threads.md @@ -72,10 +72,10 @@ process_t* create_process(char* name, void(*function)(void*), void* arg) { strncpy(process->name, name, NAME_MAX_LEN); process->pid = next_free_pid++; process->process_status = READY; - process->context.iret_ss = KERNEL_SS; + process->context.iret_ss = KERNEL_DS; // from the GDT chapter process->context.iret_rsp = alloc_stack(); process->context.iret_flags = 0x202; - process->context.iret_cs = KERNEL_CS; + process->context.iret_cs = KERNEL_CS; // from the GDT chapter process->context.iret_rip = (uint64_t)function; process->context.rdi = (uint64_t)arg; process->context.rbp = 0; @@ -237,10 +237,10 @@ thread_t* add_thread(process_t* proc, char* name, void(*function)(void*), void* thread->tid = next_thread_id++; thread->status = READY; thread->next = NULL: - thread->context.iret_ss = KERNEL_SS; + thread->context.iret_ss = KERNEL_SS; // from the GDT chapter thread->context.iret_rsp = alloc_stack(); thread->context.iret_flags = 0x202; - thread->context.iret_cs = KERNEL_CS; + thread->context.iret_cs = KERNEL_CS; // from the GDT chapter thread->context.iret_rip = (uint64_t)function; thread->context.rdi = (uint64_t)arg; thread->context.rbp = 0; From 3af7003d7d7f7c755f4208eeee289b10180bf1c6 Mon Sep 17 00:00:00 2001 From: Pratik Devkota Date: Mon, 21 Jul 2025 16:38:01 +0545 Subject: [PATCH 4/4] fix missing KERNEL_DS instead of KERNEL_SS in "Processes and Threads" --- 05_Scheduling/03_Processes_And_Threads.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05_Scheduling/03_Processes_And_Threads.md b/05_Scheduling/03_Processes_And_Threads.md index 1bc9e49..353d393 100644 --- a/05_Scheduling/03_Processes_And_Threads.md +++ b/05_Scheduling/03_Processes_And_Threads.md @@ -237,7 +237,7 @@ thread_t* add_thread(process_t* proc, char* name, void(*function)(void*), void* thread->tid = next_thread_id++; thread->status = READY; thread->next = NULL: - thread->context.iret_ss = KERNEL_SS; // from the GDT chapter + thread->context.iret_ss = KERNEL_DS; // from the GDT chapter thread->context.iret_rsp = alloc_stack(); thread->context.iret_flags = 0x202; thread->context.iret_cs = KERNEL_CS; // from the GDT chapter