blob: 7dc043349d66a491518822491440450e60f32e9d [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>
Ralf Baechlefd3d2762008-10-03 22:43:38 +010024#include <asm/pgtable-bits.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/mipsregs.h>
26#include <asm/stackframe.h>
Ralf Baechle7e359522005-07-14 09:42:32 +000027
28#include <kernel-entry-init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * For the moment disable interrupts, mark the kernel mode and
32 * set ST0_KX so that the CPU does not spit fire when using
33 * 64-bit addresses. A full initialization of the CPU's status
34 * register is done later in per_cpu_trap_init().
35 */
36 .macro setup_c0_status set clr
37 .set push
38 mfc0 t0, CP0_STATUS
39 or t0, ST0_CU0|\set|0x1f|\clr
40 xor t0, 0x1f|\clr
41 mtc0 t0, CP0_STATUS
42 .set noreorder
43 sll zero,3 # ehb
44 .set pop
45 .endm
46
47 .macro setup_c0_status_pri
Ralf Baechle875d43e2005-09-03 15:56:16 -070048#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 setup_c0_status ST0_KX 0
50#else
51 setup_c0_status 0 0
52#endif
53 .endm
54
55 .macro setup_c0_status_sec
Ralf Baechle875d43e2005-09-03 15:56:16 -070056#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 setup_c0_status ST0_KX ST0_BEV
58#else
59 setup_c0_status 0 ST0_BEV
60#endif
61 .endm
62
Marc St-Jean9267a302007-06-14 15:55:31 -060063#ifndef CONFIG_NO_EXCEPT_FILL
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 /*
65 * Reserved space for exception handlers.
66 * Necessary for machines which link their kernels at KSEG0.
67 */
68 .fill 0x400
Marc St-Jean9267a302007-06-14 15:55:31 -060069#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071EXPORT(_stext)
72
Ralf Baechle396a2ae2007-10-16 20:05:18 +010073#ifdef CONFIG_BOOT_RAW
Ralf Baechleb490ff42005-07-11 11:53:44 +000074 /*
75 * Give us a fighting chance of running if execution beings at the
Ralf Baechle70342282013-01-22 12:59:30 +010076 * kernel load address. This is needed because this platform does
Ralf Baechleb490ff42005-07-11 11:53:44 +000077 * not have a ELF loader yet.
78 */
Ralf Baechleba820c52008-01-07 15:09:50 +000079FEXPORT(__kernel_entry)
80 j kernel_entry
Ralf Baechlef6e23732007-07-10 17:32:56 +010081#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Ralf Baechlea0559172008-01-30 12:14:59 +000083 __REF
Ralf Baechle396a2ae2007-10-16 20:05:18 +010084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085NESTED(kernel_entry, 16, sp) # kernel entry point
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Ralf Baechle7e359522005-07-14 09:42:32 +000087 kernel_entry_setup # cpu specific setup
88
89 setup_c0_status_pri
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Thomas Bogendoerfer15ad8382007-09-13 20:23:48 +020091 /* We might not get launched at the address the kernel is linked to,
92 so we jump there. */
93 PTR_LA t0, 0f
94 jr t0
950:
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Jonas Gorski1da8f172015-04-12 12:24:58 +020097#ifdef CONFIG_MIPS_RAW_APPENDED_DTB
98 PTR_LA t0, __appended_dtb
99
100#ifdef CONFIG_CPU_BIG_ENDIAN
101 li t1, 0xd00dfeed
102#else
103 li t1, 0xedfe0dd0
104#endif
105 lw t2, (t0)
106 bne t1, t2, not_found
107 nop
108
109 move a1, t0
110 PTR_LI a0, -2
111not_found:
112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 PTR_LA t0, __bss_start # clear .bss
114 LONG_S zero, (t0)
115 PTR_LA t1, __bss_stop - LONGSIZE
1161:
117 PTR_ADDIU t0, LONGSIZE
118 LONG_S zero, (t0)
119 bne t0, t1, 1b
120
121 LONG_S a0, fw_arg0 # firmware arguments
122 LONG_S a1, fw_arg1
123 LONG_S a2, fw_arg2
124 LONG_S a3, fw_arg3
125
Thiemo Seufer1b3a6e92005-04-01 14:07:13 +0000126 MTC0 zero, CP0_CONTEXT # clear context register
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 PTR_LA $28, init_thread_union
David Daney484889f2009-07-08 10:07:50 -0700128 /* Set the SP after an empty pt_regs. */
129 PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
Ralf Baechle242954b2006-10-24 02:29:01 +0100130 PTR_ADDU sp, $28
Ralf Baechlec2ea1d52009-10-13 23:23:28 +0200131 back_to_back_c0_hazard
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 set_saved_sp sp, t0, t1
133 PTR_SUBU sp, 4 * SZREG # init stack pointer
134
Matt Redfearnaf09ab52016-03-31 10:05:37 +0100135#ifdef CONFIG_RELOCATABLE
136 /* Copy kernel and apply the relocations */
137 jal relocate_kernel
138
139 /* Repoint the sp into the new kernel image */
140 PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
141 PTR_ADDU sp, $28
142 set_saved_sp sp, t0, t1
143 PTR_SUBU sp, 4 * SZREG # init stack pointer
144
145 /*
146 * relocate_kernel returns the entry point either
147 * in the relocated kernel or the original if for
148 * some reason relocation failed - jump there now
149 * with instruction hazard barrier because of the
150 * newly sync'd icache.
151 */
152 jr.hb v0
153#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 j start_kernel
Matt Redfearnaf09ab52016-03-31 10:05:37 +0100155#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 END(kernel_entry)
157
158#ifdef CONFIG_SMP
159/*
Ralf Baechle70342282013-01-22 12:59:30 +0100160 * SMP slave cpus entry point. Board specific code for bootstrap calls this
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 * function after setting up the stack and gp registers.
162 */
163NESTED(smp_bootstrap, 16, sp)
Ralf Baechle7e359522005-07-14 09:42:32 +0000164 smp_slave_setup
Markos Chandrasd0ba3542014-01-21 09:52:23 +0000165 setup_c0_status_sec
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 j start_secondary
167 END(smp_bootstrap)
168#endif /* CONFIG_SMP */