debuggers.hg

view xen/arch/ia64/linux-xen/process-linux-xen.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
1 /*
2 * Architecture-specific setup.
3 *
4 * Copyright (C) 1998-2003 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
6 * 04/11/17 Ashok Raj <ashok.raj@intel.com> Added CPU Hotplug Support
7 */
8 #ifdef XEN
9 #include <linux/cpu.h>
10 #include <linux/notifier.h>
11 #include <xen/types.h>
12 #include <xen/lib.h>
13 #include <xen/symbols.h>
14 #include <xen/smp.h>
15 #include <xen/sched.h>
16 #include <asm/elf.h>
17 #include <asm/uaccess.h>
18 #include <asm/processor.h>
19 #include <asm/ptrace.h>
20 #include <asm/unwind.h>
21 #include <asm/sal.h>
22 #else
23 #define __KERNEL_SYSCALLS__ /* see <asm/unistd.h> */
24 #include <linux/config.h>
26 #include <linux/cpu.h>
27 #include <linux/pm.h>
28 #include <linux/elf.h>
29 #include <linux/errno.h>
30 #include <linux/kallsyms.h>
31 #include <linux/kernel.h>
32 #include <linux/mm.h>
33 #include <linux/module.h>
34 #include <linux/notifier.h>
35 #include <linux/personality.h>
36 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <linux/smp_lock.h>
39 #include <linux/stddef.h>
40 #include <linux/thread_info.h>
41 #include <linux/unistd.h>
42 #include <linux/efi.h>
43 #include <linux/interrupt.h>
44 #include <linux/delay.h>
45 #include <linux/kprobes.h>
47 #include <asm/cpu.h>
48 #include <asm/delay.h>
49 #include <asm/elf.h>
50 #include <asm/ia32.h>
51 #include <asm/irq.h>
52 #include <asm/pgalloc.h>
53 #include <asm/processor.h>
54 #include <asm/sal.h>
55 #include <asm/tlbflush.h>
56 #include <asm/uaccess.h>
57 #include <asm/unwind.h>
58 #include <asm/user.h>
60 #include "entry.h"
62 #ifdef CONFIG_PERFMON
63 # include <asm/perfmon.h>
64 #endif
66 #include "sigframe.h"
68 void (*ia64_mark_idle)(int);
69 static DEFINE_PER_CPU(unsigned int, cpu_idle_state);
71 unsigned long boot_option_idle_override = 0;
72 EXPORT_SYMBOL(boot_option_idle_override);
73 #endif
75 void
76 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
77 {
78 unsigned long ip, sp, bsp;
79 char buf[128]; /* don't make it so big that it overflows the stack! */
81 printk("\nCall Trace:\n");
82 do {
83 unw_get_ip(info, &ip);
84 if (ip == 0)
85 break;
87 unw_get_sp(info, &sp);
88 unw_get_bsp(info, &bsp);
89 snprintf(buf, sizeof(buf),
90 " [<%016lx>] %%s\n"
91 " sp=%016lx bsp=%016lx\n",
92 ip, sp, bsp);
93 print_symbol(buf, ip);
94 } while (unw_unwind(info) >= 0);
95 }
97 void
98 show_stack (struct task_struct *task, unsigned long *sp)
99 {
100 if (!task)
101 unw_init_running(ia64_do_show_stack, NULL);
102 else {
103 struct unw_frame_info info;
105 unw_init_from_blocked_task(&info, task);
106 ia64_do_show_stack(&info, NULL);
107 }
108 }
110 void
111 dump_stack (void)
112 {
113 show_stack(NULL, NULL);
114 }
116 EXPORT_SYMBOL(dump_stack);
118 #ifdef XEN
119 void
120 show_registers(struct pt_regs *regs)
121 #else
122 void
123 show_regs (struct pt_regs *regs)
124 #endif
125 {
126 unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
128 #ifndef XEN
129 print_modules();
130 printk("\nPid: %d, CPU %d, comm: %20s\n", current->pid, smp_processor_id(), current->comm);
131 printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s\n",
132 regs->cr_ipsr, regs->cr_ifs, ip, print_tainted());
133 #else
134 struct vcpu* vcpu = current;
135 if (vcpu != NULL) {
136 struct domain* d = vcpu->domain;
137 printk("d 0x%p domid %d\n", d, d->domain_id);
138 printk("vcpu 0x%p vcpu %d\n",
139 vcpu, vcpu->vcpu_id);
140 }
141 printk("\nCPU %d\n", smp_processor_id());
142 printk("psr : %016lx ifs : %016lx ip : [<%016lx>]\n",
143 regs->cr_ipsr, regs->cr_ifs, ip);
144 #endif
145 print_symbol("ip is at %s\n", ip);
146 printk("unat: %016lx pfs : %016lx rsc : %016lx\n",
147 regs->ar_unat, regs->ar_pfs, regs->ar_rsc);
148 printk("rnat: %016lx bsps: %016lx pr : %016lx\n",
149 regs->ar_rnat, regs->ar_bspstore, regs->pr);
150 printk("ldrs: %016lx ccv : %016lx fpsr: %016lx\n",
151 regs->loadrs, regs->ar_ccv, regs->ar_fpsr);
152 printk("csd : %016lx ssd : %016lx\n", regs->ar_csd, regs->ar_ssd);
153 printk("b0 : %016lx b6 : %016lx b7 : %016lx\n", regs->b0, regs->b6, regs->b7);
154 printk("f6 : %05lx%016lx f7 : %05lx%016lx\n",
155 regs->f6.u.bits[1], regs->f6.u.bits[0],
156 regs->f7.u.bits[1], regs->f7.u.bits[0]);
157 printk("f8 : %05lx%016lx f9 : %05lx%016lx\n",
158 regs->f8.u.bits[1], regs->f8.u.bits[0],
159 regs->f9.u.bits[1], regs->f9.u.bits[0]);
160 printk("f10 : %05lx%016lx f11 : %05lx%016lx\n",
161 regs->f10.u.bits[1], regs->f10.u.bits[0],
162 regs->f11.u.bits[1], regs->f11.u.bits[0]);
164 printk("r1 : %016lx r2 : %016lx r3 : %016lx\n", regs->r1, regs->r2, regs->r3);
165 printk("r8 : %016lx r9 : %016lx r10 : %016lx\n", regs->r8, regs->r9, regs->r10);
166 printk("r11 : %016lx r12 : %016lx r13 : %016lx\n", regs->r11, regs->r12, regs->r13);
167 printk("r14 : %016lx r15 : %016lx r16 : %016lx\n", regs->r14, regs->r15, regs->r16);
168 printk("r17 : %016lx r18 : %016lx r19 : %016lx\n", regs->r17, regs->r18, regs->r19);
169 printk("r20 : %016lx r21 : %016lx r22 : %016lx\n", regs->r20, regs->r21, regs->r22);
170 printk("r23 : %016lx r24 : %016lx r25 : %016lx\n", regs->r23, regs->r24, regs->r25);
171 printk("r26 : %016lx r27 : %016lx r28 : %016lx\n", regs->r26, regs->r27, regs->r28);
172 printk("r29 : %016lx r30 : %016lx r31 : %016lx\n", regs->r29, regs->r30, regs->r31);
174 #ifndef XEN
175 if (user_mode(regs)) {
176 /* print the stacked registers */
177 unsigned long val, *bsp, ndirty;
178 int i, sof, is_nat = 0;
180 sof = regs->cr_ifs & 0x7f; /* size of frame */
181 ndirty = (regs->loadrs >> 19);
182 bsp = ia64_rse_skip_regs((unsigned long *) regs->ar_bspstore, ndirty);
183 for (i = 0; i < sof; ++i) {
184 get_user(val, (unsigned long __user *) ia64_rse_skip_regs(bsp, i));
185 printk("r%-3u:%c%016lx%s", 32 + i, is_nat ? '*' : ' ', val,
186 ((i == sof - 1) || (i % 3) == 2) ? "\n" : " ");
187 }
188 } else
189 #endif
190 show_stack(NULL, NULL);
191 }
193 #ifndef XEN
194 void
195 do_notify_resume_user (sigset_t *oldset, struct sigscratch *scr, long in_syscall)
196 {
197 if (fsys_mode(current, &scr->pt)) {
198 /* defer signal-handling etc. until we return to privilege-level 0. */
199 if (!ia64_psr(&scr->pt)->lp)
200 ia64_psr(&scr->pt)->lp = 1;
201 return;
202 }
204 #ifdef CONFIG_PERFMON
205 if (current->thread.pfm_needs_checking)
206 pfm_handle_work();
207 #endif
209 /* deal with pending signal delivery */
210 if (test_thread_flag(TIF_SIGPENDING))
211 ia64_do_signal(oldset, scr, in_syscall);
212 }
214 static int pal_halt = 1;
215 static int can_do_pal_halt = 1;
217 static int __init nohalt_setup(char * str)
218 {
219 pal_halt = can_do_pal_halt = 0;
220 return 1;
221 }
222 __setup("nohalt", nohalt_setup);
224 void
225 update_pal_halt_status(int status)
226 {
227 can_do_pal_halt = pal_halt && status;
228 }
230 /*
231 * We use this if we don't have any better idle routine..
232 */
233 void
234 default_idle (void)
235 {
236 local_irq_enable();
237 while (!need_resched())
238 if (can_do_pal_halt)
239 safe_halt();
240 else
241 cpu_relax();
242 }
243 #endif
245 #ifdef CONFIG_HOTPLUG_CPU
246 /* We don't actually take CPU down, just spin without interrupts. */
247 #ifndef XEN
248 static inline void play_dead(void)
249 #else
250 void play_dead(void)
251 #endif
252 {
253 extern void ia64_cpu_local_tick (void);
254 unsigned int this_cpu = smp_processor_id();
256 /* Ack it */
257 __get_cpu_var(cpu_state) = CPU_DEAD;
259 max_xtp();
260 local_irq_disable();
261 ia64_jump_to_sal(&sal_boot_rendez_state[this_cpu]);
262 /*
263 * The above is a point of no-return, the processor is
264 * expected to be in SAL loop now.
265 */
266 BUG();
267 }
268 #else
269 #ifndef XEN
270 static inline void play_dead(void)
271 #else
272 void play_dead(void)
273 #endif
274 {
275 BUG();
276 }
277 #endif /* CONFIG_HOTPLUG_CPU */
279 #ifndef XEN
280 void cpu_idle_wait(void)
281 {
282 unsigned int cpu, this_cpu = get_cpu();
283 cpumask_t map;
285 set_cpus_allowed(current, cpumask_of_cpu(this_cpu));
286 put_cpu();
288 cpus_clear(map);
289 for_each_online_cpu(cpu) {
290 per_cpu(cpu_idle_state, cpu) = 1;
291 cpu_set(cpu, map);
292 }
294 __get_cpu_var(cpu_idle_state) = 0;
296 wmb();
297 do {
298 ssleep(1);
299 for_each_online_cpu(cpu) {
300 if (cpu_isset(cpu, map) && !per_cpu(cpu_idle_state, cpu))
301 cpu_clear(cpu, map);
302 }
303 cpus_and(map, map, cpu_online_map);
304 } while (!cpus_empty(map));
305 }
306 EXPORT_SYMBOL_GPL(cpu_idle_wait);
308 void __attribute__((noreturn))
309 cpu_idle (void)
310 {
311 void (*mark_idle)(int) = ia64_mark_idle;
313 /* endless idle loop with no priority at all */
314 while (1) {
315 #ifdef CONFIG_SMP
316 if (!need_resched())
317 min_xtp();
318 #endif
319 while (!need_resched()) {
320 void (*idle)(void);
322 if (__get_cpu_var(cpu_idle_state))
323 __get_cpu_var(cpu_idle_state) = 0;
325 rmb();
326 if (mark_idle)
327 (*mark_idle)(1);
329 idle = pm_idle;
330 if (!idle)
331 idle = default_idle;
332 (*idle)();
333 }
335 if (mark_idle)
336 (*mark_idle)(0);
338 #ifdef CONFIG_SMP
339 normal_xtp();
340 #endif
341 schedule();
342 check_pgt_cache();
343 if (cpu_is_offline(smp_processor_id()))
344 play_dead();
345 }
346 }
348 void
349 ia64_save_extra (struct task_struct *task)
350 {
351 #ifdef CONFIG_PERFMON
352 unsigned long info;
353 #endif
355 if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
356 ia64_save_debug_regs(&task->thread.dbr[0]);
358 #ifdef CONFIG_PERFMON
359 if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
360 pfm_save_regs(task);
362 info = __get_cpu_var(pfm_syst_info);
363 if (info & PFM_CPUINFO_SYST_WIDE)
364 pfm_syst_wide_update_task(task, info, 0);
365 #endif
367 #ifdef CONFIG_IA32_SUPPORT
368 if (IS_IA32_PROCESS(ia64_task_regs(task)))
369 ia32_save_state(task);
370 #endif
371 }
373 void
374 ia64_load_extra (struct task_struct *task)
375 {
376 #ifdef CONFIG_PERFMON
377 unsigned long info;
378 #endif
380 if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
381 ia64_load_debug_regs(&task->thread.dbr[0]);
383 #ifdef CONFIG_PERFMON
384 if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
385 pfm_load_regs(task);
387 info = __get_cpu_var(pfm_syst_info);
388 if (info & PFM_CPUINFO_SYST_WIDE)
389 pfm_syst_wide_update_task(task, info, 1);
390 #endif
392 #ifdef CONFIG_IA32_SUPPORT
393 if (IS_IA32_PROCESS(ia64_task_regs(task)))
394 ia32_load_state(task);
395 #endif
396 }
398 /*
399 * Copy the state of an ia-64 thread.
400 *
401 * We get here through the following call chain:
402 *
403 * from user-level: from kernel:
404 *
405 * <clone syscall> <some kernel call frames>
406 * sys_clone :
407 * do_fork do_fork
408 * copy_thread copy_thread
409 *
410 * This means that the stack layout is as follows:
411 *
412 * +---------------------+ (highest addr)
413 * | struct pt_regs |
414 * +---------------------+
415 * | struct switch_stack |
416 * +---------------------+
417 * | |
418 * | memory stack |
419 * | | <-- sp (lowest addr)
420 * +---------------------+
421 *
422 * Observe that we copy the unat values that are in pt_regs and switch_stack. Spilling an
423 * integer to address X causes bit N in ar.unat to be set to the NaT bit of the register,
424 * with N=(X & 0x1ff)/8. Thus, copying the unat value preserves the NaT bits ONLY if the
425 * pt_regs structure in the parent is congruent to that of the child, modulo 512. Since
426 * the stack is page aligned and the page size is at least 4KB, this is always the case,
427 * so there is nothing to worry about.
428 */
429 int
430 copy_thread (int nr, unsigned long clone_flags,
431 unsigned long user_stack_base, unsigned long user_stack_size,
432 struct task_struct *p, struct pt_regs *regs)
433 {
434 extern char ia64_ret_from_clone, ia32_ret_from_clone;
435 struct switch_stack *child_stack, *stack;
436 unsigned long rbs, child_rbs, rbs_size;
437 struct pt_regs *child_ptregs;
438 int retval = 0;
440 #ifdef CONFIG_SMP
441 /*
442 * For SMP idle threads, fork_by_hand() calls do_fork with
443 * NULL regs.
444 */
445 if (!regs)
446 return 0;
447 #endif
449 stack = ((struct switch_stack *) regs) - 1;
451 child_ptregs = (struct pt_regs *) ((unsigned long) p + IA64_STK_OFFSET) - 1;
452 child_stack = (struct switch_stack *) child_ptregs - 1;
454 /* copy parent's switch_stack & pt_regs to child: */
455 memcpy(child_stack, stack, sizeof(*child_ptregs) + sizeof(*child_stack));
457 rbs = (unsigned long) current + IA64_RBS_OFFSET;
458 child_rbs = (unsigned long) p + IA64_RBS_OFFSET;
459 rbs_size = stack->ar_bspstore - rbs;
461 /* copy the parent's register backing store to the child: */
462 memcpy((void *) child_rbs, (void *) rbs, rbs_size);
464 if (likely(user_mode(child_ptregs))) {
465 if ((clone_flags & CLONE_SETTLS) && !IS_IA32_PROCESS(regs))
466 child_ptregs->r13 = regs->r16; /* see sys_clone2() in entry.S */
467 if (user_stack_base) {
468 child_ptregs->r12 = user_stack_base + user_stack_size - 16;
469 child_ptregs->ar_bspstore = user_stack_base;
470 child_ptregs->ar_rnat = 0;
471 child_ptregs->loadrs = 0;
472 }
473 } else {
474 /*
475 * Note: we simply preserve the relative position of
476 * the stack pointer here. There is no need to
477 * allocate a scratch area here, since that will have
478 * been taken care of by the caller of sys_clone()
479 * already.
480 */
481 child_ptregs->r12 = (unsigned long) child_ptregs - 16; /* kernel sp */
482 child_ptregs->r13 = (unsigned long) p; /* set `current' pointer */
483 }
484 child_stack->ar_bspstore = child_rbs + rbs_size;
485 if (IS_IA32_PROCESS(regs))
486 child_stack->b0 = (unsigned long) &ia32_ret_from_clone;
487 else
488 child_stack->b0 = (unsigned long) &ia64_ret_from_clone;
490 /* copy parts of thread_struct: */
491 p->thread.ksp = (unsigned long) child_stack - 16;
493 /* stop some PSR bits from being inherited.
494 * the psr.up/psr.pp bits must be cleared on fork but inherited on execve()
495 * therefore we must specify them explicitly here and not include them in
496 * IA64_PSR_BITS_TO_CLEAR.
497 */
498 child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET)
499 & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_PP | IA64_PSR_UP));
501 /*
502 * NOTE: The calling convention considers all floating point
503 * registers in the high partition (fph) to be scratch. Since
504 * the only way to get to this point is through a system call,
505 * we know that the values in fph are all dead. Hence, there
506 * is no need to inherit the fph state from the parent to the
507 * child and all we have to do is to make sure that
508 * IA64_THREAD_FPH_VALID is cleared in the child.
509 *
510 * XXX We could push this optimization a bit further by
511 * clearing IA64_THREAD_FPH_VALID on ANY system call.
512 * However, it's not clear this is worth doing. Also, it
513 * would be a slight deviation from the normal Linux system
514 * call behavior where scratch registers are preserved across
515 * system calls (unless used by the system call itself).
516 */
517 # define THREAD_FLAGS_TO_CLEAR (IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID \
518 | IA64_THREAD_PM_VALID)
519 # define THREAD_FLAGS_TO_SET 0
520 p->thread.flags = ((current->thread.flags & ~THREAD_FLAGS_TO_CLEAR)
521 | THREAD_FLAGS_TO_SET);
522 ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */
523 #ifdef CONFIG_IA32_SUPPORT
524 /*
525 * If we're cloning an IA32 task then save the IA32 extra
526 * state from the current task to the new task
527 */
528 if (IS_IA32_PROCESS(ia64_task_regs(current))) {
529 ia32_save_state(p);
530 if (clone_flags & CLONE_SETTLS)
531 retval = ia32_clone_tls(p, child_ptregs);
533 /* Copy partially mapped page list */
534 if (!retval)
535 retval = ia32_copy_partial_page_list(p, clone_flags);
536 }
537 #endif
539 #ifdef CONFIG_PERFMON
540 if (current->thread.pfm_context)
541 pfm_inherit(p, child_ptregs);
542 #endif
543 return retval;
544 }
546 #endif /* !XEN */
548 static void
549 do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg)
550 {
551 unsigned long mask, sp, nat_bits = 0, ip, ar_rnat, urbs_end, cfm;
552 elf_greg_t *dst = arg;
553 struct pt_regs *pt;
554 char nat;
555 int i;
557 memset(dst, 0, sizeof(elf_gregset_t)); /* don't leak any kernel bits to user-level */
559 if (unw_unwind_to_user(info) < 0)
560 return;
562 unw_get_sp(info, &sp);
563 pt = (struct pt_regs *) (sp + 16);
565 #ifndef XEN
566 /* FIXME: Is this needed by XEN when it makes its crash notes
567 * during kdump? */
568 urbs_end = ia64_get_user_rbs_end(task, pt, &cfm);
570 if (ia64_sync_user_rbs(task, info->sw, pt->ar_bspstore, urbs_end) < 0)
571 return;
573 ia64_peek(task, info->sw, urbs_end, (long) ia64_rse_rnat_addr((long *) urbs_end),
574 &ar_rnat);
575 #else
577 ia64_peek(task, info->sw, urbs_end, (long) ia64_rse_rnat_addr((u64 *) urbs_end),
578 (long *)&ar_rnat);
579 #endif
581 /*
582 * coredump format:
583 * r0-r31
584 * NaT bits (for r0-r31; bit N == 1 iff rN is a NaT)
585 * predicate registers (p0-p63)
586 * b0-b7
587 * ip cfm user-mask
588 * ar.rsc ar.bsp ar.bspstore ar.rnat
589 * ar.ccv ar.unat ar.fpsr ar.pfs ar.lc ar.ec
590 */
592 /* r0 is zero */
593 for (i = 1, mask = (1UL << i); i < 32; ++i) {
594 unw_get_gr(info, i, &dst[i], &nat);
595 if (nat)
596 nat_bits |= mask;
597 mask <<= 1;
598 }
599 dst[32] = nat_bits;
600 unw_get_pr(info, &dst[33]);
602 for (i = 0; i < 8; ++i)
603 unw_get_br(info, i, &dst[34 + i]);
605 unw_get_rp(info, &ip);
606 dst[42] = ip + ia64_psr(pt)->ri;
607 dst[43] = cfm;
608 dst[44] = pt->cr_ipsr & IA64_PSR_UM;
610 unw_get_ar(info, UNW_AR_RSC, &dst[45]);
611 /*
612 * For bsp and bspstore, unw_get_ar() would return the kernel
613 * addresses, but we need the user-level addresses instead:
614 */
615 dst[46] = urbs_end; /* note: by convention PT_AR_BSP points to the end of the urbs! */
616 dst[47] = pt->ar_bspstore;
617 dst[48] = ar_rnat;
618 unw_get_ar(info, UNW_AR_CCV, &dst[49]);
619 unw_get_ar(info, UNW_AR_UNAT, &dst[50]);
620 unw_get_ar(info, UNW_AR_FPSR, &dst[51]);
621 dst[52] = pt->ar_pfs; /* UNW_AR_PFS is == to pt->cr_ifs for interrupt frames */
622 unw_get_ar(info, UNW_AR_LC, &dst[53]);
623 unw_get_ar(info, UNW_AR_EC, &dst[54]);
624 unw_get_ar(info, UNW_AR_CSD, &dst[55]);
625 unw_get_ar(info, UNW_AR_SSD, &dst[56]);
626 }
628 #ifndef XEN
630 void
631 do_dump_task_fpu (struct task_struct *task, struct unw_frame_info *info, void *arg)
632 {
633 elf_fpreg_t *dst = arg;
634 int i;
636 memset(dst, 0, sizeof(elf_fpregset_t)); /* don't leak any "random" bits */
638 if (unw_unwind_to_user(info) < 0)
639 return;
641 /* f0 is 0.0, f1 is 1.0 */
643 for (i = 2; i < 32; ++i)
644 unw_get_fr(info, i, dst + i);
646 ia64_flush_fph(task);
647 if ((task->thread.flags & IA64_THREAD_FPH_VALID) != 0)
648 memcpy(dst + 32, task->thread.fph, 96*16);
649 }
651 #endif /* !XEN */
653 void
654 do_copy_regs (struct unw_frame_info *info, void *arg)
655 {
656 do_copy_task_regs(current, info, arg);
657 }
659 #ifndef XEN
661 void
662 do_dump_fpu (struct unw_frame_info *info, void *arg)
663 {
664 do_dump_task_fpu(current, info, arg);
665 }
667 int
668 dump_task_regs(struct task_struct *task, elf_gregset_t *regs)
669 {
670 struct unw_frame_info tcore_info;
672 if (current == task) {
673 unw_init_running(do_copy_regs, regs);
674 } else {
675 memset(&tcore_info, 0, sizeof(tcore_info));
676 unw_init_from_blocked_task(&tcore_info, task);
677 do_copy_task_regs(task, &tcore_info, regs);
678 }
679 return 1;
680 }
682 #endif /* !XEN */
684 void
685 ia64_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst)
686 {
687 unw_init_running(do_copy_regs, dst);
688 }
690 #ifndef XEN
692 int
693 dump_task_fpu (struct task_struct *task, elf_fpregset_t *dst)
694 {
695 struct unw_frame_info tcore_info;
697 if (current == task) {
698 unw_init_running(do_dump_fpu, dst);
699 } else {
700 memset(&tcore_info, 0, sizeof(tcore_info));
701 unw_init_from_blocked_task(&tcore_info, task);
702 do_dump_task_fpu(task, &tcore_info, dst);
703 }
704 return 1;
705 }
707 int
708 dump_fpu (struct pt_regs *pt, elf_fpregset_t dst)
709 {
710 unw_init_running(do_dump_fpu, dst);
711 return 1; /* f0-f31 are always valid so we always return 1 */
712 }
714 long
715 sys_execve (char __user *filename, char __user * __user *argv, char __user * __user *envp,
716 struct pt_regs *regs)
717 {
718 char *fname;
719 int error;
721 fname = getname(filename);
722 error = PTR_ERR(fname);
723 if (IS_ERR(fname))
724 goto out;
725 error = do_execve(fname, argv, envp, regs);
726 putname(fname);
727 out:
728 return error;
729 }
731 pid_t
732 kernel_thread (int (*fn)(void *), void *arg, unsigned long flags)
733 {
734 extern void start_kernel_thread (void);
735 unsigned long *helper_fptr = (unsigned long *) &start_kernel_thread;
736 struct {
737 struct switch_stack sw;
738 struct pt_regs pt;
739 } regs;
741 memset(&regs, 0, sizeof(regs));
742 regs.pt.cr_iip = helper_fptr[0]; /* set entry point (IP) */
743 regs.pt.r1 = helper_fptr[1]; /* set GP */
744 regs.pt.r9 = (unsigned long) fn; /* 1st argument */
745 regs.pt.r11 = (unsigned long) arg; /* 2nd argument */
746 /* Preserve PSR bits, except for bits 32-34 and 37-45, which we can't read. */
747 regs.pt.cr_ipsr = ia64_getreg(_IA64_REG_PSR) | IA64_PSR_BN;
748 regs.pt.cr_ifs = 1UL << 63; /* mark as valid, empty frame */
749 regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR);
750 regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET;
751 regs.sw.pr = (1 << PRED_KERNEL_STACK);
752 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs.pt, 0, NULL, NULL);
753 }
754 EXPORT_SYMBOL(kernel_thread);
756 /* This gets called from kernel_thread() via ia64_invoke_thread_helper(). */
757 int
758 kernel_thread_helper (int (*fn)(void *), void *arg)
759 {
760 #ifdef CONFIG_IA32_SUPPORT
761 if (IS_IA32_PROCESS(ia64_task_regs(current))) {
762 /* A kernel thread is always a 64-bit process. */
763 current->thread.map_base = DEFAULT_MAP_BASE;
764 current->thread.task_size = DEFAULT_TASK_SIZE;
765 ia64_set_kr(IA64_KR_IO_BASE, current->thread.old_iob);
766 ia64_set_kr(IA64_KR_TSSD, current->thread.old_k1);
767 }
768 #endif
769 return (*fn)(arg);
770 }
772 /*
773 * Flush thread state. This is called when a thread does an execve().
774 */
775 void
776 flush_thread (void)
777 {
778 /*
779 * Remove function-return probe instances associated with this task
780 * and put them back on the free list. Do not insert an exit probe for
781 * this function, it will be disabled by kprobe_flush_task if you do.
782 */
783 kprobe_flush_task(current);
785 /* drop floating-point and debug-register state if it exists: */
786 current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID);
787 ia64_drop_fpu(current);
788 if (IS_IA32_PROCESS(ia64_task_regs(current)))
789 ia32_drop_partial_page_list(current);
790 }
792 /*
793 * Clean up state associated with current thread. This is called when
794 * the thread calls exit().
795 */
796 void
797 exit_thread (void)
798 {
800 /*
801 * Remove function-return probe instances associated with this task
802 * and put them back on the free list. Do not insert an exit probe for
803 * this function, it will be disabled by kprobe_flush_task if you do.
804 */
805 kprobe_flush_task(current);
807 ia64_drop_fpu(current);
808 #ifdef CONFIG_PERFMON
809 /* if needed, stop monitoring and flush state to perfmon context */
810 if (current->thread.pfm_context)
811 pfm_exit_thread(current);
813 /* free debug register resources */
814 if (current->thread.flags & IA64_THREAD_DBG_VALID)
815 pfm_release_debug_registers(current);
816 #endif
817 if (IS_IA32_PROCESS(ia64_task_regs(current)))
818 ia32_drop_partial_page_list(current);
819 }
821 unsigned long
822 get_wchan (struct task_struct *p)
823 {
824 struct unw_frame_info info;
825 unsigned long ip;
826 int count = 0;
828 /*
829 * Note: p may not be a blocked task (it could be current or
830 * another process running on some other CPU. Rather than
831 * trying to determine if p is really blocked, we just assume
832 * it's blocked and rely on the unwind routines to fail
833 * gracefully if the process wasn't really blocked after all.
834 * --davidm 99/12/15
835 */
836 unw_init_from_blocked_task(&info, p);
837 do {
838 if (unw_unwind(&info) < 0)
839 return 0;
840 unw_get_ip(&info, &ip);
841 if (!in_sched_functions(ip))
842 return ip;
843 } while (count++ < 16);
844 return 0;
845 }
846 #endif // !XEN
848 void
849 cpu_halt (void)
850 {
851 pal_power_mgmt_info_u_t power_info[8];
852 unsigned long min_power;
853 int i, min_power_state;
855 if (ia64_pal_halt_info(power_info) != 0)
856 return;
858 min_power_state = 0;
859 min_power = power_info[0].pal_power_mgmt_info_s.power_consumption;
860 for (i = 1; i < 8; ++i)
861 if (power_info[i].pal_power_mgmt_info_s.im
862 && power_info[i].pal_power_mgmt_info_s.power_consumption < min_power) {
863 min_power = power_info[i].pal_power_mgmt_info_s.power_consumption;
864 min_power_state = i;
865 }
867 while (1)
868 ia64_pal_halt(min_power_state);
869 }
871 #ifndef XEN
872 void
873 machine_restart (char *restart_cmd)
874 {
875 (*efi.reset_system)(EFI_RESET_WARM, 0, 0, NULL);
876 }
878 void
879 machine_halt (void)
880 {
881 cpu_halt();
882 }
884 void
885 machine_power_off (void)
886 {
887 if (pm_power_off)
888 pm_power_off();
889 machine_halt();
890 }
891 #endif // !XEN