17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
22 #include <linux/stddef.h>
24 #include <linux/ptrace.h>
25 #include <linux/slab.h>
27 #include <linux/elf.h>
31 #include <linux/export.h>
35 #include <linux/utsname.h>
38 #include <linux/personality.h>
39 #include <linux/random.h>
40 #include <linux/hw_breakpoint.h>
42 #include <asm/pgtable.h>
43 #include <asm/uaccess.h>
45 #include <asm/processor.h>
48 #include <asm/machdep.h>
51 #include <asm/syscalls.h>
52 #include <asm/switch_to.h>
53 #include <asm/debug.h>
60 extern unsigned long _get_SP(
void);
85 if (tsk->
thread.regs->msr & MSR_FP) {
118 #ifdef CONFIG_ALTIVEC
124 if (
current->thread.regs && (
current->thread.regs->msr & MSR_VEC))
127 giveup_altivec_notask();
129 giveup_altivec(last_task_used_altivec);
138 void flush_altivec_to_thread(
struct task_struct *tsk)
142 if (tsk->
thread.regs->msr & MSR_VEC) {
157 void enable_kernel_vsx(
void)
162 if (
current->thread.regs && (
current->thread.regs->msr & MSR_VSX))
184 if (tsk->
thread.regs->msr & MSR_VSX) {
203 if (
current->thread.regs && (
current->thread.regs->msr & MSR_SPE))
217 if (tsk->
thread.regs->msr & MSR_SPE) {
237 if (last_task_used_math ==
current)
238 last_task_used_math =
NULL;
239 #ifdef CONFIG_ALTIVEC
240 if (last_task_used_altivec ==
current)
241 last_task_used_altivec =
NULL;
244 if (last_task_used_vsx ==
current)
245 last_task_used_vsx =
NULL;
248 if (last_task_used_spe ==
current)
249 last_task_used_spe =
NULL;
255 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
257 unsigned long error_code,
int signal_code,
int breakpt)
261 current->thread.trap_nr = signal_code;
262 if (
notify_die(DIE_DABR_MATCH,
"dabr_match", regs, error_code,
270 info.si_addr = (
void __user *)address;
275 unsigned long error_code)
280 if (
notify_die(DIE_DABR_MATCH,
"dabr_match", regs, error_code,
284 if (debugger_dabr_match(regs))
294 info.si_addr = (
void __user *)address;
301 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
307 thread->iac1 = thread->iac2 = 0;
308 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
309 thread->iac3 = thread->iac4 = 0;
311 thread->dac1 = thread->dac2 = 0;
312 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
313 thread->dvc1 = thread->dvc2 = 0;
320 thread->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US | \
321 DBCR1_IAC3US | DBCR1_IAC4US;
326 thread->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
334 mtspr(SPRN_IAC1, thread->iac1);
335 mtspr(SPRN_IAC2, thread->iac2);
336 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
337 mtspr(SPRN_IAC3, thread->iac3);
338 mtspr(SPRN_IAC4, thread->iac4);
340 mtspr(SPRN_DAC1, thread->dac1);
341 mtspr(SPRN_DAC2, thread->dac2);
342 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
343 mtspr(SPRN_DVC1, thread->dvc1);
344 mtspr(SPRN_DVC2, thread->dvc2);
346 mtspr(SPRN_DBCR0, thread->dbcr0);
347 mtspr(SPRN_DBCR1, thread->dbcr1);
349 mtspr(SPRN_DBCR2, thread->dbcr2);
359 if ((
current->thread.dbcr0 & DBCR0_IDM)
360 || (new_thread->dbcr0 & DBCR0_IDM))
361 prime_debug_regs(new_thread);
364 #ifndef CONFIG_HAVE_HW_BREAKPOINT
376 int set_dabr(
unsigned long dabr,
unsigned long dabrx)
381 return ppc_md.set_dabr(dabr, dabrx);
384 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
385 mtspr(SPRN_DAC1, dabr);
386 #ifdef CONFIG_PPC_47x
389 #elif defined(CONFIG_PPC_BOOK3S)
390 mtspr(SPRN_DABR, dabr);
391 mtspr(SPRN_DABRX, dabrx);
406 #ifdef CONFIG_PPC_BOOK3S_64
407 struct ppc64_tlb_batch *batch;
420 if (prev->
thread.regs && (prev->
thread.regs->msr & MSR_FP))
422 #ifdef CONFIG_ALTIVEC
434 if (prev->
thread.regs && (prev->
thread.regs->msr & MSR_VEC))
435 giveup_altivec(prev);
438 if (prev->
thread.regs && (prev->
thread.regs->msr & MSR_VSX))
450 if ((prev->
thread.regs && (prev->
thread.regs->msr & MSR_SPE)))
455 #ifdef CONFIG_ALTIVEC
459 if (new->thread.regs && last_task_used_altivec ==
new)
460 new->thread.regs->msr |= MSR_VEC;
463 if (new->thread.regs && last_task_used_vsx ==
new)
464 new->thread.regs->msr |= MSR_VSX;
470 if (new->thread.regs && last_task_used_spe ==
new)
471 new->thread.regs->msr |= MSR_SPE;
476 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
477 switch_booke_debug_regs(&new->thread);
483 #ifndef CONFIG_HAVE_HW_BREAKPOINT
485 set_dabr(new->thread.dabr, new->thread.dabrx);
490 new_thread = &
new->
thread;
497 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
499 long unsigned start_tb, current_tb;
500 start_tb = old_thread->start_tb;
501 cu->current_tb = current_tb =
mfspr(SPRN_PURR);
502 old_thread->accum_tb += (current_tb - start_tb);
503 new_thread->start_tb = current_tb;
507 #ifdef CONFIG_PPC_BOOK3S_64
525 last =
_switch(old_thread, new_thread);
527 #ifdef CONFIG_PPC_BOOK3S_64
540 static int instructions_to_print = 16;
542 static void show_instructions(
struct pt_regs *regs)
545 unsigned long pc = regs->
nip - (instructions_to_print * 3 / 4 *
548 printk(
"Instruction dump:");
550 for (i = 0; i < instructions_to_print; i++) {
556 #if !defined(CONFIG_BOOKE)
560 if (!(regs->
msr & MSR_IR))
569 __get_user(instr, (
unsigned int __user *)pc)) {
584 static struct regbit {
588 #if defined(CONFIG_PPC64) && !defined(CONFIG_BOOKE)
617 static void printbits(
unsigned long val,
struct regbit *
bits)
619 const char *sep =
"";
622 for (; bits->bit; ++
bits)
623 if (val & bits->bit) {
624 printk(
"%s%s", sep, bits->name);
632 #define REGS_PER_LINE 4
633 #define LAST_VOLATILE 13
636 #define REGS_PER_LINE 8
637 #define LAST_VOLATILE 12
646 printk(
"REGS: %p TRAP: %04lx %s (%s)\n",
649 printbits(regs->
msr, msr_bits);
650 printk(
" CR: %08lx XER: %08lx\n", regs->
ccr, regs->
xer);
652 printk(
"SOFTE: %ld\n", regs->softe);
657 if (trap == 0x300 || trap == 0x600)
658 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
663 printk(
"TASK = %p[%d] '%s' THREAD: %p",
670 for (i = 0; i < 32; i++) {
678 #ifdef CONFIG_KALLSYMS
683 printk(
"NIP ["REG
"] %pS\n", regs->
nip, (
void *)regs->
nip);
688 show_instructions(regs);
700 #ifdef CONFIG_HAVE_HW_BREAKPOINT
703 set_debug_reg_defaults(&
current->thread);
719 flush_altivec_to_thread(src);
720 flush_vsx_to_thread(src);
721 flush_spe_to_thread(src);
722 #ifdef CONFIG_HAVE_HW_BREAKPOINT
739 struct pt_regs *childregs, *kregs;
747 childregs = (
struct pt_regs *) sp;
751 childregs->
gpr[1] = sp +
sizeof(
struct pt_regs);
753 childregs->
gpr[14] = *(
unsigned long *)usp;
754 childregs->
gpr[2] = ((
unsigned long *)usp)[1],
755 clear_tsk_thread_flag(p, TIF_32BIT);
758 childregs->
gpr[2] = (
unsigned long) p;
767 p->
thread.regs = childregs;
768 childregs->
gpr[3] = 0;
772 childregs->
gpr[13] = childregs->
gpr[6];
775 childregs->
gpr[2] = childregs->
gpr[6];
797 #ifdef CONFIG_PPC_STD_MMU_64
798 if (mmu_has_feature(MMU_FTR_SLB)) {
799 unsigned long sp_vsid;
802 if (mmu_has_feature(MMU_FTR_1T_SEGMENT))
809 p->
thread.ksp_vsid = sp_vsid;
825 kregs->
nip = *((
unsigned long *)
f);
838 unsigned long load_addr = regs->
gpr[2];
847 current->thread.regs = regs - 1;
867 regs->
msr = MSR_USER;
870 unsigned long entry, toc;
883 if (load_addr != 0) {
889 regs->
msr = MSR_USER64;
893 regs->
msr = MSR_USER32;
903 #ifdef CONFIG_ALTIVEC
906 current->thread.vscr.u[3] = 0x00010000;
918 #define PR_FP_ALL_EXCEPT (PR_FP_EXC_DIV | PR_FP_EXC_OVF | PR_FP_EXC_UND \
919 | PR_FP_EXC_RES | PR_FP_EXC_INV)
932 tsk->
thread.fpexc_mode = val &
950 tsk->
thread.fpexc_mode = __pack_fe01(val);
951 if (regs !=
NULL && (regs->
msr & MSR_FP) != 0)
952 regs->
msr = (regs->
msr & ~(MSR_FE0|MSR_FE1))
964 val = tsk->
thread.fpexc_mode;
971 val = __unpack_fe01(tsk->
thread.fpexc_mode);
987 regs->
msr &= ~MSR_LE;
1008 if (regs->
msr & MSR_LE) {
1030 #define TRUNC_PTR(x) ((typeof(x))(((unsigned long)(x)) & 0xffffffff))
1033 int __user *parent_tidp,
void __user *child_threadptr,
1034 int __user *child_tidp,
int p6,
1046 return do_fork(clone_flags, usp, regs, 0, parent_tidp, child_tidp);
1050 unsigned long p4,
unsigned long p5,
unsigned long p6,
1058 unsigned long p4,
unsigned long p5,
unsigned long p6,
1071 set_thread_flag(TIF_RESTOREALL);
1075 static inline int valid_irq_stack(
unsigned long sp,
struct task_struct *
p,
1078 unsigned long stack_page;
1079 unsigned long cpu = task_cpu(p);
1086 stack_page = (
unsigned long) hardirq_ctx[cpu];
1091 stack_page = (
unsigned long) softirq_ctx[cpu];
1100 unsigned long nbytes)
1108 return valid_irq_stack(sp, p, nbytes);
1115 unsigned long ip,
sp;
1126 sp = *(
unsigned long *)sp;
1134 }
while (count++ < 16);
1142 unsigned long sp,
ip,
lr, newsp;
1145 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1146 int curr_frame =
current->curr_ret_stack;
1148 unsigned long rth = (
unsigned long)return_to_handler;
1149 unsigned long mrth = -1;
1151 extern void mod_return_to_handler(
void);
1152 rth = *(
unsigned long *)rth;
1153 mrth = (
unsigned long)mod_return_to_handler;
1154 mrth = *(
unsigned long *)mrth;
1158 sp = (
unsigned long) stack;
1163 asm(
"mr %0,1" :
"=r" (
sp));
1174 stack = (
unsigned long *) sp;
1177 if (!firstframe || ip != lr) {
1179 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1180 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
1182 (
void *)
current->ret_stack[curr_frame].ret);
1201 printk(
"--- Exception: %lx at %pS\n LR = %pS\n",
1202 regs->
trap, (
void *)regs->
nip, (
void *)lr);
1207 }
while (count++ < kstack_depth_to_print);
1218 void __ppc64_runlatch_on(
void)
1223 ctrl =
mfspr(SPRN_CTRLF);
1224 ctrl |= CTRL_RUNLATCH;
1225 mtspr(SPRN_CTRLT, ctrl);
1227 ti->local_flags |= _TLF_RUNLATCH;
1231 void __ppc64_runlatch_off(
void)
1236 ti->local_flags &= ~_TLF_RUNLATCH;
1238 ctrl =
mfspr(SPRN_CTRLF);
1239 ctrl &= ~CTRL_RUNLATCH;
1240 mtspr(SPRN_CTRLT, ctrl);
1251 static inline unsigned long brk_rnd(
void)
1253 unsigned long rnd = 0;
1269 #ifdef CONFIG_PPC_STD_MMU_64