home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / NFSRC305.ZIP / CPMI / ALIAS.ASM next >
Encoding:
Assembly Source File  |  1995-05-01  |  4.6 KB  |  119 lines

  1. ; File......: ALIAS.ASM
  2. ; Author....: Ted Means
  3. ; CIS ID....: 73067,3332
  4. ;
  5. ; This is an original work by Ted Means and is placed in the
  6. ; public domain.
  7. ;
  8. ; Modification history:
  9. ; ---------------------
  10. ;     Rev 1.0   01 Jan 1995 03:01:00   TED
  11. ;     Initial release
  12. ;
  13.  
  14. ;  $DOC$
  15. ;  $FUNCNAME$
  16. ;     cpmiMakeAlias()
  17. ;  $CATEGORY$
  18. ;     CPMI
  19. ;  $ONELINER$
  20. ;     Create alias descriptor
  21. ;  $SYNTAX$
  22. ;     SELECTOR pascal cpmiMakeAlias( SELECTOR Selector, unsigned int Rights )
  23. ;  $ARGUMENTS$
  24. ;     Selector is a selector for which an alias should be created.
  25. ;
  26. ;     Rights is an integer describing the access rights for the selector,
  27. ;     and should be either AR_READ, AR_WRITE, or AR_EXECUTE.  You may
  28. ;     also combine these attributes with the | operator, although
  29. ;     you may not mix AR_WRITE and AR_EXECUTE.  Note that AR_WRITE and
  30. ;     AR_EXECUTE both implicitly allow AR_READ rights.
  31. ;  $RETURNS$
  32. ;     A selector which maps to the same physical memory as the source
  33. ;     selector.
  34. ;  $DESCRIPTION$
  35. ;     This function duplicates a selector while giving different access
  36. ;     rights.  This is useful for writing to a code segment, making a
  37. ;     data segment read-only, etc.
  38. ;
  39. ;     When no longer needed, the selector should be freed via a call to
  40. ;     cpmiFreeSelector().
  41. ;  $EXAMPLES$
  42. ;     OldSelector = FP_SEG( SomePointer );
  43. ;
  44. ;     // Create a read / write data selector
  45. ;
  46. ;     NewSelector = cpmiMakeAlias( OldSelector, AR_READ | AR_WRITE )
  47. ;
  48. ;     // You can also make it read-only
  49. ;
  50. ;     NewSelector = cpmiMakeAlias( OldSelector, AR_READ )
  51. ;
  52. ;     cpmiWillGPF( NewSelector, AR_WRITE, 1 )     // Returns INVALID_ACCESS
  53. ;  $INCLUDE$
  54. ;     CPMI.H
  55. ;  $SEEALSO$
  56. ;     cpmiFreeSelector()
  57. ;  $END$
  58. ;
  59.  
  60. IDEAL
  61. P286
  62.  
  63. Public    cpmiMakeAlias
  64.  
  65. Segment   _NanFor   Word      Public    "CODE"
  66.           Assume    CS:_NanFor
  67.  
  68. Proc      cpmiMakeAlias     Far
  69.  
  70.           Enter     10,0                          ; Create stack frame
  71.           Push      DI                            ; Save DI
  72.  
  73.           Mov       AX,0Ah                        ; DPMI -- create alias
  74.           Mov       BX,[Word Ptr BP + 8]          ; Load selector
  75.           Int       31h                           ; Call DPMI
  76.           JC        @@Null                        ; Bail if error
  77.  
  78.           Mov       [Word Ptr BP - 2],AX          ; Store selector
  79.           Mov       BX,AX                         ; Load selector into BX
  80.           Push      SS                            ; Move SS . . .
  81.           Pop       ES                            ; . . . to ES
  82.           LEA       DI,[BP - 10]                  ; Load offset of buffer
  83.           Mov       AX,0Bh                        ; DPMI -- get descriptor
  84.           Int       31h                           ; Call DPMI
  85.           JC        @@Free                        ; Bail if error
  86.  
  87.           Mov       AX,[Word Ptr BP + 6]          ; Load access rights
  88.           Mov       CL,[Byte BP - 5]              ; Load existing rights
  89.           Test      AX,4                          ; Check for code bit
  90.           JZ        @@Data                        ; If not set, must be data
  91.           Or        CL,00001010b                  ; Set bits for code
  92.           And       CL,11111010b                  ; Turn off A & E/C bits
  93.           Jmp       Short @@Reset                 ; Set new rights
  94.  
  95. @@Data:   And       CL,11110000b                  ; Set bits for data
  96.           And       AL,2                          ; Isolate write bit
  97.           Or        CL,AL                         ; Set / Clear write bit
  98.  
  99. @@Reset:  Mov       [Byte Ptr BP - 5],CL          ; Store new rights
  100.           Push      SS                            ; Move SS . . .
  101.           Pop       ES                            ; . . . to ES
  102.           LEA       DI,[BP - 10]                  ; Load offset of buffer
  103.           Mov       AX,0Ch                        ; DPMI -- set descriptor
  104.           Int       31h                           ; Call DPMI
  105.           Mov       AX,[Word Ptr BP - 2]          ; Load return selector
  106.           JNC       @@Exit                        ; If no error, quit
  107.  
  108. @@Free:   Mov       AX,1                          ; DPMI -- Free selector
  109.           Mov       BX,[Word Ptr BP - 2]          ; Get selector
  110.           Int       31h                           ; Call DPMI
  111.  
  112. @@Null:   Xor       AX,AX                         ; Return NULL selector
  113.  
  114. @@Exit:   Pop       DI                            ; Restore DI
  115.           Leave                                   ; Destroy stack frame
  116.           RetF      4
  117. Endp      cpmiMakeAlias
  118. Ends      _NanFor
  119. End