process.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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. /* Temporary flags/tests. All to be removed/undefined. BEGIN */
  23. #define IDLE_TRACE
  24. #define VM_SHOW_TABLES
  25. #define VM_TEST_FAULT
  26. #define VM_TEST_RTLBMISS
  27. #define VM_TEST_WTLBMISS
  28. #undef VM_SHOW_TABLES
  29. #undef IDLE_TRACE
  30. /* Temporary flags/tests. All to be removed/undefined. END */
  31. #define __KERNEL_SYSCALLS__
  32. #include <stdarg.h>
  33. #include <linux/kernel.h>
  34. #include <linux/rwsem.h>
  35. #include <linux/mm.h>
  36. #include <linux/smp.h>
  37. #include <linux/smp_lock.h>
  38. #include <linux/ptrace.h>
  39. #include <linux/slab.h>
  40. #include <linux/vmalloc.h>
  41. #include <linux/user.h>
  42. #include <linux/a.out.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/unistd.h>
  45. #include <linux/delay.h>
  46. #include <linux/reboot.h>
  47. #include <linux/init.h>
  48. #include <asm/uaccess.h>
  49. #include <asm/pgtable.h>
  50. #include <asm/system.h>
  51. #include <asm/io.h>
  52. #include <asm/processor.h> /* includes also <asm/registers.h> */
  53. #include <asm/mmu_context.h>
  54. #include <asm/elf.h>
  55. #include <asm/page.h>
  56. #include <linux/irq.h>
  57. struct task_struct *last_task_used_math = NULL;
  58. #ifdef IDLE_TRACE
  59. #ifdef VM_SHOW_TABLES
  60. /* For testing */
  61. static void print_PTE(long base)
  62. {
  63. int i, skip=0;
  64. long long x, y, *p = (long long *) base;
  65. for (i=0; i< 512; i++, p++){
  66. if (*p == 0) {
  67. if (!skip) {
  68. skip++;
  69. printk("(0s) ");
  70. }
  71. } else {
  72. skip=0;
  73. x = (*p) >> 32;
  74. y = (*p) & 0xffffffff;
  75. printk("%08Lx%08Lx ", x, y);
  76. if (!((i+1)&0x3)) printk("\n");
  77. }
  78. }
  79. }
  80. /* For testing */
  81. static void print_DIR(long base)
  82. {
  83. int i, skip=0;
  84. long *p = (long *) base;
  85. for (i=0; i< 512; i++, p++){
  86. if (*p == 0) {
  87. if (!skip) {
  88. skip++;
  89. printk("(0s) ");
  90. }
  91. } else {
  92. skip=0;
  93. printk("%08lx ", *p);
  94. if (!((i+1)&0x7)) printk("\n");
  95. }
  96. }
  97. }
  98. /* For testing */
  99. static void print_vmalloc_first_tables(void)
  100. {
  101. #define PRESENT 0x800 /* Bit 11 */
  102. /*
  103. * Do it really dirty by looking at raw addresses,
  104. * raw offsets, no types. If we used pgtable/pgalloc
  105. * macros/definitions we could hide potential bugs.
  106. *
  107. * Note that pointers are 32-bit for CDC.
  108. */
  109. long pgdt, pmdt, ptet;
  110. pgdt = (long) &swapper_pg_dir;
  111. printk("-->PGD (0x%08lx):\n", pgdt);
  112. print_DIR(pgdt);
  113. printk("\n");
  114. /* VMALLOC pool is mapped at 0xc0000000, second (pointer) entry in PGD */
  115. pgdt += 4;
  116. pmdt = (long) (* (long *) pgdt);
  117. if (!(pmdt & PRESENT)) {
  118. printk("No PMD\n");
  119. return;
  120. } else pmdt &= 0xfffff000;
  121. printk("-->PMD (0x%08lx):\n", pmdt);
  122. print_DIR(pmdt);
  123. printk("\n");
  124. /* Get the pmdt displacement for 0xc0000000 */
  125. pmdt += 2048;
  126. /* just look at first two address ranges ... */
  127. /* ... 0xc0000000 ... */
  128. ptet = (long) (* (long *) pmdt);
  129. if (!(ptet & PRESENT)) {
  130. printk("No PTE0\n");
  131. return;
  132. } else ptet &= 0xfffff000;
  133. printk("-->PTE0 (0x%08lx):\n", ptet);
  134. print_PTE(ptet);
  135. printk("\n");
  136. /* ... 0xc0001000 ... */
  137. ptet += 4;
  138. if (!(ptet & PRESENT)) {
  139. printk("No PTE1\n");
  140. return;
  141. } else ptet &= 0xfffff000;
  142. printk("-->PTE1 (0x%08lx):\n", ptet);
  143. print_PTE(ptet);
  144. printk("\n");
  145. }
  146. #else
  147. #define print_vmalloc_first_tables()
  148. #endif /* VM_SHOW_TABLES */
  149. static void test_VM(void)
  150. {
  151. void *a, *b, *c;
  152. #ifdef VM_SHOW_TABLES
  153. printk("Initial PGD/PMD/PTE\n");
  154. #endif
  155. print_vmalloc_first_tables();
  156. printk("Allocating 2 bytes\n");
  157. a = vmalloc(2);
  158. print_vmalloc_first_tables();
  159. printk("Allocating 4100 bytes\n");
  160. b = vmalloc(4100);
  161. print_vmalloc_first_tables();
  162. printk("Allocating 20234 bytes\n");
  163. c = vmalloc(20234);
  164. print_vmalloc_first_tables();
  165. #ifdef VM_TEST_FAULT
  166. /* Here you may want to fault ! */
  167. #ifdef VM_TEST_RTLBMISS
  168. printk("Ready to fault upon read.\n");
  169. if (* (char *) a) {
  170. printk("RTLBMISSed on area a !\n");
  171. }
  172. printk("RTLBMISSed on area a !\n");
  173. #endif
  174. #ifdef VM_TEST_WTLBMISS
  175. printk("Ready to fault upon write.\n");
  176. *((char *) b) = 'L';
  177. printk("WTLBMISSed on area b !\n");
  178. #endif
  179. #endif /* VM_TEST_FAULT */
  180. printk("Deallocating the 4100 byte chunk\n");
  181. vfree(b);
  182. print_vmalloc_first_tables();
  183. printk("Deallocating the 2 byte chunk\n");
  184. vfree(a);
  185. print_vmalloc_first_tables();
  186. printk("Deallocating the last chunk\n");
  187. vfree(c);
  188. print_vmalloc_first_tables();
  189. }
  190. extern unsigned long volatile jiffies;
  191. int once = 0;
  192. unsigned long old_jiffies;
  193. int pid = -1, pgid = -1;
  194. void idle_trace(void)
  195. {
  196. _syscall0(int, getpid)
  197. _syscall1(int, getpgid, int, pid)
  198. if (!once) {
  199. /* VM allocation/deallocation simple test */
  200. test_VM();
  201. pid = getpid();
  202. printk("Got all through to Idle !!\n");
  203. printk("I'm now going to loop forever ...\n");
  204. printk("Any ! below is a timer tick.\n");
  205. printk("Any . below is a getpgid system call from pid = %d.\n", pid);
  206. old_jiffies = jiffies;
  207. once++;
  208. }
  209. if (old_jiffies != jiffies) {
  210. old_jiffies = jiffies - old_jiffies;
  211. switch (old_jiffies) {
  212. case 1:
  213. printk("!");
  214. break;
  215. case 2:
  216. printk("!!");
  217. break;
  218. case 3:
  219. printk("!!!");
  220. break;
  221. case 4:
  222. printk("!!!!");
  223. break;
  224. default:
  225. printk("(%d!)", (int) old_jiffies);
  226. }
  227. old_jiffies = jiffies;
  228. }
  229. pgid = getpgid(pid);
  230. printk(".");
  231. }
  232. #else
  233. #define idle_trace() do { } while (0)
  234. #endif /* IDLE_TRACE */
  235. static int hlt_counter = 1;
  236. #define HARD_IDLE_TIMEOUT (HZ / 3)
  237. void disable_hlt(void)
  238. {
  239. hlt_counter++;
  240. }
  241. void enable_hlt(void)
  242. {
  243. hlt_counter--;
  244. }
  245. static int __init nohlt_setup(char *__unused)
  246. {
  247. hlt_counter = 1;
  248. return 1;
  249. }
  250. static int __init hlt_setup(char *__unused)
  251. {
  252. hlt_counter = 0;
  253. return 1;
  254. }
  255. __setup("nohlt", nohlt_setup);
  256. __setup("hlt", hlt_setup);
  257. static inline void hlt(void)
  258. {
  259. __asm__ __volatile__ ("sleep" : : : "memory");
  260. }
  261. /*
  262. * The idle loop on a uniprocessor SH..
  263. */
  264. void cpu_idle(void)
  265. {
  266. /* endless idle loop with no priority at all */
  267. while (1) {
  268. if (hlt_counter) {
  269. while (!need_resched())
  270. cpu_relax();
  271. } else {
  272. local_irq_disable();
  273. while (!need_resched()) {
  274. local_irq_enable();
  275. idle_trace();
  276. hlt();
  277. local_irq_disable();
  278. }
  279. local_irq_enable();
  280. }
  281. preempt_enable_no_resched();
  282. schedule();
  283. preempt_disable();
  284. }
  285. }
  286. void machine_restart(char * __unused)
  287. {
  288. extern void phys_stext(void);
  289. phys_stext();
  290. }
  291. void machine_halt(void)
  292. {
  293. for (;;);
  294. }
  295. void machine_power_off(void)
  296. {
  297. extern void enter_deep_standby(void);
  298. enter_deep_standby();
  299. }
  300. void show_regs(struct pt_regs * regs)
  301. {
  302. unsigned long long ah, al, bh, bl, ch, cl;
  303. printk("\n");
  304. ah = (regs->pc) >> 32;
  305. al = (regs->pc) & 0xffffffff;
  306. bh = (regs->regs[18]) >> 32;
  307. bl = (regs->regs[18]) & 0xffffffff;
  308. ch = (regs->regs[15]) >> 32;
  309. cl = (regs->regs[15]) & 0xffffffff;
  310. printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
  311. ah, al, bh, bl, ch, cl);
  312. ah = (regs->sr) >> 32;
  313. al = (regs->sr) & 0xffffffff;
  314. asm volatile ("getcon " __TEA ", %0" : "=r" (bh));
  315. asm volatile ("getcon " __TEA ", %0" : "=r" (bl));
  316. bh = (bh) >> 32;
  317. bl = (bl) & 0xffffffff;
  318. asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch));
  319. asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl));
  320. ch = (ch) >> 32;
  321. cl = (cl) & 0xffffffff;
  322. printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
  323. ah, al, bh, bl, ch, cl);
  324. ah = (regs->regs[0]) >> 32;
  325. al = (regs->regs[0]) & 0xffffffff;
  326. bh = (regs->regs[1]) >> 32;
  327. bl = (regs->regs[1]) & 0xffffffff;
  328. ch = (regs->regs[2]) >> 32;
  329. cl = (regs->regs[2]) & 0xffffffff;
  330. printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
  331. ah, al, bh, bl, ch, cl);
  332. ah = (regs->regs[3]) >> 32;
  333. al = (regs->regs[3]) & 0xffffffff;
  334. bh = (regs->regs[4]) >> 32;
  335. bl = (regs->regs[4]) & 0xffffffff;
  336. ch = (regs->regs[5]) >> 32;
  337. cl = (regs->regs[5]) & 0xffffffff;
  338. printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
  339. ah, al, bh, bl, ch, cl);
  340. ah = (regs->regs[6]) >> 32;
  341. al = (regs->regs[6]) & 0xffffffff;
  342. bh = (regs->regs[7]) >> 32;
  343. bl = (regs->regs[7]) & 0xffffffff;
  344. ch = (regs->regs[8]) >> 32;
  345. cl = (regs->regs[8]) & 0xffffffff;
  346. printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
  347. ah, al, bh, bl, ch, cl);
  348. ah = (regs->regs[9]) >> 32;
  349. al = (regs->regs[9]) & 0xffffffff;
  350. bh = (regs->regs[10]) >> 32;
  351. bl = (regs->regs[10]) & 0xffffffff;
  352. ch = (regs->regs[11]) >> 32;
  353. cl = (regs->regs[11]) & 0xffffffff;
  354. printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
  355. ah, al, bh, bl, ch, cl);
  356. ah = (regs->regs[12]) >> 32;
  357. al = (regs->regs[12]) & 0xffffffff;
  358. bh = (regs->regs[13]) >> 32;
  359. bl = (regs->regs[13]) & 0xffffffff;
  360. ch = (regs->regs[14]) >> 32;
  361. cl = (regs->regs[14]) & 0xffffffff;
  362. printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
  363. ah, al, bh, bl, ch, cl);
  364. ah = (regs->regs[16]) >> 32;
  365. al = (regs->regs[16]) & 0xffffffff;
  366. bh = (regs->regs[17]) >> 32;
  367. bl = (regs->regs[17]) & 0xffffffff;
  368. ch = (regs->regs[19]) >> 32;
  369. cl = (regs->regs[19]) & 0xffffffff;
  370. printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
  371. ah, al, bh, bl, ch, cl);
  372. ah = (regs->regs[20]) >> 32;
  373. al = (regs->regs[20]) & 0xffffffff;
  374. bh = (regs->regs[21]) >> 32;
  375. bl = (regs->regs[21]) & 0xffffffff;
  376. ch = (regs->regs[22]) >> 32;
  377. cl = (regs->regs[22]) & 0xffffffff;
  378. printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
  379. ah, al, bh, bl, ch, cl);
  380. ah = (regs->regs[23]) >> 32;
  381. al = (regs->regs[23]) & 0xffffffff;
  382. bh = (regs->regs[24]) >> 32;
  383. bl = (regs->regs[24]) & 0xffffffff;
  384. ch = (regs->regs[25]) >> 32;
  385. cl = (regs->regs[25]) & 0xffffffff;
  386. printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
  387. ah, al, bh, bl, ch, cl);
  388. ah = (regs->regs[26]) >> 32;
  389. al = (regs->regs[26]) & 0xffffffff;
  390. bh = (regs->regs[27]) >> 32;
  391. bl = (regs->regs[27]) & 0xffffffff;
  392. ch = (regs->regs[28]) >> 32;
  393. cl = (regs->regs[28]) & 0xffffffff;
  394. printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
  395. ah, al, bh, bl, ch, cl);
  396. ah = (regs->regs[29]) >> 32;
  397. al = (regs->regs[29]) & 0xffffffff;
  398. bh = (regs->regs[30]) >> 32;
  399. bl = (regs->regs[30]) & 0xffffffff;
  400. ch = (regs->regs[31]) >> 32;
  401. cl = (regs->regs[31]) & 0xffffffff;
  402. printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
  403. ah, al, bh, bl, ch, cl);
  404. ah = (regs->regs[32]) >> 32;
  405. al = (regs->regs[32]) & 0xffffffff;
  406. bh = (regs->regs[33]) >> 32;
  407. bl = (regs->regs[33]) & 0xffffffff;
  408. ch = (regs->regs[34]) >> 32;
  409. cl = (regs->regs[34]) & 0xffffffff;
  410. printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
  411. ah, al, bh, bl, ch, cl);
  412. ah = (regs->regs[35]) >> 32;
  413. al = (regs->regs[35]) & 0xffffffff;
  414. bh = (regs->regs[36]) >> 32;
  415. bl = (regs->regs[36]) & 0xffffffff;
  416. ch = (regs->regs[37]) >> 32;
  417. cl = (regs->regs[37]) & 0xffffffff;
  418. printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
  419. ah, al, bh, bl, ch, cl);
  420. ah = (regs->regs[38]) >> 32;
  421. al = (regs->regs[38]) & 0xffffffff;
  422. bh = (regs->regs[39]) >> 32;
  423. bl = (regs->regs[39]) & 0xffffffff;
  424. ch = (regs->regs[40]) >> 32;
  425. cl = (regs->regs[40]) & 0xffffffff;
  426. printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
  427. ah, al, bh, bl, ch, cl);
  428. ah = (regs->regs[41]) >> 32;
  429. al = (regs->regs[41]) & 0xffffffff;
  430. bh = (regs->regs[42]) >> 32;
  431. bl = (regs->regs[42]) & 0xffffffff;
  432. ch = (regs->regs[43]) >> 32;
  433. cl = (regs->regs[43]) & 0xffffffff;
  434. printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
  435. ah, al, bh, bl, ch, cl);
  436. ah = (regs->regs[44]) >> 32;
  437. al = (regs->regs[44]) & 0xffffffff;
  438. bh = (regs->regs[45]) >> 32;
  439. bl = (regs->regs[45]) & 0xffffffff;
  440. ch = (regs->regs[46]) >> 32;
  441. cl = (regs->regs[46]) & 0xffffffff;
  442. printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
  443. ah, al, bh, bl, ch, cl);
  444. ah = (regs->regs[47]) >> 32;
  445. al = (regs->regs[47]) & 0xffffffff;
  446. bh = (regs->regs[48]) >> 32;
  447. bl = (regs->regs[48]) & 0xffffffff;
  448. ch = (regs->regs[49]) >> 32;
  449. cl = (regs->regs[49]) & 0xffffffff;
  450. printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
  451. ah, al, bh, bl, ch, cl);
  452. ah = (regs->regs[50]) >> 32;
  453. al = (regs->regs[50]) & 0xffffffff;
  454. bh = (regs->regs[51]) >> 32;
  455. bl = (regs->regs[51]) & 0xffffffff;
  456. ch = (regs->regs[52]) >> 32;
  457. cl = (regs->regs[52]) & 0xffffffff;
  458. printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
  459. ah, al, bh, bl, ch, cl);
  460. ah = (regs->regs[53]) >> 32;
  461. al = (regs->regs[53]) & 0xffffffff;
  462. bh = (regs->regs[54]) >> 32;
  463. bl = (regs->regs[54]) & 0xffffffff;
  464. ch = (regs->regs[55]) >> 32;
  465. cl = (regs->regs[55]) & 0xffffffff;
  466. printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
  467. ah, al, bh, bl, ch, cl);
  468. ah = (regs->regs[56]) >> 32;
  469. al = (regs->regs[56]) & 0xffffffff;
  470. bh = (regs->regs[57]) >> 32;
  471. bl = (regs->regs[57]) & 0xffffffff;
  472. ch = (regs->regs[58]) >> 32;
  473. cl = (regs->regs[58]) & 0xffffffff;
  474. printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
  475. ah, al, bh, bl, ch, cl);
  476. ah = (regs->regs[59]) >> 32;
  477. al = (regs->regs[59]) & 0xffffffff;
  478. bh = (regs->regs[60]) >> 32;
  479. bl = (regs->regs[60]) & 0xffffffff;
  480. ch = (regs->regs[61]) >> 32;
  481. cl = (regs->regs[61]) & 0xffffffff;
  482. printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
  483. ah, al, bh, bl, ch, cl);
  484. ah = (regs->regs[62]) >> 32;
  485. al = (regs->regs[62]) & 0xffffffff;
  486. bh = (regs->tregs[0]) >> 32;
  487. bl = (regs->tregs[0]) & 0xffffffff;
  488. ch = (regs->tregs[1]) >> 32;
  489. cl = (regs->tregs[1]) & 0xffffffff;
  490. printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n",
  491. ah, al, bh, bl, ch, cl);
  492. ah = (regs->tregs[2]) >> 32;
  493. al = (regs->tregs[2]) & 0xffffffff;
  494. bh = (regs->tregs[3]) >> 32;
  495. bl = (regs->tregs[3]) & 0xffffffff;
  496. ch = (regs->tregs[4]) >> 32;
  497. cl = (regs->tregs[4]) & 0xffffffff;
  498. printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n",
  499. ah, al, bh, bl, ch, cl);
  500. ah = (regs->tregs[5]) >> 32;
  501. al = (regs->tregs[5]) & 0xffffffff;
  502. bh = (regs->tregs[6]) >> 32;
  503. bl = (regs->tregs[6]) & 0xffffffff;
  504. ch = (regs->tregs[7]) >> 32;
  505. cl = (regs->tregs[7]) & 0xffffffff;
  506. printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n",
  507. ah, al, bh, bl, ch, cl);
  508. /*
  509. * If we're in kernel mode, dump the stack too..
  510. */
  511. if (!user_mode(regs)) {
  512. void show_stack(struct task_struct *tsk, unsigned long *sp);
  513. unsigned long sp = regs->regs[15] & 0xffffffff;
  514. struct task_struct *tsk = get_current();
  515. tsk->thread.kregs = regs;
  516. show_stack(tsk, (unsigned long *)sp);
  517. }
  518. }
  519. struct task_struct * alloc_task_struct(void)
  520. {
  521. /* Get task descriptor pages */
  522. return (struct task_struct *)
  523. __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE));
  524. }
  525. void free_task_struct(struct task_struct *p)
  526. {
  527. free_pages((unsigned long) p, get_order(THREAD_SIZE));
  528. }
  529. /*
  530. * Create a kernel thread
  531. */
  532. /*
  533. * This is the mechanism for creating a new kernel thread.
  534. *
  535. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  536. * who haven't done an "execve()") should use this: it will work within
  537. * a system call from a "real" process, but the process memory space will
  538. * not be free'd until both the parent and the child have exited.
  539. */
  540. int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  541. {
  542. /* A bit less processor dependent than older sh ... */
  543. unsigned int reply;
  544. static __inline__ _syscall2(int,clone,unsigned long,flags,unsigned long,newsp)
  545. static __inline__ _syscall1(int,exit,int,ret)
  546. reply = clone(flags | CLONE_VM, 0);
  547. if (!reply) {
  548. /* Child */
  549. reply = exit(fn(arg));
  550. }
  551. return reply;
  552. }
  553. /*
  554. * Free current thread data structures etc..
  555. */
  556. void exit_thread(void)
  557. {
  558. /* See arch/sparc/kernel/process.c for the precedent for doing this -- RPC.
  559. The SH-5 FPU save/restore approach relies on last_task_used_math
  560. pointing to a live task_struct. When another task tries to use the
  561. FPU for the 1st time, the FPUDIS trap handling (see
  562. arch/sh64/kernel/fpu.c) will save the existing FPU state to the
  563. FP regs field within last_task_used_math before re-loading the new
  564. task's FPU state (or initialising it if the FPU has been used
  565. before). So if last_task_used_math is stale, and its page has already been
  566. re-allocated for another use, the consequences are rather grim. Unless we
  567. null it here, there is no other path through which it would get safely
  568. nulled. */
  569. #ifdef CONFIG_SH_FPU
  570. if (last_task_used_math == current) {
  571. last_task_used_math = NULL;
  572. }
  573. #endif
  574. }
  575. void flush_thread(void)
  576. {
  577. /* Called by fs/exec.c (flush_old_exec) to remove traces of a
  578. * previously running executable. */
  579. #ifdef CONFIG_SH_FPU
  580. if (last_task_used_math == current) {
  581. last_task_used_math = NULL;
  582. }
  583. /* Force FPU state to be reinitialised after exec */
  584. clear_used_math();
  585. #endif
  586. /* if we are a kernel thread, about to change to user thread,
  587. * update kreg
  588. */
  589. if(current->thread.kregs==&fake_swapper_regs) {
  590. current->thread.kregs =
  591. ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
  592. current->thread.uregs = current->thread.kregs;
  593. }
  594. }
  595. void release_thread(struct task_struct *dead_task)
  596. {
  597. /* do nothing */
  598. }
  599. /* Fill in the fpu structure for a core dump.. */
  600. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  601. {
  602. #ifdef CONFIG_SH_FPU
  603. int fpvalid;
  604. struct task_struct *tsk = current;
  605. fpvalid = !!tsk_used_math(tsk);
  606. if (fpvalid) {
  607. if (current == last_task_used_math) {
  608. grab_fpu();
  609. fpsave(&tsk->thread.fpu.hard);
  610. release_fpu();
  611. last_task_used_math = 0;
  612. regs->sr |= SR_FD;
  613. }
  614. memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));
  615. }
  616. return fpvalid;
  617. #else
  618. return 0; /* Task didn't use the fpu at all. */
  619. #endif
  620. }
  621. asmlinkage void ret_from_fork(void);
  622. int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
  623. unsigned long unused,
  624. struct task_struct *p, struct pt_regs *regs)
  625. {
  626. struct pt_regs *childregs;
  627. unsigned long long se; /* Sign extension */
  628. #ifdef CONFIG_SH_FPU
  629. if(last_task_used_math == current) {
  630. grab_fpu();
  631. fpsave(&current->thread.fpu.hard);
  632. release_fpu();
  633. last_task_used_math = NULL;
  634. regs->sr |= SR_FD;
  635. }
  636. #endif
  637. /* Copy from sh version */
  638. childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
  639. *childregs = *regs;
  640. if (user_mode(regs)) {
  641. childregs->regs[15] = usp;
  642. p->thread.uregs = childregs;
  643. } else {
  644. childregs->regs[15] = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  645. }
  646. childregs->regs[9] = 0; /* Set return value for child */
  647. childregs->sr |= SR_FD; /* Invalidate FPU flag */
  648. p->thread.sp = (unsigned long) childregs;
  649. p->thread.pc = (unsigned long) ret_from_fork;
  650. /*
  651. * Sign extend the edited stack.
  652. * Note that thread.pc and thread.pc will stay
  653. * 32-bit wide and context switch must take care
  654. * of NEFF sign extension.
  655. */
  656. se = childregs->regs[15];
  657. se = (se & NEFF_SIGN) ? (se | NEFF_MASK) : se;
  658. childregs->regs[15] = se;
  659. return 0;
  660. }
  661. asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
  662. unsigned long r4, unsigned long r5,
  663. unsigned long r6, unsigned long r7,
  664. struct pt_regs *pregs)
  665. {
  666. return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  667. }
  668. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  669. unsigned long r4, unsigned long r5,
  670. unsigned long r6, unsigned long r7,
  671. struct pt_regs *pregs)
  672. {
  673. if (!newsp)
  674. newsp = pregs->regs[15];
  675. return do_fork(clone_flags, newsp, pregs, 0, 0, 0);
  676. }
  677. /*
  678. * This is trivial, and on the face of it looks like it
  679. * could equally well be done in user mode.
  680. *
  681. * Not so, for quite unobvious reasons - register pressure.
  682. * In user mode vfork() cannot have a stack frame, and if
  683. * done by calling the "clone()" system call directly, you
  684. * do not have enough call-clobbered registers to hold all
  685. * the information you need.
  686. */
  687. asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,
  688. unsigned long r4, unsigned long r5,
  689. unsigned long r6, unsigned long r7,
  690. struct pt_regs *pregs)
  691. {
  692. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  693. }
  694. /*
  695. * sys_execve() executes a new program.
  696. */
  697. asmlinkage int sys_execve(char *ufilename, char **uargv,
  698. char **uenvp, unsigned long r5,
  699. unsigned long r6, unsigned long r7,
  700. struct pt_regs *pregs)
  701. {
  702. int error;
  703. char *filename;
  704. lock_kernel();
  705. filename = getname((char __user *)ufilename);
  706. error = PTR_ERR(filename);
  707. if (IS_ERR(filename))
  708. goto out;
  709. error = do_execve(filename,
  710. (char __user * __user *)uargv,
  711. (char __user * __user *)uenvp,
  712. pregs);
  713. if (error == 0) {
  714. task_lock(current);
  715. current->ptrace &= ~PT_DTRACE;
  716. task_unlock(current);
  717. }
  718. putname(filename);
  719. out:
  720. unlock_kernel();
  721. return error;
  722. }
  723. /*
  724. * These bracket the sleeping functions..
  725. */
  726. extern void interruptible_sleep_on(wait_queue_head_t *q);
  727. #define mid_sched ((unsigned long) interruptible_sleep_on)
  728. static int in_sh64_switch_to(unsigned long pc)
  729. {
  730. extern char __sh64_switch_to_end;
  731. /* For a sleeping task, the PC is somewhere in the middle of the function,
  732. so we don't have to worry about masking the LSB off */
  733. return (pc >= (unsigned long) sh64_switch_to) &&
  734. (pc < (unsigned long) &__sh64_switch_to_end);
  735. }
  736. unsigned long get_wchan(struct task_struct *p)
  737. {
  738. unsigned long schedule_fp;
  739. unsigned long sh64_switch_to_fp;
  740. unsigned long schedule_caller_pc;
  741. unsigned long pc;
  742. if (!p || p == current || p->state == TASK_RUNNING)
  743. return 0;
  744. /*
  745. * The same comment as on the Alpha applies here, too ...
  746. */
  747. pc = thread_saved_pc(p);
  748. #ifdef CONFIG_FRAME_POINTER
  749. if (in_sh64_switch_to(pc)) {
  750. sh64_switch_to_fp = (long) p->thread.sp;
  751. /* r14 is saved at offset 4 in the sh64_switch_to frame */
  752. schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
  753. /* and the caller of 'schedule' is (currently!) saved at offset 24
  754. in the frame of schedule (from disasm) */
  755. schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
  756. return schedule_caller_pc;
  757. }
  758. #endif
  759. return pc;
  760. }
  761. /* Provide a /proc/asids file that lists out the
  762. ASIDs currently associated with the processes. (If the DM.PC register is
  763. examined through the debug link, this shows ASID + PC. To make use of this,
  764. the PID->ASID relationship needs to be known. This is primarily for
  765. debugging.)
  766. */
  767. #if defined(CONFIG_SH64_PROC_ASIDS)
  768. #include <linux/init.h>
  769. #include <linux/proc_fs.h>
  770. static int
  771. asids_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
  772. {
  773. int len=0;
  774. struct task_struct *p;
  775. read_lock(&tasklist_lock);
  776. for_each_process(p) {
  777. int pid = p->pid;
  778. struct mm_struct *mm;
  779. if (!pid) continue;
  780. mm = p->mm;
  781. if (mm) {
  782. unsigned long asid, context;
  783. context = mm->context;
  784. asid = (context & 0xff);
  785. len += sprintf(buf+len, "%5d : %02lx\n", pid, asid);
  786. } else {
  787. len += sprintf(buf+len, "%5d : (none)\n", pid);
  788. }
  789. }
  790. read_unlock(&tasklist_lock);
  791. *eof = 1;
  792. return len;
  793. }
  794. static int __init register_proc_asids(void)
  795. {
  796. create_proc_read_entry("asids", 0, NULL, asids_proc_info, NULL);
  797. return 0;
  798. }
  799. __initcall(register_proc_asids);
  800. #endif