From c6bdd600d790cdf690f4a2674175633210029963 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Tue, 21 Jul 2015 12:19:25 +0400 Subject: [PATCH] Implement Gdt constructor --- kernel/GDT/gdt.cpp | 30 +++++++++++++++++++++--------- kernel/GDT/gdt.hpp | 22 +++++++++++----------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/kernel/GDT/gdt.cpp b/kernel/GDT/gdt.cpp index 00a7025..4e2c28c 100644 --- a/kernel/GDT/gdt.cpp +++ b/kernel/GDT/gdt.cpp @@ -3,17 +3,29 @@ Gdt::Gdt(){ - //Init desc 1 (0 conventional) - //Init desc 2 (code segment) - //Init desc 3 (data segment) - //Init desc 4 (stack segment) - - + + //Init conventional segment + this->initGdtDesc(0x0,0x0,0x0,0x0, &m_Descriptors[0]); + + //Init code segment + this->initGdtDesc(0x0,0xFFFFF,0x9A,0x0D, &m_Descriptors[1]); + + //Init data segment + this->initGdtDesc(0x0,0xFFFFF,0x92,0x0D, &m_Descriptors[2]); + + //Init stack segment + this->initGdtDesc(0x00B00000,0x00000500,0x96,0x0D, &m_Descriptors[3]); + + + //Init GDT Pointer + this->m_Pointer.size=4*sizeof(this->m_Descriptors); + this->m_Pointer.segment=0x00007E00; + } Gdt::~Gdt(){ - + } void Gdt::initGdtDesc(u32 base, u32 limit, u8 access, u8 flags, gdtDescriptorStruct *Descriptor){ @@ -23,11 +35,11 @@ void Gdt::initGdtDesc(u32 base, u32 limit, u8 access, u8 flags, gdtDescriptorStr Descriptor->access = access; Descriptor->limit2 = (limit & 0xF0000 ) >> 16; Descriptor->flags = flags & 0xFF; - Descriptor->base3 = (base & 0xFF000000) >> 24; + Descriptor->base3 = (base & 0xFF000000) >> 24; } void Gdt::loadGdt(){ - //Copy Gdt into memory + //Copy Gdt into memory and init registers } diff --git a/kernel/GDT/gdt.hpp b/kernel/GDT/gdt.hpp index d830e3f..f6caa3d 100644 --- a/kernel/GDT/gdt.hpp +++ b/kernel/GDT/gdt.hpp @@ -14,7 +14,7 @@ struct gdtDescriptorStruct{ u16 limit1; u16 base1; u8 base2; - u8 access : 4; + u8 access; u8 limit2 : 4; u8 flags : 4; u8 base3; @@ -25,30 +25,30 @@ typedef struct gdtPointerStruct gdtPointerStruct; typedef struct gdtDescriptorStruct gdtDescriptorStruct; -//Gdt class +//Gdt class class Gdt{ - + private: - + //Data members - gdtDescriptorStruct m_Descriptor[4]; + gdtDescriptorStruct m_Descriptors[4]; gdtPointerStruct m_Pointer; - + //Methods void initGdtDesc(u32 base, u32 limit, u8 access, u8 flags, gdtDescriptorStruct *Descriptor); - + public: - + //Constructor Gdt(); - + //Destructor ~Gdt(); - + //Methods void loadGdt(); - + };