/arch/ia64/kernel/process.c

https://bitbucket.org/evzijst/gittest · C · 800 lines · 562 code · 107 blank · 131 comment · 82 complexity · 023e41f44bc3ed41930cdc65b17a76d1 MD5 · raw file

  1. /*
  2. * Architecture-specific setup.
  3. *
  4. * Copyright (C) 1998-2003 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. */
  7. #define __KERNEL_SYSCALLS__ /* see <asm/unistd.h> */
  8. #include <linux/config.h>
  9. #include <linux/cpu.h>
  10. #include <linux/pm.h>
  11. #include <linux/elf.h>
  12. #include <linux/errno.h>
  13. #include <linux/kallsyms.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/module.h>
  17. #include <linux/notifier.h>
  18. #include <linux/personality.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include <linux/smp_lock.h>
  22. #include <linux/stddef.h>
  23. #include <linux/thread_info.h>
  24. #include <linux/unistd.h>
  25. #include <linux/efi.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/delay.h>
  28. #include <asm/cpu.h>
  29. #include <asm/delay.h>
  30. #include <asm/elf.h>
  31. #include <asm/ia32.h>
  32. #include <asm/irq.h>
  33. #include <asm/pgalloc.h>
  34. #include <asm/processor.h>
  35. #include <asm/sal.h>
  36. #include <asm/tlbflush.h>
  37. #include <asm/uaccess.h>
  38. #include <asm/unwind.h>
  39. #include <asm/user.h>
  40. #include "entry.h"
  41. #ifdef CONFIG_PERFMON
  42. # include <asm/perfmon.h>
  43. #endif
  44. #include "sigframe.h"
  45. void (*ia64_mark_idle)(int);
  46. static cpumask_t cpu_idle_map;
  47. unsigned long boot_option_idle_override = 0;
  48. EXPORT_SYMBOL(boot_option_idle_override);
  49. void
  50. ia64_do_show_stack (struct unw_frame_info *info, void *arg)
  51. {
  52. unsigned long ip, sp, bsp;
  53. char buf[128]; /* don't make it so big that it overflows the stack! */
  54. printk("\nCall Trace:\n");
  55. do {
  56. unw_get_ip(info, &ip);
  57. if (ip == 0)
  58. break;
  59. unw_get_sp(info, &sp);
  60. unw_get_bsp(info, &bsp);
  61. snprintf(buf, sizeof(buf),
  62. " [<%016lx>] %%s\n"
  63. " sp=%016lx bsp=%016lx\n",
  64. ip, sp, bsp);
  65. print_symbol(buf, ip);
  66. } while (unw_unwind(info) >= 0);
  67. }
  68. void
  69. show_stack (struct task_struct *task, unsigned long *sp)
  70. {
  71. if (!task)
  72. unw_init_running(ia64_do_show_stack, NULL);
  73. else {
  74. struct unw_frame_info info;
  75. unw_init_from_blocked_task(&info, task);
  76. ia64_do_show_stack(&info, NULL);
  77. }
  78. }
  79. void
  80. dump_stack (void)
  81. {
  82. show_stack(NULL, NULL);
  83. }
  84. EXPORT_SYMBOL(dump_stack);
  85. void
  86. show_regs (struct pt_regs *regs)
  87. {
  88. unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
  89. print_modules();
  90. printk("\nPid: %d, CPU %d, comm: %20s\n", current->pid, smp_processor_id(), current->comm);
  91. printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s\n",
  92. regs->cr_ipsr, regs->cr_ifs, ip, print_tainted());
  93. print_symbol("ip is at %s\n", ip);
  94. printk("unat: %016lx pfs : %016lx rsc : %016lx\n",
  95. regs->ar_unat, regs->ar_pfs, regs->ar_rsc);
  96. printk("rnat: %016lx bsps: %016lx pr : %016lx\n",
  97. regs->ar_rnat, regs->ar_bspstore, regs->pr);
  98. printk("ldrs: %016lx ccv : %016lx fpsr: %016lx\n",
  99. regs->loadrs, regs->ar_ccv, regs->ar_fpsr);
  100. printk("csd : %016lx ssd : %016lx\n", regs->ar_csd, regs->ar_ssd);
  101. printk("b0 : %016lx b6 : %016lx b7 : %016lx\n", regs->b0, regs->b6, regs->b7);
  102. printk("f6 : %05lx%016lx f7 : %05lx%016lx\n",
  103. regs->f6.u.bits[1], regs->f6.u.bits[0],
  104. regs->f7.u.bits[1], regs->f7.u.bits[0]);
  105. printk("f8 : %05lx%016lx f9 : %05lx%016lx\n",
  106. regs->f8.u.bits[1], regs->f8.u.bits[0],
  107. regs->f9.u.bits[1], regs->f9.u.bits[0]);
  108. printk("f10 : %05lx%016lx f11 : %05lx%016lx\n",
  109. regs->f10.u.bits[1], regs->f10.u.bits[0],
  110. regs->f11.u.bits[1], regs->f11.u.bits[0]);
  111. printk("r1 : %016lx r2 : %016lx r3 : %016lx\n", regs->r1, regs->r2, regs->r3);
  112. printk("r8 : %016lx r9 : %016lx r10 : %016lx\n", regs->r8, regs->r9, regs->r10);
  113. printk("r11 : %016lx r12 : %016lx r13 : %016lx\n", regs->r11, regs->r12, regs->r13);
  114. printk("r14 : %016lx r15 : %016lx r16 : %016lx\n", regs->r14, regs->r15, regs->r16);
  115. printk("r17 : %016lx r18 : %016lx r19 : %016lx\n", regs->r17, regs->r18, regs->r19);
  116. printk("r20 : %016lx r21 : %016lx r22 : %016lx\n", regs->r20, regs->r21, regs->r22);
  117. printk("r23 : %016lx r24 : %016lx r25 : %016lx\n", regs->r23, regs->r24, regs->r25);
  118. printk("r26 : %016lx r27 : %016lx r28 : %016lx\n", regs->r26, regs->r27, regs->r28);
  119. printk("r29 : %016lx r30 : %016lx r31 : %016lx\n", regs->r29, regs->r30, regs->r31);
  120. if (user_mode(regs)) {
  121. /* print the stacked registers */
  122. unsigned long val, *bsp, ndirty;
  123. int i, sof, is_nat = 0;
  124. sof = regs->cr_ifs & 0x7f; /* size of frame */
  125. ndirty = (regs->loadrs >> 19);
  126. bsp = ia64_rse_skip_regs((unsigned long *) regs->ar_bspstore, ndirty);
  127. for (i = 0; i < sof; ++i) {
  128. get_user(val, (unsigned long __user *) ia64_rse_skip_regs(bsp, i));
  129. printk("r%-3u:%c%016lx%s", 32 + i, is_nat ? '*' : ' ', val,
  130. ((i == sof - 1) || (i % 3) == 2) ? "\n" : " ");
  131. }
  132. } else
  133. show_stack(NULL, NULL);
  134. }
  135. void
  136. do_notify_resume_user (sigset_t *oldset, struct sigscratch *scr, long in_syscall)
  137. {
  138. if (fsys_mode(current, &scr->pt)) {
  139. /* defer signal-handling etc. until we return to privilege-level 0. */
  140. if (!ia64_psr(&scr->pt)->lp)
  141. ia64_psr(&scr->pt)->lp = 1;
  142. return;
  143. }
  144. #ifdef CONFIG_PERFMON
  145. if (current->thread.pfm_needs_checking)
  146. pfm_handle_work();
  147. #endif
  148. /* deal with pending signal delivery */
  149. if (test_thread_flag(TIF_SIGPENDING))
  150. ia64_do_signal(oldset, scr, in_syscall);
  151. }
  152. static int pal_halt = 1;
  153. static int __init nohalt_setup(char * str)
  154. {
  155. pal_halt = 0;
  156. return 1;
  157. }
  158. __setup("nohalt", nohalt_setup);
  159. /*
  160. * We use this if we don't have any better idle routine..
  161. */
  162. void
  163. default_idle (void)
  164. {
  165. unsigned long pmu_active = ia64_getreg(_IA64_REG_PSR) & (IA64_PSR_PP | IA64_PSR_UP);
  166. while (!need_resched())
  167. if (pal_halt && !pmu_active)
  168. safe_halt();
  169. else
  170. cpu_relax();
  171. }
  172. #ifdef CONFIG_HOTPLUG_CPU
  173. /* We don't actually take CPU down, just spin without interrupts. */
  174. static inline void play_dead(void)
  175. {
  176. extern void ia64_cpu_local_tick (void);
  177. /* Ack it */
  178. __get_cpu_var(cpu_state) = CPU_DEAD;
  179. /* We shouldn't have to disable interrupts while dead, but
  180. * some interrupts just don't seem to go away, and this makes
  181. * it "work" for testing purposes. */
  182. max_xtp();
  183. local_irq_disable();
  184. /* Death loop */
  185. while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
  186. cpu_relax();
  187. /*
  188. * Enable timer interrupts from now on
  189. * Not required if we put processor in SAL_BOOT_RENDEZ mode.
  190. */
  191. local_flush_tlb_all();
  192. cpu_set(smp_processor_id(), cpu_online_map);
  193. wmb();
  194. ia64_cpu_local_tick ();
  195. local_irq_enable();
  196. }
  197. #else
  198. static inline void play_dead(void)
  199. {
  200. BUG();
  201. }
  202. #endif /* CONFIG_HOTPLUG_CPU */
  203. void cpu_idle_wait(void)
  204. {
  205. int cpu;
  206. cpumask_t map;
  207. for_each_online_cpu(cpu)
  208. cpu_set(cpu, cpu_idle_map);
  209. wmb();
  210. do {
  211. ssleep(1);
  212. cpus_and(map, cpu_idle_map, cpu_online_map);
  213. } while (!cpus_empty(map));
  214. }
  215. EXPORT_SYMBOL_GPL(cpu_idle_wait);
  216. void __attribute__((noreturn))
  217. cpu_idle (void)
  218. {
  219. void (*mark_idle)(int) = ia64_mark_idle;
  220. int cpu = smp_processor_id();
  221. /* endless idle loop with no priority at all */
  222. while (1) {
  223. #ifdef CONFIG_SMP
  224. if (!need_resched())
  225. min_xtp();
  226. #endif
  227. while (!need_resched()) {
  228. void (*idle)(void);
  229. if (mark_idle)
  230. (*mark_idle)(1);
  231. if (cpu_isset(cpu, cpu_idle_map))
  232. cpu_clear(cpu, cpu_idle_map);
  233. rmb();
  234. idle = pm_idle;
  235. if (!idle)
  236. idle = default_idle;
  237. (*idle)();
  238. }
  239. if (mark_idle)
  240. (*mark_idle)(0);
  241. #ifdef CONFIG_SMP
  242. normal_xtp();
  243. #endif
  244. schedule();
  245. check_pgt_cache();
  246. if (cpu_is_offline(smp_processor_id()))
  247. play_dead();
  248. }
  249. }
  250. void
  251. ia64_save_extra (struct task_struct *task)
  252. {
  253. #ifdef CONFIG_PERFMON
  254. unsigned long info;
  255. #endif
  256. if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
  257. ia64_save_debug_regs(&task->thread.dbr[0]);
  258. #ifdef CONFIG_PERFMON
  259. if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
  260. pfm_save_regs(task);
  261. info = __get_cpu_var(pfm_syst_info);
  262. if (info & PFM_CPUINFO_SYST_WIDE)
  263. pfm_syst_wide_update_task(task, info, 0);
  264. #endif
  265. #ifdef CONFIG_IA32_SUPPORT
  266. if (IS_IA32_PROCESS(ia64_task_regs(task)))
  267. ia32_save_state(task);
  268. #endif
  269. }
  270. void
  271. ia64_load_extra (struct task_struct *task)
  272. {
  273. #ifdef CONFIG_PERFMON
  274. unsigned long info;
  275. #endif
  276. if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
  277. ia64_load_debug_regs(&task->thread.dbr[0]);
  278. #ifdef CONFIG_PERFMON
  279. if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
  280. pfm_load_regs(task);
  281. info = __get_cpu_var(pfm_syst_info);
  282. if (info & PFM_CPUINFO_SYST_WIDE)
  283. pfm_syst_wide_update_task(task, info, 1);
  284. #endif
  285. #ifdef CONFIG_IA32_SUPPORT
  286. if (IS_IA32_PROCESS(ia64_task_regs(task)))
  287. ia32_load_state(task);
  288. #endif
  289. }
  290. /*
  291. * Copy the state of an ia-64 thread.
  292. *
  293. * We get here through the following call chain:
  294. *
  295. * from user-level: from kernel:
  296. *
  297. * <clone syscall> <some kernel call frames>
  298. * sys_clone :
  299. * do_fork do_fork
  300. * copy_thread copy_thread
  301. *
  302. * This means that the stack layout is as follows:
  303. *
  304. * +---------------------+ (highest addr)
  305. * | struct pt_regs |
  306. * +---------------------+
  307. * | struct switch_stack |
  308. * +---------------------+
  309. * | |
  310. * | memory stack |
  311. * | | <-- sp (lowest addr)
  312. * +---------------------+
  313. *
  314. * Observe that we copy the unat values that are in pt_regs and switch_stack. Spilling an
  315. * integer to address X causes bit N in ar.unat to be set to the NaT bit of the register,
  316. * with N=(X & 0x1ff)/8. Thus, copying the unat value preserves the NaT bits ONLY if the
  317. * pt_regs structure in the parent is congruent to that of the child, modulo 512. Since
  318. * the stack is page aligned and the page size is at least 4KB, this is always the case,
  319. * so there is nothing to worry about.
  320. */
  321. int
  322. copy_thread (int nr, unsigned long clone_flags,
  323. unsigned long user_stack_base, unsigned long user_stack_size,
  324. struct task_struct *p, struct pt_regs *regs)
  325. {
  326. extern char ia64_ret_from_clone, ia32_ret_from_clone;
  327. struct switch_stack *child_stack, *stack;
  328. unsigned long rbs, child_rbs, rbs_size;
  329. struct pt_regs *child_ptregs;
  330. int retval = 0;
  331. #ifdef CONFIG_SMP
  332. /*
  333. * For SMP idle threads, fork_by_hand() calls do_fork with
  334. * NULL regs.
  335. */
  336. if (!regs)
  337. return 0;
  338. #endif
  339. stack = ((struct switch_stack *) regs) - 1;
  340. child_ptregs = (struct pt_regs *) ((unsigned long) p + IA64_STK_OFFSET) - 1;
  341. child_stack = (struct switch_stack *) child_ptregs - 1;
  342. /* copy parent's switch_stack & pt_regs to child: */
  343. memcpy(child_stack, stack, sizeof(*child_ptregs) + sizeof(*child_stack));
  344. rbs = (unsigned long) current + IA64_RBS_OFFSET;
  345. child_rbs = (unsigned long) p + IA64_RBS_OFFSET;
  346. rbs_size = stack->ar_bspstore - rbs;
  347. /* copy the parent's register backing store to the child: */
  348. memcpy((void *) child_rbs, (void *) rbs, rbs_size);
  349. if (likely(user_mode(child_ptregs))) {
  350. if ((clone_flags & CLONE_SETTLS) && !IS_IA32_PROCESS(regs))
  351. child_ptregs->r13 = regs->r16; /* see sys_clone2() in entry.S */
  352. if (user_stack_base) {
  353. child_ptregs->r12 = user_stack_base + user_stack_size - 16;
  354. child_ptregs->ar_bspstore = user_stack_base;
  355. child_ptregs->ar_rnat = 0;
  356. child_ptregs->loadrs = 0;
  357. }
  358. } else {
  359. /*
  360. * Note: we simply preserve the relative position of
  361. * the stack pointer here. There is no need to
  362. * allocate a scratch area here, since that will have
  363. * been taken care of by the caller of sys_clone()
  364. * already.
  365. */
  366. child_ptregs->r12 = (unsigned long) child_ptregs - 16; /* kernel sp */
  367. child_ptregs->r13 = (unsigned long) p; /* set `current' pointer */
  368. }
  369. child_stack->ar_bspstore = child_rbs + rbs_size;
  370. if (IS_IA32_PROCESS(regs))
  371. child_stack->b0 = (unsigned long) &ia32_ret_from_clone;
  372. else
  373. child_stack->b0 = (unsigned long) &ia64_ret_from_clone;
  374. /* copy parts of thread_struct: */
  375. p->thread.ksp = (unsigned long) child_stack - 16;
  376. /* stop some PSR bits from being inherited.
  377. * the psr.up/psr.pp bits must be cleared on fork but inherited on execve()
  378. * therefore we must specify them explicitly here and not include them in
  379. * IA64_PSR_BITS_TO_CLEAR.
  380. */
  381. child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET)
  382. & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_PP | IA64_PSR_UP));
  383. /*
  384. * NOTE: The calling convention considers all floating point
  385. * registers in the high partition (fph) to be scratch. Since
  386. * the only way to get to this point is through a system call,
  387. * we know that the values in fph are all dead. Hence, there
  388. * is no need to inherit the fph state from the parent to the
  389. * child and all we have to do is to make sure that
  390. * IA64_THREAD_FPH_VALID is cleared in the child.
  391. *
  392. * XXX We could push this optimization a bit further by
  393. * clearing IA64_THREAD_FPH_VALID on ANY system call.
  394. * However, it's not clear this is worth doing. Also, it
  395. * would be a slight deviation from the normal Linux system
  396. * call behavior where scratch registers are preserved across
  397. * system calls (unless used by the system call itself).
  398. */
  399. # define THREAD_FLAGS_TO_CLEAR (IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID \
  400. | IA64_THREAD_PM_VALID)
  401. # define THREAD_FLAGS_TO_SET 0
  402. p->thread.flags = ((current->thread.flags & ~THREAD_FLAGS_TO_CLEAR)
  403. | THREAD_FLAGS_TO_SET);
  404. ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */
  405. #ifdef CONFIG_IA32_SUPPORT
  406. /*
  407. * If we're cloning an IA32 task then save the IA32 extra
  408. * state from the current task to the new task
  409. */
  410. if (IS_IA32_PROCESS(ia64_task_regs(current))) {
  411. ia32_save_state(p);
  412. if (clone_flags & CLONE_SETTLS)
  413. retval = ia32_clone_tls(p, child_ptregs);
  414. /* Copy partially mapped page list */
  415. if (!retval)
  416. retval = ia32_copy_partial_page_list(p, clone_flags);
  417. }
  418. #endif
  419. #ifdef CONFIG_PERFMON
  420. if (current->thread.pfm_context)
  421. pfm_inherit(p, child_ptregs);
  422. #endif
  423. return retval;
  424. }
  425. static void
  426. do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg)
  427. {
  428. unsigned long mask, sp, nat_bits = 0, ip, ar_rnat, urbs_end, cfm;
  429. elf_greg_t *dst = arg;
  430. struct pt_regs *pt;
  431. char nat;
  432. int i;
  433. memset(dst, 0, sizeof(elf_gregset_t)); /* don't leak any kernel bits to user-level */
  434. if (unw_unwind_to_user(info) < 0)
  435. return;
  436. unw_get_sp(info, &sp);
  437. pt = (struct pt_regs *) (sp + 16);
  438. urbs_end = ia64_get_user_rbs_end(task, pt, &cfm);
  439. if (ia64_sync_user_rbs(task, info->sw, pt->ar_bspstore, urbs_end) < 0)
  440. return;
  441. ia64_peek(task, info->sw, urbs_end, (long) ia64_rse_rnat_addr((long *) urbs_end),
  442. &ar_rnat);
  443. /*
  444. * coredump format:
  445. * r0-r31
  446. * NaT bits (for r0-r31; bit N == 1 iff rN is a NaT)
  447. * predicate registers (p0-p63)
  448. * b0-b7
  449. * ip cfm user-mask
  450. * ar.rsc ar.bsp ar.bspstore ar.rnat
  451. * ar.ccv ar.unat ar.fpsr ar.pfs ar.lc ar.ec
  452. */
  453. /* r0 is zero */
  454. for (i = 1, mask = (1UL << i); i < 32; ++i) {
  455. unw_get_gr(info, i, &dst[i], &nat);
  456. if (nat)
  457. nat_bits |= mask;
  458. mask <<= 1;
  459. }
  460. dst[32] = nat_bits;
  461. unw_get_pr(info, &dst[33]);
  462. for (i = 0; i < 8; ++i)
  463. unw_get_br(info, i, &dst[34 + i]);
  464. unw_get_rp(info, &ip);
  465. dst[42] = ip + ia64_psr(pt)->ri;
  466. dst[43] = cfm;
  467. dst[44] = pt->cr_ipsr & IA64_PSR_UM;
  468. unw_get_ar(info, UNW_AR_RSC, &dst[45]);
  469. /*
  470. * For bsp and bspstore, unw_get_ar() would return the kernel
  471. * addresses, but we need the user-level addresses instead:
  472. */
  473. dst[46] = urbs_end; /* note: by convention PT_AR_BSP points to the end of the urbs! */
  474. dst[47] = pt->ar_bspstore;
  475. dst[48] = ar_rnat;
  476. unw_get_ar(info, UNW_AR_CCV, &dst[49]);
  477. unw_get_ar(info, UNW_AR_UNAT, &dst[50]);
  478. unw_get_ar(info, UNW_AR_FPSR, &dst[51]);
  479. dst[52] = pt->ar_pfs; /* UNW_AR_PFS is == to pt->cr_ifs for interrupt frames */
  480. unw_get_ar(info, UNW_AR_LC, &dst[53]);
  481. unw_get_ar(info, UNW_AR_EC, &dst[54]);
  482. unw_get_ar(info, UNW_AR_CSD, &dst[55]);
  483. unw_get_ar(info, UNW_AR_SSD, &dst[56]);
  484. }
  485. void
  486. do_dump_task_fpu (struct task_struct *task, struct unw_frame_info *info, void *arg)
  487. {
  488. elf_fpreg_t *dst = arg;
  489. int i;
  490. memset(dst, 0, sizeof(elf_fpregset_t)); /* don't leak any "random" bits */
  491. if (unw_unwind_to_user(info) < 0)
  492. return;
  493. /* f0 is 0.0, f1 is 1.0 */
  494. for (i = 2; i < 32; ++i)
  495. unw_get_fr(info, i, dst + i);
  496. ia64_flush_fph(task);
  497. if ((task->thread.flags & IA64_THREAD_FPH_VALID) != 0)
  498. memcpy(dst + 32, task->thread.fph, 96*16);
  499. }
  500. void
  501. do_copy_regs (struct unw_frame_info *info, void *arg)
  502. {
  503. do_copy_task_regs(current, info, arg);
  504. }
  505. void
  506. do_dump_fpu (struct unw_frame_info *info, void *arg)
  507. {
  508. do_dump_task_fpu(current, info, arg);
  509. }
  510. int
  511. dump_task_regs(struct task_struct *task, elf_gregset_t *regs)
  512. {
  513. struct unw_frame_info tcore_info;
  514. if (current == task) {
  515. unw_init_running(do_copy_regs, regs);
  516. } else {
  517. memset(&tcore_info, 0, sizeof(tcore_info));
  518. unw_init_from_blocked_task(&tcore_info, task);
  519. do_copy_task_regs(task, &tcore_info, regs);
  520. }
  521. return 1;
  522. }
  523. void
  524. ia64_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst)
  525. {
  526. unw_init_running(do_copy_regs, dst);
  527. }
  528. int
  529. dump_task_fpu (struct task_struct *task, elf_fpregset_t *dst)
  530. {
  531. struct unw_frame_info tcore_info;
  532. if (current == task) {
  533. unw_init_running(do_dump_fpu, dst);
  534. } else {
  535. memset(&tcore_info, 0, sizeof(tcore_info));
  536. unw_init_from_blocked_task(&tcore_info, task);
  537. do_dump_task_fpu(task, &tcore_info, dst);
  538. }
  539. return 1;
  540. }
  541. int
  542. dump_fpu (struct pt_regs *pt, elf_fpregset_t dst)
  543. {
  544. unw_init_running(do_dump_fpu, dst);
  545. return 1; /* f0-f31 are always valid so we always return 1 */
  546. }
  547. long
  548. sys_execve (char __user *filename, char __user * __user *argv, char __user * __user *envp,
  549. struct pt_regs *regs)
  550. {
  551. char *fname;
  552. int error;
  553. fname = getname(filename);
  554. error = PTR_ERR(fname);
  555. if (IS_ERR(fname))
  556. goto out;
  557. error = do_execve(fname, argv, envp, regs);
  558. putname(fname);
  559. out:
  560. return error;
  561. }
  562. pid_t
  563. kernel_thread (int (*fn)(void *), void *arg, unsigned long flags)
  564. {
  565. extern void start_kernel_thread (void);
  566. unsigned long *helper_fptr = (unsigned long *) &start_kernel_thread;
  567. struct {
  568. struct switch_stack sw;
  569. struct pt_regs pt;
  570. } regs;
  571. memset(&regs, 0, sizeof(regs));
  572. regs.pt.cr_iip = helper_fptr[0]; /* set entry point (IP) */
  573. regs.pt.r1 = helper_fptr[1]; /* set GP */
  574. regs.pt.r9 = (unsigned long) fn; /* 1st argument */
  575. regs.pt.r11 = (unsigned long) arg; /* 2nd argument */
  576. /* Preserve PSR bits, except for bits 32-34 and 37-45, which we can't read. */
  577. regs.pt.cr_ipsr = ia64_getreg(_IA64_REG_PSR) | IA64_PSR_BN;
  578. regs.pt.cr_ifs = 1UL << 63; /* mark as valid, empty frame */
  579. regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR);
  580. regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET;
  581. regs.sw.pr = (1 << PRED_KERNEL_STACK);
  582. return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs.pt, 0, NULL, NULL);
  583. }
  584. EXPORT_SYMBOL(kernel_thread);
  585. /* This gets called from kernel_thread() via ia64_invoke_thread_helper(). */
  586. int
  587. kernel_thread_helper (int (*fn)(void *), void *arg)
  588. {
  589. #ifdef CONFIG_IA32_SUPPORT
  590. if (IS_IA32_PROCESS(ia64_task_regs(current))) {
  591. /* A kernel thread is always a 64-bit process. */
  592. current->thread.map_base = DEFAULT_MAP_BASE;
  593. current->thread.task_size = DEFAULT_TASK_SIZE;
  594. ia64_set_kr(IA64_KR_IO_BASE, current->thread.old_iob);
  595. ia64_set_kr(IA64_KR_TSSD, current->thread.old_k1);
  596. }
  597. #endif
  598. return (*fn)(arg);
  599. }
  600. /*
  601. * Flush thread state. This is called when a thread does an execve().
  602. */
  603. void
  604. flush_thread (void)
  605. {
  606. /* drop floating-point and debug-register state if it exists: */
  607. current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID);
  608. ia64_drop_fpu(current);
  609. if (IS_IA32_PROCESS(ia64_task_regs(current)))
  610. ia32_drop_partial_page_list(current);
  611. }
  612. /*
  613. * Clean up state associated with current thread. This is called when
  614. * the thread calls exit().
  615. */
  616. void
  617. exit_thread (void)
  618. {
  619. ia64_drop_fpu(current);
  620. #ifdef CONFIG_PERFMON
  621. /* if needed, stop monitoring and flush state to perfmon context */
  622. if (current->thread.pfm_context)
  623. pfm_exit_thread(current);
  624. /* free debug register resources */
  625. if (current->thread.flags & IA64_THREAD_DBG_VALID)
  626. pfm_release_debug_registers(current);
  627. #endif
  628. if (IS_IA32_PROCESS(ia64_task_regs(current)))
  629. ia32_drop_partial_page_list(current);
  630. }
  631. unsigned long
  632. get_wchan (struct task_struct *p)
  633. {
  634. struct unw_frame_info info;
  635. unsigned long ip;
  636. int count = 0;
  637. /*
  638. * Note: p may not be a blocked task (it could be current or
  639. * another process running on some other CPU. Rather than
  640. * trying to determine if p is really blocked, we just assume
  641. * it's blocked and rely on the unwind routines to fail
  642. * gracefully if the process wasn't really blocked after all.
  643. * --davidm 99/12/15
  644. */
  645. unw_init_from_blocked_task(&info, p);
  646. do {
  647. if (unw_unwind(&info) < 0)
  648. return 0;
  649. unw_get_ip(&info, &ip);
  650. if (!in_sched_functions(ip))
  651. return ip;
  652. } while (count++ < 16);
  653. return 0;
  654. }
  655. void
  656. cpu_halt (void)
  657. {
  658. pal_power_mgmt_info_u_t power_info[8];
  659. unsigned long min_power;
  660. int i, min_power_state;
  661. if (ia64_pal_halt_info(power_info) != 0)
  662. return;
  663. min_power_state = 0;
  664. min_power = power_info[0].pal_power_mgmt_info_s.power_consumption;
  665. for (i = 1; i < 8; ++i)
  666. if (power_info[i].pal_power_mgmt_info_s.im
  667. && power_info[i].pal_power_mgmt_info_s.power_consumption < min_power) {
  668. min_power = power_info[i].pal_power_mgmt_info_s.power_consumption;
  669. min_power_state = i;
  670. }
  671. while (1)
  672. ia64_pal_halt(min_power_state);
  673. }
  674. void
  675. machine_restart (char *restart_cmd)
  676. {
  677. (*efi.reset_system)(EFI_RESET_WARM, 0, 0, NULL);
  678. }
  679. EXPORT_SYMBOL(machine_restart);
  680. void
  681. machine_halt (void)
  682. {
  683. cpu_halt();
  684. }
  685. EXPORT_SYMBOL(machine_halt);
  686. void
  687. machine_power_off (void)
  688. {
  689. if (pm_power_off)
  690. pm_power_off();
  691. machine_halt();
  692. }
  693. EXPORT_SYMBOL(machine_power_off);