Loading a descriptor in C (PM)

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
PomeX

Loading a descriptor in C (PM)

Post by PomeX »

Umm... this could be stupid, but here it goes:
I've already managed to get the bootstrap and the loader working, and I'm writing the kernel in C now. I loaded the IDT and a basic GDT with 3 descriptors (a null descriptor, a code desc and a data/stack code - I' m using the Flat Mode) in the loader(asm), and I have a gdt pointer in the kernel code (the address of this pointer is obtained during compilation with another program) that looks like this:

Code: Select all

dword _gdt;
My goal is to develop Hardware Task Switching, so I also created a TSS struct. I'm thinking in just 3 task right now. This means something like:

Code: Select all

struct TSS mytss[3];
Ok, now I want to add a new descriptor for each tss, and my question is... How do I get the linear address of the begining of each Tss? That's it, I think that I can't just write:

Code: Select all

((tssdesc*)_gdt + 0x03)->base = &mytss[0];
right? (Of course, the tssdesc struct is not like I 've shown, that was just a simple example). I mean, &mytss[ 0 ] isn 't just an offset? How do I get the linear address under Protected mode? (I have switched to PM in the Loader, asm code)
(Sorry for my bad english, and if the question is too stupid - I'm new at this)
Dreamsmith

Re:Loading a descriptor in C (PM)

Post by Dreamsmith »

The unary & operative gives you the address of an object. The fact that you're in protected mode doesn't alter this any. Your example looks fine to me (save for the fact that for forum messed up the formatting a bit). As another example:

((tssdesc *)_gdt)[4]->base = &mytss[1];

Nothing wrong with that...
Post Reply