locore.S revision 1.38
11.38Sskrll/* $NetBSD: locore.S,v 1.38 2017/10/14 15:35:02 skrll 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.38Sskrll RCSID("$NetBSD: locore.S,v 1.38 2017/10/14 15:35:02 skrll 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.38Sskrll /* 601.38Sskrll * Get bss bounds (r1, r2), curlwp or curcpu (r8), and set initial 611.38Sskrll * stack. 621.38Sskrll */ 631.9Sbjh21 adr r1, .Lstart 641.38Sskrll ldmia r1, {r1, r2, r8, sp} 651.25Smatt 661.27Smatt#if defined(TPIDRPRW_IS_CURCPU) || defined(TPIDRPRW_IS_CURLWP) 671.27Smatt mcr p15, 0, r8, c13, c0, 4 681.25Smatt#endif 691.28Smatt#if defined(TPIDRPRW_IS_CURLWP) 701.28Smatt ldr r8, [r8, #L_CPU] /* r8 needs curcpu in it */ 711.28Smatt#endif 721.25Smatt 731.32Smatt mov r4, #0 741.32Smatt#ifdef _ARM_ARCH_DWORD_OK 751.32Smatt mov r5, #0 761.32Smatt#endif 771.7Sbriggs.L1: 781.32Smatt#ifdef _ARM_ARCH_DWORD_OK 791.34Sjoerg strd r4, r5, [r1], #0x0008 /* Zero the bss */ 801.32Smatt#else 811.32Smatt str r4, [r1], #0x0004 /* Zero the bss */ 821.32Smatt#endif 831.32Smatt cmp r1, r2 841.32Smatt blt .L1 851.1Schris 861.27Smatt mrc p15, 0, r3, c0, c0, 0 /* get our cpuid and save it early */ 871.27Smatt str r3, [r8, #CI_ARM_CPUID] 881.27Smatt 891.4Sthorpej mov fp, #0x00000000 /* trace back starts here */ 901.4Sthorpej bl _C_LABEL(initarm) /* Off we go */ 911.1Schris 921.1Schris /* init arm will return the new stack pointer. */ 931.1Schris mov sp, r0 941.1Schris 951.1Schris mov fp, #0x00000000 /* trace back starts here */ 961.1Schris mov ip, sp 971.33Smatt push {fp, ip, lr, pc} 981.1Schris sub fp, ip, #4 991.1Schris 1001.4Sthorpej bl _C_LABEL(main) /* call main()! */ 1011.1Schris 1021.9Sbjh21 adr r0, .Lmainreturned 1031.4Sthorpej b _C_LABEL(panic) 1041.17Spooka /* NOTREACHED */ 1051.1Schris 1061.7Sbriggs.Lstart: 1071.1Schris .word _edata 1081.1Schris .word _end 1091.28Smatt#if defined(TPIDRPRW_IS_CURLWP) 1101.27Smatt .word _C_LABEL(lwp0) 1111.27Smatt#else 1121.28Smatt .word _C_LABEL(cpu_info_store) 1131.27Smatt#endif 1141.1Schris .word svcstk + INIT_ARM_STACK_SIZE 1151.4Sthorpej 1161.8Sthorpej.Lmainreturned: 1171.4Sthorpej .asciz "main() returned" 1181.4Sthorpej .align 0 1191.33SmattASEND(start) 1201.1Schris 1211.1Schris .bss 1221.37Smatt#ifdef __ARM_EABI__ 1231.37Smatt .align 3 1241.37Smatt#endif 1251.1Schrissvcstk: 1261.1Schris .space INIT_ARM_STACK_SIZE 1271.1Schris 1281.1Schris .text 1291.1Schris .align 0 1301.1Schris 1311.1Schris#ifndef OFW 1321.1Schris /* OFW based systems will used OF_boot() */ 1331.36Smatt 1341.36Smatt.Lcpufuncs: 1351.1Schris .word _C_LABEL(cpufuncs) 1361.1Schris 1371.1SchrisENTRY_NP(cpu_reset) 1381.27Smatt#ifdef _ARM_ARCH_6 1391.27Smatt cpsid if, #PSR_SVC32_MODE 1401.27Smatt#else 1411.7Sbriggs mrs r2, cpsr 1421.1Schris bic r2, r2, #(PSR_MODE) 1431.1Schris orr r2, r2, #(PSR_SVC32_MODE) 1441.24Smatt orr r2, r2, #(IF32_bits) 1451.22Schris msr cpsr_c, r2 1461.27Smatt#endif 1471.1Schris 1481.8Sthorpej ldr r0, .Lcpufuncs 1491.10Sbsh mov lr, pc 1501.3Sthorpej ldr pc, [r0, #CF_IDCACHE_WBINV_ALL] 1511.1Schris 1521.1Schris /* 1531.26Smatt * Load the virutal address of the MD reset function first. 1541.1Schris */ 1551.26Smatt ldr r4, .Lcpu_reset_address 1561.26Smatt ldr r4, [r4] 1571.26Smatt cmp r4, #0 1581.1Schris 1591.26Smatt /* 1601.26Smatt * If virtual address is NULL, we must be using the physical address 1611.26Smatt */ 1621.26Smatt ldreq r4, .Lcpu_reset_address_paddr 1631.26Smatt ldreq r4, [r4] 1641.1Schris 1651.1Schris /* 1661.1Schris * MMU & IDC off, 32 bit program & data space 1671.1Schris * Hurl ourselves into the ROM 1681.1Schris */ 1691.27Smatt mrc p15, 0, r0, c1, c0, 0 1701.30Smatt bic r0, r0, #(CPU_CONTROL_MMU_ENABLE | CPU_CONTROL_DC_ENABLE) 1711.30Smatt bic r0, r0, #(CPU_CONTROL_IC_ENABLE) 1721.30Smatt orr r0, r0, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE) 1731.27Smatt mcr p15, 0, r0, c1, c0, 0 1741.27Smatt mcreq p15, 0, r2, c8, c7, 0 /* nail I+D TLB on ARMv4 and greater */ 1751.1Schris mov pc, r4 1761.1Schris 1771.1Schris /* 1781.26Smatt * cpu_reset_address contains the address to branch to, to complete 1791.15Swiz * the CPU reset after turning the MMU off 1801.1Schris * This variable is provided by the hardware specific code 1811.1Schris */ 1821.8Sthorpej.Lcpu_reset_address: 1831.1Schris .word _C_LABEL(cpu_reset_address) 1841.26Smatt.Lcpu_reset_address_paddr: 1851.26Smatt .word _C_LABEL(cpu_reset_address_paddr) 1861.33SmattEND(cpu_reset) 1871.1Schris#endif /* OFW */ 1881.1Schris 1891.1Schris/* 1901.1Schris * setjump + longjmp 1911.1Schris */ 1921.1SchrisENTRY(setjmp) 1931.1Schris stmia r0, {r4-r14} 1941.1Schris mov r0, #0x00000000 1951.33Smatt RET 1961.33SmattEND(setjmp) 1971.1Schris 1981.1SchrisENTRY(longjmp) 1991.1Schris ldmia r0, {r4-r14} 2001.1Schris mov r0, #0x00000001 2011.33Smatt RET 2021.33SmattEND(longjmp) 2031.1Schris 2041.1Schris .data 2051.1Schris .global _C_LABEL(esym) 2061.1Schris_C_LABEL(esym): .word _C_LABEL(end) 2071.1Schris 2081.1SchrisENTRY_NP(abort) 2091.1Schris b _C_LABEL(abort) 2101.33SmattEND(abort) 2111.1Schris 2121.19Schris/* 2131.21Sskrll * Part of doing a system dump, we need to save a switchframe onto the 2141.21Sskrll * stack, then save the rest of the registers into the dumppcb. 2151.19Schris */ 2161.19SchrisENTRY(dumpsys) 2171.19Schris /* push registers onto stack */ 2181.20Sskrll mov ip, sp 2191.33Smatt push {r4-r7, ip, lr} 2201.19Schris 2211.19Schris /* fill in dumppcb */ 2221.19Schris ldr r0, .Ldumppcb 2231.19Schris 2241.19Schris#ifndef __XSCALE__ 2251.19Schris add r2, r0, #(PCB_R8) 2261.19Schris stmia r2, {r8-r13} 2271.19Schris#else 2281.35Sjoerg strd r8, r9, [r0, #(PCB_R8)] 2291.35Sjoerg strd r10, r11, [r0, #(PCB_R10)] 2301.35Sjoerg strd r12, r13, [r0, #(PCB_R12)] 2311.19Schris#endif 2321.19Schris 2331.19Schris bl _C_LABEL(dodumpsys) 2341.19Schris 2351.19Schris /* unwind the stack */ 2361.33Smatt pop {r4-r7, ip, pc} 2371.19Schris 2381.19Schris.Ldumppcb: 2391.19Schris .word _C_LABEL(dumppcb) 2401.33SmattEND(dumpsys) 2411.1Schris 2421.1Schris/* End of locore.S */ 243