1 /* $NetBSD: locore.S,v 1.14 2003/04/20 16:21:40 thorpej 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.
36 #include <sys/syscall.h>
37 #include <machine/asm.h>
38 #include <machine/armreg.h>
39 #include <machine/pte.h>
40 __FBSDID("$FreeBSD$");
42 /* What size should this really be ? It is only used by init_arm() */
43 #define INIT_ARM_STACK_SIZE 2048
46 * This is for kvm_mkdb, and should be the address of the beginning
47 * of the kernel text segment (not necessarily the same as kernbase).
51 #define CPWAIT_BRANCH \
55 mrc p15, 0, tmp, c2, c0, 0 /* arbitrary read of CP15 */ ;\
56 mov tmp, tmp /* wait for it to complete */ ;\
57 CPWAIT_BRANCH /* branch to next insn */
62 .set kernbase,KERNBASE
64 .set physaddr,PHYSADDR
71 /* Check if we are running on RAM, if not move ourself to RAM */
74 bhi start_inram /* XXX: This is wrong */
77 * XXX: this is even more wrong, but RedBoot
78 * use 0x00000000-0x100000000 as virtual
79 * addresses for the RAM.
83 * XXX: we can use memcpy if it is PIC
86 adr r0, _C_LABEL(_start)
90 add r2, r2, #0x00200000
102 Lcopy_size: .word _edata-_C_LABEL(_start)
103 Lstart_off: .word start_inram-_C_LABEL(_start)
106 bic r7, r7, #0xff000000
107 orr r7, r7, #PHYSADDR
110 /* Disable MMU for a while */
111 mrc p15, 0, r2, c1, c0, 0
112 bic r2, r2, #(CPU_CONTROL_MMU_ENABLE | CPU_CONTROL_DC_ENABLE |\
113 CPU_CONTROL_WBUF_ENABLE)
114 bic r2, r2, #(CPU_CONTROL_IC_ENABLE)
115 bic r2, r2, #(CPU_CONTROL_BPRD_ENABLE)
116 mcr p15, 0, r2, c1, c0, 0
124 #ifdef STARTUP_PAGETABLE_ADDR
125 /* build page table from scratch */
126 ldr r0, Lstartup_pagetable
127 adr r4, mmu_init_table
133 add r3, r3, #(L1_S_SIZE)
137 ldmia r4!, {r1,r2,r3} /* # of sections, PA|attr, VA */
140 bicne r5, r5, #0xff000000
141 orrne r5, r5, #PHYSADDR
144 mcr p15, 0, r0, c2, c0, 0 /* Set TTB */
145 mcr p15, 0, r0, c8, c7, 0 /* Flush TLB */
147 /* Set the Domain Access register. Very important! */
148 mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
149 mcr p15, 0, r0, c3, c0, 0
151 mrc p15, 0, r0, c1, c0, 0
152 orr r0, r0, #CPU_CONTROL_MMU_ENABLE
153 mcr p15, 0, r0, c1, c0, 0
163 ldmia r1, {r1, r2, sp} /* Set initial stack and */
164 sub r2, r2, r1 /* get zero init data */
167 str r3, [r1], #0x0004 /* get zero init data */
173 mov fp, #0 /* trace back starts here */
174 bl _C_LABEL(initarm) /* Off we go */
176 /* init arm will return the new stack pointer. */
179 bl _C_LABEL(mi_startup) /* call mi_startup()! */
181 adr r0, .Lmainreturned
184 #ifdef STARTUP_PAGETABLE_ADDR
185 #define MMU_INIT(va,pa,n_sec,attr) \
187 .word 4*((va)>>L1_S_SHIFT) ; \
195 .word STARTUP_PAGETABLE_ADDR
197 /* fill all table VA==PA */
198 /* map SDRAM VA==PA, WT cacheable */
199 MMU_INIT(PHYSADDR, PHYSADDR , 64, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))
200 /* map VA 0xc0000000..0xc3ffffff to PA */
201 MMU_INIT(KERNBASE, PHYSADDR, 64, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))
203 .word 0 /* end of table */
208 .word svcstk + INIT_ARM_STACK_SIZE
213 .asciz "main() returned"
218 .space INIT_ARM_STACK_SIZE
224 /* OFW based systems will used OF_boot() */
227 .word _C_LABEL(cpufuncs)
231 bic r2, r2, #(PSR_MODE)
232 orr r2, r2, #(PSR_SVC32_MODE)
233 orr r2, r2, #(I32_bit | F32_bit)
236 ldr r4, .Lcpu_reset_address
241 ldr pc, [r0, #CF_IDCACHE_WBINV_ALL]
244 * Load the cpu_reset_needs_v4_MMU_disable flag to determine if it's
248 ldr r1, .Lcpu_reset_needs_v4_MMU_disable
254 * MMU & IDC off, 32 bit program & data space
255 * Hurl ourselves into the ROM
257 mov r0, #(CPU_CONTROL_32BP_ENABLE | CPU_CONTROL_32BD_ENABLE)
258 mcr 15, 0, r0, c1, c0, 0
259 mcrne 15, 0, r2, c8, c7, 0 /* nail I+D TLB on ARMv4 and greater */
263 * _cpu_reset_address contains the address to branch to, to complete
264 * the cpu reset after turning the MMU off
265 * This variable is provided by the hardware specific code
268 .word _C_LABEL(cpu_reset_address)
271 * cpu_reset_needs_v4_MMU_disable contains a flag that signals if the
272 * v4 MMU disable instruction needs executing... it is an illegal instruction
273 * on f.e. ARM6/7 that locks up the computer in an endless illegal
274 * instruction / data-abort / reset loop.
276 .Lcpu_reset_needs_v4_MMU_disable:
277 .word _C_LABEL(cpu_reset_needs_v4_MMU_disable)
283 * Execute(inst, psr, args, sp)
285 * Execute INSTruction with PSR and ARGS[0] - ARGS[3] making
286 * available stack at SP for next undefined instruction trap.
288 * Move the instruction onto the stack and jump to it.
292 stmfd sp!, {r2, r4-r7, fp, ip, lr, pc}
307 /* XXX Cannot switch thus easily back from user mode */
313 ldmdb fp, {r4-r7, fp, sp, pc}
332 .global _C_LABEL(esym)
333 _C_LABEL(esym): .word _C_LABEL(end)
342 /* Well if that failed we better exit quick ! */
348 .global _C_LABEL(esigcode)
354 .long esigcode-sigcode
355 /* End of locore.S */