Loading new GDT ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
amirsadig

Loading new GDT ?

Post by amirsadig »

before I use only data and code segment for the kernel,
but now I would like to make my gdt flexible, so that I can change it during execution. therefore I have write a code which do that. but when I try to load the new gdt a receive CPU Panic from Bochs.
I have attached the source code also.

this struct define the segment descriptor :
struct seg_descriptor {
unsigned short limit1; // 0 - 15
unsigned short base1; // 16 - 31
unsigned char base2; // 0 - 7
unsigned char type_s_dpl_p ;// type : 8 - 11 , S : 12, DPL : 13-14, P:15
unsigned char limit2_avl_O_DB_G; // limit 16 - 19, AVL 20 ,bit 21 : 0, D/B : 22, G: 23
unsigned char base3; // 24 - 31
};

this assembler code that load the gdt register:
load_gdt:???
???; stop using my old GDT, and load new GDT
???
???lgdt [gdt_descs_ptr]
???
???retn

there is an error which I have change it, but still does not work. it was the KERNEL_CODE_SEG it has 0x92 but it should be 0x9A.

[attachment deleted by admin]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Loading new GDT ?

Post by Pype.Clicker »

You should make sure your structure is packed so that it reflects what the CPU expects. try sizeof(struct seg_descriptor)==8. If this is not the case, try to find out how you could tell the compiler to pack the structure so that it works.

(with GCC, this is done with __attribute__((PACKED)) or something alike.
Post Reply