Home | History | Annotate | Line # | Download | only in evbsh3
locore.S revision 1.2
      1  1.2  uch /*	$NetBSD: locore.S,v 1.2 2002/02/28 01:53:42 uch Exp $	*/
      2  1.1  uch 
      3  1.1  uch /*-
      4  1.1  uch  * Copyright (c) 1993, 1994, 1995, 1997
      5  1.1  uch  *	Charles M. Hannum.  All rights reserved.
      6  1.1  uch  * Copyright (c) 1990 The Regents of the University of California.
      7  1.1  uch  * All rights reserved.
      8  1.1  uch  *
      9  1.1  uch  * This code is derived from software contributed to Berkeley by
     10  1.1  uch  * William Jolitz.
     11  1.1  uch  *
     12  1.1  uch  * Redistribution and use in source and binary forms, with or without
     13  1.1  uch  * modification, are permitted provided that the following conditions
     14  1.1  uch  * are met:
     15  1.1  uch  * 1. Redistributions of source code must retain the above copyright
     16  1.1  uch  *    notice, this list of conditions and the following disclaimer.
     17  1.1  uch  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.1  uch  *    notice, this list of conditions and the following disclaimer in the
     19  1.1  uch  *    documentation and/or other materials provided with the distribution.
     20  1.1  uch  * 3. All advertising materials mentioning features or use of this software
     21  1.1  uch  *    must display the following acknowledgement:
     22  1.1  uch  *	This product includes software developed by the University of
     23  1.1  uch  *	California, Berkeley and its contributors.
     24  1.1  uch  * 4. Neither the name of the University nor the names of its contributors
     25  1.1  uch  *    may be used to endorse or promote products derived from this software
     26  1.1  uch  *    without specific prior written permission.
     27  1.1  uch  *
     28  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  1.1  uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  1.1  uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  1.1  uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  1.1  uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  1.1  uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  1.1  uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  1.1  uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  1.1  uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  1.1  uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  1.1  uch  * SUCH DAMAGE.
     39  1.1  uch  *
     40  1.1  uch  *	@(#)locore.s	7.3 (Berkeley) 5/13/91
     41  1.1  uch  */
     42  1.1  uch 
     43  1.2  uch #include "opt_memsize.h"
     44  1.1  uch #include "assym.h"
     45  1.1  uch 
     46  1.2  uch #if defined(SH3) && defined(SH4)
     47  1.2  uch #error "evbsh3 port don't support SH3,SH4 common kernel."
     48  1.2  uch #endif
     49  1.1  uch 
     50  1.2  uch #include <sh3/asm.h>
     51  1.2  uch #include <sh3/locore.h>
     52  1.2  uch #include <sh3/trapreg.h>
     53  1.2  uch #include <sh3/mmu_sh3.h>
     54  1.2  uch #include <sh3/mmu_sh4.h>
     55  1.2  uch #include <sh3/cache_sh3.h>
     56  1.2  uch #include <sh3/cache_sh4.h>
     57  1.1  uch 
     58  1.1  uch #define INIT_STACK	IOM_RAM_BEGIN + IOM_RAM_SIZE - 0x00001000
     59  1.1  uch 
     60  1.1  uch NENTRY(start)
     61  1.1  uch 	/* Set SP to initial position */
     62  1.1  uch 	mov.l	XLtmpstk, r15
     63  1.1  uch 
     64  1.2  uch 	/* Mask all interrupt */
     65  1.2  uch 	__INTR_MASK(r0, r1)
     66  1.1  uch 
     67  1.1  uch 	/* Set Register Bank to Bank 0 */
     68  1.1  uch 	mov.l	SR_init, r0
     69  1.1  uch 	ldc	r0, sr
     70  1.1  uch 
     71  1.2  uch 	/* MMU off */
     72  1.1  uch 	xor	r0, r0
     73  1.2  uch 	MOV	(MMUCR, r2)
     74  1.2  uch 	mov.l	r0, @r2
     75  1.1  uch 
     76  1.1  uch 	bra	start1
     77  1.1  uch 	nop
     78  1.1  uch 	.align	2
     79  1.1  uch SR_init:	.long	0x500000F0
     80  1.2  uch REG_SYMBOL(MMUCR)
     81  1.1  uch start1:
     82  1.1  uch 
     83  1.1  uch #ifdef ROMIMAGE
     84  1.1  uch 	/* Initialize BUS State Control Regs. */
     85  1.1  uch 	mov.l	_ROM_START, r3
     86  1.1  uch 	mov.l	XL_ram_start, r4
     87  1.1  uch 	mov.l	@r4, r4
     88  1.1  uch 	sub	r3, r4
     89  1.1  uch 	/* Set Bus State Controler */
     90  1.1  uch 	mov.l	XLInitializeBsc, r0
     91  1.1  uch 	sub	r4, r0
     92  1.1  uch 	jsr	@r0
     93  1.1  uch 	nop
     94  1.1  uch 
     95  1.1  uch 	/* Move kernel image from ROM area to RAM area */
     96  1.1  uch 	mov.l	___end, r0
     97  1.1  uch 	mov.l	___start, r1
     98  1.1  uch 	mov.l	_KERNBASE, r2
     99  1.1  uch 	sub	r2, r0
    100  1.1  uch 	sub	r2, r1
    101  1.1  uch 	sub	r1, r0
    102  1.1  uch 	add	#4, r0		/* size of bytes to be copied */
    103  1.1  uch 	shlr2	r0		/* number of long word */
    104  1.1  uch 	mov.l	_ROM_START, r3
    105  1.1  uch 	add	r3, r1		/* src address */
    106  1.1  uch 	mov.l	___start, r3
    107  1.1  uch 	sub	r2, r3
    108  1.1  uch 	mov.l	XL_ram_start, r4
    109  1.1  uch 	mov.l	@r4, r4
    110  1.1  uch 	add	r4, r3		/* dest address */
    111  1.1  uch 1:
    112  1.1  uch 	mov.l	@r1+, r4
    113  1.1  uch 	mov.l	r4, @r3
    114  1.1  uch 	add	#4, r3
    115  1.1  uch 	dt	r0		/* decrement and Test */
    116  1.1  uch 	bf	1b
    117  1.1  uch 	/* kernel image copy end */
    118  1.1  uch 
    119  1.1  uch 	mov.l	LXstart_in_RAM, r0
    120  1.1  uch 	jmp	@r0		/* jump to RAM area */
    121  1.1  uch 	nop
    122  1.1  uch 
    123  1.1  uch 	.align	2
    124  1.1  uch LXstart_in_RAM:
    125  1.1  uch 	.long	start_in_RAM
    126  1.1  uch XL_ram_start:
    127  1.1  uch 	.long	_C_LABEL(ram_start)
    128  1.2  uch #else /* ROMIMAGE */
    129  1.1  uch #ifndef	DONT_INIT_BSC
    130  1.1  uch 	/* Set Bus State Controler */
    131  1.1  uch 	mov.l	XLInitializeBsc, r0
    132  1.1  uch 	jsr	@r0
    133  1.1  uch 	nop
    134  1.2  uch #endif /* !DONT_INIT_BSC */
    135  1.2  uch #endif /* ROMIMAGE */
    136  1.1  uch 
    137  1.1  uch start_in_RAM:
    138  1.1  uch 	mova	1f, r0
    139  1.1  uch 	mov	r0, r4
    140  1.1  uch 	mov.l	XLinitSH3, r0
    141  1.1  uch 	jsr	@r0		/* call initSH3() */
    142  1.1  uch 	nop
    143  1.1  uch 
    144  1.1  uch 	.align	2
    145  1.1  uch 1:
    146  1.1  uch 
    147  1.1  uch #ifdef SH4
    148  1.1  uch 	/* CCR must be accessed from P2 area */
    149  1.1  uch 	mova	cache_on, r0
    150  1.1  uch 	mov	r0, r5
    151  1.1  uch 	mov.l	XLtoP2, r1
    152  1.1  uch 	add	r1, r5
    153  1.1  uch 	mova	main_label, r0
    154  1.1  uch 	mov	r0, r2
    155  1.2  uch 	MOV	(CCR, r3)
    156  1.1  uch 	mov.l	XL_CCRVAL, r4
    157  1.1  uch 	jmp	@r5
    158  1.1  uch 	nop
    159  1.1  uch 
    160  1.1  uch 	.align	2
    161  1.1  uch cache_on:
    162  1.1  uch 	mov.l	r4, @r3 /* Write to CCR */
    163  1.1  uch 	nop
    164  1.1  uch 	nop
    165  1.1  uch 	nop
    166  1.1  uch 	nop
    167  1.1  uch 	nop
    168  1.1  uch 	nop
    169  1.1  uch 	nop
    170  1.1  uch 	nop
    171  1.1  uch 	jmp @r2
    172  1.1  uch 	nop
    173  1.1  uch 
    174  1.1  uch 	.align	2
    175  1.1  uch main_label:
    176  1.2  uch #endif /* SH4 */
    177  1.1  uch 	mov.l	XLmain, r0
    178  1.1  uch 	jsr	@r0		/* call main() */
    179  1.1  uch 	nop
    180  1.1  uch 
    181  1.1  uch 		.align	2
    182  1.1  uch 
    183  1.1  uch #ifndef	DONT_INIT_BSC
    184  1.1  uch XLInitializeBsc:.long	_C_LABEL(InitializeBsc)
    185  1.2  uch #endif /* DONT_INIT_BSC */
    186  1.1  uch ___start:	.long	start
    187  1.1  uch ___etext:	.long	_etext
    188  1.1  uch ___end:		.long	_end
    189  1.1  uch XLtmpstk:	.long	INIT_STACK
    190  1.2  uch _KERNBASE:	.long	0x8c000000
    191  1.1  uch _ROM_START:	.long	IOM_ROM_BEGIN
    192  1.1  uch XLinitSH3:	.long	_C_LABEL(initSH3)
    193  1.1  uch XLmain:		.long	_C_LABEL(main)
    194  1.1  uch XLtoP2:		.long	0x20000000
    195  1.2  uch REG_SYMBOL(CCR)
    196  1.1  uch #ifdef SH4
    197  1.1  uch XL_CCRVAL:	.long	0x0909 /* Operand cache ON */
    198  1.2  uch #endif /* SH4 */
    199  1.1  uch 
    200  1.1  uch load_and_reset:
    201  1.1  uch 	mov.l	XL_start_address, r0
    202  1.1  uch 	mov	r0, r8
    203  1.1  uch 	mov.l	@r4+, r1	/* r1 = osimage size */
    204  1.1  uch 	mov.l	@r4+, r2	/* r2 = check sum */
    205  1.1  uch 	shlr2	r1		/* r1 = osimage size in dword */
    206  1.1  uch 1:
    207  1.1  uch 	mov.l	@r4+, r3
    208  1.1  uch 	mov.l	r3, @r0
    209  1.1  uch 	add	#4, r0
    210  1.1  uch 	dt	r1
    211  1.1  uch 	bf	1b
    212  1.1  uch 
    213  1.1  uch 	jmp	@r8		/* jump to start address */
    214  1.1  uch 	nop
    215  1.1  uch 
    216  1.1  uch 	.align	2
    217  1.1  uch XL_start_address:
    218  1.1  uch 	.long	IOM_RAM_BEGIN + 0x00010000
    219  1.1  uch load_and_reset_end:
    220  1.1  uch 
    221  1.1  uch ENTRY(XLoadAndReset)
    222  1.2  uch 	__INTR_MASK(r0, r1)
    223  1.1  uch 	/* copy trampoline code to RAM area top */
    224  1.1  uch 	mov.l	XL_load_and_reset, r0
    225  1.1  uch 	mov.l	XL_load_and_reset_end, r1
    226  1.1  uch 	mov.l	XL_load_trampoline_addr, r2
    227  1.1  uch 	mov	r2, r8
    228  1.1  uch 	sub	r0, r1		/* r1 = bytes to be copied */
    229  1.1  uch 1:	mov.b	@r0+, r3
    230  1.1  uch 	mov.b	r3, @r2
    231  1.1  uch 	add	#1, r2
    232  1.1  uch 	dt	r1
    233  1.1  uch 	bf	1b
    234  1.1  uch 
    235  1.1  uch 	jmp	@r8		/* jump to trampoline code */
    236  1.1  uch 	nop
    237  1.1  uch 
    238  1.1  uch 	.align	2
    239  1.1  uch XL_load_trampoline_addr:
    240  1.1  uch 	.long	IOM_RAM_BEGIN + 0x00008000
    241  1.1  uch XL_load_and_reset:
    242  1.1  uch 	.long	load_and_reset
    243  1.1  uch XL_load_and_reset_end:
    244  1.1  uch 	.long	load_and_reset_end
    245  1.1  uch 
    246  1.1  uch /*
    247  1.1  uch  * void interrupt_exp(int, int, int, int, stuct trapframe)
    248  1.1  uch  *    __attribute__((__noreturn__)):
    249  1.1  uch  *	on entry, SR.BL = 1, SR_RB = 0, all regsiters are saved,
    250  1.1  uch  *	stack is already setuped.
    251  1.1  uch  */
    252  1.1  uch 	.align	2
    253  1.1  uch recurse:
    254  1.1  uch 	stc	sr, r4
    255  1.1  uch 	ldc	r5, spc
    256  1.1  uch 	ldc	r4, ssr
    257  1.1  uch 	RECURSEENTRY
    258  1.1  uch 	bra	1f
    259  1.1  uch 	 nop
    260  1.1  uch NENTRY(interrupt_exp)
    261  1.1  uch 1:
    262  1.1  uch 	MOV	(INTEVT, r0)
    263  1.1  uch 	mov.l	@r0,	r0
    264  1.1  uch 	mov.l	r0, @(TF_TRAPNO, r15)	/* trapframe->tf_trapno = INTEVT */
    265  1.2  uch 	__INTR_MASK(r0, r1)		/* mask all interrupt */
    266  1.2  uch 	__EXCEPTION_UNBLOCK(r0, r1)	/* enable exception for TLB handling */
    267  1.1  uch 	mov.l	_L.intrhandler, r0
    268  1.1  uch 	jsr	@r0
    269  1.1  uch  	 nop
    270  1.1  uch 	tst	r0,	r0	/* intrhandler() == 0, fast intr return */
    271  1.1  uch 	bt	2f
    272  1.1  uch 
    273  1.1  uch 	mov.l	_L.check_ipending, r0
    274  1.1  uch 	jsr	@r0
    275  1.1  uch 	 nop
    276  1.1  uch 	tst	r0,	r0
    277  1.1  uch 	bf	1b		/* handle pending interrupt. */
    278  1.1  uch 
    279  1.1  uch 	/* Check for ASTs on exit to user mode. */
    280  1.1  uch 	mov.l	_L.ast,	r0
    281  1.1  uch 	jsr	@r0
    282  1.1  uch 	 mov	r15,	r4
    283  1.1  uch 2:
    284  1.1  uch 	EXCEPTION_RETURN
    285  1.1  uch 	/* NOTREACHED */
    286  1.1  uch 	.align	2
    287  1.1  uch REG_SYMBOL(INTEVT)
    288  1.1  uch _L.intrhandler:		.long	_C_LABEL(intrhandler)
    289  1.1  uch _L.ast:			.long	_C_LABEL(ast)
    290  1.1  uch 
    291  1.1  uch NENTRY(Xspllower)
    292  1.1  uch 	sts.l	pr,	@-r15
    293  1.1  uch 
    294  1.1  uch restart:
    295  1.2  uch 	__INTR_MASK(r0, r1)
    296  1.2  uch 	__EXCEPTION_UNBLOCK(r0, r1)
    297  1.1  uch 	mov.l	_L.check_ipending, r0
    298  1.1  uch 	jsr	@r0
    299  1.1  uch 	 nop
    300  1.1  uch 	tst	r0,	r0
    301  1.1  uch 	bt	1f
    302  1.1  uch 
    303  1.1  uch 	mov.l	_L.restart, r5
    304  1.1  uch 	mov.l	_L.recurse, r0
    305  1.1  uch 	jmp	@r0
    306  1.1  uch 	 nop
    307  1.1  uch 
    308  1.1  uch 1:
    309  1.2  uch 	__INTR_UNMASK(r0, r1)
    310  1.1  uch 	lds.l	@r15+,	pr
    311  1.1  uch 	rts
    312  1.1  uch 	 nop
    313  1.1  uch 
    314  1.1  uch 	.align	2
    315  1.1  uch _L.check_ipending:	.long	_C_LABEL(check_ipending)
    316  1.1  uch _L.recurse:		.long	recurse
    317  1.1  uch _L.restart:		.long	restart
    318  1.1  uch 
    319  1.1  uch 	.data
    320  1.1  uch 	.align	2
    321  1.1  uch 	.globl	_C_LABEL(intrcnt), _C_LABEL(eintrcnt)
    322  1.1  uch 	.globl	_C_LABEL(intrnames), _C_LABEL(eintrnames)
    323  1.1  uch _C_LABEL(intrcnt):
    324  1.1  uch _C_LABEL(eintrcnt):
    325  1.1  uch _C_LABEL(intrnames):
    326  1.1  uch _C_LABEL(eintrnames):
    327