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