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