Skip to content

Commit f36ac62

Browse files
authored
Fix mistakes in "Processes and Threads" (#122)
* fix typo in Scheduler * define segment selector values in GDT * use proper macro for segment selector in "Processes and Threads" * fix missing KERNEL_DS instead of KERNEL_SS in "Processes and Threads"
1 parent de4a06c commit f36ac62

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

02_Architecture/04_GDT.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@ A simple example is outline just below, for a simple 64-bit long mode setup we'd
183183
- Selector 0x18: user code (64-bit, ring 3)
184184
- Selector 0x20: user data (64-bit)
185185

186+
For future reference, we should define macros for these selectors. So let's assume we have the following:
187+
188+
```c
189+
#define NULL_SELECTOR 0x00
190+
#define KERNEL_CS 0x08
191+
#define KERNEL_DS 0x10
192+
#define USER_CS 0x18
193+
#define USER_DS 0x20
194+
```
195+
186196
To create a GDT populated with these entries we'd do something like the following:
187197
188198
```c

05_Scheduling/02_Scheduler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ For the purpose of our example the scheduler will only have three states for now
184184
185185
* READY: The process is in the queue and waiting to be scheduled.
186186
* RUNNING: The process is currently running on the cpu.
187-
* DEAD: The process has finished running and should not be scheduled. It's resources can also be cleaned up.
187+
* DEAD: The process has finished running and should not be scheduled. Its resources can also be cleaned up.
188188
189189
We'll modify our selection algorithm to take these new states into account:
190190

05_Scheduling/03_Processes_And_Threads.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ process_t* create_process(char* name, void(*function)(void*), void* arg) {
7272
strncpy(process->name, name, NAME_MAX_LEN);
7373
process->pid = next_free_pid++;
7474
process->process_status = READY;
75-
process->context.iret_ss = KERNEL_SS;
75+
process->context.iret_ss = KERNEL_DS; // from the GDT chapter
7676
process->context.iret_rsp = alloc_stack();
7777
process->context.iret_flags = 0x202;
78-
process->context.iret_cs = KERNEL_CS;
78+
process->context.iret_cs = KERNEL_CS; // from the GDT chapter
7979
process->context.iret_rip = (uint64_t)function;
8080
process->context.rdi = (uint64_t)arg;
8181
process->context.rbp = 0;
@@ -237,10 +237,10 @@ thread_t* add_thread(process_t* proc, char* name, void(*function)(void*), void*
237237
thread->tid = next_thread_id++;
238238
thread->status = READY;
239239
thread->next = NULL:
240-
thread->context.iret_ss = KERNEL_SS;
240+
thread->context.iret_ss = KERNEL_DS; // from the GDT chapter
241241
thread->context.iret_rsp = alloc_stack();
242242
thread->context.iret_flags = 0x202;
243-
thread->context.iret_cs = KERNEL_CS;
243+
thread->context.iret_cs = KERNEL_CS; // from the GDT chapter
244244
thread->context.iret_rip = (uint64_t)function;
245245
thread->context.rdi = (uint64_t)arg;
246246
thread->context.rbp = 0;

0 commit comments

Comments
 (0)