Home | History | Annotate | Line # | Download | only in boot
startit.s revision 1.6
      1 /*	$NetBSD: startit.s,v 1.6 2001/02/26 14:58:37 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.6 2001/02/26 14:58:37 is Exp $
     35  */
     36 #include <machine/asm.h>
     37 
     38 	.set	ABSEXECBASE,4
     39 
     40 	.text
     41 
     42 ENTRY_NOPROFILE(startit)
     43 #if TESTONAMIGA
     44 	movew	#0x999,0xdff180		| gray
     45 #endif
     46 #if TESTONDRACO
     47 	moveb	#0,0x200003c8
     48 	moveb	#31,0x200003c9
     49 	moveb	#31,0x200003c9
     50 	moveb	#31,0x200003c9
     51 #endif
     52 	movel	sp,a3
     53 	movel	4:w,a6
     54 	lea	pc@(start_super:w),a5
     55 	jmp	a6@(-0x1e)		| supervisor-call
     56 
     57 start_super:
     58 #if TESTONAMIGA
     59 	movew	#0x900,0xdff180		| dark red
     60 #endif
     61 	movew	#0x2700,sr
     62 
     63 	| the BSD kernel wants values into the following registers:
     64 	| a0:  fastmem-start
     65 	| d0:  fastmem-size
     66 	| d1:  chipmem-size
     67 	| d3:  Amiga specific flags
     68 	| d4:  E clock frequency
     69 	| d5:  AttnFlags (cpuid)
     70 	| d6:  boot partition offset
     71 	| d7:  boothowto
     72 	| a4:  esym location
     73 	| a2:  Inhibit sync flags
     74 	| All other registers zeroed for possible future requirements.
     75 
     76 	lea	pc@(_startit:w),sp	| make sure we have a good stack ***
     77 
     78 	movel	a3@(4),a1		| loaded kernel
     79 	movel	a3@(8),d2		| length of loaded kernel
     80 |	movel	a3@(12),sp		| entry point in stack pointer
     81 	movel	a3@(12),a6		| entry point		***
     82 	movel	a3@(16),a0		| fastmem-start
     83 	movel	a3@(20),d0		| fastmem-size
     84 	movel	a3@(24),d1		| chipmem-size
     85 	movel	a3@(28),d7		| boothowto
     86 	movel	a3@(32),a4		| esym
     87 	movel	a3@(36),d5		| cpuid
     88 	movel	a3@(40),d4		| E clock frequency
     89 	movel	a3@(44),d3		| Amiga flags
     90 	movel	a3@(48),a2		| Inhibit sync flags
     91 	movel	a3@(52),d6		| boot partition offset
     92 
     93 	cmpb	#0x7D,a3@(36)		| is it DraCo?
     94 	movel	a3@(56),a3		| Load to fastmem flag
     95 	jeq	nott			| yes, switch off MMU later
     96 
     97 					| no, it is an Amiga:
     98 
     99 #if TESTONAMIGA
    100 	movew	#0xf00,0xdff180		|red
    101 #endif
    102 #if TESTONDRACO
    103 	moveb	#0,0x200003c8
    104 	moveb	#63,0x200003c9
    105 	moveb	#0,0x200003c9
    106 	moveb	#0,0x200003c9
    107 #endif
    108 
    109 	movew	#(1<<9),0xdff096	| disable DMA on Amigas.
    110 
    111 | ------ mmu off start -----
    112 
    113 	btst	#3,d5			| AFB_68040,SysBase->AttnFlags
    114 	jeq	not040
    115 
    116 | Turn off 68040/060 MMU
    117 
    118 	subl	a5,a5
    119 	.word 0x4e7b,0xd003		| movec a5,tc
    120 	.word 0x4e7b,0xd806		| movec a5,urp
    121 	.word 0x4e7b,0xd807		| movec a5,srp
    122 	.word 0x4e7b,0xd004		| movec a5,itt0
    123 	.word 0x4e7b,0xd005		| movec a5,itt1
    124 	.word 0x4e7b,0xd006		| movec a5,dtt0
    125 	.word 0x4e7b,0xd007		| movec a5,dtt1
    126 	jra	nott
    127 
    128 not040:
    129 	lea	pc@(zero:w),a5
    130 	pmove	a5@,tc			| Turn off MMU
    131 	lea	pc@(nullrp:w),a5
    132 	pmove	a5@,crp			| Turn off MMU some more
    133 	pmove	a5@,srp			| Really, really, turn off MMU
    134 
    135 | Turn off 68030 TT registers
    136 
    137 	btst	#2,d5			| AFB_68030,SysBase->AttnFlags
    138 	jeq	nott			| Skip TT registers if not 68030
    139 	lea	pc@(zero:w),a5
    140 	.word 0xf015,0x0800		| pmove a5@,tt0 (gas only knows about 68851 ops..)
    141 	.word 0xf015,0x0c00		| pmove a5@,tt1 (gas only knows about 68851 ops..)
    142 
    143 nott:
    144 | ---- mmu off end ----
    145 #if TESTONAMIGA
    146 	movew	#0xf60,0xdff180		| orange
    147 #endif
    148 #if TESTONDRACO
    149 	moveb	#0,0x200003c8
    150 	moveb	#63,0x200003c9
    151 	moveb	#24,0x200003c9
    152 	moveb	#0,0x200003c9
    153 #endif
    154 
    155 
    156 | ---- copy kernel start ----
    157 
    158 | removed Z flag
    159 |	tstl	a3			| Can we load to fastmem?
    160 |	jeq	L0			| No, leave destination at 0
    161 	movl	a0,a3			| Move to start of fastmem chunk
    162 	addl	a0,a6			| relocate kernel entry point
    163 
    164 	addl	#3,d2
    165 	andl	#0xfffffffc,d2		| round up.
    166 
    167 	| determine if the kernel need be copied upwards or downwards
    168 
    169 	cmpl	a1,a3			| a3-a1
    170 	bcs	above			| source is above
    171 
    172 	movl	a0,sp
    173 	addl	d0,sp			| move the stack to the end of segment
    174 
    175 	| copy from below upwards requires copying from end to start.
    176 
    177 	addl	d2,a3			| one long word past
    178 	addl	d2,a1			| one long word past
    179 
    180 	subl	#4,sp			| alloc space
    181 	movl	a1,sp@-			| save source
    182 	movl	a3,sp@-			| save destination
    183 
    184 	| copy copier to end of segment
    185 
    186 	movl	sp,a3
    187 	subl	#256,a3			| end of segment save our stack
    188 
    189 	lea	pc@(_startit_end:w),a1
    190 	movl	a0,sp@-			| save segment start
    191 	lea	pc@(below:w),a0
    192 
    193 L0:	movw	a1@-,a3@-
    194 	cmpl	a0,a1
    195 	bne	L0
    196 	movl	sp@,a0			| restore segment start
    197 	movl	a3,sp@			| address of relocated below
    198 	addl	#(ckend - below),a3
    199 	movl	a3,sp@(12)		| address of ckend for later
    200 | ---- switch off cache ----
    201 	bra	Lchoff			| and to relocated below
    202 
    203 
    204 below:	movl	sp@+,a3			| recover destination
    205 	movl	sp@+,a1			| recover source
    206 
    207 L1:	movl	a1@-,a3@-		| copy kernel
    208 	subl	#4,d2
    209 	bne	L1
    210 
    211 | ---- switch off cache ----
    212 	bra	Lchoff			| and to relocated ckend
    213 
    214 above:	movl	a1@+,a3@+
    215 	subl	#4,d2
    216 	bne	above
    217 
    218 	lea	pc@(ckend:w),a1
    219 	movl	a3,sp@-
    220 	pea	pc@(_startit_end:w)
    221 L2:
    222 	movl	a1@+,a3@+
    223 	cmpl	sp@,a1
    224 	bcs	L2
    225 	addql	#4,sp
    226 
    227 #if TESTONAMIGA
    228 	movew	#0xFF0,0xdff180		| yellow
    229 #endif
    230 #if TESTONDRACO
    231 	moveb	#0,0x200003c8
    232 	moveb	#63,0x200003c9
    233 	moveb	#63,0x200003c9
    234 	moveb	#0,0x200003c9
    235 #endif
    236 
    237 | ---- switch off cache ----
    238 Lchoff:	btst	#3,d5
    239 	jeq	L3c
    240 	.word	0xf4f8
    241 L3c:	movl	d2,sp@-			| save d2
    242 	movql	#0,d2			| switch off cache to ensure we use
    243 	movec	d2,cacr			| valid kernel data
    244 	movl	sp@+,d2			| restore d2
    245 	rts
    246 
    247 | ---- copy kernel end ----
    248 
    249 ckend:
    250 #if TESTONAMIGA
    251 	movew	#0x0ff,0xdff180		| petrol
    252 #endif
    253 #if TESTONDRACO
    254 	moveb	#0,0x200003c8
    255 	moveb	#0,0x200003c9
    256 	moveb	#63,0x200003c9
    257 	moveb	#63,0x200003c9
    258 #endif
    259 
    260 	movl	d5,d2
    261 	roll	#8,d2
    262 	cmpb	#0x7D,d2
    263 	jne	noDraCo
    264 
    265 | DraCo: switch off MMU now:
    266 
    267 	subl	a5,a5
    268 	.word 0x4e7b,0xd003		| movec a5,tc
    269 	.word 0x4e7b,0xd806		| movec a5,urp
    270 	.word 0x4e7b,0xd807		| movec a5,srp
    271 	.word 0x4e7b,0xd004		| movec a5,itt0
    272 	.word 0x4e7b,0xd005		| movec a5,itt1
    273 	.word 0x4e7b,0xd006		| movec a5,dtt0
    274 	.word 0x4e7b,0xd007		| movec a5,dtt1
    275 
    276 noDraCo:
    277 	moveq	#0,d2			| zero out unused registers
    278 	movel	d2,a1			| (might make future compatibility
    279 	movel	d2,a3			|  would have known contents)
    280 	movel	d2,a5
    281 	movel	a6,sp			| entry point into stack pointer
    282 	movel	d2,a6
    283 
    284 #if TESTONAMIGA
    285 	movew	#0x0F0,0xdff180		| green
    286 #endif
    287 #if TESTONDRACO
    288 	moveb	#0,0x200003c8
    289 	moveb	#0,0x200003c9
    290 	moveb	#63,0x200003c9
    291 	moveb	#0,0x200003c9
    292 #endif
    293 
    294 	jmp	sp@			| jump to kernel entry point
    295 
    296 
    297 | A do-nothing MMU root pointer (includes the following long as well)
    298 
    299 nullrp:	.long	0x7fff0001
    300 zero:	.long	0
    301 
    302 ENTRY_NOPROFILE(startit_end)
    303