aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86_64/arch.c5
-rw-r--r--core/gdt.c11
-rw-r--r--include/garmos/arch.h7
3 files changed, 17 insertions, 6 deletions
diff --git a/arch/x86_64/arch.c b/arch/x86_64/arch.c
index 0479a52..d7762c2 100644
--- a/arch/x86_64/arch.c
+++ b/arch/x86_64/arch.c
@@ -74,3 +74,8 @@ void regset32(const uint32_t reg, const uint32_t val)
volatile uint32_t *p = (volatile uint32_t *) reg;
*p = val;
}
+
+void gdtset(struct gdtp gdtp)
+{
+ asm volatile("lgdt %0" : : "m" (gdtp));
+}
diff --git a/core/gdt.c b/core/gdt.c
index 819262e..708e2c5 100644
--- a/core/gdt.c
+++ b/core/gdt.c
@@ -12,7 +12,9 @@
* more details.
*/
+#include <garmos/arch.h>
#include <garmos/gdt.h>
+#include <garmos/kernel.h>
#include <garmos/types.h>
struct gdt_sgmt {
@@ -33,11 +35,6 @@ enum gdt_sgmts {
struct gdt_sgmt gdt[GDT_SGMT_COUNT];
-struct gdtp {
- uint16_t limit;
- void *pointer;
-} __attribute__((packed));
-
struct gdtp gdtp = {
.limit = GDT_SGMT_COUNT * sizeof(*gdt) - 1,
.pointer = gdt,
@@ -69,9 +66,11 @@ static void gdt_sgmt_set(uint32_t base, uint32_t limit, uint8_t access,
void gdt_init(void)
{
+ ker_dbg("Initializing GDT ...");
+
gdt_sgmt_set(0, 0, 0, &gdt[GDT_SGMT_NULL]);
gdt_sgmt_set(0, 64 * 1024 * 1024, 0x9A, &gdt[GDT_SGMT_CODE]);
gdt_sgmt_set(0, 64 * 1024 * 1024, 0x92, &gdt[GDT_SGMT_NULL]);
- asm volatile("lgdt %0" : : "m" (gdtp));
+ gdtset(gdtp);
}
diff --git a/include/garmos/arch.h b/include/garmos/arch.h
index 0cee4c2..6d0f54d 100644
--- a/include/garmos/arch.h
+++ b/include/garmos/arch.h
@@ -37,4 +37,11 @@ void regset8(const uint32_t reg, const uint8_t val);
void regset16(const uint32_t reg, const uint16_t val);
void regset32(const uint32_t reg, const uint32_t val);
+/* global description table initialization */
+struct gdtp {
+ uint16_t limit;
+ void *pointer;
+} __attribute__((packed));
+void gdtset(struct gdtp gdtp);
+
#endif