1 1.6 andvar /* $NetBSD: ixm1200_start.S,v 1.6 2022/05/24 20:50:18 andvar Exp $ */ 2 1.1 ichiro 3 1.1 ichiro /* 4 1.1 ichiro * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 1.1 ichiro * All rights reserved. 6 1.1 ichiro * 7 1.1 ichiro * This code is derived from software contributed to The NetBSD Foundation 8 1.1 ichiro * by Ichiro FUKUHARA and Naoto Shimazaki. 9 1.1 ichiro * 10 1.1 ichiro * This code is derived from software contributed to The NetBSD Foundation 11 1.1 ichiro * by Jason R. Thorpe. 12 1.1 ichiro * 13 1.1 ichiro * Redistribution and use in source and binary forms, with or without 14 1.1 ichiro * modification, are permitted provided that the following conditions 15 1.1 ichiro * are met: 16 1.1 ichiro * 1. Redistributions of source code must retain the above copyright 17 1.1 ichiro * notice, this list of conditions and the following disclaimer. 18 1.1 ichiro * 2. Redistributions in binary form must reproduce the above copyright 19 1.1 ichiro * notice, this list of conditions and the following disclaimer in the 20 1.1 ichiro * documentation and/or other materials provided with the distribution. 21 1.1 ichiro * 22 1.1 ichiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 23 1.1 ichiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 1.1 ichiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 1.1 ichiro * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 26 1.1 ichiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 1.1 ichiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 1.1 ichiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 1.1 ichiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 1.1 ichiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 1.1 ichiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 1.1 ichiro * POSSIBILITY OF SUCH DAMAGE. 33 1.1 ichiro */ 34 1.1 ichiro 35 1.1 ichiro 36 1.1 ichiro #include <arm/asm.h> 37 1.1 ichiro #include <arm/armreg.h> 38 1.4 matt #include "assym.h" 39 1.1 ichiro 40 1.1 ichiro .section .start,"ax",%progbits 41 1.1 ichiro 42 1.6 andvar RCSID("$NetBSD: ixm1200_start.S,v 1.6 2022/05/24 20:50:18 andvar Exp $") 43 1.4 matt 44 1.1 ichiro .global _C_LABEL(ixm1200_start) 45 1.1 ichiro _C_LABEL(ixm1200_start): 46 1.1 ichiro /* 47 1.1 ichiro * Disable IRQ and FIQ 48 1.1 ichiro */ 49 1.5 joerg mrs r3, cpsr 50 1.1 ichiro orr r1, r3, #(I32_bit | F32_bit) 51 1.1 ichiro msr cpsr_all, r1 52 1.1 ichiro 53 1.1 ichiro /* 54 1.1 ichiro * Setup coprocessor 15. 55 1.1 ichiro * 56 1.1 ichiro * We assume we've been loaded VA == PA, or that the MMU is 57 1.1 ichiro * disabled. We will go ahead and disable the MMU here 58 1.1 ichiro * so that we don't have to worry about flushing caches, etc. 59 1.1 ichiro */ 60 1.1 ichiro 61 1.1 ichiro /* CONTROL_CP15 */ 62 1.1 ichiro mrc p15, 0, r0, c1, c0 ,0 /* read ctrl */ 63 1.1 ichiro bic r0, r0, #CPU_CONTROL_MMU_ENABLE 64 1.1 ichiro bic r0, r0, #CPU_CONTROL_AFLT_ENABLE 65 1.1 ichiro orr r0, r0, #CPU_CONTROL_DC_ENABLE 66 1.1 ichiro orr r0, r0, #CPU_CONTROL_WBUF_ENABLE 67 1.1 ichiro bic r0, r0, #CPU_CONTROL_BEND_ENABLE 68 1.1 ichiro orr r0, r0, #CPU_CONTROL_SYST_ENABLE 69 1.1 ichiro bic r0, r0, #CPU_CONTROL_ROM_ENABLE 70 1.1 ichiro orr r0, r0, #CPU_CONTROL_IC_ENABLE 71 1.1 ichiro bic r0, r0, #CPU_CONTROL_VECRELOC 72 1.1 ichiro mcr p15, 0, r0, c1, c0 ,0 /* write ctrl */ 73 1.1 ichiro 74 1.1 ichiro nop 75 1.1 ichiro nop 76 1.1 ichiro nop 77 1.1 ichiro 78 1.1 ichiro /* TRANSLATION_TABLE_BASE */ 79 1.1 ichiro mov r0, #0 80 1.1 ichiro mcr p15, 0, r0, c2, c0 ,0 /* write trans table base */ 81 1.1 ichiro 82 1.1 ichiro /* DOMAIN_ACCESS_CONTROL */ 83 1.1 ichiro mov r0, #0x00000001 /* use domain 0 as client */ 84 1.1 ichiro mcr p15, 0, r0, c3, c0 ,0 /* write domain */ 85 1.1 ichiro 86 1.1 ichiro /* CACHE_CONTROL_OPERATIONS */ 87 1.1 ichiro mrc p15, 0, r0, c7, c7 ,0 /* flush D and I cache */ 88 1.1 ichiro mrc p15, 0, r0, c7, c10 ,4 /* drain write buffer */ 89 1.1 ichiro 90 1.1 ichiro /* TLB_OPERATIONS */ 91 1.1 ichiro mcr p15, 0, r0, c8, c7 ,0 /* flush D and I TLB */ 92 1.1 ichiro 93 1.1 ichiro /* READ_BUFFER_OPERATIONS */ 94 1.1 ichiro mcr p15, 0, r0, c9, c0 ,0 /* flush all entries */ 95 1.1 ichiro mcr p15, 0, r0, c9, c0 ,4 /* disable user mode MCR access */ 96 1.1 ichiro 97 1.1 ichiro /* PROCESS_ID_VIRTUAL_ADDR_MAPPING */ 98 1.1 ichiro mov r0, #0 99 1.1 ichiro mcr p15, 0, r0, c13, c0 ,0 /* process ID 0 100 1.1 ichiro 101 1.1 ichiro /* BREAKPOINT_DEBUG_SUPPORT */ 102 1.1 ichiro mov r0, #0 103 1.1 ichiro mcr p15, 0, r0, c15, c0 ,0 /* DBAR = 0 */ 104 1.1 ichiro mcr p15, 0, r0, c15, c1 ,0 /* DBVR = 0 */ 105 1.1 ichiro mcr p15, 0, r0, c15, c2 ,0 /* DBMR = 0 */ 106 1.1 ichiro mcr p15, 0, r0, c15, c3 ,0 /* DBCR = 0 (never watch) */ 107 1.1 ichiro mcr p15, 0, r0, c15, c8 ,0 /* IBCR = 0 (never watch) */ 108 1.1 ichiro 109 1.1 ichiro /* 110 1.1 ichiro * We want to construct a memory map that maps us 111 1.1 ichiro * VA == PA (SDRAM at 0xc0000000). We create these mappings 112 1.1 ichiro * uncached and unbuffered to be safe. 113 1.1 ichiro * 114 1.1 ichiro * We also want to map the various devices we want to 115 1.1 ichiro * talk to VA == PA during bootstrap. 116 1.1 ichiro * 117 1.1 ichiro * We also want to map the v0xf0000000 == p0x90000000 118 1.6 andvar * to output early bootstrup messages to the console. 119 1.1 ichiro * 120 1.1 ichiro * We just use section mappings for all of this to make it easy. 121 1.1 ichiro * 122 1.1 ichiro * We will put the L1 table to do all this at c01fc000 123 1.1 ichiro * where is our KERNEL_TEXT_BASE - sizeof(L1 table). 124 1.1 ichiro */ 125 1.1 ichiro 126 1.1 ichiro /* 127 1.1 ichiro * Step 1: Map the entire address space VA == PA. 128 1.1 ichiro */ 129 1.1 ichiro ldr r0, Ltable 130 1.1 ichiro mov r1, #(L1_TABLE_SIZE / 4) /* 4096 entry */ 131 1.1 ichiro mov r2, #(L1_S_SIZE) /* 1MB / section */ 132 1.4 matt mov r3, #(L1_S_AP_KRW) /* kernel read/write */ 133 1.1 ichiro orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */ 134 1.1 ichiro 1: 135 1.1 ichiro str r3, [r0], #4 136 1.1 ichiro add r3, r3, r2 137 1.1 ichiro subs r1, r1, #1 138 1.1 ichiro bgt 1b 139 1.1 ichiro 140 1.1 ichiro /* 141 1.1 ichiro * Step 2: Map VA 0xf0000000->0xf0100000 to PA 0x90000000->0x90100000. 142 1.1 ichiro */ 143 1.1 ichiro ldr r0, Ltable 144 1.1 ichiro add r0, r0, #(0xf00 * 4) /* offset to 0xf0000000 */ 145 1.1 ichiro mov r3, #0x90000000 146 1.1 ichiro add r3, r3, #0x00100000 /* set 0x90100000 to r3 */ 147 1.4 matt orr r3, r3, #(L1_S_AP_KRW) /* kernel read/write */ 148 1.1 ichiro orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */ 149 1.1 ichiro str r3, [r0] 150 1.1 ichiro 151 1.1 ichiro /* OK! Page table is set up. Give it to the CPU. */ 152 1.1 ichiro ldr r0, Ltable 153 1.1 ichiro mcr p15, 0, r0, c2, c0 ,0 /* write trans table base */ 154 1.1 ichiro mcr p15, 0, r0, c8, c7 ,0 /* flush D and I TLB */ 155 1.1 ichiro 156 1.1 ichiro /* Get ready to jump to the "real" kernel entry point... */ 157 1.1 ichiro ldr r0, Lstart 158 1.1 ichiro 159 1.1 ichiro /* OK, let's enable the MMU. */ 160 1.1 ichiro mrc p15, 0, r1, c1, c0 ,0 /* read ctrl */ 161 1.1 ichiro orr r1, r1, #CPU_CONTROL_MMU_ENABLE 162 1.1 ichiro mcr p15, 0, r1, c1, c0 ,0 /* write ctrl */ 163 1.1 ichiro 164 1.1 ichiro nop 165 1.1 ichiro nop 166 1.1 ichiro nop 167 1.1 ichiro 168 1.1 ichiro /* CPWAIT sequence to make sure the MMU is on... */ 169 1.1 ichiro mrc p15, 0, r2, c2, c0, 0 /* arbitrary read of CP15 */ 170 1.1 ichiro mov r2, r2 /* force it to complete */ 171 1.1 ichiro mov pc, r0 /* leap to kernel entry point! */ 172 1.1 ichiro 173 1.1 ichiro Lstart: 174 1.1 ichiro .word start 175 1.1 ichiro 176 1.1 ichiro Ltable: 177 1.1 ichiro .word 0xc0200000 - 0x4000 /* our KERNEL_TEXT_BASE - 16KB */ 178 1.2 ichiro 179 1.2 ichiro /* end of ixm1200_start.S */ 180