gdt
Re:gdt
I wrote my GDT setup code in C. It's pretty easy. Just declare a descriptor struct, and your GDT is an array of these. You'll also need a GDTR struct. Remember to turn on packing on all these structures.
Code: Select all
#pragma pack (push, 1) /* align structures to a byte boundary */
/* Segment desciptor definition */
struct descriptor_t
{
uint16_t limit;
uint16_t base_l;
uint8_t base_m;
uint8_t access;
uint8_t attribs;
uint8_t base_h;
};
typedef struct descriptor_t descriptor_t;
struct gdtr_t
{
uint16_t limit;
uint32_t base;
};
typedef struct gdtr_t gdtr_t;
#pragma pack(pop)
Re:gdt
i like to do everything that is written about in the INTEL manuals in pure ASM code like GDT, IDT, etc. other compilers will work but i find it easier to debug problems since ur working in pure ASM. i think compilers should only be used when your Code doesnt deal with actually setting up your system architecture because your never sure of every line of code it generates....i guess i dont trust compilers....
Re:gdt
shad your making it too complicated...its 2x easier if you write it in ASM:
;---constants---
GDTpointer:
GDTlim DW ENDGDT-GDT-1
GDTbase DD 0x500 ;we will be moving GDT to 0x50:0x0
GDT_Selectors: ;used as offset from start of GDT
NULLsel EQU 0x0
CODEsel EQU 0x0008
DATAsel EQU 0x0010
;---gdt---
GDT: ;flat memory model
;NULLsel ;required
DD 0x00
DD 0x00
;CODEsel
DW 0xFFFF
DW 0x00
DB 0x00
DB 0x9A
DB 0xCF
DB 0x00
;DATAsel
DW 0xFFFF
DW 0x00
DB 0x00
DB 0x92
DB 0xCF
DB 0x00
ENDGDT:
there--your done. now work on your IDT--its trickier
;---constants---
GDTpointer:
GDTlim DW ENDGDT-GDT-1
GDTbase DD 0x500 ;we will be moving GDT to 0x50:0x0
GDT_Selectors: ;used as offset from start of GDT
NULLsel EQU 0x0
CODEsel EQU 0x0008
DATAsel EQU 0x0010
;---gdt---
GDT: ;flat memory model
;NULLsel ;required
DD 0x00
DD 0x00
;CODEsel
DW 0xFFFF
DW 0x00
DB 0x00
DB 0x9A
DB 0xCF
DB 0x00
;DATAsel
DW 0xFFFF
DW 0x00
DB 0x00
DB 0x92
DB 0xCF
DB 0x00
ENDGDT:
there--your done. now work on your IDT--its trickier
Re:gdt
No, I think you just don't understand them.i guess i dont trust compilers....
By default, the compiler aligns structure fields on multiples of their size to make things faster. To do this, it adds bytes in between fields as needed.What is this packing thing?
If you declare this:
Code: Select all
struct gdtr_t
{
uint16_t limit;
uint32_t base;
};
Code: Select all
struct gdtr_t
{
uint16_t limit;
uint16_t PADDING;
uint32_t base;
};
Normally this doesn't make any difference, but it does when you need to pass the structures to the hardware. So you need to turn off alignment. In gcc, you can either use a #pragma like I did here, or add __attribute__((packed)) at the end.
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:gdt
slacker: better trust your compiler *gg* It does a lot of work for you the assembler (even nasm) won't, and the people working on compiler stuff do hard and good work.
I trust my compiler. I see the result and the result is a running program just as I expect it. So why not trrusting it? When it says there is an error, it is clear to me, that I have to do debugging. It canna tell all errors - see your string/pointer problem, slacker - but most syntactic and some semantic ones. you canna expact a compiler to recoginze EVERYTHING.
Simply put: Get used to your compiler. It will be a good friend.
I trust my compiler. I see the result and the result is a running program just as I expect it. So why not trrusting it? When it says there is an error, it is clear to me, that I have to do debugging. It canna tell all errors - see your string/pointer problem, slacker - but most syntactic and some semantic ones. you canna expact a compiler to recoginze EVERYTHING.
Simply put: Get used to your compiler. It will be a good friend.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image