source: mainline/kernel/arch/sparc64/src/sun4v/start.S@ be6cef1b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since be6cef1b was b97b348, checked in by Martin Decky <martin@…>, 15 years ago

do not use ofw_quiesce() (it can actually make more harm than good)
fix the order of arguments passed from the bootloader to kernel on sparc64 (this fixes booting on machines with non-zero physical address start)
remove separate cache.S, use the code directly in start.S

  • Property mode set to 100644
File size: 8.8 KB
Line 
1#
2# Copyright (c) 2005 Jakub Jermar
3# Copyright (c) 2008 Pavel Rimsky
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30#include <arch/arch.h>
31#include <arch/stack.h>
32#include <arch/context_offset.h>
33#include <arch/sun4v/regdef.h>
34#include <arch/sun4v/hypercall.h>
35#include <arch/sun4v/arch.h>
36#include <arch/sun4v/cpu.h>
37#include <arch/mm/pagesize.h>
38#include <arch/mm/sun4v/tte.h>
39#include <arch/mm/sun4v/mmu.h>
40#include <arch/mm/sun4v/tlb.h>
41
42.register %g2, #scratch
43.register %g3, #scratch
44
45.section K_TEXT_START, "ax"
46
47#define BSP_FLAG 1
48#define PHYSMEM_ADDR_SIZE 56
49
50/*
51 * Flags set in the TTE data entry mapping the kernel.
52 */
53#ifdef CONFIG_VIRT_IDX_DCACHE
54 #define TTE_FLAGS \
55 (1 << TTE_V_SHIFT) \
56 | (1 << TTE_EP_SHIFT) \
57 | (1 << TTE_CP_SHIFT) \
58 | (1 << TTE_CV_SHIFT) \
59 | (1 << TTE_P_SHIFT) \
60 | (1 << TTE_W_SHIFT)
61#else
62 #define TTE_FLAGS \
63 (1 << TTE_V_SHIFT) \
64 | (1 << TTE_EP_SHIFT) \
65 | (1 << TTE_CP_SHIFT) \
66 | (1 << TTE_P_SHIFT) \
67 | (1 << TTE_W_SHIFT)
68#endif
69
70
71/*
72 * Fills a register with a TTE Data item. The item will map the given virtual
73 * address to a real address which will be computed by adding the starting
74 * address of the physical memory to the virtual address.
75 *
76 * parameters:
77 * addr: virtual address to be mapped
78 * rphysmem_start: register containing the starting address
79 * of the physical memory
80 * rtmp1: a register to be used as temporary
81 * rtmp2: a register to be used as temporary
82 * rd: register where the result will be saved
83 *
84 */
85#define TTE_DATA(addr, rphysmem_start, rtmp1, rtmp2, rd) \
86 setx TTE_FLAGS | PAGESIZE_4M, rtmp1, rd; \
87 add rd, rphysmem_start, rd; \
88 setx (addr), rtmp1, rtmp2; \
89 add rd, rtmp2, rd;
90
91/*
92 * Here is where the kernel is passed control from the boot loader.
93 *
94 * The registers are expected to be in this state:
95 * - %o0 starting address of physical memory
96 * + bootstrap processor flag
97 * bits 63...1: physical memory starting address / 2
98 * bit 0: non-zero on BSP processor, zero on AP processors
99 * - %o1 bootinfo structure address (BSP only)
100 *
101 *
102 * Moreover, we depend on boot having established the following environment:
103 * - TLBs are on
104 * - identity mapping for the kernel image
105 *
106 */
107.global kernel_image_start
108kernel_image_start:
109 mov BSP_FLAG, %l0
110 and %o0, %l0, %l7 ! l7 <= bootstrap processor?
111 andn %o0, %l0, %l6 ! l6 <= start of physical memory
112 or %o1, %g0, %l1
113
114 ! Get bits (PHYSMEM_ADDR_SIZE - 1):13 of physmem_base.
115 srlx %l6, 13, %l5
116
117 ! l5 <= physmem_base[(PHYSMEM_ADDR_SIZE - 1):13]
118 sllx %l5, 13 + (63 - (PHYSMEM_ADDR_SIZE - 1)), %l5
119 srlx %l5, 63 - (PHYSMEM_ADDR_SIZE - 1), %l5
120
121 /*
122 * Setup basic runtime environment.
123 */
124 wrpr %g0, NWINDOWS - 2, %cansave ! set maximum saveable windows
125 wrpr %g0, 0, %canrestore ! get rid of windows we will
126 ! never need again
127 wrpr %g0, 0, %otherwin ! make sure the window state is
128 ! consistent
129 wrpr %g0, NWINDOWS - 1, %cleanwin ! prevent needless clean_window
130 ! traps for kernel
131
132 wrpr %g0, 0, %wstate ! use default spill/fill trap
133
134 wrpr %g0, 0, %tl ! TL = 0, primary context
135 ! register is used
136 wrpr %g0, 0, %gl
137
138 wrpr %g0, PSTATE_PRIV_BIT, %pstate ! disable interrupts and disable
139 ! 32-bit address masking
140
141 wrpr %g0, 0, %pil ! intialize %pil
142
143 /*
144 * Switch to kernel trap table.
145 */
146 sethi %hi(trap_table), %g1
147 wrpr %g1, %lo(trap_table), %tba
148
149 /* Explicitly switch to hypervisor API 1.1. */
150 mov 1, %o0
151 mov 1, %o1
152 mov 1, %o2
153 mov 0, %o3
154 mov 0, %o4
155 mov 0, %o5
156 ta 0xff
157 nop
158
159 /*
160 * Take over the MMU.
161 */
162
163 ! map kernel in context 1
164 set kernel_image_start, %o0 ! virt. address
165 set 1, %o1 ! context
166 TTE_DATA(kernel_image_start, %l5, %g2, %g3, %o2) ! TTE data
167 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
168 __HYPERCALL_HYPERFAST(MMU_MAP_ADDR)
169
170 ! switch to context 1
171 set 1, %o0
172 set VA_PRIMARY_CONTEXT_REG, %o1
173 stxa %o0, [%o1] ASI_PRIMARY_CONTEXT_REG
174
175 ! demap all in context 0
176 set 0, %o0 ! reserved
177 set 0, %o1 ! reserved
178 set 0, %o2 ! context
179 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
180 __HYPERCALL_FAST(MMU_DEMAP_CTX)
181
182 ! install permanent mapping for kernel in context 0
183 set kernel_image_start, %o0 ! virtual address
184 set 0, %o1 ! context
185 TTE_DATA(kernel_image_start, %l5, %g2, %g3, %o2) ! TTE data
186 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
187 __HYPERCALL_FAST(MMU_MAP_PERM_ADDR)
188
189 ! switch to context 0
190 mov 0, %o0
191 set VA_PRIMARY_CONTEXT_REG, %o1
192 stxa %o0, [%o1] ASI_PRIMARY_CONTEXT_REG
193
194 ! demap all in context 1 (cleanup)
195 set 0, %o0 ! reserved
196 set 0, %o1 ! reserved
197 set 1, %o2 ! context
198 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
199 __HYPERCALL_FAST(MMU_DEMAP_CTX)
200
201 /*
202 * Set CPUID.
203 */
204 __HYPERCALL_FAST(CPU_MYID)
205 mov SCRATCHPAD_CPUID, %g1
206 stxa %o1, [%g1] ASI_SCRATCHPAD
207
208 /*
209 * Set MMU fault status area for the current CPU.
210 */
211 set mmu_fsas, %o0 ! o0 <= addr. of fault status areas array
212 add %o0, %l6, %o0 ! kernel address to real address
213 mulx %o1, MMU_FSA_SIZE, %g1 ! g1 <= offset of current CPU's fault status area
214 add %g1, %o0, %o0 ! o0 <= FSA of the current CPU
215 mov SCRATCHPAD_MMU_FSA, %g1
216 stxa %o0, [%g1] ASI_SCRATCHPAD ! remember MMU fault status area to speed up miss handler
217 __HYPERCALL_FAST(MMU_FAULT_AREA_CONF)
218
219 ! on APs skip executing the following code
220 cmp %l7, 0
221 be 1f
222 nop
223
224 /*
225 * Save physmem_base for use by the mm subsystem.
226 * %l6 contains starting physical address
227 */
228 sethi %hi(physmem_base), %l4
229 stx %l6, [%l4 + %lo(physmem_base)]
230
231 /*
232 * Store a template of a TTE Data entry for kernel mappings.
233 * This template will be used from the kernel MMU miss handler.
234 */
235 !TTE_DATA(0, %l5, %g2, %g3, %g1)
236 setx TTE_FLAGS | PAGESIZE_8K, %g2, %g1; \
237 add %g1, %l5, %g1; \
238 set kernel_8k_tlb_data_template, %g4
239 stx %g1, [%g4]
240
241 /*
242 * So far, we have not touched the stack.
243 * It is a good idea to set the kernel stack to a known state now.
244 */
245 sethi %hi(temporary_boot_stack), %sp
246 or %sp, %lo(temporary_boot_stack), %sp
247 sub %sp, STACK_BIAS, %sp
248
249 /*
250 * Call arch_pre_main(bootinfo)
251 */
252 or %l1, %g0, %o0
253 call arch_pre_main
254 nop
255
256 call main_bsp
257 nop
258
259 /* Not reached. */
260
2610:
262 ba 0b
263 nop
264
2651:
266
267#ifdef CONFIG_SMP
268
269 /*
270 * Configure stack for the AP.
271 * The AP is expected to use the stack saved
272 * in the ctx global variable.
273 */
274
275 mov 1, %o0 ! MMU enable flag
276 set mmu_enabled, %o1
277 mov MMU_ENABLE, %o5 ! MMU enable HV call
278 ta 0x80 ! call HV
279
280 mmu_enabled:
281
282 /*
283 * Configure stack for the AP.
284 * The AP is expected to use the stack saved
285 * in the ctx global variable.
286 */
287 set ctx, %g1
288 add %g1, OFFSET_SP, %g1
289 ldx [%g1], %o6
290
291 call main_ap
292 nop
293#endif
294
295 /* Not reached. */
2960:
297 ba 0b
298 nop
299
300.align 8
301.global temp_cpu_mondo_handler
302temp_cpu_mondo_handler:
303
304 set 0x3c, %o0
305 set 0x15, %o5
306 ta 0x80
307
308 mov 0, %o0
309 setx before_ap_boots, %g1, %o1
310 setx 0x80400000, %g1, %o2
311 add %o1, %o2, %o1
312 __HYPERCALL_FAST(MMU_ENABLE)
313
314before_ap_boots:
315 setx 0x80400000, %g0, %o0
316 ba kernel_image_start
317 nop
318
319.section K_DATA_START, "aw", @progbits
320
321#define INITIAL_STACK_SIZE 1024
322
323.align STACK_ALIGNMENT
324 .space INITIAL_STACK_SIZE
325.align STACK_ALIGNMENT
326temporary_boot_stack:
327 .space STACK_WINDOW_SAVE_AREA_SIZE
328
329
330.data
331
332.align 8
333.global physmem_base ! copy of the physical memory base address
334physmem_base:
335 .quad 0
336
337.global kernel_8k_tlb_data_template
338kernel_8k_tlb_data_template:
339 .quad 0
340
341/* MMU fault status areas for all CPUs */
342.align MMU_FSA_ALIGNMENT
343.global mmu_fsas
344mmu_fsas:
345 .space (MMU_FSA_SIZE * MAX_NUM_STRANDS)
Note: See TracBrowser for help on using the repository browser.