process.c 24 KB

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