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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7f1d897 was c92af69b, checked in by Jakub Jermar <jakub@…>, 15 years ago

Create initial stack frames for main_bsp() and main_ap().

  • Property mode set to 100644
File size: 9.1 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
158 /*
159 * Take over the MMU.
160 */
161
162 ! map kernel in context 1
163 set kernel_image_start, %o0 ! virt. address
164 set 1, %o1 ! context
165 TTE_DATA(kernel_image_start, %l5, %g2, %g3, %o2) ! TTE data
166 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
167 __HYPERCALL_HYPERFAST(MMU_MAP_ADDR)
168
169 ! switch to context 1
170 set 1, %o0
171 set VA_PRIMARY_CONTEXT_REG, %o1
172 stxa %o0, [%o1] ASI_PRIMARY_CONTEXT_REG
173
174 ! demap all in context 0
175 set 0, %o0 ! reserved
176 set 0, %o1 ! reserved
177 set 0, %o2 ! context
178 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
179 __HYPERCALL_FAST(MMU_DEMAP_CTX)
180
181 ! install permanent mapping for kernel in context 0
182 set kernel_image_start, %o0 ! virtual address
183 set 0, %o1 ! context
184 TTE_DATA(kernel_image_start, %l5, %g2, %g3, %o2) ! TTE data
185 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
186 __HYPERCALL_FAST(MMU_MAP_PERM_ADDR)
187
188 ! switch to context 0
189 mov 0, %o0
190 set VA_PRIMARY_CONTEXT_REG, %o1
191 stxa %o0, [%o1] ASI_PRIMARY_CONTEXT_REG
192
193 ! demap all in context 1 (cleanup)
194 set 0, %o0 ! reserved
195 set 0, %o1 ! reserved
196 set 1, %o2 ! context
197 set MMU_FLAG_DTLB | MMU_FLAG_ITLB, %o3 ! MMU flags
198 __HYPERCALL_FAST(MMU_DEMAP_CTX)
199
200 /*
201 * Set CPUID.
202 */
203 __HYPERCALL_FAST(CPU_MYID)
204 mov SCRATCHPAD_CPUID, %g1
205 stxa %o1, [%g1] ASI_SCRATCHPAD
206
207 /*
208 * Set MMU fault status area for the current CPU.
209 */
210 set mmu_fsas, %o0 ! o0 <= addr. of fault status areas array
211 add %o0, %l6, %o0 ! kernel address to real address
212 mulx %o1, MMU_FSA_SIZE, %g1 ! g1 <= offset of current CPU's fault status area
213 add %g1, %o0, %o0 ! o0 <= FSA of the current CPU
214 mov SCRATCHPAD_MMU_FSA, %g1
215 stxa %o0, [%g1] ASI_SCRATCHPAD ! remember MMU fault status area to speed up miss handler
216 __HYPERCALL_FAST(MMU_FAULT_AREA_CONF)
217
218 ! on APs skip executing the following code
219 cmp %l7, 0
220 be %xcc, 1f
221 nop
222
223 /*
224 * Save physmem_base for use by the mm subsystem.
225 * %l6 contains starting physical address
226 */
227 sethi %hi(physmem_base), %l4
228 stx %l6, [%l4 + %lo(physmem_base)]
229
230 /*
231 * Store a template of a TTE Data entry for kernel mappings.
232 * This template will be used from the kernel MMU miss handler.
233 */
234 !TTE_DATA(0, %l5, %g2, %g3, %g1)
235 setx TTE_FLAGS | PAGESIZE_8K, %g2, %g1; \
236 add %g1, %l5, %g1; \
237 set kernel_8k_tlb_data_template, %g4
238 stx %g1, [%g4]
239
240 /*
241 * So far, we have not touched the stack.
242 * It is a good idea to set the kernel stack to a known state now.
243 */
244 sethi %hi(temporary_boot_stack), %sp
245 or %sp, %lo(temporary_boot_stack), %sp
246 sub %sp, STACK_BIAS, %sp
247
248 /*
249 * Call arch_pre_main(bootinfo)
250 */
251 call arch_pre_main
252 or %l1, %g0, %o0
253
254 /*
255 * Create the first stack frame.
256 */
257 save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp
258 flushw
259 add %g0, -STACK_BIAS, %fp
260
261 call main_bsp
262 nop
263
264 /* Not reached. */
265
2660:
267 ba,a %xcc, 0b
268
2691:
270
271#ifdef CONFIG_SMP
272
273 /*
274 * Configure stack for the AP.
275 * The AP is expected to use the stack saved
276 * in the ctx global variable.
277 */
278
279 mov 1, %o0 ! MMU enable flag
280 set mmu_enabled, %o1
281 mov MMU_ENABLE, %o5 ! MMU enable HV call
282 ta 0x80 ! call HV
283
284 mmu_enabled:
285
286 /*
287 * Configure stack for the AP.
288 * The AP is expected to use the stack saved
289 * in the ctx global variable.
290 */
291 set ctx, %g1
292 add %g1, OFFSET_SP, %g1
293 ldx [%g1], %o6
294
295 /*
296 * Create the first stack frame.
297 */
298 save %sp, -(STACK_WINDWO_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp
299 flushw
300 add %g0, -STACK_BIAS, %fp
301
302 call main_ap
303 nop
304#endif
305
306 /* Not reached. */
3070:
308 ba,a %xcc, 0b
309
310.align 8
311.global temp_cpu_mondo_handler
312temp_cpu_mondo_handler:
313
314 set 0x3c, %o0
315 set 0x15, %o5
316 ta 0x80
317
318 mov 0, %o0
319 setx before_ap_boots, %g1, %o1
320 setx 0x80400000, %g1, %o2
321 add %o1, %o2, %o1
322 __HYPERCALL_FAST(MMU_ENABLE)
323
324before_ap_boots:
325 setx 0x80400000, %g0, %o0
326 ba,a %xcc, kernel_image_start
327
328.section K_DATA_START, "aw", @progbits
329
330#define INITIAL_STACK_SIZE 1024
331
332.align STACK_ALIGNMENT
333 .space INITIAL_STACK_SIZE
334.align STACK_ALIGNMENT
335temporary_boot_stack:
336 .space STACK_WINDOW_SAVE_AREA_SIZE
337
338
339.data
340
341.align 8
342.global physmem_base ! copy of the physical memory base address
343physmem_base:
344 .quad 0
345
346.global kernel_8k_tlb_data_template
347kernel_8k_tlb_data_template:
348 .quad 0
349
350/* MMU fault status areas for all CPUs */
351.align MMU_FSA_ALIGNMENT
352.global mmu_fsas
353mmu_fsas:
354 .space (MMU_FSA_SIZE * MAX_NUM_STRANDS)
Note: See TracBrowser for help on using the repository browser.