Last active
March 27, 2022 18:50
-
-
Save josephxanderson/67235aebca8790b50f84048b371af7b5 to your computer and use it in GitHub Desktop.
Poncho OS Tutorials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[bits 64] | |
loadGDT: | |
lgdt [rdi] ; "rdi" register will contain parameter passed to loadGDT when called from C. | |
; Upload kernelData segment. | |
mov ax, 0x10 | |
mov ds, ax | |
mov es, ax | |
mov fs, ax | |
mov gs, ax | |
mov ss, ax | |
pop rdi ; Pop return address of loadGDT function. | |
; Upload kernelCode segment. | |
mov rax, 0x08 | |
push rax | |
push rdi | |
retfq | |
GLOBAL loadGDT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__attribute__((aligned(0x1000))) | |
GlobalDescriptorTable defaultGDT = { | |
{0, 0, 0, 0x00, 0x00, 0}, // null | |
{0, 0, 0, 0x9a, 0xa0, 0}, // kernelCode | |
{0, 0, 0, 0x92, 0xa0, 0}, // kernelData | |
{0, 0, 0, 0x9a, 0xa0, 0}, // userCode | |
{0, 0, 0, 0x92, 0xa0, 0}, // userData | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <Common/Types.h> | |
struct GDTDescriptor { | |
UInt16 size; | |
UInt64 offset; | |
} __attribute__((packed)); | |
struct GDTEntry { | |
UInt16 limit0; | |
UInt16 base0; | |
UInt8 base1; | |
UInt8 accessByte; | |
UInt8 limit1Flags; | |
UInt8 base2; | |
}__attribute__((packed)); | |
struct GlobalDescriptorTable { | |
GDTEntry null; // 0x00 | |
GDTEntry kernelCode; // 0x08 | |
GDTEntry kernelData; // 0x10 | |
GDTEntry userNull; | |
GDTEntry userCode; | |
GDTEntry userData; | |
}__attribute__((packed)) __attribute__((aligned(0x1000))); | |
extern GlobalDescriptorTable defaultGDT; | |
extern "C" void loadGDT(GDTDescriptor *gdtDescriptor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KernelInformation initializeKernel(BootInformation *bootInformation) | |
{ | |
GDTDescriptor gdtDescriptor; | |
gdtDescriptor.size = (sizeof(GlobalDescriptorTable) - 1); | |
gdtDescriptor.offset = (UInt64)&defaultGDT; | |
loadGDT(&gdtDescriptor); | |
prepareMemory(bootInformation); | |
return kernelInformation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment