1 /* $NetBSD: armadillo9_start.S,v 1.3 2006/02/13 12:24:21 hamajima Exp $ */
5 * Ichiro FUKUHARA <ichiro@ichiro.org>.
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.
17 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <machine/asm.h>
31 #include <arm/armreg.h>
32 #include <arm/arm32/pte.h>
35 .section .start,"ax",%progbits
37 .global _C_LABEL(armadillo9_start)
38 _C_LABEL(armadillo9_start):
40 /* make sure svc mode and all fiqs&irqs disabled */
41 mov r0, #(PSR_SVC32_MODE | I32_bit | F32_bit)
45 * We will go ahead and disable the MMU here so that we don't
46 * have to worry about flushing caches, etc.
48 * Note that we may not currently be running VA==PA, which means
49 * we'll need to leap to the next insn after disabing the MMU.
52 bic r8, r8, #0xff000000 /* clear upper 8 bits */
53 orr r8, r8, #0xc0000000 /* OR in physical base address */
56 * Setup coprocessor 15.
58 mrc p15, 0, r2, c1, c0, 0
59 bic r2, r2, #CPU_CONTROL_MMU_ENABLE
60 bic r2, r2, #CPU_CONTROL_DC_ENABLE
61 bic r2, r2, #CPU_CONTROL_IC_ENABLE
62 mcr p15, 0, r2, c1, c0, 0
67 mov pc, r8 /* Heave-ho! */
70 /* set temporary stack pointer */
73 #ifdef VERBOSE_INIT_ARM
80 /* copy myself to virtual address */
84 * We want to construct a memory map that maps us
85 * VA==PA (SDRAM at 0xc0000000). We create these
86 * mappings uncached and unbuffered to be safe.
89 * Step 1: Map the entire address space VA==PA.
92 ldr r0, [r4] /* r0 = &l1table */
93 mov r1, #(L1_TABLE_SIZE / 4) /* 4096 entry */
94 mov r2, #(L1_S_SIZE) /* 1MB / section */
95 mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
96 orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
104 * Step 2: Map VA 0xf0000000->0xf00fffff to PA 0x80000000->0x800fffff.
107 add r0, r0, #(0xf00 * 4) /* offset to 0xf0000000 */
108 mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
109 orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
110 orr r3, r3, #0x80000000
114 * Step 3: Map VA 0xf0100000->0xf02fffff to PA 0x80800000->0x809fffff.
116 mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
117 orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
118 orr r3, r3, #0x80000000
119 orr r3, r3, #0x00800000
124 /* OK! Page table is set up. Give it to the CPU. */
127 mcr p15, 0, r0, c2, c0, 0
129 /* Flush the old TLBs, just in case. */
130 mcr p15, 0, r0, c8, c7, 0
132 /* Set the Domain Access register. Very important! */
134 mcr p15, 0, r0, c3, c0, 0
136 /* Get ready to jump to the "real" kernel entry point... */
138 mov r1, r1 /* Make sure the load completes! */
140 /* OK, let's enable the MMU. */
141 mrc p15, 0, r2, c1, c0, 0
142 orr r2, r2, #CPU_CONTROL_MMU_ENABLE
143 mcr p15, 0, r2, c1, c0, 0
149 /* CPWAIT sequence to make sure the MMU is on... */
150 mrc p15, 0, r2, c2, c0, 0 /* arbitrary read of CP15 */
151 mov r2, r2 /* force it to complete */
152 mov pc, r1 /* leap to kernel entry point! */
154 #define BOOTPARAM_ADDRESS 0xc0000100
155 #define BOOTPARAM_SIZE 0x0f00
158 .word armadillo9_start - L1_TABLE_SIZE
168 .word BOOTPARAM_ADDRESS
171 stmfd sp!, {r0-r5, lr}
173 ldmia r0, {r1, r2, r4} /* r1: kernel(load) start address */
174 /* r2: kernel(virtual) start address */
175 /* r3: kernel size */
176 sub r3, r4, r2 /* r4: kernel(virtual) end address */
177 add r5, r1, r3 /* r5: kernel(load) end address */
178 #ifdef VERBOSE_INIT_ARM
179 adr r0, Lmsg1 /* "copy kernel from " */
182 adr r0, Lmsg2 /* " to " */
185 adr r0, Lmsg3 /* " size " */
195 ldmfd sp!, {r0-r5, pc}
198 stmfd sp!, {r0-r3, lr}
199 mov r1, #BOOTPARAM_SIZE
200 ldr r2, Lbootparam_address
201 adr r3, _C_LABEL(bootparam)
202 #ifdef VERBOSE_INIT_ARM
203 adr r0, Lmsg0 /* "copy bootparam from " */
206 adr r0, Lmsg2 /* " to " */
209 adr r0, Lmsg3 /* " size " */
219 ldmfd sp!, {r0-r3, pc}
221 #ifdef VERBOSE_INIT_ARM
223 .asciz "copy bootparam from "
226 .asciz "copy kernel from "
236 #define EP93XX_APB_UART1 0x808c0000
237 #define EP93XX_APB_UART2 0x808d0000
244 .word EP93XX_APB_UART1
245 .word EP93XX_APB_UART2
249 stmfd sp!, {r4-r5, lr}
251 ldr r4, Lcomaddr+(CONUNIT*4)
254 str r5, [r4, #0x08] /* enable FIFO */
256 str r5, [r4, #0x14] /* disable interrupt */
258 ldmfd sp!, {r4-r5, pc}
260 print_char: /* char = r0 */
261 stmfd sp!, {r4-r5, lr}
263 ldr r4, Lcomaddr+(CONUNIT*4)
266 tst r5, #0x20 /* check TXFF */
270 ldmfd sp!, {r4-r5, pc}
275 mov r0, #0x0d /* cr */
277 mov r0, #0x0a /* lf */
283 stmfd sp!, {r0, r4, lr}
294 ldmfd sp!, {r0, r4, pc}
297 stmfd sp!, {r0, r3-r6, lr}
302 and r6, r5, r3, ROR r4
305 addge r0, r6, #('a' - 0x0a)
310 ldmfd sp!, {r0, r3-r6, pc}
312 #define print_register(reg) \
313 stmfd sp!, {r3, lr} ;\
328 .global _C_LABEL(bootparam)
330 .space BOOTPARAM_SIZE