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