locore.S revision 1.22
11.22Schris/* $NetBSD: locore.S,v 1.22 2008/01/19 13:11:09 chris 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.1Schris#include <machine/asm.h> 381.1Schris#include <machine/cpu.h> 391.1Schris#include <machine/frame.h> 401.1Schris#include <machine/param.h> 411.1Schris 421.1Schris/* What size should this really be ? It is only used by init_arm() */ 431.1Schris#define INIT_ARM_STACK_SIZE 2048 441.1Schris 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.9Sbjh21 adr r1, .Lstart 571.4Sthorpej ldmia r1, {r1, r2, sp} /* Set initial stack and */ 581.4Sthorpej sub r2, r2, r1 /* get zero init data */ 591.1Schris mov r3, #0 601.1Schris 611.7Sbriggs.L1: 621.4Sthorpej str r3, [r1], #0x0004 /* Zero the bss */ 631.1Schris subs r2, r2, #4 641.7Sbriggs bgt .L1 651.1Schris 661.4Sthorpej mov fp, #0x00000000 /* trace back starts here */ 671.4Sthorpej bl _C_LABEL(initarm) /* Off we go */ 681.1Schris 691.1Schris /* init arm will return the new stack pointer. */ 701.1Schris mov sp, r0 711.1Schris 721.1Schris mov fp, #0x00000000 /* trace back starts here */ 731.1Schris mov ip, sp 741.1Schris stmfd sp!, {fp, ip, lr, pc} 751.1Schris sub fp, ip, #4 761.1Schris 771.4Sthorpej bl _C_LABEL(main) /* call main()! */ 781.1Schris 791.9Sbjh21 adr r0, .Lmainreturned 801.4Sthorpej b _C_LABEL(panic) 811.17Spooka /* NOTREACHED */ 821.1Schris 831.7Sbriggs.Lstart: 841.1Schris .word _edata 851.1Schris .word _end 861.1Schris .word svcstk + INIT_ARM_STACK_SIZE 871.4Sthorpej 881.8Sthorpej.Lmainreturned: 891.4Sthorpej .asciz "main() returned" 901.4Sthorpej .align 0 911.1Schris 921.1Schris .bss 931.1Schrissvcstk: 941.1Schris .space INIT_ARM_STACK_SIZE 951.1Schris 961.1Schris .text 971.1Schris .align 0 981.1Schris 991.1Schris#ifndef OFW 1001.1Schris /* OFW based systems will used OF_boot() */ 1011.1Schris 1021.8Sthorpej.Lcpufuncs: 1031.1Schris .word _C_LABEL(cpufuncs) 1041.1Schris 1051.1SchrisENTRY_NP(cpu_reset) 1061.7Sbriggs mrs r2, cpsr 1071.1Schris bic r2, r2, #(PSR_MODE) 1081.1Schris orr r2, r2, #(PSR_SVC32_MODE) 1091.1Schris orr r2, r2, #(I32_bit | F32_bit) 1101.22Schris msr cpsr_c, r2 1111.1Schris 1121.8Sthorpej ldr r4, .Lcpu_reset_address 1131.1Schris ldr r4, [r4] 1141.1Schris 1151.8Sthorpej ldr r0, .Lcpufuncs 1161.10Sbsh mov lr, pc 1171.3Sthorpej ldr pc, [r0, #CF_IDCACHE_WBINV_ALL] 1181.1Schris 1191.1Schris /* 1201.1Schris * Load the cpu_reset_needs_v4_MMU_disable flag to determine if it's 1211.1Schris * necessary. 1221.1Schris */ 1231.1Schris 1241.8Sthorpej ldr r1, .Lcpu_reset_needs_v4_MMU_disable 1251.1Schris ldr r1, [r1] 1261.1Schris cmp r1, #0 1271.14Sthorpej mov r2, #0 1281.1Schris 1291.1Schris /* 1301.1Schris * MMU & IDC off, 32 bit program & data space 1311.1Schris * Hurl ourselves into the ROM 1321.1Schris */ 1331.13Sthorpej mov r0, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE) 1341.1Schris mcr 15, 0, r0, c1, c0, 0 1351.14Sthorpej mcrne 15, 0, r2, c8, c7, 0 /* nail I+D TLB on ARMv4 and greater */ 1361.1Schris mov pc, r4 1371.1Schris 1381.1Schris /* 1391.1Schris * _cpu_reset_address contains the address to branch to, to complete 1401.15Swiz * the CPU reset after turning the MMU off 1411.1Schris * This variable is provided by the hardware specific code 1421.1Schris */ 1431.8Sthorpej.Lcpu_reset_address: 1441.1Schris .word _C_LABEL(cpu_reset_address) 1451.1Schris 1461.1Schris /* 1471.1Schris * cpu_reset_needs_v4_MMU_disable contains a flag that signals if the 1481.1Schris * v4 MMU disable instruction needs executing... it is an illegal instruction 1491.1Schris * on f.e. ARM6/7 that locks up the computer in an endless illegal 1501.1Schris * instruction / data-abort / reset loop. 1511.1Schris */ 1521.8Sthorpej.Lcpu_reset_needs_v4_MMU_disable: 1531.1Schris .word _C_LABEL(cpu_reset_needs_v4_MMU_disable) 1541.1Schris 1551.1Schris#endif /* OFW */ 1561.1Schris 1571.1Schris/* 1581.1Schris * setjump + longjmp 1591.1Schris */ 1601.1SchrisENTRY(setjmp) 1611.1Schris stmia r0, {r4-r14} 1621.1Schris mov r0, #0x00000000 1631.1Schris mov pc, lr 1641.1Schris 1651.1SchrisENTRY(longjmp) 1661.1Schris ldmia r0, {r4-r14} 1671.1Schris mov r0, #0x00000001 1681.1Schris mov pc, lr 1691.1Schris 1701.1Schris .data 1711.1Schris .global _C_LABEL(esym) 1721.1Schris_C_LABEL(esym): .word _C_LABEL(end) 1731.1Schris 1741.1SchrisENTRY_NP(abort) 1751.1Schris b _C_LABEL(abort) 1761.1Schris 1771.19Schris/* 1781.21Sskrll * Part of doing a system dump, we need to save a switchframe onto the 1791.21Sskrll * stack, then save the rest of the registers into the dumppcb. 1801.19Schris */ 1811.19SchrisENTRY(dumpsys) 1821.19Schris /* push registers onto stack */ 1831.20Sskrll mov ip, sp 1841.20Sskrll stmfd sp!, {r4-r7, ip, lr} 1851.19Schris 1861.19Schris /* fill in dumppcb */ 1871.19Schris ldr r0, .Ldumppcb 1881.19Schris 1891.19Schris#ifndef __XSCALE__ 1901.19Schris add r2, r0, #(PCB_R8) 1911.19Schris stmia r2, {r8-r13} 1921.19Schris#else 1931.19Schris strd r8, [r0, #(PCB_R8)] 1941.19Schris strd r10, [r0, #(PCB_R10)] 1951.19Schris strd r12, [r0, #(PCB_R12)] 1961.19Schris#endif 1971.19Schris 1981.19Schris bl _C_LABEL(dodumpsys) 1991.19Schris 2001.19Schris /* unwind the stack */ 2011.20Sskrll ldmfd sp, {r4-r7, sp, pc} 2021.19Schris 2031.19Schris.Ldumppcb: 2041.19Schris .word _C_LABEL(dumppcb) 2051.1Schris 2061.1Schris/* End of locore.S */ 207