I developing kernel for KISSEM operating system. Problem is GRUB2 starts in protected mode and fill gdt table, so I must to reload GDT.
My code is:
1. x86.h
Code: Select all
#pragma pack(push, 0)
struct gdt_entry
{
short int llimit;
short int lbase;
unsigned char mbase;
unsigned char flags1;
unsigned char flags2;
unsigned char hbase;
};
struct gdt_header
{
short int size;
void *ptr;
};
struct git_header
{
short int size;
void *ptr;
};
struct git_entry {
short int addr_lower;
short int sel_number;
unsigned char mesh;
unsigned char flags;
short int addr_higher;
};
#pragma pack(pop)
Code: Select all
struct gdt_header *info;
++init;
info = &gdts_info;
gdts_info.size = 3*8-1;
gdts_info.ptr = gdts;
gdts[1].llimit = 0xFFFF;
gdts[1].lbase = 0;
gdts[1].mbase = 0;
gdts[1].hbase = 0;
gdts[1].flags1= 0b10011110;
gdts[1].flags2= 0xCF;
gdts[2].llimit = 0xFFFF;
gdts[2].lbase = 0;
gdts[2].mbase = 0;
gdts[2].hbase = 0;
gdts[2].flags1= 0b10010010;
gdts[2].flags2= 0xCF;
#if 1
__asm__ __volatile__ (
//"lol:\n"
//"hlt\n"
//"jmp lol\n"
"lgdt %0\n"
"push next\n"
"ret\n"
"ljmp $0x8,$next\n"
"next:\n"
"mov $16, %%eax\n"
"mov %%eax,%%ds\n"
"mov %%eax,%%es\n"
"mov %%eax,%%fs\n"
"mov %%eax,%%gs\n"
"mov %%eax,%%ss\n"
::"m"(*info):"eax","memory");
#endif