]> git.sesse.net Git - pistorm/blob - platforms/amiga/piscsi/device_driver_amiga/bootrom.s
23b0aefd35b2a0d6f8df5675fb075a90129b7b36
[pistorm] / platforms / amiga / piscsi / device_driver_amiga / bootrom.s
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     INCLUDE "libraries/expansionbase.i"
23
24     ; LVO's resolved by linking with library amiga.lib
25     XREF   _LVOFindResident
26
27 ROMINFO     EQU      0
28 ROMOFFS     EQU     $4000
29
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)
33 *
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.
42
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
46
47 * See the Addison-Wesley Amiga Hardware Manual for more info.
48     
49 MANUF_ID            EQU 2011            ; CBM assigned (2011 for hackers only)
50 PRODUCT_ID          EQU 1               ; Manufacturer picks product ID
51
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)
58                 CODE
59
60 ; Exec stuff
61 AllocMem        EQU -198
62 InitResident    EQU -102
63 FindResident    EQU -96
64 OpenLibrary     EQU -552
65 CloseLibrary    EQU -414
66 OpenResource    EQU -$1F2
67 AddResource     EQU -$1E6
68 Enqueue         EQU -$10E
69
70 ; Expansion stuff
71 MakeDosNode     EQU -144
72 AddDosNode      EQU -150
73 AddBootNode     EQU -36
74
75 ; PiSCSI stuff
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
99
100 *******  RomStart  ***************************************************
101 **********************************************************************
102
103 RomStart:
104
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
111             dc.b    0                              ; da_Flags
112             dc.w    $4000              ; da_Size
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
118
119 *******  Resident Structure  *****************************************
120 Romtag:
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
131
132
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
136
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
140
141 DosDevName: dc.b    'ABC',0        ; dos device name for MakeDosNode()
142                                    ;   (dos device will be ABC:)
143
144             ds.w    0              ; word align
145
146 *******  DiagEntry  **************************************************
147 **********************************************************************
148 *
149 *   success = DiagEntry(BoardBase,DiagCopy, configDev)
150 *   d0                  a0         a2                  a3
151 *
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.
157 *
158 **********************************************************************
159
160 DiagEntry:
161             align 2
162             nop
163             nop
164             nop
165             move.l #1,PiSCSIDebugMe
166             move.l a3,PiSCSIAddr1
167             nop
168             nop
169             nop
170             nop
171             nop
172             nop
173
174             lea      patchTable-RomStart(a0),a1   ; find patch table
175             adda.l   #ROMOFFS,a1                  ; adjusting for ROMOFFS
176
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.
180 *
181 dpatches:
182             move.l   a2,d1           ;d1=base of ram Diag copy
183 dloop:
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
187             bra.s    dloop
188
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.
192 *
193 bpatches:
194             move.l   a0,d1           ;d1 = board base address
195             add.l    #ROMOFFS,d1     ;add offset to where your ROMs are
196 rloop:
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
200             bra.s   rloop
201
202 endpatches:
203             moveq.l #1,d0           ; indicate "success"
204             rts
205
206
207 *******  BootEntry  **************************************************
208 **********************************************************************
209
210 BootEntry:
211             align 2
212             move.l #2,PiSCSIDebugMe
213             lea DosName(pc),a1
214             jsr FindResident(a6)
215             tst.l d0
216             beq.b .End
217             move.l d0,a0
218             move.l RT_INIT(a0),a0
219             jmp (a0)
220 .End
221             moveq.l #1,d0           ; indicate "success"
222             rts
223
224 *
225 * End of the Diag copy area which is copied to RAM
226 *
227 EndCopy:
228 *************************************************************************
229
230 *************************************************************************
231 *
232 *   Beginning of ROM driver code and data that is accessed only in
233 *   the ROM space.  This must all be position-independent.
234 *
235
236 patchTable:
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
241             dc.w   rt_Id-DiagStart
242             dc.w   -1
243
244 * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
245             dc.w   rt_Init-DiagStart
246             dc.w   -1
247
248 *******  Romtag InitEntry  **********************************************
249 *************************************************************************
250
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.
257             ;
258             align 2
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
263
264             move.l  #11,PiSCSIDebugMe
265             movea.l 4,a6
266             lea LibName(pc),a1
267             jsr FindResident(a6)
268             move.l  #10,PiSCSIDebugMe
269             cmp.l #0,d0
270             bne.s SkipDriverLoad        ; Library is already loaded, jump straight to partitions
271
272             move.l  #4,PiSCSIDebugMe
273             movea.l 4,a6
274             move.l #$40000,d0
275             moveq #0,d1
276             jsr AllocMem(a6)            ; Allocate memory for the PiStorm to copy the driver to
277
278             move.l  d0,PiSCSIDriver     ; Copy the PiSCSI driver to allocated memory and patch offsets
279
280             move.l  #5,PiSCSIDebugMe
281             move.l  d0,a1
282             move.l  #0,d1
283             movea.l  4,a6
284             add.l #$02c,a1
285             jsr InitResident(a6)        ; Initialize the PiSCSI driver
286
287 SkipDriverLoad:
288             move.l  #9,PiSCSIDebugMe
289             bra.w LoadFileSystems
290
291 FSLoadExit:
292             lea ExpansionName(pc),a1
293             moveq #0,d0
294             jsr OpenLibrary(a6)         ; Open expansion.library to make this work, somehow
295             move.l a6,a4
296             move.l d0,a6
297
298             move.l  #7,PiSCSIDebugMe
299 PartitionLoop:
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
302             move.l d0,a0
303             jsr MakeDosNode(a6)
304             move.l d0,PiSCSISetFSH
305             move.l d0,PiSCSIAddr2       ; Put DeviceNode address in PiSCSIAddr2, because I'm useless
306             move.l d0,a0
307             move.l PiSCSIGetPrio,d0
308             move.l #0,d1
309             move.l PiSCSIAddr1,a1
310
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.
313             cmp.l   #-128,d0
314             bne.s   EnqueueNode
315
316 * BOOL AddDosNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode );
317 * amicall(ExpansionBase, 0x96, AddDosNode(d0,d1,a0))
318             move.l #38,PiSCSIDebugMe
319             jsr AddDosNode(a6)
320             bra.w SkipEnqueue
321 * VOID Enqueue( struct List *list, struct Node *node );
322 * amicall(SysBase, 0x10e, Enqueue(a0,a1))
323
324 EnqueueNode:
325             exg a6,a4
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
334
335             move.l #BootNode_SIZEOF,d0
336             move.l #$10001,d1
337             jsr AllocMem(a6)            ; Allocate memory for the BootNode
338
339             move.l d0,PiSCSIAddr3
340             move.l #36,PiSCSIDebugMe
341
342             move.l d0,a1
343             move.b #NT_BOOTNODE,LN_TYPE(a1)
344             move.l PiSCSIGetPrio,d0
345             move.b d0,LN_PRI(a1)
346             move.l PiSCSIAddr2,bn_DeviceNode(a1)
347             move.l PiSCSIAddr1,LN_NAME(a1)
348
349             lea eb_MountList(a4),a0
350             jsr Enqueue(a6)
351             exg a6,a4
352
353 SkipEnqueue:
354
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
360             bra.w PartitionLoop
361
362
363 EndPartitions:
364             move.l #8,PiSCSIDebugMe
365             move.l a6,a1
366             move.l #800,PiSCSIDebugMe
367             movea.l 4,a6
368             move.l #801,PiSCSIDebugMe
369             jsr CloseLibrary(a6)
370             move.l #802,PiSCSIDebugMe
371
372             move.l (a7)+,a6             ; Pop A6 from stack
373             move.l #803,PiSCSIDebugMe
374
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
379             rts
380
381             align 4
382 FileSysName     dc.b    'FileSystem.resource',0
383 FileSysCreator  dc.b    'PiStorm',0
384
385 CurFS:          dc.l    $0
386 FSResource:     dc.l    $0
387
388             align 2
389 LoadFileSystems:
390             movem.l d0-d7/a0-a6,-(sp)       ; Push registers to stack
391             move.l #30,PiSCSIDebugMe
392             lea FileSysName(pc),a1
393             jsr OpenResource(a6)
394             tst.l d0
395             bne FSRExists
396
397             move.l #33,PiSCSIDebugMe        ; FileSystem.resource isn't open, create it
398             lea FSRes(pc),a1
399             move.l a1,-(a7)
400             jsr AddResource(a6)
401             move.l (a7)+,a0
402             move.l a0,d0
403
404 FSRExists:  
405             move.l d0,PiSCSIAddr2             ; PiSCSIAddr2 is now FileSystem.resource
406             move.l #31,PiSCSIDebugMe
407             move.l PiSCSIAddr2,a0
408             move.l PiSCSIGetFS,d0
409             cmp.l #0,d0
410             beq.w FSDone
411             move.l d0,d7
412
413 FSNext:     
414             move.l #45,PiSCSIDebugMe
415             lea fsr_FileSysEntries(a0),a0
416             move.l a0,d2
417             move.l LH_HEAD(a0),d0
418             beq.w NoEntries
419
420 FSLoop:     
421             move.l #34,PiSCSIDebugMe
422             move.l d0,a1
423             move.l #35,PiSCSIDebugMe
424             cmp.l fse_DosType(a1),d7
425             move.l #36,PiSCSIDebugMe
426             beq.w AlreadyLoaded
427             move.l #37,PiSCSIDebugMe
428             move.l LN_SUCC(a1),d0
429             bne.w FSLoop
430             move.l #390,PiSCSIDebugMe
431             bra.w NoEntries
432
433             align 2
434 NoEntries:  
435             move.l #39,PiSCSIDebugMe
436             move.l PiSCSIFSSize,d0
437             move.l #40,PiSCSIDebugMe
438             move.l #0,d1
439             move.l #41,PiSCSIDebugMe
440             jsr AllocMem(a6)
441             move.l d0,PiSCSIAddr3
442             move.l #1,PiSCSICopyFS
443
444 AlreadyLoaded:
445             move.l #480,PiSCSIDebugMe
446             move.l PiSCSIAddr2,a0
447             move.l #1,PiSCSINextFS
448             move.l PiSCSIGetFS,d0
449             move.l d0,d7
450             cmp.l #0,d0
451             bne.w FSNext
452
453 FSDone:     move.l #37,PiSCSIDebugMe
454             move.l #32,PiSCSIDebugMe    ; Couldn't open FileSystem.resource, Kick 1.2/1.3?
455
456             movem.l (sp)+,d0-d7/a0-a6   ; Pop registers from stack
457             bra.w FSLoadExit
458
459 FSRes
460     dc.l    0
461     dc.l    0
462     dc.b    NT_RESOURCE
463     dc.b    0
464     dc.l    FileSysName
465     dc.l    FileSysCreator
466 .Head
467     dc.l    .Tail
468 .Tail
469     dc.l    0
470     dc.l    .Head
471     dc.b    NT_RESOURCE
472     dc.b    0