ixm1200_start.S revision 1.2 1 1.2 ichiro /* $NetBSD: ixm1200_start.S,v 1.2 2002/07/21 14:26:05 ichiro Exp $ */
2 1.1 ichiro
3 1.1 ichiro /*
4 1.1 ichiro * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 ichiro * All rights reserved.
6 1.1 ichiro *
7 1.1 ichiro * This code is derived from software contributed to The NetBSD Foundation
8 1.1 ichiro * by Ichiro FUKUHARA and Naoto Shimazaki.
9 1.1 ichiro *
10 1.1 ichiro * This code is derived from software contributed to The NetBSD Foundation
11 1.1 ichiro * by Jason R. Thorpe.
12 1.1 ichiro *
13 1.1 ichiro * Redistribution and use in source and binary forms, with or without
14 1.1 ichiro * modification, are permitted provided that the following conditions
15 1.1 ichiro * are met:
16 1.1 ichiro * 1. Redistributions of source code must retain the above copyright
17 1.1 ichiro * notice, this list of conditions and the following disclaimer.
18 1.1 ichiro * 2. Redistributions in binary form must reproduce the above copyright
19 1.1 ichiro * notice, this list of conditions and the following disclaimer in the
20 1.1 ichiro * documentation and/or other materials provided with the distribution.
21 1.1 ichiro * 3. All advertising materials mentioning features or use of this software
22 1.1 ichiro * must display the following acknowledgement:
23 1.1 ichiro * This product includes software developed by the NetBSD
24 1.1 ichiro * Foundation, Inc. and its contributors.
25 1.1 ichiro * 4. Neither the name of The NetBSD Foundation nor the names of its
26 1.1 ichiro * contributors may be used to endorse or promote products derived
27 1.1 ichiro * from this software without specific prior written permission.
28 1.1 ichiro *
29 1.1 ichiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 1.1 ichiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 1.1 ichiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 1.1 ichiro * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 1.1 ichiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 1.1 ichiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 1.1 ichiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 1.1 ichiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 1.1 ichiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 1.1 ichiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 1.1 ichiro * POSSIBILITY OF SUCH DAMAGE.
40 1.1 ichiro */
41 1.1 ichiro
42 1.1 ichiro #include "assym.h"
43 1.1 ichiro
44 1.1 ichiro #include <arm/asm.h>
45 1.1 ichiro #include <arm/armreg.h>
46 1.1 ichiro #include <arm/arm32/pte.h>
47 1.1 ichiro
48 1.1 ichiro .section .start,"ax",%progbits
49 1.1 ichiro
50 1.1 ichiro .global _C_LABEL(ixm1200_start)
51 1.1 ichiro _C_LABEL(ixm1200_start):
52 1.1 ichiro /*
53 1.1 ichiro * Disable IRQ and FIQ
54 1.1 ichiro */
55 1.1 ichiro mrs r3, cpsr_all
56 1.1 ichiro orr r1, r3, #(I32_bit | F32_bit)
57 1.1 ichiro msr cpsr_all, r1
58 1.1 ichiro
59 1.1 ichiro /*
60 1.1 ichiro * Setup coprocessor 15.
61 1.1 ichiro *
62 1.1 ichiro * We assume we've been loaded VA == PA, or that the MMU is
63 1.1 ichiro * disabled. We will go ahead and disable the MMU here
64 1.1 ichiro * so that we don't have to worry about flushing caches, etc.
65 1.1 ichiro */
66 1.1 ichiro
67 1.1 ichiro /* CONTROL_CP15 */
68 1.1 ichiro mrc p15, 0, r0, c1, c0 ,0 /* read ctrl */
69 1.1 ichiro bic r0, r0, #CPU_CONTROL_MMU_ENABLE
70 1.1 ichiro bic r0, r0, #CPU_CONTROL_AFLT_ENABLE
71 1.1 ichiro orr r0, r0, #CPU_CONTROL_DC_ENABLE
72 1.1 ichiro orr r0, r0, #CPU_CONTROL_WBUF_ENABLE
73 1.1 ichiro bic r0, r0, #CPU_CONTROL_BEND_ENABLE
74 1.1 ichiro orr r0, r0, #CPU_CONTROL_SYST_ENABLE
75 1.1 ichiro bic r0, r0, #CPU_CONTROL_ROM_ENABLE
76 1.1 ichiro orr r0, r0, #CPU_CONTROL_IC_ENABLE
77 1.1 ichiro bic r0, r0, #CPU_CONTROL_VECRELOC
78 1.1 ichiro mcr p15, 0, r0, c1, c0 ,0 /* write ctrl */
79 1.1 ichiro
80 1.1 ichiro nop
81 1.1 ichiro nop
82 1.1 ichiro nop
83 1.1 ichiro
84 1.1 ichiro /* TRANSLATION_TABLE_BASE */
85 1.1 ichiro mov r0, #0
86 1.1 ichiro mcr p15, 0, r0, c2, c0 ,0 /* write trans table base */
87 1.1 ichiro
88 1.1 ichiro /* DOMAIN_ACCESS_CONTROL */
89 1.1 ichiro mov r0, #0x00000001 /* use domain 0 as client */
90 1.1 ichiro mcr p15, 0, r0, c3, c0 ,0 /* write domain */
91 1.1 ichiro
92 1.1 ichiro /* CACHE_CONTROL_OPERATIONS */
93 1.1 ichiro mrc p15, 0, r0, c7, c7 ,0 /* flush D and I cache */
94 1.1 ichiro mrc p15, 0, r0, c7, c10 ,4 /* drain write buffer */
95 1.1 ichiro
96 1.1 ichiro /* TLB_OPERATIONS */
97 1.1 ichiro mcr p15, 0, r0, c8, c7 ,0 /* flush D and I TLB */
98 1.1 ichiro
99 1.1 ichiro /* READ_BUFFER_OPERATIONS */
100 1.1 ichiro mcr p15, 0, r0, c9, c0 ,0 /* flush all entries */
101 1.1 ichiro mcr p15, 0, r0, c9, c0 ,4 /* disable user mode MCR access */
102 1.1 ichiro
103 1.1 ichiro /* PROCESS_ID_VIRTUAL_ADDR_MAPPING */
104 1.1 ichiro mov r0, #0
105 1.1 ichiro mcr p15, 0, r0, c13, c0 ,0 /* process ID 0
106 1.1 ichiro
107 1.1 ichiro /* BREAKPOINT_DEBUG_SUPPORT */
108 1.1 ichiro mov r0, #0
109 1.1 ichiro mcr p15, 0, r0, c15, c0 ,0 /* DBAR = 0 */
110 1.1 ichiro mcr p15, 0, r0, c15, c1 ,0 /* DBVR = 0 */
111 1.1 ichiro mcr p15, 0, r0, c15, c2 ,0 /* DBMR = 0 */
112 1.1 ichiro mcr p15, 0, r0, c15, c3 ,0 /* DBCR = 0 (never watch) */
113 1.1 ichiro mcr p15, 0, r0, c15, c8 ,0 /* IBCR = 0 (never watch) */
114 1.1 ichiro
115 1.1 ichiro /*
116 1.1 ichiro * We want to construct a memory map that maps us
117 1.1 ichiro * VA == PA (SDRAM at 0xc0000000). We create these mappings
118 1.1 ichiro * uncached and unbuffered to be safe.
119 1.1 ichiro *
120 1.1 ichiro * We also want to map the various devices we want to
121 1.1 ichiro * talk to VA == PA during bootstrap.
122 1.1 ichiro *
123 1.1 ichiro * We also want to map the v0xf0000000 == p0x90000000
124 1.1 ichiro * to output eary bootstrup messages to the console.
125 1.1 ichiro *
126 1.1 ichiro * We just use section mappings for all of this to make it easy.
127 1.1 ichiro *
128 1.1 ichiro * We will put the L1 table to do all this at c01fc000
129 1.1 ichiro * where is our KERNEL_TEXT_BASE - sizeof(L1 table).
130 1.1 ichiro */
131 1.1 ichiro
132 1.1 ichiro /*
133 1.1 ichiro * Step 1: Map the entire address space VA == PA.
134 1.1 ichiro */
135 1.1 ichiro ldr r0, Ltable
136 1.1 ichiro mov r1, #(L1_TABLE_SIZE / 4) /* 4096 entry */
137 1.1 ichiro mov r2, #(L1_S_SIZE) /* 1MB / section */
138 1.1 ichiro mov r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
139 1.1 ichiro orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
140 1.1 ichiro 1:
141 1.1 ichiro str r3, [r0], #4
142 1.1 ichiro add r3, r3, r2
143 1.1 ichiro subs r1, r1, #1
144 1.1 ichiro bgt 1b
145 1.1 ichiro
146 1.1 ichiro /*
147 1.1 ichiro * Step 2: Map VA 0xf0000000->0xf0100000 to PA 0x90000000->0x90100000.
148 1.1 ichiro */
149 1.1 ichiro ldr r0, Ltable
150 1.1 ichiro add r0, r0, #(0xf00 * 4) /* offset to 0xf0000000 */
151 1.1 ichiro mov r3, #0x90000000
152 1.1 ichiro add r3, r3, #0x00100000 /* set 0x90100000 to r3 */
153 1.1 ichiro orr r3, r3, #(L1_S_AP(AP_KRW)) /* kernel read/write */
154 1.1 ichiro orr r3, r3, #(L1_TYPE_S) /* L1 entry is section */
155 1.1 ichiro str r3, [r0]
156 1.1 ichiro
157 1.1 ichiro /* OK! Page table is set up. Give it to the CPU. */
158 1.1 ichiro ldr r0, Ltable
159 1.1 ichiro mcr p15, 0, r0, c2, c0 ,0 /* write trans table base */
160 1.1 ichiro mcr p15, 0, r0, c8, c7 ,0 /* flush D and I TLB */
161 1.1 ichiro
162 1.1 ichiro /* Get ready to jump to the "real" kernel entry point... */
163 1.1 ichiro ldr r0, Lstart
164 1.1 ichiro
165 1.1 ichiro /* OK, let's enable the MMU. */
166 1.1 ichiro mrc p15, 0, r1, c1, c0 ,0 /* read ctrl */
167 1.1 ichiro orr r1, r1, #CPU_CONTROL_MMU_ENABLE
168 1.1 ichiro mcr p15, 0, r1, c1, c0 ,0 /* write ctrl */
169 1.1 ichiro
170 1.1 ichiro nop
171 1.1 ichiro nop
172 1.1 ichiro nop
173 1.1 ichiro
174 1.1 ichiro /* CPWAIT sequence to make sure the MMU is on... */
175 1.1 ichiro mrc p15, 0, r2, c2, c0, 0 /* arbitrary read of CP15 */
176 1.1 ichiro mov r2, r2 /* force it to complete */
177 1.1 ichiro mov pc, r0 /* leap to kernel entry point! */
178 1.1 ichiro
179 1.1 ichiro Lstart:
180 1.1 ichiro .word start
181 1.1 ichiro
182 1.1 ichiro Ltable:
183 1.1 ichiro .word 0xc0200000 - 0x4000 /* our KERNEL_TEXT_BASE - 16KB */
184 1.2 ichiro
185 1.2 ichiro /* end of ixm1200_start.S */
186