MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / InitializeTSS

Function InitializeTSS

Kernel/src/arch/x86_64/tss.cpp:12–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10namespace TSS
11{
12 void InitializeTSS(tss_t* tss, void* gdt){
13
14 LoadTSS((uintptr_t)tss, (uint64_t)gdt, 0x28);
15
16 memset(tss, 0, sizeof(tss_t));
17
18 // Set up Interrupt Stack Tables
19 tss->ist1 = (uint64_t)Memory::KernelAllocate4KPages(8);
20 tss->ist2 = (uint64_t)Memory::KernelAllocate4KPages(8);
21 tss->ist3 = (uint64_t)Memory::KernelAllocate4KPages(8);
22
23 for(unsigned i = 0; i < 8; i++){
24 Memory::KernelMapVirtualMemory4K(Memory::AllocatePhysicalMemoryBlock(), tss->ist1 + 8 * PAGE_SIZE_4K, 1);
25 Memory::KernelMapVirtualMemory4K(Memory::AllocatePhysicalMemoryBlock(), tss->ist2 + 8 * PAGE_SIZE_4K, 1);
26 Memory::KernelMapVirtualMemory4K(Memory::AllocatePhysicalMemoryBlock(), tss->ist3 + 8 * PAGE_SIZE_4K, 1);
27 }
28
29 memset((void*)tss->ist1, 0, PAGE_SIZE_4K);
30 memset((void*)tss->ist2, 0, PAGE_SIZE_4K);
31 memset((void*)tss->ist3, 0, PAGE_SIZE_4K);
32
33 tss->ist1 += PAGE_SIZE_4K * 8;
34 tss->ist2 += PAGE_SIZE_4K * 8;
35 tss->ist3 += PAGE_SIZE_4K * 8;
36
37 asm volatile("mov %%rsp, %0" : "=r"(tss->rsp0));
38
39 asm volatile("ltr %%ax" :: "a"(0x2B));
40 }
41}

Callers 2

SMPEntryFunction · 0.85
InitializeFunction · 0.85

Calls 4

memsetFunction · 0.85
KernelAllocate4KPagesFunction · 0.85
KernelMapVirtualMemory4KFunction · 0.85

Tested by

no test coverage detected