tsarm_start.S revision 1.5 1 1.5 kenh /* $NetBSD: tsarm_start.S,v 1.5 2008/12/14 03:00:59 kenh Exp $ */
2 1.1 joff
3 1.1 joff /*
4 1.1 joff * Copyright (c) 2003
5 1.1 joff * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
6 1.1 joff * All rights reserved.
7 1.1 joff *
8 1.1 joff * Redistribution and use in source and binary forms, with or without
9 1.1 joff * modification, are permitted provided that the following conditions
10 1.1 joff * are met:
11 1.1 joff * 1. Redistributions of source code must retain the above copyright
12 1.1 joff * notice, this list of conditions and the following disclaimer.
13 1.1 joff * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 joff * notice, this list of conditions and the following disclaimer in the
15 1.1 joff * documentation and/or other materials provided with the distribution.
16 1.1 joff * 3. All advertising materials mentioning features or use of this software
17 1.1 joff * must display the following acknowledgement:
18 1.1 joff * This product includes software developed by Ichiro FUKUHARA.
19 1.1 joff * 4. The name of the company nor the name of the author may be used to
20 1.1 joff * endorse or promote products derived from this software without specific
21 1.1 joff * prior written permission.
22 1.1 joff *
23 1.1 joff * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
24 1.1 joff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 joff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 joff * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
27 1.1 joff * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 joff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 joff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 joff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 joff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 joff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 joff * SUCH DAMAGE.
34 1.1 joff */
35 1.1 joff #include <machine/asm.h>
36 1.1 joff #include <arm/armreg.h>
37 1.1 joff #include <arm/arm32/pte.h>
38 1.1 joff
39 1.1 joff #include <arm/ep93xx/ep93xxreg.h>
40 1.1 joff
41 1.1 joff .section .start,"ax",%progbits
42 1.1 joff
43 1.1 joff .global _C_LABEL(ts7xxx_start)
44 1.1 joff _C_LABEL(ts7xxx_start):
45 1.1 joff
46 1.1 joff /*
47 1.1 joff * We will go ahead and disable the MMU here so that we don't
48 1.1 joff * have to worry about flushing caches, etc.
49 1.1 joff *
50 1.1 joff * Note that we may not currently be running VA==PA, which means
51 1.1 joff * we'll need to leap to the next insn after disabing the MMU.
52 1.1 joff */
53 1.1 joff adr r8, Lunmapped
54 1.1 joff bic r8, r8, #0xff000000 /* clear upper 8 bits */
55 1.1 joff
56 1.1 joff /*
57 1.1 joff * Setup coprocessor 15.
58 1.1 joff */
59 1.1 joff mrc p15, 0, r2, c1, c0, 0
60 1.1 joff bic r2, r2, #CPU_CONTROL_MMU_ENABLE
61 1.1 joff mcr p15, 0, r2, c1, c0, 0
62 1.1 joff
63 1.1 joff nop
64 1.1 joff nop
65 1.1 joff nop
66 1.1 joff
67 1.1 joff mov pc, r8 /* Heave-ho! */
68 1.1 joff
69 1.1 joff Lunmapped:
70 1.1 joff /*
71 1.1 joff * We want to construct a memory map that maps us
72 1.1 joff * VA==PA (SDRAM at 0x00000000). We create these
73 1.1 joff * mappings uncached and unbuffered to be safe.
74 1.1 joff */
75 1.1 joff /*
76 1.1 joff * Step 1: Map the entire address space VA==PA.
77 1.1 joff */
78 1.1 joff adr r4, Ltable
79 1.1 joff ldr r0, [r4] /* r0 = &l1table */
80 1.1 joff
81 1.1 joff mov r1, #(L1_TABLE_SIZE / 4) /* 4096 entry */
82 1.1 joff mov r2, #(L1_S_SIZE) /* 1MB / section */
83 1.1 joff mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
84 1.1 joff orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
85 1.1 joff 1:
86 1.1 joff str r3, [r0], #0x04
87 1.1 joff add r3, r3, r2
88 1.1 joff subs r1, r1, #1
89 1.1 joff bgt 1b
90 1.1 joff
91 1.1 joff
92 1.1 joff /*
93 1.1 joff * Step 2: Map VA 0xc0000000->0xc07fffff to PA 0x00000000->0x007fffff.
94 1.1 joff */
95 1.1 joff ldr r0, [r4]
96 1.1 joff add r0, r0, #(0xc00 * 4) /* offset to 0xc00xxxxx */
97 1.1 joff
98 1.5 kenh mov r1, #0x8 /* 8MB */
99 1.1 joff mov r3, #(L1_S_AP(AP_KRW))
100 1.1 joff orr r3, r3, #(L1_TYPE_S)
101 1.1 joff 1:
102 1.1 joff str r3, [r0], #0x04
103 1.1 joff add r3, r3, r2
104 1.1 joff subs r1, r1, #1
105 1.1 joff bgt 1b
106 1.1 joff
107 1.1 joff /*
108 1.1 joff * Step 3: Map VA 0xf0000000->0xf0100000 to PA 0x80000000->0x80100000.
109 1.1 joff */
110 1.1 joff ldr r0, [r4]
111 1.1 joff
112 1.1 joff add r0, r0, #(0xf00 * 4) /* offset to 0xf0000000 */
113 1.1 joff mov r3, #0x80000000
114 1.1 joff orr r3, r3, #(L1_S_AP(AP_KRW))
115 1.1 joff orr r3, r3, #(L1_TYPE_S)
116 1.1 joff str r3, [r0], #4
117 1.1 joff
118 1.1 joff /*
119 1.1 joff * Step 4: Map VA 0xf0100000->0xf0300000 to PA 0x80800000->0x80a00000.
120 1.1 joff */
121 1.1 joff mov r3, #0x80000000
122 1.1 joff add r3, r3, #0x00800000
123 1.1 joff orr r3, r3, #(L1_S_AP(AP_KRW))
124 1.1 joff orr r3, r3, #(L1_TYPE_S)
125 1.1 joff str r3, [r0], #0x4
126 1.1 joff add r3, r3, r2
127 1.1 joff str r3, [r0], #0x4
128 1.1 joff
129 1.1 joff /*
130 1.1 joff * Step 5: Map VA 0xf0300000->0xf4300000 to PA 0x10000000->0x14000000.
131 1.1 joff */
132 1.1 joff mov r1, #0x40 /* 64MB */
133 1.1 joff mov r3, #(L1_S_AP(AP_KRW))
134 1.1 joff orr r3, r3, #(L1_TYPE_S)
135 1.1 joff orr r3, r3, #0x10000000
136 1.1 joff 1:
137 1.1 joff str r3, [r0], #0x04
138 1.1 joff add r3, r3, r2
139 1.1 joff subs r1, r1, #1
140 1.1 joff bgt 1b
141 1.1 joff
142 1.1 joff /*
143 1.1 joff * Step 6: Map VA 0xf4300000->0xf8300000 to PA 0x20000000->0x24000000.
144 1.1 joff */
145 1.1 joff mov r1, #0x40 /* 64MB */
146 1.1 joff mov r3, #(L1_S_AP(AP_KRW))
147 1.1 joff orr r3, r3, #(L1_TYPE_S)
148 1.1 joff orr r3, r3, #0x20000000
149 1.1 joff 1:
150 1.1 joff str r3, [r0], #0x04
151 1.1 joff add r3, r3, r2
152 1.1 joff subs r1, r1, #1
153 1.1 joff bgt 1b
154 1.1 joff
155 1.1 joff
156 1.1 joff /* OK! Page table is set up. Give it to the CPU. */
157 1.1 joff adr r0, Ltable
158 1.1 joff ldr r0, [r0]
159 1.1 joff mcr p15, 0, r0, c2, c0, 0
160 1.1 joff
161 1.1 joff /* Flush the old TLBs, just in case. */
162 1.1 joff mcr p15, 0, r0, c8, c7, 0
163 1.1 joff
164 1.1 joff /* Set the Domain Access register. Very important! */
165 1.1 joff mov r0, #1
166 1.1 joff mcr p15, 0, r0, c3, c0, 0
167 1.1 joff
168 1.1 joff /* Get ready to jump to the "real" kernel entry point... */
169 1.1 joff ldr r1, Lstart
170 1.1 joff mov r1, r1 /* Make sure the load completes! */
171 1.1 joff
172 1.1 joff /* OK, let's enable the MMU. */
173 1.1 joff mrc p15, 0, r2, c1, c0, 0
174 1.1 joff orr r2, r2, #CPU_CONTROL_MMU_ENABLE
175 1.1 joff mcr p15, 0, r2, c1, c0, 0
176 1.1 joff
177 1.1 joff nop
178 1.1 joff nop
179 1.1 joff nop
180 1.1 joff
181 1.1 joff /* CPWAIT sequence to make sure the MMU is on... */
182 1.1 joff mrc p15, 0, r2, c2, c0, 0 /* arbitrary read of CP15 */
183 1.1 joff mov r2, r2 /* force it to complete */
184 1.1 joff mov pc, r1 /* leap to kernel entry point! */
185 1.1 joff
186 1.1 joff Ltable:
187 1.1 joff .word 0x4000
188 1.1 joff
189 1.1 joff Lstart:
190 1.1 joff .word start
191