x86_64 GDT for Remapped Kernel (2/2) | UEFI Dev (in C)

Channel:
Subscribers:
5,840
Published on ● Video Link: https://www.youtube.com/watch?v=KlykwpJTDy4



Duration: 1:41:37
1,283 views
43


This is the second half of recordings from the last video. Finishing the page table mappings and setting a new Global Descriptor Table (GDT) with an empty Task State Segment (TSS) for x86_64, so that we know we have full control and setup for memory when calling a kernel (other than interrupts, but I'm clearing those with cli, and a kernel can set those and other things up later as it wants).

Notes:
- The D/B bit is clear for 64 bit code segments because the intel manual states if the L (long mode) bit is set then the D bit must be clear.

- Instead of hardcoding GDT byte offsets such as 0x48 for the TSS descriptor, you could use offsetof(type, member) from stddef.h like
[tss]"r"((UINT16)(offsetof(GDT, tss)))

Links:
https://uefi.org/specifications (uefi & other specifications)
https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html (intel manuals)
https://wiki.osdev.org/GDT_Tutorial
https://wiki.osdev.org/Global_Descriptor_Table
https://en.wikipedia.org/wiki/X86_calling_conventions

UEFI Programming playlist:
https://www.youtube.com/playlist?list=PLT7NbkyNWaqZYHNLtOZ1MNxOt8myP5K0p

Git Repo:
https://github.com/queso-fuego/uefi-dev

Repo state at the start of (the previous) video:
git clone --recurse-submodules https://github.com/queso-fuego/uefi-dev
cd uefi-dev
git checkout 50de8d4a551458b89c55748b62097a4a2d0704c5

Repo state at the end of this video:
git checkout 3011ea7347916c753644c73b72b075639564964b

Join the Community Discord: https://discord.gg/yKm4T89QFn

Contact:
https://queso_fuego.srht.site/contact.html

Questions about setup/software/etc.?
Check the FAQ: https://queso_fuego.srht.site/about.html

If you feel like throwing money my way:
https://queso_fuego.srht.site/support.html

0:00:00 make kernel entry point 4KB aligned
0:02:55 remap kernel buffer & framebuffer, map stack memory
0:09:36 add types for GDT & TSS
0:35:05 go over new GDT/TSS values
0:49:40 fix/do other new changes since last part
0:57:11 get new kernel entry point for higher address
1:03:08 use inline asm to set page tables/GDT/TSS and call kernel
1:34:27 next video topics

Music credits:
"Pookatori and Friends" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/

#uefidev #cprogramming #gdt







Tags:
queso fuego
c programming
uefi dev
uefi programming
efi dev
x86_64
gdt
global descriptor table
task state segment
descriptors
higher half kernel
inline assembly