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
147void flush_thread(void)
148{
149
150
151
152}
153
154void release_thread(struct task_struct *dead_task)
155{
156}
157
158
159
160
161
162int dump_fpu (struct pt_regs * regs, elf_fpregset_t *r)
163{
164 if (regs == NULL)
165 return 0;
166
167 memcpy(r, regs->fr, sizeof *r);
168 return 1;
169}
170
171int dump_task_fpu (struct task_struct *tsk, elf_fpregset_t *r)
172{
173 memcpy(r, tsk->thread.regs.fr, sizeof(*r));
174 return 1;
175}
176
177
178
179
180int
181copy_thread(unsigned long clone_flags, unsigned long usp,
182 unsigned long kthread_arg, struct task_struct *p)
183{
184 struct pt_regs *cregs = &(p->thread.regs);
185 void *stack = task_stack_page(p);
186
187
188
189
190 extern void * const ret_from_kernel_thread;
191 extern void * const child_return;
192
193 if (unlikely(p->flags & PF_KTHREAD)) {
194
195 memset(cregs, 0, sizeof(struct pt_regs));
196 if (!usp)
197 return 0;
198
199
200
201 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
202 cregs->kpc = (unsigned long) &ret_from_kernel_thread;
203
204
205
206
207#ifdef CONFIG_64BIT
208 cregs->gr[27] = ((unsigned long *)usp)[3];
209 cregs->gr[26] = ((unsigned long *)usp)[2];
210#else
211 cregs->gr[26] = usp;
212#endif
213 cregs->gr[25] = kthread_arg;
214 } else {
215
216
217
218
219 if (usp) {
220 usp = ALIGN(usp, 4);
221 if (likely(usp))
222 cregs->gr[30] = usp;
223 }
224 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
225 cregs->kpc = (unsigned long) &child_return;
226
227
228 if (clone_flags & CLONE_SETTLS)
229 cregs->cr27 = cregs->gr[23];
230 }
231
232 return 0;
233}
234
235unsigned long thread_saved_pc(struct task_struct *t)
236{
237 return t->thread.regs.kpc;
238}
239
240unsigned long
241get_wchan(struct task_struct *p)
242{
243 struct unwind_frame_info info;
244 unsigned long ip;
245 int count = 0;
246
247 if (!p || p == current || p->state == TASK_RUNNING)
248 return 0;
249
250
251
252
253
254 unwind_frame_init_from_blocked_task(&info, p);
255 do {
256 if (unwind_once(&info) < 0)
257 return 0;
258 ip = info.ip;
259 if (!in_sched_functions(ip))
260 return ip;
261 } while (count++ < 16);
262 return 0;
263}
264
265#ifdef CONFIG_64BIT
266void *dereference_function_descriptor(void *ptr)
267{
268 Elf64_Fdesc *desc = ptr;
269 void *p;
270
271 if (!probe_kernel_address(&desc->addr, p))
272 ptr = p;
273 return ptr;
274}
275#endif
276
277static inline unsigned long brk_rnd(void)
278{
279
280 if (is_32bit_task())
281 return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
282 else
283 return (get_random_int() & 0x3ffffUL) << 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