Loadin up the GDT whilst in protected mode.
Loadin up the GDT whilst in protected mode.
hey,
I use grub too boot my kernel, and it sets up protected mode using a tem GDT. so i was wonderin if u cud give me sum help on sum code and abt whether it will work or not. it is in assembly and can be called from C. my assembly is not good so need help. sum of de code is off frotz os
[BTIS 16] ;shud dis be in a protected mode code
segment .text
[global _setupgdt]
gdtr
dw gdt_end - 1
dd gdt
gdt
nullsel equ $-gdt
gdt0
dd 0
dd 0
CodeSel equ $-gdt
dw 0FFFFH
dw 0
db 0
db 09AH
db 0CFH
db 0H
DataSel equ $-gdt
dw 0FFFFH
dw 0H
db 0H
db 092H
db 0CFH
db 0
gdt_end
; Begin Setup GDT
_setupgdt:
push ebp
mov ebp, esp
lgdt [gdtr] ; Load GDT
pop ebp ; Restore Caller's stack frame
ret
; End Setup GDT
I use grub too boot my kernel, and it sets up protected mode using a tem GDT. so i was wonderin if u cud give me sum help on sum code and abt whether it will work or not. it is in assembly and can be called from C. my assembly is not good so need help. sum of de code is off frotz os
[BTIS 16] ;shud dis be in a protected mode code
segment .text
[global _setupgdt]
gdtr
dw gdt_end - 1
dd gdt
gdt
nullsel equ $-gdt
gdt0
dd 0
dd 0
CodeSel equ $-gdt
dw 0FFFFH
dw 0
db 0
db 09AH
db 0CFH
db 0H
DataSel equ $-gdt
dw 0FFFFH
dw 0H
db 0H
db 092H
db 0CFH
db 0
gdt_end
; Begin Setup GDT
_setupgdt:
push ebp
mov ebp, esp
lgdt [gdtr] ; Load GDT
pop ebp ; Restore Caller's stack frame
ret
; End Setup GDT
Re:Loadin up the GDT whilst in protected mode.
Looks like it'll work,....
FrotzOS? Don't you mean FritzOS?
FrotzOS? Don't you mean FritzOS?
Re:Loadin up the GDT whilst in protected mode.
sorry i typed ur OS name wrong, its meant to be FritzOS
is dat all i need to do to set up the GDt or do i need to do more?
is dat all i need to do to set up the GDt or do i need to do more?
Re:Loadin up the GDT whilst in protected mode.
Actually...this is how i'd set up my GDT:
In your C code:
extern void LoadGDT();
in your asm code:
[GLOBAL _LoadGDT]
_LoadGDT:
lgdt [ gdtr ]
ret
and in your C code again:
LoadGDT();
In your C code:
extern void LoadGDT();
in your asm code:
[GLOBAL _LoadGDT]
_LoadGDT:
lgdt [ gdtr ]
ret
and in your C code again:
LoadGDT();
Re:Loadin up the GDT whilst in protected mode.
hi, i tried the above but it doesnt seem to work properly.
is der a mistake in the code or is der even a better way of achievin it?
is der a mistake in the code or is der even a better way of achievin it?
Re:Loadin up the GDT whilst in protected mode.
i also tried puttin the call to the loadgdt function in the assembly file that calls the main kernel file. whilst doin this i get the following linker msg:
loadgdt.o(.text+0x0): relocation truncated to fit : 16 text
wot does that mean
and wots wrong
can u plz help
loadgdt.o(.text+0x0): relocation truncated to fit : 16 text
wot does that mean
and wots wrong
can u plz help
Re:Loadin up the GDT whilst in protected mode.
Strange...worked for me...
If you load your kernel at 1 meg...my GDT does not work for some reason...I don't know why...so I'm making another GDT...that's why you get that linker message...
If you load your kernel at 1 meg...my GDT does not work for some reason...I don't know why...so I'm making another GDT...that's why you get that linker message...
Re:Loadin up the GDT whilst in protected mode.
Unless by some miracle your code is loaded at 0 linear then this "dw gdt_end - 1" is wrong.
Re:Loadin up the GDT whilst in protected mode.
The worst thing that can happen to a OS developer: All The Wrong Code Works on my PC! :'(
Re:Loadin up the GDT whilst in protected mode.
Ok, correction because I feel sorry for Tom .
It's incorrect shall we say, in that it's holding the wrong value. It just so happens that it'll be holding a value that's too big so your gdt will still work, but IMO that doesn't make it any more correct.
It's incorrect shall we say, in that it's holding the wrong value. It just so happens that it'll be holding a value that's too big so your gdt will still work, but IMO that doesn't make it any more correct.
Re:Loadin up the GDT whilst in protected mode.
..
Last edited by Perica on Sun Dec 03, 2006 8:24 pm, edited 1 time in total.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Loadin up the GDT whilst in protected mode.
about GDT change :
thou shalt do a selektor reload afther thou haft changed thee GDT
Remember the shadow registers ... a hidden (not visible to software) register caches the base, limit and descriptor of the segment for every segment register once the segment register has been loaded from the GDT.
So after you changed the GDT you should do something like
to force the CPU to read back the GDT and fill the shadow register with the new values ...
Same thing applies for the code segment: you should do a
just as you did in your pmode setup code ... This will refresh the shadow registers for your code segment.
Remember to do the same with stack or extra segment if needed.
thou shalt do a selektor reload afther thou haft changed thee GDT
Remember the shadow registers ... a hidden (not visible to software) register caches the base, limit and descriptor of the segment for every segment register once the segment register has been loaded from the GDT.
So after you changed the GDT you should do something like
Code: Select all
mov ax,ds
mov ds,ax
Same thing applies for the code segment: you should do a
Code: Select all
jmp CODE_SELECTOR:.here
.here:
Remember to do the same with stack or extra segment if needed.
Re:Loadin up the GDT whilst in protected mode.
FFS Perica is it impossible for you to read the damn manual before you post?Perica Senjak wrote: Hey,
Curufir: Could you please tell me what's wrong with "gdt_end -1"? I have something simmilar to this in my GDT aswell, I want to know what's wrong so i can fix the problem?
"gdt_end -1" is not wrong (At least that's what i think); It Stores the Memory address of gdt_end minus 1, this takes it one spot back (Because gdt_end it not part of the GDT); Therefore is points to the End of the GDT - What's Wrong with it?
I saw somebody put "dw gdt_end - gdt_start - 1", This can't be Correct? - Is it Correct?
Could somebody please explain this.....
Cya.
The GDT register has 2 components.
GDT size in bytes (word)
GDT base address (dword)
Now it should be freakin' obvious that gdt_end-1 is not the size of the GDT unless the gdt starts at 0, it should also be blindingly obvious how to actually get the correct size. The reason it works is that if the GDT size is too big then your selectors will still be valid, whereas if it was too small the processor would fault. Having it too big removes one of the basic protection mechanisms preventing loading of nonexistent selectors. Therefore it is wrong to have it too big.
Re:Loadin up the GDT whilst in protected mode.
Now I really need to read about the GDT more...