[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Mismatch of GDT ( Global descriptor table) Entries.



Hello everybody,

[ GDT entries in arch\i386\boot\setup.S ]
>  [snip]
> As each entry takes 8 bytes.Thus filled entries will be at the following
> locations.
> 1st entry will be at offset 0x0h
> 2nd entry will be at offset 0x08h
> 3rd entry will be at offset 0X10h
> 4rth entry will be at offset 0x18h
> 

from include\asm-i386\segment.h
> #define KERNEL_CS 0x10
> #define KERNEL_DS 0x18
> 
> #define USER_CS  0x23
> #define USER_DS  0x2B

> I did not understand how  and where USER_CS and  USER_DS segments are
> getting created in GDT.
> More over these two values are not falling on the border of multiples of
> 8, like our KERNEL_CS and
> KERNEL_DS.

The error you are making in is in understanding the 
format of the segment selectors(basically an index into the GDT). 
Of the 16 bits in a segment selector, the lowermost 2 are the mode.
Linux uses 00 as the Kernel or supervisor mode and 11 as the user 
mode. And the 3rd bit is TI or Table Index which decides whether 
to index the GDT or the LDT.

So when KERNEL_CS is #defined to 0x10 then it means that we 
are indexing the entry 2 in GDT, and #define USER_CS  0x23 talks 
about entry 3 in user mode indexing the GDT.

However there is one thing that I haven't understood for a long time about
all these statically defined entries. And that is why does Linux use just
one entry each for User code and data when it could have allocated each 
process its own entry. The only concievable way to use the current setup
is to dynamically change the GDT whenever we are scheduling another
process. And how would this be done under SMP ?

And personally I've been unable to track down the data structure where
this info is kept to be restored when a process is rescheduled.
Any thoughts ?

regards,
ankur


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com