mmnet_start.S revision 1.1.2.2 1 1.1.2.2 yamt /* $NetBSD: mmnet_start.S,v 1.1.2.2 2011/11/10 14:31:40 yamt Exp $ */
2 1.1.2.2 yamt /*
3 1.1.2.2 yamt * Copyright (C) 2005, 2006 WIDE Project and SOUM Corporation.
4 1.1.2.2 yamt * All rights reserved.
5 1.1.2.2 yamt *
6 1.1.2.2 yamt * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
7 1.1.2.2 yamt * Corporation.
8 1.1.2.2 yamt *
9 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 yamt * modification, are permitted provided that the following conditions
11 1.1.2.2 yamt * are met:
12 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
17 1.1.2.2 yamt * 3. Neither the name of the project nor the name of SOUM Corporation
18 1.1.2.2 yamt * may be used to endorse or promote products derived from this software
19 1.1.2.2 yamt * without specific prior written permission.
20 1.1.2.2 yamt *
21 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
22 1.1.2.2 yamt * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
25 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
32 1.1.2.2 yamt */
33 1.1.2.2 yamt /*
34 1.1.2.2 yamt * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
35 1.1.2.2 yamt * Written by Hiroyuki Bessho for Genetec Corporation.
36 1.1.2.2 yamt *
37 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
38 1.1.2.2 yamt * modification, are permitted provided that the following conditions
39 1.1.2.2 yamt * are met:
40 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
41 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
42 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
43 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
44 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
45 1.1.2.2 yamt * 3. The name of Genetec Corporation may not be used to endorse or
46 1.1.2.2 yamt * promote products derived from this software without specific prior
47 1.1.2.2 yamt * written permission.
48 1.1.2.2 yamt *
49 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
50 1.1.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
53 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
60 1.1.2.2 yamt */
61 1.1.2.2 yamt
62 1.1.2.2 yamt #include <machine/asm.h>
63 1.1.2.2 yamt #include <arm/armreg.h>
64 1.1.2.2 yamt #include <arm/arm32/pte.h>
65 1.1.2.2 yamt #include <arm/arm32/pmap.h> /* for PMAP_DOMAIN_KERNEL */
66 1.1.2.2 yamt
67 1.1.2.2 yamt #ifndef SDRAM_START
68 1.1.2.2 yamt #define SDRAM_START 0x20000000
69 1.1.2.2 yamt #endif
70 1.1.2.2 yamt
71 1.1.2.2 yamt /*
72 1.1.2.2 yamt * CPWAIT -- Canonical method to wait for CP15 update.
73 1.1.2.2 yamt * NOTE: Clobbers the specified temp reg.
74 1.1.2.2 yamt * copied from arm/arm/cpufunc_asm_xscale.S
75 1.1.2.2 yamt * XXX: better be in a common header file.
76 1.1.2.2 yamt */
77 1.1.2.2 yamt #define CPWAIT_BRANCH \
78 1.1.2.2 yamt sub pc, pc, #4
79 1.1.2.2 yamt
80 1.1.2.2 yamt #define CPWAIT(tmp) \
81 1.1.2.2 yamt mrc p15, 0, tmp, c2, c0, 0 /* arbitrary read of CP15 */ ;\
82 1.1.2.2 yamt mov tmp, tmp /* wait for it to complete */ ;\
83 1.1.2.2 yamt CPWAIT_BRANCH /* branch to next insn */
84 1.1.2.2 yamt
85 1.1.2.2 yamt /*
86 1.1.2.2 yamt * Kernel start routine for the Propox MMnet 1002
87 1.1.2.2 yamt * this code is executed at the very beginning after the kernel is loaded
88 1.1.2.2 yamt * by U-Boot.
89 1.1.2.2 yamt */
90 1.1.2.2 yamt .text
91 1.1.2.2 yamt
92 1.1.2.2 yamt .global _C_LABEL(mmnet_start)
93 1.1.2.2 yamt _C_LABEL(mmnet_start):
94 1.1.2.2 yamt /*
95 1.1.2.2 yamt * Kernel is loaded in SDRAM (0x20200000), and is expected to run
96 1.1.2.2 yamt * in VA 0xc0200000..
97 1.1.2.2 yamt */
98 1.1.2.2 yamt /* save u-boot's args */
99 1.1.2.2 yamt adr r4, u_boot_args
100 1.1.2.2 yamt nop
101 1.1.2.2 yamt nop
102 1.1.2.2 yamt nop
103 1.1.2.2 yamt stmia r4!, {r0, r1, r2, r3}
104 1.1.2.2 yamt nop
105 1.1.2.2 yamt nop
106 1.1.2.2 yamt nop
107 1.1.2.2 yamt
108 1.1.2.2 yamt /* Calculate RAM size */
109 1.1.2.2 yamt adr r4, ram_size
110 1.1.2.2 yamt ldr r0, [r4]
111 1.1.2.2 yamt 0:
112 1.1.2.2 yamt add r3, r4, r0
113 1.1.2.2 yamt ldr r1, [r3]
114 1.1.2.2 yamt cmp r0, r1
115 1.1.2.2 yamt beq 2f
116 1.1.2.2 yamt 1:
117 1.1.2.2 yamt add r0, r0, r0 /* r0 <<= 1 */
118 1.1.2.2 yamt str r0, [r4]
119 1.1.2.2 yamt b 0b
120 1.1.2.2 yamt 2:
121 1.1.2.2 yamt mvn r1, r1 /* r1 ^= 0xffffffff */
122 1.1.2.2 yamt str r1, [r3]
123 1.1.2.2 yamt ldr r2, [r4]
124 1.1.2.2 yamt cmp r1, r2
125 1.1.2.2 yamt beq 3f
126 1.1.2.2 yamt str r0, [r3] /* restore */
127 1.1.2.2 yamt b 1b
128 1.1.2.2 yamt 3:
129 1.1.2.2 yamt str r0, [r4]
130 1.1.2.2 yamt
131 1.1.2.2 yamt /* build page table from scratch */
132 1.1.2.2 yamt ldr r0, Lstartup_pagetable /* pagetable */
133 1.1.2.2 yamt adr r4, mmu_init_table
134 1.1.2.2 yamt b 5f
135 1.1.2.2 yamt
136 1.1.2.2 yamt 4:
137 1.1.2.2 yamt str r3, [r0, r2]
138 1.1.2.2 yamt add r2, r2, #4
139 1.1.2.2 yamt add r3, r3, #(L1_S_SIZE)
140 1.1.2.2 yamt adds r1, r1, #-1
141 1.1.2.2 yamt bhi 4b
142 1.1.2.2 yamt 5:
143 1.1.2.2 yamt ldmia r4!, {r1, r2, r3} /* # of sections, PA|attr, VA */
144 1.1.2.2 yamt cmp r1, #0
145 1.1.2.2 yamt bne 4b
146 1.1.2.2 yamt
147 1.1.2.2 yamt mcr p15, 0, r0, c2, c0, 0 /* Set TTB */
148 1.1.2.2 yamt mcr p15, 0, r0, c8, c7, 0 /* Flush TLB */
149 1.1.2.2 yamt
150 1.1.2.2 yamt /* Set the Domain Access register. Very important! */
151 1.1.2.2 yamt mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
152 1.1.2.2 yamt mcr p15, 0, r0, c3, c0, 0
153 1.1.2.2 yamt
154 1.1.2.2 yamt /* Enable MMU */
155 1.1.2.2 yamt mrc p15, 0, r0, c1, c0, 0
156 1.1.2.2 yamt orr r0, r0, #CPU_CONTROL_SYST_ENABLE
157 1.1.2.2 yamt orr r0, r0, #CPU_CONTROL_MMU_ENABLE
158 1.1.2.2 yamt mcr p15, 0, r0, c1, c0, 0
159 1.1.2.2 yamt CPWAIT(r0)
160 1.1.2.2 yamt
161 1.1.2.2 yamt /* Jump to kernel code in TRUE VA */
162 1.1.2.2 yamt adr r0, Lstart
163 1.1.2.2 yamt ldr pc, [r0]
164 1.1.2.2 yamt
165 1.1.2.2 yamt Lstart:
166 1.1.2.2 yamt .word start
167 1.1.2.2 yamt
168 1.1.2.2 yamt #ifndef STARTUP_PAGETABLE_ADDR
169 1.1.2.2 yamt #define STARTUP_PAGETABLE_ADDR 0x20000000 /* aligned 16kByte */
170 1.1.2.2 yamt #endif
171 1.1.2.2 yamt Lstartup_pagetable:
172 1.1.2.2 yamt .word STARTUP_PAGETABLE_ADDR
173 1.1.2.2 yamt
174 1.1.2.2 yamt .globl _C_LABEL(u_boot_args)
175 1.1.2.2 yamt u_boot_args:
176 1.1.2.2 yamt .space 16 /* r0, r1, r2, r3 */
177 1.1.2.2 yamt
178 1.1.2.2 yamt .globl _C_LABEL(ram_size)
179 1.1.2.2 yamt ram_size:
180 1.1.2.2 yamt .word 0x04000000 /* 64Mbyte */
181 1.1.2.2 yamt
182 1.1.2.2 yamt
183 1.1.2.2 yamt #define MMU_INIT(va,pa,n_sec,attr) \
184 1.1.2.2 yamt .word n_sec ; \
185 1.1.2.2 yamt .word 4 * ((va) >> L1_S_SHIFT) ; \
186 1.1.2.2 yamt .word (pa) | (attr) ;
187 1.1.2.2 yamt
188 1.1.2.2 yamt mmu_init_table:
189 1.1.2.2 yamt /* fill all table VA==PA */
190 1.1.2.2 yamt MMU_INIT(0x00000000, 0x00000000,
191 1.1.2.2 yamt 1 << (32 - L1_S_SHIFT), L1_TYPE_S | L1_S_AP(AP_KRW))
192 1.1.2.2 yamt
193 1.1.2.2 yamt /* map SDRAM VA==PA, WT cacheable */
194 1.1.2.2 yamt MMU_INIT(SDRAM_START, SDRAM_START,
195 1.1.2.2 yamt 64, L1_TYPE_S | L1_S_C | L1_S_AP(AP_KRW))
196 1.1.2.2 yamt
197 1.1.2.2 yamt /* map VA 0xc0000000..0xc3ffffff to PA 0x20000000..0x23ffffff */
198 1.1.2.2 yamt MMU_INIT(0xc0000000, SDRAM_START,
199 1.1.2.2 yamt 64, L1_TYPE_S | L1_S_C | L1_S_AP(AP_KRW))
200 1.1.2.2 yamt
201 1.1.2.2 yamt .word 0 /* end of table */
202