^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1994, 1995 Waldorf Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Written by Ralf Baechle and Andreas Busse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 1994 - 99, 2003, 06 Ralf Baechle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 1996 Paul M. Antoine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Modified for DECStation and hence R3000 support by Paul M. Antoine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Further modifications by David S. Miller and Harald Koerfgen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (C) 1999 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/threads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/addrspace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/asmmacro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/irqflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/regdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/mipsregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/stackframe.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <kernel-entry-init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * For the moment disable interrupts, mark the kernel mode and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * set ST0_KX so that the CPU does not spit fire when using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * 64-bit addresses. A full initialization of the CPU's status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * register is done later in per_cpu_trap_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .macro setup_c0_status set clr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .set push
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) mfc0 t0, CP0_STATUS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) or t0, ST0_KERNEL_CUMASK|\set|0x1f|\clr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) xor t0, 0x1f|\clr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) mtc0 t0, CP0_STATUS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .set noreorder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) sll zero,3 # ehb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .set pop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .macro setup_c0_status_pri
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) setup_c0_status ST0_KX 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) setup_c0_status 0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .macro setup_c0_status_sec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) setup_c0_status ST0_KX ST0_BEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) setup_c0_status 0 ST0_BEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #ifndef CONFIG_NO_EXCEPT_FILL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Reserved space for exception handlers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * Necessary for machines which link their kernels at KSEG0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .fill 0x400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) EXPORT(_stext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #ifdef CONFIG_BOOT_RAW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * Give us a fighting chance of running if execution beings at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * kernel load address. This is needed because this platform does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * not have a ELF loader yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) FEXPORT(__kernel_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) j kernel_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #endif /* CONFIG_BOOT_RAW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __REF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) NESTED(kernel_entry, 16, sp) # kernel entry point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) kernel_entry_setup # cpu specific setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) setup_c0_status_pri
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* We might not get launched at the address the kernel is linked to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) so we jump there. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) PTR_LA t0, 0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) jr t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #ifdef CONFIG_USE_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #if defined(CONFIG_MIPS_RAW_APPENDED_DTB) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) defined(CONFIG_MIPS_ELF_APPENDED_DTB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) PTR_LA t2, __appended_dtb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #ifdef CONFIG_CPU_BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) li t1, 0xd00dfeed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #else /* !CONFIG_CPU_BIG_ENDIAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) li t1, 0xedfe0dd0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #endif /* !CONFIG_CPU_BIG_ENDIAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) lw t0, (t2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) beq t0, t1, dtb_found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #endif /* CONFIG_MIPS_RAW_APPENDED_DTB || CONFIG_MIPS_ELF_APPENDED_DTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) li t1, -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) move t2, a1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) beq a0, t1, dtb_found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #ifdef CONFIG_BUILTIN_DTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) PTR_LA t2, __dtb_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) PTR_LA t1, __dtb_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) bne t1, t2, dtb_found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #endif /* CONFIG_BUILTIN_DTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) li t2, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) dtb_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #endif /* CONFIG_USE_OF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) PTR_LA t0, __bss_start # clear .bss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) LONG_S zero, (t0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) PTR_LA t1, __bss_stop - LONGSIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) PTR_ADDIU t0, LONGSIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) LONG_S zero, (t0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) bne t0, t1, 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) LONG_S a0, fw_arg0 # firmware arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) LONG_S a1, fw_arg1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) LONG_S a2, fw_arg2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) LONG_S a3, fw_arg3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #ifdef CONFIG_USE_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) LONG_S t2, fw_passed_dtb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) MTC0 zero, CP0_CONTEXT # clear context register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) MTC0 zero, CP0_XCONTEXT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) PTR_LA $28, init_thread_union
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* Set the SP after an empty pt_regs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) PTR_ADDU sp, $28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) back_to_back_c0_hazard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) set_saved_sp sp, t0, t1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) PTR_SUBU sp, 4 * SZREG # init stack pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #ifdef CONFIG_RELOCATABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* Copy kernel and apply the relocations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) jal relocate_kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Repoint the sp into the new kernel image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) PTR_ADDU sp, $28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) set_saved_sp sp, t0, t1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) PTR_SUBU sp, 4 * SZREG # init stack pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * relocate_kernel returns the entry point either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * in the relocated kernel or the original if for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * some reason relocation failed - jump there now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * with instruction hazard barrier because of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * newly sync'd icache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) jr.hb v0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #else /* !CONFIG_RELOCATABLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) j start_kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #endif /* !CONFIG_RELOCATABLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) END(kernel_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * SMP slave cpus entry point. Board specific code for bootstrap calls this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * function after setting up the stack and gp registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) NESTED(smp_bootstrap, 16, sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) smp_slave_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) setup_c0_status_sec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) j start_secondary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) END(smp_bootstrap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #endif /* CONFIG_SMP */