process_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * arch/sh/kernel/process_64.c
  3. *
  4. * This file handles the architecture-dependent parts of process handling..
  5. *
  6. * Copyright (C) 2000, 2001 Paolo Alberelli
  7. * Copyright (C) 2003 - 2007 Paul Mundt
  8. * Copyright (C) 2003, 2004 Richard Curnow
  9. *
  10. * Started from SH3/4 version:
  11. * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  12. *
  13. * In turn started from i386 version:
  14. * Copyright (C) 1995 Linus Torvalds
  15. *
  16. * This file is subject to the terms and conditions of the GNU General Public
  17. * License. See the file "COPYING" in the main directory of this archive
  18. * for more details.
  19. */
  20. #include <linux/mm.h>
  21. #include <linux/fs.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/reboot.h>
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/io.h>
  28. #include <asm/syscalls.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/mmu_context.h>
  32. #include <asm/fpu.h>
  33. struct task_struct *last_task_used_math = NULL;
  34. static int hlt_counter = 1;
  35. #define HARD_IDLE_TIMEOUT (HZ / 3)
  36. static int __init nohlt_setup(char *__unused)
  37. {
  38. hlt_counter = 1;
  39. return 1;
  40. }
  41. static int __init hlt_setup(char *__unused)
  42. {
  43. hlt_counter = 0;
  44. return 1;
  45. }
  46. __setup("nohlt", nohlt_setup);
  47. __setup("hlt", hlt_setup);
  48. static inline void hlt(void)
  49. {
  50. __asm__ __volatile__ ("sleep" : : : "memory");
  51. }
  52. /*
  53. * The idle loop on a uniprocessor SH..
  54. */
  55. void cpu_idle(void)
  56. {
  57. /* endless idle loop with no priority at all */
  58. while (1) {
  59. if (hlt_counter) {
  60. while (!need_resched())
  61. cpu_relax();
  62. } else {
  63. local_irq_disable();
  64. while (!need_resched()) {
  65. local_irq_enable();
  66. hlt();
  67. local_irq_disable();
  68. }
  69. local_irq_enable();
  70. }
  71. preempt_enable_no_resched();
  72. schedule();
  73. preempt_disable();
  74. }
  75. }
  76. void machine_restart(char * __unused)
  77. {
  78. extern void phys_stext(void);
  79. phys_stext();
  80. }
  81. void machine_halt(void)
  82. {
  83. for (;;);
  84. }
  85. void machine_power_off(void)
  86. {
  87. #if 0
  88. /* Disable watchdog timer */
  89. ctrl_outl(0xa5000000, WTCSR);
  90. /* Configure deep standby on sleep */
  91. ctrl_outl(0x03, STBCR);
  92. #endif
  93. __asm__ __volatile__ (
  94. "sleep\n\t"
  95. "synci\n\t"
  96. "nop;nop;nop;nop\n\t"
  97. );
  98. panic("Unexpected wakeup!\n");
  99. }
  100. void (*pm_power_off)(void) = machine_power_off;
  101. EXPORT_SYMBOL(pm_power_off);
  102. void show_regs(struct pt_regs * regs)
  103. {
  104. unsigned long long ah, al, bh, bl, ch, cl;
  105. printk("\n");
  106. ah = (regs->pc) >> 32;
  107. al = (regs->pc) & 0xffffffff;
  108. bh = (regs->regs[18]) >> 32;
  109. bl = (regs->regs[18]) & 0xffffffff;
  110. ch = (regs->regs[15]) >> 32;
  111. cl = (regs->regs[15]) & 0xffffffff;
  112. printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
  113. ah, al, bh, bl, ch, cl);
  114. ah = (regs->sr) >> 32;
  115. al = (regs->sr) & 0xffffffff;
  116. asm volatile ("getcon " __TEA ", %0" : "=r" (bh));
  117. asm volatile ("getcon " __TEA ", %0" : "=r" (bl));
  118. bh = (bh) >> 32;
  119. bl = (bl) & 0xffffffff;
  120. asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch));
  121. asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl));
  122. ch = (ch) >> 32;
  123. cl = (cl) & 0xffffffff;
  124. printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
  125. ah, al, bh, bl, ch, cl);
  126. ah = (regs->regs[0]) >> 32;
  127. al = (regs->regs[0]) & 0xffffffff;
  128. bh = (regs->regs[1]) >> 32;
  129. bl = (regs->regs[1]) & 0xffffffff;
  130. ch = (regs->regs[2]) >> 32;
  131. cl = (regs->regs[2]) & 0xffffffff;
  132. printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
  133. ah, al, bh, bl, ch, cl);
  134. ah = (regs->regs[3]) >> 32;
  135. al = (regs->regs[3]) & 0xffffffff;
  136. bh = (regs->regs[4]) >> 32;
  137. bl = (regs->regs[4]) & 0xffffffff;
  138. ch = (regs->regs[5]) >> 32;
  139. cl = (regs->regs[5]) & 0xffffffff;
  140. printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
  141. ah, al, bh, bl, ch, cl);
  142. ah = (regs->regs[6]) >> 32;
  143. al = (regs->regs[6]) & 0xffffffff;
  144. bh = (regs->regs[7]) >> 32;
  145. bl = (regs->regs[7]) & 0xffffffff;
  146. ch = (regs->regs[8]) >> 32;
  147. cl = (regs->regs[8]) & 0xffffffff;
  148. printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
  149. ah, al, bh, bl, ch, cl);
  150. ah = (regs->regs[9]) >> 32;
  151. al = (regs->regs[9]) & 0xffffffff;
  152. bh = (regs->regs[10]) >> 32;
  153. bl = (regs->regs[10]) & 0xffffffff;
  154. ch = (regs->regs[11]) >> 32;
  155. cl = (regs->regs[11]) & 0xffffffff;
  156. printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
  157. ah, al, bh, bl, ch, cl);
  158. ah = (regs->regs[12]) >> 32;
  159. al = (regs->regs[12]) & 0xffffffff;
  160. bh = (regs->regs[13]) >> 32;
  161. bl = (regs->regs[13]) & 0xffffffff;
  162. ch = (regs->regs[14]) >> 32;
  163. cl = (regs->regs[14]) & 0xffffffff;
  164. printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
  165. ah, al, bh, bl, ch, cl);
  166. ah = (regs->regs[16]) >> 32;
  167. al = (regs->regs[16]) & 0xffffffff;
  168. bh = (regs->regs[17]) >> 32;
  169. bl = (regs->regs[17]) & 0xffffffff;
  170. ch = (regs->regs[19]) >> 32;
  171. cl = (regs->regs[19]) & 0xffffffff;
  172. printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
  173. ah, al, bh, bl, ch, cl);
  174. ah = (regs->regs[20]) >> 32;
  175. al = (regs->regs[20]) & 0xffffffff;
  176. bh = (regs->regs[21]) >> 32;
  177. bl = (regs->regs[21]) & 0xffffffff;
  178. ch = (regs->regs[22]) >> 32;
  179. cl = (regs->regs[22]) & 0xffffffff;
  180. printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
  181. ah, al, bh, bl, ch, cl);
  182. ah = (regs->regs[23]) >> 32;
  183. al = (regs->regs[23]) & 0xffffffff;
  184. bh = (regs->regs[24]) >> 32;
  185. bl = (regs->regs[24]) & 0xffffffff;
  186. ch = (regs->regs[25]) >> 32;
  187. cl = (regs->regs[25]) & 0xffffffff;
  188. printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
  189. ah, al, bh, bl, ch, cl);
  190. ah = (regs->regs[26]) >> 32;
  191. al = (regs->regs[26]) & 0xffffffff;
  192. bh = (regs->regs[27]) >> 32;
  193. bl = (regs->regs[27]) & 0xffffffff;
  194. ch = (regs->regs[28]) >> 32;
  195. cl = (regs->regs[28]) & 0xffffffff;
  196. printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
  197. ah, al, bh, bl, ch, cl);
  198. ah = (regs->regs[29]) >> 32;
  199. al = (regs->regs[29]) & 0xffffffff;
  200. bh = (regs->regs[30]) >> 32;
  201. bl = (regs->regs[30]) & 0xffffffff;
  202. ch = (regs->regs[31]) >> 32;
  203. cl = (regs->regs[31]) & 0xffffffff;
  204. printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
  205. ah, al, bh, bl, ch, cl);
  206. ah = (regs->regs[32]) >> 32;
  207. al = (regs->regs[32]) & 0xffffffff;
  208. bh = (regs->regs[33]) >> 32;
  209. bl = (regs->regs[33]) & 0xffffffff;
  210. ch = (regs->regs[34]) >> 32;
  211. cl = (regs->regs[34]) & 0xffffffff;
  212. printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
  213. ah, al, bh, bl, ch, cl);
  214. ah = (regs->regs[35]) >> 32;
  215. al = (regs->regs[35]) & 0xffffffff;
  216. bh = (regs->regs[36]) >> 32;
  217. bl = (regs->regs[36]) & 0xffffffff;
  218. ch = (regs->regs[37]) >> 32;
  219. cl = (regs->regs[37]) & 0xffffffff;
  220. printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
  221. ah, al, bh, bl, ch, cl);
  222. ah = (regs->regs[38]) >> 32;
  223. al = (regs->regs[38]) & 0xffffffff;
  224. bh = (regs->regs[39]) >> 32;
  225. bl = (regs->regs[39]) & 0xffffffff;
  226. ch = (regs->regs[40]) >> 32;
  227. cl = (regs->regs[40]) & 0xffffffff;
  228. printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
  229. ah, al, bh, bl, ch, cl);
  230. ah = (regs->regs[41]) >> 32;
  231. al = (regs->regs[41]) & 0xffffffff;
  232. bh = (regs->regs[42]) >> 32;
  233. bl = (regs->regs[42]) & 0xffffffff;
  234. ch = (regs->regs[43]) >> 32;
  235. cl = (regs->regs[43]) & 0xffffffff;
  236. printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
  237. ah, al, bh, bl, ch, cl);
  238. ah = (regs->regs[44]) >> 32;
  239. al = (regs->regs[44]) & 0xffffffff;
  240. bh = (regs->regs[45]) >> 32;
  241. bl = (regs->regs[45]) & 0xffffffff;
  242. ch = (regs->regs[46]) >> 32;
  243. cl = (regs->regs[46]) & 0xffffffff;
  244. printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
  245. ah, al, bh, bl, ch, cl);
  246. ah = (regs->regs[47]) >> 32;
  247. al = (regs->regs[47]) & 0xffffffff;
  248. bh = (regs->regs[48]) >> 32;
  249. bl = (regs->regs[48]) & 0xffffffff;
  250. ch = (regs->regs[49]) >> 32;
  251. cl = (regs->regs[49]) & 0xffffffff;
  252. printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
  253. ah, al, bh, bl, ch, cl);
  254. ah = (regs->regs[50]) >> 32;
  255. al = (regs->regs[50]) & 0xffffffff;
  256. bh = (regs->regs[51]) >> 32;
  257. bl = (regs->regs[51]) & 0xffffffff;
  258. ch = (regs->regs[52]) >> 32;
  259. cl = (regs->regs[52]) & 0xffffffff;
  260. printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
  261. ah, al, bh, bl, ch, cl);
  262. ah = (regs->regs[53]) >> 32;
  263. al = (regs->regs[53]) & 0xffffffff;
  264. bh = (regs->regs[54]) >> 32;
  265. bl = (regs->regs[54]) & 0xffffffff;
  266. ch = (regs->regs[55]) >> 32;
  267. cl = (regs->regs[55]) & 0xffffffff;
  268. printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
  269. ah, al, bh, bl, ch, cl);
  270. ah = (regs->regs[56]) >> 32;
  271. al = (regs->regs[56]) & 0xffffffff;
  272. bh = (regs->regs[57]) >> 32;
  273. bl = (regs->regs[57]) & 0xffffffff;
  274. ch = (regs->regs[58]) >> 32;
  275. cl = (regs->regs[58]) & 0xffffffff;
  276. printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
  277. ah, al, bh, bl, ch, cl);
  278. ah = (regs->regs[59]) >> 32;
  279. al = (regs->regs[59]) & 0xffffffff;
  280. bh = (regs->regs[60]) >> 32;
  281. bl = (regs->regs[60]) & 0xffffffff;
  282. ch = (regs->regs[61]) >> 32;
  283. cl = (regs->regs[61]) & 0xffffffff;
  284. printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
  285. ah, al, bh, bl, ch, cl);
  286. ah = (regs->regs[62]) >> 32;
  287. al = (regs->regs[62]) & 0xffffffff;
  288. bh = (regs->tregs[0]) >> 32;
  289. bl = (regs->tregs[0]) & 0xffffffff;
  290. ch = (regs->tregs[1]) >> 32;
  291. cl = (regs->tregs[1]) & 0xffffffff;
  292. printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n",
  293. ah, al, bh, bl, ch, cl);
  294. ah = (regs->tregs[2]) >> 32;
  295. al = (regs->tregs[2]) & 0xffffffff;
  296. bh = (regs->tregs[3]) >> 32;
  297. bl = (regs->tregs[3]) & 0xffffffff;
  298. ch = (regs->tregs[4]) >> 32;
  299. cl = (regs->tregs[4]) & 0xffffffff;
  300. printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n",
  301. ah, al, bh, bl, ch, cl);
  302. ah = (regs->tregs[5]) >> 32;
  303. al = (regs->tregs[5]) & 0xffffffff;
  304. bh = (regs->tregs[6]) >> 32;
  305. bl = (regs->tregs[6]) & 0xffffffff;
  306. ch = (regs->tregs[7]) >> 32;
  307. cl = (regs->tregs[7]) & 0xffffffff;
  308. printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n",
  309. ah, al, bh, bl, ch, cl);
  310. /*
  311. * If we're in kernel mode, dump the stack too..
  312. */
  313. if (!user_mode(regs)) {
  314. void show_stack(struct task_struct *tsk, unsigned long *sp);
  315. unsigned long sp = regs->regs[15] & 0xffffffff;
  316. struct task_struct *tsk = get_current();
  317. tsk->thread.kregs = regs;
  318. show_stack(tsk, (unsigned long *)sp);
  319. }
  320. }
  321. struct task_struct * alloc_task_struct(void)
  322. {
  323. /* Get task descriptor pages */
  324. return (struct task_struct *)
  325. __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE));
  326. }
  327. void free_task_struct(struct task_struct *p)
  328. {
  329. free_pages((unsigned long) p, get_order(THREAD_SIZE));
  330. }
  331. /*
  332. * Create a kernel thread
  333. */
  334. ATTRIB_NORET void kernel_thread_helper(void *arg, int (*fn)(void *))
  335. {
  336. do_exit(fn(arg));
  337. }
  338. /*
  339. * This is the mechanism for creating a new kernel thread.
  340. *
  341. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  342. * who haven't done an "execve()") should use this: it will work within
  343. * a system call from a "real" process, but the process memory space will
  344. * not be freed until both the parent and the child have exited.
  345. */
  346. int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  347. {
  348. struct pt_regs regs;
  349. int pid;
  350. memset(&regs, 0, sizeof(regs));
  351. regs.regs[2] = (unsigned long)arg;
  352. regs.regs[3] = (unsigned long)fn;
  353. regs.pc = (unsigned long)kernel_thread_helper;
  354. regs.sr = (1 << 30);
  355. /* Ok, create the new process.. */
  356. pid = do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
  357. &regs, 0, NULL, NULL);
  358. trace_mark(kernel_arch_kthread_create, "pid %d fn %p", pid, fn);
  359. return pid;
  360. }
  361. /*
  362. * Free current thread data structures etc..
  363. */
  364. void exit_thread(void)
  365. {
  366. /*
  367. * See arch/sparc/kernel/process.c for the precedent for doing
  368. * this -- RPC.
  369. *
  370. * The SH-5 FPU save/restore approach relies on
  371. * last_task_used_math pointing to a live task_struct. When
  372. * another task tries to use the FPU for the 1st time, the FPUDIS
  373. * trap handling (see arch/sh/kernel/cpu/sh5/fpu.c) will save the
  374. * existing FPU state to the FP regs field within
  375. * last_task_used_math before re-loading the new task's FPU state
  376. * (or initialising it if the FPU has been used before). So if
  377. * last_task_used_math is stale, and its page has already been
  378. * re-allocated for another use, the consequences are rather
  379. * grim. Unless we null it here, there is no other path through
  380. * which it would get safely nulled.
  381. */
  382. #ifdef CONFIG_SH_FPU
  383. if (last_task_used_math == current) {
  384. last_task_used_math = NULL;
  385. }
  386. #endif
  387. }
  388. void flush_thread(void)
  389. {
  390. /* Called by fs/exec.c (flush_old_exec) to remove traces of a
  391. * previously running executable. */
  392. #ifdef CONFIG_SH_FPU
  393. if (last_task_used_math == current) {
  394. last_task_used_math = NULL;
  395. }
  396. /* Force FPU state to be reinitialised after exec */
  397. clear_used_math();
  398. #endif
  399. /* if we are a kernel thread, about to change to user thread,
  400. * update kreg
  401. */
  402. if(current->thread.kregs==&fake_swapper_regs) {
  403. current->thread.kregs =
  404. ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
  405. current->thread.uregs = current->thread.kregs;
  406. }
  407. }
  408. void release_thread(struct task_struct *dead_task)
  409. {
  410. /* do nothing */
  411. }
  412. /* Fill in the fpu structure for a core dump.. */
  413. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  414. {
  415. #ifdef CONFIG_SH_FPU
  416. int fpvalid;
  417. struct task_struct *tsk = current;
  418. fpvalid = !!tsk_used_math(tsk);
  419. if (fpvalid) {
  420. if (current == last_task_used_math) {
  421. enable_fpu();
  422. save_fpu(tsk, regs);
  423. disable_fpu();
  424. last_task_used_math = 0;
  425. regs->sr |= SR_FD;
  426. }
  427. memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));
  428. }
  429. return fpvalid;
  430. #else
  431. return 0; /* Task didn't use the fpu at all. */
  432. #endif
  433. }
  434. asmlinkage void ret_from_fork(void);
  435. int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
  436. unsigned long unused,
  437. struct task_struct *p, struct pt_regs *regs)
  438. {
  439. struct pt_regs *childregs;
  440. unsigned long long se; /* Sign extension */
  441. #ifdef CONFIG_SH_FPU
  442. if(last_task_used_math == current) {
  443. enable_fpu();
  444. save_fpu(current, regs);
  445. disable_fpu();
  446. last_task_used_math = NULL;
  447. regs->sr |= SR_FD;
  448. }
  449. #endif
  450. /* Copy from sh version */
  451. childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
  452. *childregs = *regs;
  453. if (user_mode(regs)) {
  454. childregs->regs[15] = usp;
  455. p->thread.uregs = childregs;
  456. } else {
  457. childregs->regs[15] = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  458. }
  459. childregs->regs[9] = 0; /* Set return value for child */
  460. childregs->sr |= SR_FD; /* Invalidate FPU flag */
  461. p->thread.sp = (unsigned long) childregs;
  462. p->thread.pc = (unsigned long) ret_from_fork;
  463. /*
  464. * Sign extend the edited stack.
  465. * Note that thread.pc and thread.pc will stay
  466. * 32-bit wide and context switch must take care
  467. * of NEFF sign extension.
  468. */
  469. se = childregs->regs[15];
  470. se = (se & NEFF_SIGN) ? (se | NEFF_MASK) : se;
  471. childregs->regs[15] = se;
  472. return 0;
  473. }
  474. asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
  475. unsigned long r4, unsigned long r5,
  476. unsigned long r6, unsigned long r7,
  477. struct pt_regs *pregs)
  478. {
  479. return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  480. }
  481. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  482. unsigned long r4, unsigned long r5,
  483. unsigned long r6, unsigned long r7,
  484. struct pt_regs *pregs)
  485. {
  486. if (!newsp)
  487. newsp = pregs->regs[15];
  488. return do_fork(clone_flags, newsp, pregs, 0, 0, 0);
  489. }
  490. /*
  491. * This is trivial, and on the face of it looks like it
  492. * could equally well be done in user mode.
  493. *
  494. * Not so, for quite unobvious reasons - register pressure.
  495. * In user mode vfork() cannot have a stack frame, and if
  496. * done by calling the "clone()" system call directly, you
  497. * do not have enough call-clobbered registers to hold all
  498. * the information you need.
  499. */
  500. asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,
  501. unsigned long r4, unsigned long r5,
  502. unsigned long r6, unsigned long r7,
  503. struct pt_regs *pregs)
  504. {
  505. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  506. }
  507. /*
  508. * sys_execve() executes a new program.
  509. */
  510. asmlinkage int sys_execve(char *ufilename, char **uargv,
  511. char **uenvp, unsigned long r5,
  512. unsigned long r6, unsigned long r7,
  513. struct pt_regs *pregs)
  514. {
  515. int error;
  516. char *filename;
  517. lock_kernel();
  518. filename = getname((char __user *)ufilename);
  519. error = PTR_ERR(filename);
  520. if (IS_ERR(filename))
  521. goto out;
  522. error = do_execve(filename,
  523. (char __user * __user *)uargv,
  524. (char __user * __user *)uenvp,
  525. pregs);
  526. if (error == 0) {
  527. task_lock(current);
  528. current->ptrace &= ~PT_DTRACE;
  529. task_unlock(current);
  530. }
  531. putname(filename);
  532. out:
  533. unlock_kernel();
  534. return error;
  535. }
  536. /*
  537. * These bracket the sleeping functions..
  538. */
  539. extern void interruptible_sleep_on(wait_queue_head_t *q);
  540. #define mid_sched ((unsigned long) interruptible_sleep_on)
  541. #ifdef CONFIG_FRAME_POINTER
  542. static int in_sh64_switch_to(unsigned long pc)
  543. {
  544. extern char __sh64_switch_to_end;
  545. /* For a sleeping task, the PC is somewhere in the middle of the function,
  546. so we don't have to worry about masking the LSB off */
  547. return (pc >= (unsigned long) sh64_switch_to) &&
  548. (pc < (unsigned long) &__sh64_switch_to_end);
  549. }
  550. #endif
  551. unsigned long get_wchan(struct task_struct *p)
  552. {
  553. unsigned long pc;
  554. if (!p || p == current || p->state == TASK_RUNNING)
  555. return 0;
  556. /*
  557. * The same comment as on the Alpha applies here, too ...
  558. */
  559. pc = thread_saved_pc(p);
  560. #ifdef CONFIG_FRAME_POINTER
  561. if (in_sh64_switch_to(pc)) {
  562. unsigned long schedule_fp;
  563. unsigned long sh64_switch_to_fp;
  564. unsigned long schedule_caller_pc;
  565. sh64_switch_to_fp = (long) p->thread.sp;
  566. /* r14 is saved at offset 4 in the sh64_switch_to frame */
  567. schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
  568. /* and the caller of 'schedule' is (currently!) saved at offset 24
  569. in the frame of schedule (from disasm) */
  570. schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
  571. return schedule_caller_pc;
  572. }
  573. #endif
  574. return pc;
  575. }
  576. /* Provide a /proc/asids file that lists out the
  577. ASIDs currently associated with the processes. (If the DM.PC register is
  578. examined through the debug link, this shows ASID + PC. To make use of this,
  579. the PID->ASID relationship needs to be known. This is primarily for
  580. debugging.)
  581. */
  582. #if defined(CONFIG_SH64_PROC_ASIDS)
  583. static int
  584. asids_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
  585. {
  586. int len=0;
  587. struct task_struct *p;
  588. read_lock(&tasklist_lock);
  589. for_each_process(p) {
  590. int pid = p->pid;
  591. if (!pid)
  592. continue;
  593. if (p->mm)
  594. len += sprintf(buf+len, "%5d : %02lx\n", pid,
  595. asid_cache(smp_processor_id()));
  596. else
  597. len += sprintf(buf+len, "%5d : (none)\n", pid);
  598. }
  599. read_unlock(&tasklist_lock);
  600. *eof = 1;
  601. return len;
  602. }
  603. static int __init register_proc_asids(void)
  604. {
  605. create_proc_read_entry("asids", 0, NULL, asids_proc_info, NULL);
  606. return 0;
  607. }
  608. __initcall(register_proc_asids);
  609. #endif