]> git.sesse.net Git - pistorm/blob - platforms/amiga/piscsi/device_driver_amiga/bootrom.s
Some non-working loading of file systems from disk for PiSCSI
[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 AddMemList      EQU -$26A
70
71 ; Expansion stuff
72 MakeDosNode     EQU -144
73 AddDosNode      EQU -150
74 AddBootNode     EQU -36
75
76 ; PiSCSI stuff
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
102
103 *******  RomStart  ***************************************************
104 **********************************************************************
105
106 RomStart:
107
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
114             dc.b    0                              ; da_Flags
115             dc.w    $4000              ; da_Size
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
121
122 *******  Resident Structure  *****************************************
123 Romtag:
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
134
135
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
139
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
143
144 DosDevName: dc.b    'ABC',0        ; dos device name for MakeDosNode()
145                                    ;   (dos device will be ABC:)
146
147             ds.w    0              ; word align
148
149 *******  DiagEntry  **************************************************
150 **********************************************************************
151 *
152 *   success = DiagEntry(BoardBase,DiagCopy, configDev)
153 *   d0                  a0         a2                  a3
154 *
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.
160 *
161 **********************************************************************
162
163 DiagEntry:
164             align 2
165             nop
166             nop
167             nop
168             move.l #1,PiSCSIDebugMe
169             move.l a3,PiSCSIAddr1
170             nop
171             nop
172             nop
173             nop
174             nop
175             nop
176
177             lea      patchTable-RomStart(a0),a1   ; find patch table
178             adda.l   #ROMOFFS,a1                  ; adjusting for ROMOFFS
179
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.
183 *
184 dpatches:
185             move.l   a2,d1           ;d1=base of ram Diag copy
186 dloop:
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
190             bra.s    dloop
191
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.
195 *
196 bpatches:
197             move.l   a0,d1           ;d1 = board base address
198             add.l    #ROMOFFS,d1     ;add offset to where your ROMs are
199 rloop:
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
203             bra.s   rloop
204
205 endpatches:
206             moveq.l #1,d0           ; indicate "success"
207             rts
208
209
210 *******  BootEntry  **************************************************
211 **********************************************************************
212
213 BootEntry:
214             align 2
215             move.l #2,PiSCSIDebugMe
216             lea DosName(pc),a1
217             jsr FindResident(a6)
218             tst.l d0
219             beq.b .End
220             move.l d0,a0
221             move.l RT_INIT(a0),a0
222             jmp (a0)
223 .End
224             moveq.l #1,d0           ; indicate "success"
225             rts
226
227 *
228 * End of the Diag copy area which is copied to RAM
229 *
230 EndCopy:
231 *************************************************************************
232
233 *************************************************************************
234 *
235 *   Beginning of ROM driver code and data that is accessed only in
236 *   the ROM space.  This must all be position-independent.
237 *
238
239 patchTable:
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
244             dc.w   rt_Id-DiagStart
245             dc.w   -1
246
247 * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
248             dc.w   rt_Init-DiagStart
249             dc.w   -1
250
251 *******  Romtag InitEntry  **********************************************
252 *************************************************************************
253
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.
260             ;
261             align 2
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
266
267             movea.l 4,a6
268
269             move.l $10000040,d1
270             move.l #$feffeeff,$10000040
271             move.l $10000040,d0
272             cmp.l #$feffeeff,d0
273             bne.s NoZ3
274             move.l d1,$10000040
275
276             move.l #$8000000,d0         ; Add some Z3 fast RAM if it hasn't been moved (Kick 1.3)
277             move.l #$405,d1
278             move.l #10,d2
279             move.l #$10000000,a0
280             move.l #0,a1
281             jsr AddMemList(a6)
282
283 NoZ3:
284             move.l  #11,PiSCSIDebugMe
285             lea LibName(pc),a1
286             jsr FindResident(a6)
287             move.l  #10,PiSCSIDebugMe
288             cmp.l #0,d0
289             bne.s SkipDriverLoad        ; Library is already loaded, jump straight to partitions
290
291             move.l  #4,PiSCSIDebugMe
292             movea.l 4,a6
293             move.l #$40000,d0
294             moveq #0,d1
295             jsr AllocMem(a6)            ; Allocate memory for the PiStorm to copy the driver to
296
297             move.l  d0,PiSCSIDriver     ; Copy the PiSCSI driver to allocated memory and patch offsets
298
299             move.l  #5,PiSCSIDebugMe
300             move.l  d0,a1
301             move.l  #0,d1
302             movea.l  4,a6
303             add.l #$02c,a1
304             jsr InitResident(a6)        ; Initialize the PiSCSI driver
305
306 SkipDriverLoad:
307             move.l  #9,PiSCSIDebugMe
308             jsr LoadFileSystems(pc)
309
310 FSLoadExit:
311             lea ExpansionName(pc),a1
312             moveq #0,d0
313             jsr OpenLibrary(a6)         ; Open expansion.library to make this work, somehow
314             move.l a6,a4
315             move.l d0,a6
316
317             move.l  #7,PiSCSIDebugMe
318 PartitionLoop:
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
321             move.l d0,a0
322             jsr MakeDosNode(a6)
323             ;cmp.l #0,PiSCSIGetFSInfo      ; This does not work for some reason... not massively surprising...
324             ;beq.s SkipLoadFS
325
326             ;move.l d0,PiSCSILoadFS        ; Attempt to load the file system driver from data/fs
327             ;cmp.l #$FFFFFFFF,PiSCSIAddr4
328             ;beq SkipLoadFS
329
330             ;jsr LoadFileSystems(pc)
331
332 SkipLoadFS:
333             move.l d0,PiSCSISetFSH
334             move.l d0,PiSCSIAddr2       ; Put DeviceNode address in PiSCSIAddr2, because I'm useless
335             move.l d0,a0
336             move.l PiSCSIGetPrio,d0
337             move.l #0,d1
338             move.l PiSCSIAddr1,a1
339
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.
342             cmp.l   #-128,d0
343             bne.s   EnqueueNode
344
345 * BOOL AddDosNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode );
346 * amicall(ExpansionBase, 0x96, AddDosNode(d0,d1,a0))
347             move.l #38,PiSCSIDebugMe
348             jsr AddDosNode(a6)
349             bra.w SkipEnqueue
350 * VOID Enqueue( struct List *list, struct Node *node );
351 * amicall(SysBase, 0x10e, Enqueue(a0,a1))
352
353 EnqueueNode:
354             exg a6,a4
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
363
364             move.l #BootNode_SIZEOF,d0
365             move.l #$10001,d1
366             jsr AllocMem(a6)            ; Allocate memory for the BootNode
367
368             move.l d0,PiSCSIAddr3
369             move.l #36,PiSCSIDebugMe
370
371             move.l d0,a1
372             move.b #NT_BOOTNODE,LN_TYPE(a1)
373             move.l PiSCSIGetPrio,d0
374             move.b d0,LN_PRI(a1)
375             move.l PiSCSIAddr2,bn_DeviceNode(a1)
376             move.l PiSCSIAddr1,LN_NAME(a1)
377
378             lea eb_MountList(a4),a0
379             jsr Enqueue(a6)
380             exg a6,a4
381
382 SkipEnqueue:
383
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
389             bra.w PartitionLoop
390
391
392 EndPartitions:
393             move.l #8,PiSCSIDebugMe
394             move.l a6,a1
395             move.l #800,PiSCSIDebugMe
396             movea.l 4,a6
397             move.l #801,PiSCSIDebugMe
398             jsr CloseLibrary(a6)
399             move.l #802,PiSCSIDebugMe
400
401             move.l (a7)+,a6             ; Pop A6 from stack
402             move.l #803,PiSCSIDebugMe
403
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
408             rts
409
410             align 4
411 FileSysName     dc.b    'FileSystem.resource',0
412 FileSysCreator  dc.b    'PiStorm',0
413
414 CurFS:          dc.l    $0
415 FSResource:     dc.l    $0
416
417             align 2
418 LoadFileSystems:
419             movem.l d0-d7/a0-a6,-(sp)       ; Push registers to stack
420             move.l #30,PiSCSIDebugMe
421             movea.l 4,a6
422 ReloadResource:
423             lea FileSysName(pc),a1
424             jsr OpenResource(a6)
425             tst.l d0
426             bne FSRExists
427
428             move.l #33,PiSCSIDebugMe        ; FileSystem.resource isn't open, create it
429                                             ; Code based on WinUAE filesys.asm
430
431             moveq #32,d0                    ; sizeof(FileSysResource)
432             move.l #$10001,d1
433             jsr AllocMem(a6)
434             move.l d0,a2
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
440             lea 18(a2),a0
441             move.l a0,(a0)                  ; NewList() fsr_FileSysEntries
442             addq.l #4,(a0)
443             move.l a0,8(a0)
444             lea $150(a6),a0                 ; ResourceList
445             move.l a2,a1
446             jsr -$f6(a6)                    ; AddTail
447             move.l a2,a0
448             move.l a0,d0
449
450 FSRExists:  
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
455             cmp.l #0,d0
456             beq.w FSDone
457
458 FSNext:     
459             move.l #45,PiSCSIDebugMe
460             lea fsr_FileSysEntries(a0),a0
461             move.l a0,d2
462             move.l LH_HEAD(a0),d0
463             beq.w NoEntries
464
465 FSLoop:     
466             move.l #34,PiSCSIDebugMe
467             move.l d0,a1
468             move.l #35,PiSCSIDebugMe
469             cmp.l fse_DosType(a1),d7
470             move.l #36,PiSCSIDebugMe
471             beq.w AlreadyLoaded
472             move.l #37,PiSCSIDebugMe
473             move.l LN_SUCC(a1),d0
474             bne.w FSLoop
475             move.l #390,PiSCSIDebugMe
476             bra.w NoEntries
477
478             align 2
479 NoEntries:  
480             move.l #39,PiSCSIDebugMe
481             move.l PiSCSIFSSize,d0
482             move.l #40,PiSCSIDebugMe
483             move.l #$10001,d1
484             move.l #41,PiSCSIDebugMe
485             jsr AllocMem(a6)
486             move.l d0,PiSCSIAddr3
487             move.l d0,a0
488             move.l #1,PiSCSICopyFS
489             move.b #NT_RESOURCE,LN_TYPE(a0)
490
491 AlreadyLoaded:
492             move.l #480,PiSCSIDebugMe
493             move.l PiSCSIAddr2,a0
494             move.l #1,PiSCSINextFS
495             move.l PiSCSIGetFS,d0
496             cmp.l #0,d0
497             bne.w FSNext
498
499 FSDone:     move.l #37,PiSCSIDebugMe
500             move.l #32,PiSCSIDebugMe    ; Couldn't open FileSystem.resource, Kick 1.2/1.3?
501
502             movem.l (sp)+,d0-d7/a0-a6   ; Pop registers from stack
503             rts
504
505 FSRes
506     dc.l    0
507     dc.l    0
508     dc.b    NT_RESOURCE
509     dc.b    0
510     dc.l    FileSysName
511     dc.l    FileSysCreator
512 .Head
513     dc.l    .Tail
514 .Tail
515     dc.l    0
516     dc.l    .Head
517     dc.b    NT_RESOURCE
518     dc.b    0