blob: 0b108587f065be51f8970f9d757e881178503f39 [file] [log] [blame]
Nicolas Schichan583bb862006-10-18 15:14:55 +02001/*
2 * relocate_kernel.S for kexec
3 * Created by <nschichan@corp.free.fr> on Thu Oct 12 17:49:57 2006
4 *
5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details.
7 */
8
9#include <asm/asm.h>
10#include <asm/asmmacro.h>
11#include <asm/regdef.h>
12#include <asm/page.h>
13#include <asm/mipsregs.h>
14#include <asm/stackframe.h>
15#include <asm/addrspace.h>
16
Ralf Baechle00be0f32007-07-31 15:17:21 +010017LEAF(relocate_new_kernel)
Ralf Baechle7aa1c8f2012-10-11 18:14:58 +020018 PTR_L a0, arg0
19 PTR_L a1, arg1
20 PTR_L a2, arg2
21 PTR_L a3, arg3
22
Ralf Baechle00be0f32007-07-31 15:17:21 +010023 PTR_L s0, kexec_indirection_page
24 PTR_L s1, kexec_start_address
Nicolas Schichan583bb862006-10-18 15:14:55 +020025
26process_entry:
Ralf Baechle00be0f32007-07-31 15:17:21 +010027 PTR_L s2, (s0)
28 PTR_ADD s0, s0, SZREG
Nicolas Schichan583bb862006-10-18 15:14:55 +020029
30 /* destination page */
Ralf Baechle00be0f32007-07-31 15:17:21 +010031 and s3, s2, 0x1
32 beq s3, zero, 1f
33 and s4, s2, ~0x1 /* store destination addr in s4 */
Ralf Baechle00be0f32007-07-31 15:17:21 +010034 b process_entry
Nicolas Schichan583bb862006-10-18 15:14:55 +020035
361:
37 /* indirection page, update s0 */
Ralf Baechle00be0f32007-07-31 15:17:21 +010038 and s3, s2, 0x2
39 beq s3, zero, 1f
40 and s0, s2, ~0x2
41 b process_entry
Nicolas Schichan583bb862006-10-18 15:14:55 +020042
431:
44 /* done page */
Ralf Baechle00be0f32007-07-31 15:17:21 +010045 and s3, s2, 0x4
46 beq s3, zero, 1f
47 b done
Nicolas Schichan583bb862006-10-18 15:14:55 +0200481:
49 /* source page */
Ralf Baechle00be0f32007-07-31 15:17:21 +010050 and s3, s2, 0x8
51 beq s3, zero, process_entry
52 and s2, s2, ~0x8
53 li s6, (1 << PAGE_SHIFT) / SZREG
Nicolas Schichan583bb862006-10-18 15:14:55 +020054
55copy_word:
56 /* copy page word by word */
Ralf Baechle00be0f32007-07-31 15:17:21 +010057 REG_L s5, (s2)
58 REG_S s5, (s4)
59 PTR_ADD s4, s4, SZREG
60 PTR_ADD s2, s2, SZREG
61 LONG_SUB s6, s6, 1
62 beq s6, zero, process_entry
63 b copy_word
64 b process_entry
Nicolas Schichan583bb862006-10-18 15:14:55 +020065
66done:
Ralf Baechle7aa1c8f2012-10-11 18:14:58 +020067#ifdef CONFIG_SMP
68 /* kexec_flag reset is signal to other CPUs what kernel
69 was moved to it's location. Note - we need relocated address
70 of kexec_flag. */
71
72 bal 1f
73 1: move t1,ra;
74 PTR_LA t2,1b
75 PTR_LA t0,kexec_flag
76 PTR_SUB t0,t0,t2;
77 PTR_ADD t0,t1,t0;
78 LONG_S zero,(t0)
79#endif
80
81 sync
Nicolas Schichan583bb862006-10-18 15:14:55 +020082 /* jump to kexec_start_address */
Ralf Baechle00be0f32007-07-31 15:17:21 +010083 j s1
84 END(relocate_new_kernel)
Nicolas Schichan583bb862006-10-18 15:14:55 +020085
Ralf Baechle7aa1c8f2012-10-11 18:14:58 +020086#ifdef CONFIG_SMP
87/*
88 * Other CPUs should wait until code is relocated and
89 * then start at entry (?) point.
90 */
91LEAF(kexec_smp_wait)
92 PTR_L a0, s_arg0
93 PTR_L a1, s_arg1
94 PTR_L a2, s_arg2
95 PTR_L a3, s_arg3
96 PTR_L s1, kexec_start_address
97
98 /* Non-relocated address works for args and kexec_start_address ( old
99 * kernel is not overwritten). But we need relocated address of
100 * kexec_flag.
101 */
102
103 bal 1f
1041: move t1,ra;
105 PTR_LA t2,1b
106 PTR_LA t0,kexec_flag
107 PTR_SUB t0,t0,t2;
108 PTR_ADD t0,t1,t0;
109
1101: LONG_L s0, (t0)
111 bne s0, zero,1b
112
113 sync
114 j s1
115 END(kexec_smp_wait)
116#endif
117
118#ifdef __mips64
119 /* all PTR's must be aligned to 8 byte in 64-bit mode */
120 .align 3
121#endif
122
123/* All parameters to new kernel are passed in registers a0-a3.
124 * kexec_args[0..3] are uses to prepare register values.
125 */
126
127kexec_args:
128 EXPORT(kexec_args)
129arg0: PTR 0x0
130arg1: PTR 0x0
131arg2: PTR 0x0
132arg3: PTR 0x0
133 .size kexec_args,PTRSIZE*4
134
135#ifdef CONFIG_SMP
136/*
137 * Secondary CPUs may have different kernel parameters in
138 * their registers a0-a3. secondary_kexec_args[0..3] are used
139 * to prepare register values.
140 */
141secondary_kexec_args:
142 EXPORT(secondary_kexec_args)
143s_arg0: PTR 0x0
144s_arg1: PTR 0x0
145s_arg2: PTR 0x0
146s_arg3: PTR 0x0
147 .size secondary_kexec_args,PTRSIZE*4
148kexec_flag:
149 LONG 0x1
150
151#endif
152
Nicolas Schichan583bb862006-10-18 15:14:55 +0200153kexec_start_address:
Ralf Baechle00be0f32007-07-31 15:17:21 +0100154 EXPORT(kexec_start_address)
155 PTR 0x0
156 .size kexec_start_address, PTRSIZE
Nicolas Schichan583bb862006-10-18 15:14:55 +0200157
Nicolas Schichan583bb862006-10-18 15:14:55 +0200158kexec_indirection_page:
Ralf Baechle00be0f32007-07-31 15:17:21 +0100159 EXPORT(kexec_indirection_page)
160 PTR 0
161 .size kexec_indirection_page, PTRSIZE
Nicolas Schichan583bb862006-10-18 15:14:55 +0200162
163relocate_new_kernel_end:
164
Nicolas Schichan583bb862006-10-18 15:14:55 +0200165relocate_new_kernel_size:
Ralf Baechle00be0f32007-07-31 15:17:21 +0100166 EXPORT(relocate_new_kernel_size)
167 PTR relocate_new_kernel_end - relocate_new_kernel
168 .size relocate_new_kernel_size, PTRSIZE