1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include <stdarg.h>
36
37#include <linux/elf.h>
38#include <linux/errno.h>
39#include <linux/kernel.h>
40#include <linux/mm.h>
41#include <linux/fs.h>
42#include <linux/module.h>
43#include <linux/personality.h>
44#include <linux/ptrace.h>
45#include <linux/sched.h>
46#include <linux/sched/debug.h>
47#include <linux/sched/task.h>
48#include <linux/sched/task_stack.h>
49#include <linux/slab.h>
50#include <linux/stddef.h>
51#include <linux/unistd.h>
52#include <linux/kallsyms.h>
53#include <linux/uaccess.h>
54#include <linux/rcupdate.h>
55#include <linux/random.h>
56#include <linux/nmi.h>
57
58#include <asm/io.h>
59#include <asm/asm-offsets.h>
60#include <asm/assembly.h>
61#include <asm/pdc.h>
62#include <asm/pdc_chassis.h>
63#include <asm/pgalloc.h>
64#include <asm/unwind.h>
65#include <asm/sections.h>
66
67#define COMMAND_GLOBAL F_EXTEND(0xfffe0030)
68#define CMD_RESET 5
69
70
71
72
73
74
75
76
77
78
79
80
81
82void machine_restart(char *cmd)
83{
84#ifdef FASTBOOT_SELFTEST_SUPPORT
85
86
87
88
89
90
91
92
93
94
95
96 if (ftc_bitmap) {
97 pdc_do_firm_test_reset(ftc_bitmap);
98 }
99#endif
100
101 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
102
103
104 pdc_do_reset();
105
106
107 gsc_writel(CMD_RESET, COMMAND_GLOBAL);
108
109
110 while (1) ;
111
112}
113
114void machine_halt(void)
115{
116
117
118
119
120}
121
122void (*chassis_power_off)(void);
123
124
125
126
127
128void machine_power_off(void)
129{
130
131 if (chassis_power_off)
132 chassis_power_off();
133
134
135
136
137 pdc_soft_power_button(0);
138
139 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
140
141
142
143
144 printk(KERN_EMERG "System shut down completed.\n"
145 "Please power this system off now.");
146
147
148 rcu_sysrq_start();
149 lockup_detector_soft_poweroff();
150 for (;;);
151}
152
153void (*pm_power_off)(void) = machine_power_off;
154EXPORT_SYMBOL(pm_power_off);
155
156void flush_thread(void)
157{
158
159
160
161}
162
163void release_thread(struct task_struct *dead_task)
164{
165}
166
167
168
169
170
171int dump_fpu (struct pt_regs * regs, elf_fpregset_t *r)
172{
173 if (regs == NULL)
174 return 0;
175
176 memcpy(r, regs->fr, sizeof *r);
177 return 1;
178}
179
180int dump_task_fpu (struct task_struct *tsk, elf_fpregset_t *r)
181{
182 memcpy(r, tsk->thread.regs.fr, sizeof(*r));
183 return 1;
184}
185
186
187
188
189int
190copy_thread(unsigned long clone_flags, unsigned long usp,
191 unsigned long kthread_arg, struct task_struct *p)
192{
193 struct pt_regs *cregs = &(p->thread.regs);
194 void *stack = task_stack_page(p);
195
196
197
198
199 extern void * const ret_from_kernel_thread;
200 extern void * const child_return;
201
202 if (unlikely(p->flags & PF_KTHREAD)) {
203
204 memset(cregs, 0, sizeof(struct pt_regs));
205 if (!usp)
206 return 0;
207
208
209
210 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
211 cregs->kpc = (unsigned long) &ret_from_kernel_thread;
212
213
214
215
216#ifdef CONFIG_64BIT
217 cregs->gr[27] = ((unsigned long *)usp)[3];
218 cregs->gr[26] = ((unsigned long *)usp)[2];
219#else
220 cregs->gr[26] = usp;
221#endif
222 cregs->gr[25] = kthread_arg;
223 } else {
224
225
226
227
228 if (usp) {
229 usp = ALIGN(usp, 4);
230 if (likely(usp))
231 cregs->gr[30] = usp;
232 }
233 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
234 cregs->kpc = (unsigned long) &child_return;
235
236
237 if (clone_flags & CLONE_SETTLS)
238 cregs->cr27 = cregs->gr[23];
239 }
240
241 return 0;
242}
243
244unsigned long
245get_wchan(struct task_struct *p)
246{
247 struct unwind_frame_info info;
248 unsigned long ip;
249 int count = 0;
250
251 if (!p || p == current || p->state == TASK_RUNNING)
252 return 0;
253
254
255
256
257
258 unwind_frame_init_from_blocked_task(&info, p);
259 do {
260 if (unwind_once(&info) < 0)
261 return 0;
262 ip = info.ip;
263 if (!in_sched_functions(ip))
264 return ip;
265 } while (count++ < 16);
266 return 0;
267}
268
269#ifdef CONFIG_64BIT
270void *dereference_function_descriptor(void *ptr)
271{
272 Elf64_Fdesc *desc = ptr;
273 void *p;
274
275 if (!probe_kernel_address(&desc->addr, p))
276 ptr = p;
277 return ptr;
278}
279#endif
280
281static inline unsigned long brk_rnd(void)
282{
283 return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
284}
285
286unsigned long arch_randomize_brk(struct mm_struct *mm)
287{
288 unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
289
290 if (ret < mm->brk)
291 return mm->brk;
292 return ret;
293}
294