home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 4 Drivers
/
04-Drivers.zip
/
DEVHLP.ZIP
/
DEVHLP.LST
< prev
next >
Wrap
File List
|
1990-09-25
|
2KB
|
60 lines
MOV AX, address_high ; top of 32-bit physical absolute address
MOV BX, address_low ; bottom of 32-bit physical absolute address
MOV CX, length ; count of bytes to map (0=64k)
MOV DH, request_type ; 0=code, 1=data, 2=cancel
MOV DL, DevHlp_PhysToUVirt ; 17h
CALL DWORD PTR [DevHlp]
JNC ok ; carry set=error, clear=ok
; AX contains error code
ok: ; ES:BX contains virtual address
[Figure 2: Parameters for calling DosDevIOCtl()]
USHORT DosDevIOCtl(pvData, pvParms, usFunction, usCategory, hDevice)
PVOID pvData; /* far pointer to data packet <- driver */
PVOID pvParms; /* far pointer to parameter packet -> driver */
USHORT usFunction; /* two-byte device function */
USHORT usCategory; /* two-byte device category */
HFILE hDevice; /* two-byte device handle */
[Figure 3: The DEVHLP parameter/data packet]
typedef struct {
USHORT ax, bx, cx, dx, si, di, ds, es, flags;
} REGS;
[Figure 4: PhysToUVirt() in C]
#define DevHlp_PhysToUVirt 0x17
typedef enum {
UVirt_Exec=0, UVirt_ReadWrite, UVirt_Release
} UVIRT_TYPE;
// turn physical address into virtual address
void far *PhysToUVirt(ULONG addr, USHORT size, UVIRT_TYPE type)
{
REGS r;
USHORT sel, ret=1;
HFILE devhlp;
r.ax = HIUSHORT(addr);
r.bx = LOUSHORT(addr);
r.cx = size;
r.si = r.di = r.ds = r.es = 0; // not used
r.dx = MAKEUSHORT(DevHlp_PhysToUVirt, type);
if ((devhlp = open("DEVHLPXX", 0)) != -1)
{
ret = DosDevIOCtl(&r, &r, 0x60, 128, devhlp);
close(devhlp);
}
// if DosDevIOCtl failed OR if DevHlp set carry flag...
if (ret || (r.flags & 1))
return NULL;
else
return MAKEP(r.es, r.bx);
}