1/* $NetBSD: startit.s,v 1.5 1998/11/11 20:57:33 is Exp $ */ 2 3/* 4 * Copyright (c) 1996 Ignatios Souvatzis 5 * Copyright (c) 1994 Michael L. Hitch 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Michael L. Hitch. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 * 34 * From: $NetBSD: startit.s,v 1.5 1998/11/11 20:57:33 is Exp $ 35 */ 36 37 .set ABSEXECBASE,4 38 39 .text 40 41 .globl _startit 42 .globl _startit_end 43 44_startit: 45#if TESTONAMIGA 46 movew #0x999,0xdff180 | gray 47#endif 48#if TESTONDRACO 49 moveb #0,0x200003c8 50 moveb #31,0x200003c9 51 moveb #31,0x200003c9 52 moveb #31,0x200003c9 53#endif 54 movel sp,a3 55 movel 4:w,a6 56 lea pc@(start_super:w),a5 57 jmp a6@(-0x1e) | supervisor-call 58 59start_super: 60#if TESTONAMIGA 61 movew #0x900,0xdff180 | dark red 62#endif 63 movew #0x2700,sr 64 65 | the BSD kernel wants values into the following registers: 66 | a0: fastmem-start 67 | d0: fastmem-size 68 | d1: chipmem-size 69 | d3: Amiga specific flags 70 | d4: E clock frequency 71 | d5: AttnFlags (cpuid) 72 | d6: boot partition offset 73 | d7: boothowto 74 | a4: esym location 75 | a2: Inhibit sync flags 76 | All other registers zeroed for possible future requirements. 77 78 lea pc@(_startit:w),sp | make sure we have a good stack *** 79 80 movel a3@(4),a1 | loaded kernel 81 movel a3@(8),d2 | length of loaded kernel 82| movel a3@(12),sp | entry point in stack pointer 83 movel a3@(12),a6 | entry point *** 84 movel a3@(16),a0 | fastmem-start 85 movel a3@(20),d0 | fastmem-size 86 movel a3@(24),d1 | chipmem-size 87 movel a3@(28),d7 | boothowto 88 movel a3@(32),a4 | esym 89 movel a3@(36),d5 | cpuid 90 movel a3@(40),d4 | E clock frequency 91 movel a3@(44),d3 | Amiga flags 92 movel a3@(48),a2 | Inhibit sync flags 93 movel a3@(52),d6 | boot partition offset 94 95 cmpb #0x7D,a3@(36) | is it DraCo? 96 movel a3@(56),a3 | Load to fastmem flag 97 jeq nott | yes, switch off MMU later 98 99 | no, it is an Amiga: 100 101#if TESTONAMIGA 102 movew #0xf00,0xdff180 |red 103#endif 104#if TESTONDRACO 105 moveb #0,0x200003c8 106 moveb #63,0x200003c9 107 moveb #0,0x200003c9 108 moveb #0,0x200003c9 109#endif 110 111 movew #(1<<9),0xdff096 | disable DMA on Amigas. 112 113| ------ mmu off start ----- 114 115 btst #3,d5 | AFB_68040,SysBase->AttnFlags 116 jeq not040 117 118| Turn off 68040/060 MMU 119 120 subl a5,a5 121 .word 0x4e7b,0xd003 | movec a5,tc 122 .word 0x4e7b,0xd806 | movec a5,urp 123 .word 0x4e7b,0xd807 | movec a5,srp 124 .word 0x4e7b,0xd004 | movec a5,itt0 125 .word 0x4e7b,0xd005 | movec a5,itt1 126 .word 0x4e7b,0xd006 | movec a5,dtt0 127 .word 0x4e7b,0xd007 | movec a5,dtt1 128 jra nott 129 130not040: 131 lea pc@(zero:w),a5 132 pmove a5@,tc | Turn off MMU 133 lea pc@(nullrp:w),a5 134 pmove a5@,crp | Turn off MMU some more 135 pmove a5@,srp | Really, really, turn off MMU 136 137| Turn off 68030 TT registers 138 139 btst #2,d5 | AFB_68030,SysBase->AttnFlags 140 jeq nott | Skip TT registers if not 68030 141 lea pc@(zero:w),a5 142 .word 0xf015,0x0800 | pmove a5@,tt0 (gas only knows about 68851 ops..) 143 .word 0xf015,0x0c00 | pmove a5@,tt1 (gas only knows about 68851 ops..) 144 145nott: 146| ---- mmu off end ---- 147#if TESTONAMIGA 148 movew #0xf60,0xdff180 | orange 149#endif 150#if TESTONDRACO 151 moveb #0,0x200003c8 152 moveb #63,0x200003c9 153 moveb #24,0x200003c9 154 moveb #0,0x200003c9 155#endif 156 157 158| ---- copy kernel start ---- 159 160| removed Z flag 161| tstl a3 | Can we load to fastmem? 162| jeq L0 | No, leave destination at 0 163 movl a0,a3 | Move to start of fastmem chunk 164 addl a0,a6 | relocate kernel entry point 165 166 addl #3,d2 167 andl #0xfffffffc,d2 | round up. 168 169 | determine if the kernel need be copied upwards or downwards 170 171 cmpl a1,a3 | a3-a1 172 bcs above | source is above 173 174 movl a0,sp 175 addl d0,sp | move the stack to the end of segment 176 177 | copy from below upwards requires copying from end to start. 178 179 addl d2,a3 | one long word past 180 addl d2,a1 | one long word past 181 182 subl #4,sp | alloc space 183 movl a1,sp@- | save source 184 movl a3,sp@- | save destination 185 186 | copy copier to end of segment 187 188 movl sp,a3 189 subl #256,a3 | end of segment save our stack 190 191 lea pc@(_startit_end:w),a1 192 movl a0,sp@- | save segment start 193 lea pc@(below:w),a0 194 195L0: movw a1@-,a3@- 196 cmpl a0,a1 197 bne L0 198 movl sp@,a0 | restore segment start 199 movl a3,sp@ | address of relocated below 200 addl #(ckend - below),a3 201 movl a3,sp@(12) | address of ckend for later 202| ---- switch off cache ---- 203 bra Lchoff | and to relocated below 204 205 206below: movl sp@+,a3 | recover destination 207 movl sp@+,a1 | recover source 208 209L1: movl a1@-,a3@- | copy kernel 210 subl #4,d2 211 bne L1 212 213| ---- switch off cache ---- 214 bra Lchoff | and to relocated ckend 215 216above: movl a1@+,a3@+ 217 subl #4,d2 218 bne above 219 220 lea pc@(ckend:w),a1 221 movl a3,sp@- 222 pea pc@(_startit_end:w) 223L2: 224 movl a1@+,a3@+ 225 cmpl sp@,a1 226 bcs L2 227 addql #4,sp 228 229#if TESTONAMIGA 230 movew #0xFF0,0xdff180 | yellow 231#endif 232#if TESTONDRACO 233 moveb #0,0x200003c8 234 moveb #63,0x200003c9 235 moveb #63,0x200003c9 236 moveb #0,0x200003c9 237#endif 238 239| ---- switch off cache ---- 240Lchoff: btst #3,d5 241 jeq L3c 242 .word 0xf4f8 243L3c: movl d2,sp@- | save d2 244 movql #0,d2 | switch off cache to ensure we use 245 movec d2,cacr | valid kernel data 246 movl sp@+,d2 | restore d2 247 rts 248 249| ---- copy kernel end ---- 250 251ckend: 252#if TESTONAMIGA 253 movew #0x0ff,0xdff180 | petrol 254#endif 255#if TESTONDRACO 256 moveb #0,0x200003c8 257 moveb #0,0x200003c9 258 moveb #63,0x200003c9 259 moveb #63,0x200003c9 260#endif 261 262 movl d5,d2 263 roll #8,d2 264 cmpb #0x7D,d2 265 jne noDraCo 266 267| DraCo: switch off MMU now: 268 269 subl a5,a5 270 .word 0x4e7b,0xd003 | movec a5,tc 271 .word 0x4e7b,0xd806 | movec a5,urp 272 .word 0x4e7b,0xd807 | movec a5,srp 273 .word 0x4e7b,0xd004 | movec a5,itt0 274 .word 0x4e7b,0xd005 | movec a5,itt1 275 .word 0x4e7b,0xd006 | movec a5,dtt0 276 .word 0x4e7b,0xd007 | movec a5,dtt1 277 278noDraCo: 279 moveq #0,d2 | zero out unused registers 280 movel d2,a1 | (might make future compatibility 281 movel d2,a3 | would have known contents) 282 movel d2,a5 283 movel a6,sp | entry point into stack pointer 284 movel d2,a6 285 286#if TESTONAMIGA 287 movew #0x0F0,0xdff180 | green 288#endif 289#if TESTONDRACO 290 moveb #0,0x200003c8 291 moveb #0,0x200003c9 292 moveb #63,0x200003c9 293 moveb #0,0x200003c9 294#endif 295 296 jmp sp@ | jump to kernel entry point 297 298 299| A do-nothing MMU root pointer (includes the following long as well) 300 301nullrp: .long 0x7fff0001 302zero: .long 0 303 304_startit_end: 305