home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / libraries / expansion / autoboot.asm next >
Encoding:
Assembly Source File  |  1980-02-03  |  9.6 KB  |  232 lines

  1. **
  2. ** Sample autoboot code fragment
  3. *
  4. * Copyright (c) 1990 Commodore-Amiga, Inc.
  5. *
  6. * This example is provided in electronic form by Commodore-Amiga, Inc. for
  7. * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  8. * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  9. * information on the correct usage of the techniques and operating system
  10. * functions presented in this example.  The source and executable code of
  11. * this example may only be distributed in free electronic form, via bulletin
  12. * board or as part of a fully non-commercial and freely redistributable
  13. * diskette.  Both the source and executable code (including comments) must
  14. * be included, without modification, in any copy.  This example may not be
  15. * published in printed form or distributed with any commercial product.
  16. * However, the programming techniques and support routines set forth in
  17. * this example may be used in the development of original executable
  18. * software products for Commodore Amiga computers.
  19. * All other rights reserved.
  20. * This example is provided "as-is" and is subject to change; no warranties
  21. * are made.  All use is at your own risk.  No liability or responsibility
  22. * is assumed.
  23. *
  24. ** These are the calling conventions for Diag area
  25. **
  26. ** A7 -- points to at least 2K of stack
  27. ** A6 -- ExecBase
  28. ** A5 -- ExpansionBase
  29. ** A3 -- your board's ConfigDev structure
  30. ** A2 -- Base of diag/init area that was copied
  31. ** A0 -- Base of your board
  32. **
  33. ** Your Diag routine should return a non-zero value in D0 for success.
  34. ** If this value is NULL, then the diag/init area that was copied
  35. ** will be returned to the free memory pool.
  36. **
  37.  
  38.             INCLUDE "exec/types.i"
  39.             INCLUDE "exec/nodes.i"
  40.             INCLUDE "exec/resident.i"
  41.             INCLUDE "libraries/configvars.i"
  42.  
  43.             ; LVO's resolved by linking with library amiga.lib
  44.             XREF   _LVOFindResident
  45.  
  46. VERSION     EQU    1
  47. REVISION    EQU    4
  48.  
  49. ROMOFFS     EQU     $2000
  50.  
  51. * ROMOFFS is the offset from your board base where your ROMs appear.
  52. * Your ROMs might appear at offset 0 and contain your autoconfig ID
  53. * information in the high nibble of the first $40 words ($80 bytes).
  54. * Or, your autoconfig ID information may be in a PAL, with your
  55. * ROMs possibly being addressed at some offset (for example $2000)
  56. * from your board base.  This ROMOFFS constant will be used as an
  57. * additional offset from your configured board address when patching 
  58. * structures which require absolute pointers to ROM code or data.
  59.  
  60.     section code
  61.  
  62. *******  RomStart  ***************************************************
  63. **********************************************************************
  64. RomStart:
  65.  
  66. * This is the start of your ROM.
  67. * If your ROMOFFS is 0 and you have $40 words of autoconfig ID
  68. * information here, it will look something like the this: 
  69. *
  70. * MANUF_ID     EQU   2011    ; CBM assigned (2011 for hackers only)
  71. * PRODUCT_ID   EQU   1       ; Manufacturer picks product ID
  72. *
  73. * SIZE_FLAG    EQU   3       ; Autoconfig 3-bit flag for BOARDSIZE
  74. *               ;   0=$800000(8meg)  4=$80000(512K)
  75. *               ;   1=$10000(64K)    5=$100000(1meg)
  76. *               ;   2=$20000(128K)   6=$200000(2meg)
  77. *               ;   3=$40000(256K)   7=$400000(4meg)
  78. *
  79. * Start of $40 words of autoconfig ID information:
  80. *
  81. *    ; High nibbles of first two words ($00,$02) are er_Type (not inverted)
  82. *            DC.W   $D000     ; 11xx = normal type
  83. *                             ; xx0x = not a memory board
  84. *                             ; xxx1 = we have a ROM driver
  85. *             
  86. *            DC.W   (SIZE_FLAG<<12)&$7000   ; 0xxx = not chained req
  87. *                                           ; xNNN = size flag above
  88. *
  89. *    ; High nibbles of next two words are er_Product
  90. *    ; These are inverted (~), as are all other words except $40 and $42
  91. *            DC.W   (~(PRODUCT_ID<<8))&$f000
  92. *            DC.W   (~(PRODUCT_ID<<12))&$f000
  93. *
  94. * etc. ($40 words at even addresses $00 through $7E)
  95. * See the Addison-Wesley Amiga Hardware Manual for more info.
  96.  
  97.  
  98. *******  DiagStart  **************************************************
  99. DiagStart:  ; This is the DiagArea structure whose relative offset from
  100.             ; your board base appears as the Init Diag vector in your
  101.             ; autoconfig ID information.  This structure is designed
  102.             ; to use all relative pointers (no patching needed).
  103.             dc.b    DAC_WORDWIDE+DAC_CONFIGTIME    ; da_Config
  104.             dc.b    0                              ; da_Flags
  105.             dc.w    EndCopy-DiagStart              ; da_Size
  106.             dc.w    DiagEntry-DiagStart            ; da_DiagPoint
  107.             dc.w    BootEntry-DiagStart            ; da_BootPoint
  108.             dc.w    DevName-DiagStart              ; da_Name
  109.             dc.w    0                              ; da_Reserved01
  110.             dc.w    0                              ; da_Reserved02
  111.  
  112. *******  Resident Structure  *****************************************
  113. Romtag:
  114.             dc.w    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
  115. rt_Match:   dc.l    Romtag-DiagStart   ; APTR  RT_MATCHTAG
  116. rt_End:     dc.l    EndCopy-DiagStart  ; APTR  RT_ENDSKIP
  117.             dc.b    RTW_COLDSTART      ; UBYTE RT_FLAGS
  118.             dc.b    VERSION            ; UBYTE RT_VERSION
  119.             dc.b    NT_DEVICE          ; UBYTE RT_TYPE
  120.             dc.b    20                 ; BYTE  RT_PRI
  121. rt_Name:    dc.l    DevName-DiagStart  ; APTR  RT_NAME
  122. rt_Id:      dc.l    IdString-DiagStart ; APTR  RT_IDSTRING
  123. rt_Init:    dc.l    Init-RomStart      ; APTR  RT_INIT
  124.  
  125.  
  126. DevName:    dc.b    'abc.device',0                      ; Name string
  127. IdString    dc.b    'abc ',48+VERSION,'.',48+REVISION   ; Id string
  128.   
  129. DosName:    dc.b    'dos.library',0                ; DOS library name
  130.  
  131. DosDevName: dc.b    'ABC',0        ; dos device name for MakeDosNode()
  132.                                    ;   (dos device will be ABC:)
  133.  
  134.             ds.w    0              ; word align
  135.  
  136. *******  DiagEntry  **************************************************
  137. **********************************************************************
  138. *
  139. *   success = DiagEntry(BoardBase,DiagCopy, configDev)
  140. *   d0                  a0         a2                  a3
  141. *
  142. *   Called by expansion architecture to relocate any pointers
  143. *   in the copied diagnostic area.   We will patch the romtag.
  144. *   If you have pre-coded your MakeDosNode packet, BootNode, 
  145. *   or device initialization structures, they would also need
  146. *   to be within this copy area, and patched by this routine.
  147. *
  148. **********************************************************************
  149.  
  150. DiagEntry:
  151.             lea      patchTable-RomStart(a0),a1   ; find patch table
  152.             adda.l   #ROMOFFS,a1                  ; adjusting for ROMOFFS
  153.  
  154. * Patch relative pointers to labels within DiagCopy area
  155. * by adding Diag RAM copy address.  These pointers were coded as
  156. * long relative offsets from base of the DiagArea structure.
  157. dpatches:
  158.             move.l   a2,d1           ;d1=base of ram Diag copy
  159. dloop:
  160.             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
  161.             bmi.s    bpatches        ;-1 is end of word patch offset table
  162.             add.l    d1,0(a2,d0.w)   ;add DiagCopy addr to coded rel. offset
  163.             bra.s    dloop
  164.  
  165. * Patches relative pointers to labels within the ROM by adding
  166. * the board base address + ROMOFFS.  These pointers were coded as
  167. * long relative offsets from RomStart.
  168. bpatches:
  169.             move.l   a0,d1           ;d1 = board base address
  170.             add.l    #ROMOFFS,d1     ;add offset to where your ROMs are
  171. rloop:
  172.             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
  173.             bmi.s   endpatches       ;-1 is end of patch offset table
  174.             add.l   d1,0(a2,d0.w)    ;add ROM address to coded relative offset
  175.             bra.s   rloop
  176.  
  177. endpatches:
  178.             moveq.l #1,d0           ; indicate "success"
  179.             rts
  180.  
  181.  
  182. *******  BootEntry  **************************************************
  183. **********************************************************************
  184.  
  185. BootEntry:  lea     DosName(PC),a1          ; 'dos.library',0
  186.             jsr     _LVOFindResident(a6)    ; find the DOS resident tag
  187.             move.l  d0,a0                   ; in order to bootstrap
  188.             move.l  RT_INIT(A0),a0          ; set vector to DOS INIT
  189.             jsr     (a0)                    ; and initialize DOS
  190.             rts
  191.  
  192. *
  193. * End of the Diag copy area which is copied to RAM
  194. *
  195. EndCopy:
  196. *************************************************************************
  197.  
  198. *************************************************************************
  199. *
  200. *   Beginning of rom driver code and data that is accessed only in
  201. *   the rom space.  This must all be position-independent.
  202. *
  203.  
  204. patchTable:
  205. * Word offsets into Diag area where pointers need Diag copy address added
  206.             dc.w   rt_Match-DiagStart
  207.             dc.w   rt_End-DiagStart
  208.             dc.w   rt_Name-DiagStart
  209.             dc.w   rt_Id-DiagStart
  210.             dc.w   -1
  211.  
  212. * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
  213.             dc.w   rt_Init-DiagStart
  214.             dc.w   -1
  215.  
  216. *******  Romtag InitEntry  **********************************************
  217. *************************************************************************
  218.  
  219. Init:       ; After Diag patching, our romtag will point to this 
  220.             ; routine in ROM so that it can be called at Resident
  221.             ; initialization time.
  222.             ; This routine will be similar to a normal expansion device
  223.             ; initialization routine, but will MakeDosNode then set up a
  224.             ; BootNode, and Enqueue() on eb_MountList. 
  225.             ;
  226.             rts
  227.  
  228.             ; Rest of your position-independent device code goes here.
  229.  
  230.             END
  231.