Need help understanding memory models, cpu modes and address translation
Vaibhav Jain
vjoss197 at gmail.com
Sun Jul 17 02:24:06 EDT 2011
Thanks a lot Joel! This is a great explanation.
Just one more question. I used to think that the compiler always
assigns/generates starting from 0 as Mulyadi has also mentioned.
In the case when Segmentation(intel-style) is being used how does the
compiler assigns
addresses?
Thanks
Vaibhav Jain
On Sat, Jul 16, 2011 at 11:13 PM, Joel A Fernandes <agnel.joel at gmail.com>wrote:
> On Sat, Jul 16, 2011 at 3:47 PM, Vaibhav Jain <vjoss197 at gmail.com> wrote:
> > Hi Mulyadi,
> >
> > Thanks for the explanation.Its really nice! But
> > what I was referring to the was this article on virtual address layout of
> > program :
> >
> > http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory
> >
> > which mentions : "The distinct bands in the address space correspond to
> > memory segments like the heap, stack, and so on. Keep in mind these
> segments
> > are simply a range of memory addresses and have nothing to do with
> > Intel-style segments."
> >
> > This gave rise to all the confusion.I used to think that code, stack and
> > heap segments in the virtual address layout of a program
> > are the same as the segments which we talk about when referring to
> hardware
> > provided Segmentation. But seems like this is not the case.
>
> Segmentation and the virtual address layout are independent of each
> other so you shouldn't confuse the two. You can choose to have
> segmentation and then virtual addressing.
>
> The way it works is:
>
> logical address (segmented) -> virtual address -> physical address
>
> The logical to virtual conversion is called segmentation, and virtual
> to physical is called paging. The Software always uses logical
> addresses.
>
> The article explains "heap", "stack" etc are segments created by the
> operating system and have nothing to do with traditional Intel-style
> "segments". Infact the hardware would not be even aware of the
> presence of the heap. The HW only knows virtual addresses.
>
> > I also read a little about real and protected mode and came to know that
> in
> > 32-bit protected mode all the Segment registers point to the same address
>
> It happens so that Linux sets up the processor tables in such a way
> that the logical addresses map to the same as virtual addresses. IIRC,
> For x86 there's a "Global Descriptor table" that Linux manipulates to
> produce this one-to-one mapping.
>
> > This confused me even more. So I need an explanation of how all these
> work
> > together. I am Sorry if the question is
> > not clear or if it sounds confusing.
>
> Hope this clears it, do read the introduction chapters of
> Understanding the Linux Kernel which touches on a lot of these topics.
> Feel free to ask more questions.
>
> Thanks,
> Joel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110716/e457be82/attachment-0001.html
More information about the Kernelnewbies
mailing list