home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / latrobe / b / biodif.arc / CACHECTL.ASM < prev    next >
Assembly Source File  |  1987-06-20  |  8KB  |  404 lines

  1.     PAGE    60,132
  2.     TITLE    MSDOS 2.0 Cache Control Routines
  3. ;++
  4. ;
  5. ;    FILE:        CACHECTL.ASM
  6. ;
  7. ;    FACILITY:    MS-DOS Drivers
  8. ;
  9. ;    ABSTRACT:
  10. ;
  11. ;        This is the set of routines that provide a disk cache
  12. ;        for the computer disk accesses.
  13. ;
  14. ;        It sets up far calls to the actual cache routines,
  15. ;        which are an additional driver stored in memory.
  16. ;
  17. ;        It is installed as an additional driver so it can
  18. ;        use MS-DOS to allocate memory for the cache buffers.
  19. ;
  20. ;    ENVIRONMENT:    Rainbow 100+
  21. ;
  22. ;    AUTHOR:        Richard Thomsen
  23. ;
  24. ;
  25. ;----------------------------------------------------------------------
  26. ;
  27. ;    CREATION DATE:    2 February 1987
  28. ;
  29. ;    MODIFIED BY:
  30. ;
  31. ;
  32. ;--
  33.  
  34. ;
  35. CGROUP    GROUP    CODE
  36. ;
  37. ;   Define the global entry points for this routine
  38. ;
  39.     PUBLIC    READ_BLOCK_FROM_CACHE    ;Routine to read cache
  40.     PUBLIC    WRITE_BLOCK_TO_CACHE    ;Routine to write cache
  41.     PUBLIC    INVALIDATE_DISK_CACHE    ;Routine to invalidate disk in cache
  42.     PUBLIC    INVALIDATE_HARD_DISK_CACHE    ;Routine to invalidate the
  43.                         ;hard disk in cache
  44.     PUBLIC    DISK_CACHE_TIMEOUT    ;Disk cache timeout
  45.     PUBLIC    CACHE_IOCTL        ;Routine to control cache
  46. ;
  47. ;   Include the Rainbow hard disk controller definition file
  48. ;
  49.     INCLUDE HCDEF.H
  50. ;
  51.  
  52. ;
  53. ;   Define the code and data segments
  54. ;
  55. CODE    SEGMENT        BYTE PUBLIC 'CODE'
  56.     ASSUME CS:CGROUP, DS:CGROUP
  57. ;
  58. ;   Define the externals used by this routine
  59. ;
  60. ;    EXTRN    None
  61. ;
  62. ;   Define the FAR entry points for the disk cache routines.
  63. ;    These will be overwritten when the cache is installed.
  64. ;
  65. DISK_ADR_SIZES        EQU    24        ;Size of addresses
  66. INV_DISK_CACHE_ADR     DD    DUMMY_RETURN
  67. INV_HARD_DISK_CACHE_ADR DD    DUMMY_RETURN
  68. DISK_CACHE_TIMEOUT_ADR    DD    DUMMY_RETURN
  69. READ_FROM_CACHE_ADR    DD    DUMMY_RETURN_CARRY_SET
  70. WRITE_TO_CACHE_ADR    DD    DUMMY_RETURN
  71. CACHE_IOCTL_ADR        DD    INSTALL_CACHE
  72. ;
  73. ;   Define the structure for the disk cache control call for installation
  74. ;    The addresses stored in the call must be in the same order as
  75. ;    the addresses above.
  76. ;
  77. DISK_CACHE_CTL        STRUC
  78. ;
  79. DCIE_FUNCTION        DB    ?    ;Function code  --  must be 10 (decimal)
  80. DCIE_DRIVE        DB    ?    ;Disk drive number (ignored)
  81. DCIE_SUB_FUNCTION    DB    ?    ;Sub-function  - must be zero
  82. DCIE_STATUS        DB    ?    ;Status code returned from function
  83. DCIE_INV_DISK_ADR    DD    ?    ;Function to invalidate disk
  84. DCIE_HINV_DISK_ADR    DD    ?    ;Function to inv hard disk
  85. DCIE_DISK_TIME_ADR    DD    ?    ;Function to decrement timeouts
  86. DCIE_READ_DISK_ADR    DD    ?    ;Function to read cache
  87. DCIE_WRITE_DISK_ADR    DD    ?    ;Function to write cache
  88. DCIE_IOCTL_ADR        DD    ?    ;Function to perform IOCTL functions
  89. ;
  90. DISK_CACHE_CTL        ENDS        ;End of structure
  91. ;
  92.  
  93. ;++
  94. ;
  95. ;   Function:    READ_BLOCK_FROM_CACHE
  96. ;
  97. ;   Abstract:
  98. ;
  99. ;    Read a block from the disk cache and write it to the user buffer.
  100. ;
  101. ;   Entry Parameters:
  102. ;
  103. ;    Reg AL        --  Code for disk for this block.
  104. ;    Reg DX        --  Logical sector number of this block.
  105. ;    Reg ES:DI    --  User buffer to be filled from disk cache.
  106. ;
  107. ;   Exit Parameters:
  108. ;
  109. ;    Carry        --  Set if block is not in cache.
  110. ;                Clear if block was filled from cache.
  111. ;    Reg ES:DI    --  If block was filled from cache,
  112. ;                then DI has been incremented to next
  113. ;                sector position.
  114. ;
  115. ;   Registers Changed:    DI
  116. ;
  117. ;
  118. ;--
  119. ;
  120. ;   Do a FAR call to the actual disk cache control routines.
  121. ;
  122. READ_BLOCK_FROM_CACHE    PROC    NEAR
  123.     CALL    CS:[READ_FROM_CACHE_ADR]    ;Read block from cache
  124.     RET                    ;And return to caller
  125. ;
  126. READ_BLOCK_FROM_CACHE    ENDP            ;End of procedure
  127. ;
  128.  
  129. ;++
  130. ;
  131. ;   Function:    WRITE_BLOCK_TO_CACHE
  132. ;
  133. ;   Abstract:
  134. ;
  135. ;    Write a block to the disk cache from the user buffer.
  136. ;
  137. ;   Entry Parameters:
  138. ;
  139. ;    Reg AL        --  Code for disk for this block.
  140. ;    Reg DX        --  Logical sector number of this block.
  141. ;    Reg ES:DI    --  User buffer to be copied to disk cache.
  142. ;
  143. ;   Exit Parameters:
  144. ;
  145. ;    None
  146. ;
  147. ;   Registers Changed:    None
  148. ;
  149. ;
  150. ;--
  151. ;
  152. ;   Do a FAR call to the actual disk cache control routines.
  153. ;
  154. WRITE_BLOCK_TO_CACHE    PROC    NEAR
  155.     CALL    CS:[WRITE_TO_CACHE_ADR]    ;Write block to cache
  156.     RET                ;And return to caller
  157. ;
  158. WRITE_BLOCK_TO_CACHE    ENDP        ;End of procedure
  159. ;
  160.  
  161. ;++
  162. ;
  163. ;   Function:    INVALIDATE_DISK_CACHE
  164. ;
  165. ;   Abstract:
  166. ;
  167. ;    Invalidate all blocks in the disk cache for a given disk.
  168. ;
  169. ;   Entry Parameters:
  170. ;
  171. ;    Reg AL        --  Code for disk for this block.
  172. ;
  173. ;   Exit Parameters:
  174. ;
  175. ;    None
  176. ;
  177. ;   Registers Changed:    None
  178. ;
  179. ;
  180. ;--
  181. ;
  182. ;   Do a FAR call to the actual disk cache control routines.
  183. ;
  184. INVALIDATE_DISK_CACHE    PROC    NEAR
  185.     CALL    CS:[INV_DISK_CACHE_ADR]    ;Invalidate disk in cache
  186.     RET                ;And return to caller
  187. ;
  188. INVALIDATE_DISK_CACHE    ENDP        ;End of procedure
  189. ;
  190.  
  191. ;++
  192. ;
  193. ;   Function:    INVALIDATE_HARD_DISK_CACHE
  194. ;
  195. ;   Abstract:
  196. ;
  197. ;    Invalidate all blocks in the disk cache for the hard disk.
  198. ;
  199. ;   Entry Parameters:
  200. ;
  201. ;    None
  202. ;
  203. ;   Exit Parameters:
  204. ;
  205. ;    None
  206. ;
  207. ;   Registers Changed:    None
  208. ;
  209. ;
  210. ;--
  211. ;
  212. ;   Do a FAR call to the actual disk cache control routines.
  213. ;
  214. INVALIDATE_HARD_DISK_CACHE    PROC    NEAR
  215.     CALL    CS:[INV_HARD_DISK_CACHE_ADR]    ;Invalidate hard disk in cache
  216.     RET                    ;And return to caller
  217. ;
  218. INVALIDATE_HARD_DISK_CACHE    ENDP        ;End of procedure
  219. ;
  220.  
  221. ;++
  222. ;
  223. ;   Function:    DISK_CACHE_TIMEOUT
  224. ;
  225. ;   Abstract:
  226. ;
  227. ;    Timeout all disks that can timeout in the cache.
  228. ;
  229. ;   Entry Parameters:
  230. ;
  231. ;    None
  232. ;
  233. ;   Exit Parameters:
  234. ;
  235. ;    None
  236. ;
  237. ;   Registers Changed:    None
  238. ;
  239. ;
  240. ;--
  241. ;
  242. ;   Do a FAR call to the actual disk cache control routines.
  243. ;
  244. DISK_CACHE_TIMEOUT    PROC    NEAR
  245.     CALL    CS:[DISK_CACHE_TIMEOUT_ADR]    ;Timeout disks in cache
  246.     RET                    ;And return to caller
  247. ;
  248. DISK_CACHE_TIMEOUT    ENDP        ;End of procedure
  249. ;
  250.  
  251. ;++
  252. ;
  253. ;   Function:    CACHE_IOCTL
  254. ;
  255. ;   Abstract:
  256. ;
  257. ;    Perform user functions on the cache
  258. ;
  259. ;   Entry Parameters:
  260. ;
  261. ;    None
  262. ;
  263. ;   Exit Parameters:
  264. ;
  265. ;    None
  266. ;
  267. ;   Registers Changed:    None
  268. ;
  269. ;
  270. ;--
  271. ;
  272. ;   Do a FAR call to the actual disk cache control routines.
  273. ;
  274. CACHE_IOCTL    PROC    NEAR
  275.     CALL    CS:[CACHE_IOCTL_ADR]    ;Call cache IOCTL routine
  276.     RET                ;And return to caller
  277. ;
  278. CACHE_IOCTL    ENDP            ;End of procedure
  279. ;
  280.  
  281. ;++
  282. ;
  283. ;   Function:    DUMMY_RETURN_CARRY_SET
  284. ;
  285. ;   Abstract:
  286. ;
  287. ;    Provide a routine that sets carry and returns.
  288. ;    This will allow an address and operation without a cache.
  289. ;    When the cache is installed, the address of the actual
  290. ;    cache routine replaces the address of this routine.
  291. ;
  292. ;   Entry Parameters:
  293. ;
  294. ;    None
  295. ;
  296. ;   Exit Parameters:
  297. ;
  298. ;    Carry set
  299. ;
  300. ;   Registers Changed:    None
  301. ;
  302. ;
  303. ;--
  304. ;
  305. ;   Do nothing, except set carry.
  306. ;
  307. DUMMY_RETURN_CARRY_SET    PROC    FAR
  308.     STC                ;Set carry for block not found
  309.     RET                ;And just return to caller
  310. ;
  311. DUMMY_RETURN_CARRY_SET    ENDP        ;End of procedure
  312. ;
  313.  
  314. ;++
  315. ;
  316. ;   Function:    DUMMY_RETURN
  317. ;
  318. ;   Abstract:
  319. ;
  320. ;    Provide a routine that returns.
  321. ;    This will allow an address and operation without a cache.
  322. ;    When the cache is installed, the address of the actual
  323. ;    cache routine replaces the address of this routine.
  324. ;
  325. ;   Entry Parameters:
  326. ;
  327. ;    None
  328. ;
  329. ;   Exit Parameters:
  330. ;
  331. ;    None
  332. ;
  333. ;   Registers Changed:    None
  334. ;
  335. ;
  336. ;--
  337. ;
  338. ;   Do nothing.
  339. ;
  340. DUMMY_RETURN    PROC    FAR
  341.     RET                ;Just return to caller
  342. ;
  343. DUMMY_RETURN    ENDP            ;End of procedure
  344. ;
  345.  
  346. ;++
  347. ;
  348. ;   Function:    INSTALL_CACHE
  349. ;
  350. ;   Abstract:
  351. ;
  352. ;    Installation routine for the disk cache.
  353. ;
  354. ;   Entry Parameters:
  355. ;
  356. ;    ES:DI    --  Address of IOCTL packet.
  357. ;
  358. ;   Exit Parameters:
  359. ;
  360. ;    None
  361. ;
  362. ;   Registers Changed:    All
  363. ;
  364. ;
  365. ;--
  366. ;
  367. ;   Routine to install cache
  368. ;
  369. INSTALL_CACHE    PROC    FAR
  370.     MOV    AL,ES:[DI].DCIE_SUB_FUNCTION    ;Get sub-function
  371.     OR    AL,AL            ;See if zero
  372.     JZ    INSTALL_CACHE_110    ;If so, then install cache
  373. ;
  374. ;   Not the proper installation code  --  return error
  375. ;
  376.     MOV    ES:BYTE PTR [DI].DCIE_STATUS,0FFH    ;Return error code
  377.     RET                ;And return to caller
  378. ;
  379. ;   Proper installation code  --  install cache
  380. ;
  381. INSTALL_CACHE_110:
  382.     PUSH    ES            ;Save segment registers
  383.     PUSH    DS
  384.     MOV    AX,ES            ;Move reg ES to DS
  385.     MOV    DS,AX
  386.     MOV    AX,CS            ;Move reg CS to ES
  387.     MOV    ES,AX
  388.     LEA    SI,[DI].DCIE_INV_DISK_ADR ;Move address of disk addresses to SI
  389.     MOV    CX,DISK_ADR_SIZES    ;Get size of addresses to move
  390.     CLD                ;Set direction forward
  391.     REP    MOVSW            ;Copy addresses to memory
  392.     POP    DS            ;Restore segment registers
  393.     POP    ES
  394.     XOR    AX,AX            ;Set return code to success
  395.     MOV    ES:[DI].DCIE_STATUS,AL    ;Return function code
  396.     RET                ;And return to caller
  397. ;
  398. INSTALL_CACHE    ENDP            ;End of procedure
  399. ;
  400.  
  401. CODE    ENDS
  402.  
  403.     END
  404.