UnnamedOS
tss.c
Go to the documentation of this file.
1 
15 #include <common.h>
16 #include <tasks/tss.h>
17 
19 typedef struct {
20  uint32_t : 32,
21  esp0 : 32,
22  ss0 : 16,
23  : 16, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32,
25  : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 32, : 16,
26  iopb : 16;
27 } __attribute__((packed)) tss_t;
28 
29 static tss_t tss;
30 
37  gdt_init_entry(GDT_TASK_STATE_SEG, (uint32_t) &tss, sizeof(tss));
38  gdt[5].ac = 1; gdt[5].rw = 0; gdt[5].dc = 0; gdt[5].ex = 1; gdt[5].dt = 0;
39  gdt[5].dpl = 3; gdt[5].pr = 1; gdt[5].sz = 1; gdt[5].gr = 0;
42 }
43 
48 void tss_set_stack(uint32_t stack_pointer) {
49  tss.esp0 = stack_pointer;
50 }
51 
53 void tss_load() {
55  uint16_t tss_selector = gdt_get_selector(GDT_TASK_STATE_SEG);
56  asm volatile("ltr %0" : : "a" (tss_selector));
57 }
58 
static tss_t tss
the TSS, for software multitasking we only need one
Definition: tss.c:29
void tss_set_stack(uint32_t stack_pointer)
Sets the TSS&#39;s kernel stack which is used to handle interrupts.
Definition: tss.c:48
void tss_init(gdt_entry_t *gdt)
Initializes the TSS.
Definition: tss.c:35
#define GDT_RING0_DATA_SEG
kernel data segment index
Definition: gdt.h:14
An entry in the GDT.
Definition: gdt.h:20
the task state segment
Definition: tss.c:19
uint32_t esp0
the stack pointer to load when entering the kernel
Definition: tss.c:20
uint16_t gdt_get_selector(size_t entry)
Returns a selector ready to be loaded in a segment register.
Definition: gdt.c:103
void tss_load()
Loads the TSS into the TR register.
Definition: tss.c:53
#define GDT_TASK_STATE_SEG
task state segment index
Definition: gdt.h:17
static gdt_entry_t gdt[GDT_ENTRIES]
The GDT itself. It is located inside the kernel.
Definition: gdt.c:41
void gdt_init_entry(size_t entry, uint32_t base, uint32_t limit)
Sets basic parameters of a GDT entry.
Definition: gdt.c:49