summaryrefslogtreecommitdiff
path: root/kernel/GDT
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-07-28 14:19:00 +0400
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-07-28 14:19:00 +0400
commite0c565f7ff7620dca9dfc6c607f4798f5291c7bf (patch)
treec18099687db0202e32ae47f4c991b895191f030e /kernel/GDT
parentaac010a9e30e479968e277ebdaf41ad366a77098 (diff)
Go back to C and adapt codeHEADmasterdevelop
Diffstat (limited to 'kernel/GDT')
-rw-r--r--kernel/GDT/Makefile4
-rw-r--r--kernel/GDT/gdt.c50
-rw-r--r--kernel/GDT/gdt.cpp58
-rw-r--r--kernel/GDT/gdt.h37
-rw-r--r--kernel/GDT/gdt.hpp55
5 files changed, 89 insertions, 115 deletions
diff --git a/kernel/GDT/Makefile b/kernel/GDT/Makefile
index 4f5192b..0f08954 100644
--- a/kernel/GDT/Makefile
+++ b/kernel/GDT/Makefile
@@ -4,8 +4,8 @@ EXEC=gdt.o
all:$(EXEC)
#----- GDT -----
-$(EXEC): gdt.cpp
- $(CXX) -c -o $(EXEC) gdt.cpp
+$(EXEC): gdt.c
+ $(CC) $(CFLAGS) -c -o $(EXEC) $^
#---------------
diff --git a/kernel/GDT/gdt.c b/kernel/GDT/gdt.c
new file mode 100644
index 0000000..4aae655
--- /dev/null
+++ b/kernel/GDT/gdt.c
@@ -0,0 +1,50 @@
+#include "gdt.h"
+#include "../Helpers/types.h"
+#include "../Helpers/memory.h"
+
+//Declare global vars
+GdtDescriptorStruct GDT_DESCRIPTORS[4];
+GdtPointerStruct GDT_POINTER;
+
+//Adapt parameter to the gdt descriptor structure
+void gdt_initGdtDesc(u32 base, u32 limit, u8 access, u8 flags, GdtDescriptorStruct *Descriptor){
+ Descriptor->limit1 = limit & 0xFFFF;
+ Descriptor->base1 = base & 0xFFFF;
+ Descriptor->base2 = (base & 0xFF0000) >> 16;
+ Descriptor->access = access;
+ Descriptor->limit2 = (limit & 0xF0000 ) >> 16;
+ Descriptor->flags = flags & 0xFF;
+ Descriptor->base3 = (base & 0xFF000000) >> 24;
+}
+
+//Copy the gdt into mémory and load it
+void gdt_loadGdt(){
+
+ //Init default segment
+ gdt_initGdtDesc(0x0,0x0,0x0,0x0, &GDT_DESCRIPTORS[0]);
+
+ //Init code segment
+ gdt_initGdtDesc(0x0,0xFFFFF,0x9A,0x0D, &GDT_DESCRIPTORS[1]);
+
+ //Init data segment
+ gdt_initGdtDesc(0x0,0xFFFFF,0x92,0x0D, &GDT_DESCRIPTORS[2]);
+
+ //Init stack segment
+ gdt_initGdtDesc(0x00B00000,0x00000500,0x96,0x0D, &GDT_DESCRIPTORS[3]);
+
+
+ //Init GDT Pointer
+ GDT_POINTER.size=4*sizeof(GDT_DESCRIPTORS);
+ GDT_POINTER.segment=0x00007E00;
+
+ //Copy Gdt into memory and init registers
+ memcpy((u32)GDT_DESCRIPTORS, (u32)GDT_POINTER.segment, (u32)GDT_POINTER.size);
+
+ //Load the GDT
+ __asm__("lgdtl (%0);"
+ :
+ :"r"(&GDT_POINTER)
+ );
+}
+
+
diff --git a/kernel/GDT/gdt.cpp b/kernel/GDT/gdt.cpp
deleted file mode 100644
index 8c6d9d9..0000000
--- a/kernel/GDT/gdt.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-#include "gdt.hpp"
-#include "../Helpers/types.hpp"
-#include "../Helpers/memory.hpp"
-
-//Constructor
-Gdt::Gdt(){
-
- //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;
-
-
-}
-
-//Destructor
-Gdt::~Gdt(){
-
-}
-
-//Adapt parameter to the gdt descriptor structure
-void Gdt::initGdtDesc(u32 base, u32 limit, u8 access, u8 flags, gdtDescriptorStruct *Descriptor){
- Descriptor->limit1 = limit & 0xFFFF;
- Descriptor->base1 = base & 0xFFFF;
- Descriptor->base2 = (base & 0xFF0000) >> 16;
- Descriptor->access = access;
- Descriptor->limit2 = (limit & 0xF0000 ) >> 16;
- Descriptor->flags = flags & 0xFF;
- Descriptor->base3 = (base & 0xFF000000) >> 24;
-}
-
-//Copy the gdt into mémory and load it
-void Gdt::loadGdt(){
- //Copy Gdt into memory and init registers
- memcpy((u32)m_Descriptors, (u32)m_Pointer.segment, (u32)m_Pointer.size);
-
- //Put m_Pointer in a var to pass it to assembly code
- int *gdtAdress=(int *)&m_Pointer;
-
- __asm__("lgdtl (%0);"
- :
- :"r"(gdtAdress)
- );
-}
-
-
diff --git a/kernel/GDT/gdt.h b/kernel/GDT/gdt.h
new file mode 100644
index 0000000..86cdaf3
--- /dev/null
+++ b/kernel/GDT/gdt.h
@@ -0,0 +1,37 @@
+#ifndef __GDT__
+#define __GDT__
+
+#include "../Helpers/types.h"
+
+
+//Define GDT pointer
+struct GdtPointerStruct{
+ u16 size;
+ u32 segment;
+} __attribute__ ((packed));
+
+
+//Define GDT descriptor
+struct GdtDescriptorStruct{
+ u16 limit1;
+ u16 base1;
+ u8 base2;
+ u8 access;
+ u8 limit2 : 4;
+ u8 flags : 4;
+ u8 base3;
+} __attribute__ ((packed));
+
+
+//Typedef :
+typedef struct GdtPointerStruct GdtPointerStruct;
+typedef struct GdtDescriptorStruct GdtDescriptorStruct;
+
+
+//Functions :
+void gdt_initGdtDesc(u32 base, u32 limit, u8 access, u8 flags, GdtDescriptorStruct *Descriptor);
+void gdt_loadGdt();
+
+
+
+#endif
diff --git a/kernel/GDT/gdt.hpp b/kernel/GDT/gdt.hpp
deleted file mode 100644
index f6caa3d..0000000
--- a/kernel/GDT/gdt.hpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef __GDT__
-#define __GDT__
-
-#include "../Helpers/types.hpp"
-
-//Define GDT pointer
-struct gdtPointerStruct{
- u16 size;
- u32 segment;
-} __attribute__ ((packed));
-
-//Define GDT descriptor
-struct gdtDescriptorStruct{
- u16 limit1;
- u16 base1;
- u8 base2;
- u8 access;
- u8 limit2 : 4;
- u8 flags : 4;
- u8 base3;
-} __attribute__ ((packed));
-
-//Typedef :
-typedef struct gdtPointerStruct gdtPointerStruct;
-typedef struct gdtDescriptorStruct gdtDescriptorStruct;
-
-
-//Gdt class
-class Gdt{
-
- private:
-
- //Data members
- 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();
-
-};
-
-
-#endif