home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 4 Drivers / 04-Drivers.zip / DEVHLP.ZIP / DEVHLP.LST < prev    next >
File List  |  1990-09-25  |  2KB  |  60 lines

  1.  
  2.     MOV AX, address_high        ; top of 32-bit physical absolute address
  3.     MOV BX, address_low         ; bottom of 32-bit physical absolute address
  4.     MOV CX, length              ; count of bytes to map (0=64k)
  5.     MOV DH, request_type        ; 0=code, 1=data, 2=cancel
  6.     MOV DL, DevHlp_PhysToUVirt  ; 17h
  7.     CALL DWORD PTR [DevHlp]
  8.     JNC ok                      ; carry set=error, clear=ok
  9.     ; AX contains error code
  10. ok: ; ES:BX contains virtual address
  11.  
  12.  
  13. [Figure 2: Parameters for calling DosDevIOCtl()]
  14.  
  15. USHORT DosDevIOCtl(pvData, pvParms, usFunction, usCategory, hDevice)
  16. PVOID pvData;       /* far pointer to data packet <- driver */
  17. PVOID pvParms;      /* far pointer to parameter packet -> driver */
  18. USHORT usFunction;  /* two-byte device function */
  19. USHORT usCategory;  /* two-byte device category */
  20. HFILE hDevice;      /* two-byte device handle */
  21.  
  22.  
  23. [Figure 3: The DEVHLP parameter/data packet]
  24.  
  25. typedef struct {
  26.     USHORT ax, bx, cx, dx, si, di, ds, es, flags;
  27.     } REGS;
  28.  
  29. [Figure 4: PhysToUVirt() in C]
  30.  
  31. #define DevHlp_PhysToUVirt      0x17
  32.  
  33. typedef enum {
  34.     UVirt_Exec=0, UVirt_ReadWrite, UVirt_Release
  35.     } UVIRT_TYPE;
  36.  
  37. // turn physical address into virtual address
  38. void far *PhysToUVirt(ULONG addr, USHORT size, UVIRT_TYPE type)
  39. {
  40.     REGS r;
  41.     USHORT sel, ret=1;
  42.     HFILE devhlp;
  43.     r.ax = HIUSHORT(addr);
  44.     r.bx = LOUSHORT(addr);
  45.     r.cx = size;
  46.     r.si = r.di = r.ds = r.es = 0;  // not used
  47.     r.dx = MAKEUSHORT(DevHlp_PhysToUVirt, type);
  48.     if ((devhlp = open("DEVHLPXX", 0)) != -1)
  49.     {
  50.         ret = DosDevIOCtl(&r, &r, 0x60, 128, devhlp);
  51.         close(devhlp);
  52.     }
  53.     // if DosDevIOCtl failed OR if DevHlp set carry flag...
  54.     if (ret || (r.flags & 1))
  55.         return NULL;
  56.     else
  57.         return MAKEP(r.es, r.bx);
  58. }
  59.  
  60.