source: mainline/kernel/arch/sparc64/src/sun4u/start.S@ 2902e1bb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2902e1bb was 7f1d897, 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: 11.6 KB
Line 
1#
2# Copyright (c) 2005 Jakub Jermar
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29#include <arch/arch.h>
30#include <arch/cpu.h>
31#include <arch/regdef.h>
32#include <arch/boot/boot.h>
33#include <arch/stack.h>
34
35#include <arch/mm/mmu.h>
36#include <arch/mm/tlb.h>
37#include <arch/mm/tte.h>
38#include <arch/mm/cache_spec.h>
39
40#ifdef CONFIG_SMP
41#include <arch/context_offset.h>
42#endif
43
44.register %g2, #scratch
45.register %g3, #scratch
46
47.section K_TEXT_START, "ax"
48
49#define BSP_FLAG 1
50
51/*
52 * 2^PHYSMEM_ADDR_SIZE is the size of the physical address space on
53 * a given processor.
54 */
55#if defined (US)
56 #define PHYSMEM_ADDR_SIZE 41
57#elif defined (US3)
58 #define PHYSMEM_ADDR_SIZE 43
59#endif
60
61/*
62 * Here is where the kernel is passed control from the boot loader.
63 *
64 * The registers are expected to be in this state:
65 * - %o0 starting address of physical memory
66 * + bootstrap processor flag
67 * bits 63...1: physical memory starting address / 2
68 * bit 0: non-zero on BSP processor, zero on AP processors
69 * - %o1 bootinfo structure address (BSP only)
70 *
71 *
72 * Moreover, we depend on boot having established the following environment:
73 * - TLBs are on
74 * - identity mapping for the kernel image
75 *
76 */
77
78.global kernel_image_start
79kernel_image_start:
80 mov BSP_FLAG, %l0
81 and %o0, %l0, %l7 ! l7 <= bootstrap processor?
82 andn %o0, %l0, %l6 ! l6 <= start of physical memory
83
84 ! Get bits (PHYSMEM_ADDR_SIZE - 1):13 of physmem_base.
85 srlx %l6, 13, %l5
86
87 ! l5 <= physmem_base[(PHYSMEM_ADDR_SIZE - 1):13]
88 sllx %l5, 13 + (63 - (PHYSMEM_ADDR_SIZE - 1)), %l5
89 srlx %l5, 63 - (PHYSMEM_ADDR_SIZE - 1), %l5
90
91 /*
92 * Setup basic runtime environment.
93 */
94
95 wrpr %g0, NWINDOWS - 2, %cansave ! set maximum saveable windows
96 wrpr %g0, 0, %canrestore ! get rid of windows we will
97 ! never need again
98 wrpr %g0, 0, %otherwin ! make sure the window state is
99 ! consistent
100 wrpr %g0, NWINDOWS - 1, %cleanwin ! prevent needless clean_window
101 ! traps for kernel
102
103 wrpr %g0, 0, %wstate ! use default spill/fill trap
104
105 wrpr %g0, 0, %tl ! TL = 0, primary context
106 ! register is used
107
108 wrpr %g0, PSTATE_PRIV_BIT, %pstate ! disable interrupts and disable
109 ! 32-bit address masking
110
111 wrpr %g0, 0, %pil ! intialize %pil
112
113 /*
114 * Switch to kernel trap table.
115 */
116 sethi %hi(trap_table), %g1
117 wrpr %g1, %lo(trap_table), %tba
118
119 /*
120 * Take over the DMMU by installing locked TTE entry identically
121 * mapping the first 4M of memory.
122 *
123 * In case of DMMU, no FLUSH instructions need to be issued. Because of
124 * that, the old DTLB contents can be demapped pretty straightforwardly
125 * and without causing any traps.
126 */
127
128 wr %g0, ASI_DMMU, %asi
129
130#define SET_TLB_DEMAP_CMD(r1, context_id) \
131 set (TLB_DEMAP_CONTEXT << TLB_DEMAP_TYPE_SHIFT) | (context_id << \
132 TLB_DEMAP_CONTEXT_SHIFT), %r1
133
134 ! demap context 0
135 SET_TLB_DEMAP_CMD(g1, TLB_DEMAP_NUCLEUS)
136 stxa %g0, [%g1] ASI_DMMU_DEMAP
137 membar #Sync
138
139#define SET_TLB_TAG(r1, context) \
140 set VMA | (context << TLB_TAG_ACCESS_CONTEXT_SHIFT), %r1
141
142 ! write DTLB tag
143 SET_TLB_TAG(g1, MEM_CONTEXT_KERNEL)
144 stxa %g1, [VA_DMMU_TAG_ACCESS] %asi
145 membar #Sync
146
147#ifdef CONFIG_VIRT_IDX_DCACHE
148#define TTE_LOW_DATA(imm) (TTE_CP | TTE_CV | TTE_P | LMA | (imm))
149#else /* CONFIG_VIRT_IDX_DCACHE */
150#define TTE_LOW_DATA(imm) (TTE_CP | TTE_P | LMA | (imm))
151#endif /* CONFIG_VIRT_IDX_DCACHE */
152
153#define SET_TLB_DATA(r1, r2, imm) \
154 set TTE_LOW_DATA(imm), %r1; \
155 or %r1, %l5, %r1; \
156 mov PAGESIZE_4M, %r2; \
157 sllx %r2, TTE_SIZE_SHIFT, %r2; \
158 or %r1, %r2, %r1; \
159 mov 1, %r2; \
160 sllx %r2, TTE_V_SHIFT, %r2; \
161 or %r1, %r2, %r1;
162
163 ! write DTLB data and install the kernel mapping
164 SET_TLB_DATA(g1, g2, TTE_L | TTE_W) ! use non-global mapping
165 stxa %g1, [%g0] ASI_DTLB_DATA_IN_REG
166 membar #Sync
167
168 /*
169 * Because we cannot use global mappings (because we want to have
170 * separate 64-bit address spaces for both the kernel and the
171 * userspace), we prepare the identity mapping also in context 1. This
172 * step is required by the code installing the ITLB mapping.
173 */
174 ! write DTLB tag of context 1 (i.e. MEM_CONTEXT_TEMP)
175 SET_TLB_TAG(g1, MEM_CONTEXT_TEMP)
176 stxa %g1, [VA_DMMU_TAG_ACCESS] %asi
177 membar #Sync
178
179 ! write DTLB data and install the kernel mapping in context 1
180 SET_TLB_DATA(g1, g2, TTE_W) ! use non-global mapping
181 stxa %g1, [%g0] ASI_DTLB_DATA_IN_REG
182 membar #Sync
183
184 /*
185 * Now is time to take over the IMMU. Unfortunatelly, it cannot be done
186 * as easily as the DMMU, because the IMMU is mapping the code it
187 * executes.
188 *
189 * [ Note that brave experiments with disabling the IMMU and using the
190 * DMMU approach failed after a dozen of desparate days with only little
191 * success. ]
192 *
193 * The approach used here is inspired from OpenBSD. First, the kernel
194 * creates IMMU mapping for itself in context 1 (MEM_CONTEXT_TEMP) and
195 * switches to it. Context 0 (MEM_CONTEXT_KERNEL) can be demapped
196 * afterwards and replaced with the kernel permanent mapping. Finally,
197 * the kernel switches back to context 0 and demaps context 1.
198 *
199 * Moreover, the IMMU requires use of the FLUSH instructions. But that
200 * is OK because we always use operands with addresses already mapped by
201 * the taken over DTLB.
202 */
203
204 set kernel_image_start, %g5
205
206 ! write ITLB tag of context 1
207 SET_TLB_TAG(g1, MEM_CONTEXT_TEMP)
208 mov VA_DMMU_TAG_ACCESS, %g2
209 stxa %g1, [%g2] ASI_IMMU
210 flush %g5
211
212 ! write ITLB data and install the temporary mapping in context 1
213 SET_TLB_DATA(g1, g2, 0) ! use non-global mapping
214 stxa %g1, [%g0] ASI_ITLB_DATA_IN_REG
215 flush %g5
216
217 ! switch to context 1
218 mov MEM_CONTEXT_TEMP, %g1
219 stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi ! ASI_DMMU is correct here !!!
220 flush %g5
221
222 ! demap context 0
223 SET_TLB_DEMAP_CMD(g1, TLB_DEMAP_NUCLEUS)
224 stxa %g0, [%g1] ASI_IMMU_DEMAP
225 flush %g5
226
227 ! write ITLB tag of context 0
228 SET_TLB_TAG(g1, MEM_CONTEXT_KERNEL)
229 mov VA_DMMU_TAG_ACCESS, %g2
230 stxa %g1, [%g2] ASI_IMMU
231 flush %g5
232
233 ! write ITLB data and install the permanent kernel mapping in context 0
234 SET_TLB_DATA(g1, g2, TTE_L) ! use non-global mapping
235 stxa %g1, [%g0] ASI_ITLB_DATA_IN_REG
236 flush %g5
237
238 ! enter nucleus - using context 0
239 wrpr %g0, 1, %tl
240
241 ! demap context 1
242 SET_TLB_DEMAP_CMD(g1, TLB_DEMAP_PRIMARY)
243 stxa %g0, [%g1] ASI_IMMU_DEMAP
244 flush %g5
245
246 ! set context 0 in the primary context register
247 stxa %g0, [VA_PRIMARY_CONTEXT_REG] %asi ! ASI_DMMU is correct here !!!
248 flush %g5
249
250 ! leave nucleus - using primary context, i.e. context 0
251 wrpr %g0, 0, %tl
252
253 brz %l7, 1f ! skip if you are not the bootstrap CPU
254 nop
255
256 /*
257 * Save physmem_base for use by the mm subsystem.
258 * %l6 contains starting physical address
259 */
260 sethi %hi(physmem_base), %l4
261 stx %l6, [%l4 + %lo(physmem_base)]
262
263 /*
264 * Precompute kernel 8K TLB data template.
265 * %l5 contains starting physical address
266 * bits [(PHYSMEM_ADDR_SIZE - 1):13]
267 */
268 sethi %hi(kernel_8k_tlb_data_template), %l4
269 ldx [%l4 + %lo(kernel_8k_tlb_data_template)], %l3
270 or %l3, %l5, %l3
271 stx %l3, [%l4 + %lo(kernel_8k_tlb_data_template)]
272
273 ! flush the whole D-cache
274 set (DCACHE_SIZE - DCACHE_LINE_SIZE), %g1
275 stxa %g0, [%g1] ASI_DCACHE_TAG
276
2770:
278 membar #Sync
279 subcc %g1, DCACHE_LINE_SIZE, %g1
280 bnz,pt %xcc, 0b
281 stxa %g0, [%g1] ASI_DCACHE_TAG
282 membar #Sync
283
284 /*
285 * So far, we have not touched the stack.
286 * It is a good idea to set the kernel stack to a known state now.
287 */
288 sethi %hi(temporary_boot_stack), %sp
289 or %sp, %lo(temporary_boot_stack), %sp
290 sub %sp, STACK_BIAS, %sp
291
292 /*
293 * Call arch_pre_main(bootinfo)
294 */
295 call arch_pre_main
296 mov %o1, %o0
297
298 /*
299 * Create the first stack frame.
300 */
301 save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp
302 flushw
303 add %g0, -STACK_BIAS, %fp
304
305 call main_bsp
306 nop
307
308 /* Not reached. */
309
3100:
311 ba,a %xcc, 0b
312
313
3141:
315#ifdef CONFIG_SMP
316 /*
317 * Determine the width of the MID and save its mask to %g3. The width
318 * is
319 * * 5 for US and US-IIIi,
320 * * 10 for US3 except US-IIIi.
321 */
322#if defined(US)
323 mov 0x1f, %g3
324#elif defined(US3)
325 mov 0x3ff, %g3
326 rdpr %ver, %g2
327 sllx %g2, 16, %g2
328 srlx %g2, 48, %g2
329 cmp %g2, IMPL_ULTRASPARCIII_I
330 move %xcc, 0x1f, %g3
331#endif
332
333 /*
334 * Read MID from the processor.
335 */
336 ldxa [%g0] ASI_ICBUS_CONFIG, %g1
337 srlx %g1, ICBUS_CONFIG_MID_SHIFT, %g1
338 and %g1, %g3, %g1
339
340 /*
341 * Active loop for APs until the BSP picks them up. A processor cannot
342 * leave the loop until the global variable 'waking_up_mid' equals its
343 * MID.
344 */
345 set waking_up_mid, %g2
3462:
347 ldx [%g2], %g3
348 cmp %g3, %g1
349 bne %xcc, 2b
350 nop
351
352 /*
353 * Configure stack for the AP.
354 * The AP is expected to use the stack saved
355 * in the ctx global variable.
356 */
357 set ctx, %g1
358 add %g1, OFFSET_SP, %g1
359 ldx [%g1], %o6
360
361 /*
362 * Create the first stack frame.
363 */
364 save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE), %sp
365 flushw
366 add %g0, -STACK_BIAS, %fp
367
368 call main_ap
369 nop
370
371 /* Not reached. */
372#endif
373
3740:
375 ba,a %xcc, 0b
376
377
378.section K_DATA_START, "aw", @progbits
379
380/*
381 * Create small stack to be used by the bootstrap processor. It is going to be
382 * used only for a very limited period of time, but we switch to it anyway,
383 * just to be sure we are properly initialized.
384 */
385
386#define INITIAL_STACK_SIZE 1024
387
388.align STACK_ALIGNMENT
389 .space INITIAL_STACK_SIZE
390.align STACK_ALIGNMENT
391temporary_boot_stack:
392 .space STACK_WINDOW_SAVE_AREA_SIZE
393
394
395.data
396
397.align 8
398.global physmem_base ! copy of the physical memory base address
399physmem_base:
400 .quad 0
401
402/*
403 * The fast_data_access_mmu_miss_data_hi label and the end_of_identity and
404 * kernel_8k_tlb_data_template variables are meant to stay together,
405 * aligned on 16B boundary.
406 */
407.global fast_data_access_mmu_miss_data_hi
408.global end_of_identity
409.global kernel_8k_tlb_data_template
410
411.align 16
412/*
413 * This label is used by the fast_data_access_MMU_miss trap handler.
414 */
415fast_data_access_mmu_miss_data_hi:
416/*
417 * This variable is used by the fast_data_access_MMU_miss trap handler.
418 * In runtime, it is modified to contain the address of the end of physical
419 * memory.
420 */
421end_of_identity:
422 .quad -1
423/*
424 * This variable is used by the fast_data_access_MMU_miss trap handler.
425 * In runtime, it is further modified to reflect the starting address of
426 * physical memory.
427 */
428kernel_8k_tlb_data_template:
429#ifdef CONFIG_VIRT_IDX_DCACHE
430 .quad ((1 << TTE_V_SHIFT) | (PAGESIZE_8K << TTE_SIZE_SHIFT) | TTE_CP | \
431 TTE_CV | TTE_P | TTE_W)
432#else /* CONFIG_VIRT_IDX_DCACHE */
433 .quad ((1 << TTE_V_SHIFT) | (PAGESIZE_8K << TTE_SIZE_SHIFT) | TTE_CP | \
434 TTE_P | TTE_W)
435#endif /* CONFIG_VIRT_IDX_DCACHE */
436
Note: See TracBrowser for help on using the repository browser.