process_64.c 18 KB

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