|
AquilaOS documentation
How it works, and its code
|
x86: the Global Descriptor Table (GDT) and the TSS. More...
#include <core/system.h>#include <core/panic.h>#include <core/assert.h>#include <core/string.h>#include <cpu/msr.h>#include <sys/cpu.h>#include "cpu.h"Go to the source code of this file.
Macros | |
| #define | RW_DATA 0x2 |
| #define | XR_CODE 0xA |
| #define | TSS_AVL 0x9 |
| #define | BASE 0 |
| #define | LIMIT -1 |
| #define | DPL0 0 |
| #define | DPL3 3 |
| #define | L 1 |
| #define | D 0 |
| #define | MSR_GS_BASE 0xC0000101 |
| #define | MSR_KERNEL_GS_BASE 0xC0000102 |
Functions | |
| static void | segment_set (struct x86_gdt_entry *e, uintptr_t base, size_t limit) |
| Sets the base and limit of a system or data segment descriptor, with byte granularity. | |
| void | x86_gdt_setup (struct cpu *cpu, uintptr_t sp) |
| Sets up and loads the running CPU's GDT and TSS, and points gs (or the GS base, on x86_64) at its struct cpu, so that curcpu() works. | |
| void | x86_kernel_stack_set (uintptr_t sp) |
| Sets the kernel stack that interrupts from user mode switch to, on the running CPU: the thread that is about to run's. | |
Variables | |
| static const struct x86_gdt_entry | gdt_template [X86_GDT_TSS] |
x86: the Global Descriptor Table (GDT) and the TSS.
Each CPU has its own GDT: the flat kernel and user code and data segments, which every CPU shares, then its own TSS (the stack that interrupts from user mode switch to) and, on i386, a segment for its struct cpu, which curcpu() reads through gs.
Definition in file gdt.c.
| #define DPL0 0 |
Definition at line 28 of file gdt.c.
Referenced by x86_gdt_setup(), and x86_idt_gate_set().
| #define DPL3 3 |
Definition at line 29 of file gdt.c.
Referenced by x86_gdt_setup(), and x86_idt_gate_user_set().
| #define MSR_GS_BASE 0xC0000101 |
Definition at line 57 of file gdt.c.
Referenced by x86_gdt_setup().
| #define MSR_KERNEL_GS_BASE 0xC0000102 |
Definition at line 58 of file gdt.c.
Referenced by x86_gdt_setup().
| #define RW_DATA 0x2 |
Definition at line 21 of file gdt.c.
Referenced by x86_gdt_setup().
| #define TSS_AVL 0x9 |
Definition at line 23 of file gdt.c.
Referenced by x86_gdt_setup().
|
static |
Sets the base and limit of a system or data segment descriptor, with byte granularity.
Definition at line 62 of file gdt.c.
References x86_gdt_entry::base_hi, x86_gdt_entry::base_lo, x86_gdt_entry::base_mid, x86_gdt_entry::limit_hi, x86_gdt_entry::limit_lo, and segment_set().
Referenced by segment_set(), and x86_gdt_setup().
Sets up and loads the running CPU's GDT and TSS, and points gs (or the GS base, on x86_64) at its struct cpu, so that curcpu() works.
| cpu | the running CPU |
| sp | the kernel stack that interrupts from user mode switch to (each thread sets its own later, x86_kernel_stack_set()) |
Definition at line 79 of file gdt.c.
References x86_tss::_, x86_tss::__, cpu::arch, assert_alignof, assert_sizeof, x86_gdt_entry::db, x86_gdt_entry::dpl, DPL0, DPL3, arch_cpu::gdt, gdt_template, memcpy(), memset(), MSR_GS_BASE, MSR_KERNEL_GS_BASE, x86_gdt_entry::p, RW_DATA, x86_gdt_entry::s, segment_set(), cpu::self, x86_tss::sp, arch_cpu::tss, TSS_AVL, x86_gdt_entry::type, X86_GDT_CPU, x86_gdt_setup(), X86_GDT_TSS, x86_lgdt(), x86_ltr(), and X86_SEL_CPU.
Referenced by x86_ap_start(), x86_cpu_init(), and x86_gdt_setup().
| void x86_kernel_stack_set | ( | uintptr_t | sp | ) |
Sets the kernel stack that interrupts from user mode switch to, on the running CPU: the thread that is about to run's.
| sp | the top of the stack |
Definition at line 152 of file gdt.c.
References x86_kernel_stack_set().
Referenced by arch_idle(), arch_thread_kill(), arch_thread_spawn(), arch_thread_switch(), and x86_kernel_stack_set().
|
static |