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