process_64.c 18 KB

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