LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2010, 07:29 PM   #16
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043

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.

jlinkels
 
1 members found this post helpful.
Old 04-16-2010, 04:53 AM   #17
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
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.
 
Old 04-16-2010, 05:38 AM   #18
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by tuxdev View Post
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.)
 
Old 04-16-2010, 06:33 AM   #19
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Sergei Steshenko View Post
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.

Last edited by MTK358; 04-16-2010 at 06:35 AM.
 
Old 04-16-2010, 07:04 AM   #20
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
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.
 
Old 04-16-2010, 01:50 PM   #21
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I found this nice book online — http://en.wikibooks.org/wiki/X86_Assembly/

Anyway, tell me if this is correct:

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?

Is segmentation used by the OS to manage memory?
 
Old 04-16-2010, 02:01 PM   #22
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by MTK358 View Post
Anyway, tell me if this is correct:

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.

Last edited by johnsfine; 04-16-2010 at 02:08 PM.
 
Old 04-16-2010, 02:34 PM   #23
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by johnsfine View Post
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.

Last edited by MTK358; 04-16-2010 at 02:35 PM.
 
Old 04-16-2010, 03:37 PM   #24
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by MTK358 View Post
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 View Post
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 View Post
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?

- Andi -
 
Old 04-16-2010, 03:52 PM   #25
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, again MTK358.

Let's go back to a previous post:
Quote:
* "Protected mode" is the opposite of "Real Mode"

* "Protected mode" uses "virtual memory"...
"Real mode" accesses RAM directly...
...
* "Real Mode" and "Protected mode" are Intel-specific terms...

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

This link might help clarify:
Quote:
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.
'Hope that helps .. PSM

Last edited by paulsm4; 04-16-2010 at 03:59 PM.
 
Old 04-16-2010, 03:53 PM   #26
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by ForzaItalia2006 View Post
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 View Post
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 View Post
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 View Post
Just for interest or do you plan to write some OS/boot code in protected/real mode?
Maybe.

Once I fully understand it
 
Old 04-16-2010, 03:56 PM   #27
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by paulsm4 View Post
And let's also introduce two new terms:

Quote:
* 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?
 
Old 04-16-2010, 04:22 PM   #28
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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 View Post
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.

Last edited by johnsfine; 04-16-2010 at 04:41 PM.
 
Old 04-16-2010, 04:32 PM   #29
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
<never mind >

Last edited by MrCode; 04-16-2010 at 04:36 PM.
 
Old 04-16-2010, 04:53 PM   #30
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by MrCode View Post
<never mind >
WTF?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to write a file in delete protected mode shiv.singh Linux - Newbie 7 05-17-2009 12:59 AM
How to implement memory mapping between protected mode and real mode? me_too Linux - Newbie 0 05-13-2008 01:12 AM
Error in switching from protected mode to real mode in Fedora East Linux - General 0 04-02-2008 02:03 AM
How to patch 0x1c interrupt handler in protected mode john_crichton Programming 2 04-05-2007 04:59 AM
Help with switching to protected mode GDT AT&T assembly!!!! aXoneX Linux - General 0 07-15-2004 09:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration