mpcsa_start.S revision 1.1.20.1 1 1.1.20.1 yamt /*
2 1.1.20.1 yamt * mpcsa_start.S
3 1.1.20.1 yamt * Copyright (c) 2007, S. Kantoluoto <sami.kantoluoto (at) iki.fi>
4 1.1.20.1 yamt * All rights reserved.
5 1.1.20.1 yamt *
6 1.1.20.1 yamt * Based on vx115_vep_start.S
7 1.1.20.1 yamt * Copyright (c) 2007, J. Sevy <jsevy (at) cs.drexel.edu>
8 1.1.20.1 yamt *
9 1.1.20.1 yamt * Based on g42xxeb_start.S
10 1.1.20.1 yamt * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
11 1.1.20.1 yamt * Written by Hiroyuki Bessho for Genetec Corporation.
12 1.1.20.1 yamt *
13 1.1.20.1 yamt * Redistribution and use in source and binary forms, with or without
14 1.1.20.1 yamt * modification, are permitted provided that the following conditions
15 1.1.20.1 yamt * are met:
16 1.1.20.1 yamt * 1. Redistributions of source code must retain the above copyright
17 1.1.20.1 yamt * notice, this list of conditions and the following disclaimer.
18 1.1.20.1 yamt * 2. Redistributions in binary form must reproduce the above copyright
19 1.1.20.1 yamt * notice, this list of conditions and the following disclaimer in the
20 1.1.20.1 yamt * documentation and/or other materials provided with the distribution.
21 1.1.20.1 yamt * 3. The name of Genetec Corporation may not be used to endorse or
22 1.1.20.1 yamt * promote products derived from this software without specific prior
23 1.1.20.1 yamt * written permission.
24 1.1.20.1 yamt *
25 1.1.20.1 yamt * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
26 1.1.20.1 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.20.1 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.20.1 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
29 1.1.20.1 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.20.1 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.20.1 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.20.1 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.20.1 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.20.1 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.20.1 yamt * POSSIBILITY OF SUCH DAMAGE.
36 1.1.20.1 yamt */
37 1.1.20.1 yamt
38 1.1.20.1 yamt #include <machine/asm.h>
39 1.1.20.1 yamt #include <arm/armreg.h>
40 1.1.20.1 yamt #include <arm/arm32/pte.h>
41 1.1.20.1 yamt #include <arm/arm32/pmap.h> /* for PMAP_DOMAIN_KERNEL */
42 1.1.20.1 yamt
43 1.1.20.1 yamt #ifndef FLASH_START
44 1.1.20.1 yamt #define FLASH_START 0x10020000
45 1.1.20.1 yamt #endif
46 1.1.20.1 yamt
47 1.1.20.1 yamt #ifndef SDRAM_START
48 1.1.20.1 yamt #define SDRAM_START 0x20000000
49 1.1.20.1 yamt #endif
50 1.1.20.1 yamt
51 1.1.20.1 yamt #define MODBASE 0x20200000
52 1.1.20.1 yamt
53 1.1.20.1 yamt /*
54 1.1.20.1 yamt * CPWAIT -- Canonical method to wait for CP15 update.
55 1.1.20.1 yamt * NOTE: Clobbers the specified temp reg.
56 1.1.20.1 yamt * copied from arm/arm/cpufunc_asm_xscale.S
57 1.1.20.1 yamt * XXX: better be in a common header file.
58 1.1.20.1 yamt */
59 1.1.20.1 yamt #define CPWAIT_BRANCH \
60 1.1.20.1 yamt sub pc, pc, #4
61 1.1.20.1 yamt
62 1.1.20.1 yamt #define CPWAIT(tmp) \
63 1.1.20.1 yamt mrc p15, 0, tmp, c2, c0, 0 /* arbitrary read of CP15 */ ;\
64 1.1.20.1 yamt mov tmp, tmp /* wait for it to complete */ ;\
65 1.1.20.1 yamt CPWAIT_BRANCH /* branch to next insn */
66 1.1.20.1 yamt
67 1.1.20.1 yamt /*
68 1.1.20.1 yamt * Kernel start routine for MPCSA board.
69 1.1.20.1 yamt * This code is executed from Flash when the bootloader jumps to it.
70 1.1.20.1 yamt */
71 1.1.20.1 yamt .text
72 1.1.20.1 yamt
73 1.1.20.1 yamt .global _C_LABEL(mpcsa_start)
74 1.1.20.1 yamt _C_LABEL(mpcsa_start):
75 1.1.20.1 yamt
76 1.1.20.1 yamt /* make sure we're in supervisor mode */
77 1.1.20.1 yamt mov r0,sp
78 1.1.20.1 yamt msr CPSR_c,#I32_bit | F32_bit | PSR_SVC32_MODE
79 1.1.20.1 yamt mov sp,r0
80 1.1.20.1 yamt
81 1.1.20.1 yamt /* move code to RAM */
82 1.1.20.1 yamt ldr r1, Lcopy_size
83 1.1.20.1 yamt adr r0, _C_LABEL(mpcsa_start)
84 1.1.20.1 yamt add r1, r1, #3
85 1.1.20.1 yamt mov r1, r1, LSR #2 /* get size of code in words */
86 1.1.20.1 yamt mov r2, #SDRAM_START
87 1.1.20.1 yamt add r2, r2, #0x200000 /* code placed 2MB above kernel base */
88 1.1.20.1 yamt mov r4, r2
89 1.1.20.1 yamt
90 1.1.20.1 yamt /* copy kernel to RAM */
91 1.1.20.1 yamt 5: ldr r3, [r0], #4
92 1.1.20.1 yamt subs r1, r1, #1
93 1.1.20.1 yamt str r3, [r2], #4
94 1.1.20.1 yamt bhi 5b
95 1.1.20.1 yamt
96 1.1.20.1 yamt /* jump to RAM */
97 1.1.20.1 yamt ldr r0, Lstart_off
98 1.1.20.1 yamt add pc, r4, r0
99 1.1.20.1 yamt
100 1.1.20.1 yamt
101 1.1.20.1 yamt Lcopy_size: .word _edata-_C_LABEL(mpcsa_start)
102 1.1.20.1 yamt Lstart_off: .word mpcsa_start_ram-_C_LABEL(mpcsa_start)
103 1.1.20.1 yamt
104 1.1.20.1 yamt mpcsa_start_ram:
105 1.1.20.1 yamt /*
106 1.1.20.1 yamt * Kernel is loaded in SDRAM (0x20200000), and is expected to run
107 1.1.20.1 yamt * in VA 0xc0200000.
108 1.1.20.1 yamt */
109 1.1.20.1 yamt
110 1.1.20.1 yamt /* build page table from scratch */
111 1.1.20.1 yamt ldr r0, Lstartup_pagetable
112 1.1.20.1 yamt adr r4, mmu_init_table
113 1.1.20.1 yamt b 3f
114 1.1.20.1 yamt
115 1.1.20.1 yamt 2:
116 1.1.20.1 yamt str r3, [r0, r2]
117 1.1.20.1 yamt add r2, r2, #4
118 1.1.20.1 yamt add r3, r3, #(L1_S_SIZE)
119 1.1.20.1 yamt adds r1, r1, #-1
120 1.1.20.1 yamt bhi 2b
121 1.1.20.1 yamt 3:
122 1.1.20.1 yamt ldmia r4!, {r1,r2,r3} /* # of sections, PA|attr, VA */
123 1.1.20.1 yamt cmp r1, #0
124 1.1.20.1 yamt bne 2b
125 1.1.20.1 yamt
126 1.1.20.1 yamt
127 1.1.20.1 yamt mcr p15, 0, r0, c2, c0, 0 /* Set TTB */
128 1.1.20.1 yamt mcr p15, 0, r0, c8, c7, 0 /* Flush TLB */
129 1.1.20.1 yamt
130 1.1.20.1 yamt /* Set the Domain Access register. Very important! */
131 1.1.20.1 yamt mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
132 1.1.20.1 yamt mcr p15, 0, r0, c3, c0, 0
133 1.1.20.1 yamt
134 1.1.20.1 yamt /* Enable MMU */
135 1.1.20.1 yamt mrc p15, 0, r0, c1, c0, 0
136 1.1.20.1 yamt orr r0, r0, #CPU_CONTROL_MMU_ENABLE
137 1.1.20.1 yamt mcr p15, 0, r0, c1, c0, 0
138 1.1.20.1 yamt CPWAIT(r0)
139 1.1.20.1 yamt
140 1.1.20.1 yamt /* Jump to kernel code in TRUE VA */
141 1.1.20.1 yamt adr r0, Lstart
142 1.1.20.1 yamt ldr pc, [r0]
143 1.1.20.1 yamt
144 1.1.20.1 yamt Lstart:
145 1.1.20.1 yamt .word start
146 1.1.20.1 yamt
147 1.1.20.1 yamt
148 1.1.20.1 yamt #define MMU_INIT(va,pa,n_sec,attr) \
149 1.1.20.1 yamt .word n_sec ;\
150 1.1.20.1 yamt .word 4*((va)>>L1_S_SHIFT) ;\
151 1.1.20.1 yamt .word (pa) | (attr)
152 1.1.20.1 yamt
153 1.1.20.1 yamt #define STARTUP_PAGETABLE_ADDR 0x20100000 + 0x4000
154 1.1.20.1 yamt
155 1.1.20.1 yamt Lstartup_pagetable:
156 1.1.20.1 yamt .word STARTUP_PAGETABLE_ADDR
157 1.1.20.1 yamt
158 1.1.20.1 yamt mmu_init_table:
159 1.1.20.1 yamt /* fill all table VA==PA */
160 1.1.20.1 yamt MMU_INIT(0x00000000, 0x00000000, 1<<(32-L1_S_SHIFT), L1_TYPE_S|L1_S_AP(AP_KRW))
161 1.1.20.1 yamt /* map in peripheral space */
162 1.1.20.1 yamt MMU_INIT(0xfff00000, 0xfff00000, 1, L1_TYPE_S|L1_S_AP(AP_KRW))
163 1.1.20.1 yamt /* map SDRAM VA==PA, WT cacheable */
164 1.1.20.1 yamt MMU_INIT(0x20100000, 0x20100000, 63, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))
165 1.1.20.1 yamt /* map VA 0xc0000000..0xc0efffff to PA 0x20100000..0x23ffffff */
166 1.1.20.1 yamt MMU_INIT(0xc0000000, 0x20000000, 63, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))
167 1.1.20.1 yamt .word 0 /* end of table */
168 1.1.20.1 yamt
169 1.1.20.1 yamt .align 7
170 1.1.20.1 yamt jme_module_header:
171 1.1.20.1 yamt .word 0xe990510e /* magic number */
172 1.1.20.1 yamt .string "NetBSD/mpcsa\0\0\0" /* module name */
173 1.1.20.1 yamt .short 0 /* build flags */
174 1.1.20.1 yamt .short 0 /* flags */
175 1.1.20.1 yamt .word 0 /* version */
176 1.1.20.1 yamt .word 0 /* compile / link timestamp */
177 1.1.20.1 yamt .word MODBASE /* pointer to init routine */
178 1.1.20.1 yamt .word MODBASE /* start address */
179 1.1.20.1 yamt .word (_edata-(_C_LABEL(mpcsa_start))) /* length of module */
180 1.1.20.1 yamt .word (jme_module_header-_C_LABEL(mpcsa_start)+MODBASE) /* back pointer to module struct*/
181 1.1.20.1 yamt .word 0 /* data pointer (ignored but SBZ)*/
182 1.1.20.1 yamt .word 0 /* data length (ignored but SBZ)*/
183 1.1.20.1 yamt .word 0x20200000 /* alternate address */
184 1.1.20.1 yamt .word 0 /* reserved, SBZ */
185 1.1.20.1 yamt
186 1.1.20.1 yamt jme_kmodule_header:
187 1.1.20.1 yamt .word 0xe000301e /* magic number */
188 1.1.20.1 yamt .string "JME kernel\0\0\0\0\0" /* module name */
189 1.1.20.1 yamt .short 0 /* build flags */
190 1.1.20.1 yamt .short 0 /* flags */
191 1.1.20.1 yamt .word 0 /* version */
192 1.1.20.1 yamt .word 0 /* compile / link timestamp */
193 1.1.20.1 yamt .word MODBASE /* pointer to init routine */
194 1.1.20.1 yamt .word MODBASE /* start address */
195 1.1.20.1 yamt .word (_edata-(_C_LABEL(mpcsa_start))) /* length of module */
196 1.1.20.1 yamt .word (jme_kmodule_header-_C_LABEL(mpcsa_start)+MODBASE) /* back pointer to module struct*/
197 1.1.20.1 yamt .word 0 /* data pointer (ignored but SBZ)*/
198 1.1.20.1 yamt .word 0 /* data length (ignored but SBZ)*/
199 1.1.20.1 yamt .word 0x20200000 /* alternate address */
200 1.1.20.1 yamt .word 0 /* reserved, SBZ */
201