Advertisement
My-Bad-2

gdt

Nov 1st, 2023
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | Source Code | 0 0
  1. gdt::gdt(const tss& _tss) : tss_entry(_tss) {
  2.     entries[Null] = gdt_entry{};
  3.  
  4.     entries[Kernel_Code] = {
  5.         Present | Segment | Read_Write | Executable,
  6.         Long_Mode,
  7.     };
  8.  
  9.     entries[Kernel_Data] = {
  10.         Present | Segment | Read_Write,
  11.         0,
  12.     };
  13.  
  14.     entries[User_Data] = {
  15.         Present | Segment | Read_Write | User,
  16.         0,
  17.     };
  18.  
  19.     entries[User_Code] = {
  20.         Present | Segment | Read_Write | Executable | User,
  21.         Long_Mode,
  22.     };
  23. }
  24.  
  25. void init() {
  26.     tss _tss = {};
  27.     gdt _gdt = {_tss};
  28.     gdt_descriptor descriptor = {_gdt};
  29.  
  30.     descriptor.load();
  31.     tss_update();
  32.  
  33.     for (size_t i = 0; i < gdt::Length - 1; i++) {
  34.         log::debug.print("GDT[%lu]: 0x%016lX", i, (_gdt.entries[i]));
  35.     }
  36.  
  37.     log::debug.print("GDT[TSS]: 0x%016lX", _gdt.tss_entry);
  38.  
  39.     log::info.print("GDT Initialization - Success");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement