1/* $NetBSD: locore.S,v 1.37 2014/08/27 03:35:32 matt Exp $ */ 2 3/* 4 * Copyright (C) 1994-1997 Mark Brinicombe 5 * Copyright (C) 1994 Brini 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Brini. 19 * 4. The name of Brini may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL BRINI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34#include "assym.h" 35#include <sys/syscall.h> 36#include <sys/errno.h> 37#include <arm/asm.h> 38#include <arm/locore.h> 39 40/* What size should this really be ? It is only used by init_arm() */ 41#define INIT_ARM_STACK_SIZE 2048 42 43 RCSID("$NetBSD: locore.S,v 1.37 2014/08/27 03:35:32 matt Exp $") 44 45/* 46 * This is for kvm_mkdb, and should be the address of the beginning 47 * of the kernel text segment (not necessarily the same as kernbase). 48 */ 49 50 .text 51 .align 0 52 53ENTRY_NP(kernel_text) 54 55ASENTRY_NP(start) 56 mrs r1, cpsr /* fetch CPSR value */ 57 msr spsr_sx, r1 /* set SPSR[23:8] to known value */ 58 59 adr r1, .Lstart 60 ldmia r1, {r1, r2, r8, sp} /* Set initial stack and */ 61 62#if defined(TPIDRPRW_IS_CURCPU) || defined(TPIDRPRW_IS_CURLWP) 63 mcr p15, 0, r8, c13, c0, 4 64#endif 65#if defined(TPIDRPRW_IS_CURLWP) 66 ldr r8, [r8, #L_CPU] /* r8 needs curcpu in it */ 67#endif 68 69 mov r4, #0 70#ifdef _ARM_ARCH_DWORD_OK 71 mov r5, #0 72#endif 73.L1: 74#ifdef _ARM_ARCH_DWORD_OK 75 strd r4, r5, [r1], #0x0008 /* Zero the bss */ 76#else 77 str r4, [r1], #0x0004 /* Zero the bss */ 78#endif 79 cmp r1, r2 80 blt .L1 81 82 mrc p15, 0, r3, c0, c0, 0 /* get our cpuid and save it early */ 83 str r3, [r8, #CI_ARM_CPUID] 84 85 mov fp, #0x00000000 /* trace back starts here */ 86 bl _C_LABEL(initarm) /* Off we go */ 87 88 /* init arm will return the new stack pointer. */ 89 mov sp, r0 90 91 mov fp, #0x00000000 /* trace back starts here */ 92 mov ip, sp 93 push {fp, ip, lr, pc} 94 sub fp, ip, #4 95 96 bl _C_LABEL(main) /* call main()! */ 97 98 adr r0, .Lmainreturned 99 b _C_LABEL(panic) 100 /* NOTREACHED */ 101 102.Lstart: 103 .word _edata 104 .word _end 105#if defined(TPIDRPRW_IS_CURLWP) 106 .word _C_LABEL(lwp0) 107#else 108 .word _C_LABEL(cpu_info_store) 109#endif 110 .word svcstk + INIT_ARM_STACK_SIZE 111 112.Lmainreturned: 113 .asciz "main() returned" 114 .align 0 115ASEND(start) 116 117 .bss 118#ifdef __ARM_EABI__ 119 .align 3 120#endif 121svcstk: 122 .space INIT_ARM_STACK_SIZE 123 124 .text 125 .align 0 126 127#ifndef OFW 128 /* OFW based systems will used OF_boot() */ 129 130.Lcpufuncs: 131 .word _C_LABEL(cpufuncs) 132 133ENTRY_NP(cpu_reset) 134#ifdef _ARM_ARCH_6 135 cpsid if, #PSR_SVC32_MODE 136#else 137 mrs r2, cpsr 138 bic r2, r2, #(PSR_MODE) 139 orr r2, r2, #(PSR_SVC32_MODE) 140 orr r2, r2, #(IF32_bits) 141 msr cpsr_c, r2 142#endif 143 144 ldr r0, .Lcpufuncs 145 mov lr, pc 146 ldr pc, [r0, #CF_IDCACHE_WBINV_ALL] 147 148 /* 149 * Load the virutal address of the MD reset function first. 150 */ 151 ldr r4, .Lcpu_reset_address 152 ldr r4, [r4] 153 cmp r4, #0 154 155 /* 156 * If virtual address is NULL, we must be using the physical address 157 */ 158 ldreq r4, .Lcpu_reset_address_paddr 159 ldreq r4, [r4] 160 161 /* 162 * MMU & IDC off, 32 bit program & data space 163 * Hurl ourselves into the ROM 164 */ 165 mrc p15, 0, r0, c1, c0, 0 166 bic r0, r0, #(CPU_CONTROL_MMU_ENABLE | CPU_CONTROL_DC_ENABLE) 167 bic r0, r0, #(CPU_CONTROL_IC_ENABLE) 168 orr r0, r0, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE) 169 mcr p15, 0, r0, c1, c0, 0 170 mcreq p15, 0, r2, c8, c7, 0 /* nail I+D TLB on ARMv4 and greater */ 171 mov pc, r4 172 173 /* 174 * cpu_reset_address contains the address to branch to, to complete 175 * the CPU reset after turning the MMU off 176 * This variable is provided by the hardware specific code 177 */ 178.Lcpu_reset_address: 179 .word _C_LABEL(cpu_reset_address) 180.Lcpu_reset_address_paddr: 181 .word _C_LABEL(cpu_reset_address_paddr) 182END(cpu_reset) 183#endif /* OFW */ 184 185/* 186 * setjump + longjmp 187 */ 188ENTRY(setjmp) 189 stmia r0, {r4-r14} 190 mov r0, #0x00000000 191 RET 192END(setjmp) 193 194ENTRY(longjmp) 195 ldmia r0, {r4-r14} 196 mov r0, #0x00000001 197 RET 198END(longjmp) 199 200 .data 201 .global _C_LABEL(esym) 202_C_LABEL(esym): .word _C_LABEL(end) 203 204ENTRY_NP(abort) 205 b _C_LABEL(abort) 206END(abort) 207 208/* 209 * Part of doing a system dump, we need to save a switchframe onto the 210 * stack, then save the rest of the registers into the dumppcb. 211 */ 212ENTRY(dumpsys) 213 /* push registers onto stack */ 214 mov ip, sp 215 push {r4-r7, ip, lr} 216 217 /* fill in dumppcb */ 218 ldr r0, .Ldumppcb 219 220#ifndef __XSCALE__ 221 add r2, r0, #(PCB_R8) 222 stmia r2, {r8-r13} 223#else 224 strd r8, r9, [r0, #(PCB_R8)] 225 strd r10, r11, [r0, #(PCB_R10)] 226 strd r12, r13, [r0, #(PCB_R12)] 227#endif 228 229 bl _C_LABEL(dodumpsys) 230 231 /* unwind the stack */ 232 pop {r4-r7, ip, pc} 233 234.Ldumppcb: 235 .word _C_LABEL(dumppcb) 236END(dumpsys) 237 238/* End of locore.S */ 239