1 /* $Id: head.S,v 1.87 2002/02/09 19:49:31 davem Exp $
2 * head.S: Initial boot code for the Sparc64 port of Linux.
4 * Copyright (C) 1996,1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 David Sitsky (David.Sitsky@anu.edu.au)
6 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
10 #include <linux/config.h>
11 #include <linux/version.h>
12 #include <linux/errno.h>
13 #include <linux/threads.h>
14 #include <asm/thread_info.h>
16 #include <asm/pstate.h>
17 #include <asm/ptrace.h>
18 #include <asm/spitfire.h>
20 #include <asm/pgtable.h>
21 #include <asm/errno.h>
22 #include <asm/signal.h>
23 #include <asm/processor.h>
28 #include <asm/ttable.h>
30 #include <asm/cpudata.h>
32 /* This section from from _start to sparc64_boot_end should fit into
33 * 0x0000000000404000 to 0x0000000000408000.
36 .globl start, _start, stext, _stext
43 flushw /* Flush register file. */
45 /* This stuff has to be in sync with SILO and other potential boot loaders
46 * Fields should be kept upward compatible and whenever any change is made,
47 * HdrS version should be incremented.
49 .global root_flags, ram_flags, root_dev
50 .global sparc_ramdisk_image, sparc_ramdisk_size
51 .global sparc_ramdisk_image64
54 .word LINUX_VERSION_CODE
58 * 0x0300 : Supports being located at other than 0x4000
59 * 0x0202 : Supports kernel params string
60 * 0x0201 : Supports reboot_command
62 .half 0x0301 /* HdrS version */
76 sparc_ramdisk_image64:
80 /* PROM cif handler code address is in %o4. */
85 be,pn %xcc, sparc64_boot_after_remap
88 /* We need to remap the kernel. Use position independant
89 * code to remap us to KERNBASE.
91 * SILO can invoke us with 32-bit address masking enabled,
92 * so make sure that's clear.
95 andn %g1, PSTATE_AM, %g1
96 wrpr %g1, 0x0, %pstate
99 .globl prom_finddev_name, prom_chosen_path, prom_root_node
100 .globl prom_getprop_name, prom_mmu_name, prom_peer_name
101 .globl prom_callmethod_name, prom_translate_name, prom_root_compatible
102 .globl prom_map_name, prom_unmap_name, prom_mmu_ihandle_cache
103 .globl prom_boot_mapped_pc, prom_boot_mapping_mode
104 .globl prom_boot_mapping_phys_high, prom_boot_mapping_phys_low
108 prom_compatible_name:
118 prom_callmethod_name:
129 prom_root_compatible:
133 prom_mmu_ihandle_cache:
137 prom_boot_mapping_mode:
140 prom_boot_mapping_phys_high:
142 prom_boot_mapping_phys_low:
149 mov (1b - prom_peer_name), %l1
153 /* prom_root_node = prom_peer(0) */
154 stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "peer"
156 stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
157 stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
158 stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, 0
159 stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
161 add %sp, (2047 + 128), %o0 ! argument array
163 ldx [%sp + 2047 + 128 + 0x20], %l4 ! prom root node
164 mov (1b - prom_root_node), %l1
168 mov (1b - prom_getprop_name), %l1
169 mov (1b - prom_compatible_name), %l2
170 mov (1b - prom_root_compatible), %l5
175 /* prom_getproperty(prom_root_node, "compatible",
176 * &prom_root_compatible, 64)
178 stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
180 stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
182 stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
183 stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, prom_root_node
184 stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "compatible"
185 stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_root_compatible
187 stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, size
188 stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
190 add %sp, (2047 + 128), %o0 ! argument array
192 mov (1b - prom_finddev_name), %l1
193 mov (1b - prom_chosen_path), %l2
194 mov (1b - prom_boot_mapped_pc), %l3
199 sub %sp, (192 + 128), %sp
201 /* chosen_node = prom_finddevice("/chosen") */
202 stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "finddevice"
204 stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 1
205 stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
206 stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1, "/chosen"
207 stx %g0, [%sp + 2047 + 128 + 0x20] ! ret1
209 add %sp, (2047 + 128), %o0 ! argument array
211 ldx [%sp + 2047 + 128 + 0x20], %l4 ! chosen device node
213 mov (1b - prom_getprop_name), %l1
214 mov (1b - prom_mmu_name), %l2
215 mov (1b - prom_mmu_ihandle_cache), %l5
220 /* prom_mmu_ihandle_cache = prom_getint(chosen_node, "mmu") */
221 stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "getprop"
223 stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 4
225 stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
226 stx %l4, [%sp + 2047 + 128 + 0x18] ! arg1, chosen_node
227 stx %l2, [%sp + 2047 + 128 + 0x20] ! arg2, "mmu"
228 stx %l5, [%sp + 2047 + 128 + 0x28] ! arg3, &prom_mmu_ihandle_cache
230 stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4, sizeof(arg3)
231 stx %g0, [%sp + 2047 + 128 + 0x38] ! ret1
233 add %sp, (2047 + 128), %o0 ! argument array
235 mov (1b - prom_callmethod_name), %l1
236 mov (1b - prom_translate_name), %l2
239 lduw [%l5], %l5 ! prom_mmu_ihandle_cache
241 stx %l1, [%sp + 2047 + 128 + 0x00] ! service, "call-method"
243 stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 3
245 stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 5
246 stx %l2, [%sp + 2047 + 128 + 0x18] ! arg1: "translate"
247 stx %l5, [%sp + 2047 + 128 + 0x20] ! arg2: prom_mmu_ihandle_cache
251 stx %l3, [%sp + 2047 + 128 + 0x28] ! arg3: vaddr, our PC
252 stx %g0, [%sp + 2047 + 128 + 0x30] ! res1
253 stx %g0, [%sp + 2047 + 128 + 0x38] ! res2
254 stx %g0, [%sp + 2047 + 128 + 0x40] ! res3
255 stx %g0, [%sp + 2047 + 128 + 0x48] ! res4
256 stx %g0, [%sp + 2047 + 128 + 0x50] ! res5
258 add %sp, (2047 + 128), %o0 ! argument array
260 ldx [%sp + 2047 + 128 + 0x40], %l1 ! translation mode
261 mov (1b - prom_boot_mapping_mode), %l4
264 mov (1b - prom_boot_mapping_phys_high), %l4
266 ldx [%sp + 2047 + 128 + 0x48], %l2 ! physaddr high
268 ldx [%sp + 2047 + 128 + 0x50], %l3 ! physaddr low
274 /* Leave service as-is, "call-method" */
276 stx %l3, [%sp + 2047 + 128 + 0x08] ! num_args, 7
278 stx %l3, [%sp + 2047 + 128 + 0x10] ! num_rets, 1
279 mov (1b - prom_map_name), %l3
281 stx %l3, [%sp + 2047 + 128 + 0x18] ! arg1: "map"
282 /* Leave arg2 as-is, prom_mmu_ihandle_cache */
284 stx %l3, [%sp + 2047 + 128 + 0x28] ! arg3: mode (-1 default)
285 sethi %hi(8 * 1024 * 1024), %l3
286 stx %l3, [%sp + 2047 + 128 + 0x30] ! arg4: size (8MB)
287 sethi %hi(KERNBASE), %l3
288 stx %l3, [%sp + 2047 + 128 + 0x38] ! arg5: vaddr (KERNBASE)
289 stx %g0, [%sp + 2047 + 128 + 0x40] ! arg6: empty
290 mov (1b - prom_boot_mapping_phys_low), %l3
293 stx %l3, [%sp + 2047 + 128 + 0x48] ! arg7: phys addr
295 add %sp, (2047 + 128), %o0 ! argument array
297 add %sp, (192 + 128), %sp
299 sparc64_boot_after_remap:
300 sethi %hi(prom_root_compatible), %g1
301 or %g1, %lo(prom_root_compatible), %g1
302 sethi %hi(prom_sun4v_name), %g7
303 or %g7, %lo(prom_sun4v_name), %g7
314 sethi %hi(is_sun4v), %g1
315 or %g1, %lo(is_sun4v), %g1
320 BRANCH_IF_SUN4V(g1, jump_to_sun4u_init)
321 BRANCH_IF_CHEETAH_BASE(g1,g7,cheetah_boot)
322 BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,cheetah_plus_boot)
323 ba,pt %xcc, spitfire_boot
327 /* Preserve OBP chosen DCU and DCR register settings. */
328 ba,pt %xcc, cheetah_generic_boot
332 mov DCR_BPE | DCR_RPE | DCR_SI | DCR_IFPOE | DCR_MS, %g1
335 sethi %uhi(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
336 or %g7, %ulo(DCU_ME|DCU_RE|DCU_HPE|DCU_SPE|DCU_SL|DCU_WE), %g7
338 or %g7, DCU_DM | DCU_IM | DCU_DC | DCU_IC, %g7
339 stxa %g7, [%g0] ASI_DCU_CONTROL_REG
342 cheetah_generic_boot:
343 mov TSB_EXTENSION_P, %g3
344 stxa %g0, [%g3] ASI_DMMU
345 stxa %g0, [%g3] ASI_IMMU
348 mov TSB_EXTENSION_S, %g3
349 stxa %g0, [%g3] ASI_DMMU
352 mov TSB_EXTENSION_N, %g3
353 stxa %g0, [%g3] ASI_DMMU
354 stxa %g0, [%g3] ASI_IMMU
357 ba,a,pt %xcc, jump_to_sun4u_init
360 /* Typically PROM has already enabled both MMU's and both on-chip
361 * caches, but we do it here anyway just to be paranoid.
363 mov (LSU_CONTROL_IC|LSU_CONTROL_DC|LSU_CONTROL_IM|LSU_CONTROL_DM), %g1
364 stxa %g1, [%g0] ASI_LSU_CONTROL
369 * Make sure we are in privileged mode, have address masking,
370 * using the ordinary globals and have enabled floating
373 * Again, typically PROM has left %pil at 13 or similar, and
374 * (PSTATE_PRIV | PSTATE_PEF | PSTATE_IE) in %pstate.
376 wrpr %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate
384 BRANCH_IF_SUN4V(g1, sun4v_init)
387 mov PRIMARY_CONTEXT, %g7
388 stxa %g0, [%g7] ASI_DMMU
391 mov SECONDARY_CONTEXT, %g7
392 stxa %g0, [%g7] ASI_DMMU
395 ba,pt %xcc, sun4u_continue
400 mov PRIMARY_CONTEXT, %g7
401 stxa %g0, [%g7] ASI_MMU
404 mov SECONDARY_CONTEXT, %g7
405 stxa %g0, [%g7] ASI_MMU
407 ba,pt %xcc, niagara_tlb_fixup
411 BRANCH_IF_ANY_CHEETAH(g1, g7, cheetah_tlb_fixup)
413 ba,pt %xcc, spitfire_tlb_fixup
417 mov 3, %g2 /* Set TLB type to hypervisor. */
418 sethi %hi(tlb_type), %g1
419 stw %g2, [%g1 + %lo(tlb_type)]
421 /* Patch copy/clear ops. */
422 call niagara_patch_copyops
424 call niagara_patch_bzero
426 call niagara_patch_pageops
429 /* Patch TLB/cache ops. */
430 call hypervisor_patch_cachetlbops
433 ba,pt %xcc, tlb_fixup_done
437 mov 2, %g2 /* Set TLB type to cheetah+. */
438 BRANCH_IF_CHEETAH_PLUS_OR_FOLLOWON(g1,g7,1f)
440 mov 1, %g2 /* Set TLB type to cheetah. */
442 1: sethi %hi(tlb_type), %g1
443 stw %g2, [%g1 + %lo(tlb_type)]
445 /* Patch copy/page operations to cheetah optimized versions. */
446 call cheetah_patch_copyops
448 call cheetah_patch_copy_page
450 call cheetah_patch_cachetlbops
453 ba,pt %xcc, tlb_fixup_done
457 /* Set TLB type to spitfire. */
459 sethi %hi(tlb_type), %g1
460 stw %g2, [%g1 + %lo(tlb_type)]
463 sethi %hi(init_thread_union), %g6
464 or %g6, %lo(init_thread_union), %g6
465 ldx [%g6 + TI_TASK], %g4
471 sllx %g1, THREAD_SHIFT, %g1
472 sub %g1, (STACKFRAME_SZ + STACK_BIAS), %g1
476 /* Set per-cpu pointer initially to zero, this makes
477 * the boot-cpu use the in-kernel-image per-cpu areas
478 * before setup_per_cpu_area() is invoked.
486 sethi %hi(__bss_start), %o0
487 or %o0, %lo(__bss_start), %o0
489 or %o1, %lo(_end), %o1
493 mov %l6, %o1 ! OpenPROM stack
495 mov %l7, %o0 ! OpenPROM cif handler
497 /* Initialize current_thread_info()->cpu as early as possible.
498 * In order to do that accurately we have to patch up the get_cpuid()
499 * assembler sequences. And that, in turn, requires that we know
500 * if we are on a Starfire box or not. While we're here, patch up
501 * the sun4v sequences as well.
503 call check_if_starfire
511 call hard_smp_processor_id
516 call boot_cpu_id_too_large
524 stb %o0, [%g6 + TI_CPU]
531 /* This is meant to allow the sharing of this code between
532 * boot processor invocation (via setup_tba() below) and
533 * secondary processor startup (via trampoline.S). The
534 * former does use this code, the latter does not yet due
535 * to some complexities. That should be fixed up at some
538 * There used to be enormous complexity wrt. transferring
539 * over from the firwmare's trap table to the Linux kernel's.
540 * For example, there was a chicken & egg problem wrt. building
541 * the OBP page tables, yet needing to be on the Linux kernel
542 * trap table (to translate PAGE_OFFSET addresses) in order to
545 * We now handle OBP tlb misses differently, via linear lookups
546 * into the prom_trans[] array. So that specific problem no
547 * longer exists. Yet, unfortunately there are still some issues
548 * preventing trampoline.S from using this code... ho hum.
550 .globl setup_trap_table
554 /* Force interrupts to be disabled. */
556 andn %o1, PSTATE_IE, %o1
557 wrpr %o1, 0x0, %pstate
560 /* Make the firmware call to jump over to the Linux trap table. */
561 sethi %hi(is_sun4v), %o0
562 lduw [%o0 + %lo(is_sun4v)], %o0
566 TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
567 add %g2, TRAP_PER_CPU_FAULT_INFO, %g2
568 stxa %g2, [%g0] ASI_SCRATCHPAD
570 /* Compute physical address:
572 * paddr = kern_base + (mmfsa_vaddr - KERNBASE)
574 sethi %hi(KERNBASE), %g3
576 sethi %hi(kern_base), %g3
577 ldx [%g3 + %lo(kern_base)], %g3
580 call prom_set_trap_table_sun4v
581 sethi %hi(sparc64_ttable_tl0), %o0
586 1: call prom_set_trap_table
587 sethi %hi(sparc64_ttable_tl0), %o0
589 /* Start using proper page size encodings in ctx register. */
590 2: sethi %hi(sparc64_kern_pri_context), %g3
591 ldx [%g3 + %lo(sparc64_kern_pri_context)], %g2
593 mov PRIMARY_CONTEXT, %g1
595 661: stxa %g2, [%g1] ASI_DMMU
596 .section .sun4v_1insn_patch, "ax"
598 stxa %g2, [%g1] ASI_MMU
603 /* Kill PROM timer */
604 sethi %hi(0x80000000), %o2
606 wr %o2, 0, %tick_cmpr
608 BRANCH_IF_SUN4V(o2, 1f)
609 BRANCH_IF_ANY_CHEETAH(o2, o3, 1f)
614 /* Disable STICK_INT interrupts. */
616 sethi %hi(0x80000000), %o2
621 wrpr %g0, %g0, %wstate
623 call init_irqwork_curcpu
626 /* Now we can turn interrupts back on. */
628 or %o1, PSTATE_IE, %o1
639 /* The boot processor is the only cpu which invokes this
640 * routine, the other cpus set things up via trampoline.S.
641 * So save the OBP trap table address here.
644 sethi %hi(prom_tba), %o1
645 or %o1, %lo(prom_tba), %o1
648 call setup_trap_table
659 #include "winfixup.S"
661 #include "sun4v_tlb_miss.S"
662 #include "sun4v_ivec.S"
665 * The following skip makes sure the trap table in ttable.S is aligned
666 * on a 32K boundary as required by the v9 specs for TBA register.
668 * We align to a 32K boundary, then we have the 32K kernel TSB,
669 * then the 32K aligned trap table.
672 .skip 0x4000 + _start - 1b
686 .globl prom_tba, tlb_type
688 tlb_type: .word 0 /* Must NOT end up in BSS */
689 .section ".fixup",#alloc,#execinstr
691 .globl __ret_efault, __retl_efault
694 restore %g0, -EFAULT, %o0