1 1.7 matt /* $NetBSD: tsarm_start.S,v 1.7 2011/01/31 06:28:05 matt Exp $ */ 2 1.1 joff 3 1.1 joff /* 4 1.1 joff * Copyright (c) 2003 5 1.1 joff * Ichiro FUKUHARA <ichiro (at) ichiro.org>. 6 1.1 joff * All rights reserved. 7 1.1 joff * 8 1.1 joff * Redistribution and use in source and binary forms, with or without 9 1.1 joff * modification, are permitted provided that the following conditions 10 1.1 joff * are met: 11 1.1 joff * 1. Redistributions of source code must retain the above copyright 12 1.1 joff * notice, this list of conditions and the following disclaimer. 13 1.1 joff * 2. Redistributions in binary form must reproduce the above copyright 14 1.1 joff * notice, this list of conditions and the following disclaimer in the 15 1.1 joff * documentation and/or other materials provided with the distribution. 16 1.1 joff * 17 1.1 joff * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR 18 1.1 joff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 1.1 joff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 1.1 joff * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR 21 1.1 joff * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 1.1 joff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 1.1 joff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 1.1 joff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 1.1 joff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 1.1 joff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 1.1 joff * SUCH DAMAGE. 28 1.1 joff */ 29 1.7 matt 30 1.1 joff #include <machine/asm.h> 31 1.1 joff #include <arm/armreg.h> 32 1.7 matt #include "assym.h" 33 1.1 joff 34 1.1 joff #include <arm/ep93xx/ep93xxreg.h> 35 1.1 joff 36 1.7 matt RCSID("$NetBSD: tsarm_start.S,v 1.7 2011/01/31 06:28:05 matt Exp $") 37 1.7 matt 38 1.1 joff .section .start,"ax",%progbits 39 1.1 joff 40 1.1 joff .global _C_LABEL(ts7xxx_start) 41 1.1 joff _C_LABEL(ts7xxx_start): 42 1.1 joff 43 1.1 joff /* 44 1.1 joff * We will go ahead and disable the MMU here so that we don't 45 1.1 joff * have to worry about flushing caches, etc. 46 1.1 joff * 47 1.1 joff * Note that we may not currently be running VA==PA, which means 48 1.1 joff * we'll need to leap to the next insn after disabing the MMU. 49 1.1 joff */ 50 1.1 joff adr r8, Lunmapped 51 1.1 joff bic r8, r8, #0xff000000 /* clear upper 8 bits */ 52 1.1 joff 53 1.1 joff /* 54 1.1 joff * Setup coprocessor 15. 55 1.1 joff */ 56 1.1 joff mrc p15, 0, r2, c1, c0, 0 57 1.1 joff bic r2, r2, #CPU_CONTROL_MMU_ENABLE 58 1.1 joff mcr p15, 0, r2, c1, c0, 0 59 1.1 joff 60 1.1 joff nop 61 1.1 joff nop 62 1.1 joff nop 63 1.1 joff 64 1.1 joff mov pc, r8 /* Heave-ho! */ 65 1.1 joff 66 1.1 joff Lunmapped: 67 1.1 joff /* 68 1.1 joff * We want to construct a memory map that maps us 69 1.1 joff * VA==PA (SDRAM at 0x00000000). We create these 70 1.1 joff * mappings uncached and unbuffered to be safe. 71 1.1 joff */ 72 1.1 joff /* 73 1.1 joff * Step 1: Map the entire address space VA==PA. 74 1.1 joff */ 75 1.1 joff adr r4, Ltable 76 1.1 joff ldr r0, [r4] /* r0 = &l1table */ 77 1.1 joff 78 1.1 joff mov r1, #(L1_TABLE_SIZE / 4) /* 4096 entry */ 79 1.1 joff mov r2, #(L1_S_SIZE) /* 1MB / section */ 80 1.7 matt mov r3, #(L1_S_AP_KRW) /* kernel read/write */ 81 1.1 joff orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */ 82 1.1 joff 1: 83 1.1 joff str r3, [r0], #0x04 84 1.1 joff add r3, r3, r2 85 1.1 joff subs r1, r1, #1 86 1.1 joff bgt 1b 87 1.1 joff 88 1.1 joff 89 1.1 joff /* 90 1.1 joff * Step 2: Map VA 0xc0000000->0xc07fffff to PA 0x00000000->0x007fffff. 91 1.1 joff */ 92 1.1 joff ldr r0, [r4] 93 1.1 joff add r0, r0, #(0xc00 * 4) /* offset to 0xc00xxxxx */ 94 1.1 joff 95 1.5 kenh mov r1, #0x8 /* 8MB */ 96 1.7 matt mov r3, #(L1_S_AP_KRW) 97 1.1 joff orr r3, r3, #(L1_TYPE_S) 98 1.1 joff 1: 99 1.1 joff str r3, [r0], #0x04 100 1.1 joff add r3, r3, r2 101 1.1 joff subs r1, r1, #1 102 1.1 joff bgt 1b 103 1.1 joff 104 1.1 joff /* 105 1.1 joff * Step 3: Map VA 0xf0000000->0xf0100000 to PA 0x80000000->0x80100000. 106 1.1 joff */ 107 1.1 joff ldr r0, [r4] 108 1.1 joff 109 1.1 joff add r0, r0, #(0xf00 * 4) /* offset to 0xf0000000 */ 110 1.1 joff mov r3, #0x80000000 111 1.7 matt orr r3, r3, #(L1_S_AP_KRW) 112 1.1 joff orr r3, r3, #(L1_TYPE_S) 113 1.1 joff str r3, [r0], #4 114 1.1 joff 115 1.1 joff /* 116 1.1 joff * Step 4: Map VA 0xf0100000->0xf0300000 to PA 0x80800000->0x80a00000. 117 1.1 joff */ 118 1.1 joff mov r3, #0x80000000 119 1.1 joff add r3, r3, #0x00800000 120 1.7 matt orr r3, r3, #(L1_S_AP_KRW) 121 1.1 joff orr r3, r3, #(L1_TYPE_S) 122 1.1 joff str r3, [r0], #0x4 123 1.1 joff add r3, r3, r2 124 1.1 joff str r3, [r0], #0x4 125 1.1 joff 126 1.1 joff /* 127 1.1 joff * Step 5: Map VA 0xf0300000->0xf4300000 to PA 0x10000000->0x14000000. 128 1.1 joff */ 129 1.1 joff mov r1, #0x40 /* 64MB */ 130 1.7 matt mov r3, #(L1_S_AP_KRW) 131 1.1 joff orr r3, r3, #(L1_TYPE_S) 132 1.1 joff orr r3, r3, #0x10000000 133 1.1 joff 1: 134 1.1 joff str r3, [r0], #0x04 135 1.1 joff add r3, r3, r2 136 1.1 joff subs r1, r1, #1 137 1.1 joff bgt 1b 138 1.1 joff 139 1.1 joff /* 140 1.1 joff * Step 6: Map VA 0xf4300000->0xf8300000 to PA 0x20000000->0x24000000. 141 1.1 joff */ 142 1.1 joff mov r1, #0x40 /* 64MB */ 143 1.7 matt mov r3, #(L1_S_AP_KRW) 144 1.1 joff orr r3, r3, #(L1_TYPE_S) 145 1.1 joff orr r3, r3, #0x20000000 146 1.1 joff 1: 147 1.1 joff str r3, [r0], #0x04 148 1.1 joff add r3, r3, r2 149 1.1 joff subs r1, r1, #1 150 1.1 joff bgt 1b 151 1.1 joff 152 1.1 joff 153 1.1 joff /* OK! Page table is set up. Give it to the CPU. */ 154 1.1 joff adr r0, Ltable 155 1.1 joff ldr r0, [r0] 156 1.1 joff mcr p15, 0, r0, c2, c0, 0 157 1.1 joff 158 1.1 joff /* Flush the old TLBs, just in case. */ 159 1.1 joff mcr p15, 0, r0, c8, c7, 0 160 1.1 joff 161 1.1 joff /* Set the Domain Access register. Very important! */ 162 1.1 joff mov r0, #1 163 1.1 joff mcr p15, 0, r0, c3, c0, 0 164 1.1 joff 165 1.1 joff /* Get ready to jump to the "real" kernel entry point... */ 166 1.1 joff ldr r1, Lstart 167 1.1 joff mov r1, r1 /* Make sure the load completes! */ 168 1.1 joff 169 1.1 joff /* OK, let's enable the MMU. */ 170 1.1 joff mrc p15, 0, r2, c1, c0, 0 171 1.1 joff orr r2, r2, #CPU_CONTROL_MMU_ENABLE 172 1.1 joff mcr p15, 0, r2, c1, c0, 0 173 1.1 joff 174 1.1 joff nop 175 1.1 joff nop 176 1.1 joff nop 177 1.1 joff 178 1.1 joff /* CPWAIT sequence to make sure the MMU is on... */ 179 1.1 joff mrc p15, 0, r2, c2, c0, 0 /* arbitrary read of CP15 */ 180 1.1 joff mov r2, r2 /* force it to complete */ 181 1.1 joff mov pc, r1 /* leap to kernel entry point! */ 182 1.1 joff 183 1.1 joff Ltable: 184 1.1 joff .word 0x4000 185 1.1 joff 186 1.1 joff Lstart: 187 1.1 joff .word start 188