lubbock_start.S revision 1.2 1 1.2 rafal /* $NetBSD: lubbock_start.S,v 1.2 2008/03/10 16:48:13 rafal Exp $ */
2 1.1 bsh
3 1.1 bsh /*
4 1.1 bsh * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
5 1.1 bsh * Written by Hiroyuki Bessho for Genetec Corporation.
6 1.1 bsh *
7 1.1 bsh * Redistribution and use in source and binary forms, with or without
8 1.1 bsh * modification, are permitted provided that the following conditions
9 1.1 bsh * are met:
10 1.1 bsh * 1. Redistributions of source code must retain the above copyright
11 1.1 bsh * notice, this list of conditions and the following disclaimer.
12 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 bsh * notice, this list of conditions and the following disclaimer in the
14 1.1 bsh * documentation and/or other materials provided with the distribution.
15 1.1 bsh * 3. The name of Genetec Corporation may not be used to endorse or
16 1.1 bsh * promote products derived from this software without specific prior
17 1.1 bsh * written permission.
18 1.1 bsh *
19 1.1 bsh * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
20 1.1 bsh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 bsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 bsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
23 1.1 bsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 bsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 bsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 bsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 bsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 bsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 bsh * POSSIBILITY OF SUCH DAMAGE.
30 1.1 bsh */
31 1.1 bsh
32 1.1 bsh #include <machine/asm.h>
33 1.1 bsh #include <arm/armreg.h>
34 1.1 bsh #include <arm/arm32/pte.h>
35 1.1 bsh #include <arm/arm32/pmap.h> /* for PMAP_DOMAIN_KERNEL */
36 1.1 bsh
37 1.1 bsh #ifndef SDRAM_START
38 1.1 bsh #define SDRAM_START 0xa0000000
39 1.1 bsh #endif
40 1.1 bsh
41 1.1 bsh /*
42 1.1 bsh * CPWAIT -- Canonical method to wait for CP15 update.
43 1.1 bsh * NOTE: Clobbers the specified temp reg.
44 1.1 bsh * copied from arm/arm/cpufunc_asm_xscale.S
45 1.1 bsh * XXX: better be in a common header file.
46 1.1 bsh */
47 1.1 bsh #define CPWAIT_BRANCH \
48 1.1 bsh sub pc, pc, #4
49 1.1 bsh
50 1.1 bsh #define CPWAIT(tmp) \
51 1.1 bsh mrc p15, 0, tmp, c2, c0, 0 /* arbitrary read of CP15 */ ;\
52 1.1 bsh mov tmp, tmp /* wait for it to complete */ ;\
53 1.1 bsh CPWAIT_BRANCH /* branch to next insn */
54 1.1 bsh
55 1.1 bsh /*
56 1.1 bsh * Kernel start routine for DBPXA250 (Lubbock)
57 1.1 bsh * this code is excuted at the very first after the kernel is loaded
58 1.1 bsh * by RedBoot.
59 1.1 bsh */
60 1.1 bsh .text
61 1.1 bsh
62 1.1 bsh .global _C_LABEL(lubbock_start)
63 1.1 bsh _C_LABEL(lubbock_start):
64 1.1 bsh /* Are we running on ROM ? */
65 1.1 bsh cmp pc, #0x06000000
66 1.1 bsh bhi lubbock_start_ram
67 1.1 bsh
68 1.1 bsh /* move me to RAM
69 1.1 bsh * XXX: we can use memcpy if it is PIC
70 1.1 bsh */
71 1.1 bsh ldr r1, Lcopy_size
72 1.1 bsh adr r0, _C_LABEL(lubbock_start)
73 1.1 bsh add r1, r1, #3
74 1.1 bsh mov r1, r1, LSR #2
75 1.1 bsh mov r2, #SDRAM_START
76 1.1 bsh add r2, r2, #0x00200000
77 1.1 bsh mov r4, r2
78 1.1 bsh
79 1.1 bsh 5: ldr r3,[r0],#4
80 1.1 bsh str r3,[r2],#4
81 1.1 bsh subs r1,r1,#1
82 1.1 bsh bhi 5b
83 1.1 bsh
84 1.1 bsh /* Jump to RAM */
85 1.1 bsh ldr r0, Lstart_off
86 1.1 bsh add pc, r4, r0
87 1.1 bsh
88 1.1 bsh Lcopy_size: .word _edata-_C_LABEL(lubbock_start)
89 1.1 bsh Lstart_off: .word lubbock_start_ram-_C_LABEL(lubbock_start)
90 1.1 bsh
91 1.1 bsh lubbock_start_ram:
92 1.1 bsh /*
93 1.1 bsh * Kernel is loaded in SDRAM (0xa0200000..), and is expected to run
94 1.1 bsh * in VA 0xc0200000..
95 1.1 bsh */
96 1.1 bsh
97 1.1 bsh mrc p15, 0, r0, c2, c0, 0 /* get ttb prepared by redboot */
98 1.1 bsh adr r4, mmu_init_table2
99 1.1 bsh
100 1.1 bsh #ifdef BUILD_STARTUP_PAGETABLE
101 1.1 bsh mrc p15, 0, r2, c1, c0, 0
102 1.1 bsh tst r2, #CPU_CONTROL_MMU_ENABLE /* we already have a page table? */
103 1.1 bsh bne 3f
104 1.1 bsh
105 1.1 bsh /* build page table from scratch */
106 1.1 bsh ldr r0, Lstartup_pagetable
107 1.1 bsh adr r4, mmu_init_table
108 1.1 bsh #endif
109 1.1 bsh b 3f
110 1.1 bsh
111 1.1 bsh 2:
112 1.1 bsh str r3, [r0, r2]
113 1.1 bsh add r2, r2, #4
114 1.1 bsh add r3, r3, #(L1_S_SIZE)
115 1.1 bsh adds r1, r1, #-1
116 1.1 bsh bhi 2b
117 1.1 bsh 3:
118 1.1 bsh ldmia r4!, {r1,r2,r3} /* # of sections, PA|attr, VA */
119 1.1 bsh cmp r1, #0
120 1.1 bsh bne 2b
121 1.1 bsh
122 1.1 bsh mcr p15, 0, r0, c2, c0, 0 /* Set TTB */
123 1.1 bsh mcr p15, 0, r0, c8, c7, 0 /* Flush TLB */
124 1.1 bsh
125 1.1 bsh /* Set the Domain Access register. Very important! */
126 1.1 bsh mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
127 1.1 bsh mcr p15, 0, r0, c3, c0, 0
128 1.1 bsh
129 1.1 bsh /* Enable MMU */
130 1.1 bsh mrc p15, 0, r0, c1, c0, 0
131 1.1 bsh orr r0, r0, #CPU_CONTROL_MMU_ENABLE
132 1.1 bsh mcr p15, 0, r0, c1, c0, 0
133 1.1 bsh CPWAIT(r0)
134 1.1 bsh
135 1.1 bsh /* Jump to kernel code in TRUE VA */
136 1.1 bsh adr r0, Lstart
137 1.1 bsh ldr pc, [r0]
138 1.1 bsh
139 1.1 bsh Lstart:
140 1.1 bsh .word start
141 1.1 bsh
142 1.1 bsh #define MMU_INIT(va,pa,n_sec,attr) \
143 1.1 bsh .word n_sec ; \
144 1.1 bsh .word 4*((va)>>L1_S_SHIFT) ; \
145 1.1 bsh .word (pa)|(attr) ;
146 1.1 bsh
147 1.1 bsh #ifdef BUILD_STARTUP_PAGETABLE
148 1.1 bsh #ifndef STARTUP_PAGETABLE_ADDR
149 1.1 bsh #define STARTUP_PAGETABLE_ADDR 0xa0004000
150 1.1 bsh #endif
151 1.2 rafal Lstartup_pagetable:
152 1.2 rafal .word STARTUP_PAGETABLE_ADDR
153 1.1 bsh mmu_init_table:
154 1.1 bsh /* fill all table VA==PA */
155 1.1 bsh MMU_INIT(0x00000000, 0x00000000, 1<<(32-L1_S_SHIFT), L1_TYPE_S|L1_S_AP(AP_KRW))
156 1.1 bsh /* map SDRAM VA==PA, WT cacheable */
157 1.1 bsh MMU_INIT(SDRAM_START, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))
158 1.1 bsh #endif
159 1.1 bsh mmu_init_table2:
160 1.1 bsh /* map VA 0xc0000000..0xc3ffffff to PA 0xa0000000..0xa3ffffff */
161 1.1 bsh MMU_INIT(0xc0000000, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP(AP_KRW))
162 1.1 bsh
163 1.1 bsh .word 0 /* end of table */
164