* Segmented or Flat model
@ 2007-05-23 22:56 A D
2007-05-24 2:12 ` Brian Raiter
0 siblings, 1 reply; 6+ messages in thread
From: A D @ 2007-05-23 22:56 UTC (permalink / raw)
To: linux-assembly
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)?
Also how does movl knows which logical address to use? I mean how do
variables
get their logical address?
Thanks.
_________________________________________________________________
Fight Allergies With Live Search
http://search.live.com/results.aspx?q=Remedies+For+Spring+Allergies&mkt=en-ca&FORM=SERNEP
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Segmented or Flat model
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
0 siblings, 1 reply; 6+ messages in thread
From: Brian Raiter @ 2007-05-24 2:12 UTC (permalink / raw)
To: linux-assembly
> 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)?
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.
> Also how does movl knows which logical address to use? I mean how do
> variables get their logical address?
The linker is generally responsible for assigning actual addresses.
(The assembler can't do this because it doesn't know what other object
files will go into the final executable.)
b
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Segmented or Flat model
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
0 siblings, 2 replies; 6+ messages in thread
From: A D @ 2007-05-24 3:01 UTC (permalink / raw)
To: breadbox, linux-assembly
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.
_________________________________________________________________
Windows Live Hotmail. Now with better security, storage and features.
www.newhotmail.ca?icid=WLHMENCA149
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Segmented or Flat model
2007-05-24 3:01 ` A D
@ 2007-05-24 4:20 ` Brian Raiter
2007-05-24 5:02 ` Robert Plantz
1 sibling, 0 replies; 6+ messages in thread
From: Brian Raiter @ 2007-05-24 4:20 UTC (permalink / raw)
To: A D; +Cc: linux-assembly
>>> 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.
Well, note that I did say, "for all practical purposes".
Linux does have selectors, of course, but you hardly ever think about
them. A process under 32-bit Linux can access a maximum of 4GB, so
there is basically only one memory segment, and it contains
everything. And that's basically the definitely of a flat memory
model. (This is still a simplification -- there are actually four
selectors, but they all map to the same address space.)
Linux instead uses the memory paging mechanism to control access. Thus
for example, most executables are loaded to the same virtual memory
address (namely 0x08048000), and it's the kernel's job to map each
process's physical memory to the correct virtual address while that
process is running.
> Because I'm reading the book "Understanding Linux Kernel" and the
> author is saying that linux uses segmented memory model.
Well, if you're talking about kernel programming, that's a slightly
different context. In that case, I would say that yes, Linux does have
segments, but it doesn't really do much with them beyond setting up
the global selector table during bootup, and a bit when switching
between kernel-mode and user-land. From the perspective of an
application programmer, however, Linux memory model is definitely
flat.
b
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Segmented or Flat model
2007-05-24 3:01 ` A D
2007-05-24 4:20 ` Brian Raiter
@ 2007-05-24 5:02 ` Robert Plantz
2007-05-24 11:48 ` A D
1 sibling, 1 reply; 6+ messages in thread
From: Robert Plantz @ 2007-05-24 5:02 UTC (permalink / raw)
To: linux-assembly
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.
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Segmented or Flat model
2007-05-24 5:02 ` Robert Plantz
@ 2007-05-24 11:48 ` A D
0 siblings, 0 replies; 6+ messages in thread
From: A D @ 2007-05-24 11:48 UTC (permalink / raw)
To: linux-assembly
Thank you to you all for explaining the internals of assembly language.
I appreciate it.
_________________________________________________________________
Windows Live Hotmail gives you the control you need to help you keep your
e-mail private, safe and secure. See for yourself!
www.newhotmail.ca?icid=WLHMENCA147
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-05-24 11:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2007-05-24 11:48 ` A D
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox