process.c 23 KB

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