process.c 7.2 KB

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