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