blob: d1bb506adc1044d6b72585ae5972fd200e224a89 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994, 1995 Waldorf Electronics
7 * Written by Ralf Baechle and Andreas Busse
Ralf Baechle192ef362006-07-07 14:07:18 +01008 * Copyright (C) 1994 - 99, 2003, 06 Ralf Baechle
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Copyright (C) 1996 Paul M. Antoine
10 * Modified for DECStation and hence R3000 support by Paul M. Antoine
11 * Further modifications by David S. Miller and Harald Koerfgen
12 * Copyright (C) 1999 Silicon Graphics, Inc.
13 * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
14 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/init.h>
17#include <linux/threads.h>
18
Marc St-Jean9267a302007-06-14 15:55:31 -060019#include <asm/addrspace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/asm.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +010021#include <asm/asmmacro.h>
Ralf Baechle192ef362006-07-07 14:07:18 +010022#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/regdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/mipsregs.h>
25#include <asm/stackframe.h>
Ralf Baechle7e359522005-07-14 09:42:32 +000026
27#include <kernel-entry-init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * For the moment disable interrupts, mark the kernel mode and
31 * set ST0_KX so that the CPU does not spit fire when using
32 * 64-bit addresses. A full initialization of the CPU's status
33 * register is done later in per_cpu_trap_init().
34 */
35 .macro setup_c0_status set clr
36 .set push
37 mfc0 t0, CP0_STATUS
38 or t0, ST0_CU0|\set|0x1f|\clr
39 xor t0, 0x1f|\clr
40 mtc0 t0, CP0_STATUS
41 .set noreorder
42 sll zero,3 # ehb
43 .set pop
44 .endm
45
46 .macro setup_c0_status_pri
Ralf Baechle875d43e2005-09-03 15:56:16 -070047#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 setup_c0_status ST0_KX 0
49#else
50 setup_c0_status 0 0
51#endif
52 .endm
53
54 .macro setup_c0_status_sec
Ralf Baechle875d43e2005-09-03 15:56:16 -070055#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 setup_c0_status ST0_KX ST0_BEV
57#else
58 setup_c0_status 0 ST0_BEV
59#endif
60 .endm
61
Marc St-Jean9267a302007-06-14 15:55:31 -060062#ifndef CONFIG_NO_EXCEPT_FILL
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 /*
64 * Reserved space for exception handlers.
65 * Necessary for machines which link their kernels at KSEG0.
66 */
67 .fill 0x400
Marc St-Jean9267a302007-06-14 15:55:31 -060068#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070EXPORT(_stext)
71
Ralf Baechle396a2ae2007-10-16 20:05:18 +010072#ifdef CONFIG_BOOT_RAW
Ralf Baechleb490ff42005-07-11 11:53:44 +000073 /*
74 * Give us a fighting chance of running if execution beings at the
Ralf Baechle70342282013-01-22 12:59:30 +010075 * kernel load address. This is needed because this platform does
Ralf Baechleb490ff42005-07-11 11:53:44 +000076 * not have a ELF loader yet.
77 */
Ralf Baechleba820c52008-01-07 15:09:50 +000078FEXPORT(__kernel_entry)
79 j kernel_entry
Ralf Baechlef6e23732007-07-10 17:32:56 +010080#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Ralf Baechlea0559172008-01-30 12:14:59 +000082 __REF
Ralf Baechle396a2ae2007-10-16 20:05:18 +010083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084NESTED(kernel_entry, 16, sp) # kernel entry point
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Ralf Baechle7e359522005-07-14 09:42:32 +000086 kernel_entry_setup # cpu specific setup
87
88 setup_c0_status_pri
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Thomas Bogendoerfer15ad8382007-09-13 20:23:48 +020090 /* We might not get launched at the address the kernel is linked to,
91 so we jump there. */
92 PTR_LA t0, 0f
93 jr t0
940:
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Jonas Gorski15f37e12016-06-20 11:27:37 +020096#ifdef CONFIG_USE_OF
Jonas Gorski1da8f172015-04-12 12:24:58 +020097#ifdef CONFIG_MIPS_RAW_APPENDED_DTB
Jonas Gorski15f37e12016-06-20 11:27:37 +020098 PTR_LA t2, __appended_dtb
Jonas Gorski1da8f172015-04-12 12:24:58 +020099
100#ifdef CONFIG_CPU_BIG_ENDIAN
101 li t1, 0xd00dfeed
102#else
103 li t1, 0xedfe0dd0
104#endif
Jonas Gorski15f37e12016-06-20 11:27:37 +0200105 lw t0, (t2)
106 beq t0, t1, dtb_found
107#endif
108 li t1, -2
Jonas Gorski15f37e12016-06-20 11:27:37 +0200109 move t2, a1
Karl Beldan3d4ac492017-06-27 19:22:16 +0000110 beq a0, t1, dtb_found
Jonas Gorski1da8f172015-04-12 12:24:58 +0200111
Jonas Gorski15f37e12016-06-20 11:27:37 +0200112 li t2, 0
113dtb_found:
Jonas Gorski1da8f172015-04-12 12:24:58 +0200114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 PTR_LA t0, __bss_start # clear .bss
116 LONG_S zero, (t0)
117 PTR_LA t1, __bss_stop - LONGSIZE
1181:
119 PTR_ADDIU t0, LONGSIZE
120 LONG_S zero, (t0)
121 bne t0, t1, 1b
122
123 LONG_S a0, fw_arg0 # firmware arguments
124 LONG_S a1, fw_arg1
125 LONG_S a2, fw_arg2
126 LONG_S a3, fw_arg3
127
Jonas Gorski15f37e12016-06-20 11:27:37 +0200128#ifdef CONFIG_USE_OF
129 LONG_S t2, fw_passed_dtb
130#endif
131
Thiemo Seufer1b3a6e92005-04-01 14:07:13 +0000132 MTC0 zero, CP0_CONTEXT # clear context register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 PTR_LA $28, init_thread_union
David Daney484889f2009-07-08 10:07:50 -0700134 /* Set the SP after an empty pt_regs. */
135 PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
Ralf Baechle242954b2006-10-24 02:29:01 +0100136 PTR_ADDU sp, $28
Ralf Baechlec2ea1d52009-10-13 23:23:28 +0200137 back_to_back_c0_hazard
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 set_saved_sp sp, t0, t1
139 PTR_SUBU sp, 4 * SZREG # init stack pointer
140
Matt Redfearnaf09ab52016-03-31 10:05:37 +0100141#ifdef CONFIG_RELOCATABLE
142 /* Copy kernel and apply the relocations */
143 jal relocate_kernel
144
145 /* Repoint the sp into the new kernel image */
146 PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
147 PTR_ADDU sp, $28
148 set_saved_sp sp, t0, t1
149 PTR_SUBU sp, 4 * SZREG # init stack pointer
150
151 /*
152 * relocate_kernel returns the entry point either
153 * in the relocated kernel or the original if for
154 * some reason relocation failed - jump there now
155 * with instruction hazard barrier because of the
156 * newly sync'd icache.
157 */
158 jr.hb v0
159#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 j start_kernel
Matt Redfearnaf09ab52016-03-31 10:05:37 +0100161#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 END(kernel_entry)
163
164#ifdef CONFIG_SMP
165/*
Ralf Baechle70342282013-01-22 12:59:30 +0100166 * SMP slave cpus entry point. Board specific code for bootstrap calls this
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * function after setting up the stack and gp registers.
168 */
169NESTED(smp_bootstrap, 16, sp)
Ralf Baechle7e359522005-07-14 09:42:32 +0000170 smp_slave_setup
Markos Chandrasd0ba3542014-01-21 09:52:23 +0000171 setup_c0_status_sec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 j start_secondary
173 END(smp_bootstrap)
174#endif /* CONFIG_SMP */