]> git.sesse.net Git - pistorm/blob - platforms/amiga/piscsi/device_driver_amiga/bootrom.s
[WIP] PiSCSI, Pi-NET and some other things
[pistorm] / platforms / amiga / piscsi / device_driver_amiga / bootrom.s
1 /* ConfigDev passed in a3 */
2 /*
3 struct ConfigDev {
4     struct Node   cd_Node; // 0  2ptr,2byte,1ptr = 14byte
5     UBYTE   cd_Flags; // 14
6     UBYTE   cd_Pad; // 15
7     struct ExpansionRom cd_Rom; // 16   16bytes
8     APTR    cd_BoardAddr; // 32
9     ...
10 */
11 .set SysBase,4
12 .set OpenLibrary,-552
13 .set CloseLibrary,-414
14 .set PutStr,-948
15 .set VPrintf,-954
16 .set AllocMem,-198
17 .set FindResident,-96
18
19 start:
20     jmp realstart(pc)
21     handover:
22     jmp trampoline(pc)
23
24 .align 4
25 realstart:
26     movea.l SysBase,a6 /* allocate RAM for loading ourselves to */
27     move.l #0x40000,d0
28     moveq #0,d1 /* MEMF_ANY */
29     jsr AllocMem(a6)
30     tst.l d0
31     beq allocfail
32
33     move.l d0, a4 /* load addr */
34
35     move.l (a7)+,a3 /* restore configdev address from stack */
36     jmp 0x24(a4) /* jmp to handover at new memory location (0x20+0x04) */
37
38 .align 4
39 allocfail:  
40     move.l d1,0xdff180
41     add.l #1,d1
42     bra allocfail
43
44 /* we will arrive here in our copy in amiga RAM */
45 /* a0 contains board addr, a3 contains configdev addr */
46 .align 4
47 trampoline:
48     lea configdev(pc),a1
49     move.l a3,(a1) /* store configdev pointer */
50
51     move.l a4, a0 /* board addr not needed anymore, keep loadaddr in a0 */
52
53     /* add resident ---------------------- */
54
55     /* mntsd.device is at loadaddr + 0x400 (skip 2 blocks) */
56     move.l  a0,-(a7)
57     add.l   #0x400, a0
58     /* relocate the binary (hunk) */
59     jsr     relocstart(pc)
60     move.l  (a7)+, a0 /* address of loaded mntsd.device */
61     move.l  a0, a4
62     move.l  a4, a1 /* restore board addr */
63
64     add.l   #0x400+0x180, a1 /* start of mntsd.device + $180 = romtag FIXME */
65     move.l  #0, d1 /* no seglist */
66     move.l  4,a6
67     jsr     -102(a6) /* InitResident */
68     /* object = InitResident(resident, segList) */
69     /* D0                    A1        D1 */
70
71     /* make dos node --------------------- */
72
73     jmp initdos(pc)
74
75 .align 4
76 configdev:
77     .long 0
78
79 segtprs:
80     .long 0
81     .long 0
82
83     .align 4
84     relocstart:
85     lea.l  segptrs(pc), a1
86
87     move.l 8(a0), d4 /* number of hunks */
88     move.l #0, d5
89
90     /*
91         a0: executable base addr
92         a1: segptrs
93         a2: addr of hunk0
94
95         d4: numhunks
96         d5: pass#
97         d6: current hunk addr
98     */
99
100     /* hunk 0 address in memory */
101     move.l a0, d6
102     add.l  #0x24, d6
103     move.l d6, a2 /* addr of first hunk */
104     move.l d6, (a1) /* store pointer to this hunk in segptrs[1] */
105
106 relocpass:
107     move.l a2, a3
108     move.l 0x14(a0), d0 /* ptr to first hunk size */
109
110     lsl.l  #2, d0 /* firsthunk + first size */
111     add.l  d0, a3 /* end of first hunk, start of reloc table */
112
113     jsr  reloctables(pc)
114
115     add.l  #4, a3 /* skip hunk_end */
116     add.l  #4, a3 /* skip hunk_data */
117     move.l (a3)+, d0 /* size of data hunk */
118     lsl.l  #2, d0
119
120     move.l a3, 4(a1) /* store pointer to this hunk in segptrs[1] */
121     move.l a3, d6 /* save current hunk ptr for patching CHECKME */
122     add.l  d0, a3 /* arrive at reloc tables of data hunk */
123
124     jsr   reloctables(pc)
125
126     cmp #1, d5
127     bge rcomplete
128
129     /* start pass 1 */
130     move.l #1, d5
131     move.l a2, d6 /* addr of first hunk */
132     bra relocpass
133
134 rcomplete:
135     rts
136
137 .align 4
138 reloctables:
139     move.l (a3)+, d2 /* skip 0000 03ec marker */
140     reloctable:
141     move.l (a3)+, d2 /* number of relocs to process */
142
143     tst.w  d2
144     beq    relocdone /* done if zero */
145
146     move.l (a3)+, d1  /* segment number to point to */
147
148     lsl.l #2, d1
149     move.l (a1,d1), d1 /* offset to add to target slots */
150
151     bra rloop
152 relocloop:
153     move.l (a3)+, a4
154
155     tst.w d5 /* pass = 0? */
156     beq rloop
157
158     /* pass = 1, so patch */
159     add.l  d6, a4 /* add current hunk address */
160     add.l  d1, (a4) /* the actual patching */
161
162     move.l d1, 0xdff180
163     rloop:
164     dbra   d2, relocloop
165     jmp reloctable(pc)
166     relocdone:
167     rts
168
169 .align 4
170 initdos:  
171     move.l  4,a6
172     lea     expansionname(pc),a1
173
174     moveq   #37, d0
175     jsr     OpenLibrary(a6) /* open expansion.library */
176     tst.l   d0
177     beq.s   nodos
178     move.l  d0,a6
179
180         /*movem.l a0-a6/d0-d6,-(a7)
181         move.l #0xbeef,d2
182         lea.l fmtdebug(pc),a1
183         jsr printf(pc)
184         movem.l (a7)+,a0-a6/d0-d6*/
185
186     lea     dosnode(pc),a0
187     lea     diskname(pc),a1
188     move.l  a1,(a0) /* store in parmpkt */
189     lea     devicename(pc),a1
190     move.l  a1,4(a0) /* store in parmpkt */
191
192     jsr     -144(a6) /* MakeDosNode */
193     move.l  d0, a0 /* fresh device node */
194
195     /* add boot node --------------------- */
196
197     move.l  #0, d0
198     move.l  #0, d1
199     move.l configdev(pc),a1
200     /*move.l  #0, a1*/ /* later put ConfigDev here (a3) */
201     jsr     -36(a6) /* AddBootNode */
202
203     move.l  a6,a1 /* close expansion library */
204     move.l  4,a6
205     jsr     CloseLibrary(a6)
206     moveq   #1,d0
207     move.l  (a7)+,a6
208     rts
209
210 nodos:
211     move.l d1,0xdff180
212     add.l #1,d1
213     bra nodos
214
215     moveq   #1,d0
216     move.l  (a7)+,a6
217     rts
218
219 .align 4
220 diskname:
221     .asciz "PDH0"
222     .align 4
223 devicename:
224     .asciz "pi-scsi.device"
225     .align 4
226 expansionname:
227     .asciz "expansion.library"
228     .align 4
229 dosnode:
230     .long 0 /* dos disk name */
231     .long 0 /* device file name */
232     .long 0 /* unit */
233     .long 0 /* flags */
234     .long 16 /* length of node? */
235     .long 128 /* longs in a block */
236     .long 0
237     .long 4 /* surfaces */
238     .long 1 /* sectors per block */
239     .long 256 /* blocks per track */
240     .long 2 /* reserved bootblocks 256 = 128KB */
241     .long 0
242     .long 0
243     .long 2  /* lowcyl FIXME */
244     /*.long 2047*/ /* hicyl */
245     .long 1023
246     .long 10 /* buffers */
247     .long 0 /* MEMF_ANY */
248     .long 0x0001fe00 /* MAXTRANS */
249     .long 0x7ffffffe /* Mask */
250     .long -1 /* boot prio */
251     .long 0x444f5303 /* dostype: DOS3 */