process.c 18 KB

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