summaryrefslogtreecommitdiff
path: root/kernel/gdt.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-09 14:26:20 +0200
committerMiguel <m.i@gmx.at>2018-09-09 14:26:20 +0200
commit9a4b35fd5a32490f8f15b48f978e7b1fbfdceb2a (patch)
treeaf39516afa68237379c30bb67aad1136ccabb2f3 /kernel/gdt.c
parentc2ef64149849fcae608b1c6010303eca86229d22 (diff)
gdt cleanup, reorder info collection to start
Diffstat (limited to 'kernel/gdt.c')
-rw-r--r--kernel/gdt.c71
1 files changed, 57 insertions, 14 deletions
diff --git a/kernel/gdt.c b/kernel/gdt.c
index f72f1ab..24b52f7 100644
--- a/kernel/gdt.c
+++ b/kernel/gdt.c
@@ -1,4 +1,3 @@
-// http://wiki.osdev.org/GDT_Tutorial
#include "kernel.h"
#include "gdt.h"
#include "asm_gdt.h"
@@ -8,28 +7,69 @@
#define GDT_SIZE 6
-//https://wiki.osdev.org/Task_State_Segment
-//Define the TSS as a global structure, boah TODO: move to own page?
+static uint8_t gdt_structs[GDT_SIZE*8*SMP_MAX_PROC]; // GLOBAL DESCRIPTOR TABLES
+
+typedef volatile struct strtss{
+ unsigned short link;
+ unsigned short link_h;
+ unsigned long esp0;
+ unsigned short ss0;
+ unsigned short ss0_h;
+ unsigned long esp1;
+ unsigned short ss1;
+ unsigned short ss1_h;
+ unsigned long esp2;
+ unsigned short ss2;
+ unsigned short ss2_h;
+ unsigned long cr3;
+ unsigned long eip;
+ unsigned long eflags;
+ unsigned long eax;
+ unsigned long ecx;
+ unsigned long edx;
+ unsigned long ebx;
+ unsigned long esp;
+ unsigned long ebp;
+ unsigned long esi;
+ unsigned long edi;
+ unsigned short es;
+ unsigned short es_h;
+ unsigned short cs;
+ unsigned short cs_h;
+ unsigned short ss;
+ unsigned short ss_h;
+ unsigned short ds;
+ unsigned short ds_h;
+ unsigned short fs;
+ unsigned short fs_h;
+ unsigned short gs;
+ unsigned short gs_h;
+ unsigned short ldt;
+ unsigned short ldt_h;
+ unsigned short trap;
+ unsigned short iomap;
+}__attribute__((packed)) tss_struct;
+
tss_struct sys_tss[SMP_MAX_PROC];
+typedef struct GDT_struct
+{
+ uint32_t base;
+ uint32_t limit;
+ uint32_t type;
+}GDT;
+
void install_tss(uint32_t cpu,uint32_t esp0){
// now fill each value
// set values necessary
sys_tss[cpu].ss0 = 0x10; //kernel data
sys_tss[cpu].esp0 = esp0;
-
// now set the IO bitmap (not necessary, so set above limit)
// sys_tss.iomap = ( unsigned short ) sizeof( tss_struct );
}
-typedef struct GDT_struct
-{
- uint32_t base;
- uint32_t limit;
- uint32_t type;
-}GDT;
-
+/*
//alternative
struct gdt_entry_bits
{
@@ -51,6 +91,7 @@ struct gdt_entry_bits
unsigned int gran :1; //1 to use 4k page addressing, 0 for byte addressing
unsigned int base_high :8;
} __packed; //or __attribute__((packed))
+*/
void setup_gdt(uint8_t *gdt_struct)
{
@@ -105,6 +146,8 @@ void gdt_init()
{
static int last_cpu=0;
+ if(last_cpu>=SMP_MAX_PROC)kpanic("not enough SMP_MAX_PROC");
+
/*
Pr=1 Privl 1 Exec DC RW Ac
0x9A == 1001 1010 == 1 00 1 1 0 1 0
@@ -113,8 +156,9 @@ void gdt_init()
0xF2 == 1111 0010 == 1 11 1 0 0 1 0
*/
-//static uint8_t gdt_struct[GDT_SIZE*8]; // GLOBAL DESCRIPTOR TABLE
- uint8_t *gdt_struct=kballoc(1); //[GDT_SIZE*8]; // GLOBAL DESCRIPTOR TABLE
+ //static uint8_t gdt_struct[GDT_SIZE*8]; // GLOBAL DESCRIPTOR TABLE
+ //uint8_t *gdt_struct=kballoc(1); //[GDT_SIZE*8]; // GLOBAL DESCRIPTOR TABLE
+ uint8_t *gdt_struct=&gdt_structs[GDT_SIZE*8*last_cpu];
GDT myGDT[GDT_SIZE];
//selector 0x0
@@ -156,6 +200,5 @@ void gdt_init()
last_cpu++;
setup_gdt(gdt_struct);
-
}