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