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
77 PiSCSIAddr1 EQU $80000010
78 PiSCSIAddr2 EQU $80000014
79 PiSCSIAddr3 EQU $80000018
80 PiSCSIAddr4 EQU $8000001C
81 PiSCSIDebugMe EQU $80000020
82 PiSCSIDriver EQU $80000040
83 PiSCSINextPart EQU $80000044
84 PiSCSIGetPart EQU $80000048
85 PiSCSIGetPrio EQU $8000004C
86 PiSCSIGetFS EQU $80000060
87 PiSCSINextFS EQU $80000064
88 PiSCSICopyFS EQU $80000068
89 PiSCSIFSSize EQU $8000006C
90 PiSCSISetFSH EQU $80000070
91 PiSCSILoadFS EQU $80000084
92 PiSCSIGetFSInfo EQU $80000088
93 PiSCSIDbg1 EQU $80001010
94 PiSCSIDbg2 EQU $80001014
95 PiSCSIDbg3 EQU $80001018
96 PiSCSIDbg4 EQU $8000101C
97 PiSCSIDbg5 EQU $80001020
98 PiSCSIDbg6 EQU $80001024
99 PiSCSIDbg7 EQU $80001028
100 PiSCSIDbg8 EQU $8000102C
101 PiSCSIDbgMsg EQU $80001000
103 ******* RomStart ***************************************************
104 **********************************************************************
108 ******* DiagStart **************************************************
109 DiagStart: ; This is the DiagArea structure whose relative offset from
110 ; your board base appears as the Init Diag vector in your
111 ; autoconfig ID information. This structure is designed
112 ; to use all relative pointers (no patching needed).
113 dc.b DAC_WORDWIDE+DAC_CONFIGTIME ; da_Config
116 dc.w DiagEntry-DiagStart ; da_DiagPoint
117 dc.w BootEntry-DiagStart ; da_BootPoint
118 dc.w DevName-DiagStart ; da_Name
119 dc.w 0 ; da_Reserved01
120 dc.w 0 ; da_Reserved02
122 ******* Resident Structure *****************************************
124 dc.w RTC_MATCHWORD ; UWORD RT_MATCHWORD
125 rt_Match: dc.l Romtag-DiagStart ; APTR RT_MATCHTAG
126 rt_End: dc.l EndCopy-DiagStart ; APTR RT_ENDSKIP
127 dc.b RTW_COLDSTART ; UBYTE RT_FLAGS
128 dc.b VERSION ; UBYTE RT_VERSION
129 dc.b NT_DEVICE ; UBYTE RT_TYPE
130 dc.b 20 ; BYTE RT_PRI
131 rt_Name: dc.l DevName-DiagStart ; APTR RT_NAME
132 rt_Id: dc.l IdString-DiagStart ; APTR RT_IDSTRING
133 rt_Init: dc.l Init-RomStart ; APTR RT_INIT
136 ******* Strings referenced in Diag Copy area ************************
137 DevName: dc.b 'pi-scsi.device',0,0 ; Name string
138 IdString dc.b 'PISCSI v0.8',0 ; Id string
140 DosName: dc.b 'dos.library',0 ; DOS library name
141 ExpansionName: dc.b "expansion.library",0
142 LibName: dc.b "pi-scsi.device",0,0
144 DosDevName: dc.b 'ABC',0 ; dos device name for MakeDosNode()
145 ; (dos device will be ABC:)
149 ******* DiagEntry **************************************************
150 **********************************************************************
152 * success = DiagEntry(BoardBase,DiagCopy, configDev)
155 * Called by expansion architecture to relocate any pointers
156 * in the copied diagnostic area. We will patch the romtag.
157 * If you have pre-coded your MakeDosNode packet, BootNode,
158 * or device initialization structures, they would also need
159 * to be within this copy area, and patched by this routine.
161 **********************************************************************
168 move.l #1,PiSCSIDebugMe
169 move.l a3,PiSCSIAddr1
177 lea patchTable-RomStart(a0),a1 ; find patch table
178 adda.l #ROMOFFS,a1 ; adjusting for ROMOFFS
180 * Patch relative pointers to labels within DiagCopy area
181 * by adding Diag RAM copy address. These pointers were coded as
182 * long relative offsets from base of the DiagArea structure.
185 move.l a2,d1 ;d1=base of ram Diag copy
187 move.w (a1)+,d0 ;d0=word offs. into Diag needing patch
188 bmi.s bpatches ;-1 is end of word patch offset table
189 add.l d1,0(a2,d0.w) ;add DiagCopy addr to coded rel. offset
192 * Patches relative pointers to labels within the ROM by adding
193 * the board base address + ROMOFFS. These pointers were coded as
194 * long relative offsets from RomStart.
197 move.l a0,d1 ;d1 = board base address
198 add.l #ROMOFFS,d1 ;add offset to where your ROMs are
200 move.w (a1)+,d0 ;d0=word offs. into Diag needing patch
201 bmi.s endpatches ;-1 is end of patch offset table
202 add.l d1,0(a2,d0.w) ;add ROM address to coded relative offset
206 moveq.l #1,d0 ; indicate "success"
210 ******* BootEntry **************************************************
211 **********************************************************************
215 move.l #2,PiSCSIDebugMe
221 move.l RT_INIT(a0),a0
224 moveq.l #1,d0 ; indicate "success"
228 * End of the Diag copy area which is copied to RAM
231 *************************************************************************
233 *************************************************************************
235 * Beginning of ROM driver code and data that is accessed only in
236 * the ROM space. This must all be position-independent.
240 * Word offsets into Diag area where pointers need Diag copy address added
241 dc.w rt_Match-DiagStart
242 dc.w rt_End-DiagStart
243 dc.w rt_Name-DiagStart
247 * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
248 dc.w rt_Init-DiagStart
251 ******* Romtag InitEntry **********************************************
252 *************************************************************************
254 Init: ; After Diag patching, our romtag will point to this
255 ; routine in ROM so that it can be called at Resident
256 ; initialization time.
257 ; This routine will be similar to a normal expansion device
258 ; initialization routine, but will MakeDosNode then set up a
259 ; BootNode, and Enqueue() on eb_MountList.
262 move.l a6,-(a7) ; Push A6 to stack
263 move.w #$00B8,$dff09a ; Disable interrupts during init
264 move.l #3,PiSCSIDebugMe
265 move.l a3,PiSCSIAddr4
270 move.l #$feffeeff,$10000040
276 move.l #$8000000,d0 ; Add some Z3 fast RAM if it hasn't been moved (Kick 1.3)
284 move.l #11,PiSCSIDebugMe
287 move.l #10,PiSCSIDebugMe
289 bne.s SkipDriverLoad ; Library is already loaded, jump straight to partitions
291 move.l #4,PiSCSIDebugMe
295 jsr AllocMem(a6) ; Allocate memory for the PiStorm to copy the driver to
297 move.l d0,PiSCSIDriver ; Copy the PiSCSI driver to allocated memory and patch offsets
299 move.l #5,PiSCSIDebugMe
304 jsr InitResident(a6) ; Initialize the PiSCSI driver
307 move.l #9,PiSCSIDebugMe
308 jsr LoadFileSystems(pc)
311 lea ExpansionName(pc),a1
313 jsr OpenLibrary(a6) ; Open expansion.library to make this work, somehow
317 move.l #7,PiSCSIDebugMe
319 move.l PiSCSIGetPart,d0 ; Get the available partition in the current slot
320 beq.w EndPartitions ; If the next partition returns 0, there's no additional partitions
323 ;cmp.l #0,PiSCSIGetFSInfo ; This does not work for some reason... not massively surprising...
326 ;move.l d0,PiSCSILoadFS ; Attempt to load the file system driver from data/fs
327 ;cmp.l #$FFFFFFFF,PiSCSIAddr4
330 ;jsr LoadFileSystems(pc)
333 move.l d0,PiSCSISetFSH
334 move.l d0,PiSCSIAddr2 ; Put DeviceNode address in PiSCSIAddr2, because I'm useless
336 move.l PiSCSIGetPrio,d0
338 move.l PiSCSIAddr1,a1
340 * Uncomment these lines to test AddDosNode/Enqueue stuff
341 * Or comment them out all the way down to and including SkipEnqueue: to use the AddBootNode method instead.
345 * BOOL AddDosNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode );
346 * amicall(ExpansionBase, 0x96, AddDosNode(d0,d1,a0))
347 move.l #38,PiSCSIDebugMe
350 * VOID Enqueue( struct List *list, struct Node *node );
351 * amicall(SysBase, 0x10e, Enqueue(a0,a1))
355 ;move.l #35,PiSCSIDebugMe
356 ;move.l #BootNode_SIZEOF,PiSCSIDebugMe
357 ;move.l #NT_BOOTNODE,PiSCSIDebugMe
358 ;move.l #LN_TYPE,PiSCSIDebugMe
359 ;move.l #LN_PRI,PiSCSIDebugMe
360 ;move.l #LN_NAME,PiSCSIDebugMe
361 ;move.l #eb_MountList,PiSCSIDebugMe
362 ;move.l #35,PiSCSIDebugMe
364 move.l #BootNode_SIZEOF,d0
366 jsr AllocMem(a6) ; Allocate memory for the BootNode
368 move.l d0,PiSCSIAddr3
369 move.l #36,PiSCSIDebugMe
372 move.b #NT_BOOTNODE,LN_TYPE(a1)
373 move.l PiSCSIGetPrio,d0
375 move.l PiSCSIAddr2,bn_DeviceNode(a1)
376 move.l PiSCSIAddr1,LN_NAME(a1)
378 lea eb_MountList(a4),a0
384 * BOOL AddBootNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode, struct ConfigDev *configDev );
385 * amicall(ExpansionBase, 0x24, AddBootNode(d0,d1,a0,a1))
386 * Comment out the line below to test AddDosNode/Enqueue stuff
387 * jsr AddBootNode(a6)
388 move.l #1,PiSCSINextPart ; Switch to the next partition
393 move.l #8,PiSCSIDebugMe
395 move.l #800,PiSCSIDebugMe
397 move.l #801,PiSCSIDebugMe
399 move.l #802,PiSCSIDebugMe
401 move.l (a7)+,a6 ; Pop A6 from stack
402 move.l #803,PiSCSIDebugMe
404 move.w #$80B8,$dff09a ; Re-enable interrupts
405 move.l #804,PiSCSIDebugMe
406 moveq.l #1,d0 ; indicate "success"
407 move.l #805,PiSCSIDebugMe
411 FileSysName dc.b 'FileSystem.resource',0
412 FileSysCreator dc.b 'PiStorm',0
419 movem.l d0-d7/a0-a6,-(sp) ; Push registers to stack
420 move.l #30,PiSCSIDebugMe
423 lea FileSysName(pc),a1
428 move.l #33,PiSCSIDebugMe ; FileSystem.resource isn't open, create it
429 ; Code based on WinUAE filesys.asm
431 moveq #32,d0 ; sizeof(FileSysResource)
435 move.b #8,8(a2) ; NT_RESOURCE
436 lea FileSysName(pc),a0
437 move.l a0,10(a2) ; node name
438 lea FileSysCreator(pc),a0
439 move.l a0,14(a2) ; fsr_Creator
441 move.l a0,(a0) ; NewList() fsr_FileSysEntries
444 lea $150(a6),a0 ; ResourceList
446 jsr -$f6(a6) ; AddTail
451 move.l d0,PiSCSIAddr2 ; PiSCSIAddr2 is now FileSystem.resource
452 move.l #31,PiSCSIDebugMe
453 move.l PiSCSIAddr2,a0
454 move.l PiSCSIGetFS,d0
459 move.l #45,PiSCSIDebugMe
460 lea fsr_FileSysEntries(a0),a0
462 move.l LH_HEAD(a0),d0
466 move.l #34,PiSCSIDebugMe
468 move.l #35,PiSCSIDebugMe
469 cmp.l fse_DosType(a1),d7
470 move.l #36,PiSCSIDebugMe
472 move.l #37,PiSCSIDebugMe
473 move.l LN_SUCC(a1),d0
475 move.l #390,PiSCSIDebugMe
480 move.l #39,PiSCSIDebugMe
481 move.l PiSCSIFSSize,d0
482 move.l #40,PiSCSIDebugMe
484 move.l #41,PiSCSIDebugMe
486 move.l d0,PiSCSIAddr3
488 move.l #1,PiSCSICopyFS
489 move.b #NT_RESOURCE,LN_TYPE(a0)
492 move.l #480,PiSCSIDebugMe
493 move.l PiSCSIAddr2,a0
494 move.l #1,PiSCSINextFS
495 move.l PiSCSIGetFS,d0
499 FSDone: move.l #37,PiSCSIDebugMe
500 move.l #32,PiSCSIDebugMe ; Couldn't open FileSystem.resource, Kick 1.2/1.3?
502 movem.l (sp)+,d0-d7/a0-a6 ; Pop registers from stack