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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#define __KERNEL_SYSCALLS__
54#include <stdarg.h>
55
56#include <linux/errno.h>
57#include <linux/sched.h>
58#include <linux/kernel.h>
59#include <linux/mm.h>
60#include <linux/stddef.h>
61#include <linux/unistd.h>
62#include <linux/ptrace.h>
63#include <linux/slab.h>
64#include <linux/user.h>
65#include <linux/a.out.h>
66#include <linux/elfcore.h>
67#include <linux/interrupt.h>
68#include <linux/delay.h>
69
70#include <asm/uaccess.h>
71#include <asm/pgtable.h>
72#include <asm/system.h>
73#include <asm/io.h>
74#include <asm/processor.h>
75
76#include <linux/smp.h>
77
78
79
80
81
82
83
84
85
86
87static struct fs_struct init_fs = INIT_FS;
88static struct files_struct init_files = INIT_FILES;
89static struct signal_struct init_signals = INIT_SIGNALS;
90struct mm_struct init_mm = INIT_MM(init_mm);
91
92
93
94
95
96
97
98
99
100union task_union init_task_union
101 __attribute__((__section__(".data.init_task"))) =
102 { INIT_TASK(init_task_union.task) };
103
104
105
106
107
108
109
110
111
112
113static int hlt_counter=0;
114
115void disable_hlt(void)
116{
117 hlt_counter++;
118}
119
120void enable_hlt(void)
121{
122 hlt_counter--;
123}
124
125int cpu_idle(void *unused)
126{
127 while(1) {
128 current->counter = -100;
129 schedule();
130 }
131}
132
133
134
135
136
137
138void hard_reset_now (void)
139{
140
141
142
143
144
145#if defined(CONFIG_ETRAX_WATCHDOG) && !defined(CONFIG_SVINTO_SIM)
146 extern int cause_of_death;
147#endif
148
149 printk("*** HARD RESET ***\n");
150 cli();
151
152#if defined(CONFIG_ETRAX_WATCHDOG) && !defined(CONFIG_SVINTO_SIM)
153 cause_of_death = 0xbedead;
154#else
155
156
157 *R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
158 IO_STATE(R_WATCHDOG, enable, start);
159#endif
160
161 while(1) ;
162}
163
164void machine_restart(void)
165{
166 hard_reset_now();
167}
168
169
170
171
172
173
174
175void machine_halt(void)
176{
177}
178
179
180
181void machine_power_off(void)
182{
183}
184
185
186
187
188
189
190
191void flush_thread(void)
192{
193}
194
195asmlinkage void ret_from_sys_call(void);
196
197
198
199
200
201
202
203
204
205
206int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
207 unsigned long unused,
208 struct task_struct *p, struct pt_regs *regs)
209{
210 struct pt_regs * childregs;
211 struct switch_stack *swstack;
212
213
214
215
216
217 childregs = user_regs(p);
218
219 *childregs = *regs;
220
221 childregs->r10 = 0;
222
223
224
225 swstack = ((struct switch_stack *)childregs) - 1;
226
227 swstack->r9 = 0;
228
229
230
231 swstack->return_ip = (unsigned long) ret_from_sys_call;
232
233
234
235 p->thread.usp = usp;
236
237
238
239 p->thread.ksp = (unsigned long) swstack;
240
241#ifdef DEBUG
242 printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
243 show_registers(childregs);
244#endif
245
246 return 0;
247}
248
249
250
251
252void dump_thread(struct pt_regs * regs, struct user * dump)
253{
254#if 0
255 int i;
256
257
258 dump->magic = CMAGIC;
259 dump->start_code = 0;
260 dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
261 dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
262 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
263 dump->u_dsize -= dump->u_tsize;
264 dump->u_ssize = 0;
265 for (i = 0; i < 8; i++)
266 dump->u_debugreg[i] = current->debugreg[i];
267
268 if (dump->start_stack < TASK_SIZE)
269 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
270
271 dump->regs = *regs;
272
273 dump->u_fpvalid = dump_fpu (regs, &dump->i387);
274#endif
275}
276
277
278int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
279{
280 return 0;
281}
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297asmlinkage int sys_fork(long r10, long r11, long r12, long r13, long mof, long srp,
298 struct pt_regs *regs)
299{
300 return do_fork(SIGCHLD, rdusp(), regs, 0);
301}
302
303
304
305asmlinkage int sys_clone(unsigned long newusp, unsigned long flags,
306 long r12, long r13, long mof, long srp,
307 struct pt_regs *regs)
308{
309 if (!newusp)
310 newusp = rdusp();
311 return do_fork(flags, newusp, regs, 0);
312}
313
314
315
316
317
318asmlinkage int sys_vfork(long r10, long r11, long r12, long r13, long mof, long srp,
319 struct pt_regs *regs)
320{
321 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0);
322}
323
324
325
326
327asmlinkage int sys_execve(const char *fname, char **argv, char **envp,
328 long r13, long mof, long srp,
329 struct pt_regs *regs)
330{
331 int error;
332 char *filename;
333
334 filename = getname(fname);
335 error = PTR_ERR(filename);
336
337 if (IS_ERR(filename))
338 goto out;
339 error = do_execve(filename, argv, envp, regs);
340 putname(filename);
341 out:
342 return error;
343}
344
345
346
347
348
349extern void scheduling_functions_start_here(void);
350extern void scheduling_functions_end_here(void);
351#define first_sched ((unsigned long) scheduling_functions_start_here)
352#define last_sched ((unsigned long) scheduling_functions_end_here)
353
354unsigned long get_wchan(struct task_struct *p)
355{
356#if 0
357
358
359 unsigned long ebp, esp, eip;
360 unsigned long stack_page;
361 int count = 0;
362 if (!p || p == current || p->state == TASK_RUNNING)
363 return 0;
364 stack_page = (unsigned long)p;
365 esp = p->thread.esp;
366 if (!stack_page || esp < stack_page || esp > 8188+stack_page)
367 return 0;
368
369 ebp = *(unsigned long *) esp;
370 do {
371 if (ebp < stack_page || ebp > 8184+stack_page)
372 return 0;
373 eip = *(unsigned long *) (ebp+4);
374 if (eip < first_sched || eip >= last_sched)
375 return eip;
376 ebp = *(unsigned long *) ebp;
377 } while (count++ < 16);
378#endif
379 return 0;
380}
381#undef last_sched
382#undef first_sched
383