]> git.sesse.net Git - pistorm/blob - platforms/amiga/piscsi/device_driver_amiga/bootrom.s
f27ac5f70f1d661913988f3942f9be03721d861b
[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
66 ; Expansion stuff
67 MakeDosNode     EQU -144
68 AddDosNode      EQU -150
69 AddBootNode     EQU -36
70
71 ; PiSCSI stuff
72 PiSCSIAddr1     EQU $80000010
73 PiSCSIDebugMe   EQU $80000020
74 PiSCSIDriver    EQU $80000040
75 PiSCSINextPart  EQU $80000044
76 PiSCSIGetPart   EQU $80000048
77 PiSCSIGetPrio   EQU $8000004C
78
79 *******  RomStart  ***************************************************
80 **********************************************************************
81
82 RomStart:
83
84 *******  DiagStart  **************************************************
85 DiagStart:  ; This is the DiagArea structure whose relative offset from
86             ; your board base appears as the Init Diag vector in your
87             ; autoconfig ID information.  This structure is designed
88             ; to use all relative pointers (no patching needed).
89             dc.b    DAC_WORDWIDE+DAC_CONFIGTIME    ; da_Config
90             dc.b    0                              ; da_Flags
91             dc.w    $4000              ; da_Size
92             dc.w    DiagEntry-DiagStart            ; da_DiagPoint
93             dc.w    BootEntry-DiagStart            ; da_BootPoint
94             dc.w    DevName-DiagStart              ; da_Name
95             dc.w    0                              ; da_Reserved01
96             dc.w    0                              ; da_Reserved02
97
98 *******  Resident Structure  *****************************************
99 Romtag:
100             dc.w    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
101 rt_Match:   dc.l    Romtag-DiagStart   ; APTR  RT_MATCHTAG
102 rt_End:     dc.l    EndCopy-DiagStart  ; APTR  RT_ENDSKIP
103             dc.b    RTW_COLDSTART      ; UBYTE RT_FLAGS
104             dc.b    VERSION            ; UBYTE RT_VERSION
105             dc.b    NT_DEVICE          ; UBYTE RT_TYPE
106             dc.b    20                 ; BYTE  RT_PRI
107 rt_Name:    dc.l    DevName-DiagStart  ; APTR  RT_NAME
108 rt_Id:      dc.l    IdString-DiagStart ; APTR  RT_IDSTRING
109 rt_Init:    dc.l    Init-RomStart      ; APTR  RT_INIT
110
111
112 ******* Strings referenced in Diag Copy area  ************************
113 DevName:    dc.b    'pi-scsi.device',0,0                      ; Name string
114 IdString    dc.b    'PISCSI v0.8',0   ; Id string
115
116 DosName:        dc.b    'dos.library',0                ; DOS library name
117 ExpansionName:  dc.b    "expansion.library",0
118 LibName:        dc.b    "pi-scsi.device",0,0
119
120 DosDevName: dc.b    'ABC',0        ; dos device name for MakeDosNode()
121                                    ;   (dos device will be ABC:)
122
123             ds.w    0              ; word align
124
125 *******  DiagEntry  **************************************************
126 **********************************************************************
127 *
128 *   success = DiagEntry(BoardBase,DiagCopy, configDev)
129 *   d0                  a0         a2                  a3
130 *
131 *   Called by expansion architecture to relocate any pointers
132 *   in the copied diagnostic area.   We will patch the romtag.
133 *   If you have pre-coded your MakeDosNode packet, BootNode,
134 *   or device initialization structures, they would also need
135 *   to be within this copy area, and patched by this routine.
136 *
137 **********************************************************************
138
139 DiagEntry:
140             align 2
141             nop
142             nop
143             nop
144             move.l  #1,PiSCSIDebugMe
145             move.l a3,PiSCSIAddr1
146             nop
147             nop
148             nop
149             nop
150             nop
151             nop
152
153             lea      patchTable-RomStart(a0),a1   ; find patch table
154             adda.l   #ROMOFFS,a1                  ; adjusting for ROMOFFS
155
156 * Patch relative pointers to labels within DiagCopy area
157 * by adding Diag RAM copy address.  These pointers were coded as
158 * long relative offsets from base of the DiagArea structure.
159 *
160 dpatches:
161             move.l   a2,d1           ;d1=base of ram Diag copy
162 dloop:
163             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
164             bmi.s    bpatches        ;-1 is end of word patch offset table
165             add.l    d1,0(a2,d0.w)   ;add DiagCopy addr to coded rel. offset
166             bra.s    dloop
167
168 * Patches relative pointers to labels within the ROM by adding
169 * the board base address + ROMOFFS.  These pointers were coded as
170 * long relative offsets from RomStart.
171 *
172 bpatches:
173             move.l   a0,d1           ;d1 = board base address
174             add.l    #ROMOFFS,d1     ;add offset to where your ROMs are
175 rloop:
176             move.w   (a1)+,d0        ;d0=word offs. into Diag needing patch
177             bmi.s   endpatches       ;-1 is end of patch offset table
178             add.l   d1,0(a2,d0.w)    ;add ROM address to coded relative offset
179             bra.s   rloop
180
181 endpatches:
182             moveq.l #1,d0           ; indicate "success"
183             rts
184
185
186 *******  BootEntry  **************************************************
187 **********************************************************************
188
189 BootEntry:
190             align 2
191             move.l  #2,PiSCSIDebugMe
192             nop
193             nop
194             nop
195             nop
196             nop
197
198             lea     DosName(PC),a1          ; 'dos.library',0
199             jsr     FindResident(a6)        ; find the DOS resident tag
200             move.l  d0,a0                   ; in order to bootstrap
201             move.l  RT_INIT(A0),a0          ; set vector to DOS INIT
202             jsr     (a0)                    ; and initialize DOS
203             rts
204
205 *
206 * End of the Diag copy area which is copied to RAM
207 *
208 EndCopy:
209 *************************************************************************
210
211 *************************************************************************
212 *
213 *   Beginning of ROM driver code and data that is accessed only in
214 *   the ROM space.  This must all be position-independent.
215 *
216
217 patchTable:
218 * Word offsets into Diag area where pointers need Diag copy address added
219             dc.w   rt_Match-DiagStart
220             dc.w   rt_End-DiagStart
221             dc.w   rt_Name-DiagStart
222             dc.w   rt_Id-DiagStart
223             dc.w   -1
224
225 * Word offsets into Diag area where pointers need boardbase+ROMOFFS added
226             dc.w   rt_Init-DiagStart
227             dc.w   -1
228
229 *******  Romtag InitEntry  **********************************************
230 *************************************************************************
231
232 Init:       ; After Diag patching, our romtag will point to this
233             ; routine in ROM so that it can be called at Resident
234             ; initialization time.
235             ; This routine will be similar to a normal expansion device
236             ; initialization routine, but will MakeDosNode then set up a
237             ; BootNode, and Enqueue() on eb_MountList.
238             ;
239             align 2
240             move.l a6,-(a7)             ; Push A6 to stack
241             ;move.w #$00B8,$dff09a       ; Disable interrupts during init
242             move.l  #3,PiSCSIDebugMe
243
244             move.l  #11,PiSCSIDebugMe
245             movea.l 4,a6
246             lea LibName(pc),a1
247             jsr FindResident(a6)
248             move.l  #10,PiSCSIDebugMe
249             cmp.l #0,d0
250             bne.s SkipDriverLoad        ; Library is already loaded, jump straight to partitions
251
252             move.l  #4,PiSCSIDebugMe
253             movea.l 4,a6
254             move.l #$40000,d0
255             moveq #0,d1
256             jsr AllocMem(a6)            ; Allocate memory for the PiStorm to copy the driver to
257
258             move.l  d0,PiSCSIDriver     ; Copy the PiSCSI driver to allocated memory and patch offsets
259
260             move.l  #5,PiSCSIDebugMe
261             move.l  d0,a1
262             move.l  #0,d1
263             movea.l  4,a6
264             add.l #$02c,a1
265             jsr InitResident(a6)        ; Initialize the PiSCSI driver
266
267 SkipDriverLoad:
268             lea ExpansionName(pc),a1
269             moveq #0,d0
270             jsr OpenLibrary(a6)         ; Open expansion.library to make this work, somehow
271             move.l d0,a6
272
273 PartitionLoop:
274             move.l  #9,PiSCSIDebugMe
275             move.l PiSCSIGetPart,d0     ; Get the available partition in the current slot
276             beq.s EndPartitions         ; If the next partition returns 0, there's no additional partitions
277             move.l d0,a0
278             jsr MakeDosNode(a6)
279             move.l  #7,PiSCSIDebugMe
280             move.l d0,a0
281             move.l PiSCSIGetPrio,d0
282             move.l #0,d1
283             move.l PiSCSIAddr1,a1
284             jsr AddBootNode(a6)
285             move.l  #8,PiSCSIDebugMe
286             move.l #1,PiSCSINextPart    ; Switch to the next partition
287             bra.w PartitionLoop
288
289
290 EndPartitions:
291             move.l a6,a1
292             movea.l 4,a6
293             jsr CloseLibrary(a6)
294             move.l  #6,PiSCSIDebugMe
295
296             move.l  (a7)+,a6            ; Pop A6 from stack
297
298             ;move.w #$80B8,$dff09a       ; Re-enable interrupts
299             moveq.l #1,d0               ; indicate "success"
300             rts
301             END