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
RevLine 
[2a99fa8]1#
[df4ed85]2# Copyright (c) 2005 Jakub Jermar
[2a99fa8]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
[a9ac978]29#include <arch/arch.h>
[965dc18]30#include <arch/cpu.h>
[63cda71]31#include <arch/regdef.h>
[e386cbf]32#include <arch/boot/boot.h>
[84060e2]33#include <arch/stack.h>
[e386cbf]34
35#include <arch/mm/mmu.h>
36#include <arch/mm/tlb.h>
37#include <arch/mm/tte.h>
[b97b348]38#include <arch/mm/cache_spec.h>
[0e4dd7b]39
[a9ac978]40#ifdef CONFIG_SMP
41#include <arch/context_offset.h>
42#endif
43
[437ee6a4]44.register %g2, #scratch
45.register %g3, #scratch
46
[2a99fa8]47.section K_TEXT_START, "ax"
48
[f2ea5d8]49#define BSP_FLAG 1
50
[965dc18]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
[c1e43e4]61/*
[f2ea5d8]62 * Here is where the kernel is passed control from the boot loader.
[4872160]63 *
[94d614e]64 * The registers are expected to be in this state:
[b97b348]65 * - %o0 starting address of physical memory
[4872160]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
[b97b348]69 * - %o1 bootinfo structure address (BSP only)
70 *
[10b890b]71 *
[f2ea5d8]72 * Moreover, we depend on boot having established the following environment:
[4872160]73 * - TLBs are on
74 * - identity mapping for the kernel image
75 *
[c1e43e4]76 */
77
[2a99fa8]78.global kernel_image_start
79kernel_image_start:
[f2ea5d8]80 mov BSP_FLAG, %l0
[b97b348]81 and %o0, %l0, %l7 ! l7 <= bootstrap processor?
82 andn %o0, %l0, %l6 ! l6 <= start of physical memory
[f2ea5d8]83
[965dc18]84 ! Get bits (PHYSMEM_ADDR_SIZE - 1):13 of physmem_base.
[79f119b9]85 srlx %l6, 13, %l5
[965dc18]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
[2bf4936]90
[94d614e]91 /*
[e386cbf]92 * Setup basic runtime environment.
[94d614e]93 */
[e386cbf]94
[8440473]95 wrpr %g0, NWINDOWS - 2, %cansave ! set maximum saveable windows
[7e7c8747]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
[965dc18]102
103 wrpr %g0, 0, %wstate ! use default spill/fill trap
[e386cbf]104
[7e7c8747]105 wrpr %g0, 0, %tl ! TL = 0, primary context
106 ! register is used
[e386cbf]107
[7e7c8747]108 wrpr %g0, PSTATE_PRIV_BIT, %pstate ! disable interrupts and disable
109 ! 32-bit address masking
[9a5b556]110
111 wrpr %g0, 0, %pil ! intialize %pil
[0ffa3ef5]112
[10b890b]113 /*
[e386cbf]114 * Switch to kernel trap table.
115 */
[7bb6b06]116 sethi %hi(trap_table), %g1
117 wrpr %g1, %lo(trap_table), %tba
[e386cbf]118
119 /*
[8dbc18c]120 * Take over the DMMU by installing locked TTE entry identically
[7e7c8747]121 * mapping the first 4M of memory.
[10b890b]122 *
[7e7c8747]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.
[10b890b]126 */
127
[e386cbf]128 wr %g0, ASI_DMMU, %asi
129
130#define SET_TLB_DEMAP_CMD(r1, context_id) \
[7e7c8747]131 set (TLB_DEMAP_CONTEXT << TLB_DEMAP_TYPE_SHIFT) | (context_id << \
132 TLB_DEMAP_CONTEXT_SHIFT), %r1
[e386cbf]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) \
[7e7c8747]140 set VMA | (context << TLB_TAG_ACCESS_CONTEXT_SHIFT), %r1
[e386cbf]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
[92778f2]147#ifdef CONFIG_VIRT_IDX_DCACHE
[44d0758]148#define TTE_LOW_DATA(imm) (TTE_CP | TTE_CV | TTE_P | LMA | (imm))
[92778f2]149#else /* CONFIG_VIRT_IDX_DCACHE */
[44d0758]150#define TTE_LOW_DATA(imm) (TTE_CP | TTE_P | LMA | (imm))
[92778f2]151#endif /* CONFIG_VIRT_IDX_DCACHE */
[44d0758]152
[e386cbf]153#define SET_TLB_DATA(r1, r2, imm) \
[44d0758]154 set TTE_LOW_DATA(imm), %r1; \
[f2ea5d8]155 or %r1, %l5, %r1; \
156 mov PAGESIZE_4M, %r2; \
[e386cbf]157 sllx %r2, TTE_SIZE_SHIFT, %r2; \
158 or %r1, %r2, %r1; \
[7bb6b06]159 mov 1, %r2; \
[e386cbf]160 sllx %r2, TTE_V_SHIFT, %r2; \
161 or %r1, %r2, %r1;
162
163 ! write DTLB data and install the kernel mapping
[e5ecc02]164 SET_TLB_DATA(g1, g2, TTE_L | TTE_W) ! use non-global mapping
[d681c17]165 stxa %g1, [%g0] ASI_DTLB_DATA_IN_REG
166 membar #Sync
167
168 /*
[7e7c8747]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.
[d681c17]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
[e5ecc02]180 SET_TLB_DATA(g1, g2, TTE_W) ! use non-global mapping
[e386cbf]181 stxa %g1, [%g0] ASI_DTLB_DATA_IN_REG
182 membar #Sync
183
184 /*
[7e7c8747]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.
[e386cbf]188 *
[7e7c8747]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. ]
[e386cbf]192 *
[7e7c8747]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.
[e386cbf]198 *
[7e7c8747]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.
[e386cbf]202 */
203
[a7961271]204 set kernel_image_start, %g5
[e386cbf]205
206 ! write ITLB tag of context 1
207 SET_TLB_TAG(g1, MEM_CONTEXT_TEMP)
[7bb6b06]208 mov VA_DMMU_TAG_ACCESS, %g2
[e386cbf]209 stxa %g1, [%g2] ASI_IMMU
[a7961271]210 flush %g5
[e386cbf]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
[a7961271]215 flush %g5
[e386cbf]216
217 ! switch to context 1
[7bb6b06]218 mov MEM_CONTEXT_TEMP, %g1
[e386cbf]219 stxa %g1, [VA_PRIMARY_CONTEXT_REG] %asi ! ASI_DMMU is correct here !!!
[a7961271]220 flush %g5
[e386cbf]221
222 ! demap context 0
223 SET_TLB_DEMAP_CMD(g1, TLB_DEMAP_NUCLEUS)
224 stxa %g0, [%g1] ASI_IMMU_DEMAP
[a7961271]225 flush %g5
[e386cbf]226
227 ! write ITLB tag of context 0
228 SET_TLB_TAG(g1, MEM_CONTEXT_KERNEL)
[7bb6b06]229 mov VA_DMMU_TAG_ACCESS, %g2
[e386cbf]230 stxa %g1, [%g2] ASI_IMMU
[a7961271]231 flush %g5
[e386cbf]232
233 ! write ITLB data and install the permanent kernel mapping in context 0
[e5ecc02]234 SET_TLB_DATA(g1, g2, TTE_L) ! use non-global mapping
[e386cbf]235 stxa %g1, [%g0] ASI_ITLB_DATA_IN_REG
[a7961271]236 flush %g5
[e386cbf]237
[398e7688]238 ! enter nucleus - using context 0
[e386cbf]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
[a7961271]244 flush %g5
[e386cbf]245
246 ! set context 0 in the primary context register
247 stxa %g0, [VA_PRIMARY_CONTEXT_REG] %asi ! ASI_DMMU is correct here !!!
[a7961271]248 flush %g5
[e386cbf]249
[398e7688]250 ! leave nucleus - using primary context, i.e. context 0
[e386cbf]251 wrpr %g0, 0, %tl
[cfa70add]252
[a9ac978]253 brz %l7, 1f ! skip if you are not the bootstrap CPU
254 nop
[b44939b]255
[79f119b9]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.
[965dc18]265 * %l5 contains starting physical address
266 * bits [(PHYSMEM_ADDR_SIZE - 1):13]
[79f119b9]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)]
[b97b348]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
[84060e2]284 /*
285 * So far, we have not touched the stack.
[3869e9c5]286 * It is a good idea to set the kernel stack to a known state now.
[84060e2]287 */
288 sethi %hi(temporary_boot_stack), %sp
289 or %sp, %lo(temporary_boot_stack), %sp
290 sub %sp, STACK_BIAS, %sp
[b97b348]291
292 /*
293 * Call arch_pre_main(bootinfo)
294 */
[cfa70add]295 call arch_pre_main
[d806ce1]296 mov %o1, %o0
[e386cbf]297
[7f1d897]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
[437ee6a4]305 call main_bsp
306 nop
307
308 /* Not reached. */
309
[a9ac978]3100:
[d806ce1]311 ba,a %xcc, 0b
[a9ac978]312
313
[965dc18]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
[a9ac978]333 /*
334 * Read MID from the processor.
335 */
[965dc18]336 ldxa [%g0] ASI_ICBUS_CONFIG, %g1
337 srlx %g1, ICBUS_CONFIG_MID_SHIFT, %g1
338 and %g1, %g3, %g1
[a9ac978]339
340 /*
[7e7c8747]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
[a9ac978]343 * MID.
344 */
345 set waking_up_mid, %g2
[39cb79a]3462:
[a9ac978]347 ldx [%g2], %g3
348 cmp %g3, %g1
[2bf4936]349 bne %xcc, 2b
[a9ac978]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
[7f1d897]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
[a9ac978]368 call main_ap
369 nop
370
371 /* Not reached. */
[c23baab]372#endif
[a9ac978]373
3740:
[d806ce1]375 ba,a %xcc, 0b
[84060e2]376
377
378.section K_DATA_START, "aw", @progbits
379
380/*
[7e7c8747]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.
[84060e2]384 */
385
386#define INITIAL_STACK_SIZE 1024
387
388.align STACK_ALIGNMENT
[f2ea5d8]389 .space INITIAL_STACK_SIZE
[84060e2]390.align STACK_ALIGNMENT
391temporary_boot_stack:
[f2ea5d8]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/*
[2bf4936]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.
[f2ea5d8]406 */
[2bf4936]407.global fast_data_access_mmu_miss_data_hi
408.global end_of_identity
[f2ea5d8]409.global kernel_8k_tlb_data_template
[2bf4936]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 */
[f2ea5d8]428kernel_8k_tlb_data_template:
[92778f2]429#ifdef CONFIG_VIRT_IDX_DCACHE
[7e7c8747]430 .quad ((1 << TTE_V_SHIFT) | (PAGESIZE_8K << TTE_SIZE_SHIFT) | TTE_CP | \
431 TTE_CV | TTE_P | TTE_W)
[92778f2]432#else /* CONFIG_VIRT_IDX_DCACHE */
[7e7c8747]433 .quad ((1 << TTE_V_SHIFT) | (PAGESIZE_8K << TTE_SIZE_SHIFT) | TTE_CP | \
434 TTE_P | TTE_W)
[92778f2]435#endif /* CONFIG_VIRT_IDX_DCACHE */
[7e7c8747]436
Note: See TracBrowser for help on using the repository browser.