home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 210_01 / newxbios.cug < prev    next >
Encoding:
Text File  |  1979-12-31  |  10.8 KB  |  246 lines

  1. ..version for C Users' Group--single spaced
  2. .HE LOADABLE BIOS EXTENSIONS FOR CP/M 2.2       Ted Carnevale 9/20/86
  3.      An article by Cal Sondgeroth in Micro/Systems Journal (vol.1 
  4. #2 pp.66-71, 1985) showed how easy it is to write loadable 
  5. drivers for CP/M 2.2 (BIOS extension modules).  I modified his 
  6. XBIOS and XLOAD programs so that:  utilities could tell what BIOS 
  7. extension modules had been loaded; extensions could be removed as 
  8. necessary without a cold boot; extensions could accommodate the 
  9. additional entries found in the BIOS jump tables of nonstandard, 
  10. enhanced BIOSs.  The files I submitted to the CUG consist of a 
  11. BIOS extension module and its loader in 8080 assembly language, 
  12. and a header file and two utility programs written in C for 
  13. working with these modules.  These files appeared with slight 
  14. modification in my article in the July/August 1986 issue of 
  15. Micro/Systems Journal (pp.72-85).
  16.  
  17.                   HOW THE BIOS EXTENSION WORKS
  18.  
  19.      How a BIOS extension module is loaded and how it intercepts 
  20. BIOS calls are described in the two articles in Micro/Systems 
  21. Journal.  These diagrams illustrate BIOS call interception.
  22.      This diagram represents the contents of RAM before a BIOS 
  23. extension module has been loaded:
  24.  
  25.                +-------------------+
  26.                |                   |
  27.                | BIOS              |
  28.                |                   |
  29.                |   - - - - - - -   |
  30.                | (BIOS jump table) |
  31.                |  .                |
  32.                | jmp old_const     |
  33. BIOS_ENTRY     | jmp old_wboot     |
  34.                | jmp old_boot      |
  35.                +-------------------+
  36. BDOS_ENTRY     | BDOS              |
  37.                +-------------------+
  38.                | CCP               |
  39.                +-------------------+
  40.                |                   |
  41.                | TPA               |
  42. 0100H          |                   |
  43.                +-------------------+
  44.                   .  
  45.                   .  
  46.                   .  
  47. 0005H          jmp BDOS_ENTRY
  48.                   .  
  49. 0000H          jmp BIOS_ENTRY
  50.  
  51.      When a BIOS extension module is loaded, it is relocated to 
  52. the top of the TPA, and a copy of the original BIOS's jump table 
  53. is written into it.  The table in the BIOS is modified to jump to 
  54. corresponding entries in the extension module (except for the 
  55. coldboot jump, which isn't worth saving).  Locations 6 and 7 are 
  56. changed to point to the start of the BIOS extension module, 
  57. thereby reducing the TPA and protecting the extension from being 
  58. overwritten by transient programs.  As a result the RAM contents 
  59. become
  60.  
  61.                +-------------------+
  62.                |                   |
  63.                | BIOS              |
  64.                |                   |
  65.                |   - - - - - - -   |
  66.                | (Modified table--jumps to special 
  67.                |  jump table in extension module)
  68.                |  .                |
  69.                | jmp new_const     |
  70. BIOS_ENTRY     | jmp new_wboot     |
  71.                | jmp old_boot      |
  72.                +-------------------+
  73. BDOS_ENTRY     | BDOS              |
  74.                +-------------------+
  75.                | CCP               |
  76.                +-------------------+
  77.                |                   |
  78.                |  BIOS extension   |
  79.                |                   |
  80.                |   - - - - - - -   |
  81.                | (special warm     |
  82. xwboot:        |  boot routine)    |
  83.                |   - - - - - - -   |
  84.                |                   |
  85.                   .
  86.                  (Special table--jumps to copy of original BIOS 
  87.                   jump table, or to drivers in this extension 
  88.                   module)
  89.                   .
  90. new_const:       jmp . . .    ;to special driver or dup_const
  91. new_wboot:       jmp xwboot   ;to special warm boot routine
  92.                 (Top of copy of original BIOS jump table)
  93.                   .
  94. dup_const:       jmp old_const
  95. dup_wboot:       jmp old_wboot
  96.                 (Bottom of copy of original BIOS jump table)
  97.                   .
  98.                   .
  99.                |                   |
  100. XBIOS_ENTRY    | jmp BDOS_ENTRY    |
  101.                +-------------------+
  102.                |                   |
  103.                | TPA               |
  104. 0100H          |                   |
  105.                +-------------------+
  106.                   .  
  107.                   .  
  108.                   .  
  109. 0005H          jmp XBIOS_ENTRY
  110.                   .  
  111. 0000H          jmp BIOS_ENTRY
  112.  
  113.      When a BIOS service call is made in the presence of such an 
  114. extension module, the modified jump table in the BIOS transfers 
  115. the request to the BIOS extension module.  Here the call may be 
  116. passed on to the original BIOS routine, or diverted to a special 
  117. driver in the extension module instead.  In this example, a call 
  118. to BIOS function LIST is served by the original BIOS code, but 
  119. the PUNCH function is handled by a new driver:
  120.  
  121.                +-------------------+
  122.                |                   |
  123.                | BIOS              |
  124.                |                   |
  125.                |   - - - - - - -   |
  126.                | (Modified table--jumps to special 
  127.                |  jump table in extension module)
  128.                |  .                |
  129.                | jmp new_punch     |
  130.                | jmp new_list      |
  131.                |  .                |
  132. BIOS_ENTRY     | jmp new_wboot     |
  133.                | jmp old_boot      |
  134.                +-------------------+
  135.                |                   |
  136.                   .
  137.                   .
  138.                   .
  139.                |                   |
  140.                |  BIOS extension   |
  141.                |                   |
  142. xpunch:          (start of code for special punch driver)
  143.                   .
  144.                  (Special table--jumps to copy of original BIOS 
  145.                   jump table, or to drivers in this extension 
  146.                   module)
  147.                   .
  148. new_punch:       jmp xpunch   ;to special driver
  149. new_list:        jmp dup_list ;eventually to original driver
  150.                   .
  151. new_wboot:       jmp xwboot   ;to special warm boot routine
  152.                 (Top of copy of original BIOS jump table)
  153.                   .
  154. dup_list:        jmp old_list ;to original list driver
  155.                   .
  156. dup_wboot:       jmp old_wboot
  157.                 (Bottom of copy of original BIOS jump table)
  158.                   .
  159.                   .
  160.  
  161.  
  162.      Several BIOS extension modules can be loaded, one after 
  163. another.  Jumps to BIOS routines (except for warm and cold boot) 
  164. pass through all of the extension modules, until they are 
  165. intercepted by a special driver or the orignal code in the BIOS 
  166. is reached.
  167.  
  168.                     LOADING A BIOS EXTENSION
  169.  
  170.      The source code for the BIOS extension must be assembled to 
  171. a REL file, which is then loaded with Digital Research's LINK.COM 
  172. to produce an SPR file using LINK's "OS" option switch:
  173.  
  174.      LINK NUXB[OS]
  175.  
  176. A special loader program (source in LXB.ASM) installs the BIOS 
  177. extension into place at the top of the TPA, copies the original 
  178. BIOS's jump table, patches the original table, and alters 
  179. locations 0006-0007H.  Relocation is governed by the bit map at 
  180. the end of the SPR file.  If necessary, LXB could be modified to 
  181. accommodate .PRL files instead.
  182.  
  183.               DETAILS OF THE BIOS EXTENSION MODULE
  184.  
  185.      LXB and NUXB are based on Sondgeroth's XLOAD and XBIOS 
  186. programs.  I revised them so the extension module contains data 
  187. for utility programs that need to know if a BIOS extension is 
  188. installed.  I also wrote two other programs in C (described 
  189. below) that identify what modules have been loaded, and in what 
  190. order, and enable their removal one at a time without a cold 
  191. boot.
  192.      NUXB is an example of a BIOS extension module.  It begins 
  193. with a 32 byte header that contains certain useful items (see 
  194. NUXB.ASM).  After the module is loaded, its first three bytes 
  195. will be "jmp bdos."
  196.      The fourth and fifth bytes allow the design of generalized 
  197. utilities to handle BIOS extension modules.  The BIOS extension 
  198. loader (see LXB.ASM) and other utilities use the fourth byte to 
  199. find where the jump tables begin.  Its value equals the total 
  200. length of the "version" and "function" strings (see below), which 
  201. must be 255 or fewer bytes.
  202.      The fifth byte in the header specifies how many jump 
  203. instructions are to be copied from the BIOS into the BIOS 
  204. extension.  This accommodates "enhanced" BIOSs that have jump 
  205. tables with additional functions.
  206.      Bytes 6-16 are presently unused.  Bytes 17-32 contain the 
  207. string "xbios installed$" which is shown on the console at every 
  208. warm boot.  It is also checked by utilities to verify that a BIOS 
  209. extension is in place.
  210.      The data area that follows the header contains "version" and 
  211. "function" strings that tell the date and revision number of the 
  212. BIOS extension, and what it does.  These strings are terminated 
  213. by nulls for ease of use with C programs.
  214.      The copy of the previous contents of the BIOS jump table 
  215. comes next (OLDTBL), followed by the BIOS extension's own jump 
  216. table.
  217.      NUXB and LXB were not designed for interception of BDOS 
  218. calls.  One way to do this might be to use the first two reserved 
  219. bytes in the BIOS extension header as storage for the BDOS entry 
  220. address, and change the first three bytes in the header to a jump 
  221. to a BDOS intercept routine in the extension module itself.  If 
  222. BDOS calls are to be simply passed on to the BDOS, the intercept 
  223. routine might just be LHLD RESERV ! PCHL.  Otherwise, the value 
  224. in register C would be tested and the appropriate action taken.  
  225. If this approach to BDOS intercepts is used, the loader would 
  226. have to be revised to patch the BDOS address into the appropriate 
  227. location in the header.
  228.  
  229.              UTILITIES FOR USE WITH BIOS EXTENSIONS
  230.  
  231.      Two utilities for dealing with these BIOS extension modules 
  232. are CXB.C and RXB.C.  XB.H contains definitions used by both CXB 
  233. and RXB.  The structures xbhdr and cpmhdr summarize the 
  234. significance and contents of key locations at the beginning of 
  235. the BIOS extension module and at the base of CP/M.
  236.      These programs were written for the Software Toolworks C80 
  237. compiler, but should run with little or no change with any other 
  238. compiler.  CXB and RXB test for the presence of a BIOS extension 
  239. by looking for the string "xbios installed$".  CXB reports the 
  240. starting address and the version and function strings of all BIOS 
  241. extensions that have been installed starting with the one lowest 
  242. in memory (i.e. the one most recently loaded).  RXB removes the 
  243. most recently installed BIOS extension module, leaving the rest 
  244. in place.  It fixes locations 0006-0007H and restores the BIOS's 
  245. jump table from the copy in the BIOS extension lowest in memory.
  246.