process.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * linux/arch/cris/kernel/process.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. * Copyright (C) 2000-2002 Axis Communications AB
  6. *
  7. * Authors: Bjorn Wesen (bjornw@axis.com)
  8. * Mikael Starvik (starvik@axis.com)
  9. *
  10. * This file handles the architecture-dependent parts of process handling..
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/slab.h>
  14. #include <linux/err.h>
  15. #include <linux/fs.h>
  16. #include <arch/svinto.h>
  17. #include <linux/init.h>
  18. #include <arch/system.h>
  19. #include <linux/ptrace.h>
  20. #ifdef CONFIG_ETRAX_GPIO
  21. void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
  22. #endif
  23. /*
  24. * We use this if we don't have any better
  25. * idle routine..
  26. */
  27. void default_idle(void)
  28. {
  29. #ifdef CONFIG_ETRAX_GPIO
  30. etrax_gpio_wake_up_check();
  31. #endif
  32. local_irq_enable();
  33. }
  34. /*
  35. * Free current thread data structures etc..
  36. */
  37. void exit_thread(void)
  38. {
  39. /* Nothing needs to be done. */
  40. }
  41. /* if the watchdog is enabled, we can simply disable interrupts and go
  42. * into an eternal loop, and the watchdog will reset the CPU after 0.1s
  43. * if on the other hand the watchdog wasn't enabled, we just enable it and wait
  44. */
  45. void hard_reset_now (void)
  46. {
  47. /*
  48. * Don't declare this variable elsewhere. We don't want any other
  49. * code to know about it than the watchdog handler in entry.S and
  50. * this code, implementing hard reset through the watchdog.
  51. */
  52. #if defined(CONFIG_ETRAX_WATCHDOG)
  53. extern int cause_of_death;
  54. #endif
  55. printk("*** HARD RESET ***\n");
  56. local_irq_disable();
  57. #if defined(CONFIG_ETRAX_WATCHDOG)
  58. cause_of_death = 0xbedead;
  59. #else
  60. /* Since we dont plan to keep on resetting the watchdog,
  61. the key can be arbitrary hence three */
  62. *R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
  63. IO_STATE(R_WATCHDOG, enable, start);
  64. #endif
  65. while(1) /* waiting for RETRIBUTION! */ ;
  66. }
  67. /*
  68. * Return saved PC of a blocked thread.
  69. */
  70. unsigned long thread_saved_pc(struct task_struct *t)
  71. {
  72. return task_pt_regs(t)->irp;
  73. }
  74. /* setup the child's kernel stack with a pt_regs and switch_stack on it.
  75. * it will be un-nested during _resume and _ret_from_sys_call when the
  76. * new thread is scheduled.
  77. *
  78. * also setup the thread switching structure which is used to keep
  79. * thread-specific data during _resumes.
  80. *
  81. */
  82. asmlinkage void ret_from_fork(void);
  83. asmlinkage void ret_from_kernel_thread(void);
  84. int copy_thread(unsigned long clone_flags, unsigned long usp,
  85. unsigned long arg, struct task_struct *p)
  86. {
  87. struct pt_regs *childregs = task_pt_regs(p);
  88. struct switch_stack *swstack = ((struct switch_stack *)childregs) - 1;
  89. /* put the pt_regs structure at the end of the new kernel stack page and fix it up
  90. * remember that the task_struct doubles as the kernel stack for the task
  91. */
  92. if (unlikely(p->flags & PF_KTHREAD)) {
  93. memset(swstack, 0,
  94. sizeof(struct switch_stack) + sizeof(struct pt_regs));
  95. swstack->r1 = usp;
  96. swstack->r2 = arg;
  97. childregs->dccr = 1 << I_DCCR_BITNR;
  98. swstack->return_ip = (unsigned long) ret_from_kernel_thread;
  99. p->thread.ksp = (unsigned long) swstack;
  100. p->thread.usp = 0;
  101. return 0;
  102. }
  103. *childregs = *current_pt_regs(); /* struct copy of pt_regs */
  104. childregs->r10 = 0; /* child returns 0 after a fork/clone */
  105. /* put the switch stack right below the pt_regs */
  106. swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
  107. /* we want to return into ret_from_sys_call after the _resume */
  108. swstack->return_ip = (unsigned long) ret_from_fork; /* Will call ret_from_sys_call */
  109. /* fix the user-mode stackpointer */
  110. p->thread.usp = usp ?: rdusp();
  111. /* and the kernel-mode one */
  112. p->thread.ksp = (unsigned long) swstack;
  113. #ifdef DEBUG
  114. printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
  115. show_registers(childregs);
  116. #endif
  117. return 0;
  118. }
  119. unsigned long get_wchan(struct task_struct *p)
  120. {
  121. #if 0
  122. /* YURGH. TODO. */
  123. unsigned long ebp, esp, eip;
  124. unsigned long stack_page;
  125. int count = 0;
  126. if (!p || p == current || p->state == TASK_RUNNING)
  127. return 0;
  128. stack_page = (unsigned long)p;
  129. esp = p->thread.esp;
  130. if (!stack_page || esp < stack_page || esp > 8188+stack_page)
  131. return 0;
  132. /* include/asm-i386/system.h:switch_to() pushes ebp last. */
  133. ebp = *(unsigned long *) esp;
  134. do {
  135. if (ebp < stack_page || ebp > 8184+stack_page)
  136. return 0;
  137. eip = *(unsigned long *) (ebp+4);
  138. if (!in_sched_functions(eip))
  139. return eip;
  140. ebp = *(unsigned long *) ebp;
  141. } while (count++ < 16);
  142. #endif
  143. return 0;
  144. }
  145. #undef last_sched
  146. #undef first_sched
  147. void show_regs(struct pt_regs * regs)
  148. {
  149. unsigned long usp = rdusp();
  150. show_regs_print_info(KERN_DEFAULT);
  151. printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
  152. regs->irp, regs->srp, regs->dccr, usp, regs->mof );
  153. printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
  154. regs->r0, regs->r1, regs->r2, regs->r3);
  155. printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
  156. regs->r4, regs->r5, regs->r6, regs->r7);
  157. printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
  158. regs->r8, regs->r9, regs->r10, regs->r11);
  159. printk("r12: %08lx r13: %08lx oR10: %08lx\n",
  160. regs->r12, regs->r13, regs->orig_r10);
  161. }