locore.S revision 1.4
11.4Sthorpej/* $NetBSD: locore.S,v 1.4 2002/03/25 16:58:18 thorpej 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 "opt_ipkdb.h" 351.1Schris#include "assym.h" 361.1Schris#include <sys/syscall.h> 371.1Schris#include <sys/errno.h> 381.1Schris#include <machine/asm.h> 391.1Schris#include <machine/cpu.h> 401.1Schris#include <machine/frame.h> 411.1Schris#include <machine/param.h> 421.1Schris 431.1Schris/* What size should this really be ? It is only used by init_arm() */ 441.1Schris#define INIT_ARM_STACK_SIZE 2048 451.1Schris 461.1Schris/* 471.1Schris * This is for kvm_mkdb, and should be the address of the beginning 481.1Schris * of the kernel text segment (not necessarily the same as kernbase). 491.1Schris */ 501.1Schris 511.1Schris#ifndef netwinder 521.1SchrisENTRY_NP(kernel_text) 531.1Schris#endif 541.1Schris 551.2Sthorpej .text 561.2Sthorpej .align 0 571.2Sthorpej 581.1SchrisASENTRY_NP(start) 591.1Schris add r1, pc, #(Lstart - . - 8) 601.4Sthorpej ldmia r1, {r1, r2, sp} /* Set initial stack and */ 611.4Sthorpej sub r2, r2, r1 /* get zero init data */ 621.1Schris mov r3, #0 631.1Schris 641.1SchrisL1: 651.4Sthorpej str r3, [r1], #0x0004 /* Zero the bss */ 661.1Schris subs r2, r2, #4 671.1Schris bgt L1 681.1Schris 691.4Sthorpej mov fp, #0x00000000 /* trace back starts here */ 701.4Sthorpej bl _C_LABEL(initarm) /* Off we go */ 711.1Schris 721.1Schris /* init arm will return the new stack pointer. */ 731.1Schris mov sp, r0 741.1Schris 751.1Schris mov fp, #0x00000000 /* trace back starts here */ 761.1Schris mov ip, sp 771.1Schris stmfd sp!, {fp, ip, lr, pc} 781.1Schris sub fp, ip, #4 791.1Schris 801.4Sthorpej bl _C_LABEL(main) /* call main()! */ 811.1Schris 821.4Sthorpej add r0, pc, #Lmainreturned - . - 8 831.4Sthorpej b _C_LABEL(panic) 841.4Sthorpej /* NOTEACHED */ 851.1Schris 861.1SchrisLstart: 871.1Schris .word _edata 881.1Schris .word _end 891.1Schris .word svcstk + INIT_ARM_STACK_SIZE 901.4Sthorpej 911.4SthorpejLmainreturned: 921.4Sthorpej .asciz "main() returned" 931.4Sthorpej .align 0 941.1Schris 951.1Schris .bss 961.1Schrissvcstk: 971.1Schris .space INIT_ARM_STACK_SIZE 981.1Schris 991.1Schris .text 1001.1Schris .align 0 1011.1Schris 1021.1Schris#ifndef OFW 1031.1Schris /* OFW based systems will used OF_boot() */ 1041.1Schris 1051.1SchrisLcpufuncs: 1061.1Schris .word _C_LABEL(cpufuncs) 1071.1Schris 1081.1SchrisENTRY_NP(cpu_reset) 1091.1Schris mrs r2, cpsr_all 1101.1Schris bic r2, r2, #(PSR_MODE) 1111.1Schris orr r2, r2, #(PSR_SVC32_MODE) 1121.1Schris orr r2, r2, #(I32_bit | F32_bit) 1131.1Schris msr cpsr_all, r2 1141.1Schris 1151.1Schris ldr r4, Lcpu_reset_address 1161.1Schris ldr r4, [r4] 1171.1Schris 1181.1Schris ldr r0, Lcpufuncs 1191.1Schris add lr, pc, #Lboot_cache_purged - . - 8 1201.3Sthorpej ldr pc, [r0, #CF_IDCACHE_WBINV_ALL] 1211.1Schris 1221.1SchrisLboot_cache_purged: 1231.1Schris 1241.1Schris /* 1251.1Schris * Load the cpu_reset_needs_v4_MMU_disable flag to determine if it's 1261.1Schris * necessary. 1271.1Schris */ 1281.1Schris 1291.1Schris ldr r1, Lcpu_reset_needs_v4_MMU_disable 1301.1Schris ldr r1, [r1] 1311.1Schris cmp r1, #0 1321.1Schris 1331.1Schris /* 1341.1Schris * MMU & IDC off, 32 bit program & data space 1351.1Schris * Hurl ourselves into the ROM 1361.1Schris */ 1371.1Schris mov r0, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE) 1381.1Schris mcr 15, 0, r0, c1, c0, 0 1391.1Schris mcrne 15, 0, r0, c8, c7, 0 /* only when v4 MMU disable is asked for */ 1401.1Schris mov pc, r4 1411.1Schris 1421.1Schris /* 1431.1Schris * _cpu_reset_address contains the address to branch to, to complete 1441.1Schris * the cpu reset after turning the MMU off 1451.1Schris * This variable is provided by the hardware specific code 1461.1Schris */ 1471.1SchrisLcpu_reset_address: 1481.1Schris .word _C_LABEL(cpu_reset_address) 1491.1Schris 1501.1Schris /* 1511.1Schris * cpu_reset_needs_v4_MMU_disable contains a flag that signals if the 1521.1Schris * v4 MMU disable instruction needs executing... it is an illegal instruction 1531.1Schris * on f.e. ARM6/7 that locks up the computer in an endless illegal 1541.1Schris * instruction / data-abort / reset loop. 1551.1Schris */ 1561.1SchrisLcpu_reset_needs_v4_MMU_disable: 1571.1Schris .word _C_LABEL(cpu_reset_needs_v4_MMU_disable) 1581.1Schris 1591.1Schris#endif /* OFW */ 1601.1Schris 1611.1Schris#ifdef IPKDB 1621.1Schris/* 1631.1Schris * Execute(inst, psr, args, sp) 1641.1Schris * 1651.1Schris * Execute INSTruction with PSR and ARGS[0] - ARGS[3] making 1661.1Schris * available stack at SP for next undefined instruction trap. 1671.1Schris * 1681.1Schris * Move the instruction onto the stack and jump to it. 1691.1Schris */ 1701.1SchrisENTRY_NP(Execute) 1711.1Schris mov ip, sp 1721.1Schris stmfd sp!, {r2, r4-r7, fp, ip, lr, pc} 1731.1Schris sub fp, ip, #4 1741.1Schris mov ip, r3 1751.1Schris ldr r7, return 1761.1Schris stmfd sp!, {r0, r7} 1771.1Schris add r7, pc, #LExec - . - 8 1781.1Schris mov r5, r1 1791.1Schris mrs r4, cpsr_all 1801.1Schris ldmia r2, {r0-r3} 1811.1Schris mov r6, sp 1821.1Schris mov sp, ip 1831.1Schris msr cpsr_all, r5 1841.1Schris mov pc, r6 1851.1SchrisLExec: 1861.1Schris mrs r5, cpsr_all 1871.1Schris/* XXX Cannot switch thus easily back from user mode */ 1881.1Schris msr cpsr_all, r4 1891.1Schris add sp, r6, #8 1901.1Schris ldmfd sp!, {r6} 1911.1Schris stmia r6, {r0-r3} 1921.1Schris mov r0, r5 1931.1Schris ldmdb fp, {r4-r7, fp, sp, pc} 1941.1Schrisreturn: 1951.1Schris mov pc, r7 1961.1Schris#endif 1971.1Schris 1981.1Schris/* 1991.1Schris * setjump + longjmp 2001.1Schris */ 2011.1SchrisENTRY(setjmp) 2021.1Schris stmia r0, {r4-r14} 2031.1Schris mov r0, #0x00000000 2041.1Schris mov pc, lr 2051.1Schris 2061.1SchrisENTRY(longjmp) 2071.1Schris ldmia r0, {r4-r14} 2081.1Schris mov r0, #0x00000001 2091.1Schris mov pc, lr 2101.1Schris 2111.1Schris .data 2121.1Schris .global _C_LABEL(esym) 2131.1Schris_C_LABEL(esym): .word _C_LABEL(end) 2141.1Schris 2151.1SchrisENTRY_NP(abort) 2161.1Schris b _C_LABEL(abort) 2171.1Schris 2181.1Schris 2191.1Schris/* 2201.1Schris * Atomic bit set and clear functions 2211.1Schris */ 2221.1Schris 2231.1SchrisENTRY(atomic_set_bit) 2241.1Schris mrs r2, cpsr_all 2251.1Schris orr r3, r2, #(I32_bit) 2261.1Schris msr cpsr_all, r3 2271.1Schris 2281.1Schris ldr r3, [r0] 2291.1Schris orr r3, r3, r1 2301.1Schris str r3, [r0] 2311.1Schris 2321.1Schris msr cpsr_all, r2 2331.1Schris mov pc, lr 2341.1Schris 2351.1Schris 2361.1SchrisENTRY(atomic_clear_bit) 2371.1Schris mrs r2, cpsr_all 2381.1Schris orr r3, r2, #(I32_bit) 2391.1Schris msr cpsr_all, r3 2401.1Schris 2411.1Schris ldr r3, [r0] 2421.1Schris bic r3, r3, r1 2431.1Schris str r3, [r0] 2441.1Schris 2451.1Schris msr cpsr_all, r2 2461.1Schris mov pc, lr 2471.1Schris 2481.1Schris/* End of locore.S */ 249