armadillo9_start.S revision 1.3.12.2 1 1.3.12.2 yamt /* $NetBSD: armadillo9_start.S,v 1.3.12.2 2006/06/21 14:50:32 yamt Exp $ */
2 1.3.12.2 yamt
3 1.3.12.2 yamt /*
4 1.3.12.2 yamt * Copyright (c) 2003
5 1.3.12.2 yamt * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
6 1.3.12.2 yamt * All rights reserved.
7 1.3.12.2 yamt *
8 1.3.12.2 yamt * Redistribution and use in source and binary forms, with or without
9 1.3.12.2 yamt * modification, are permitted provided that the following conditions
10 1.3.12.2 yamt * are met:
11 1.3.12.2 yamt * 1. Redistributions of source code must retain the above copyright
12 1.3.12.2 yamt * notice, this list of conditions and the following disclaimer.
13 1.3.12.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
14 1.3.12.2 yamt * notice, this list of conditions and the following disclaimer in the
15 1.3.12.2 yamt * documentation and/or other materials provided with the distribution.
16 1.3.12.2 yamt * 3. All advertising materials mentioning features or use of this software
17 1.3.12.2 yamt * must display the following acknowledgement:
18 1.3.12.2 yamt * This product includes software developed by Ichiro FUKUHARA.
19 1.3.12.2 yamt * 4. The name of the company nor the name of the author may be used to
20 1.3.12.2 yamt * endorse or promote products derived from this software without specific
21 1.3.12.2 yamt * prior written permission.
22 1.3.12.2 yamt *
23 1.3.12.2 yamt * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
24 1.3.12.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.3.12.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.3.12.2 yamt * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
27 1.3.12.2 yamt * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.3.12.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.3.12.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.3.12.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.3.12.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.3.12.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.3.12.2 yamt * SUCH DAMAGE.
34 1.3.12.2 yamt */
35 1.3.12.2 yamt
36 1.3.12.2 yamt #include <machine/asm.h>
37 1.3.12.2 yamt #include <arm/armreg.h>
38 1.3.12.2 yamt #include <arm/arm32/pte.h>
39 1.3.12.2 yamt #include "epcom.h"
40 1.3.12.2 yamt
41 1.3.12.2 yamt .section .start,"ax",%progbits
42 1.3.12.2 yamt
43 1.3.12.2 yamt .global _C_LABEL(armadillo9_start)
44 1.3.12.2 yamt _C_LABEL(armadillo9_start):
45 1.3.12.2 yamt
46 1.3.12.2 yamt /* make sure svc mode and all fiqs&irqs disabled */
47 1.3.12.2 yamt mov r0, #(PSR_SVC32_MODE | I32_bit | F32_bit)
48 1.3.12.2 yamt msr cpsr_c, r0
49 1.3.12.2 yamt
50 1.3.12.2 yamt /*
51 1.3.12.2 yamt * We will go ahead and disable the MMU here so that we don't
52 1.3.12.2 yamt * have to worry about flushing caches, etc.
53 1.3.12.2 yamt *
54 1.3.12.2 yamt * Note that we may not currently be running VA==PA, which means
55 1.3.12.2 yamt * we'll need to leap to the next insn after disabing the MMU.
56 1.3.12.2 yamt */
57 1.3.12.2 yamt adr r8, Lunmapped
58 1.3.12.2 yamt bic r8, r8, #0xff000000 /* clear upper 8 bits */
59 1.3.12.2 yamt orr r8, r8, #0xc0000000 /* OR in physical base address */
60 1.3.12.2 yamt
61 1.3.12.2 yamt /*
62 1.3.12.2 yamt * Setup coprocessor 15.
63 1.3.12.2 yamt */
64 1.3.12.2 yamt mrc p15, 0, r2, c1, c0, 0
65 1.3.12.2 yamt bic r2, r2, #CPU_CONTROL_MMU_ENABLE
66 1.3.12.2 yamt bic r2, r2, #CPU_CONTROL_DC_ENABLE
67 1.3.12.2 yamt bic r2, r2, #CPU_CONTROL_IC_ENABLE
68 1.3.12.2 yamt mcr p15, 0, r2, c1, c0, 0
69 1.3.12.2 yamt
70 1.3.12.2 yamt nop
71 1.3.12.2 yamt nop
72 1.3.12.2 yamt nop
73 1.3.12.2 yamt mov pc, r8 /* Heave-ho! */
74 1.3.12.2 yamt
75 1.3.12.2 yamt Lunmapped:
76 1.3.12.2 yamt /* set temporary stack pointer */
77 1.3.12.2 yamt ldr sp, Ltable
78 1.3.12.2 yamt
79 1.3.12.2 yamt #ifdef VERBOSE_INIT_ARM
80 1.3.12.2 yamt /* initialize UART */
81 1.3.12.2 yamt bl init_UART
82 1.3.12.2 yamt #endif
83 1.3.12.2 yamt /* copy bootparam */
84 1.3.12.2 yamt bl copy_bootparam
85 1.3.12.2 yamt
86 1.3.12.2 yamt /* copy myself to virtual address */
87 1.3.12.2 yamt bl copy_myself
88 1.3.12.2 yamt
89 1.3.12.2 yamt /*
90 1.3.12.2 yamt * We want to construct a memory map that maps us
91 1.3.12.2 yamt * VA==PA (SDRAM at 0xc0000000). We create these
92 1.3.12.2 yamt * mappings uncached and unbuffered to be safe.
93 1.3.12.2 yamt */
94 1.3.12.2 yamt /*
95 1.3.12.2 yamt * Step 1: Map the entire address space VA==PA.
96 1.3.12.2 yamt */
97 1.3.12.2 yamt adr r4, Ltable
98 1.3.12.2 yamt ldr r0, [r4] /* r0 = &l1table */
99 1.3.12.2 yamt mov r1, #(L1_TABLE_SIZE / 4) /* 4096 entry */
100 1.3.12.2 yamt mov r2, #(L1_S_SIZE) /* 1MB / section */
101 1.3.12.2 yamt mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
102 1.3.12.2 yamt orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
103 1.3.12.2 yamt 1:
104 1.3.12.2 yamt str r3, [r0], #0x04
105 1.3.12.2 yamt add r3, r3, r2
106 1.3.12.2 yamt subs r1, r1, #1
107 1.3.12.2 yamt bgt 1b
108 1.3.12.2 yamt
109 1.3.12.2 yamt /*
110 1.3.12.2 yamt * Step 2: Map VA 0xf0000000->0xf00fffff to PA 0x80000000->0x800fffff.
111 1.3.12.2 yamt */
112 1.3.12.2 yamt ldr r0, [r4]
113 1.3.12.2 yamt add r0, r0, #(0xf00 * 4) /* offset to 0xf0000000 */
114 1.3.12.2 yamt mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
115 1.3.12.2 yamt orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
116 1.3.12.2 yamt orr r3, r3, #0x80000000
117 1.3.12.2 yamt str r3, [r0], #4
118 1.3.12.2 yamt
119 1.3.12.2 yamt /*
120 1.3.12.2 yamt * Step 3: Map VA 0xf0100000->0xf02fffff to PA 0x80800000->0x809fffff.
121 1.3.12.2 yamt */
122 1.3.12.2 yamt mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
123 1.3.12.2 yamt orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
124 1.3.12.2 yamt orr r3, r3, #0x80000000
125 1.3.12.2 yamt orr r3, r3, #0x00800000
126 1.3.12.2 yamt str r3, [r0], #0x4
127 1.3.12.2 yamt add r3, r3, r2
128 1.3.12.2 yamt str r3, [r0], #0x4
129 1.3.12.2 yamt
130 1.3.12.2 yamt /* OK! Page table is set up. Give it to the CPU. */
131 1.3.12.2 yamt adr r0, Ltable
132 1.3.12.2 yamt ldr r0, [r0]
133 1.3.12.2 yamt mcr p15, 0, r0, c2, c0, 0
134 1.3.12.2 yamt
135 1.3.12.2 yamt /* Flush the old TLBs, just in case. */
136 1.3.12.2 yamt mcr p15, 0, r0, c8, c7, 0
137 1.3.12.2 yamt
138 1.3.12.2 yamt /* Set the Domain Access register. Very important! */
139 1.3.12.2 yamt mov r0, #1
140 1.3.12.2 yamt mcr p15, 0, r0, c3, c0, 0
141 1.3.12.2 yamt
142 1.3.12.2 yamt /* Get ready to jump to the "real" kernel entry point... */
143 1.3.12.2 yamt ldr r1, Lstart
144 1.3.12.2 yamt mov r1, r1 /* Make sure the load completes! */
145 1.3.12.2 yamt
146 1.3.12.2 yamt /* OK, let's enable the MMU. */
147 1.3.12.2 yamt mrc p15, 0, r2, c1, c0, 0
148 1.3.12.2 yamt orr r2, r2, #CPU_CONTROL_MMU_ENABLE
149 1.3.12.2 yamt mcr p15, 0, r2, c1, c0, 0
150 1.3.12.2 yamt
151 1.3.12.2 yamt nop
152 1.3.12.2 yamt nop
153 1.3.12.2 yamt nop
154 1.3.12.2 yamt
155 1.3.12.2 yamt /* CPWAIT sequence to make sure the MMU is on... */
156 1.3.12.2 yamt mrc p15, 0, r2, c2, c0, 0 /* arbitrary read of CP15 */
157 1.3.12.2 yamt mov r2, r2 /* force it to complete */
158 1.3.12.2 yamt mov pc, r1 /* leap to kernel entry point! */
159 1.3.12.2 yamt
160 1.3.12.2 yamt #define BOOTPARAM_ADDRESS 0xc0000100
161 1.3.12.2 yamt #define BOOTPARAM_SIZE 0x0f00
162 1.3.12.2 yamt
163 1.3.12.2 yamt Ltable:
164 1.3.12.2 yamt .word armadillo9_start - L1_TABLE_SIZE
165 1.3.12.2 yamt Lstart:
166 1.3.12.2 yamt .word start
167 1.3.12.2 yamt
168 1.3.12.2 yamt Lsection:
169 1.3.12.2 yamt .word .start
170 1.3.12.2 yamt .word 0xc0200000
171 1.3.12.2 yamt .word __bss_start
172 1.3.12.2 yamt
173 1.3.12.2 yamt Lbootparam_address:
174 1.3.12.2 yamt .word BOOTPARAM_ADDRESS
175 1.3.12.2 yamt
176 1.3.12.2 yamt copy_myself:
177 1.3.12.2 yamt stmfd sp!, {r0-r5, lr}
178 1.3.12.2 yamt adr r0, Lsection
179 1.3.12.2 yamt ldmia r0, {r1, r2, r4} /* r1: kernel(load) start address */
180 1.3.12.2 yamt /* r2: kernel(virtual) start address */
181 1.3.12.2 yamt /* r3: kernel size */
182 1.3.12.2 yamt sub r3, r4, r2 /* r4: kernel(virtual) end address */
183 1.3.12.2 yamt add r5, r1, r3 /* r5: kernel(load) end address */
184 1.3.12.2 yamt #ifdef VERBOSE_INIT_ARM
185 1.3.12.2 yamt adr r0, Lmsg1 /* "copy kernel from " */
186 1.3.12.2 yamt bl print_str
187 1.3.12.2 yamt bl print_r1
188 1.3.12.2 yamt adr r0, Lmsg2 /* " to " */
189 1.3.12.2 yamt bl print_str
190 1.3.12.2 yamt bl print_r2
191 1.3.12.2 yamt adr r0, Lmsg3 /* " size " */
192 1.3.12.2 yamt bl print_str
193 1.3.12.2 yamt bl print_r3
194 1.3.12.2 yamt bl print_cr
195 1.3.12.2 yamt #endif
196 1.3.12.2 yamt 1:
197 1.3.12.2 yamt ldr r0, [r5], #-4
198 1.3.12.2 yamt str r0, [r4], #-4
199 1.3.12.2 yamt cmp r5, r1
200 1.3.12.2 yamt bge 1b
201 1.3.12.2 yamt ldmfd sp!, {r0-r5, pc}
202 1.3.12.2 yamt
203 1.3.12.2 yamt copy_bootparam:
204 1.3.12.2 yamt stmfd sp!, {r0-r3, lr}
205 1.3.12.2 yamt mov r1, #BOOTPARAM_SIZE
206 1.3.12.2 yamt ldr r2, Lbootparam_address
207 1.3.12.2 yamt adr r3, _C_LABEL(bootparam)
208 1.3.12.2 yamt #ifdef VERBOSE_INIT_ARM
209 1.3.12.2 yamt adr r0, Lmsg0 /* "copy bootparam from " */
210 1.3.12.2 yamt bl print_str
211 1.3.12.2 yamt bl print_r2
212 1.3.12.2 yamt adr r0, Lmsg2 /* " to " */
213 1.3.12.2 yamt bl print_str
214 1.3.12.2 yamt bl print_r3
215 1.3.12.2 yamt adr r0, Lmsg3 /* " size " */
216 1.3.12.2 yamt bl print_str
217 1.3.12.2 yamt bl print_r1
218 1.3.12.2 yamt bl print_cr
219 1.3.12.2 yamt #endif
220 1.3.12.2 yamt 1:
221 1.3.12.2 yamt ldr r0, [r2], #4
222 1.3.12.2 yamt str r0, [r3], #4
223 1.3.12.2 yamt subs r1, r1, #4
224 1.3.12.2 yamt bne 1b
225 1.3.12.2 yamt ldmfd sp!, {r0-r3, pc}
226 1.3.12.2 yamt
227 1.3.12.2 yamt #ifdef VERBOSE_INIT_ARM
228 1.3.12.2 yamt Lmsg0:
229 1.3.12.2 yamt .asciz "copy bootparam from "
230 1.3.12.2 yamt .align 0
231 1.3.12.2 yamt Lmsg1:
232 1.3.12.2 yamt .asciz "copy kernel from "
233 1.3.12.2 yamt .align 0
234 1.3.12.2 yamt Lmsg2:
235 1.3.12.2 yamt .asciz " to "
236 1.3.12.2 yamt .align 0
237 1.3.12.2 yamt Lmsg3:
238 1.3.12.2 yamt .asciz " size "
239 1.3.12.2 yamt .align 0
240 1.3.12.2 yamt
241 1.3.12.2 yamt #if NEPCOM > 0
242 1.3.12.2 yamt #define EP93XX_APB_UART1 0x808c0000
243 1.3.12.2 yamt #define EP93XX_APB_UART2 0x808d0000
244 1.3.12.2 yamt
245 1.3.12.2 yamt #ifndef CONUNIT
246 1.3.12.2 yamt #define CONUNIT 0
247 1.3.12.2 yamt #endif
248 1.3.12.2 yamt
249 1.3.12.2 yamt Lcomaddr:
250 1.3.12.2 yamt .word EP93XX_APB_UART1
251 1.3.12.2 yamt .word EP93XX_APB_UART2
252 1.3.12.2 yamt #endif
253 1.3.12.2 yamt
254 1.3.12.2 yamt init_UART:
255 1.3.12.2 yamt stmfd sp!, {r4-r5, lr}
256 1.3.12.2 yamt #if NEPCOM > 0
257 1.3.12.2 yamt ldr r4, Lcomaddr+(CONUNIT*4)
258 1.3.12.2 yamt ldr r5, [r4, #0x08]
259 1.3.12.2 yamt orr r5, r5, #0x10
260 1.3.12.2 yamt str r5, [r4, #0x08] /* enable FIFO */
261 1.3.12.2 yamt mov r5, #0x01
262 1.3.12.2 yamt str r5, [r4, #0x14] /* disable interrupt */
263 1.3.12.2 yamt #endif
264 1.3.12.2 yamt ldmfd sp!, {r4-r5, pc}
265 1.3.12.2 yamt
266 1.3.12.2 yamt print_char: /* char = r0 */
267 1.3.12.2 yamt stmfd sp!, {r4-r5, lr}
268 1.3.12.2 yamt #if NEPCOM > 0
269 1.3.12.2 yamt ldr r4, Lcomaddr+(CONUNIT*4)
270 1.3.12.2 yamt 1:
271 1.3.12.2 yamt ldr r5, [r4, #0x18]
272 1.3.12.2 yamt tst r5, #0x20 /* check TXFF */
273 1.3.12.2 yamt bne 1b
274 1.3.12.2 yamt str r0, [r4, #0x00]
275 1.3.12.2 yamt #endif
276 1.3.12.2 yamt ldmfd sp!, {r4-r5, pc}
277 1.3.12.2 yamt
278 1.3.12.2 yamt print_cr:
279 1.3.12.2 yamt stmfd sp!, {r0, lr}
280 1.3.12.2 yamt #if NEPCOM > 0
281 1.3.12.2 yamt mov r0, #0x0d /* cr */
282 1.3.12.2 yamt bl print_char
283 1.3.12.2 yamt mov r0, #0x0a /* lf */
284 1.3.12.2 yamt bl print_char
285 1.3.12.2 yamt #endif
286 1.3.12.2 yamt ldmfd sp!, {r0, pc}
287 1.3.12.2 yamt
288 1.3.12.2 yamt print_str:
289 1.3.12.2 yamt stmfd sp!, {r0, r4, lr}
290 1.3.12.2 yamt #if NEPCOM > 0
291 1.3.12.2 yamt mov r4, r0
292 1.3.12.2 yamt 1:
293 1.3.12.2 yamt ldrb r0, [r4], #1
294 1.3.12.2 yamt cmp r0, #0
295 1.3.12.2 yamt beq 2f
296 1.3.12.2 yamt bl print_char
297 1.3.12.2 yamt b 1b
298 1.3.12.2 yamt 2:
299 1.3.12.2 yamt #endif
300 1.3.12.2 yamt ldmfd sp!, {r0, r4, pc}
301 1.3.12.2 yamt
302 1.3.12.2 yamt print_r3:
303 1.3.12.2 yamt stmfd sp!, {r0, r3-r6, lr}
304 1.3.12.2 yamt #if NEPCOM > 0
305 1.3.12.2 yamt mov r4, #28
306 1.3.12.2 yamt mov r5, #0xf
307 1.3.12.2 yamt 1:
308 1.3.12.2 yamt and r6, r5, r3, ROR r4
309 1.3.12.2 yamt cmp r6, #10
310 1.3.12.2 yamt addlt r0, r6, #'0'
311 1.3.12.2 yamt addge r0, r6, #('a' - 0x0a)
312 1.3.12.2 yamt bl print_char
313 1.3.12.2 yamt subs r4, r4, #4
314 1.3.12.2 yamt bge 1b
315 1.3.12.2 yamt #endif
316 1.3.12.2 yamt ldmfd sp!, {r0, r3-r6, pc}
317 1.3.12.2 yamt
318 1.3.12.2 yamt #define print_register(reg) \
319 1.3.12.2 yamt stmfd sp!, {r3, lr} ;\
320 1.3.12.2 yamt mov r3, reg ;\
321 1.3.12.2 yamt bl print_r3 ;\
322 1.3.12.2 yamt ldmfd sp!, {r3, pc}
323 1.3.12.2 yamt
324 1.3.12.2 yamt print_r0:
325 1.3.12.2 yamt print_register(r0)
326 1.3.12.2 yamt
327 1.3.12.2 yamt print_r1:
328 1.3.12.2 yamt print_register(r1)
329 1.3.12.2 yamt
330 1.3.12.2 yamt print_r2:
331 1.3.12.2 yamt print_register(r2)
332 1.3.12.2 yamt #endif
333 1.3.12.2 yamt
334 1.3.12.2 yamt .global _C_LABEL(bootparam)
335 1.3.12.2 yamt _C_LABEL(bootparam):
336 1.3.12.2 yamt .space BOOTPARAM_SIZE
337