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#include <linux/module.h>
27#include <linux/reboot.h>
28#include <linux/elfcore.h>
29#include <linux/pm.h>
30
31void (*pm_power_off)(void);
32EXPORT_SYMBOL(pm_power_off);
33
34
35void machine_restart(char *command) {}
36
37
38void machine_halt(void) {}
39
40
41void machine_power_off(void) {}
42
43
44
45
46
47
48
49void __noreturn cpu_idle(void)
50{
51
52 while (1) {
53 while (!need_resched())
54 barrier();
55
56 preempt_enable_no_resched();
57 schedule();
58 preempt_disable();
59 }
60}
61
62void ret_from_fork(void);
63
64void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
65{
66 unsigned long status;
67
68
69 status = regs->cp0_psr & ~(KU_MASK);
70 status |= KU_USER;
71 regs->cp0_psr = status;
72 regs->cp0_epc = pc;
73 regs->regs[0] = sp;
74}
75
76void exit_thread(void) {}
77
78
79
80
81
82
83void flush_thread(void) {}
84
85
86
87
88int copy_thread(unsigned long clone_flags, unsigned long usp,
89 unsigned long unused,
90 struct task_struct *p, struct pt_regs *regs)
91{
92 struct thread_info *ti = task_thread_info(p);
93 struct pt_regs *childregs = task_pt_regs(p);
94
95 p->set_child_tid = NULL;
96 p->clear_child_tid = NULL;
97
98 *childregs = *regs;
99 childregs->regs[7] = 0;
100 childregs->regs[4] = 0;
101 regs->regs[4] = p->pid;
102
103 if (childregs->cp0_psr & 0x8) {
104 childregs->regs[0] = usp;
105 } else {
106 childregs->regs[28] = (unsigned long) ti;
107 childregs->regs[0] = (unsigned long) childregs;
108 }
109
110 p->thread.reg0 = (unsigned long) childregs;
111 p->thread.reg3 = (unsigned long) ret_from_fork;
112 p->thread.cp0_psr = 0;
113
114 return 0;
115}
116
117
118int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)
119{
120 return 1;
121}
122
123static void __noreturn
124kernel_thread_helper(void *unused0, int (*fn)(void *),
125 void *arg, void *unused1)
126{
127 do_exit(fn(arg));
128}
129
130
131
132
133long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
134{
135 struct pt_regs regs;
136
137 memset(®s, 0, sizeof(regs));
138
139 regs.regs[6] = (unsigned long) arg;
140 regs.regs[5] = (unsigned long) fn;
141 regs.cp0_epc = (unsigned long) kernel_thread_helper;
142 regs.cp0_psr = (regs.cp0_psr & ~(0x1|0x4|0x8)) | \
143 ((regs.cp0_psr & 0x3) << 2);
144
145 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, \
146 0, ®s, 0, NULL, NULL);
147}
148
149unsigned long thread_saved_pc(struct task_struct *tsk)
150{
151 return task_pt_regs(tsk)->cp0_epc;
152}
153
154unsigned long get_wchan(struct task_struct *task)
155{
156 if (!task || task == current || task->state == TASK_RUNNING)
157 return 0;
158
159 if (!task_stack_page(task))
160 return 0;
161
162 return task_pt_regs(task)->cp0_epc;
163}
164
165unsigned long arch_align_stack(unsigned long sp)
166{
167 return sp;
168}
169