home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / Diag.asm < prev    next >
Encoding:
Assembly Source File  |  1992-08-21  |  10.5 KB  |  278 lines

  1. **
  2. ** Sample autoboot code fragment
  3. **
  4. ** These are the calling conventions for the Diag routine
  5. **
  6. ** A7 -- points to at least 2K of stack
  7. ** A6 -- ExecBase
  8. ** A5 -- ExpansionBase
  9. ** A3 -- your board's ConfigDev structure
  10. ** A2 -- Base of diag/init area that was copied
  11. ** A0 -- Base of your board
  12. **
  13. ** Your Diag routine should return a non-zero value in D0 for success.
  14. ** If this value is NULL, then the diag/init area that was copied
  15. ** will be returned to the free memory pool.
  16. **
  17.  
  18.             INCLUDE "exec/types.i"
  19.             INCLUDE "exec/nodes.i"
  20.             INCLUDE "exec/resident.i"
  21.             INCLUDE "libraries/configvars.i"
  22.  
  23.             ; LVO's resolved by linking with library amiga.lib
  24.             XREF   _LVOFindResident
  25.  
  26. ROMINFO     EQU      1
  27. ROMOFFS     EQU     $0
  28.  
  29. * ROMINFO defines whether you want the AUTOCONFIG information in
  30. * the beginning of your ROM (set to 0 if you instead have PALS
  31. * providing the AUTOCONFIG information instead)
  32. *
  33. * ROMOFFS is the offset from your board base where your ROMs appear.
  34. * Your ROMs might appear at offset 0 and contain your AUTOCONFIG
  35. * information in the high nibbles of the first $40 words ($80 bytes).
  36. * Or, your autoconfig ID information may be in a PAL, with your
  37. * ROMs possibly being addressed at some offset (for example $2000)
  38. * from your board base.  This ROMOFFS constant will be used as an
  39. * additional offset from your configured board address when patching
  40. * structures which require absolute pointers to ROM code or data.
  41.  
  42. *----- We'll store Version and Revision in serial number
  43. VERSION     EQU    37        ; also the high word of serial number
  44. REVISION    EQU    1        ; also the low word of serial number
  45.  
  46. * See the Addison-Wesley Amiga Hardware Manual for more info.
  47.  
  48. MANUF_ID    EQU    2011        ; CBM assigned (2011 for hackers only)
  49. PRODUCT_ID    EQU    1        ; Manufacturer picks product ID
  50.  
  51. BOARDSIZE    EQU    $40000          ; How much address space board decodes
  52. SIZE_FLAG    EQU    3        ; Autoconfig 3-bit flag for BOARDSIZE
  53.                     ;   0=$800000(8meg)  4=$80000(512K)
  54.                     ;   1=$10000(64K)    5=$100000(1meg)
  55.                     ;   2=$20000(128K)   6=$200000(2meg)
  56.                     ;   3=$40000(256K)   7=$400000(4meg)
  57.             CODE
  58.  
  59. *******  RomStart  ***************************************************
  60. **********************************************************************
  61.  
  62. RomStart:
  63.  
  64.     IFGT    ROMINFO
  65. ;
  66. ;   ExpansionRom structure
  67. ;
  68. ;   Note - If you implement your ExpansionRom and ExpansionControl
  69. ;   with PALS, then you can comment out everything until DiagStart:
  70. ;   (ie. Make ROMID EQU 0)
  71.  
  72. *    ; High nibbles of first two words ($00,$02) are er_Type (not inverted)
  73.                         ; er_Type
  74.         dc.w    $D000            ;   11xx normal board type
  75.                         ;   xx0x not in memory free list
  76.                         ;   xxx1 Diag valid (has driver)
  77.         dc.w    (SIZE_FLAG<<12)&$7000    ;   0xxx not chained
  78.                         ;   xnnn flags board size
  79.  
  80. *    ; High nibbles of next two words are er_Product
  81. *    ; These are inverted (~), as are all other words except $40 and $42
  82.  
  83.                         ; er_Product
  84.         dc.w    (~(PRODUCT_ID<<8))&$f000,(~(PRODUCT_ID<<12))&$f000
  85.  
  86.                         ; er_Flags
  87.         dc.w    (~$C000)&$f000        ;   ~1xxx board is moveable
  88.                         ;   ~x1xx board can't be shut up
  89.         dc.w    (~0)&$f000        ;
  90.  
  91.         dc.w    (~0)&$f000,(~0)&$f000    ; er_Reserved03
  92.  
  93.                         ; er_Manufacturer
  94.         dc.w    (~(MANUF_ID))&$f000,(~(MANUF_ID<<4))&$f000
  95.         dc.w    (~(MANUF_ID<<8))&$f000,(~(MANUF_ID<<12))&$f000
  96.  
  97.                         ; er_SerialNumber
  98.         dc.w    (~(VERSION))&$f000,(~(VERSION<<4))&$f000
  99.         dc.w    (~(VERSION<<8))&$f000,(~(VERSION<<12))&$f000
  100.         dc.w    (~(REVISION))&$f000,(~(REVISION<<4))&$f000
  101.         dc.w    (~(REVISION<<8))&$f000,(~(REVISION<<12))&$f000
  102.  
  103.                         ; er_InitDiagVec
  104.         dc.w    (~((DiagStart-RomStart)))&$f000
  105.         dc.w    (~((DiagStart-RomStart)<<4))&$f000
  106.         dc.w    (~((DiagStart-RomStart)<<8))&$f000
  107.         dc.w    (~((DiagStart-RomStart)<<12))&$f000
  108.  
  109.         dc.w    (~0)&$f000,(~0)&$f000    ; er_Reserved0c
  110.         dc.w    (~0)&$f000,(~0)&$f000    ; er_Reserved0d
  111.         dc.w    (~0)&$f000,(~0)&$f000    ; er_Reserved0e
  112.         dc.w    (~0)&$f000,(~0)&$f000    ; er_Reserved0f
  113.  
  114.     IFNE    *-RomStart-$40
  115.     FAIL    "ExpansionRom structure not the right size"
  116.     ENDC
  117.  
  118.         ;Note: nibbles $40 and $42 are not to be inverted
  119.         dc.w    (0)&$f000,(0)&$f000    ; ec_Interrupt (no interrupts)
  120.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved11
  121.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_BaseAddress (write only)
  122.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Shutup (write only)
  123.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved14
  124.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved15
  125.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved16
  126.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved17
  127.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved18
  128.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved19
  129.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved1a
  130.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved1b
  131.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved1c
  132.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved1d
  133.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved1e
  134.         dc.w    (~0)&$f000,(~0)&$f000    ; ec_Reserved1f
  135.  
  136.     IFNE    *-RomStart-$80
  137.     FAIL    "Expansion Control structure not the right size"
  138.     ENDC
  139.  
  140.     ENDC    ;ROMINFO
  141.  
  142. *******  DiagStart  **************************************************
  143. DiagStart:  ; This is the DiagArea structure whose relative offset from
  144.             ; your board base appears as the Init Diag vector in your
  145.             ; autoconfig ID information.  This structure is designed
  146.             ; to use all relative pointers (no patching needed).
  147.             dc.b    DAC_WORDWIDE+DAC_CONFIGTIME    ; da_Config
  148.             dc.b    0                              ; da_Flags
  149.             dc.w    EndCopy-DiagStart              ; da_Size
  150.             dc.w    DiagEntry-DiagStart            ; da_DiagPoint
  151.             dc.w    BootEntry-DiagStart            ; da_BootPoint
  152.             dc.w    DevName-DiagStart              ; da_Name
  153.             dc.w    0                              ; da_Reserved01
  154.             dc.w    0                              ; da_Reserved02
  155.  
  156. *******  Resident Structure  *****************************************
  157. Romtag:
  158.             dc.w    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
  159. rt_Match:   dc.l    Romtag-DiagStart   ; APTR  RT_MATCHTAG
  160. rt_End:     dc.l    EndCopy-DiagStart  ; APTR  RT_ENDSKIP
  161.             dc.b    RTW_COLDSTART      ; UBYTE RT_FLAGS
  162.             dc.b    VERSION            ; UBYTE RT_VERSION
  163.             dc.b    NT_DEVICE          ; UBYTE RT_TYPE
  164.             dc.b    20                 ; BYTE  RT_PRI
  165. rt_Name:    dc.l    DevName-DiagStart  ; APTR  RT_NAME
  166. rt_Id:      dc.l    IdString-DiagStart ; APTR  RT_IDSTRING
  167. rt_Init:    dc.l    Init-RomStart      ; APTR  RT_INIT
  168.  
  169.  
  170. ******* Strings referenced in Diag Copy area  ************************
  171. DevName:    dc.b    'abc.device',0                      ; Name string
  172. IdString    dc.b    'abc ',48+VERSION,'.',48+REVISION   ; Id string
  173.  
  174. DosName:    dc.b    'dos.library',0                ; DOS library name
  175.  
  176. DosDevName: dc.b    'ABC',0        ; dos device name for MakeDosNode()
  177.                                    ;   (dos device will be ABC:)
  178.  
  179.             ds.w    0              ; word align
  180.  
  181. *******  DiagEntry  **************************************************
  182. **********************************************************************
  183. *
  184. *   success = DiagEntry(BoardBase,DiagCopy, configDev)
  185. *   d0                  a0         a2                  a3
  186. *
  187. *   Called by expansion architecture to relocate any pointers
  188. *   in the copied diagnostic area.   We will patch the romtag.
  189. *   If you have pre-coded your MakeDosNode packet, BootNode,
  190. *   or device initialization structures, they would also need
  191. *   to be within this copy area, and patched by this routine.
  192. *
  193. **********************************************************************
  194.  
  195. DiagEntry:
  196.             lea      patchTable-RomStart(a0),a1   ; find patch table
  197.             adda.l   #ROMOFFS,a1                  ; adjusting for ROMOFFS
  198.  
  199. * Patch relative pointers to labels within DiagCopy area
  200. * by adding Diag RAM copy address.  These pointers were coded as
  201. * long relative offsets from base of the DiagArea structure.
  202. *
  203. dpatches:
  204.             move.l   a2,d1           ;d1=base of ram Diag copy
  205. dloop:
  206.             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
  207.             bmi.s    bpatches        ;-1 is end of word patch offset table
  208.             add.l    d1,0(a2,d0.w)   ;add DiagCopy addr to coded rel. offset
  209.             bra.s    dloop
  210.  
  211. * Patches relative pointers to labels within the ROM by adding
  212. * the board base address + ROMOFFS.  These pointers were coded as
  213. * long relative offsets from RomStart.
  214. *
  215. bpatches:
  216.             move.l   a0,d1           ;d1 = board base address
  217.             add.l    #ROMOFFS,d1     ;add offset to where your ROMs are
  218. rloop:
  219.             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
  220.             bmi.s   endpatches       ;-1 is end of patch offset table
  221.             add.l   d1,0(a2,d0.w)    ;add ROM address to coded relative offset
  222.             bra.s   rloop
  223.  
  224. endpatches:
  225.             moveq.l #1,d0           ; indicate "success"
  226.             rts
  227.  
  228.  
  229. *******  BootEntry  **************************************************
  230. **********************************************************************
  231.  
  232. BootEntry:  lea     DosName(PC),a1          ; 'dos.library',0
  233.             jsr     _LVOFindResident(a6)    ; find the DOS resident tag
  234.             move.l  d0,a0                   ; in order to bootstrap
  235.             move.l  RT_INIT(A0),a0          ; set vector to DOS INIT
  236.             jsr     (a0)                    ; and initialize DOS
  237.             rts
  238.  
  239. *
  240. * End of the Diag copy area which is copied to RAM
  241. *
  242. EndCopy:
  243. *************************************************************************
  244.  
  245. *************************************************************************
  246. *
  247. *   Beginning of ROM driver code and data that is accessed only in
  248. *   the ROM space.  This must all be position-independent.
  249. *
  250.  
  251. patchTable:
  252. * Word offsets into Diag area where pointers need Diag copy address added
  253.             dc.w   rt_Match-DiagStart
  254.             dc.w   rt_End-DiagStart
  255.             dc.w   rt_Name-DiagStart
  256.             dc.w   rt_Id-DiagStart
  257.             dc.w   -1
  258.  
  259. * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
  260.             dc.w   rt_Init-DiagStart
  261.             dc.w   -1
  262.  
  263. *******  Romtag InitEntry  **********************************************
  264. *************************************************************************
  265.  
  266. Init:       ; After Diag patching, our romtag will point to this
  267.             ; routine in ROM so that it can be called at Resident
  268.             ; initialization time.
  269.             ; This routine will be similar to a normal expansion device
  270.             ; initialization routine, but will MakeDosNode then set up a
  271.             ; BootNode, and Enqueue() on eb_MountList.
  272.             ;
  273.             rts
  274.  
  275.             ; Rest of your position-independent device code goes here.
  276.  
  277.             END
  278.