process.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  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 (*pm_power_off)(void) = machine_power_off;
  301. EXPORT_SYMBOL(pm_power_off);
  302. void show_regs(struct pt_regs * regs)
  303. {
  304. unsigned long long ah, al, bh, bl, ch, cl;
  305. printk("\n");
  306. ah = (regs->pc) >> 32;
  307. al = (regs->pc) & 0xffffffff;
  308. bh = (regs->regs[18]) >> 32;
  309. bl = (regs->regs[18]) & 0xffffffff;
  310. ch = (regs->regs[15]) >> 32;
  311. cl = (regs->regs[15]) & 0xffffffff;
  312. printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
  313. ah, al, bh, bl, ch, cl);
  314. ah = (regs->sr) >> 32;
  315. al = (regs->sr) & 0xffffffff;
  316. asm volatile ("getcon " __TEA ", %0" : "=r" (bh));
  317. asm volatile ("getcon " __TEA ", %0" : "=r" (bl));
  318. bh = (bh) >> 32;
  319. bl = (bl) & 0xffffffff;
  320. asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch));
  321. asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl));
  322. ch = (ch) >> 32;
  323. cl = (cl) & 0xffffffff;
  324. printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
  325. ah, al, bh, bl, ch, cl);
  326. ah = (regs->regs[0]) >> 32;
  327. al = (regs->regs[0]) & 0xffffffff;
  328. bh = (regs->regs[1]) >> 32;
  329. bl = (regs->regs[1]) & 0xffffffff;
  330. ch = (regs->regs[2]) >> 32;
  331. cl = (regs->regs[2]) & 0xffffffff;
  332. printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
  333. ah, al, bh, bl, ch, cl);
  334. ah = (regs->regs[3]) >> 32;
  335. al = (regs->regs[3]) & 0xffffffff;
  336. bh = (regs->regs[4]) >> 32;
  337. bl = (regs->regs[4]) & 0xffffffff;
  338. ch = (regs->regs[5]) >> 32;
  339. cl = (regs->regs[5]) & 0xffffffff;
  340. printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
  341. ah, al, bh, bl, ch, cl);
  342. ah = (regs->regs[6]) >> 32;
  343. al = (regs->regs[6]) & 0xffffffff;
  344. bh = (regs->regs[7]) >> 32;
  345. bl = (regs->regs[7]) & 0xffffffff;
  346. ch = (regs->regs[8]) >> 32;
  347. cl = (regs->regs[8]) & 0xffffffff;
  348. printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
  349. ah, al, bh, bl, ch, cl);
  350. ah = (regs->regs[9]) >> 32;
  351. al = (regs->regs[9]) & 0xffffffff;
  352. bh = (regs->regs[10]) >> 32;
  353. bl = (regs->regs[10]) & 0xffffffff;
  354. ch = (regs->regs[11]) >> 32;
  355. cl = (regs->regs[11]) & 0xffffffff;
  356. printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
  357. ah, al, bh, bl, ch, cl);
  358. ah = (regs->regs[12]) >> 32;
  359. al = (regs->regs[12]) & 0xffffffff;
  360. bh = (regs->regs[13]) >> 32;
  361. bl = (regs->regs[13]) & 0xffffffff;
  362. ch = (regs->regs[14]) >> 32;
  363. cl = (regs->regs[14]) & 0xffffffff;
  364. printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
  365. ah, al, bh, bl, ch, cl);
  366. ah = (regs->regs[16]) >> 32;
  367. al = (regs->regs[16]) & 0xffffffff;
  368. bh = (regs->regs[17]) >> 32;
  369. bl = (regs->regs[17]) & 0xffffffff;
  370. ch = (regs->regs[19]) >> 32;
  371. cl = (regs->regs[19]) & 0xffffffff;
  372. printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
  373. ah, al, bh, bl, ch, cl);
  374. ah = (regs->regs[20]) >> 32;
  375. al = (regs->regs[20]) & 0xffffffff;
  376. bh = (regs->regs[21]) >> 32;
  377. bl = (regs->regs[21]) & 0xffffffff;
  378. ch = (regs->regs[22]) >> 32;
  379. cl = (regs->regs[22]) & 0xffffffff;
  380. printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
  381. ah, al, bh, bl, ch, cl);
  382. ah = (regs->regs[23]) >> 32;
  383. al = (regs->regs[23]) & 0xffffffff;
  384. bh = (regs->regs[24]) >> 32;
  385. bl = (regs->regs[24]) & 0xffffffff;
  386. ch = (regs->regs[25]) >> 32;
  387. cl = (regs->regs[25]) & 0xffffffff;
  388. printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
  389. ah, al, bh, bl, ch, cl);
  390. ah = (regs->regs[26]) >> 32;
  391. al = (regs->regs[26]) & 0xffffffff;
  392. bh = (regs->regs[27]) >> 32;
  393. bl = (regs->regs[27]) & 0xffffffff;
  394. ch = (regs->regs[28]) >> 32;
  395. cl = (regs->regs[28]) & 0xffffffff;
  396. printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
  397. ah, al, bh, bl, ch, cl);
  398. ah = (regs->regs[29]) >> 32;
  399. al = (regs->regs[29]) & 0xffffffff;
  400. bh = (regs->regs[30]) >> 32;
  401. bl = (regs->regs[30]) & 0xffffffff;
  402. ch = (regs->regs[31]) >> 32;
  403. cl = (regs->regs[31]) & 0xffffffff;
  404. printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
  405. ah, al, bh, bl, ch, cl);
  406. ah = (regs->regs[32]) >> 32;
  407. al = (regs->regs[32]) & 0xffffffff;
  408. bh = (regs->regs[33]) >> 32;
  409. bl = (regs->regs[33]) & 0xffffffff;
  410. ch = (regs->regs[34]) >> 32;
  411. cl = (regs->regs[34]) & 0xffffffff;
  412. printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
  413. ah, al, bh, bl, ch, cl);
  414. ah = (regs->regs[35]) >> 32;
  415. al = (regs->regs[35]) & 0xffffffff;
  416. bh = (regs->regs[36]) >> 32;
  417. bl = (regs->regs[36]) & 0xffffffff;
  418. ch = (regs->regs[37]) >> 32;
  419. cl = (regs->regs[37]) & 0xffffffff;
  420. printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
  421. ah, al, bh, bl, ch, cl);
  422. ah = (regs->regs[38]) >> 32;
  423. al = (regs->regs[38]) & 0xffffffff;
  424. bh = (regs->regs[39]) >> 32;
  425. bl = (regs->regs[39]) & 0xffffffff;
  426. ch = (regs->regs[40]) >> 32;
  427. cl = (regs->regs[40]) & 0xffffffff;
  428. printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
  429. ah, al, bh, bl, ch, cl);
  430. ah = (regs->regs[41]) >> 32;
  431. al = (regs->regs[41]) & 0xffffffff;
  432. bh = (regs->regs[42]) >> 32;
  433. bl = (regs->regs[42]) & 0xffffffff;
  434. ch = (regs->regs[43]) >> 32;
  435. cl = (regs->regs[43]) & 0xffffffff;
  436. printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
  437. ah, al, bh, bl, ch, cl);
  438. ah = (regs->regs[44]) >> 32;
  439. al = (regs->regs[44]) & 0xffffffff;
  440. bh = (regs->regs[45]) >> 32;
  441. bl = (regs->regs[45]) & 0xffffffff;
  442. ch = (regs->regs[46]) >> 32;
  443. cl = (regs->regs[46]) & 0xffffffff;
  444. printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
  445. ah, al, bh, bl, ch, cl);
  446. ah = (regs->regs[47]) >> 32;
  447. al = (regs->regs[47]) & 0xffffffff;
  448. bh = (regs->regs[48]) >> 32;
  449. bl = (regs->regs[48]) & 0xffffffff;
  450. ch = (regs->regs[49]) >> 32;
  451. cl = (regs->regs[49]) & 0xffffffff;
  452. printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
  453. ah, al, bh, bl, ch, cl);
  454. ah = (regs->regs[50]) >> 32;
  455. al = (regs->regs[50]) & 0xffffffff;
  456. bh = (regs->regs[51]) >> 32;
  457. bl = (regs->regs[51]) & 0xffffffff;
  458. ch = (regs->regs[52]) >> 32;
  459. cl = (regs->regs[52]) & 0xffffffff;
  460. printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
  461. ah, al, bh, bl, ch, cl);
  462. ah = (regs->regs[53]) >> 32;
  463. al = (regs->regs[53]) & 0xffffffff;
  464. bh = (regs->regs[54]) >> 32;
  465. bl = (regs->regs[54]) & 0xffffffff;
  466. ch = (regs->regs[55]) >> 32;
  467. cl = (regs->regs[55]) & 0xffffffff;
  468. printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
  469. ah, al, bh, bl, ch, cl);
  470. ah = (regs->regs[56]) >> 32;
  471. al = (regs->regs[56]) & 0xffffffff;
  472. bh = (regs->regs[57]) >> 32;
  473. bl = (regs->regs[57]) & 0xffffffff;
  474. ch = (regs->regs[58]) >> 32;
  475. cl = (regs->regs[58]) & 0xffffffff;
  476. printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
  477. ah, al, bh, bl, ch, cl);
  478. ah = (regs->regs[59]) >> 32;
  479. al = (regs->regs[59]) & 0xffffffff;
  480. bh = (regs->regs[60]) >> 32;
  481. bl = (regs->regs[60]) & 0xffffffff;
  482. ch = (regs->regs[61]) >> 32;
  483. cl = (regs->regs[61]) & 0xffffffff;
  484. printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
  485. ah, al, bh, bl, ch, cl);
  486. ah = (regs->regs[62]) >> 32;
  487. al = (regs->regs[62]) & 0xffffffff;
  488. bh = (regs->tregs[0]) >> 32;
  489. bl = (regs->tregs[0]) & 0xffffffff;
  490. ch = (regs->tregs[1]) >> 32;
  491. cl = (regs->tregs[1]) & 0xffffffff;
  492. printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n",
  493. ah, al, bh, bl, ch, cl);
  494. ah = (regs->tregs[2]) >> 32;
  495. al = (regs->tregs[2]) & 0xffffffff;
  496. bh = (regs->tregs[3]) >> 32;
  497. bl = (regs->tregs[3]) & 0xffffffff;
  498. ch = (regs->tregs[4]) >> 32;
  499. cl = (regs->tregs[4]) & 0xffffffff;
  500. printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n",
  501. ah, al, bh, bl, ch, cl);
  502. ah = (regs->tregs[5]) >> 32;
  503. al = (regs->tregs[5]) & 0xffffffff;
  504. bh = (regs->tregs[6]) >> 32;
  505. bl = (regs->tregs[6]) & 0xffffffff;
  506. ch = (regs->tregs[7]) >> 32;
  507. cl = (regs->tregs[7]) & 0xffffffff;
  508. printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n",
  509. ah, al, bh, bl, ch, cl);
  510. /*
  511. * If we're in kernel mode, dump the stack too..
  512. */
  513. if (!user_mode(regs)) {
  514. void show_stack(struct task_struct *tsk, unsigned long *sp);
  515. unsigned long sp = regs->regs[15] & 0xffffffff;
  516. struct task_struct *tsk = get_current();
  517. tsk->thread.kregs = regs;
  518. show_stack(tsk, (unsigned long *)sp);
  519. }
  520. }
  521. struct task_struct * alloc_task_struct(void)
  522. {
  523. /* Get task descriptor pages */
  524. return (struct task_struct *)
  525. __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE));
  526. }
  527. void free_task_struct(struct task_struct *p)
  528. {
  529. free_pages((unsigned long) p, get_order(THREAD_SIZE));
  530. }
  531. /*
  532. * Create a kernel thread
  533. */
  534. /*
  535. * This is the mechanism for creating a new kernel thread.
  536. *
  537. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  538. * who haven't done an "execve()") should use this: it will work within
  539. * a system call from a "real" process, but the process memory space will
  540. * not be free'd until both the parent and the child have exited.
  541. */
  542. int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  543. {
  544. /* A bit less processor dependent than older sh ... */
  545. unsigned int reply;
  546. static __inline__ _syscall2(int,clone,unsigned long,flags,unsigned long,newsp)
  547. static __inline__ _syscall1(int,exit,int,ret)
  548. reply = clone(flags | CLONE_VM, 0);
  549. if (!reply) {
  550. /* Child */
  551. reply = exit(fn(arg));
  552. }
  553. return reply;
  554. }
  555. /*
  556. * Free current thread data structures etc..
  557. */
  558. void exit_thread(void)
  559. {
  560. /* See arch/sparc/kernel/process.c for the precedent for doing this -- RPC.
  561. The SH-5 FPU save/restore approach relies on last_task_used_math
  562. pointing to a live task_struct. When another task tries to use the
  563. FPU for the 1st time, the FPUDIS trap handling (see
  564. arch/sh64/kernel/fpu.c) will save the existing FPU state to the
  565. FP regs field within last_task_used_math before re-loading the new
  566. task's FPU state (or initialising it if the FPU has been used
  567. before). So if last_task_used_math is stale, and its page has already been
  568. re-allocated for another use, the consequences are rather grim. Unless we
  569. null it here, there is no other path through which it would get safely
  570. nulled. */
  571. #ifdef CONFIG_SH_FPU
  572. if (last_task_used_math == current) {
  573. last_task_used_math = NULL;
  574. }
  575. #endif
  576. }
  577. void flush_thread(void)
  578. {
  579. /* Called by fs/exec.c (flush_old_exec) to remove traces of a
  580. * previously running executable. */
  581. #ifdef CONFIG_SH_FPU
  582. if (last_task_used_math == current) {
  583. last_task_used_math = NULL;
  584. }
  585. /* Force FPU state to be reinitialised after exec */
  586. clear_used_math();
  587. #endif
  588. /* if we are a kernel thread, about to change to user thread,
  589. * update kreg
  590. */
  591. if(current->thread.kregs==&fake_swapper_regs) {
  592. current->thread.kregs =
  593. ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
  594. current->thread.uregs = current->thread.kregs;
  595. }
  596. }
  597. void release_thread(struct task_struct *dead_task)
  598. {
  599. /* do nothing */
  600. }
  601. /* Fill in the fpu structure for a core dump.. */
  602. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  603. {
  604. #ifdef CONFIG_SH_FPU
  605. int fpvalid;
  606. struct task_struct *tsk = current;
  607. fpvalid = !!tsk_used_math(tsk);
  608. if (fpvalid) {
  609. if (current == last_task_used_math) {
  610. grab_fpu();
  611. fpsave(&tsk->thread.fpu.hard);
  612. release_fpu();
  613. last_task_used_math = 0;
  614. regs->sr |= SR_FD;
  615. }
  616. memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));
  617. }
  618. return fpvalid;
  619. #else
  620. return 0; /* Task didn't use the fpu at all. */
  621. #endif
  622. }
  623. asmlinkage void ret_from_fork(void);
  624. int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
  625. unsigned long unused,
  626. struct task_struct *p, struct pt_regs *regs)
  627. {
  628. struct pt_regs *childregs;
  629. unsigned long long se; /* Sign extension */
  630. #ifdef CONFIG_SH_FPU
  631. if(last_task_used_math == current) {
  632. grab_fpu();
  633. fpsave(&current->thread.fpu.hard);
  634. release_fpu();
  635. last_task_used_math = NULL;
  636. regs->sr |= SR_FD;
  637. }
  638. #endif
  639. /* Copy from sh version */
  640. childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
  641. *childregs = *regs;
  642. if (user_mode(regs)) {
  643. childregs->regs[15] = usp;
  644. p->thread.uregs = childregs;
  645. } else {
  646. childregs->regs[15] = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  647. }
  648. childregs->regs[9] = 0; /* Set return value for child */
  649. childregs->sr |= SR_FD; /* Invalidate FPU flag */
  650. p->thread.sp = (unsigned long) childregs;
  651. p->thread.pc = (unsigned long) ret_from_fork;
  652. /*
  653. * Sign extend the edited stack.
  654. * Note that thread.pc and thread.pc will stay
  655. * 32-bit wide and context switch must take care
  656. * of NEFF sign extension.
  657. */
  658. se = childregs->regs[15];
  659. se = (se & NEFF_SIGN) ? (se | NEFF_MASK) : se;
  660. childregs->regs[15] = se;
  661. return 0;
  662. }
  663. asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
  664. unsigned long r4, unsigned long r5,
  665. unsigned long r6, unsigned long r7,
  666. struct pt_regs *pregs)
  667. {
  668. return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  669. }
  670. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  671. unsigned long r4, unsigned long r5,
  672. unsigned long r6, unsigned long r7,
  673. struct pt_regs *pregs)
  674. {
  675. if (!newsp)
  676. newsp = pregs->regs[15];
  677. return do_fork(clone_flags, newsp, pregs, 0, 0, 0);
  678. }
  679. /*
  680. * This is trivial, and on the face of it looks like it
  681. * could equally well be done in user mode.
  682. *
  683. * Not so, for quite unobvious reasons - register pressure.
  684. * In user mode vfork() cannot have a stack frame, and if
  685. * done by calling the "clone()" system call directly, you
  686. * do not have enough call-clobbered registers to hold all
  687. * the information you need.
  688. */
  689. asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,
  690. unsigned long r4, unsigned long r5,
  691. unsigned long r6, unsigned long r7,
  692. struct pt_regs *pregs)
  693. {
  694. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  695. }
  696. /*
  697. * sys_execve() executes a new program.
  698. */
  699. asmlinkage int sys_execve(char *ufilename, char **uargv,
  700. char **uenvp, unsigned long r5,
  701. unsigned long r6, unsigned long r7,
  702. struct pt_regs *pregs)
  703. {
  704. int error;
  705. char *filename;
  706. lock_kernel();
  707. filename = getname((char __user *)ufilename);
  708. error = PTR_ERR(filename);
  709. if (IS_ERR(filename))
  710. goto out;
  711. error = do_execve(filename,
  712. (char __user * __user *)uargv,
  713. (char __user * __user *)uenvp,
  714. pregs);
  715. if (error == 0) {
  716. task_lock(current);
  717. current->ptrace &= ~PT_DTRACE;
  718. task_unlock(current);
  719. }
  720. putname(filename);
  721. out:
  722. unlock_kernel();
  723. return error;
  724. }
  725. /*
  726. * These bracket the sleeping functions..
  727. */
  728. extern void interruptible_sleep_on(wait_queue_head_t *q);
  729. #define mid_sched ((unsigned long) interruptible_sleep_on)
  730. static int in_sh64_switch_to(unsigned long pc)
  731. {
  732. extern char __sh64_switch_to_end;
  733. /* For a sleeping task, the PC is somewhere in the middle of the function,
  734. so we don't have to worry about masking the LSB off */
  735. return (pc >= (unsigned long) sh64_switch_to) &&
  736. (pc < (unsigned long) &__sh64_switch_to_end);
  737. }
  738. unsigned long get_wchan(struct task_struct *p)
  739. {
  740. unsigned long schedule_fp;
  741. unsigned long sh64_switch_to_fp;
  742. unsigned long schedule_caller_pc;
  743. unsigned long pc;
  744. if (!p || p == current || p->state == TASK_RUNNING)
  745. return 0;
  746. /*
  747. * The same comment as on the Alpha applies here, too ...
  748. */
  749. pc = thread_saved_pc(p);
  750. #ifdef CONFIG_FRAME_POINTER
  751. if (in_sh64_switch_to(pc)) {
  752. sh64_switch_to_fp = (long) p->thread.sp;
  753. /* r14 is saved at offset 4 in the sh64_switch_to frame */
  754. schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
  755. /* and the caller of 'schedule' is (currently!) saved at offset 24
  756. in the frame of schedule (from disasm) */
  757. schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
  758. return schedule_caller_pc;
  759. }
  760. #endif
  761. return pc;
  762. }
  763. /* Provide a /proc/asids file that lists out the
  764. ASIDs currently associated with the processes. (If the DM.PC register is
  765. examined through the debug link, this shows ASID + PC. To make use of this,
  766. the PID->ASID relationship needs to be known. This is primarily for
  767. debugging.)
  768. */
  769. #if defined(CONFIG_SH64_PROC_ASIDS)
  770. #include <linux/init.h>
  771. #include <linux/proc_fs.h>
  772. static int
  773. asids_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
  774. {
  775. int len=0;
  776. struct task_struct *p;
  777. read_lock(&tasklist_lock);
  778. for_each_process(p) {
  779. int pid = p->pid;
  780. struct mm_struct *mm;
  781. if (!pid) continue;
  782. mm = p->mm;
  783. if (mm) {
  784. unsigned long asid, context;
  785. context = mm->context;
  786. asid = (context & 0xff);
  787. len += sprintf(buf+len, "%5d : %02lx\n", pid, asid);
  788. } else {
  789. len += sprintf(buf+len, "%5d : (none)\n", pid);
  790. }
  791. }
  792. read_unlock(&tasklist_lock);
  793. *eof = 1;
  794. return len;
  795. }
  796. static int __init register_proc_asids(void)
  797. {
  798. create_proc_read_entry("asids", 0, NULL, asids_proc_info, NULL);
  799. return 0;
  800. }
  801. __initcall(register_proc_asids);
  802. #endif