1 /* $NetBSD: locore.S,v 1.23 2008/04/27 18:58:44 matt Exp $ */
4 * Copyright (C) 1994-1997 Mark Brinicombe
5 * Copyright (C) 1994 Brini
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
35 #include <sys/syscall.h>
36 #include <sys/errno.h>
37 #include <machine/asm.h>
38 #include <machine/cpu.h>
39 #include <machine/frame.h>
40 #include <machine/param.h>
42 /* What size should this really be ? It is only used by init_arm() */
43 #define INIT_ARM_STACK_SIZE 2048
45 RCSID("$NetBSD: locore.S,v 1.23 2008/04/27 18:58:44 matt Exp $")
48 * This is for kvm_mkdb, and should be the address of the beginning
49 * of the kernel text segment (not necessarily the same as kernbase).
59 ldmia r1, {r1, r2, sp} /* Set initial stack and */
60 sub r2, r2, r1 /* get zero init data */
64 str r3, [r1], #0x0004 /* Zero the bss */
68 mov fp, #0x00000000 /* trace back starts here */
69 bl _C_LABEL(initarm) /* Off we go */
71 /* init arm will return the new stack pointer. */
74 mov fp, #0x00000000 /* trace back starts here */
76 stmfd sp!, {fp, ip, lr, pc}
79 bl _C_LABEL(main) /* call main()! */
81 adr r0, .Lmainreturned
88 .word svcstk + INIT_ARM_STACK_SIZE
91 .asciz "main() returned"
96 .space INIT_ARM_STACK_SIZE
102 /* OFW based systems will used OF_boot() */
105 .word _C_LABEL(cpufuncs)
109 bic r2, r2, #(PSR_MODE)
110 orr r2, r2, #(PSR_SVC32_MODE)
111 orr r2, r2, #(IF32_bits)
114 ldr r4, .Lcpu_reset_address
119 ldr pc, [r0, #CF_IDCACHE_WBINV_ALL]
122 * Load the cpu_reset_needs_v4_MMU_disable flag to determine if it's
126 ldr r1, .Lcpu_reset_needs_v4_MMU_disable
132 * MMU & IDC off, 32 bit program & data space
133 * Hurl ourselves into the ROM
135 mov r0, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE)
136 mcr 15, 0, r0, c1, c0, 0
137 mcrne 15, 0, r2, c8, c7, 0 /* nail I+D TLB on ARMv4 and greater */
141 * _cpu_reset_address contains the address to branch to, to complete
142 * the CPU reset after turning the MMU off
143 * This variable is provided by the hardware specific code
146 .word _C_LABEL(cpu_reset_address)
149 * cpu_reset_needs_v4_MMU_disable contains a flag that signals if the
150 * v4 MMU disable instruction needs executing... it is an illegal instruction
151 * on f.e. ARM6/7 that locks up the computer in an endless illegal
152 * instruction / data-abort / reset loop.
154 .Lcpu_reset_needs_v4_MMU_disable:
155 .word _C_LABEL(cpu_reset_needs_v4_MMU_disable)
173 .global _C_LABEL(esym)
174 _C_LABEL(esym): .word _C_LABEL(end)
180 * Part of doing a system dump, we need to save a switchframe onto the
181 * stack, then save the rest of the registers into the dumppcb.
184 /* push registers onto stack */
186 stmfd sp!, {r4-r7, ip, lr}
188 /* fill in dumppcb */
192 add r2, r0, #(PCB_R8)
195 strd r8, [r0, #(PCB_R8)]
196 strd r10, [r0, #(PCB_R10)]
197 strd r12, [r0, #(PCB_R12)]
200 bl _C_LABEL(dodumpsys)
202 /* unwind the stack */
203 ldmfd sp, {r4-r7, sp, pc}
206 .word _C_LABEL(dumppcb)
208 /* End of locore.S */