Board index » delphi » Mem[] in pmode

Mem[] in pmode

i recall someone posting a few weeks back that if you're
compiling a borland pascal program in protected mode, you
should do this:

var
 x:byte absolute $40:$06;

instead of:

x:=mem[$40:$06];

in the program body.  i guess the latter would reflect an
incorrect address (or vice versa).  why is this the case?
also, does this apply to GNU-pascal and Free Pascal under
Linux?  i'm working on a communications prog and want to
make sure reading the BIOS data area for the serial port
is reliable..

thanks

assas...@reality.yps.org

 

Re:Mem[] in pmode


Quote
Assassin wrote in message ...
>i recall someone posting a few weeks back that if you're
>compiling a borland pascal program in protected mode, you
>should do this:

>var
> x:byte absolute $40:$06;

>instead of:

>x:=mem[$40:$06];

That doesn't seem right. In protected mode you have to use
Seg0040 instead of $40. Seg0040 is a word variable; Pascal will
set a selector so it can be used to access the BIOS variables and
put the selector's value in Seg0040; the value of that selector
may be other than $40, so the literal $40 would be wrong.

In real mode, TP7 (I don't think this applies to earlier
versions) defines Seg0040 and sets its value to $40 so you can
write code that would work in either mode.

BUT: Seg0400 being a variable, you can't use it in an "Absolute"
declaration like that - the compiler wouldn't know where to put x
because the address could change at run-time. So the second
usage - x := Mem[Seg0040:$6C]; - would be the one to use. (And I
suspect that the offset was $6C rather than 6.)

Now, you're asking about porting a comms port program to Linux.
What happens in the BIOS variable area in non-DOS operating
systems is something I know nothing about, but AFAIK Linux does
not use the BIOS except when booting, so even if you get the
address right, chances are nothing will be happening there. And
there's sure to be a "correct" way of dealing with such
peripherals in other OSes that bears no resemblance to what you'd
do in DOS!

FP

Re:Mem[] in pmode


Quote
Assassin wrote:
> i recall someone posting a few weeks back that if you're
> compiling a borland pascal program in protected mode, you
> should do this:
> var
>  x:byte absolute $40:$06;
> instead of:
> x:=mem[$40:$06];

My guess:
 x := mem[ seg0040:$06 ]
This is because pmode uses adressing with selectors instead of physical
semgments and so the 'location' (the selector) of the BIOS data can be
located anywhere!

Don't know about GNU- or Free-pascal! Sorry!
--
Arno Fehm (af...@bigfoot.de)

------------------------------------------------------------------------
Member of Grey Dreams Design: visit http://GreyDreams.home.pages.de !!!!
He who can destroy a thing has the real control over it. (Frank Herbert)
------------------------------------------------------------------------

Re:Mem[] in pmode


In article <mEkP2.818$Dz5.3603...@elnws01.ce.mediaone.net>,

Quote
Assassin  <assas...@reality.yps.org> wrote:
>i recall someone posting a few weeks back that if you're
>compiling a borland pascal program in protected mode, you
>should do this:

>var
> x:byte absolute $40:$06;

>instead of:

>x:=mem[$40:$06];

NO, you should NOT use absolute variables in PM. Also you should use
Seg0040 and not $40 (though I have found that $40 also works for some
reason). That is: x:=mem[Seg0040:6]

Quote
>in the program body.  i guess the latter would reflect an
>incorrect address (or vice versa).  why is this the case?
>also, does this apply to GNU-pascal and Free Pascal under
>Linux?  i'm working on a communications prog and want to
>make sure reading the BIOS data area for the serial port
>is reliable..

In 32-bit compilers completely different rules apply. They use linear
addressing and it is typically zero based, that means you just read
location $406. What the syntax is on particular compilers I do not know.

Osmo

Re:Mem[] in pmode


:>i recall someone posting a few weeks back that if you're
:>compiling a borland pascal program in protected mode, you
:>should do this:
:>
:>var
:> x:byte absolute $40:$06;
:>
:>instead of:
:>
:>x:=mem[$40:$06];

: That doesn't seem right. In protected mode you have to use
: Seg0040 instead of $40. Seg0040 is a word variable; Pascal will
: set a selector so it can be used to access the BIOS variables and
: put the selector's value in Seg0040; the value of that selector
: may be other than $40, so the literal $40 would be wrong.

: In real mode, TP7 (I don't think this applies to earlier
: versions) defines Seg0040 and sets its value to $40 so you can
: write code that would work in either mode.

thanks for the reply (and to everyone else who responded).  yeah,
absolute is the same thing as mem - i completely forgot about
the Seg0040.

: BUT: Seg0400 being a variable, you can't use it in an "Absolute"
: declaration like that - the compiler wouldn't know where to put x
: because the address could change at run-time. So the second
: usage - x := Mem[Seg0040:$6C]; - would be the one to use. (And I
: suspect that the offset was $6C rather than 6.)

heh, $6C is actually what i was *going* to type, but i changed it
to $6 because the second part of my question dealt with COM
ports. :)

: Now, you're asking about porting a comms port program to Linux.
: What happens in the BIOS variable area in non-DOS operating
: systems is something I know nothing about, but AFAIK Linux does
: not use the BIOS except when booting, so even if you get the
: address right, chances are nothing will be happening there. And
: there's sure to be a "correct" way of dealing with such
: peripherals in other OSes that bears no resemblance to what you'd
: do in DOS!

hmm.. i'll probably just use /dev/ttyS0 and be more compliant
overall.

thanks fer the info

-Assassin

Re:Mem[] in pmode


On 9 Apr 1999 20:40:39 +0300, ronka...@cc.helsinki.fi (Osmo Ronkanen)
wrote:

Quote
> >var
> > x:byte absolute $40:$06;
> >instead of:
> >x:=mem[$40:$06];
> NO, you should NOT use absolute variables in PM. Also you should use
> Seg0040 and not $40 (though I have found that $40 also works for some
> reason). That is: x:=mem[Seg0040:6]

This appears to be a silent convention in order to facilitate ports of
legacy code accessing and handling BIOS functions.

All 16 bit DPMI hosts I met pre-initialize the selector# $0040 with
the BIOS data segment value $0040.

Thus using $40 instead of SEG0040 in BP and even declaring absolute
valiables at $40:xxxx will work - as an exception.

Regards
Horst

Other Threads