]> git.sesse.net Git - pistorm/blob - platforms/amiga/piscsi/device_driver_amiga/bootrom.s
PiSCSI boot ROM+custom file systems working
[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
23     ; LVO's resolved by linking with library amiga.lib
24     XREF   _LVOFindResident
25
26 ROMINFO     EQU      0
27 ROMOFFS     EQU     $4000
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 $10000          ; 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 ; Exec stuff
60 AllocMem        EQU -198
61 InitResident    EQU -102
62 FindResident    EQU -96
63 OpenLibrary     EQU -552
64 CloseLibrary    EQU -414
65 OpenResource    EQU -$1F2
66 AddResource     EQU -$1E6
67
68 ; Expansion stuff
69 MakeDosNode     EQU -144
70 AddDosNode      EQU -150
71 AddBootNode     EQU -36
72
73 ; PiSCSI stuff
74 PiSCSIAddr1     EQU $80000010
75 PiSCSIAddr2     EQU $80000014
76 PiSCSIAddr3     EQU $80000018
77 PiSCSIAddr4     EQU $8000001C
78 PiSCSIDebugMe   EQU $80000020
79 PiSCSIDriver    EQU $80000040
80 PiSCSINextPart  EQU $80000044
81 PiSCSIGetPart   EQU $80000048
82 PiSCSIGetPrio   EQU $8000004C
83 PiSCSIGetFS     EQU $80000060
84 PiSCSINextFS    EQU $80000064
85 PiSCSICopyFS    EQU $80000068
86 PiSCSIFSSize    EQU $8000006C
87 PiSCSISetFSH    EQU $80000070
88 PiSCSIDbg1      EQU $80001010
89 PiSCSIDbg2      EQU $80001014
90 PiSCSIDbg3      EQU $80001018
91 PiSCSIDbg4      EQU $8000101C
92 PiSCSIDbg5      EQU $80001020
93 PiSCSIDbg6      EQU $80001024
94 PiSCSIDbg7      EQU $80001028
95 PiSCSIDbg8      EQU $8000102C
96 PiSCSIDbgMsg    EQU $80001000
97
98 *******  RomStart  ***************************************************
99 **********************************************************************
100
101 RomStart:
102
103 *******  DiagStart  **************************************************
104 DiagStart:  ; This is the DiagArea structure whose relative offset from
105             ; your board base appears as the Init Diag vector in your
106             ; autoconfig ID information.  This structure is designed
107             ; to use all relative pointers (no patching needed).
108             dc.b    DAC_WORDWIDE+DAC_CONFIGTIME    ; da_Config
109             dc.b    0                              ; da_Flags
110             dc.w    $4000              ; da_Size
111             dc.w    DiagEntry-DiagStart            ; da_DiagPoint
112             dc.w    BootEntry-DiagStart            ; da_BootPoint
113             dc.w    DevName-DiagStart              ; da_Name
114             dc.w    0                              ; da_Reserved01
115             dc.w    0                              ; da_Reserved02
116
117 *******  Resident Structure  *****************************************
118 Romtag:
119             dc.w    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
120 rt_Match:   dc.l    Romtag-DiagStart   ; APTR  RT_MATCHTAG
121 rt_End:     dc.l    EndCopy-DiagStart  ; APTR  RT_ENDSKIP
122             dc.b    RTW_COLDSTART      ; UBYTE RT_FLAGS
123             dc.b    VERSION            ; UBYTE RT_VERSION
124             dc.b    NT_DEVICE          ; UBYTE RT_TYPE
125             dc.b    20                 ; BYTE  RT_PRI
126 rt_Name:    dc.l    DevName-DiagStart  ; APTR  RT_NAME
127 rt_Id:      dc.l    IdString-DiagStart ; APTR  RT_IDSTRING
128 rt_Init:    dc.l    Init-RomStart      ; APTR  RT_INIT
129
130
131 ******* Strings referenced in Diag Copy area  ************************
132 DevName:    dc.b    'pi-scsi.device',0,0                      ; Name string
133 IdString    dc.b    'PISCSI v0.8',0   ; Id string
134
135 DosName:        dc.b    'dos.library',0                ; DOS library name
136 ExpansionName:  dc.b    "expansion.library",0
137 LibName:        dc.b    "pi-scsi.device",0,0
138
139 DosDevName: dc.b    'ABC',0        ; dos device name for MakeDosNode()
140                                    ;   (dos device will be ABC:)
141
142             ds.w    0              ; word align
143
144 *******  DiagEntry  **************************************************
145 **********************************************************************
146 *
147 *   success = DiagEntry(BoardBase,DiagCopy, configDev)
148 *   d0                  a0         a2                  a3
149 *
150 *   Called by expansion architecture to relocate any pointers
151 *   in the copied diagnostic area.   We will patch the romtag.
152 *   If you have pre-coded your MakeDosNode packet, BootNode,
153 *   or device initialization structures, they would also need
154 *   to be within this copy area, and patched by this routine.
155 *
156 **********************************************************************
157
158 DiagEntry:
159             align 2
160             nop
161             nop
162             nop
163             move.l  #1,PiSCSIDebugMe
164             move.l a3,PiSCSIAddr1
165             nop
166             nop
167             nop
168             nop
169             nop
170             nop
171
172             lea      patchTable-RomStart(a0),a1   ; find patch table
173             adda.l   #ROMOFFS,a1                  ; adjusting for ROMOFFS
174
175 * Patch relative pointers to labels within DiagCopy area
176 * by adding Diag RAM copy address.  These pointers were coded as
177 * long relative offsets from base of the DiagArea structure.
178 *
179 dpatches:
180             move.l   a2,d1           ;d1=base of ram Diag copy
181 dloop:
182             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
183             bmi.s    bpatches        ;-1 is end of word patch offset table
184             add.l    d1,0(a2,d0.w)   ;add DiagCopy addr to coded rel. offset
185             bra.s    dloop
186
187 * Patches relative pointers to labels within the ROM by adding
188 * the board base address + ROMOFFS.  These pointers were coded as
189 * long relative offsets from RomStart.
190 *
191 bpatches:
192             move.l   a0,d1           ;d1 = board base address
193             add.l    #ROMOFFS,d1     ;add offset to where your ROMs are
194 rloop:
195             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
196             bmi.s   endpatches       ;-1 is end of patch offset table
197             add.l   d1,0(a2,d0.w)    ;add ROM address to coded relative offset
198             bra.s   rloop
199
200 endpatches:
201             moveq.l #1,d0           ; indicate "success"
202             rts
203
204
205 *******  BootEntry  **************************************************
206 **********************************************************************
207
208 BootEntry:
209             align 2
210             move.l  #2,PiSCSIDebugMe
211             nop
212             nop
213             nop
214             nop
215             nop
216
217             lea     DosName(PC),a1          ; 'dos.library',0
218             jsr     FindResident(a6)        ; find the DOS resident tag
219             move.l  d0,a0                   ; in order to bootstrap
220             move.l  RT_INIT(A0),a0          ; set vector to DOS INIT
221             jsr     (a0)                    ; and initialize DOS
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
263             move.l  #11,PiSCSIDebugMe
264             movea.l 4,a6
265             lea LibName(pc),a1
266             jsr FindResident(a6)
267             move.l  #10,PiSCSIDebugMe
268             cmp.l #0,d0
269             bne.s SkipDriverLoad        ; Library is already loaded, jump straight to partitions
270
271             move.l  #4,PiSCSIDebugMe
272             movea.l 4,a6
273             move.l #$40000,d0
274             moveq #0,d1
275             jsr AllocMem(a6)            ; Allocate memory for the PiStorm to copy the driver to
276
277             move.l  d0,PiSCSIDriver     ; Copy the PiSCSI driver to allocated memory and patch offsets
278
279             move.l  #5,PiSCSIDebugMe
280             move.l  d0,a1
281             move.l  #0,d1
282             movea.l  4,a6
283             add.l #$02c,a1
284             jsr InitResident(a6)        ; Initialize the PiSCSI driver
285
286 SkipDriverLoad:
287             move.l  #9,PiSCSIDebugMe
288             bra.w LoadFileSystems
289
290 FSLoadExit:
291             lea ExpansionName(pc),a1
292             moveq #0,d0
293             jsr OpenLibrary(a6)         ; Open expansion.library to make this work, somehow
294             move.l d0,a6
295
296             move.l  #7,PiSCSIDebugMe
297 PartitionLoop:
298             move.l PiSCSIGetPart,d0     ; Get the available partition in the current slot
299             beq.s EndPartitions         ; If the next partition returns 0, there's no additional partitions
300             move.l d0,a0
301             jsr MakeDosNode(a6)
302             move.l d0,PiSCSISetFSH
303             move.l d0,a0
304             move.l PiSCSIGetPrio,d0
305             move.l #0,d1
306             move.l PiSCSIAddr1,a1
307             jsr AddBootNode(a6)
308             move.l #1,PiSCSINextPart    ; Switch to the next partition
309             bra.w PartitionLoop
310
311
312 EndPartitions:
313             move.l #8,PiSCSIDebugMe
314             move.l a6,a1
315             move.l #800,PiSCSIDebugMe
316             movea.l 4,a6
317             move.l #801,PiSCSIDebugMe
318             jsr CloseLibrary(a6)
319             move.l #802,PiSCSIDebugMe
320
321             move.l (a7)+,a6             ; Pop A6 from stack
322             move.l #803,PiSCSIDebugMe
323
324             move.w #$80B8,$dff09a       ; Re-enable interrupts
325             move.l #804,PiSCSIDebugMe
326             moveq.l #1,d0               ; indicate "success"
327             move.l #805,PiSCSIDebugMe
328             rts
329
330             align 4
331 FileSysName     dc.b    'FileSystem.resource',0
332 FileSysCreator  dc.b    'PiStorm',0
333
334 CurFS:          dc.l    $0
335 FSResource:     dc.l    $0
336
337             align 2
338 LoadFileSystems:
339             movem.l d0-d7/a0-a6,-(sp)       ; Push registers to stack
340             move.l #30,PiSCSIDebugMe
341             lea FileSysName(pc),a1
342             jsr OpenResource(a6)
343             tst.l d0
344             bne FSRExists
345
346             move.l #33,PiSCSIDebugMe        ; FileSystem.resource isn't open, create it
347             lea FSRes(pc),a1
348             move.l a1,-(a7)
349             jsr AddResource(a6)
350             move.l (a7)+,a0
351             move.l a0,d0
352
353 FSRExists:  
354             move.l d0,PiSCSIAddr2             ; PiSCSIAddr2 is now FileSystem.resource
355             move.l #31,PiSCSIDebugMe
356             move.l PiSCSIAddr2,a0
357             move.l PiSCSIGetFS,d0
358             cmp.l #0,d0
359             beq.w FSDone
360             move.l d0,d7
361
362 FSNext:     
363             move.l #45,PiSCSIDebugMe
364             lea fsr_FileSysEntries(a0),a0
365             move.l a0,d2
366             move.l LH_HEAD(a0),d0
367             beq.w NoEntries
368
369 FSLoop:     
370             move.l #34,PiSCSIDebugMe
371             move.l d0,a1
372             move.l #35,PiSCSIDebugMe
373             cmp.l fse_DosType(a1),d7
374             move.l #36,PiSCSIDebugMe
375             beq.w AlreadyLoaded
376             move.l #37,PiSCSIDebugMe
377             move.l LN_SUCC(a1),d0
378             bne.w FSLoop
379             move.l #390,PiSCSIDebugMe
380             bra.w NoEntries
381
382             align 2
383 NoEntries:  
384             move.l #39,PiSCSIDebugMe
385             move.l PiSCSIFSSize,d0
386             move.l #40,PiSCSIDebugMe
387             move.l #0,d1
388             move.l #41,PiSCSIDebugMe
389             jsr AllocMem(a6)
390             move.l d0,PiSCSIAddr3
391             move.l #1,PiSCSICopyFS
392
393 AlreadyLoaded:
394             move.l #480,PiSCSIDebugMe
395             move.l PiSCSIAddr2,a0
396             move.l #1,PiSCSINextFS
397             move.l PiSCSIGetFS,d0
398             move.l d0,d7
399             cmp.l #0,d0
400             bne.w FSNext
401
402 FSDone:     move.l #37,PiSCSIDebugMe
403             move.l #32,PiSCSIDebugMe    ; Couldn't open FileSystem.resource, Kick 1.2/1.3?
404
405             movem.l (sp)+,d0-d7/a0-a6   ; Pop registers from stack
406             bra.w FSLoadExit
407
408 FileSysRes
409     dc.l    0
410     dc.l    0
411     dc.b    NT_RESOURCE
412     dc.b    0
413     dc.l    FileSysName
414     dc.l    FileSysCreator
415 .Head
416     dc.l    .Tail
417 .Tail
418     dc.l    0
419     dc.l    .Head
420     dc.b    NT_RESOURCE
421     dc.b    0