2 ** Sample autoboot code fragment
4 ** These are the calling conventions for the Diag routine
6 ** A7 -- points to at least 2K of stack
9 ** A3 -- your board's ConfigDev structure
10 ** A2 -- Base of diag/init area that was copied
11 ** A0 -- Base of your board
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.
18 INCLUDE "exec/types.i"
19 INCLUDE "exec/nodes.i"
20 INCLUDE "exec/resident.i"
21 INCLUDE "libraries/configvars.i"
22 INCLUDE "libraries/expansionbase.i"
24 ; LVO's resolved by linking with library amiga.lib
30 * ROMINFO defines whether you want the AUTOCONFIG information in
31 * the beginning of your ROM (set to 0 if you instead have PALS
32 * providing the AUTOCONFIG information instead)
34 * ROMOFFS is the offset from your board base where your ROMs appear.
35 * Your ROMs might appear at offset 0 and contain your AUTOCONFIG
36 * information in the high nibbles of the first $40 words ($80 bytes).
37 * Or, your autoconfig ID information may be in a PAL, with your
38 * ROMs possibly being addressed at some offset (for example $2000)
39 * from your board base. This ROMOFFS constant will be used as an
40 * additional offset from your configured board address when patching
41 * structures which require absolute pointers to ROM code or data.
43 *----- We'll store Version and Revision in serial number
44 VERSION EQU 37 ; also the high word of serial number
45 REVISION EQU 1 ; also the low word of serial number
47 * See the Addison-Wesley Amiga Hardware Manual for more info.
49 MANUF_ID EQU 2011 ; CBM assigned (2011 for hackers only)
50 PRODUCT_ID EQU 1 ; Manufacturer picks product ID
52 BOARDSIZE EQU $10000 ; How much address space board decodes
53 SIZE_FLAG EQU 3 ; Autoconfig 3-bit flag for BOARDSIZE
54 ; 0=$800000(8meg) 4=$80000(512K)
55 ; 1=$10000(64K) 5=$100000(1meg)
56 ; 2=$20000(128K) 6=$200000(2meg)
57 ; 3=$40000(256K) 7=$400000(4meg)
66 OpenResource EQU -$1F2
76 PiSCSIAddr1 EQU $80000010
77 PiSCSIAddr2 EQU $80000014
78 PiSCSIAddr3 EQU $80000018
79 PiSCSIAddr4 EQU $8000001C
80 PiSCSIDebugMe EQU $80000020
81 PiSCSIDriver EQU $80000040
82 PiSCSINextPart EQU $80000044
83 PiSCSIGetPart EQU $80000048
84 PiSCSIGetPrio EQU $8000004C
85 PiSCSIGetFS EQU $80000060
86 PiSCSINextFS EQU $80000064
87 PiSCSICopyFS EQU $80000068
88 PiSCSIFSSize EQU $8000006C
89 PiSCSISetFSH EQU $80000070
90 PiSCSIDbg1 EQU $80001010
91 PiSCSIDbg2 EQU $80001014
92 PiSCSIDbg3 EQU $80001018
93 PiSCSIDbg4 EQU $8000101C
94 PiSCSIDbg5 EQU $80001020
95 PiSCSIDbg6 EQU $80001024
96 PiSCSIDbg7 EQU $80001028
97 PiSCSIDbg8 EQU $8000102C
98 PiSCSIDbgMsg EQU $80001000
100 ******* RomStart ***************************************************
101 **********************************************************************
105 ******* DiagStart **************************************************
106 DiagStart: ; This is the DiagArea structure whose relative offset from
107 ; your board base appears as the Init Diag vector in your
108 ; autoconfig ID information. This structure is designed
109 ; to use all relative pointers (no patching needed).
110 dc.b DAC_WORDWIDE+DAC_CONFIGTIME ; da_Config
113 dc.w DiagEntry-DiagStart ; da_DiagPoint
114 dc.w BootEntry-DiagStart ; da_BootPoint
115 dc.w DevName-DiagStart ; da_Name
116 dc.w 0 ; da_Reserved01
117 dc.w 0 ; da_Reserved02
119 ******* Resident Structure *****************************************
121 dc.w RTC_MATCHWORD ; UWORD RT_MATCHWORD
122 rt_Match: dc.l Romtag-DiagStart ; APTR RT_MATCHTAG
123 rt_End: dc.l EndCopy-DiagStart ; APTR RT_ENDSKIP
124 dc.b RTW_COLDSTART ; UBYTE RT_FLAGS
125 dc.b VERSION ; UBYTE RT_VERSION
126 dc.b NT_DEVICE ; UBYTE RT_TYPE
127 dc.b 20 ; BYTE RT_PRI
128 rt_Name: dc.l DevName-DiagStart ; APTR RT_NAME
129 rt_Id: dc.l IdString-DiagStart ; APTR RT_IDSTRING
130 rt_Init: dc.l Init-RomStart ; APTR RT_INIT
133 ******* Strings referenced in Diag Copy area ************************
134 DevName: dc.b 'pi-scsi.device',0,0 ; Name string
135 IdString dc.b 'PISCSI v0.8',0 ; Id string
137 DosName: dc.b 'dos.library',0 ; DOS library name
138 ExpansionName: dc.b "expansion.library",0
139 LibName: dc.b "pi-scsi.device",0,0
141 DosDevName: dc.b 'ABC',0 ; dos device name for MakeDosNode()
142 ; (dos device will be ABC:)
146 ******* DiagEntry **************************************************
147 **********************************************************************
149 * success = DiagEntry(BoardBase,DiagCopy, configDev)
152 * Called by expansion architecture to relocate any pointers
153 * in the copied diagnostic area. We will patch the romtag.
154 * If you have pre-coded your MakeDosNode packet, BootNode,
155 * or device initialization structures, they would also need
156 * to be within this copy area, and patched by this routine.
158 **********************************************************************
165 move.l #1,PiSCSIDebugMe
166 move.l a3,PiSCSIAddr1
174 lea patchTable-RomStart(a0),a1 ; find patch table
175 adda.l #ROMOFFS,a1 ; adjusting for ROMOFFS
177 * Patch relative pointers to labels within DiagCopy area
178 * by adding Diag RAM copy address. These pointers were coded as
179 * long relative offsets from base of the DiagArea structure.
182 move.l a2,d1 ;d1=base of ram Diag copy
184 move.w (a1)+,d0 ;d0=word offs. into Diag needing patch
185 bmi.s bpatches ;-1 is end of word patch offset table
186 add.l d1,0(a2,d0.w) ;add DiagCopy addr to coded rel. offset
189 * Patches relative pointers to labels within the ROM by adding
190 * the board base address + ROMOFFS. These pointers were coded as
191 * long relative offsets from RomStart.
194 move.l a0,d1 ;d1 = board base address
195 add.l #ROMOFFS,d1 ;add offset to where your ROMs are
197 move.w (a1)+,d0 ;d0=word offs. into Diag needing patch
198 bmi.s endpatches ;-1 is end of patch offset table
199 add.l d1,0(a2,d0.w) ;add ROM address to coded relative offset
203 moveq.l #1,d0 ; indicate "success"
207 ******* BootEntry **************************************************
208 **********************************************************************
212 move.l #2,PiSCSIDebugMe
218 move.l RT_INIT(a0),a0
221 moveq.l #1,d0 ; indicate "success"
225 * End of the Diag copy area which is copied to RAM
228 *************************************************************************
230 *************************************************************************
232 * Beginning of ROM driver code and data that is accessed only in
233 * the ROM space. This must all be position-independent.
237 * Word offsets into Diag area where pointers need Diag copy address added
238 dc.w rt_Match-DiagStart
239 dc.w rt_End-DiagStart
240 dc.w rt_Name-DiagStart
244 * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
245 dc.w rt_Init-DiagStart
248 ******* Romtag InitEntry **********************************************
249 *************************************************************************
251 Init: ; After Diag patching, our romtag will point to this
252 ; routine in ROM so that it can be called at Resident
253 ; initialization time.
254 ; This routine will be similar to a normal expansion device
255 ; initialization routine, but will MakeDosNode then set up a
256 ; BootNode, and Enqueue() on eb_MountList.
259 move.l a6,-(a7) ; Push A6 to stack
260 move.w #$00B8,$dff09a ; Disable interrupts during init
261 move.l #3,PiSCSIDebugMe
262 move.l a3,PiSCSIAddr4
264 move.l #11,PiSCSIDebugMe
268 move.l #10,PiSCSIDebugMe
270 bne.s SkipDriverLoad ; Library is already loaded, jump straight to partitions
272 move.l #4,PiSCSIDebugMe
276 jsr AllocMem(a6) ; Allocate memory for the PiStorm to copy the driver to
278 move.l d0,PiSCSIDriver ; Copy the PiSCSI driver to allocated memory and patch offsets
280 move.l #5,PiSCSIDebugMe
285 jsr InitResident(a6) ; Initialize the PiSCSI driver
288 move.l #9,PiSCSIDebugMe
289 bra.w LoadFileSystems
292 lea ExpansionName(pc),a1
294 jsr OpenLibrary(a6) ; Open expansion.library to make this work, somehow
298 move.l #7,PiSCSIDebugMe
300 move.l PiSCSIGetPart,d0 ; Get the available partition in the current slot
301 beq.w EndPartitions ; If the next partition returns 0, there's no additional partitions
304 move.l d0,PiSCSISetFSH
305 move.l d0,PiSCSIAddr2 ; Put DeviceNode address in PiSCSIAddr2, because I'm useless
307 move.l PiSCSIGetPrio,d0
309 move.l PiSCSIAddr1,a1
311 * Uncomment these lines to test AddDosNode/Enqueue stuff
312 * Or comment them out all the way down to and including SkipEnqueue: to use the AddBootNode method instead.
316 * BOOL AddDosNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode );
317 * amicall(ExpansionBase, 0x96, AddDosNode(d0,d1,a0))
318 move.l #38,PiSCSIDebugMe
321 * VOID Enqueue( struct List *list, struct Node *node );
322 * amicall(SysBase, 0x10e, Enqueue(a0,a1))
326 move.l #35,PiSCSIDebugMe
327 move.l #BootNode_SIZEOF,PiSCSIDebugMe
328 move.l #NT_BOOTNODE,PiSCSIDebugMe
329 move.l #LN_TYPE,PiSCSIDebugMe
330 move.l #LN_PRI,PiSCSIDebugMe
331 move.l #LN_NAME,PiSCSIDebugMe
332 move.l #eb_MountList,PiSCSIDebugMe
333 move.l #35,PiSCSIDebugMe
335 move.l #BootNode_SIZEOF,d0
337 jsr AllocMem(a6) ; Allocate memory for the BootNode
339 move.l d0,PiSCSIAddr3
340 move.l #36,PiSCSIDebugMe
343 move.b #NT_BOOTNODE,LN_TYPE(a1)
344 move.l PiSCSIGetPrio,d0
346 move.l PiSCSIAddr2,bn_DeviceNode(a1)
347 move.l PiSCSIAddr1,LN_NAME(a1)
349 lea eb_MountList(a4),a0
355 * BOOL AddBootNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode, struct ConfigDev *configDev );
356 * amicall(ExpansionBase, 0x24, AddBootNode(d0,d1,a0,a1))
357 * Comment out the line below to test AddDosNode/Enqueue stuff
358 * jsr AddBootNode(a6)
359 move.l #1,PiSCSINextPart ; Switch to the next partition
364 move.l #8,PiSCSIDebugMe
366 move.l #800,PiSCSIDebugMe
368 move.l #801,PiSCSIDebugMe
370 move.l #802,PiSCSIDebugMe
372 move.l (a7)+,a6 ; Pop A6 from stack
373 move.l #803,PiSCSIDebugMe
375 move.w #$80B8,$dff09a ; Re-enable interrupts
376 move.l #804,PiSCSIDebugMe
377 moveq.l #1,d0 ; indicate "success"
378 move.l #805,PiSCSIDebugMe
382 FileSysName dc.b 'FileSystem.resource',0
383 FileSysCreator dc.b 'PiStorm',0
390 movem.l d0-d7/a0-a6,-(sp) ; Push registers to stack
391 move.l #30,PiSCSIDebugMe
393 lea FileSysName(pc),a1
398 move.l #33,PiSCSIDebugMe ; FileSystem.resource isn't open, create it
399 ; Code based on WinUAE filesys.asm
401 moveq #32,d0 ; sizeof(FileSysResource)
405 move.b #8,8(a2) ; NT_RESOURCE
406 lea FileSysName(pc),a0
407 move.l a0,10(a2) ; node name
408 lea FileSysCreator(pc),a0
409 move.l a0,14(a2) ; fsr_Creator
411 move.l a0,(a0) ; NewList() fsr_FileSysEntries
414 lea $150(a6),a0 ; ResourceList
416 jsr -$f6(a6) ; AddTail
421 move.l d0,PiSCSIAddr2 ; PiSCSIAddr2 is now FileSystem.resource
422 move.l #31,PiSCSIDebugMe
423 move.l PiSCSIAddr2,a0
424 move.l PiSCSIGetFS,d0
430 move.l #45,PiSCSIDebugMe
431 lea fsr_FileSysEntries(a0),a0
433 move.l LH_HEAD(a0),d0
437 move.l #34,PiSCSIDebugMe
439 move.l #35,PiSCSIDebugMe
440 cmp.l fse_DosType(a1),d7
441 move.l #36,PiSCSIDebugMe
443 move.l #37,PiSCSIDebugMe
444 move.l LN_SUCC(a1),d0
446 move.l #390,PiSCSIDebugMe
451 move.l #39,PiSCSIDebugMe
452 move.l PiSCSIFSSize,d0
453 move.l #40,PiSCSIDebugMe
455 move.l #41,PiSCSIDebugMe
457 move.l d0,PiSCSIAddr3
458 move.l #1,PiSCSICopyFS
461 move.l #480,PiSCSIDebugMe
462 move.l PiSCSIAddr2,a0
463 move.l #1,PiSCSINextFS
464 move.l PiSCSIGetFS,d0
469 FSDone: move.l #37,PiSCSIDebugMe
470 move.l #32,PiSCSIDebugMe ; Couldn't open FileSystem.resource, Kick 1.2/1.3?
472 movem.l (sp)+,d0-d7/a0-a6 ; Pop registers from stack