ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / cris / kernel / process.c
1 /* $Id: process.c,v 1.14 2003/06/10 10:21:12 johana Exp $
2  * 
3  *  linux/arch/cris/kernel/process.c
4  *
5  *  Copyright (C) 1995  Linus Torvalds
6  *  Copyright (C) 2000-2002  Axis Communications AB
7  *
8  *  Authors:   Bjorn Wesen (bjornw@axis.com)
9  *
10  *  $Log: process.c,v $
11  *  Revision 1.14  2003/06/10 10:21:12  johana
12  *  Moved thread_saved_pc() from arch/cris/kernel/process.c to
13  *  subarch specific process.c. 
14  *
15  *  Revision 1.13  2003/04/09 05:20:47  starvik
16  *  Merge of Linux 2.5.67
17  *
18  *  Revision 1.12  2002/12/11 15:41:11  starvik
19  *  Extracted v10 (ETRAX 100LX) specific stuff to arch/cris/arch-v10/kernel
20  *
21  *  Revision 1.11  2002/12/10 09:00:10  starvik
22  *  Merge of Linux 2.5.51
23  *
24  *  Revision 1.10  2002/11/27 08:42:34  starvik
25  *  Argument to user_regs() is thread_info*
26  *
27  *  Revision 1.9  2002/11/26 09:44:21  starvik
28  *  New threads exits through ret_from_fork (necessary for preemptive scheduling)
29  *
30  *  Revision 1.8  2002/11/19 14:35:24  starvik
31  *  Changes from linux 2.4
32  *  Changed struct initializer syntax to the currently prefered notation
33  *
34  *  Revision 1.7  2002/11/18 07:39:42  starvik
35  *  thread_saved_pc moved here from processor.h
36  *
37  *  Revision 1.6  2002/11/14 06:51:27  starvik
38  *  Made cpu_idle more similar with other archs
39  *  init_task_union -> init_thread_union
40  *  Updated for new interrupt macros
41  *  sys_clone and do_fork have a new argument, user_tid
42  *
43  *  Revision 1.5  2002/11/05 06:45:11  starvik
44  *  Merge of Linux 2.5.45
45  *
46  *  Revision 1.4  2002/02/05 15:37:44  bjornw
47  *  Need init_task.h
48  *
49  *  Revision 1.3  2002/01/21 15:22:49  bjornw
50  *  current->counter is gone
51  *
52  *  Revision 1.22  2001/11/13 09:40:43  orjanf
53  *  Added dump_fpu (needed for core dumps).
54  *
55  *  Revision 1.21  2001/11/12 18:26:21  pkj
56  *  Fixed compiler warnings.
57  *
58  *  Revision 1.20  2001/10/03 08:21:39  jonashg
59  *  cause_of_death does not exist if CONFIG_SVINTO_SIM is defined.
60  *
61  *  Revision 1.19  2001/09/26 11:52:54  bjornw
62  *  INIT_MMAP is gone in 2.4.10
63  *
64  *  Revision 1.18  2001/08/21 21:43:51  hp
65  *  Move last watchdog fix inside #ifdef CONFIG_ETRAX_WATCHDOG
66  *
67  *  Revision 1.17  2001/08/21 13:48:01  jonashg
68  *  Added fix by HP to avoid oops when doing a hard_reset_now.
69  *
70  *  Revision 1.16  2001/06/21 02:00:40  hp
71  *      * entry.S: Include asm/unistd.h.
72  *      (_sys_call_table): Use section .rodata, not .data.
73  *      (_kernel_thread): Move from...
74  *      * process.c: ... here.
75  *      * entryoffsets.c (VAL): Break out from...
76  *      (OF): Use VAL.
77  *      (LCLONE_VM): New asmified value from CLONE_VM.
78  *
79  *  Revision 1.15  2001/06/20 16:31:57  hp
80  *  Add comments to describe empty functions according to review.
81  *
82  *  Revision 1.14  2001/05/29 11:27:59  markusl
83  *  Fixed so that hard_reset_now will do reset even if watchdog wasn't enabled
84  *
85  *  Revision 1.13  2001/03/20 19:44:06  bjornw
86  *  Use the 7th syscall argument for regs instead of current_regs
87  *
88  */
89
90 /*
91  * This file handles the architecture-dependent parts of process handling..
92  */
93
94 #include <asm/atomic.h>
95 #include <asm/pgtable.h>
96 #include <asm/uaccess.h>
97 #include <linux/module.h>
98 #include <linux/spinlock.h>
99 #include <linux/fs_struct.h>
100 #include <linux/init_task.h>
101 #include <linux/sched.h>
102 #include <linux/fs.h>
103 #include <linux/user.h>
104 #include <linux/elfcore.h>
105
106 //#define DEBUG
107
108 /*
109  * Initial task structure. Make this a per-architecture thing,
110  * because different architectures tend to have different
111  * alignment requirements and potentially different initial
112  * setup.
113  */
114
115 static struct fs_struct init_fs = INIT_FS;
116 static struct files_struct init_files = INIT_FILES;
117 static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
118 static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
119 struct mm_struct init_mm = INIT_MM(init_mm);
120
121 EXPORT_SYMBOL(init_mm);
122
123 /*
124  * Initial thread structure.
125  *
126  * We need to make sure that this is 8192-byte aligned due to the
127  * way process stacks are handled. This is done by having a special
128  * "init_task" linker map entry..
129  */
130 union thread_union init_thread_union 
131         __attribute__((__section__(".data.init_task"))) =
132                 { INIT_THREAD_INFO(init_task) };
133
134 /*
135  * Initial task structure.
136  *
137  * All other task structs will be allocated on slabs in fork.c
138  */
139 struct task_struct init_task = INIT_TASK(init_task);
140
141 EXPORT_SYMBOL(init_task);
142
143 /*
144  * The hlt_counter, disable_hlt and enable_hlt is just here as a hook if
145  * there would ever be a halt sequence (for power save when idle) with
146  * some largish delay when halting or resuming *and* a driver that can't
147  * afford that delay.  The hlt_counter would then be checked before
148  * executing the halt sequence, and the driver marks the unhaltable
149  * region by enable_hlt/disable_hlt.
150  */
151
152 static int hlt_counter=0;
153
154 void disable_hlt(void)
155 {
156         hlt_counter++;
157 }
158
159 EXPORT_SYMBOL(disable_hlt);
160
161 void enable_hlt(void)
162 {
163         hlt_counter--;
164 }
165
166 EXPORT_SYMBOL(enable_hlt);
167  
168 /*
169  * The following aren't currently used.
170  */
171 void (*pm_idle)(void);
172
173 extern void default_idle(void);
174
175 /*
176  * The idle thread. There's no useful work to be
177  * done, so just try to conserve power and have a
178  * low exit latency (ie sit in a loop waiting for
179  * somebody to say that they'd like to reschedule)
180  */
181 void cpu_idle (void)
182 {
183         /* endless idle loop with no priority at all */
184         while (1) {
185                 void (*idle)(void) = pm_idle;
186                 if (!idle)
187                         idle = default_idle;
188                 while (!need_resched())
189                         idle();
190                 schedule();
191         }
192 }
193
194 void hard_reset_now (void);
195
196 void machine_restart(void)
197 {
198         hard_reset_now();
199 }
200
201 EXPORT_SYMBOL(machine_restart);
202
203 /*
204  * Similar to machine_power_off, but don't shut off power.  Add code
205  * here to freeze the system for e.g. post-mortem debug purpose when
206  * possible.  This halt has nothing to do with the idle halt.
207  */
208
209 void machine_halt(void)
210 {
211 }
212
213 EXPORT_SYMBOL(machine_halt);
214
215 /* If or when software power-off is implemented, add code here.  */
216
217 void machine_power_off(void)
218 {
219 }
220
221 EXPORT_SYMBOL(machine_power_off);
222
223 /*
224  * When a process does an "exec", machine state like FPU and debug
225  * registers need to be reset.  This is a hook function for that.
226  * Currently we don't have any such state to reset, so this is empty.
227  */
228
229 void flush_thread(void)
230 {
231 }
232
233 /*
234  * fill in the user structure for a core dump..
235  */
236 void dump_thread(struct pt_regs * regs, struct user * dump)
237 {
238 #if 0
239         int i;
240
241         /* changed the size calculations - should hopefully work better. lbt */
242         dump->magic = CMAGIC;
243         dump->start_code = 0;
244         dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
245         dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
246         dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
247         dump->u_dsize -= dump->u_tsize;
248         dump->u_ssize = 0;
249         for (i = 0; i < 8; i++)
250                 dump->u_debugreg[i] = current->debugreg[i];  
251
252         if (dump->start_stack < TASK_SIZE)
253                 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
254
255         dump->regs = *regs;
256
257         dump->u_fpvalid = dump_fpu (regs, &dump->i387);
258 #endif 
259 }
260
261 /* Fill in the fpu structure for a core dump. */
262 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
263 {
264         return 0;
265 }