Page 1 of 1
Calculating my flags for an idt entry
Posted: Wed Jan 28, 2009 9:11 pm
by cjhawley001
I have this code in place to get the flags for an IDT entry:
Code: Select all
idt[num].flags = (TYPE_ATTRIB | (dpl << DPL_SHIFT) | gate_type);
It works when my values for TYPE_ATTRIB = 0x80, dpl = 0x0 and gate_type = 0xE
But it also works if i change my dpl outside of the 0-3 zone.
Is my formula to get my flag right?
I have looked at tutorials but they all just have pre defined flags...
Chris
Re: Calculating my flags for an idt entry
Posted: Thu Jan 29, 2009 1:47 am
by Tomaka17
If you set the DPL to 4, it will be 1
00, the 1 being thus considered as something else in the entry
I recommend using a structure with a variable for each bit
This is mine:
Code: Select all
typedef struct IDTEntry {
u16 loffset;
u16 segment;
int notsetA:1; // always set to 0
int trap:1; // if 0, there will be an automatic "cli" on interrupt
int setA:1; // always set to 1
int setB:1; // always set to 1
int bits32:1;
int notsetB:1; // always set to 0
int dpl:2;
int present:1;
u16 hoffset;
} __attribute__((packed)) IDTEntry;
Note that this is only for 32 bits
You can certainly improve this structure with like:
Code: Select all
struct {
...
#ifdef _64BITS_
u32 hhoffset;
#endif
}
Re: Calculating my flags for an idt entry
Posted: Thu Jan 29, 2009 7:48 am
by neon
I recommend using a structure with a variable for each bit
Please take note that the format of bit fields are undefined by the standard. This is my primary argument against using them.
Re: Calculating my flags for an idt entry
Posted: Thu Jan 29, 2009 1:17 pm
by cjhawley001
Should I just do some checking to make sure values are legal?
Chris