From: Robert Plantz <plantz@sonoma.edu>
To: linux-assembly <linux-assembly@vger.kernel.org>
Subject: Re: Segmented or Flat model
Date: Wed, 23 May 2007 22:02:40 -0700 [thread overview]
Message-ID: <1179982961.5536.51.camel@ubuntu> (raw)
In-Reply-To: <BAY133-F13206F74E0BF11906D203CF5340@phx.gbl>
First, Brian provided an excellent response while I was composing this.
Perhaps my comments will add to his.
I believe that Brian Raiter was referring to "real mode" segmented
memory. Memory segments in older x86 architectures were limited to 2^20
bytes. The segmentation registers were used to effectively provide the
higher-order part of the address in order to access more memory. Newer
x86 architectures still have "real mode" for backward compatibility.
The memory segmentation used by Linux is separate from the "real mode"
segmentation. The processor is run in "protected mode" where 2^32 bytes
of memory can be accessed. But memory is still logically divided into
segments. For example there is a "text" segment, which is where the code
exists and is read only. The processor provides hardware that allows
Linux to enforce this "read only" policy and prevent you from, say,
writing self-modifying code.
So in the example you give, the integer named "output" will be the
"data" segment and the movl instruction will be in the "text" segment.
As Brian pointed out, the assembler does not know what addresses these
will be located at. You have to run the linker/loader, ld, which figures
out the address of "output" and fills it into the space left by the
assembler in the movl instruction.
By the way, notice that your program stores the _address_ of the
variable in ebx, not the value stored in the variable. It is logically
equivalent to
leal output, %ebx
If you wanted the value stored there, you would use
movl output, %ebx
If you wanted the address for later use, you might do something like
movl $output, %ebx
movl (%ebx), %ecx
On Wed, 2007-05-23 at 23:01 -0400, A D wrote:
> First of all thanks for your reply.
>
> >I need clarification to a particular gnu assembly question. When i
> >write a code:
> >
> >.section .data
> >output:
> > .int 1
> >
> >.section .text
> >.globl _start
> >_start:
> > movl $output, %ebx
> > ....
> >
> >here what type of memory model is used for movl statement(flat or
> >segmented)?
> >
> >
> >>Brian Raiter wrote:
> >>I suppose that depends on your target platform. Since you sent this to
> >>linux-assembly, I'm going to assume that the answer is "flat". For all
> >>practical purposes, there is no "segmented" memory model on 32-bit
> >>x86 linux.
>
> correct me if i'm wrong. But what I understand are you saying that x86 linux
> doesn't use segmented memory model. Are you sure?(i could be wrong in
> understanding sorry) Because I'm reading the book "Understanding Linux
> Kernel"
> and the author is saying that linux uses segmented memory model. I wasn't
> sure
> whether linux uses seg model by default so i asked the question.
>
> Again thanks.
>
next prev parent reply other threads:[~2007-05-24 5:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-23 22:56 Segmented or Flat model A D
2007-05-24 2:12 ` Brian Raiter
2007-05-24 3:01 ` A D
2007-05-24 4:20 ` Brian Raiter
2007-05-24 5:02 ` Robert Plantz [this message]
2007-05-24 11:48 ` A D
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1179982961.5536.51.camel@ubuntu \
--to=plantz@sonoma.edu \
--cc=linux-assembly@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox