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