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

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



Thank u for initiating the discussion.

>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.

I understood that USER_CS is going to be the 5rd entry in GDT.
bcoz the 1st and 2nd entries are not used,  3rd and 4rth entries are used for
KERNEL code and data segments, that is why they are indexed by the locations
0x10 and 0x18.

If we have to give the 5th and 6th entries for user CODE and DATA segments
they should go to the location
0x20 and 0x28.

OK , if there is no restriction on adding the segment descriptors then I agree
that it can take the value 0x23 i.e
equal to 35 and 0x2B equal to 43 bcoz they are maintaining the 8 bytes gap (
no overlap).

But what I did not undertand, nice way to say is "I am  not able to trace out
which part of the kernel has filled the
values at those descriptors".

---
GL



ankur arora wrote:

> 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.

I understood the descriptor strctures.each descriptor takes 8 bytes.

>
>
> 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
>
> ---------------------------------------------
> Find out more about this and other Linux India
> mailing lists at http://lists.linux-india.org/