00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <const.h>
00020
00021 #include <arch/i386.h>
00022 #include <arch/paging.h>
00023
00024 #include <kernel/console.h>
00025 #include <kernel/kernel.h>
00026 #include <kernel/task.h>
00027
00028 #include <arch/mem.h>
00029
00030
00031 volatile gdt_entry_t gdt[GDT_DIM];
00032
00033 static gdt_reg gdt_ptr;
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 word setup_GDT_entry(word limit, dword base, byte attribs0_7, byte attribs8_15)
00045 {
00046
00047 register unsigned short i=1;
00048 dword IF = GET_IF();
00049
00050 disable();
00051 for (; i<GDT_DIM; i++)
00052 {
00053 if (!(gdt[i].limit))
00054 {
00055 gdt[i].limit = limit;
00056 gdt[i].base0_15 = base & 0xFFFF;
00057 gdt[i].base16_23 = (base >> 16) & 0xFF;
00058 gdt[i].base24_31 = (base >> 24) & 0xFF;
00059 gdt[i].attribs0_7 = attribs0_7;
00060 gdt[i].attribs8_15 = attribs8_15;
00061
00062 SET_IF(IF);
00063
00064
00065 return(i * GDT_ENTRY_DIM);
00066 }
00067 }
00068 error("Out of GDT entries!");
00069 return( NULL );
00070 }
00071
00072
00073
00074 void remove_GDT_entry(word sel)
00075 {
00076 dword IF = GET_IF();
00077
00078 disable();
00079
00080 gdt[sel/GDT_ENTRY_DIM].limit = 0;
00081 gdt[sel/GDT_ENTRY_DIM].base0_15 = 0;
00082 gdt[sel/GDT_ENTRY_DIM].base16_23 = 0;
00083 gdt[sel/GDT_ENTRY_DIM].base24_31 = 0;
00084 gdt[sel/GDT_ENTRY_DIM].attribs0_7 = 0;
00085 gdt[sel/GDT_ENTRY_DIM].attribs8_15 = 0;
00086
00087 SET_IF(IF);
00088 }
00089
00090
00091
00092
00093 void install_GDT()
00094 {
00095
00096 memset(&gdt, 0, sizeof(gdt));
00097
00098
00099
00100
00101 setup_GDT_entry(0, 0, 0, 0);
00102
00103 setup_GDT_entry(0xFFFF, 0, DATA_SEG, (ATTR_GRANUL | ATTR_32BIT | 0xF));
00104
00105 setup_GDT_entry(0xFFFF, 0, CODE_SEG, (ATTR_GRANUL | ATTR_32BIT | 0xF));
00106
00107 setup_GDT_entry(0xFFFF, 0, (DATA_SEG | DPL_3), (ATTR_GRANUL | ATTR_32BIT | 0xF));
00108
00109 setup_GDT_entry(0xFFFF, 0, (CODE_SEG | DPL_3), (ATTR_GRANUL | ATTR_32BIT | 0xF));
00110
00111
00112
00113
00114 gdt_ptr.limit = (uint16_t)(GDT_DIM * GDT_ENTRY_DIM - 1);
00115 gdt_ptr.base = (size_t)gdt;
00116
00117
00118 __asm__ __volatile__ ("lgdtl (%0)" : : "r"(&gdt_ptr));
00119
00120
00121 k_update_segment_regs();
00122 }