process.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * linux/arch/h8300/kernel/process.c
  3. *
  4. * Yoshinori Sato <ysato@users.sourceforge.jp>
  5. *
  6. * Based on:
  7. *
  8. * linux/arch/m68knommu/kernel/process.c
  9. *
  10. * Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
  11. * Kenneth Albanowski <kjahds@kjahds.com>,
  12. * The Silver Hammer Group, Ltd.
  13. *
  14. * linux/arch/m68k/kernel/process.c
  15. *
  16. * Copyright (C) 1995 Hamish Macdonald
  17. *
  18. * 68060 fixes by Jesper Skov
  19. */
  20. /*
  21. * This file handles the architecture-dependent parts of process handling..
  22. */
  23. #include <linux/config.h>
  24. #include <linux/errno.h>
  25. #include <linux/module.h>
  26. #include <linux/sched.h>
  27. #include <linux/kernel.h>
  28. #include <linux/mm.h>
  29. #include <linux/smp.h>
  30. #include <linux/smp_lock.h>
  31. #include <linux/stddef.h>
  32. #include <linux/unistd.h>
  33. #include <linux/ptrace.h>
  34. #include <linux/slab.h>
  35. #include <linux/user.h>
  36. #include <linux/a.out.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/reboot.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/system.h>
  41. #include <asm/traps.h>
  42. #include <asm/setup.h>
  43. #include <asm/pgtable.h>
  44. asmlinkage void ret_from_fork(void);
  45. /*
  46. * The idle loop on an H8/300..
  47. */
  48. #if !defined(CONFIG_H8300H_SIM) && !defined(CONFIG_H8S_SIM)
  49. void default_idle(void)
  50. {
  51. while(1) {
  52. if (!need_resched()) {
  53. local_irq_enable();
  54. __asm__("sleep");
  55. local_irq_disable();
  56. }
  57. schedule();
  58. }
  59. }
  60. #else
  61. void default_idle(void)
  62. {
  63. while(1) {
  64. if (need_resched())
  65. schedule();
  66. }
  67. }
  68. #endif
  69. void (*idle)(void) = default_idle;
  70. /*
  71. * The idle thread. There's no useful work to be
  72. * done, so just try to conserve power and have a
  73. * low exit latency (ie sit in a loop waiting for
  74. * somebody to say that they'd like to reschedule)
  75. */
  76. void cpu_idle(void)
  77. {
  78. idle();
  79. }
  80. void machine_restart(char * __unused)
  81. {
  82. local_irq_disable();
  83. __asm__("jmp @@0");
  84. }
  85. void machine_halt(void)
  86. {
  87. local_irq_disable();
  88. __asm__("sleep");
  89. for (;;);
  90. }
  91. void machine_power_off(void)
  92. {
  93. local_irq_disable();
  94. __asm__("sleep");
  95. for (;;);
  96. }
  97. void show_regs(struct pt_regs * regs)
  98. {
  99. printk("\nPC: %08lx Status: %02x",
  100. regs->pc, regs->ccr);
  101. printk("\nORIG_ER0: %08lx ER0: %08lx ER1: %08lx",
  102. regs->orig_er0, regs->er0, regs->er1);
  103. printk("\nER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx",
  104. regs->er2, regs->er3, regs->er4, regs->er5);
  105. printk("\nER6' %08lx ",regs->er6);
  106. if (user_mode(regs))
  107. printk("USP: %08lx\n", rdusp());
  108. else
  109. printk("\n");
  110. }
  111. /*
  112. * Create a kernel thread
  113. */
  114. int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  115. {
  116. long retval;
  117. long clone_arg;
  118. mm_segment_t fs;
  119. fs = get_fs();
  120. set_fs (KERNEL_DS);
  121. clone_arg = flags | CLONE_VM;
  122. __asm__("mov.l sp,er3\n\t"
  123. "sub.l er2,er2\n\t"
  124. "mov.l %2,er1\n\t"
  125. "mov.l %1,er0\n\t"
  126. "trapa #0\n\t"
  127. "cmp.l sp,er3\n\t"
  128. "beq 1f\n\t"
  129. "mov.l %4,er0\n\t"
  130. "mov.l %3,er1\n\t"
  131. "jsr @er1\n\t"
  132. "mov.l %5,er0\n\t"
  133. "trapa #0\n"
  134. "1:\n\t"
  135. "mov.l er0,%0"
  136. :"=r"(retval)
  137. :"i"(__NR_clone),"g"(clone_arg),"g"(fn),"g"(arg),"i"(__NR_exit)
  138. :"er0","er1","er2","er3");
  139. set_fs (fs);
  140. return retval;
  141. }
  142. void flush_thread(void)
  143. {
  144. }
  145. /*
  146. * "h8300_fork()".. By the time we get here, the
  147. * non-volatile registers have also been saved on the
  148. * stack. We do some ugly pointer stuff here.. (see
  149. * also copy_thread)
  150. */
  151. asmlinkage int h8300_fork(struct pt_regs *regs)
  152. {
  153. return -EINVAL;
  154. }
  155. asmlinkage int h8300_vfork(struct pt_regs *regs)
  156. {
  157. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);
  158. }
  159. asmlinkage int h8300_clone(struct pt_regs *regs)
  160. {
  161. unsigned long clone_flags;
  162. unsigned long newsp;
  163. /* syscall2 puts clone_flags in er1 and usp in er2 */
  164. clone_flags = regs->er1;
  165. newsp = regs->er2;
  166. if (!newsp)
  167. newsp = rdusp();
  168. return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
  169. }
  170. int copy_thread(int nr, unsigned long clone_flags,
  171. unsigned long usp, unsigned long topstk,
  172. struct task_struct * p, struct pt_regs * regs)
  173. {
  174. struct pt_regs * childregs;
  175. childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p->thread_info)) - 1;
  176. *childregs = *regs;
  177. childregs->retpc = (unsigned long) ret_from_fork;
  178. childregs->er0 = 0;
  179. p->thread.usp = usp;
  180. p->thread.ksp = (unsigned long)childregs;
  181. return 0;
  182. }
  183. /*
  184. * fill in the user structure for a core dump..
  185. */
  186. void dump_thread(struct pt_regs * regs, struct user * dump)
  187. {
  188. /* changed the size calculations - should hopefully work better. lbt */
  189. dump->magic = CMAGIC;
  190. dump->start_code = 0;
  191. dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
  192. dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
  193. dump->u_dsize = ((unsigned long) (current->mm->brk +
  194. (PAGE_SIZE-1))) >> PAGE_SHIFT;
  195. dump->u_dsize -= dump->u_tsize;
  196. dump->u_ssize = 0;
  197. dump->u_ar0 = (struct user_regs_struct *)(((int)(&dump->regs)) -((int)(dump)));
  198. dump->regs.er0 = regs->er0;
  199. dump->regs.er1 = regs->er1;
  200. dump->regs.er2 = regs->er2;
  201. dump->regs.er3 = regs->er3;
  202. dump->regs.er4 = regs->er4;
  203. dump->regs.er5 = regs->er5;
  204. dump->regs.er6 = regs->er6;
  205. dump->regs.orig_er0 = regs->orig_er0;
  206. dump->regs.ccr = regs->ccr;
  207. dump->regs.pc = regs->pc;
  208. }
  209. /*
  210. * sys_execve() executes a new program.
  211. */
  212. asmlinkage int sys_execve(char *name, char **argv, char **envp,int dummy,...)
  213. {
  214. int error;
  215. char * filename;
  216. struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
  217. lock_kernel();
  218. filename = getname(name);
  219. error = PTR_ERR(filename);
  220. if (IS_ERR(filename))
  221. goto out;
  222. error = do_execve(filename, argv, envp, regs);
  223. putname(filename);
  224. out:
  225. unlock_kernel();
  226. return error;
  227. }
  228. unsigned long thread_saved_pc(struct task_struct *tsk)
  229. {
  230. return ((struct pt_regs *)tsk->thread.esp0)->pc;
  231. }
  232. unsigned long get_wchan(struct task_struct *p)
  233. {
  234. unsigned long fp, pc;
  235. unsigned long stack_page;
  236. int count = 0;
  237. if (!p || p == current || p->state == TASK_RUNNING)
  238. return 0;
  239. stack_page = (unsigned long)p;
  240. fp = ((struct pt_regs *)p->thread.ksp)->er6;
  241. do {
  242. if (fp < stack_page+sizeof(struct thread_info) ||
  243. fp >= 8184+stack_page)
  244. return 0;
  245. pc = ((unsigned long *)fp)[1];
  246. if (!in_sched_functions(pc))
  247. return pc;
  248. fp = *(unsigned long *) fp;
  249. } while (count++ < 16);
  250. return 0;
  251. }