locore.S revision 1.37
11.37Smatt/* $NetBSD: locore.S,v 1.37 2014/08/27 03:35:32 matt Exp $ */ 21.1Schris 31.1Schris/* 41.1Schris * Copyright (C) 1994-1997 Mark Brinicombe 51.1Schris * Copyright (C) 1994 Brini 61.1Schris * All rights reserved. 71.1Schris * 81.1Schris * Redistribution and use in source and binary forms, with or without 91.1Schris * modification, are permitted provided that the following conditions 101.1Schris * are met: 111.1Schris * 1. Redistributions of source code must retain the above copyright 121.1Schris * notice, this list of conditions and the following disclaimer. 131.1Schris * 2. Redistributions in binary form must reproduce the above copyright 141.1Schris * notice, this list of conditions and the following disclaimer in the 151.1Schris * documentation and/or other materials provided with the distribution. 161.1Schris * 3. All advertising materials mentioning features or use of this software 171.1Schris * must display the following acknowledgement: 181.1Schris * This product includes software developed by Brini. 191.1Schris * 4. The name of Brini may not be used to endorse or promote products 201.1Schris * derived from this software without specific prior written permission. 211.1Schris * 221.1Schris * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR 231.1Schris * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 241.1Schris * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 251.1Schris * IN NO EVENT SHALL BRINI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 261.1Schris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 271.1Schris * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 281.1Schris * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 291.1Schris * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 301.1Schris * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 311.1Schris * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 321.1Schris */ 331.1Schris 341.1Schris#include "assym.h" 351.1Schris#include <sys/syscall.h> 361.1Schris#include <sys/errno.h> 371.33Smatt#include <arm/asm.h> 381.33Smatt#include <arm/locore.h> 391.1Schris 401.1Schris/* What size should this really be ? It is only used by init_arm() */ 411.1Schris#define INIT_ARM_STACK_SIZE 2048 421.1Schris 431.37Smatt RCSID("$NetBSD: locore.S,v 1.37 2014/08/27 03:35:32 matt Exp $") 441.23Smatt 451.1Schris/* 461.1Schris * This is for kvm_mkdb, and should be the address of the beginning 471.1Schris * of the kernel text segment (not necessarily the same as kernbase). 481.1Schris */ 491.1Schris 501.2Sthorpej .text 511.2Sthorpej .align 0 521.5Sthorpej 531.5SthorpejENTRY_NP(kernel_text) 541.2Sthorpej 551.1SchrisASENTRY_NP(start) 561.29Smatt mrs r1, cpsr /* fetch CPSR value */ 571.29Smatt msr spsr_sx, r1 /* set SPSR[23:8] to known value */ 581.29Smatt 591.9Sbjh21 adr r1, .Lstart 601.27Smatt ldmia r1, {r1, r2, r8, sp} /* Set initial stack and */ 611.25Smatt 621.27Smatt#if defined(TPIDRPRW_IS_CURCPU) || defined(TPIDRPRW_IS_CURLWP) 631.27Smatt mcr p15, 0, r8, c13, c0, 4 641.25Smatt#endif 651.28Smatt#if defined(TPIDRPRW_IS_CURLWP) 661.28Smatt ldr r8, [r8, #L_CPU] /* r8 needs curcpu in it */ 671.28Smatt#endif 681.25Smatt 691.32Smatt mov r4, #0 701.32Smatt#ifdef _ARM_ARCH_DWORD_OK 711.32Smatt mov r5, #0 721.32Smatt#endif 731.7Sbriggs.L1: 741.32Smatt#ifdef _ARM_ARCH_DWORD_OK 751.34Sjoerg strd r4, r5, [r1], #0x0008 /* Zero the bss */ 761.32Smatt#else 771.32Smatt str r4, [r1], #0x0004 /* Zero the bss */ 781.32Smatt#endif 791.32Smatt cmp r1, r2 801.32Smatt blt .L1 811.1Schris 821.27Smatt mrc p15, 0, r3, c0, c0, 0 /* get our cpuid and save it early */ 831.27Smatt str r3, [r8, #CI_ARM_CPUID] 841.27Smatt 851.4Sthorpej mov fp, #0x00000000 /* trace back starts here */ 861.4Sthorpej bl _C_LABEL(initarm) /* Off we go */ 871.1Schris 881.1Schris /* init arm will return the new stack pointer. */ 891.1Schris mov sp, r0 901.1Schris 911.1Schris mov fp, #0x00000000 /* trace back starts here */ 921.1Schris mov ip, sp 931.33Smatt push {fp, ip, lr, pc} 941.1Schris sub fp, ip, #4 951.1Schris 961.4Sthorpej bl _C_LABEL(main) /* call main()! */ 971.1Schris 981.9Sbjh21 adr r0, .Lmainreturned 991.4Sthorpej b _C_LABEL(panic) 1001.17Spooka /* NOTREACHED */ 1011.1Schris 1021.7Sbriggs.Lstart: 1031.1Schris .word _edata 1041.1Schris .word _end 1051.28Smatt#if defined(TPIDRPRW_IS_CURLWP) 1061.27Smatt .word _C_LABEL(lwp0) 1071.27Smatt#else 1081.28Smatt .word _C_LABEL(cpu_info_store) 1091.27Smatt#endif 1101.1Schris .word svcstk + INIT_ARM_STACK_SIZE 1111.4Sthorpej 1121.8Sthorpej.Lmainreturned: 1131.4Sthorpej .asciz "main() returned" 1141.4Sthorpej .align 0 1151.33SmattASEND(start) 1161.1Schris 1171.1Schris .bss 1181.37Smatt#ifdef __ARM_EABI__ 1191.37Smatt .align 3 1201.37Smatt#endif 1211.1Schrissvcstk: 1221.1Schris .space INIT_ARM_STACK_SIZE 1231.1Schris 1241.1Schris .text 1251.1Schris .align 0 1261.1Schris 1271.1Schris#ifndef OFW 1281.1Schris /* OFW based systems will used OF_boot() */ 1291.36Smatt 1301.36Smatt.Lcpufuncs: 1311.1Schris .word _C_LABEL(cpufuncs) 1321.1Schris 1331.1SchrisENTRY_NP(cpu_reset) 1341.27Smatt#ifdef _ARM_ARCH_6 1351.27Smatt cpsid if, #PSR_SVC32_MODE 1361.27Smatt#else 1371.7Sbriggs mrs r2, cpsr 1381.1Schris bic r2, r2, #(PSR_MODE) 1391.1Schris orr r2, r2, #(PSR_SVC32_MODE) 1401.24Smatt orr r2, r2, #(IF32_bits) 1411.22Schris msr cpsr_c, r2 1421.27Smatt#endif 1431.1Schris 1441.8Sthorpej ldr r0, .Lcpufuncs 1451.10Sbsh mov lr, pc 1461.3Sthorpej ldr pc, [r0, #CF_IDCACHE_WBINV_ALL] 1471.1Schris 1481.1Schris /* 1491.26Smatt * Load the virutal address of the MD reset function first. 1501.1Schris */ 1511.26Smatt ldr r4, .Lcpu_reset_address 1521.26Smatt ldr r4, [r4] 1531.26Smatt cmp r4, #0 1541.1Schris 1551.26Smatt /* 1561.26Smatt * If virtual address is NULL, we must be using the physical address 1571.26Smatt */ 1581.26Smatt ldreq r4, .Lcpu_reset_address_paddr 1591.26Smatt ldreq r4, [r4] 1601.1Schris 1611.1Schris /* 1621.1Schris * MMU & IDC off, 32 bit program & data space 1631.1Schris * Hurl ourselves into the ROM 1641.1Schris */ 1651.27Smatt mrc p15, 0, r0, c1, c0, 0 1661.30Smatt bic r0, r0, #(CPU_CONTROL_MMU_ENABLE | CPU_CONTROL_DC_ENABLE) 1671.30Smatt bic r0, r0, #(CPU_CONTROL_IC_ENABLE) 1681.30Smatt orr r0, r0, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE) 1691.27Smatt mcr p15, 0, r0, c1, c0, 0 1701.27Smatt mcreq p15, 0, r2, c8, c7, 0 /* nail I+D TLB on ARMv4 and greater */ 1711.1Schris mov pc, r4 1721.1Schris 1731.1Schris /* 1741.26Smatt * cpu_reset_address contains the address to branch to, to complete 1751.15Swiz * the CPU reset after turning the MMU off 1761.1Schris * This variable is provided by the hardware specific code 1771.1Schris */ 1781.8Sthorpej.Lcpu_reset_address: 1791.1Schris .word _C_LABEL(cpu_reset_address) 1801.26Smatt.Lcpu_reset_address_paddr: 1811.26Smatt .word _C_LABEL(cpu_reset_address_paddr) 1821.33SmattEND(cpu_reset) 1831.1Schris#endif /* OFW */ 1841.1Schris 1851.1Schris/* 1861.1Schris * setjump + longjmp 1871.1Schris */ 1881.1SchrisENTRY(setjmp) 1891.1Schris stmia r0, {r4-r14} 1901.1Schris mov r0, #0x00000000 1911.33Smatt RET 1921.33SmattEND(setjmp) 1931.1Schris 1941.1SchrisENTRY(longjmp) 1951.1Schris ldmia r0, {r4-r14} 1961.1Schris mov r0, #0x00000001 1971.33Smatt RET 1981.33SmattEND(longjmp) 1991.1Schris 2001.1Schris .data 2011.1Schris .global _C_LABEL(esym) 2021.1Schris_C_LABEL(esym): .word _C_LABEL(end) 2031.1Schris 2041.1SchrisENTRY_NP(abort) 2051.1Schris b _C_LABEL(abort) 2061.33SmattEND(abort) 2071.1Schris 2081.19Schris/* 2091.21Sskrll * Part of doing a system dump, we need to save a switchframe onto the 2101.21Sskrll * stack, then save the rest of the registers into the dumppcb. 2111.19Schris */ 2121.19SchrisENTRY(dumpsys) 2131.19Schris /* push registers onto stack */ 2141.20Sskrll mov ip, sp 2151.33Smatt push {r4-r7, ip, lr} 2161.19Schris 2171.19Schris /* fill in dumppcb */ 2181.19Schris ldr r0, .Ldumppcb 2191.19Schris 2201.19Schris#ifndef __XSCALE__ 2211.19Schris add r2, r0, #(PCB_R8) 2221.19Schris stmia r2, {r8-r13} 2231.19Schris#else 2241.35Sjoerg strd r8, r9, [r0, #(PCB_R8)] 2251.35Sjoerg strd r10, r11, [r0, #(PCB_R10)] 2261.35Sjoerg strd r12, r13, [r0, #(PCB_R12)] 2271.19Schris#endif 2281.19Schris 2291.19Schris bl _C_LABEL(dodumpsys) 2301.19Schris 2311.19Schris /* unwind the stack */ 2321.33Smatt pop {r4-r7, ip, pc} 2331.19Schris 2341.19Schris.Ldumppcb: 2351.19Schris .word _C_LABEL(dumppcb) 2361.33SmattEND(dumpsys) 2371.1Schris 2381.1Schris/* End of locore.S */ 239