home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cdrom.zip / DDK / BASE / SRC / VDEV / VCDROM / cdstub.asm next >
Assembly Source File  |  1996-06-18  |  12KB  |  370 lines

  1. PAGE    ,132
  2. NAME    CDROMSTUB
  3. TITLE   CDROM stub device driver
  4. ;/*****************************************************************************
  5. ;*
  6. ;* SOURCE FILE NAME = CDSTUB.ASM
  7. ;*
  8. ;* DESCRIPTIVE NAME = CDROM VDD V86 box stub driver
  9. ;*
  10. ;* COPYRIGHT    COPYRIGHT IBM CORPORATION, 1991, 1992
  11. ;*              Copyright Microsoft Corporation, 1990
  12. ;*              LICENSED MATERIAL - PROGRAM PROPERTY OF IBM
  13. ;*              REFER TO COPYRIGHT INSTRUCTION FORM#G120-2083
  14. ;*              RESTRICTED MATERIALS OF IBM
  15. ;*              IBM CONFIDENTIAL
  16. ;*
  17. ;* VERSION      V2.0
  18. ;*
  19. ;* DATE         08-21-91
  20. ;*
  21. ;* DESCRIPTION  small V86 CDROM stub device driver
  22. ;*
  23. ;* FUNCTIONS    The CDROM stub driver serves three purposes.
  24. ;*
  25. ;*              (1) To supply a device driver header that a DOS application
  26. ;*                  can find to determine whether CDROM is installed.
  27. ;*
  28. ;*              (2) To hook int 2fh, and forward those requests to VCDROM
  29. ;*                  through ARPL. We cannot hook int 2fh in VCDROMCreate
  30. ;*                  because the DOS kernel stomps over the interrupt table after
  31. ;*                  calling VCDROMCreate.
  32. ;*
  33. ;*              (3) To convert device driver requests other than init to
  34. ;*                  int 2F, function 1510h, and send them to VCDROM. This
  35. ;*                  support is for apps like Groliers that bypass MSCDEX,
  36. ;*                  and call the device driver directly.
  37. ;*
  38. ;*              This stub code will be copied to the VDM address space and
  39. ;*              installed by the VDD, not the loader.  It will be installed on
  40. ;*              a paragraph boundary.
  41. ;*
  42. ;* NOTES        NONE
  43. ;*
  44. ;* STRUCTURES   NONE
  45. ;*
  46. ;* EXTERNAL REFERENCES
  47. ;*
  48. ;*              NONE
  49. ;*
  50. ;* EXTERNAL FUNCTIONS
  51. ;*
  52. ;*              NONE
  53. ;*
  54. ;* CHANGE ACTIVITY =
  55. ;*   DATE      FLAG        APAR   CHANGE DESCRIPTION
  56. ;*   --------  ----------  -----  --------------------------------------
  57. ;*   mm/dd/yy  @Vr.mpppxx  xxxxx  xxxxxxx
  58. ;*   08/21/91  @V2.0DTF           created
  59. ;*
  60. ;*   08/11/92  @V2.0FJS00         Changed the dos stub device driver to
  61. ;*                                use ARPL to call VCDROM via int 2fh
  62. ;*                                instead of int 66h.
  63. ;*
  64. ;*   08/11/92  @V2.0FJS01         Changed the attribute word in header from
  65. ;*                                A800h to C800h.  Header was also missing
  66. ;*                                the last 4 bytes; reserved, drive letter,
  67. ;*                                and number of units supported.
  68. ;*
  69. ;*****************************************************************************/
  70.  
  71.         .8086           ; This is run in real mode
  72.  
  73. ;* ***LD+ CDROM DOS STUB DD data structures
  74. ;*
  75. ;*        DD header indicates character device, open allowed,
  76. ;*        and removable media.  OldInt2f stores the address to
  77. ;*        chain to at interrupt time.  NOTE: The header must
  78. ;*        be at the start of the segment.
  79. ;*
  80. ;*
  81.  
  82. DONE            equ     0100h
  83. Int2f           equ     2fh * 4h    ; hook vector 2f
  84. CDROM_FUNCTION  equ     015h        ; the MSCDEX CDROM function code
  85. VDDINTERFACE    equ     066h        ; Int vector for VDD interface
  86.  
  87. reqhdr   struc                      ; initialize header
  88.     rh_reqlen   db      ?
  89.     rh_unit     db      ?
  90.     rh_command  db      ?
  91.     rh_status   dw      ?
  92.     rh_rs2      db      8 dup (?)
  93.     rh_units    db      ?
  94.     rh_addr     dd      ?
  95.     rh_count    dw      ?
  96.     rh_rs3      dw      ?
  97. reqhdr ends
  98.  
  99. CODE    SEGMENT BYTE PUBLIC 'CODE'
  100.  
  101.         assume cs:CODE,ds:CODE,es:CODE
  102.  
  103.         org 0
  104.  
  105. ;*
  106. ;* When this is run through the makefile, CDROMStubStart will be the
  107. ;* start of the data block, and CDROMStubLength its length.
  108. ;*
  109. ;* The next few lines are used by an REXX script.
  110. ;*
  111. ;* #### HEADERFILE=cdstub.h
  112. ;* #### ENTRYPOINT=CDROMStubStart
  113. ;* #### LENGTH=CDROMStubLength
  114. ;*
  115. ;* #### BEGIN EXTRACTION
  116. ;* It is used by n REXX script to convert the listing file into an .ASM file.
  117. ;*
  118. ;* Standard Device Driver Header follows
  119.  
  120. Header      dd  -1              ; link to nxet driver; -1 = end of list
  121. Attrib      dw  0C800h          ; character, ioctl, ibm, removable
  122.             dw  Strategy        ; "Strategy" entry point
  123.             dw  Interrupt       ; "Interrupt" entry point
  124. patch1      LABEL byte          ; #### LABEL=CDROMDevName
  125.             db  'MSCD001 '      ; Device name, Grolliers app looks for it
  126.             dw  0               ; reserved (must be zero)
  127.             db  0               ; drive letter (must be zero)
  128. patch2      LABEL byte          ; #### LABEL=CDROMNumUnits
  129.             db  0               ; number of units supported
  130.  
  131. ; Global variables go here
  132.  
  133. ReqHdr      dd  ?               ; address of Request Header
  134. OldInt2f    dd  ?               ; old 2f handler address
  135. ctrladdr    dw  ?               ; offset to CDROMControl
  136.  
  137.  
  138. ;/***************************************************************************
  139. ;*
  140. ;* FUNCTION NAME = CDROMInt2f
  141. ;*
  142. ;* DESCRIPTION   = CDROM DOS STUB Int 2f handler
  143. ;*
  144. ;*      This function catches int 2fh's.  It only reacts to the following:
  145. ;*
  146. ;*              AH=15h
  147. ;*
  148. ;*      All other functions are passed down the chain.
  149. ;*
  150. ;*      NOTE:   At VDM creation time, VCDROM loads this device driver and hooks
  151. ;*              int 2fh.  VCDROM's int 2fh handler will not be called directly
  152. ;*              since the DOS kernel loads next, hooks int 2fh, and then
  153. ;*              initializes this DOS device driver.  The DOS kernel must be
  154. ;*              last in the int 2fh chain and does not pass int 2fh requests
  155. ;*              to VCDROM.  So, this DOS device driver at init time hooks int
  156. ;*              2fh ahead of the DOS kernel.  DOS applications that issue a
  157. ;*              MSCDEX int 2fh call will be trapped by the device driver's
  158. ;*              CDROMInt2f routine and sent to VCDROM VCDROMDosLink for
  159. ;*              processing.
  160. ;*
  161. ;*              GLOBAL EFFECTS:
  162. ;*              VCDROM modifies appropriate registers and request packet
  163. ;*                fields.
  164. ;*
  165. ;*              PSEUDOCODE:
  166. ;*              Call VCDROM through local device driver routine with ARPL
  167. ;*
  168. ;* INPUT         = AX = function call
  169. ;*
  170. ;* OUTPUT        = MSCDEX request serviced
  171. ;*
  172. ;* RETURN-NORMAL =
  173. ;* RETURN-ERROR  =
  174. ;*
  175. ;**************************************************************************/
  176.  
  177. CDROMInt2f proc far
  178.  
  179.         cmp     ah, CDROM_FUNCTION      ; MSCDEX function?
  180.         jne     short Int2fNextInt      ; nope, someone else service it
  181.  
  182.         sti
  183.         call    word ptr cs:[ctrladdr]  ; call vcdrom via device driver hook
  184.         iret
  185.  
  186. Int2fNextInt:
  187.         cli
  188.         jmp     cs:[OldInt2f]           ; chain to old handler
  189.  
  190. CDROMInt2f endp
  191.  
  192.  
  193. ;/***************************************************************************
  194. ;*
  195. ;* FUNCTION NAME = CDROMControl
  196. ;*
  197. ;* DESCRIPTION   = CDROM DOS STUB control function
  198. ;*
  199. ;*                 All CDROM calls get routed through here.
  200. ;*                 We simply jump to the ARPL we saved away;
  201. ;*                 the jump will eventually reach the VCDROM handler
  202. ;*                 which is sitting in protected mode.
  203. ;*
  204. ;*                 During initialization, the ARPL address will be
  205. ;*                 placed in the space labelled "patch0".
  206. ;*
  207. ;*                 The first several bytes are required by the specification.
  208. ;*
  209. ;*                 GLOBAL EFFECTS:
  210. ;*                 depends on which function was called
  211. ;*
  212. ;*                 METHOD:
  213. ;*                 Perform a short jump, followed by three nops, as required
  214. ;*                         by the specifications.
  215. ;*                 Fake an interrupt by pushing the flags, then performing
  216. ;*                         a far call.
  217. ;*
  218. ;* INPUT         = AH = function request number
  219. ;*                 other registers as appropriate
  220. ;*
  221. ;* OUTPUT        = depends on which function was called
  222. ;*
  223. ;* RETURN-NORMAL =
  224. ;* RETURN-ERROR  =
  225. ;*
  226. ;**************************************************************************/
  227.  
  228. CDROMControl    proc near
  229.         jmp     short CDROMControlEntry ; for "hookability"
  230.         nop                             ; NOTE: The jump must be a short
  231.         nop                             ;  jump to indicate the end of
  232.         nop                             ;  any hook chain.  The nop's
  233.                                         ;  allow a far jump to be
  234.                                         ;  patched in.
  235.  
  236. CDROMControlEntry:
  237.         pushf
  238.  
  239.         db      09ah                    ; far call
  240. patch0  LABEL   byte                    ; #### LABEL=CDROMPatch0
  241.         dd      ?                       ; This number will get patched
  242.                                         ; during installation.
  243.         ret
  244. CDROMControl    endp
  245.  
  246.  
  247. ;/***************************************************************************
  248. ;*
  249. ;* FUNCTION NAME = Strategy
  250. ;*
  251. ;* DESCRIPTION   = CDROM DOS STUB DD strategy handler
  252. ;*
  253. ;*                 This function is called by DOS whenever the driver is
  254. ;*                 accessed.
  255. ;*
  256. ;*                 GLOBAL EFFECTS:
  257. ;*                 ReqHdr  points to the request header
  258. ;*
  259. ;*                 PSEUDOCODE:
  260. ;*                 Save the address of the request packet in ReqHdr .
  261. ;*
  262. ;* INPUT         = ES:BX = Address of Request Header
  263. ;*
  264. ;* OUTPUT        = NONE
  265. ;*
  266. ;* RETURN-NORMAL =
  267. ;* RETURN-ERROR  =
  268. ;*
  269. ;**************************************************************************/
  270.  
  271. Strategy    proc far
  272.  
  273.         mov     word ptr cs:[ReqHdr], bx
  274.         mov     word ptr cs:[ReqHdr+2], es
  275.  
  276.         ret
  277.  
  278. Strategy    endp
  279.  
  280.  
  281. ;/***************************************************************************
  282. ;*
  283. ;* FUNCTION NAME = Interrupt
  284. ;*
  285. ;* DESCRIPTION   = CDROM DOS DD Stub interrupt routine
  286. ;*
  287. ;*                 This function is called by DOS after calling Strategy.
  288. ;*
  289. ;*                 PSEUDOCODE:
  290. ;*                 Initialize - Hook 2F and set the break address.
  291. ;*                 Convert all other commands to int 2F, function 1510h and
  292. ;*                   call VCDROM through int 66h.
  293. ;*
  294. ;* INPUT         = Request packet saved by Strategy
  295. ;*
  296. ;* OUTPUT        = Request serviced, status code set
  297. ;*
  298. ;* RETURN-NORMAL =
  299. ;* RETURN-ERROR  =
  300. ;*
  301. ;**************************************************************************/
  302.  
  303. Interrupt proc far
  304.  
  305.         push    ax
  306.         push    bx
  307.         push    es
  308.  
  309.         les     bx, cs:[ReqHdr]
  310.  
  311.         mov     word ptr es:[bx.rh_status], DONE
  312.         mov     al, es:[bx.rh_command]
  313.         or      al, al
  314.         jz      Initialize
  315.  
  316. ;* Support for apps that call the driver directly.
  317. ;* Convert into a 2f, function 1510h type request and send to vcdrom.
  318.  
  319.         push    cx                      ; es:bx -> req hdr
  320.         mov     ax, 1510h               ; 2f, send device request
  321.         xor     cx, cx                  ; cx=0 means drive letter not passed
  322.         call    word ptr cs:[ctrladdr]  ; call vcdrom via device driver hook
  323.         pop     cx
  324.  
  325. InterruptExit:
  326.         pop     es
  327.         pop     bx
  328.         pop     ax
  329.         ret
  330.  
  331.         ;* all code from here on is discarded after initialization
  332.  
  333. Initialize:                             ; cannot be a function
  334.  
  335.         mov     word ptr es:[bx.rh_status], DONE
  336.         mov     word ptr es:[bx.rh_addr], offset Initialize
  337.         mov     word ptr es:[bx.rh_addr+2], cs
  338.  
  339.         mov     ax, offset CDROMControl         ; REXX cannot perform fixups
  340.         mov     ctrladdr, ax                    ; must do it myself, sigh!
  341.  
  342.         xor     ax, ax                          ; hook the int 2fh handler
  343.         mov     es, ax
  344.  
  345.         cli
  346.  
  347.         mov     ax, cs
  348.         xchg    ax, word ptr es:[Int2f+2]
  349.         mov     word ptr [OldInt2f+2], ax
  350.  
  351.         mov     ax, offset CDROMInt2f
  352.         xchg    ax, word ptr es:[Int2f]
  353.         mov     word ptr [OldInt2f], ax
  354.  
  355.         sti
  356.         jmp     InterruptExit
  357.  
  358. Interrupt endp
  359.  
  360.  
  361. CDROMEnd    label   byte           ; This line is a dummy to keep
  362.                                    ; the REXX happy with the byte length count
  363.                                    ; PUT ALL DATA/CODE ABOVE THIS LABEL
  364. ;*
  365. ;* #### END EXTRACTION
  366. ;*
  367.  
  368. CODE    ends
  369.         end
  370.