|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "common/stdint.h"Go to the source code of this file.
Macros | |
| #define | GDT_KERNEL_CODE 0x08 |
| kernel code segment selector (GDT index 1, RPL 0). | |
| #define | GDT_KERNEL_DATA 0x10 |
| kernel data segment selector (GDT index 2, RPL 0). | |
| #define | GDT_USER_CODE 0x1B |
| user code segment selector (GDT index 3, RPL 3). | |
| #define | GDT_USER_DATA 0x23 |
| user data segment selector (GDT index 4, RPL 3). | |
| #define | GDT_TSS 0x28 |
| TSS segment selector (GDT index 5, RPL 0). | |
| #define | GDT_DOUBLE_FAULT_TSS 0x30 |
| double-fault task TSS selector (GDT index 6, RPL 0). | |
| #define | GDT_USER_TLS 0x3B |
| #define | GDT_KERNEL_PERCPU 0x40 |
Functions | |
| void | gdt_initialize (uint32_t core) |
| set up the GDT of a core with kernel segments, user segments and a Task State Segment, and load the GDT into GDTR and the TSS into TR. | |
| void | tss_set_kernel_stack (uintptr_t esp0) |
| update the kernel stack pointer (ESP0) in the TSS of the core that runs the call. | |
| void | gdt_set_tls (uint32_t base) |
| set the base of the user TLS segment in the GDT of the core that runs the call, and load GS with it. | |
| void | gdt_set_percpu (uint32_t core, uint32_t base) |
| set the base of the per-CPU segment (the cpu_t of the core) and load FS with it. | |
| void | tss_install_double_fault (uint32_t core, void(*entry)(void), uintptr_t stack_top) |
| set up the double-fault task: a second TSS whose state the CPU loads when a double fault arrives through a task gate, so the handler runs on its own stack even when the faulting stack is unusable (a kernel stack overflow into its guard page). | |
| void | tss_set_double_fault_cr3 (uint32_t core, uint32_t cr3) |
| set the page directory the double-fault task of a core runs with. | |
| void | tss_interrupted_state (uint32_t *eip, uint32_t *esp, uint32_t *ebp) |
| read the state of the task that was running when the double fault struck. | |
| #define GDT_KERNEL_CODE 0x08 |
kernel code segment selector (GDT index 1, RPL 0).
| #define GDT_KERNEL_DATA 0x10 |
kernel data segment selector (GDT index 2, RPL 0).
| #define GDT_USER_CODE 0x1B |
user code segment selector (GDT index 3, RPL 3).
| #define GDT_USER_DATA 0x23 |
user data segment selector (GDT index 4, RPL 3).
| #define GDT_TSS 0x28 |
TSS segment selector (GDT index 5, RPL 0).
| #define GDT_DOUBLE_FAULT_TSS 0x30 |
double-fault task TSS selector (GDT index 6, RPL 0).
| #define GDT_USER_TLS 0x3B |
| #define GDT_KERNEL_PERCPU 0x40 |
| void gdt_initialize | ( | uint32_t | core | ) |
set up the GDT of a core with kernel segments, user segments and a Task State Segment, and load the GDT into GDTR and the TSS into TR.
each core has its own GDT and TSS. call it on the core itself.
| core | the index of the core (cpu_t.index), 0 for the boot core. |
| void tss_set_kernel_stack | ( | uintptr_t | esp0 | ) |
update the kernel stack pointer (ESP0) in the TSS of the core that runs the call.
called on context switches so the CPU knows where to find the kernel stack when an interrupt occurs in ring 3.
| esp0 | the kernel stack pointer to store. |
| void gdt_set_tls | ( | uint32_t | base | ) |
set the base of the user TLS segment in the GDT of the core that runs the call, and load GS with it.
| base | the thread pointer. |
set up the double-fault task: a second TSS whose state the CPU loads when a double fault arrives through a task gate, so the handler runs on its own stack even when the faulting stack is unusable (a kernel stack overflow into its guard page).
each core has its own task.
| core | the index of the core. |
| entry | function the task starts in; it must never return. |
| stack_top | initial ESP for the task. |
set the page directory the double-fault task of a core runs with.
| core | the index of the core. |
| cr3 | physical address of the kernel page directory. |
read the state of the task that was running when the double fault struck.
the task switch saves it into the main TSS of the core that runs the call.
| eip | receives the interrupted EIP. |
| esp | receives the interrupted ESP. |
| ebp | receives the interrupted EBP. |