Article View: alt.lang.asm
Article #176Re: 32bit conversion help needed
From: Donald K. Forbes
Date: Mon, 21 Aug 1995 21:25
Date: Mon, 21 Aug 1995 21:25
80 lines
3108 bytes
3108 bytes
ewirtz@bga.com (Erik Wirtz) wrote:
>I am trying to convert a program that accesses a network card
>to 32bit Protected mode. It consists of a small C program and a
>small ASM program, It works flawlessly in real mode. When compiled
>under 32bit Protected Mode it generates GP's. I need help getting
My guess is you are trying to access memory using a real mode
segment/offset pair. You can not do this from protected mode.
You must allocate a selector and set its base address and limit.
In Windows 16 bit or Borland 16 bit DPMI you can use
AllocSelector(), SetSelectorBase() and SetSelectorLimit().
but since your are using Borland 32 bit DPMI these are not
available, therefore, you must call DPMI yourself. If you
do this, though, your program will not run in a DOS shell
under Windows 95 (it will if you use 16 bit DPMI). Here is
some code that will allocate a selector and set its base/limit:
/**************************************************************************
*
* Allocates a selector with base addres 'dwBaseAddress' and limit of
* 'dwLimit'. The return value is the new selector if the function is
* successful or 0 on failure.
*
* This is function should not be confused with the Windows API
function
* of the same name which simply allocates a selector.
*
********************************************/
SELECTOR _EXPORT AllocSelector(DWORD dwBaseAddress, DWORD dwLimit)
{
SELECTOR selNew;
asm {
// dwLimit must be non-zero
mov eax, dwLimit
or eax, eax
jz short Fail
// Allocate a data selector (DPMI sets default acces rights)
mov ax, 0x0000
mov cx, 0x0001
int DPMI_INT
jc short Fail
mov selNew, ax
// Set the selector's base address
mov ax, 0x0007
mov bx, selNew
mov ecx, dwBaseAddress
mov dx, cx
shr ecx, 16
int DPMI_INT
jc short Fail
// Set the selector's limit
mov ax, 0x0008
mov bx, selNew
mov ecx, dwLimit
dec ecx
mov dx, cx
shr ecx, 16
int DPMI_INT
jc short Fail
}
Success:
return selNew;
Fail:
return 0;
}
------------------------------------------------------------
Donald K. Forbes e-mail: don@mythos.com
_ _ ____ ___ ___
/ / //__/ / /__// //__
/ / / / / //__/___/ Software, Inc.
My opinions are mine and not necessarily that of my employer
------------------------------------------------------------
Technical Details
Message-ID:
<41arfs$s6v@nnrp3.primenet.com>Path:
arc1-ca.pugleaf.net!news.primenet.com!usenetReferences:
<40tocr$k7b@giga.bga.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.primenet.com!usenet From: don@mythos.com (Donald K. Forbes) Newsgroups: alt.lang.asm,comp.lang.c,rec.games.progammer,alt.msdos.programmer,comp.os.msdos.programmer,comp.os.netware.misc,comp.programming,realtime.programmers,comp.lang.c++ Subject: Re: 32bit conversion help needed Date: Mon, 21 Aug 1995 21:25:38 GMT Organization: Mythos Software, Inc. Message-ID: <41arfs$s6v@nnrp3.primenet.com> References: <40tocr$k7b@giga.bga.com> NNTP-Posting-Host: dforbes.mythos.com X-Newsreader: Forte Free Agent 1.0.82