1 /* $NetBSD: omap_start.S,v 1.2 2008/04/27 18:58:45 matt Exp $ */
4 * Machine dependant startup code for OMAP boards.
5 * Based on lubbock_start.S and tsarm_start.S
7 * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
8 * Written by Hiroyuki Bessho for Genetec Corporation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of Genetec Corporation may not be used to endorse or
19 * promote products derived from this software without specific prior
22 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 * Ichiro FUKUHARA <ichiro@ichiro.org>.
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
47 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
51 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * Copyright (c) 2007 Microsoft
60 * All rights reserved.
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 * 2. Redistributions in binary form must reproduce the above copyright
68 * notice, this list of conditions and the following disclaimer in the
69 * documentation and/or other materials provided with the distribution.
70 * 3. All advertising materials mentioning features or use of this software
71 * must display the following acknowledgement:
72 * This product includes software developed by Microsoft
74 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
75 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
76 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
78 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
79 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
80 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
81 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
82 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
83 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 #include <machine/asm.h>
90 #include <arm/armreg.h>
91 #undef DOMAIN_CLIENT /* assym.h defines as 1, but pte.h defines as 0x01 */
92 #include <arm/arm32/pmap.h>
93 #include <arm/omap/omap_reg.h>
96 * Kernel start routine for OMAP boards.
97 * At this point, this code has been loaded into the very beginning of SDRAM
98 * and the MMU is off, which implies the data cache is off.
100 .section .start,"ax",%progbits
102 .global _C_LABEL(omap_start)
103 _C_LABEL(omap_start):
104 /* Move into supervisor mode and disable IRQs/FIQs. */
106 bic r0, r0, #PSR_MODE
107 orr r0, r0, #(I32_bit | F32_bit | PSR_SVC32_MODE)
111 * Set up a preliminary mapping in the MMU to allow us to run
112 * at KERNEL_BASE with caches on.
114 /* Build page table from scratch */
115 ldr r0, Ltemp_l1_table
116 mov r1, r0 /* Save the page table address. */
117 /* Zero the entire table so all virtual addresses are invalid. */
118 mov r2, #L1_TABLE_SIZE /* in bytes */
127 1: stmia r1!, {r3-r8,r10-r11}
128 stmia r1!, {r3-r8,r10-r11}
129 stmia r1!, {r3-r8,r10-r11}
130 stmia r1!, {r3-r8,r10-r11}
131 subs r2, r2, #(4 * 4 * 8) /* bytes per loop */
134 /* Now create our entries per the mmu_init_table. */
142 adr itable, mmu_init_table
143 ldr l1sfrm, Ll1_s_frame
145 2: str pa, [l1table, va]
147 add pa, pa, #(L1_S_SIZE)
148 adds n_sec, n_sec, #-1
150 3: ldmia itable!, {va,pa,n_sec,attr}
151 /* Convert va to l1 offset: va = 4 * (va >> L1_S_SHIFT) */
152 mov va, va, LSR #L1_S_SHIFT
154 /* Convert pa to l1 entry: pa = (pa & L1_S_FRAME) | attr */
168 * In theory, because the MMU is off, we shouldn't need all of this,
169 * but let's not take any chances and do a typical sequence to set
170 * the Translation Table Base.
172 mcr p15, 0, r0, c7, c5, 0 /* Invalidate I cache */
173 1: mrc p15, 0, r15, c7, c14, 3 /* Test, clean, invalidate D cache. */
175 mcr p15, 0, r0, c7, c10, 4 /* Drain the write buffers. */
176 mcr p15, 0, r0, c2, c0, 0 /* Set Translation Table Base */
177 mcr p15, 0, r0, c8, c7, 0 /* Invalidate TLBs */
179 /* Set the Domain Access register. Very important! */
180 mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
181 mcr p15, 0, r0, c3, c0, 0
187 mcr p15, 0, r0, c1, c0, 0
190 * Ensure that the coprocessor has finished turning on the MMU.
192 mrc p15, 0, r0, c2, c0, 0 /* Read an arbitrary value. */
193 mov r0, r0 /* Stall until read completes. */
196 * Jump to start in locore.S, which in turn will call initarm and main.
198 ldr pc, Lstart /* Jump to start (flushes pipeline). */
206 /* Put the temporary L1 translation table at the end of SDRAM. */
207 .word KERNEL_BASE_phys + MEMSIZE_BYTES - L1_TABLE_SIZE
209 /* What we want to have the CPSR be when we jump to start. */
210 .word CPU_CONTROL_MMU_ENABLE | \
211 CPU_CONTROL_AFLT_ENABLE | \
212 CPU_CONTROL_DC_ENABLE | \
213 CPU_CONTROL_WBUF_ENABLE | \
214 CPU_CONTROL_32BP_ENABLE | \
215 CPU_CONTROL_32BD_ENABLE | \
216 CPU_CONTROL_LABT_ENABLE | \
217 CPU_CONTROL_SYST_ENABLE | \
218 CPU_CONTROL_IC_ENABLE
220 /* We'll modify va and pa at run time so we can use relocatable addresses. */
221 #define MMU_INIT(va,pa,n_sec,attr) \
228 /* Map SDRAM where we're executing from VA==PA, read-only */
229 MMU_INIT(KERNEL_BASE_phys, KERNEL_BASE_phys,
231 L1_S_PROTO | L1_S_AP(AP_KR))
232 /* Map KERNEL_BASE VA to SDRAM PA, write-back cacheable */
233 MMU_INIT(KERNEL_BASE, KERNEL_BASE_phys,
234 (MEMSIZE_BYTES + L1_S_SIZE - 1) / L1_S_SIZE,
235 L1_S_PROTO | L1_S_AP(AP_KRW) | L1_S_B | L1_S_C)
236 /* Map TIPB VA==PA so peripherals will work. */
237 MMU_INIT(OMAP_TIPB_PBASE, OMAP_TIPB_PBASE,
238 (OMAP_TIPB_SIZE + L1_S_SIZE - 1) / L1_S_SIZE,
239 L1_S_PROTO | L1_S_AP(AP_KRW))