home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / mmos2 / mmtoolkt / samples / audiodd / cdevhlp.asm < prev    next >
Encoding:
Assembly Source File  |  1992-05-06  |  10.8 KB  |  383 lines

  1.  
  2.  
  3.         PAGE    80,132
  4.         .386p
  5.  
  6.         TITLE   CDEVHLP - 'C' INTERFACE FOR DEVHELP CALLS
  7.         SUBTTL  'C' DEVHLP
  8.         NAME    DEVHLPs
  9.  
  10. ;********************** START OF SPECIFICATIONS *********************
  11. ;*
  12. ;* SOURCE FILE NAME:  CDEVHLP.ASM
  13. ;*
  14. ;* DESCRIPTIVE NAME:  'C' interface for OS/2 devhelp calls
  15. ;*
  16. ;* FUNCTION: This module provides the interface mechanism to translate a 'C'
  17. ;*           stacked based devhelp call to a MASM register based OS/2 devhelp
  18. ;*           call.
  19. ;*
  20. ;* NOTES:
  21. ;*    DEPENDENCIES: NONE
  22. ;*    RESTRICTIONS: Use assmebly language only.
  23. ;*
  24. ;* ENTRY POINTS:    _DevHlp_AllocGDTSelector
  25. ;*                  _DevHlp_AllocPhys
  26. ;*                  _DevHlp_PhysToGDTSelector
  27. ;*                  _DevHlp_PhysToVirt
  28. ;*                  _DevHlp_VirtToPhys
  29. ;*
  30. ;* EXTERNAL REFERENCES (system):  Far calls to OS/2 kernal DevHlp routines.
  31. ;*
  32. ;*********************** END OF SPECIFICATIONS **********************
  33. ;******************************************************************************
  34. ;                       I N C L U D E S
  35. ;******************************************************************************
  36.  
  37. .xlist
  38. include devhlp.inc
  39. .list
  40.  
  41. ;******************************************************************************
  42. ;                       E X T E R N S
  43. ;******************************************************************************
  44. _DATA   SEGMENT WORD PUBLIC USE16 'DATA'
  45.         EXTRN   _DevHlp:DWORD
  46. _DATA   ENDS
  47.  
  48. ;******************************************************************************
  49. ;                   D A T A   D E C L A R A T I O N S
  50. ;******************************************************************************
  51.  
  52. ;******************************************************************************
  53. ;                           C O D E
  54. ;******************************************************************************
  55.  
  56. _TEXT   SEGMENT WORD PUBLIC USE16 'CODE'
  57.         ASSUME cs:_TEXT
  58.  
  59. ;********************** START OF SPECIFICATIONS *********************
  60. ;*
  61. ;* SUBROUTINE NAME: _DevHlp_AllocGDTSelector
  62. ;*
  63. ;* DESCRIPTIVE NAME:
  64. ;*
  65. ;* FUNCTION: Call the devhelper routine with the 'C' parameters passed in the
  66. ;*           registers.
  67. ;*
  68. ;* NOTES:
  69. ;*
  70. ;* ENTRY POINTS:  _DevHlp_AllocGDTSelector
  71. ;*     LINKAGE:   CALL NEAR
  72. ;*
  73. ;* INPUT: ULONG block size in bytes
  74. ;*
  75. ;* EXIT-NORMAL:  Refer to OS/2 devhelp api document ES:DI contains locaton of array
  76. ;*               of words of GDT's.
  77. ;*
  78. ;* EXIT_ERROR: 'Carry flag set' and AX=error code
  79. ;*
  80. ;* EFFECTS:  Registers:
  81. ;*
  82. ;* INTERNAL REFERENCES: none
  83. ;*
  84. ;* EXTERNAL REFERENCES: DevHlp_AllocGDTSelector
  85. ;*
  86. ;*********************** END OF SPECIFICATIONS **********************
  87.  
  88. _DevHlp_AllocGDTSelector proc near
  89.         ASSUME cs:_TEXT,ds:_DATA,es:NOTHING,ss:NOTHING
  90. NumGDTSelectors EQU     <[bp+4]>
  91. paGDTSel        EQU     <[bp+8]>        ; seg:off of GDT array
  92.         push    bp
  93.         mov     bp,sp                   ; allocate NULL stack frame
  94.         push    cx
  95.         push    dx
  96.         push    di
  97.         push    es
  98.  
  99. IFDEF   DEVHLP_DEBUG
  100.         int     3
  101. ENDIF
  102.         mov     es,WORD PTR paGDTSel+2          ; get seg.
  103.         mov     di,WORD PTR paGDTSel            ; get off.
  104.         mov     cx,NumGDTSelectors
  105.         mov     dl,DevHlp_AllocGDTSelector
  106.         call    [_DevHlp]
  107.         jc      allocgdt
  108.         xor     ax,ax                           ; clear for no error
  109. allocgdt:
  110.         pop     es
  111.         pop     di
  112.         pop     dx
  113.         pop     cx
  114.         pop     bp
  115.         ret
  116. _DevHlp_AllocGDTSelector endp
  117.  
  118. ;********************** START OF SPECIFICATIONS *********************
  119. ;*
  120. ;* SUBROUTINE NAME: _DevHlp_AllocPhys
  121. ;*
  122. ;* DESCRIPTIVE NAME:
  123. ;*
  124. ;* FUNCTION: Call the devhelper routine with the 'C' parameters passed in the
  125. ;*           registers.
  126. ;*
  127. ;* NOTES:
  128. ;*
  129. ;* ENTRY POINTS:  _DevHlp_AllocPhys
  130. ;*     LINKAGE:   CALL NEAR
  131. ;*
  132. ;* INPUT: ULONG block size in bytes
  133. ;*
  134. ;* EXIT-NORMAL:  Refer to OS/2 devhelp api document ax:bx = 32 bit physical addr
  135. ;*               AX = 0
  136. ;*
  137. ;* EXIT_ERROR: AX=error code
  138. ;*
  139. ;* EFFECTS:  Registers:
  140. ;*
  141. ;* INTERNAL REFERENCES: none
  142. ;*
  143. ;* EXTERNAL REFERENCES: DevHlp_AllocPhys
  144. ;*
  145. ;*********************** END OF SPECIFICATIONS **********************
  146.  
  147. _DevHlp_AllocPhys proc near
  148.         ASSUME cs:_TEXT,ds:_DATA,es:NOTHING,ss:NOTHING
  149. BytesLo         EQU     <[bp+4]>        ; memory block size
  150. BytesHi         EQU     <[bp+6]>
  151. Location        EQU     <[bp+8]>        ; above or below 1MB
  152. pRetAddress     EQU     <[bp+10]>       ; 32bit address to allocated memory blk
  153.  
  154.         push    bp
  155.         mov     bp,sp                   ; allocate NULL stack frame
  156.         push    bx
  157.         push    dx
  158.         push    es
  159.  
  160. IFDEF   DEVHLP_DEBUG
  161.         int     3
  162. ENDIF
  163.         mov     bx,BytesLo
  164.         mov     ax,BytesHi
  165.         mov     dh,BYTE PTR Location            ; 0=above 1MB
  166.         mov     dl,DevHlp_AllocPhys             ; 1=below 1MB
  167.         call    [_DevHlp]
  168.         jc      allocphys
  169.  
  170.         mov     dx,bx                           ; Need bx for addressing
  171.         les     bx,pRetAddress                  ; Dereference address of
  172.                                                 ; callers variable
  173.         mov     es:[bx+2],ax                    ; Return high 16 bits and
  174.         mov     es:[bx],dx                      ; Low 16 bits (flat pointer)
  175.  
  176.         xor     ax,ax                           ; clear ax => no error
  177. allocphys:
  178.         pop     es
  179.         pop     dx
  180.         pop     bx
  181.         pop     bp                              ; restore callers frame
  182.         ret
  183. _DevHlp_AllocPhys endp
  184.  
  185. ;********************** START OF SPECIFICATIONS *********************
  186. ;*
  187. ;* SUBROUTINE NAME: _DevHlp_PhysToGDTSelector
  188. ;*
  189. ;* DESCRIPTIVE NAME:
  190. ;*
  191. ;* FUNCTION: Call the devhelper routine with the 'C' parameters passed in the
  192. ;*           registers.
  193. ;*
  194. ;* NOTES:
  195. ;*
  196. ;* ENTRY POINTS:  _DevHlp_PhysToGDTSelector
  197. ;*     LINKAGE:   CALL NEAR
  198. ;*
  199. ;* INPUT: 32bit physical address, length of segment, selector to setup
  200. ;*
  201. ;* EXIT-NORMAL: Refer to OS/2 devhelp api document
  202. ;*              ptr that contained 32bit physaddrr is now a sel:off.
  203. ;*              AX = 0
  204. ;*
  205. ;* EXIT_ERROR: ax=error code
  206. ;*
  207. ;* EFFECTS:  Registers:
  208. ;*
  209. ;* INTERNAL REFERENCES:
  210. ;*
  211. ;* EXTERNAL REFERENCES: DevHlp_PhysToGDTSelector
  212. ;*
  213. ;*********************** END OF SPECIFICATIONS **********************
  214.  
  215. _DevHlp_PhysToGDTSelector proc near
  216.         ASSUME cs:_TEXT,ds:_DATA,es:NOTHING,ss:NOTHING
  217. PhysAddress     EQU     <[bp+4]>
  218. ByteLength      EQU     <[bp+8]>
  219. Selector        EQU     <[bp+10]>
  220.         push    bp
  221.         mov     bp,sp                   ; allocate NULL stack frame
  222.         push    bx
  223.         push    cx
  224.         push    dx
  225.         push    si
  226.  
  227. IFDEF   DEVHLP_DEBUG
  228.         int     3
  229. ENDIF
  230.         mov     ax,WORD PTR PhysAddress+2
  231.         mov     bx,WORD PTR PhysAddress
  232.         mov     cx,ByteLength
  233.         mov     si,Selector
  234.         mov     dl,DevHlp_PhysToGDTSelector
  235.         call    DWORD PTR [_DevHlp]      ; return error in ax if CF
  236.         jc      physToGDT
  237.         xor     ax,ax
  238. physToGDT:
  239.         pop     si
  240.         pop     dx
  241.         pop     cx
  242.         pop     bx
  243.         pop     bp
  244.         ret
  245. _DevHlp_PhysToGDTSelector endp
  246.  
  247.  
  248.  
  249. ;********************** START OF SPECIFICATIONS *********************
  250. ;*
  251. ;* SUBROUTINE NAME: _DevHlp_PhysToVirt
  252. ;*
  253. ;* DESCRIPTIVE NAME:
  254. ;*
  255. ;* FUNCTION: Call the devhelper routine with the 'C' parameters passed in the
  256. ;*           registers.
  257. ;*
  258. ;* NOTES:
  259. ;*
  260. ;* ENTRY POINTS:  _DevHlp_PhysVirt
  261. ;*     LINKAGE:   CALL NEAR
  262. ;*
  263. ;* INPUT: ULONG block size in bytes
  264. ;*
  265. ;* EXIT-NORMAL: Refer to OS/2 devhelp api document ax:bx = 32 bit physical addr
  266. ;*              AX = 0
  267. ;*
  268. ;* EXIT_ERROR: ax=error code
  269. ;*
  270. ;* EFFECTS:  Registers:
  271. ;*
  272. ;* INTERNAL REFERENCES: none
  273. ;*
  274. ;* EXTERNAL REFERENCES: DevHlp_PhysToVirt
  275. ;*
  276. ;*********************** END OF SPECIFICATIONS **********************
  277.  
  278. _DevHlp_PhysToVirt proc near
  279.         ASSUME cs:_TEXT,ds:_DATA,es:NOTHING,ss:NOTHING
  280. PhysAddress     EQU     <[bp+4]>        ; physical address
  281. BlockSize       EQU     <[bp+8]>        ; block size
  282. pRetAddress     EQU     <[bp+12]>       ; address of returned virtual pointer
  283.         push    bp
  284.         mov     bp,sp                   ; allocate NULL stack frame
  285.         push    dx
  286.         push    es
  287.         push    di
  288.         push    ds
  289.         push    si
  290.  
  291. IFDEF   DEVHLP_DEBUG
  292.         int     3
  293. ENDIF
  294.         mov     ax,WORD PTR PhysAddress+2
  295.         mov     bx,WORD PTR PhysAddress
  296.         mov     cx,BlockSize
  297.         xor     dh,dh                           ; set DS:SI
  298.         mov     dl,DevHlp_PhysToVirt
  299.         call    [_DevHlp]
  300.         jc      physvirterr
  301.  
  302.         les     di,pRetAddress                  ; de-reference pointer
  303.         mov     es:[di+2],ds                    ; hi word (return ds:si)
  304.         mov     es:[di],si                      ; lo word
  305.         xor     ax,ax                           ; clear for no error
  306.  
  307. physvirterr:
  308.         pop     si
  309.         pop     ds
  310.         pop     di
  311.         pop     es
  312.         pop     dx
  313.         pop     bp
  314.         ret
  315. _DevHlp_PhysToVirt endp
  316.  
  317. ;********************** START OF SPECIFICATIONS *********************
  318. ;*
  319. ;* SUBROUTINE NAME: _DevHlp_VirtToPhys
  320. ;*
  321. ;* DESCRIPTIVE NAME:
  322. ;*
  323. ;* FUNCTION: Call the devhelper routine with the 'C' parameters passed in the
  324. ;*           registers.
  325. ;*
  326. ;* NOTES:
  327. ;*
  328. ;* ENTRY POINTS:  _DevHlp_VirtToPhys
  329. ;*     LINKAGE:   CALL NEAR
  330. ;*
  331. ;* INPUT:
  332. ;*
  333. ;* EXIT-NORMAL: Refer to OS/2 devhelp api document
  334. ;*              AX = 0
  335. ;*
  336. ;* EXIT_ERROR: ax = -1
  337. ;*
  338. ;* EFFECTS:  Registers:
  339. ;*
  340. ;* INTERNAL REFERENCES:
  341. ;*
  342. ;* EXTERNAL REFERENCES: DevHlp_VirtToPhys
  343. ;*
  344. ;*********************** END OF SPECIFICATIONS **********************
  345.  
  346. _DevHlp_VirtToPhys proc near
  347.         ASSUME cs:_TEXT,ds:_DATA,es:NOTHING,ss:NOTHING
  348. VirtAddress     EQU     <[bp+4]>        ; dword
  349. pRetPhysAddress EQU     <[bp+8]>        ; dword
  350.         push    bp
  351.         mov     bp,sp                   ; allocate NULL stack frame
  352.         push    si
  353.         push    dx
  354.         push    ds
  355.  
  356. IFDEF   DEVHLP_DEBUG
  357.         int     3
  358. ENDIF
  359.         lds     si,VirtAddress
  360.         mov     dl,DevHlp_VirtToPhys
  361.         call    DWORD PTR [_DevHlp]     ; return error in ax if CF
  362.         jc      VirtPhysErr
  363.  
  364.         les     si,pRetPhysAddress      ; de-reference pointer
  365.         mov     es:[si+2],ax            ; Return high word
  366.         mov     es:[si],bx              ; Return low word
  367.         xor     ax, ax                  ; Success, RC = zero
  368.         jmp     VirtPhysDone
  369.  
  370. VirtPhysErr:
  371.         mov     ax,-1
  372.  
  373. VirtPhysDone:
  374.         pop     ds
  375.         pop     dx
  376.         pop     si
  377.         pop     bp
  378.         ret
  379. _DevHlp_VirtToPhys endp
  380.  
  381. _TEXT   ENDS
  382.         END
  383.