Home | History | Annotate | Line # | Download | only in lubbock
      1  1.3   matt /*	$NetBSD: lubbock_start.S,v 1.3 2011/01/31 06:28:04 matt Exp $ */
      2  1.1    bsh 
      3  1.1    bsh /*
      4  1.1    bsh  * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
      5  1.1    bsh  * Written by Hiroyuki Bessho for Genetec Corporation.
      6  1.1    bsh  *
      7  1.1    bsh  * Redistribution and use in source and binary forms, with or without
      8  1.1    bsh  * modification, are permitted provided that the following conditions
      9  1.1    bsh  * are met:
     10  1.1    bsh  * 1. Redistributions of source code must retain the above copyright
     11  1.1    bsh  *    notice, this list of conditions and the following disclaimer.
     12  1.1    bsh  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1    bsh  *    notice, this list of conditions and the following disclaimer in the
     14  1.1    bsh  *    documentation and/or other materials provided with the distribution.
     15  1.1    bsh  * 3. The name of Genetec Corporation may not be used to endorse or
     16  1.1    bsh  *    promote products derived from this software without specific prior
     17  1.1    bsh  *    written permission.
     18  1.1    bsh  *
     19  1.1    bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     20  1.1    bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1    bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1    bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     23  1.1    bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1    bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1    bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1    bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1    bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1    bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1    bsh  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1    bsh  */
     31  1.1    bsh 
     32  1.1    bsh #include <machine/asm.h>
     33  1.1    bsh #include <arm/armreg.h>
     34  1.3   matt #include "assym.h"
     35  1.3   matt 
     36  1.3   matt RCSID("$NetBSD: lubbock_start.S,v 1.3 2011/01/31 06:28:04 matt Exp $")
     37  1.1    bsh 
     38  1.1    bsh #ifndef SDRAM_START
     39  1.1    bsh #define SDRAM_START	0xa0000000
     40  1.1    bsh #endif
     41  1.1    bsh 
     42  1.1    bsh /*
     43  1.1    bsh  * CPWAIT -- Canonical method to wait for CP15 update.
     44  1.1    bsh  * NOTE: Clobbers the specified temp reg.
     45  1.1    bsh  * copied from arm/arm/cpufunc_asm_xscale.S
     46  1.1    bsh  * XXX: better be in a common header file.
     47  1.1    bsh  */
     48  1.1    bsh #define	CPWAIT_BRANCH							 \
     49  1.1    bsh 	sub	pc, pc, #4
     50  1.1    bsh 
     51  1.1    bsh #define	CPWAIT(tmp)							 \
     52  1.1    bsh 	mrc	p15, 0, tmp, c2, c0, 0	/* arbitrary read of CP15 */	;\
     53  1.1    bsh 	mov	tmp, tmp		/* wait for it to complete */	;\
     54  1.1    bsh 	CPWAIT_BRANCH			/* branch to next insn */
     55  1.1    bsh 
     56  1.1    bsh /*
     57  1.1    bsh  * Kernel start routine for DBPXA250 (Lubbock)
     58  1.1    bsh  * this code is excuted at the very first after the kernel is loaded
     59  1.1    bsh  * by RedBoot.
     60  1.1    bsh  */
     61  1.1    bsh 	.text
     62  1.1    bsh 
     63  1.1    bsh 	.global	_C_LABEL(lubbock_start)
     64  1.1    bsh _C_LABEL(lubbock_start):
     65  1.1    bsh 	/* Are we running on ROM ? */
     66  1.1    bsh 	cmp	pc, #0x06000000
     67  1.1    bsh 	bhi	lubbock_start_ram
     68  1.1    bsh 
     69  1.1    bsh 	/* move me to RAM
     70  1.1    bsh 	 * XXX: we can use memcpy if it is PIC
     71  1.1    bsh 	 */
     72  1.1    bsh 	ldr r1, Lcopy_size
     73  1.1    bsh 	adr r0, _C_LABEL(lubbock_start)
     74  1.1    bsh 	add r1, r1, #3
     75  1.1    bsh 	mov r1, r1, LSR #2
     76  1.1    bsh 	mov r2, #SDRAM_START
     77  1.1    bsh 	add r2, r2, #0x00200000
     78  1.1    bsh 	mov r4, r2
     79  1.1    bsh 
     80  1.1    bsh 5:	ldr r3,[r0],#4
     81  1.1    bsh 	str r3,[r2],#4
     82  1.1    bsh 	subs r1,r1,#1
     83  1.1    bsh 	bhi 5b
     84  1.1    bsh 
     85  1.1    bsh 	/* Jump to RAM */
     86  1.1    bsh 	ldr r0, Lstart_off
     87  1.1    bsh 	add pc, r4, r0
     88  1.1    bsh 
     89  1.1    bsh Lcopy_size:	.word _edata-_C_LABEL(lubbock_start)
     90  1.1    bsh Lstart_off:	.word lubbock_start_ram-_C_LABEL(lubbock_start)
     91  1.1    bsh 
     92  1.1    bsh lubbock_start_ram:
     93  1.1    bsh 	/*
     94  1.1    bsh 	 *  Kernel is loaded in SDRAM (0xa0200000..), and is expected to run
     95  1.1    bsh 	 *  in VA 0xc0200000..
     96  1.1    bsh 	 */
     97  1.1    bsh 
     98  1.1    bsh 	mrc	p15, 0, r0, c2, c0, 0		/* get ttb prepared by redboot */
     99  1.1    bsh 	adr	r4, mmu_init_table2
    100  1.1    bsh 
    101  1.1    bsh #ifdef BUILD_STARTUP_PAGETABLE
    102  1.1    bsh 	mrc	p15, 0, r2, c1, c0, 0
    103  1.1    bsh 	tst	r2, #CPU_CONTROL_MMU_ENABLE		/* we already have a page table? */
    104  1.1    bsh 	bne	3f
    105  1.1    bsh 
    106  1.1    bsh 	/* build page table from scratch */
    107  1.1    bsh 	ldr	r0, Lstartup_pagetable
    108  1.1    bsh 	adr	r4, mmu_init_table
    109  1.1    bsh #endif
    110  1.1    bsh 	b	3f
    111  1.1    bsh 
    112  1.1    bsh 2:
    113  1.1    bsh 	str	r3, [r0, r2]
    114  1.1    bsh 	add	r2, r2, #4
    115  1.1    bsh 	add	r3, r3, #(L1_S_SIZE)
    116  1.1    bsh 	adds	r1, r1, #-1
    117  1.1    bsh 	bhi	2b
    118  1.1    bsh 3:
    119  1.1    bsh 	ldmia	r4!, {r1,r2,r3}   /* # of sections, PA|attr, VA */
    120  1.1    bsh 	cmp	r1, #0
    121  1.1    bsh 	bne	2b
    122  1.1    bsh 
    123  1.1    bsh 	mcr	p15, 0, r0, c2, c0, 0	/* Set TTB */
    124  1.1    bsh 	mcr	p15, 0, r0, c8, c7, 0	/* Flush TLB */
    125  1.1    bsh 
    126  1.1    bsh 	/* Set the Domain Access register.  Very important! */
    127  1.1    bsh         mov     r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
    128  1.1    bsh 	mcr	p15, 0, r0, c3, c0, 0
    129  1.1    bsh 
    130  1.1    bsh 	/* Enable MMU */
    131  1.1    bsh 	mrc	p15, 0, r0, c1, c0, 0
    132  1.1    bsh 	orr	r0, r0, #CPU_CONTROL_MMU_ENABLE
    133  1.1    bsh 	mcr	p15, 0, r0, c1, c0, 0
    134  1.1    bsh 	CPWAIT(r0)
    135  1.1    bsh 
    136  1.1    bsh 	/* Jump to kernel code in TRUE VA */
    137  1.1    bsh 	adr	r0, Lstart
    138  1.1    bsh 	ldr	pc, [r0]
    139  1.1    bsh 
    140  1.1    bsh Lstart:
    141  1.1    bsh 	.word	start
    142  1.1    bsh 
    143  1.1    bsh #define MMU_INIT(va,pa,n_sec,attr) \
    144  1.1    bsh 	.word	n_sec					    ; \
    145  1.1    bsh 	.word	4*((va)>>L1_S_SHIFT)			    ; \
    146  1.1    bsh 	.word	(pa)|(attr)				    ;
    147  1.1    bsh 
    148  1.1    bsh #ifdef BUILD_STARTUP_PAGETABLE
    149  1.1    bsh #ifndef STARTUP_PAGETABLE_ADDR
    150  1.1    bsh #define STARTUP_PAGETABLE_ADDR 0xa0004000
    151  1.1    bsh #endif
    152  1.2  rafal Lstartup_pagetable:
    153  1.2  rafal 	.word	STARTUP_PAGETABLE_ADDR
    154  1.1    bsh mmu_init_table:
    155  1.1    bsh 	/* fill all table VA==PA */
    156  1.3   matt 	MMU_INIT(0x00000000, 0x00000000, 1<<(32-L1_S_SHIFT), L1_TYPE_S|L1_S_AP_KRW)
    157  1.1    bsh 	/* map SDRAM VA==PA, WT cacheable */
    158  1.3   matt 	MMU_INIT(SDRAM_START, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
    159  1.1    bsh #endif
    160  1.1    bsh mmu_init_table2:
    161  1.1    bsh 	/* map VA 0xc0000000..0xc3ffffff to PA 0xa0000000..0xa3ffffff */
    162  1.3   matt 	MMU_INIT(0xc0000000, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
    163  1.1    bsh 
    164  1.1    bsh 	.word 0	/* end of table */
    165