14 #include <linux/errno.h>
15 #include <linux/export.h>
16 #include <linux/sched.h>
17 #include <linux/kernel.h>
21 #include <linux/stddef.h>
22 #include <linux/ptrace.h>
23 #include <linux/slab.h>
30 #include <linux/perf_event.h>
31 #include <linux/elfcore.h>
35 #include <asm/uaccess.h>
37 #include <asm/pgalloc.h>
38 #include <asm/pgtable.h>
39 #include <asm/processor.h>
45 #include <asm/mmu_context.h>
46 #include <asm/unistd.h>
47 #include <asm/hypervisor.h>
48 #include <asm/syscalls.h>
49 #include <asm/irq_regs.h>
55 static void sparc64_yield(
int cpu)
62 clear_thread_flag(TIF_POLLING_NRFLAG);
70 "rdpr %%pstate, %0\n\t"
72 "wrpr %0, %%g0, %%pstate"
81 "rdpr %%pstate, %0\n\t"
83 "wrpr %0, %%g0, %%pstate"
88 set_thread_flag(TIF_POLLING_NRFLAG);
96 set_thread_flag(TIF_POLLING_NRFLAG);
99 tick_nohz_idle_enter();
106 tick_nohz_idle_exit();
108 #ifdef CONFIG_HOTPLUG_CPU
125 __asm__ __volatile__ (
"flushw");
126 rw = compat_ptr((
unsigned)regs->
u_regs[14]);
135 printk(
"l0: %08x l1: %08x l2: %08x l3: %08x "
136 "l4: %08x l5: %08x l6: %08x l7: %08x\n",
137 r_w.locals[0], r_w.locals[1], r_w.locals[2], r_w.locals[3],
138 r_w.locals[4], r_w.locals[5], r_w.locals[6], r_w.locals[7]);
139 printk(
"i0: %08x i1: %08x i2: %08x i3: %08x "
140 "i4: %08x i5: %08x i6: %08x i7: %08x\n",
141 r_w.ins[0], r_w.ins[1], r_w.ins[2], r_w.ins[3],
142 r_w.ins[4], r_w.ins[5], r_w.ins[6], r_w.ins[7]);
145 #define show_regwindow32(regs) do { } while (0)
148 static void show_regwindow(
struct pt_regs *regs)
150 struct reg_window __user *
rw;
151 struct reg_window *rwk;
152 struct reg_window r_w;
155 if ((regs->tstate &
TSTATE_PRIV) || !(test_thread_flag(TIF_32BIT))) {
156 __asm__ __volatile__ (
"flushw");
157 rw = (
struct reg_window __user *)
159 rwk = (
struct reg_window *)
175 printk(
"l0: %016lx l1: %016lx l2: %016lx l3: %016lx\n",
176 rwk->locals[0], rwk->locals[1], rwk->locals[2], rwk->locals[3]);
177 printk(
"l4: %016lx l5: %016lx l6: %016lx l7: %016lx\n",
178 rwk->locals[4], rwk->locals[5], rwk->locals[6], rwk->locals[7]);
179 printk(
"i0: %016lx i1: %016lx i2: %016lx i3: %016lx\n",
180 rwk->ins[0], rwk->ins[1], rwk->ins[2], rwk->ins[3]);
181 printk(
"i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
182 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
184 printk(
"I7: <%pS>\n", (
void *) rwk->ins[7]);
189 printk(
"TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
191 printk(
"TPC: <%pS>\n", (
void *) regs->tpc);
192 printk(
"g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
195 printk(
"g4: %016lx g5: %016lx g6: %016lx g7: %016lx\n",
198 printk(
"o0: %016lx o1: %016lx o2: %016lx o3: %016lx\n",
201 printk(
"o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
205 show_regwindow(regs);
215 struct global_reg_snapshot *
rp;
221 rp->tstate = regs->tstate;
223 rp->tnpc = regs->tnpc;
227 struct reg_window *
rw;
229 rw = (
struct reg_window *)
231 if (kstack_valid(tp, (
unsigned long) rw)) {
233 rw = (
struct reg_window *)
235 if (kstack_valid(tp, (
unsigned long)
rw))
236 rp->rpc = rw->ins[7];
250 static void __global_reg_poll(
struct global_reg_snapshot *
gp)
254 while (!gp->thread && ++limit < 100) {
276 __global_reg_self(tp, regs, this_cpu);
283 __global_reg_poll(gp);
286 printk(
"%c CPU[%3d]: TSTATE[%016lx] TPC[%016lx] TNPC[%016lx] TASK[%s:%d]\n",
287 (cpu == this_cpu ?
'*' :
' '), cpu,
288 gp->tstate, gp->tpc, gp->tnpc,
289 ((tp && tp->
task) ? tp->
task->comm :
"NULL"),
290 ((tp && tp->
task) ? tp->
task->pid : -1));
293 printk(
" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
299 printk(
" TPC[%lx] O7[%lx] I7[%lx] RPC[%lx]\n",
300 gp->tpc, gp->o7, gp->i7, gp->rpc);
306 spin_unlock_irqrestore(&global_cpu_snapshot_lock, flags);
309 #ifdef CONFIG_MAGIC_SYSRQ
311 static void sysrq_handle_globreg(
int key)
317 .
handler = sysrq_handle_globreg,
318 .help_msg =
"global-regs(Y)",
319 .action_msg =
"Show Global CPU Regs",
322 static void __global_pmu_self(
int this_cpu)
324 struct global_pmu_snapshot *
pp;
331 sun4v_chip_type >= SUN4V_CHIP_NIAGARA4)
334 for (i = 0; i < num; i++) {
340 static void __global_pmu_poll(
struct global_pmu_snapshot *pp)
344 while (!pp->pcr[0] && ++limit < 100) {
350 static void pmu_snapshot_all_cpus(
void)
361 __global_pmu_self(this_cpu);
368 __global_pmu_poll(pp);
370 printk(
"%c CPU[%3d]: PCR[%08lx:%08lx:%08lx:%08lx] PIC[%08lx:%08lx:%08lx:%08lx]\n",
371 (cpu == this_cpu ?
'*' :
' '), cpu,
372 pp->pcr[0], pp->pcr[1], pp->pcr[2], pp->pcr[3],
373 pp->pic[0], pp->pic[1], pp->pic[2], pp->pic[3]);
378 spin_unlock_irqrestore(&global_cpu_snapshot_lock, flags);
381 static void sysrq_handle_globpmu(
int key)
383 pmu_snapshot_all_cpus();
387 .
handler = sysrq_handle_globpmu,
388 .help_msg =
"global-pmu(X)",
389 .action_msg =
"Show Global PMU Regs",
392 static int __init sparc_sysrq_init(
void)
408 unsigned long ret = 0xdeadbeef
UL;
413 if (((
unsigned long)sp & (
sizeof(
long) - 1)) == 0
UL &&
417 if (((
unsigned long)fp & (
sizeof(
long) - 1)) == 0
UL)
430 if (t->utraps[0] < 2)
444 tsb_context_switch(mm);
446 set_thread_wsaved(0);
453 static unsigned long clone_stackframe(
unsigned long csp,
unsigned long psp)
455 bool stack_64bit = test_thread_64bit_stack(psp);
456 unsigned long fp, distance, rval;
461 __get_user(fp, &(((
struct reg_window __user *)psp)->
ins[6]));
463 if (test_thread_flag(TIF_32BIT))
475 rval = (csp - distance);
476 if (
copy_in_user((
void __user *) rval, (
void __user *) psp, distance))
478 else if (!stack_64bit) {
484 &(((
struct reg_window __user *)rval)->
ins[6])))
494 static inline void shift_window_buffer(
int first_win,
int last_win,
499 for (i = first_win; i < last_win; i++) {
500 t->rwbuf_stkptrs[
i] = t->rwbuf_stkptrs[i+1];
501 memcpy(&t->reg_window[i], &t->reg_window[i+1],
502 sizeof(
struct reg_window));
512 if ((window = get_thread_wsaved()) != 0) {
515 struct reg_window *rwin = &t->reg_window[
window];
516 int winsize =
sizeof(
struct reg_window);
519 sp = t->rwbuf_stkptrs[
window];
521 if (test_thread_64bit_stack(sp))
527 shift_window_buffer(window, get_thread_wsaved() - 1, t);
528 set_thread_wsaved(get_thread_wsaved() - 1);
534 static void stack_unaligned(
unsigned long sp)
541 info.si_addr = (
void __user *) sp;
552 window = get_thread_wsaved();
554 if (
likely(window != 0)) {
557 struct reg_window *rwin = &t->reg_window[
window];
558 int winsize =
sizeof(
struct reg_window);
561 sp = t->rwbuf_stkptrs[
window];
563 if (test_thread_64bit_stack(sp))
576 set_thread_wsaved(0);
580 set_thread_wsaved(window + 1);
587 unsigned long stack_size)
589 int __user *parent_tid_ptr, *child_tid_ptr;
594 if (test_thread_flag(TIF_32BIT)) {
604 ret =
do_fork(clone_flags, stack_start,
606 parent_tid_ptr, child_tid_ptr);
630 unsigned long child_stack_sz;
631 char *child_trap_frame;
634 kernel_thread = (regs->tstate &
TSTATE_PRIV) ? 1 : 0;
642 memcpy(child_trap_frame, parent_sf, child_stack_sz);
644 t->
flags = (t->
flags & ~((0xff
UL << TI_FLAG_CWP_SHIFT) |
645 (0xffUL << TI_FLAG_CURRENT_DS_SHIFT))) |
646 (((regs->tstate + 1) &
TSTATE_CWP) << TI_FLAG_CWP_SHIFT);
649 t->kregs = (
struct pt_regs *) (child_trap_frame +
655 (child_trap_frame + (STACKFRAME_SZ +
TRACEREG_SZ));
666 if (t->
flags & _TIF_32BIT) {
667 sp &= 0x00000000ffffffff
UL;
678 t->kregs->u_regs[
UREG_FP] = csp;
714 __asm__ __volatile__(
"mov %4, %%g2\n\t"
720 "brz,a,pn %%o1, 1f\n\t"
722 "jmpl %%g2, %%o7\n\t"
723 " mov %%g3, %%o0\n\t"
731 "g1",
"g2",
"g3",
"o0",
"o1",
"memory",
"cc");
738 unsigned int pr_regs[32];
739 unsigned long pr_dregs[16];
746 unsigned int pr_q[64];
757 if (test_thread_flag(TIF_32BIT)) {
762 sizeof(
unsigned int) * 32);
765 sizeof(
unsigned int) * 32);
769 (
sizeof(
unsigned int) * 64));
780 sizeof(
unsigned int) * 32);
783 sizeof(
unsigned int) * 32);
786 sizeof(
unsigned int) * 32);
789 sizeof(
unsigned int) * 32);
818 error = PTR_ERR(filename);
819 if (IS_ERR(filename))
839 unsigned long pc,
fp, bias = 0;
841 struct reg_window *
rw;
842 unsigned long ret = 0;
845 if (!task || task ==
current ||
854 if (!kstack_valid(tp, fp))
856 rw = (
struct reg_window *) fp;
862 fp = rw->ins[6] + bias;
863 }
while (++count < 16);