]> git.sesse.net Git - pistorm/blob - platforms/amiga/piscsi/device_driver_amiga/bootrom.s
Non-working AddDosNode/Enqueue experiments 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
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             nop
214             nop
215             nop
216             nop
217             nop
218
219             lea     DosName(PC),a1          ; 'dos.library',0
220             jsr     FindResident(a6)        ; find the DOS resident tag
221             move.l  d0,a0                   ; in order to bootstrap
222             move.l  RT_INIT(A0),a0          ; set vector to DOS INIT
223             jsr     (a0)                    ; and initialize DOS
224             rts
225
226 *
227 * End of the Diag copy area which is copied to RAM
228 *
229 EndCopy:
230 *************************************************************************
231
232 *************************************************************************
233 *
234 *   Beginning of ROM driver code and data that is accessed only in
235 *   the ROM space.  This must all be position-independent.
236 *
237
238 patchTable:
239 * Word offsets into Diag area where pointers need Diag copy address added
240             dc.w   rt_Match-DiagStart
241             dc.w   rt_End-DiagStart
242             dc.w   rt_Name-DiagStart
243             dc.w   rt_Id-DiagStart
244             dc.w   -1
245
246 * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
247             dc.w   rt_Init-DiagStart
248             dc.w   -1
249
250 *******  Romtag InitEntry  **********************************************
251 *************************************************************************
252
253 Init:       ; After Diag patching, our romtag will point to this
254             ; routine in ROM so that it can be called at Resident
255             ; initialization time.
256             ; This routine will be similar to a normal expansion device
257             ; initialization routine, but will MakeDosNode then set up a
258             ; BootNode, and Enqueue() on eb_MountList.
259             ;
260             align 2
261             move.l a6,-(a7)             ; Push A6 to stack
262             move.w #$00B8,$dff09a       ; Disable interrupts during init
263             move.l  #3,PiSCSIDebugMe
264
265             move.l  #11,PiSCSIDebugMe
266             movea.l 4,a6
267             lea LibName(pc),a1
268             jsr FindResident(a6)
269             move.l  #10,PiSCSIDebugMe
270             cmp.l #0,d0
271             bne.s SkipDriverLoad        ; Library is already loaded, jump straight to partitions
272
273             move.l  #4,PiSCSIDebugMe
274             movea.l 4,a6
275             move.l #$40000,d0
276             moveq #0,d1
277             jsr AllocMem(a6)            ; Allocate memory for the PiStorm to copy the driver to
278
279             move.l  d0,PiSCSIDriver     ; Copy the PiSCSI driver to allocated memory and patch offsets
280
281             move.l  #5,PiSCSIDebugMe
282             move.l  d0,a1
283             move.l  #0,d1
284             movea.l  4,a6
285             add.l #$02c,a1
286             jsr InitResident(a6)        ; Initialize the PiSCSI driver
287
288 SkipDriverLoad:
289             move.l  #9,PiSCSIDebugMe
290             bra.w LoadFileSystems
291
292 FSLoadExit:
293             lea ExpansionName(pc),a1
294             moveq #0,d0
295             jsr OpenLibrary(a6)         ; Open expansion.library to make this work, somehow
296             move.l a6,a4
297             move.l d0,a6
298
299             move.l  #7,PiSCSIDebugMe
300 PartitionLoop:
301             move.l PiSCSIGetPart,d0     ; Get the available partition in the current slot
302             beq.w EndPartitions         ; If the next partition returns 0, there's no additional partitions
303             move.l d0,a0
304             jsr MakeDosNode(a6)
305             move.l d0,PiSCSISetFSH
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 *            cmp.l   #-128,d0
313 *            bne.s   EnqueueNode
314 *
315 ** BOOL AddDosNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode );
316 ** amicall(ExpansionBase, 0x96, AddDosNode(d0,d1,a0))
317 *            move.l #38,PiSCSIDebugMe
318 *            jsr AddDosNode(a6)
319 *            bra.w SkipEnqueue
320 ** VOID Enqueue( struct List *list, struct Node *node );
321 ** amicall(SysBase, 0x10e, Enqueue(a0,a1))
322 *
323 *EnqueueNode:
324 *            exg a6,a4
325 *            move.l #35,PiSCSIDebugMe
326 *            move.l #BootNode_SIZEOF,PiSCSIDebugMe
327 *            move.l #NT_BOOTNODE,PiSCSIDebugMe
328 *            move.l #LN_TYPE,PiSCSIDebugMe
329 *            move.l #LN_PRI,PiSCSIDebugMe
330 *            move.l #LN_NAME,PiSCSIDebugMe
331 *            move.l #eb_MountList,PiSCSIDebugMe
332 *            move.l #35,PiSCSIDebugMe
333 *
334 *            move.l #BootNode_SIZEOF,d0
335 *            move.l #$10001,d1
336 *            jsr AllocMem(a6)            ; Allocate memory for the BootNode
337 *
338 *            move.l d0,a1
339 *            move.b #NT_BOOTNODE,LN_TYPE(a1)
340 *            move.b PiSCSIGetPrio,LN_PRI(a1)
341 *            move.l a0,bn_DeviceNode(a1)
342 *            move.l PiSCSIAddr1,LN_NAME(a1)
343 *
344 *            lea eb_MountList(a4),a0
345 *            jsr Enqueue(a6)
346 *            exg a6,a4
347 *
348 *SkipEnqueue:
349
350 * BOOL AddBootNode( LONG bootPri, ULONG flags, struct DeviceNode *deviceNode, struct ConfigDev *configDev );
351 * amicall(ExpansionBase, 0x24, AddBootNode(d0,d1,a0,a1))
352 * Comment out the line below to test AddDosNode/Enqueue stuff
353             jsr AddBootNode(a6)
354             move.l #1,PiSCSINextPart    ; Switch to the next partition
355             bra.w PartitionLoop
356
357
358 EndPartitions:
359             move.l #8,PiSCSIDebugMe
360             move.l a6,a1
361             move.l #800,PiSCSIDebugMe
362             movea.l 4,a6
363             move.l #801,PiSCSIDebugMe
364             jsr CloseLibrary(a6)
365             move.l #802,PiSCSIDebugMe
366
367             move.l (a7)+,a6             ; Pop A6 from stack
368             move.l #803,PiSCSIDebugMe
369
370             move.w #$80B8,$dff09a       ; Re-enable interrupts
371             move.l #804,PiSCSIDebugMe
372             moveq.l #1,d0               ; indicate "success"
373             move.l #805,PiSCSIDebugMe
374             rts
375
376             align 4
377 FileSysName     dc.b    'FileSystem.resource',0
378 FileSysCreator  dc.b    'PiStorm',0
379
380 CurFS:          dc.l    $0
381 FSResource:     dc.l    $0
382
383             align 2
384 LoadFileSystems:
385             movem.l d0-d7/a0-a6,-(sp)       ; Push registers to stack
386             move.l #30,PiSCSIDebugMe
387             lea FileSysName(pc),a1
388             jsr OpenResource(a6)
389             tst.l d0
390             bne FSRExists
391
392             move.l #33,PiSCSIDebugMe        ; FileSystem.resource isn't open, create it
393             lea FSRes(pc),a1
394             move.l a1,-(a7)
395             jsr AddResource(a6)
396             move.l (a7)+,a0
397             move.l a0,d0
398
399 FSRExists:  
400             move.l d0,PiSCSIAddr2             ; PiSCSIAddr2 is now FileSystem.resource
401             move.l #31,PiSCSIDebugMe
402             move.l PiSCSIAddr2,a0
403             move.l PiSCSIGetFS,d0
404             cmp.l #0,d0
405             beq.w FSDone
406             move.l d0,d7
407
408 FSNext:     
409             move.l #45,PiSCSIDebugMe
410             lea fsr_FileSysEntries(a0),a0
411             move.l a0,d2
412             move.l LH_HEAD(a0),d0
413             beq.w NoEntries
414
415 FSLoop:     
416             move.l #34,PiSCSIDebugMe
417             move.l d0,a1
418             move.l #35,PiSCSIDebugMe
419             cmp.l fse_DosType(a1),d7
420             move.l #36,PiSCSIDebugMe
421             beq.w AlreadyLoaded
422             move.l #37,PiSCSIDebugMe
423             move.l LN_SUCC(a1),d0
424             bne.w FSLoop
425             move.l #390,PiSCSIDebugMe
426             bra.w NoEntries
427
428             align 2
429 NoEntries:  
430             move.l #39,PiSCSIDebugMe
431             move.l PiSCSIFSSize,d0
432             move.l #40,PiSCSIDebugMe
433             move.l #0,d1
434             move.l #41,PiSCSIDebugMe
435             jsr AllocMem(a6)
436             move.l d0,PiSCSIAddr3
437             move.l #1,PiSCSICopyFS
438
439 AlreadyLoaded:
440             move.l #480,PiSCSIDebugMe
441             move.l PiSCSIAddr2,a0
442             move.l #1,PiSCSINextFS
443             move.l PiSCSIGetFS,d0
444             move.l d0,d7
445             cmp.l #0,d0
446             bne.w FSNext
447
448 FSDone:     move.l #37,PiSCSIDebugMe
449             move.l #32,PiSCSIDebugMe    ; Couldn't open FileSystem.resource, Kick 1.2/1.3?
450
451             movem.l (sp)+,d0-d7/a0-a6   ; Pop registers from stack
452             bra.w FSLoadExit
453
454 FileSysRes
455     dc.l    0
456     dc.l    0
457     dc.b    NT_RESOURCE
458     dc.b    0
459     dc.l    FileSysName
460     dc.l    FileSysCreator
461 .Head
462     dc.l    .Tail
463 .Tail
464     dc.l    0
465     dc.l    .Head
466     dc.b    NT_RESOURCE
467     dc.b    0