Calculating my flags for an idt entry

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
cjhawley001
Member
Member
Posts: 29
Joined: Mon Jun 30, 2008 9:51 am

Calculating my flags for an idt entry

Post 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
User avatar
Tomaka17
Member
Member
Posts: 67
Joined: Thu Oct 02, 2008 8:20 am

Re: Calculating my flags for an idt entry

Post by Tomaka17 »

If you set the DPL to 4, it will be 100, 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
}
MysteriOS
Currently working on: TCP/IP
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Calculating my flags for an idt entry

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
cjhawley001
Member
Member
Posts: 29
Joined: Mon Jun 30, 2008 9:51 am

Re: Calculating my flags for an idt entry

Post by cjhawley001 »

Should I just do some checking to make sure values are legal?

Chris
Post Reply