Re: doubt in protected mode



OS wrote:
Hi all,

Hi Dharma - if you're using "OS" as a handle, what's your OS called, "OSOS"??? :)

SpooK has given you a pretty good answer to this, but I'll try a slightly different "approach"...

I have doubt about the memory manager.

Memory manager??? If you're doing what I think, the "memory manager" is up to you!

When i compile any asm
program,

As SpooK points out, "compile" is a dirty word to some people. If there's a linker involved, it's more than "assemble" that's happening. I like "build" as a fairly neutral word...

it generates
the map file

Is the map file coming from the assembler or the linker? Usually, it's the linker's job, I think. Nasm's "-f bin" mode will generate a map file, too, though... It might be helpful if you'd specify which tools you're using, since they differ quite a bit. (normally we'd want to know "what OS?", too, but I assume that's "in progress")

which will contain information about the code segment
,data segment.

While the segmented memory addressing scheme is "real" (who'd make up something so ugly?), "code segment" and "data segment" is somewhat of an "abstraction", known only to the assembler/linker - at the "machine level" it's all just bytes.

There's a subtle distinction you'll need to understand between "16/32-bit code", and having the CPU in "16/32-bit mode". The former is what you tell the assembler to do. The latter is determined by a bit in the cs descriptor. You want 'em to match!!!

when i execute
the program, it will copy the code and data to some location in memory

Right. But the copy routine doesn't know or care if it's code or data, or what "bitness" it is - it's "just bytes". The copy knows "from where, to where, how many?" ("from" or "to" may be reachable - easily - only in pmode...)

. Now iam jumping to protected mode .

Okay. Let's ASSume you mean 32-bit protected mode. 16-bit protected mode exists - you'll want to switch to 16-bit pmode before switching back to rmode, if you want to do that. Otherwise you can probably ignore it.

1) if the base address for code and data segment is zero and paging is
disabled , which part of memory will the code and data will be copied

Since you say "base", I assume you *do* know how pmode selectors work - if not, SpooK has straightened you out. It'll copy from/to where you say - if the "base" is zero, from offset to offset (probably esi to edi). But... big *BUT*... is your a20 gate enabled? If not, memory intended to access odd megabyte addresses will access even megabytes. This will screw you up!!! May not be an issue... yet.

If paging is not enabled, a "logical" or "linear" address is the same as the "physical" address - segreg * 16 + offset in rmode, segreg.base + offset in pmode - big difference!

2) will the content of the data segment in the real mode, copied to the
data segment in the
protected or how to know whether the content of code and data segment
belongs to real or
protected mode,

What mode is the CPU in when it encounters it?

If you've told the assembler "bits 16" (or per your assembler's syntax), it isn't going to change to 32-bit code by copying it someplace else. Data is less fussy.

3) which part of code segment and data segment will be copied in real
mode and
which part of code and data segment will be copied to protected
mode ? when i executed a
asm program

What mode is the CPU in when it executes this copy? What mode is it in when it executes the code you've copied? What "bitness" was the code? That's what counts.

Please help me in this regards, since it is very much important,

Yup!!!

i
tried myself a lot to understand but i didnt find the solution

10 RTFM
20 experiment
30 ask
40 goto 10

You'll probably have to loop for a while before you "get" it all. No single part is that "hard", but there's a lot of it...

Best,
Frank
.



Relevant Pages

  • Phew!
    ... I've a fair amount of programming experience, so I already had some basic concepts under my belt. ... I'm in the process of converting a little calendar program I wrote for CLISP over to assembler using nasm - the main problem being that one has nothing to work with. ... I then write a wrapper test function which plugs in some values, calls the routines, and fills out the results to a data segment. ...
    (comp.lang.asm.x86)
  • Re: delete "0D"
    ... I think this results a data segment with a dword alignment. ... tell the assembler the addressing mode for which the code should be ... I think this is only for code segments importend, ... MASM need a datasegment-declaration anyyway. ...
    (alt.lang.asm)
  • Re: Gnu Assembler - Real Mode - accessing variable from code
    ... is to obtain the relative offset within the data segment ... symbols" or even "offset within section". ... to do this (the linker manual documents it as a way to initialize RAM ... regions overlap. ...
    (comp.lang.asm.x86)
  • Re: Is it Data Segment ?
    ... the linker can be controlled with the linker control script ... to make a copy of the data segment ... tauno voipio iki fi ...
    (comp.os.linux.development.system)