home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / devddemo.zip / DEVHLP.ASM < prev    next >
Assembly Source File  |  1991-01-31  |  13KB  |  370 lines

  1.               PAGE      60,131
  2.               TITLE     GENERIC Device Driver devhlp interface
  3. ;
  4. ;┌───────────────────────────────────────────────────────────────────────────┐
  5. ;│                                                                           │
  6. ;│ GENERIC Device Driver DEVHLP Interface                                    │
  7. ;│                                                                           │
  8. ;│ _dev_help  - calls OS/2 DevHlp function by doing a far call to the value  │
  9. ;│              stored in dev_hlpCS.  This is the one to use generally.      │
  10. ;│              The general operation is to copy all the parameters passed   │
  11. ;│              in the input structure by the caller onto the stack and      │
  12. ;│              then pop them into the registers.  Then, dev_hlp is called   │
  13. ;│              by referring to the one in our CODE segment.  This lets us   │
  14. ;│              use DS and ES to hold all sorts of values.  After we         │
  15. ;│              (hopefully) get back from dev_hlp, we store the register and │
  16. ;│              flag values in the output structure and return to the caller │
  17. ;│                                                                           │
  18. ;│ _dev_help1 - Same as above, except it uses the value of del_hlp stored in │
  19. ;│              our data segment and points to it with ES.  This one is      │
  20. ;│              intended to be used only until dev_hlpCS has the right value,│
  21. ;│              very soon after INIT starts.  It is used by those functions  │
  22. ;│              to get the right value in dev_hlpCS.  It is in a segment that│
  23. ;│              is discarded after INIT is done, so it is not accessable by  │
  24. ;│              other functions.                                             │
  25. ;│                                                                           │
  26. ;└───────────────────────────────────────────────────────────────────────────┘
  27. ;
  28.               .286P                        ;    Must use 286 mode if OS/2
  29.               PAGE
  30. ;┌───────────────────────────────────────────────────────────────────────────┐
  31. ;│                  STRUCTURE DEFINITIONS                                    │
  32. ;└───────────────────────────────────────────────────────────────────────────┘
  33. ;
  34. regs          struc
  35. r_ax          dw        ?                  ; AX value
  36. r_bx          dw        ?                  ; BX
  37. r_cx          dw        ?                  ; CX
  38. r_dx          dw        ?                  ; DX
  39. r_si          dw        ?                  ; SI
  40. r_di          dw        ?                  ; DI
  41. r_es          dw        ?                  ; ES
  42. r_ds          dw        ?                  ; DS
  43. r_cs          dw        ?                  ; CS
  44. r_flags       dw        ?                  ; FLAGS
  45. r_es_valid    db        ?                  ; Indicator if ES is valid
  46. r_ds_valid    db        ?                  ; Indicator if DS is valid
  47. regs          ends
  48. ;
  49. ;┌───────────────────────────────────────────────────────────────────────────┐
  50. ;│                  CONSTANT DEFINITIONS                                     │
  51. ;└───────────────────────────────────────────────────────────────────────────┘
  52. ;
  53. TRUE          equ       1      ; Boolean values
  54. FALSE         equ       0
  55. ;
  56. ;
  57. NULL          SEGMENT   WORD PUBLIC 'BEGDATA'
  58.               extrn _devhlp:dword
  59. NULL          ENDS
  60.               PAGE
  61. ;
  62. ;┌───────────────────────────────────────────────────────────────────────────┐
  63. ;│                  CODE SEGMENT                                             │
  64. ;└───────────────────────────────────────────────────────────────────────────┘
  65. ;
  66. MAINSEG       SEGMENT   WORD PUBLIC 'CODE'
  67. ;
  68.               ASSUME    CS:MAINSEG
  69.               public    _dev_help
  70.               public    _dev_hlpCS
  71. ;
  72. ;┌───────────────────────────────────────────────────────────────────────────┐
  73. ;│                                                                           │
  74. ;│  dev_help    - function to call OS/2 DevHlp facility.                     │
  75. ;│                                                                           │
  76. ;│  struct regs {                                                            │
  77. ;│         unsigned AX,BX,CX,DX,SI,DI,ES,flags;                              │
  78. ;│         boolean es_valid;                                                 │
  79. ;│         boolean ds_valid;                                                 │
  80. ;│         }                                                                 │
  81. ;│                                                                           │
  82. ;│  Syntax - unsigned dev_helper(far ptr *in_regs, far ptr *out_regs);       │
  83. ;│                                                                           │
  84. ;└───────────────────────────────────────────────────────────────────────────┘
  85. ;
  86. _dev_hlpCS    dd        0
  87. _dev_help     proc      far
  88. ;
  89. ; Point to current frame
  90. ; This gets BP pointing generally at the parameters passed to us by the caller
  91. ;
  92.               push      bp
  93.               mov       bp,sp
  94. ;
  95. ; Save entry regs - we are gonna step on them hard
  96. ;
  97.               push      ax
  98.               push      bx
  99.               push      cx
  100.               push      dx
  101.               push      si
  102.               push      di
  103.               push      es
  104.               pushf
  105.               push      ds
  106. ;
  107. ; Load stack with values to go into registers
  108. ;
  109. ; First one is DS.  If the ds_valid flag in the in_regs struc passed by the
  110. ; caller is TRUE, use the value in the in_regs struc.  If it is FALSE, use
  111. ; the current value of DS.
  112. ;
  113.               les       bx,[bp+6]
  114.               cmp       es:[bx].r_ds_valid,TRUE
  115.               jnz       devh1001
  116.               mov       ax,es:[bx].r_ds
  117.               push      ax
  118.               jmp       devh2001
  119. devh1001:
  120.               push      ds
  121. ;
  122. devh2001:
  123. ;
  124. ; Next is ES.  Same bit of logic with the es_valid flag, use the struc value
  125. ; if es_valid is TRUE, otherwise, use the value in the ES register.
  126. ;
  127.               les       bx,[bp+6]
  128.               cmp       es:[bx].r_es_valid,TRUE
  129.               jnz       devh3001
  130.               mov       ax,es:[bx].r_es
  131.               push      ax
  132.               jmp       devh4001
  133. devh3001:
  134.               push      es
  135. ;
  136. devh4001:
  137. ;
  138. ; Now for the rest of the registers.  They are removed from the struc and
  139. ; pushed onto the stack in the following order: AX, BX, CX, DX, SI, and DI
  140. ;
  141.               mov       ax,es:[bx].r_ax
  142.               push      ax
  143.               mov       ax,es:[bx].r_bx
  144.               push      ax
  145.               mov       ax,es:[bx].r_cx
  146.               push      ax
  147.               mov       ax,es:[bx].r_dx
  148.               push      ax
  149.               mov       ax,es:[bx].r_si
  150.               push      ax
  151.               mov       ax,es:[bx].r_di
  152.               push      ax
  153. ;
  154. ; Now pop the values off the stack and into the proper registers
  155. ;
  156.               pop       di
  157.               pop       si
  158.               pop       dx
  159.               pop       cx
  160.               pop       bx
  161.               pop       ax
  162.               pop       es
  163.               pop       ds
  164. ;
  165. ; call OS/2 DevHlp
  166. ;
  167.               call      cs:_dev_hlpCS
  168. ;
  169. ; Save return values in output structure.  The first thing to do is to save
  170. ; DS and BX because that is what we are going to use to point to the struc.
  171. ; We save the flags too, 'cause we don't want 'em touched by these operations.
  172. ;
  173.               push      ds
  174.               pushf
  175.               push      bx
  176. ;
  177. ; Now, load DS:BX to point to the output struc given to us by the caller.
  178. ;
  179.               lds       bx,[bp+10]
  180. ;
  181. ; Store AX into the return struc
  182. ;
  183.               mov       [bx].r_ax,ax
  184. ;
  185. ; Next, is BX (use the value in the stack)
  186. ;
  187.               pop       ax
  188.               mov       [bx].r_bx,ax
  189. ;
  190. ; Then the flags, also on the stack
  191. ;
  192.               pop       ax
  193.               mov       [bx].r_flags,ax
  194. ;
  195. ; and DS from the stack.
  196. ;
  197.               pop       ax
  198.               mov       [bx].r_ds,ax
  199. ;
  200. ; ES. But we need to move it to a general register, as we cannot move ES to
  201. ; memory directly (the CPU won't do it).  So, we push ES onto the stack and
  202. ; pop it into AX, then move AX to the struc.
  203. ;
  204.               push      es
  205.               pop       ax
  206.               mov       [bx].r_es,ax
  207. ;
  208. ; Now the rest of the registers.  We can move them straight from the register
  209. ; to the struc as we have not touched them since we returned from DevHlp.
  210. ;
  211.               mov       [bx].r_cx,cx
  212.               mov       [bx].r_dx,dx
  213.               mov       [bx].r_di,di
  214.               mov       [bx].r_si,si
  215. ;
  216. ; And finally, set both es_valid and ds_valid to TRUE cause they are silly
  217. ;
  218.               mov       [bx].r_es_valid,TRUE
  219.               mov       [bx].r_ds_valid,TRUE
  220. ;
  221. ; Restore entry regs
  222. ;
  223.               pop       ds
  224.               popf
  225.               pop       es
  226.               pop       di
  227.               pop       si
  228.               pop       dx
  229.               pop       cx
  230.               pop       bx
  231.               pop       ax
  232. ;
  233. ; Return to caller
  234. ;
  235.               pop       bp
  236.               ret
  237. ;
  238. _dev_help     endp
  239. MAINSEG       ENDS
  240. ;
  241. INITSEG       SEGMENT   WORD PUBLIC 'CODE'
  242. ;
  243.               ASSUME    CS:INITSEG
  244.               public    _dev_help1
  245. ;
  246. ;┌───────────────────────────────────────────────────────────────────────────┐
  247. ;│                                                                           │
  248. ;│  dev_help1   - function to call OS/2 DevHlp facility.                     │
  249. ;│                                                                           │
  250. ;│  struct regs {                                                            │
  251. ;│         unsigned AX,BX,CX,DX,SI,DI,ES,flags;                              │
  252. ;│         boolean es_valid;                                                 │
  253. ;│         boolean ds_valid;                                                 │
  254. ;│         }                                                                 │
  255. ;│                                                                           │
  256. ;│  Syntax - unsigned dev_helper(far ptr *in_regs, far ptr *out_regs);       │
  257. ;│                                                                           │
  258. ;│  This one is used at init time until dev_hlpCS is initialized.  After     │
  259. ;│  INIT, this one is gone as it is in a segment that is discarded after     │
  260. ;│  initialization is finished.                                              │
  261. ;│                                                                           │
  262. ;└───────────────────────────────────────────────────────────────────────────┘
  263. ;
  264. _dev_help1    proc      far
  265. ;
  266. ; Point to current frame
  267. ;
  268.               push      bp
  269.               mov       bp,sp
  270. ;
  271. ; Save entry regs
  272. ;
  273.               push      ax
  274.               push      bx
  275.               push      cx
  276.               push      dx
  277.               push      si
  278.               push      di
  279.               push      es
  280.               pushf
  281.               push      ds
  282.               push      ds
  283. ;
  284. ; Load stack with values to go into registers
  285. ;
  286.               les       bx,[bp+6]
  287.               cmp       es:[bx].r_ds_valid,TRUE
  288.               jnz       devh1000
  289.               mov       ax,es:[bx].r_ds
  290.               push      ax
  291.               jmp       devh2000
  292. devh1000:
  293.               push      ds
  294. ;
  295. devh2000:
  296. ;
  297.               mov       ax,es:[bx].r_ax
  298.               push      ax
  299.               mov       ax,es:[bx].r_bx
  300.               push      ax
  301.               mov       ax,es:[bx].r_cx
  302.               push      ax
  303.               mov       ax,es:[bx].r_dx
  304.               push      ax
  305.               mov       ax,es:[bx].r_si
  306.               push      ax
  307.               mov       ax,es:[bx].r_di
  308.               push      ax
  309. ;
  310. ; load registers from the stack
  311. ;
  312.               pop       di
  313.               pop       si
  314.               pop       dx
  315.               pop       cx
  316.               pop       bx
  317.               pop       ax
  318.               pop       ds
  319.               pop       es
  320. ;
  321. ; call OS/2 DevHlp
  322. ;
  323.               call      es:_devhlp
  324. ;
  325. ; Save return values in output structure
  326. ;
  327.               push      ds
  328.               pushf
  329.               push      bx
  330.               lds       bx,[bp+10]
  331.               mov       [bx].r_ax,ax
  332.               pop       ax
  333.               mov       [bx].r_bx,ax
  334.               pop       ax
  335.               mov       [bx].r_flags,ax
  336.               pop       ax
  337.               mov       [bx].r_ds,ax
  338.               push      es
  339.               pop       ax
  340.               mov       [bx].r_es,ax
  341.               mov       [bx].r_cx,cx
  342.               mov       [bx].r_dx,dx
  343.               mov       [bx].r_di,di
  344.               mov       [bx].r_si,si
  345.               mov       [bx].r_es_valid,TRUE
  346.               mov       [bx].r_ds_valid,TRUE
  347. ;
  348. ; Restore entry regs
  349. ;
  350.               pop       ds
  351.               popf
  352.               pop       es
  353.               pop       di
  354.               pop       si
  355.               pop       dx
  356.               pop       cx
  357.               pop       bx
  358.               pop       ax
  359. ;
  360. ; Return to caller
  361. ;
  362.               pop       bp
  363.               ret
  364. ;
  365. _dev_help1    endp
  366.               PAGE
  367. INITSEG       ENDS
  368. ;
  369.               END
  370.