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 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: diff --git a/05_Scheduling/03_Processes_And_Threads.md b/05_Scheduling/03_Processes_And_Threads.md index 93ece5c..353d393 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_DS; // 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;