/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 1994, 1995 Waldorf Electronics6* Written by Ralf Baechle and Andreas Busse7* Copyright (C) 1994 - 99, 2003, 06 Ralf Baechle8* Copyright (C) 1996 Paul M. Antoine9* Modified for DECStation and hence R3000 support by Paul M. Antoine10* Further modifications by David S. Miller and Harald Koerfgen11* Copyright (C) 1999 Silicon Graphics, Inc.12* Kevin Kissell, [email protected] and Carsten Langgaard, [email protected]13* Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.14*/15#include <linux/init.h>16#include <linux/threads.h>1718#include <asm/addrspace.h>19#include <asm/asm.h>20#include <asm/asmmacro.h>21#include <asm/irqflags.h>22#include <asm/regdef.h>23#include <asm/page.h>24#include <asm/pgtable-bits.h>25#include <asm/mipsregs.h>26#include <asm/stackframe.h>2728#include <kernel-entry-init.h>2930/*31* inputs are the text nasid in t1, data nasid in t2.32*/33.macro MAPPED_KERNEL_SETUP_TLB34#ifdef CONFIG_MAPPED_KERNEL35/*36* This needs to read the nasid - assume 0 for now.37* Drop in 0xffffffffc0000000 in tlbhi, 0+VG in tlblo_0,38* 0+DVG in tlblo_1.39*/40dli t0, 0xffffffffc000000041dmtc0 t0, CP0_ENTRYHI42li t0, 0x1c000 # Offset of text into node memory43dsll t1, NASID_SHFT # Shift text nasid into place44dsll t2, NASID_SHFT # Same for data nasid45or t1, t1, t0 # Physical load address of kernel text46or t2, t2, t0 # Physical load address of kernel data47dsrl t1, 12 # 4K pfn48dsrl t2, 12 # 4K pfn49dsll t1, 6 # Get pfn into place50dsll t2, 6 # Get pfn into place51li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _CACHE_CACHABLE_COW) >> 6)52or t0, t0, t153mtc0 t0, CP0_ENTRYLO0 # physaddr, VG, cach exlwr54li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _PAGE_DIRTY|_CACHE_CACHABLE_COW) >> 6)55or t0, t0, t256mtc0 t0, CP0_ENTRYLO1 # physaddr, DVG, cach exlwr57li t0, 0x1ffe000 # MAPPED_KERN_TLBMASK, TLBPGMASK_16M58mtc0 t0, CP0_PAGEMASK59li t0, 0 # KMAP_INX60mtc0 t0, CP0_INDEX61li t0, 162mtc0 t0, CP0_WIRED63tlbwi64#else65mtc0 zero, CP0_WIRED66#endif67.endm6869/*70* For the moment disable interrupts, mark the kernel mode and71* set ST0_KX so that the CPU does not spit fire when using72* 64-bit addresses. A full initialization of the CPU's status73* register is done later in per_cpu_trap_init().74*/75.macro setup_c0_status set clr76.set push77#ifdef CONFIG_MIPS_MT_SMTC78/*79* For SMTC, we need to set privilege and disable interrupts only for80* the current TC, using the TCStatus register.81*/82mfc0 t0, CP0_TCSTATUS83/* Fortunately CU 0 is in the same place in both registers */84/* Set TCU0, TMX, TKSU (for later inversion) and IXMT */85li t1, ST0_CU0 | 0x08001c0086or t0, t187/* Clear TKSU, leave IXMT */88xori t0, 0x0000180089mtc0 t0, CP0_TCSTATUS90_ehb91/* We need to leave the global IE bit set, but clear EXL...*/92mfc0 t0, CP0_STATUS93or t0, ST0_CU0 | ST0_EXL | ST0_ERL | \set | \clr94xor t0, ST0_EXL | ST0_ERL | \clr95mtc0 t0, CP0_STATUS96#else97mfc0 t0, CP0_STATUS98or t0, ST0_CU0|\set|0x1f|\clr99xor t0, 0x1f|\clr100mtc0 t0, CP0_STATUS101.set noreorder102sll zero,3 # ehb103#endif104.set pop105.endm106107.macro setup_c0_status_pri108#ifdef CONFIG_64BIT109setup_c0_status ST0_KX 0110#else111setup_c0_status 0 0112#endif113.endm114115.macro setup_c0_status_sec116#ifdef CONFIG_64BIT117setup_c0_status ST0_KX ST0_BEV118#else119setup_c0_status 0 ST0_BEV120#endif121.endm122123#ifndef CONFIG_NO_EXCEPT_FILL124/*125* Reserved space for exception handlers.126* Necessary for machines which link their kernels at KSEG0.127*/128.fill 0x400129#endif130131EXPORT(_stext)132133#ifdef CONFIG_BOOT_RAW134/*135* Give us a fighting chance of running if execution beings at the136* kernel load address. This is needed because this platform does137* not have a ELF loader yet.138*/139FEXPORT(__kernel_entry)140j kernel_entry141#endif142143__REF144145NESTED(kernel_entry, 16, sp) # kernel entry point146147kernel_entry_setup # cpu specific setup148149setup_c0_status_pri150151/* We might not get launched at the address the kernel is linked to,152so we jump there. */153PTR_LA t0, 0f154jr t01550:156157#ifdef CONFIG_MIPS_MT_SMTC158/*159* In SMTC kernel, "CLI" is thread-specific, in TCStatus.160* We still need to enable interrupts globally in Status,161* and clear EXL/ERL.162*163* TCContext is used to track interrupt levels under164* service in SMTC kernel. Clear for boot TC before165* allowing any interrupts.166*/167mtc0 zero, CP0_TCCONTEXT168169mfc0 t0, CP0_STATUS170ori t0, t0, 0xff1f171xori t0, t0, 0x001e172mtc0 t0, CP0_STATUS173#endif /* CONFIG_MIPS_MT_SMTC */174175PTR_LA t0, __bss_start # clear .bss176LONG_S zero, (t0)177PTR_LA t1, __bss_stop - LONGSIZE1781:179PTR_ADDIU t0, LONGSIZE180LONG_S zero, (t0)181bne t0, t1, 1b182183LONG_S a0, fw_arg0 # firmware arguments184LONG_S a1, fw_arg1185LONG_S a2, fw_arg2186LONG_S a3, fw_arg3187188MTC0 zero, CP0_CONTEXT # clear context register189PTR_LA $28, init_thread_union190/* Set the SP after an empty pt_regs. */191PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE192PTR_ADDU sp, $28193back_to_back_c0_hazard194set_saved_sp sp, t0, t1195PTR_SUBU sp, 4 * SZREG # init stack pointer196197j start_kernel198END(kernel_entry)199200__CPUINIT201202#ifdef CONFIG_SMP203/*204* SMP slave cpus entry point. Board specific code for bootstrap calls this205* function after setting up the stack and gp registers.206*/207NESTED(smp_bootstrap, 16, sp)208#ifdef CONFIG_MIPS_MT_SMTC209/*210* Read-modify-writes of Status must be atomic, and this211* is one case where CLI is invoked without EXL being212* necessarily set. The CLI and setup_c0_status will213* in fact be redundant for all but the first TC of214* each VPE being booted.215*/216DMT 10 # dmt t2 /* t0, t1 are used by CLI and setup_c0_status() */217jal mips_ihb218#endif /* CONFIG_MIPS_MT_SMTC */219setup_c0_status_sec220smp_slave_setup221#ifdef CONFIG_MIPS_MT_SMTC222andi t2, t2, VPECONTROL_TE223beqz t2, 2f224EMT # emt2252:226#endif /* CONFIG_MIPS_MT_SMTC */227j start_secondary228END(smp_bootstrap)229#endif /* CONFIG_SMP */230231__FINIT232233234