home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / devddemo.zip / LDTMEM.C < prev    next >
Text File  |  1991-01-31  |  5KB  |  94 lines

  1. /*****************************************************************************/
  2. /* Routines for managing LDT accessed memory                                 */
  3. /*                                                                           */
  4. /* char *phys_to_ldt(loc,count)                                              */
  5. /* long loc;                                                                 */
  6. /* unsigned count;                                                           */
  7. /*                                                                           */
  8. /* Creates a selector in the current LDT from the physical address (loc) and */
  9. /* the size of the block.  Returns the selector as the function value.  If   */
  10. /* The creation fails, the return pointer is 0000:0000.                      */
  11. /*                                                                           */
  12. /* ------------------------------------------------------------------------- */
  13. /*                                                                           */
  14. /* int free_virt(selector)                                                   */
  15. /* unsigned selector;                                                        */
  16. /*                                                                           */
  17. /* Gives the LDT selector back to OS/2 for later use.  Returns 0 if          */
  18. /* successful, -1 if the return was rejected by OS/2.                        */
  19. /*                                                                           */
  20. /*****************************************************************************/
  21. #include "demo.h"
  22.  
  23. int far free_virt(selctr)
  24. unsigned selctr;
  25. {
  26.   union cpu_regs in_regs,out_regs;
  27.   union cpu_regs *ptr;
  28.  
  29.   ptr = &in_regs;                            /* Make sure ES = DS            */
  30.   ptr->W.AX = selctr;
  31.   in_regs.W.AX = selctr;                     /* AX = Segment to give back    */
  32.   in_regs.B.DH = 2;                          /* Say we are giving it back    */
  33.   in_regs.B.DL = devhlp_PhysToUVirt;         /* DevHlp command               */
  34.   in_regs.W.es_valid = FALSE;                /* Use current ES and DS regs   */
  35.   in_regs.W.ds_valid = FALSE;
  36.   dev_help(&in_regs,&out_regs);
  37.                                              /* If failure                   */
  38.   if ((out_regs.W.flags & 0x0001) != 0) {    /*    Return -1                 */
  39.      return(-1);
  40.      }                                       /* Else                         */
  41.   return(0);                                 /*    Return 0                  */
  42. }
  43.  
  44.  
  45. _32bits far phys_to_ldt1(loc,count)
  46. _32bits loc;
  47. unsigned count;
  48. {
  49.   union cpu_regs in_regs,out_regs;
  50.   _32bits temp;
  51.  
  52.   in_regs.W.AX = loc._2words.high;           /* AX:BX points to phys address */
  53.   in_regs.W.BX = loc._2words.low;            /* AX:BX points to phys address */
  54.   in_regs.W.CX = count;                      /* CX has the size              */
  55.   in_regs.B.DH = 1;                          /* Allocate above the 1M line   */
  56.   in_regs.B.DL = devhlp_PhysToUVirt;
  57.   in_regs.W.es_valid = FALSE;                /* struct ES not valid          */
  58.   in_regs.W.ds_valid = FALSE;                /* struct DS not valid          */
  59.   dev_help1(&in_regs,&out_regs);             /* Call DevHlp1                 */
  60.   if ((out_regs.W.flags & 0x0001) != 0) {    /* If failure                   */
  61.      temp.phys = 0;
  62.      return(temp);                           /*    Return 0000:0000          */
  63.      }
  64.   temp._2words.high = out_regs.W.ES;         /* Else, return pointer         */
  65.   temp._2words.low  = out_regs.W.BX;
  66.   return(temp);
  67. }
  68.  
  69.  
  70. _32bits far phys_to_ldt(loc,count)
  71. _32bits loc;
  72. unsigned count;
  73. {
  74.   union cpu_regs in_regs,out_regs;
  75.   _32bits temp;
  76.  
  77.   in_regs.W.AX = loc._2words.high;           /* AX:BX points to phys address */
  78.   in_regs.W.BX = loc._2words.low;            /* AX:BX points to phys address */
  79.   in_regs.W.CX = count;                      /* CX has the size              */
  80.   in_regs.B.DH = 1;                          /* Allocate above the 1M line   */
  81.   in_regs.B.DL = devhlp_PhysToUVirt;
  82.   in_regs.W.es_valid = FALSE;                /* ES not valid                 */
  83.   in_regs.W.ds_valid = FALSE;                /* DS not valid                 */
  84.   dev_help(&in_regs,&out_regs);              /* Call DevHlp                  */
  85.   if ((out_regs.W.flags & 0x0001) != 0) {    /* If failure                   */
  86.      temp.phys = 0;
  87.      return(temp);                           /*    Return 0000:0000          */
  88.      }
  89.   temp._2words.high = out_regs.W.ES;         /* Else, return pointer         */
  90.   temp._2words.low  = out_regs.W.BX;
  91.   return(temp);
  92. }
  93.  
  94.