How to load a GDT in C
How to load a GDT in C
I have entered pmode and want to reload the gdt. I have created a GDT in a assembly file and want to call it from my C file. How would I do this.
Re:How to load a GDT in C
hi,
there is no function in C which can load the GDT, you may use inline asssemly or your Assemply ;
normaly this code will load the GDT;
suppse that gtd begin at 0xXXXXXX then with assemly :
lgdt 0xXXXXXX ;
will load it
there is no function in C which can load the GDT, you may use inline asssemly or your Assemply ;
normaly this code will load the GDT;
suppse that gtd begin at 0xXXXXXX then with assemly :
lgdt 0xXXXXXX ;
will load it
Re:How to load a GDT in C
Even if you don't know assembly it would still be much easier to have an assembly stub linked to the kernel which loads the GDT and IDT then jumps to C code
This is what I've done and many others have too
This is what I've done and many others have too
Re:How to load a GDT in C
Well, what I know it is a bit more trickier than that...amirsadig wrote: hi,
there is no function in C which can load the GDT, you may use inline asssemly or your Assemply ;
normaly this code will load the GDT;
suppse that gtd begin at 0xXXXXXX then with assemly :
lgdt 0xXXXXXX ;
will load it
The parameter following the lgdt command is not the beginning of the GDT, it is the place (in real address = 32-bit non-segment-based address) where the GDT register is.
So to load the GDT, use this command:
Code: Select all
Lgdt [GlobalDescriptorTableRegister]
Code: Select all
GlobalDescriptorTableRegister
dw???GlobalDescriptorTableEnding - GlobalDescriptorTableBeginning - 1
dd???GlobalDescriptorTableBeginning
Re:How to load a GDT in C
Ok, so I just going to reload it in my assembly stub that is linked with my kernel.
I have one question though. When the time comes and I want to task-switch, How will I do it? Considering If I wanted to have it done in C.
I have one question though. When the time comes and I want to task-switch, How will I do it? Considering If I wanted to have it done in C.
Re:How to load a GDT in C
Hello!
Normally Multitasking is done with TSS (Task State Segment). This is a Processor-Structure (like the gdt is one). Every Process or Task (nearly the same) has such a structure. And every TSS as although an entry in the GDT with points to the TSS. If you want to make a taskswitch you simply jump to the GDT-Entry. For example if you have three entries Null-Descriptor, kernel-code-descriptor and your TSS-Descriptor in that order you can do the following jump in asm:
[tt]jmp (2*8):0x0000[/tt]
The offset is ignored so you can use every offset. The selector is the "normal" GDT index (starting with zero and multiplicated with 8)
Normally Multitasking is done with TSS (Task State Segment). This is a Processor-Structure (like the gdt is one). Every Process or Task (nearly the same) has such a structure. And every TSS as although an entry in the GDT with points to the TSS. If you want to make a taskswitch you simply jump to the GDT-Entry. For example if you have three entries Null-Descriptor, kernel-code-descriptor and your TSS-Descriptor in that order you can do the following jump in asm:
[tt]jmp (2*8):0x0000[/tt]
The offset is ignored so you can use every offset. The selector is the "normal" GDT index (starting with zero and multiplicated with 8)