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