1/* $NetBSD: imx31lk_start.S,v 1.4 2011/01/31 06:28:03 matt Exp $ */ 2/*- 3 * Copyright (c) 2011 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Matt Thomas of 3am Software Foundry. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include <machine/asm.h> 32#include <arm/armreg.h> 33#include "assym.h" 34 35RCSID("$NetBSD: imx31lk_start.S,v 1.4 2011/01/31 06:28:03 matt Exp $") 36 37/* 38 */ 39 40#define CPWAIT_BRANCH \ 41 sub pc, pc, #4 42 43#define CPWAIT(tmp) \ 44 mrc p15, 0, tmp, c2, c0, 0 /* arbitrary read of CP15 */ ;\ 45 mov tmp, tmp /* wait for it to complete */ ;\ 46 CPWAIT_BRANCH /* branch to next insn */ 47 48 49#ifndef SDRAM_START 50#define SDRAM_START 0x80000000 51#endif 52 53#define IMX31_DCACHE_SIZE 0x4000 /* 16KB L1 */ 54 55/* 56 * L1 == "Level One" == "first-level" 57 * L2 == "Level Two" == "second-level" 58 */ 59 60 .text 61 62 .global _C_LABEL(imx31lk_start) 63_C_LABEL(imx31lk_start): 64 /* Figure out where we want to jump to when the time comes */ 65 adr r8, .Lstart 66 ldr r8, [r8] 67 68 /* 69 * set up virtual address space mapping 70 * for initial bootstrap. 71 */ 72 mov r2, #(L1_S_SIZE) /* 1MB chunks */ 73 74 /* 75 * Firmware already mapped SDRAM VA == PA. at 0x800.. 76 * now map SDRAM also at VA 0x800... 77 */ 78 mrc p15, 0, r0, c2, c0, 0 /* L1 table addr into r0 */ 79 add r0, r0, #(0x800 * 4) /* offset to 0x80000000 */ 80 81 mov r3, #SDRAM_START /* map to 0x800.. */ 82 orr r3, r3, #(L1_S_AP_KRW) /* the usual perms & stuff */ 83 orr r3, r3, #(L1_TYPE_S) 84 orr r3, r3, #(L1_S_DOM_KERNEL) 85 86 mov r1, #0x80 /* 128 1MB entries */ 871: 88 /* and looplooploop */ 89 str r3, [r0], #4 90 add r3, r3, r2 91 subs r1, r1, #1 92 bgt 1b 93 94 /* 95 * Map an L1 section for each device to make this easy. 96 */ 97 /* UART1 */ 98 mrc p15, 0, r0, c2, c0, 0 /* L1 table addr into r0 */ 99 add r0, r0, #(0xfd0 * 4) /* offset to 0xfd000000 */ 100 101 mov r3, #0x43000000 102 orr r3, r3, #0x00f00000 103 orr r3, r3, #(L1_S_AP_KRW) 104 orr r3, r3, #(L1_TYPE_S) 105 orr r3, r3, #(L1_S_DOM_KERNEL) 106 str r3, [r0], #4 /* note autoinc */ 107 108 /* etc, TBD... */ 109 110 /* 111 * Make domain control go full art. 112 */ 113 mov r0, #0xffffffff 114 mcr p15, 0, r0, c3, c0, 0 115 116 /* 117 * Now let's clean the cache again to make sure everything 118 * is in place. 119 * 120 * XXX: should this take into account the XScale cache clean bug? 121 */ 122 mov r3, #(IMX31_DCACHE_SIZE) 123 subs r3, r3, #32 1241: 125 mcr p15, 0, r3, c7, c10, 2 126 subs r3, r3, #32 127 bne 1b 128 CPWAIT(r3) 129 130 /* Drain write buffer */ 131 mcr p15, 0, r6, c7, c10, 4 132 133 /* Invalidate TLBs just to be sure */ 134 mcr p15, 0, r0, c8, c7, 0 135 136 /* 137 * You are standing at the gate to NetBSD. --More-- 138 * Unspeakable cruelty and harm lurk down there. --More-- 139 * Are you sure you want to enter? 140 */ 141 adr r8, .Lstart 142 ldr r8, [r8] 143 mov pc, r8 /* So be it */ 144 145/* symbol to use for address calculation in the right VA */ 146.Lstart: 147 .word start 148 149 150/* 151 * Calculate size of kernel to copy. Don't bother to copy bss, 152 * although I guess the CPU could use the warmup exercise ... 153 */ 154.Lcopy_size: 155 .word _edata - _C_LABEL(imx31lk_start) 156 157