Add GDT and IDT

This commit is contained in:
Bananymous
2022-11-16 19:49:09 +02:00
parent b500a8a7ed
commit f2b45ba212
6 changed files with 236 additions and 15 deletions

View File

@@ -0,0 +1,56 @@
#pragma once
#include <stdint.h>
union SegmentDesriptor
{
struct
{
uint16_t limit_lo;
uint16_t base_lo;
uint8_t base_hi1;
uint8_t type : 4;
uint8_t system : 1;
uint8_t DPL : 2;
uint8_t present : 1;
uint8_t limit_hi : 4;
uint8_t flags : 4;
uint8_t base_hi2;
};
struct
{
uint32_t low;
uint32_t high;
};
SegmentDesriptor() : low(0), high(0) {}
SegmentDesriptor(uint32_t base, uint32_t limit, uint8_t access, uint8_t _flags)
: low(0), high(0)
{
set_base(base);
set_limit(limit);
high |= ((uint16_t)access) << 8;
flags = _flags;
}
void set_base(uint32_t base)
{
base_lo = base & 0xFFFF;
base_hi1 = (base >> 16) & 0x00FF;
base_hi2 = (base >> 24) & 0x00FF;
}
void set_limit(uint32_t limit)
{
limit_lo = limit & 0xFFFF;
limit_hi = (limit >> 16) & 0x00FF;
}
} __attribute__((packed));
void gdt_initialize();

View File

@@ -0,0 +1,27 @@
#pragma once
#include <stdint.h>
union GateDescriptor
{
struct
{
uint16_t offset_lo;
uint16_t selector;
uint8_t reserved;
uint8_t type : 4;
uint8_t zero : 1;
uint8_t dpl : 2;
uint8_t present : 1;
uint16_t offset_hi;
};
struct
{
uint32_t low;
uint32_t high;
};
} __attribute__((packed));
void idt_initialize();