[comp.os.msdos.programmer] Physical addresses in protected mode?

cchapman@msd.gatech.edu (Chuck H. Chapman) (06/21/91)

I'm new to assembly language programming on the PC.  I need to do DMA transfers
to a device while running a protected mode program.  How do I figure out what
the physical address of the data I want to transfer is so I can pass this
address to the DMA controller so it can access the data?  It's easy in
real mode but how do you figure out physical addresses in protected mode?

Thanks in advance,
Chuck
--
Charles H. Chapman  (GTRI/MATD)             (404) 528-7588
Georgia Institute of Technology, Atlanta Georgia, 30332
**************************************************************
* Home of the 1990 National Champion Ga. Tech Yellow Jackets *
**************************************************************
uucp:     ...!{allegra,amd,hplabs,ut-ngp}!gatech!msd!cchapman
Internet: cchapman@msd.gatech.edu

rcollins@gumby.Altos.COM (Robert Collins) (06/25/91)

In article <cchapman.677508274@msd> cchapman@msd.gatech.edu (Chuck H. Chapman) writes:
>
>I'm new to assembly language programming on the PC.  I need to do DMA transfers
>to a device while running a protected mode program.  How do I figure out what
>the physical address of the data I want to transfer is so I can pass this
>address to the DMA controller so it can access the data?  It's easy in
>real mode but how do you figure out physical addresses in protected mode?
>
First of all, you must be at IOPL=0.  If you aren't, then you can't find
the physical address.  Assuming IOPL=0, SGDT to save the gdt base address.
Build your own GDT (on the stack or memory) that has a data segment pointing
to the original GDT.  Now using whatever segment:offset you wanted to DMA
into, (or out of) look in that GDT entry, and calculate the virtual address.

If paging is not enabled, then the virtual address=physical address.  If paging
is enabled then you must use your virtual address to index into the
page directory and page tables associated with that address.  From those
tables, you then calculate the physical address.

If you are in V86 mode, then give it up because you are executing at IOPL=3
which makes it impossible to get the physical address.

Since you are 'new' to assembly language programming...have fun.

Robert Collins

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (06/25/91)

In article <4948@gumby.Altos.COM> rcollins@altos.COM (Robert Collins) writes:
>
>If you are in V86 mode, then give it up because you are executing at IOPL=3
>which makes it impossible to get the physical address.

If running under VCPI, there's a call to find the physical address corresponding
to any V86 address.  This is done by calling INT 67h with AX=0DE06h, CX=the
linear V86 address shifted right 12 bits.  It returns with EDX holding the
physical address of the page.  I imagine DPMI has a similar service, but
I don't have the spec.

Duncan Murdoch
dmurdoch@watstat.waterloo.edu

resnicks@netcom.COM (Steve Resnick) (06/26/91)

In article <1991Jun25.023154.16683@maytag.waterloo.edu> dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:
>In article <4948@gumby.Altos.COM> rcollins@altos.COM (Robert Collins) writes:
>>
>>If you are in V86 mode, then give it up because you are executing at IOPL=3
>>which makes it impossible to get the physical address.
>
>If running under VCPI, there's a call to find the physical address corresponding
>to any V86 address.  This is done by calling INT 67h with AX=0DE06h, CX=the
>linear V86 address shifted right 12 bits.  It returns with EDX holding the
>physical address of the page.  I imagine DPMI has a similar service, but
>I don't have the spec.

DPMI Does support a virtual-to-physical address translation. I don't have the
spec here, but I will dig it up if someone wants the info.... Let me
know via mail ....


Steve



-- 
-------------------------------------------------------------------------------
        resnicks@netcom.com, steve@camphq, IFNA:        1:143/105.0, 
                 co moderator for comp.binaries.os2
 Real life: Steve Resnick. Chief Software Architect, Process Scientific, Inc
 Flames, grammar and spelling errors >/dev/null
 The Asylum OS/2 BBS - (408)263-8017 12/2400,8,1 - Running Maximus CBCS 1.2
-------------------------------------------------------------------------------