ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Try to get a hold on "operating systems" by Lister. The book is easy reading and explains about every aspect of a modern operating system of terms of task switching, virtual memory, paging etc. http://www.google.com/url?sa=t&sourc...Va2KUOGx66gljQ
It doesn't feel good to see someone asking for help (you!), asking very detailed questions, very fundamental and then start whining over the number of pages a manual consists of. Had you even opened those manuals, then you should have noticed that you can skip entire parts of explanations which are already obvious to you. If that isn't the case: do you expect us to write it all down here for you in nice digestive parts so you can lean back and have the knowledge shoved into your mouth? You do you think we gained that knowledge? Handing out questions on the university campus and asking for answers the next day?
Again, there is a wealth of knowledge out on the internet, the Wikipedia to start with, which gives a thorough and correct explanation of most if not all of the terms you are looking for.
I did look through the whole output, I just did not understand a lot of it. The one thing that caught my attention was the --architecture flag, and it just happened to be near the beginning.
No, you didn't. Because I know for sure (rechecked myself before asking you) that in that whole output there are switches controlling where 'ld' looks for libraries and output format.
Last edited by Sergei Steshenko; 04-16-2010 at 05:04 AM.
Pretty much all of the above. There do exist still some embedded CPUs that don't have an MMU, but it's vanishingly rare.
Vanishingly rare? No.
Here are the numbers I have by summing the entries in an industry standard directory:
Code:
total parts 1195
with MMU 35.48%
no MMU/MPU 63.51%
Partial system 0.25%
MPU only 0.75%
So, by part number at least, unless you think that 63.5% is vanishingly small, and 35.5 (or 36.5) percent is a lot bigger, it is a difficult case to make.
(There are some peculiar corner cases, including one dual core device for which one core has an MMU and the other doesn't, but I've included that in the full implementation because it really doesn't affect the overall conclusion, although you could argue for another approach. And there are some part numbers, primarily for soft core devices, which are available either with or without, depending on which license you buy, but again it doesn't affect the overall outcome to any real extent.)
No, you didn't. Because I know for sure (rechecked myself before asking you) that in that whole output there are switches controlling where 'ld' looks for libraries and output format.
But I don't understand those kinds of things. It seems like you always expect me to magically know everything in advance, and that everyone you're helping already knows what you do. But I don't, I mean why would I be asking you a question if I already knew I was smarter than you at the subject?
But I did look at the whole thing ( at developers for putting --architecture flag in the first page).
I got the Intel manual and it isn't as bad as I thought. I see it also says it will contain some other things I couldn't find the answer to, like floating-point calculations.
But I don't understand those kinds of things. It seems like you always expect me to magically know everything in advance, and that everyone you're helping already knows what you do. But I don't, I mean why would I be asking you a question if I already knew I was smarter than you at the subject?
But I did look at the whole thing ( at developers for putting --architecture flag in the first page).
I got the Intel manual and it isn't as bad as I thought. I see it also says it will contain some other things I couldn't find the answer to, like floating-point calculations.
Lame excuses. As I wrote you before, it is your duty to read, comprehend and analyze the text. The text is structured, i.e. as much as possible the items are described independently. The items you were supposed to pick do not depend (WRT understanding) on other items.
As I wrote you before, the items you had to pick up are described in plain English, without anything related to computer science or math.
The segment registers contain the addresses of separate blocks to be used for the stack, code, and data, and this is so you can access the whole memory even though it cannot all be addressed by the CPU's word size.
Can segmentation be used in a program running under an OS or not, and why?
The segment registers contain the addresses of separate blocks to be used for the stack, code, and data, and this is so you can access the whole memory even though it cannot all be addressed by the CPU's word size.
That is vague enough it could be considered correct or incorrect depending on your point of view.
Quote:
Can segmentation be used in a program running under an OS or not, and why?
Under some OS, yes. Under Linux, I'm pretty sure the answer is almost entirely "no". X86 architecture and even X86_64 architecture require the OS to deal with some odd remnants of the segmented design even if the OS is based on "flat" addressing. But in practical terms, segmentation is not used in Linux.
Quote:
Is segmentation used by the OS to manage memory?
What OS?
If you mean Linux or a recent version of Windows, then no.
Overall, I don't think you're going to learn anything from posted answers to such vague questions about complicated and largely obsolete topics.
There are some good web pages you could read about Linux memory management and how it uses the page table system of X86 and X86_64 architecture (try google, I don't have URLs handy). If you really want to understand more obscure topics such as segmentation, first learn enough asm that you can even grasp the concepts, then read it in the Intel processor documents. Generalized answers in a forum to bad questions aren't really going to teach you anything.
That is vague enough it could be considered correct or incorrect depending on your point of view.
Well, I don't know.
Quote:
If you mean Linux or a recent version of Windows, then no.
So modern OSes do not use segmentation whatsoever, right?
And is it right that other CPUs like ARM and PowerPC don't have segmentation?
And does this mean that segmentation can be completely ignored for all practical purposes?
Quote:
There are some good web pages you could read about Linux memory management and how it uses the page table system of X86 and X86_64 architecture (try google, I don't have URLs handy). If you really want to understand more obscure topics such as segmentation, first learn enough asm that you can even grasp the concepts, then read it in the Intel processor documents. Generalized answers in a forum to bad questions aren't really going to teach you anything.
I guess I will do a few searches later, not quite sure what to look for, though.
So modern OSes do not use segmentation whatsoever, right?
Yes and no :-) For reasons of backward compatibility for example, each x86(_64) CPU starts in real mode using the segmented memeory address (segment addressffset in segment). Though, when Linux is "called" by the boot loader, it also starts in real mode up to the point where it switches to protected mode. I once read about Linux that it only uses segmentation where really imposed by the architecture, so just as minimal as possible.
Quote:
Originally Posted by MTK358
And is it right that other CPUs like ARM and PowerPC don't have segmentation?
I don't know :-) I would have to search for this ...
Quote:
Originally Posted by MTK358
And does this mean that segmentation can be completely ignored for all practical purposes?
Just like above, some parts must be done in segmentation mode. E.g. switching to protected mode ;-)
Quote:
I guess I will do a few searches later, not quite sure what to look for, though.
Just tried from a different point-of-view ... Why do you want to know so many details about the protected mode? Just for interest or do you plan to write some OS/boot code in protected/real mode?
* Segmentation" is largely an artifact of "real mode": you can safely consider it an "anachronism" in assembly programming.
* "Pages" are an artifact of virtual memory ("protected mode")...
And let's also introduce two new terms:
Quote:
* Segmented addressing
... and ...
* Linear addressing
DOS used to run in "real mode" and used "segmented addressing".
Linux runs in "protected mode" and uses "linear addressing".
There's no "magic" or "mystery" with segment registers: it's just a base address (the address in the segment register) plus an offset. Segment registers were there on 8088 CPUs in DOS; they're still there on Pentium CPUs in Windows or Linux.
But you're correct: with linear addresses, you don't need to worry about them. The 32-bit "offset" *is* the whole address.
Q: So I decided to teach myself assembly language. I know on a very basic level how this stuff works, but I have never programmed so close to the hardware and I thought that I should definitely know this stuff. I was playing around with different registers and general syntactical stuff and I have realized that my program will not compile if I attempt to change the value of any segment register. Every article that I have found says that I can indeed change the value of at least 4 segment registers, so what gives?
A: In protected-mode (Win32), segment registers are not used any more.
Memory model is also drastically different from the old days of the 16-bit world. Under Win32, we need not be concerned with memory model or segment anymore! There's only one memory model: Flat memory model. There's no more 64K segments. The memory is a large continuous space of 4 GB. That also means you don't have to play with segment registers. You can use any segment register to address any point in the memory space. That's a GREAT help to programmers. This is what makes Win32 assembly programming as easy as C.
Yes and no :-) For reasons of backward compatibility for example, each x86(_64) CPU starts in real mode using the segmented memeory address (segment addressffset in segment). Though, when Linux is "called" by the boot loader, it also starts in real mode up to the point where it switches to protected mode. I once read about Linux that it only uses segmentation where really imposed by the architecture, so just as minimal as possible.
OK.
Quote:
Originally Posted by ForzaItalia2006
I don't know :-) I would have to search for this ...
I don't know either, I guess I will Google it.
Quote:
Originally Posted by ForzaItalia2006
Just like above, some parts must be done in segmentation mode. E.g. switching to protected mode ;-)
But once your boot code switches to protected mode, you can forget about segmentation, right?
Quote:
Originally Posted by ForzaItalia2006
Just for interest or do you plan to write some OS/boot code in protected/real mode?
* Segmented addressing
... and ...
* Linear addressing
And?
So linear addressing is when the program accesses memory by it's address, and segmented addressing is when a program accesses stack memory relative to the stack segment, code relative to the code segment, etc., right?
First, I would have selected the term "flat addressing" rather than "linear addressing" for the contrast to "segmented", that paulsm4 made.
Second, you're still giving simplistic enough descriptions that they are too ambiguous to be right or wrong:
Quote:
Originally Posted by MTK358
So linear addressing is when the program accesses memory by it's address, and segmented addressing is when a program accesses stack memory relative to the stack segment, code relative to the code segment, etc., right?
When talking about the inner details of addressing systems, to act like there is a fundamental meaning of the word address as you did above interferes with understanding.
Quick (I hope) detour in the basics of 386 32 bit protected mode addressing addressing:
You have a segmented address consisting of a 16 bit segment selector and a 32 bit offset.
The CPU uses the 16 bit segment selector for a table lookup to get various info to combine with the 32 bit offset to compute a 32 bit linear address.
The CPU uses page tables (same as non PAE 32 bit X86 Linux now uses) to translate the 32 bit linear address to a 32 bit physical address.
The memory controller translates the 32 bit physical address into a set of select and strobe and internal address signals to get to an actual chunk of ram.
Now contrast that with "flat addressing". The program uses a 32 bit (for X86) or 64 bit (for X86_64) address, which acts like the linear address described above and gets translated as above to a physical address and then translated again by the memory controller.
In 32 bit X86 flat addressing designs, the CPU design won't let you turn off the translation from segmented address to linear address (without losing the rest of 32 bit protected mode and just having "real" mode). So instead the OS programs the tables used by segmented addressing so that the linear address after that first translation will equal the offset part of the address before the translation.
In X86_64, almost all of the X86 segmented design is disabled by the CPU, so the 64 bit offset is unavoidably the same as the 64 bit linear address, and the bottom 48 bits of that linear address are translated by the CPU using the page tables into a physical address.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.