1 /* $Id: process.c,v 1.16 2001/06/21 02:00:40 hp Exp $
3 * linux/arch/cris/kernel/process.c
5 * Copyright (C) 1995 Linus Torvalds
6 * Copyright (C) 2000, 2001 Axis Communications AB
8 * Authors: Bjorn Wesen (bjornw@axis.com)
11 * Revision 1.16 2001/06/21 02:00:40 hp
12 * * entry.S: Include asm/unistd.h.
13 * (_sys_call_table): Use section .rodata, not .data.
14 * (_kernel_thread): Move from...
15 * * process.c: ... here.
16 * * entryoffsets.c (VAL): Break out from...
18 * (LCLONE_VM): New asmified value from CLONE_VM.
20 * Revision 1.15 2001/06/20 16:31:57 hp
21 * Add comments to describe empty functions according to review.
23 * Revision 1.14 2001/05/29 11:27:59 markusl
24 * Fixed so that hard_reset_now will do reset even if watchdog wasn't enabled
26 * Revision 1.13 2001/03/20 19:44:06 bjornw
27 * Use the 7th syscall argument for regs instead of current_regs
32 * This file handles the architecture-dependent parts of process handling..
35 #define __KERNEL_SYSCALLS__
38 #include <linux/errno.h>
39 #include <linux/sched.h>
40 #include <linux/kernel.h>
42 #include <linux/stddef.h>
43 #include <linux/unistd.h>
44 #include <linux/ptrace.h>
45 #include <linux/slab.h>
46 #include <linux/user.h>
47 #include <linux/a.out.h>
48 #include <linux/interrupt.h>
49 #include <linux/delay.h>
51 #include <asm/uaccess.h>
52 #include <asm/pgtable.h>
53 #include <asm/system.h>
55 #include <asm/processor.h>
57 #include <linux/smp.h>
62 * Initial task structure. Make this a per-architecture thing,
63 * because different architectures tend to have different
64 * alignment requirements and potentially different initial
68 static struct fs_struct init_fs = INIT_FS;
69 static struct files_struct init_files = INIT_FILES;
70 static struct signal_struct init_signals = INIT_SIGNALS;
71 struct mm_struct init_mm = INIT_MM(init_mm);
74 * Initial task structure.
76 * We need to make sure that this is 8192-byte aligned due to the
77 * way process stacks are handled. This is done by having a special
78 * "init_task" linker map entry..
81 union task_union init_task_union
82 __attribute__((__section__(".data.init_task"))) =
83 { INIT_TASK(init_task_union.task) };
86 * The hlt_counter, disable_hlt and enable_hlt is just here as a hook if
87 * there would ever be a halt sequence (for power save when idle) with
88 * some largish delay when halting or resuming *and* a driver that can't
89 * afford that delay. The hlt_counter would then be checked before
90 * executing the halt sequence, and the driver marks the unhaltable
91 * region by enable_hlt/disable_hlt.
94 static int hlt_counter=0;
96 void disable_hlt(void)
101 void enable_hlt(void)
106 int cpu_idle(void *unused)
109 current->counter = -100;
114 /* if the watchdog is enabled, we can simply disable interrupts and go
115 * into an eternal loop, and the watchdog will reset the CPU after 0.1s
116 * if on the other hand the watchdog wasn't enabled, we just enable it and wait
119 void hard_reset_now (void)
121 printk("*** HARD RESET ***\n");
124 #ifndef CONFIG_ETRAX_WATCHDOG
125 /* Since we dont plan to keep on reseting the watchdog,
126 the key can be arbitrary hence three */
127 *R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
128 IO_STATE(R_WATCHDOG, enable, start);
131 while(1) /* waiting for RETRIBUTION! */ ;
134 void machine_restart(void)
140 * Similar to machine_power_off, but don't shut off power. Add code
141 * here to freeze the system for e.g. post-mortem debug purpose when
142 * possible. This halt has nothing to do with the idle halt.
145 void machine_halt(void)
149 /* If or when software power-off is implemented, add code here. */
151 void machine_power_off(void)
156 * When a process does an "exec", machine state like FPU and debug
157 * registers need to be reset. This is a hook function for that.
158 * Currently we don't have any such state to reset, so this is empty.
161 void flush_thread(void)
165 asmlinkage void ret_from_sys_call(void);
167 /* setup the child's kernel stack with a pt_regs and switch_stack on it.
168 * it will be un-nested during _resume and _ret_from_sys_call when the
169 * new thread is scheduled.
171 * also setup the thread switching structure which is used to keep
172 * thread-specific data during _resumes.
176 int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
177 unsigned long unused,
178 struct task_struct *p, struct pt_regs *regs)
180 struct pt_regs * childregs;
181 struct switch_stack *swstack;
183 /* put the pt_regs structure at the end of the new kernel stack page and fix it up
184 * remember that the task_struct doubles as the kernel stack for the task
187 childregs = user_regs(p);
189 *childregs = *regs; /* struct copy of pt_regs */
191 childregs->r10 = 0; /* child returns 0 after a fork/clone */
193 /* put the switch stack right below the pt_regs */
195 swstack = ((struct switch_stack *)childregs) - 1;
197 swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
199 /* we want to return into ret_from_sys_call after the _resume */
201 swstack->return_ip = (unsigned long) ret_from_sys_call;
203 /* fix the user-mode stackpointer */
207 /* and the kernel-mode one */
209 p->thread.ksp = (unsigned long) swstack;
212 printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
213 show_registers(childregs);
220 * fill in the user structure for a core dump..
222 void dump_thread(struct pt_regs * regs, struct user * dump)
226 /* changed the size calculations - should hopefully work better. lbt */
227 dump->magic = CMAGIC;
228 dump->start_code = 0;
229 dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
230 dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
231 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
232 dump->u_dsize -= dump->u_tsize;
234 for (i = 0; i < 8; i++)
235 dump->u_debugreg[i] = current->debugreg[i];
237 if (dump->start_stack < TASK_SIZE)
238 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
242 dump->u_fpvalid = dump_fpu (regs, &dump->i387);
247 * Be aware of the "magic" 7th argument in the four system-calls below.
248 * They need the latest stackframe, which is put as the 7th argument by
249 * entry.S. The previous arguments are dummies or actually used, but need
250 * to be defined to reach the 7th argument.
252 * N.B.: Another method to get the stackframe is to use current_regs(). But
253 * it returns the latest stack-frame stacked when going from _user mode_ and
254 * some of these (at least sys_clone) are called from kernel-mode sometimes
255 * (for example during kernel_thread, above) and thus cannot use it. Thus,
256 * to be sure not to get any surprises, we use the method for the other calls
260 asmlinkage int sys_fork(long r10, long r11, long r12, long r13, long mof, long srp,
261 struct pt_regs *regs)
263 return do_fork(SIGCHLD, rdusp(), regs, 0);
266 /* if newusp is 0, we just grab the old usp */
268 asmlinkage int sys_clone(unsigned long newusp, unsigned long flags,
269 long r12, long r13, long mof, long srp,
270 struct pt_regs *regs)
274 return do_fork(flags, newusp, regs, 0);
277 /* vfork is a system call in i386 because of register-pressure - maybe
278 * we can remove it and handle it in libc but we put it here until then.
281 asmlinkage int sys_vfork(long r10, long r11, long r12, long r13, long mof, long srp,
282 struct pt_regs *regs)
284 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0);
288 * sys_execve() executes a new program.
290 asmlinkage int sys_execve(const char *fname, char **argv, char **envp,
291 long r13, long mof, long srp,
292 struct pt_regs *regs)
297 filename = getname(fname);
298 error = PTR_ERR(filename);
300 if (IS_ERR(filename))
302 error = do_execve(filename, argv, envp, regs);
309 * These bracket the sleeping functions..
312 extern void scheduling_functions_start_here(void);
313 extern void scheduling_functions_end_here(void);
314 #define first_sched ((unsigned long) scheduling_functions_start_here)
315 #define last_sched ((unsigned long) scheduling_functions_end_here)
317 unsigned long get_wchan(struct task_struct *p)
322 unsigned long ebp, esp, eip;
323 unsigned long stack_page;
325 if (!p || p == current || p->state == TASK_RUNNING)
327 stack_page = (unsigned long)p;
329 if (!stack_page || esp < stack_page || esp > 8188+stack_page)
331 /* include/asm-i386/system.h:switch_to() pushes ebp last. */
332 ebp = *(unsigned long *) esp;
334 if (ebp < stack_page || ebp > 8184+stack_page)
336 eip = *(unsigned long *) (ebp+4);
337 if (eip < first_sched || eip >= last_sched)
339 ebp = *(unsigned long *) ebp;
340 } while (count++ < 16);