xref: /openbmc/linux/arch/csky/kernel/ptrace.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
12ce36bfaSGuo Ren // SPDX-License-Identifier: GPL-2.0
22ce36bfaSGuo Ren // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
32ce36bfaSGuo Ren 
42f7932b0SGuo Ren #include <linux/audit.h>
52ce36bfaSGuo Ren #include <linux/elf.h>
62ce36bfaSGuo Ren #include <linux/errno.h>
72ce36bfaSGuo Ren #include <linux/kernel.h>
82ce36bfaSGuo Ren #include <linux/mm.h>
92ce36bfaSGuo Ren #include <linux/ptrace.h>
102ce36bfaSGuo Ren #include <linux/regset.h>
112ce36bfaSGuo Ren #include <linux/sched.h>
129216cd72SGuo Ren #include <linux/sched/task_stack.h>
132ce36bfaSGuo Ren #include <linux/signal.h>
142ce36bfaSGuo Ren #include <linux/smp.h>
152ce36bfaSGuo Ren #include <linux/uaccess.h>
162ce36bfaSGuo Ren #include <linux/user.h>
172ce36bfaSGuo Ren 
182ce36bfaSGuo Ren #include <asm/thread_info.h>
192ce36bfaSGuo Ren #include <asm/page.h>
202ce36bfaSGuo Ren #include <asm/processor.h>
212ce36bfaSGuo Ren #include <asm/asm-offsets.h>
222ce36bfaSGuo Ren 
232ce36bfaSGuo Ren #include <abi/regdef.h>
241152cb5aSGuo Ren #include <abi/ckmmu.h>
252ce36bfaSGuo Ren 
262f7932b0SGuo Ren #define CREATE_TRACE_POINTS
272f7932b0SGuo Ren #include <trace/events/syscalls.h>
282f7932b0SGuo Ren 
292ce36bfaSGuo Ren /* sets the trace bits. */
302ce36bfaSGuo Ren #define TRACE_MODE_SI      (1 << 14)
312ce36bfaSGuo Ren #define TRACE_MODE_RUN     0
322ce36bfaSGuo Ren #define TRACE_MODE_MASK    ~(0x3 << 14)
332ce36bfaSGuo Ren 
342ce36bfaSGuo Ren /*
352ce36bfaSGuo Ren  * Make sure the single step bit is not set.
362ce36bfaSGuo Ren  */
singlestep_disable(struct task_struct * tsk)372ce36bfaSGuo Ren static void singlestep_disable(struct task_struct *tsk)
382ce36bfaSGuo Ren {
392ce36bfaSGuo Ren 	struct pt_regs *regs;
402ce36bfaSGuo Ren 
412ce36bfaSGuo Ren 	regs = task_pt_regs(tsk);
422ce36bfaSGuo Ren 	regs->sr = (regs->sr & TRACE_MODE_MASK) | TRACE_MODE_RUN;
43c2e59d1fSGuo Ren 
44c2e59d1fSGuo Ren 	/* Enable irq */
45c2e59d1fSGuo Ren 	regs->sr |= BIT(6);
462ce36bfaSGuo Ren }
472ce36bfaSGuo Ren 
singlestep_enable(struct task_struct * tsk)482ce36bfaSGuo Ren static void singlestep_enable(struct task_struct *tsk)
492ce36bfaSGuo Ren {
502ce36bfaSGuo Ren 	struct pt_regs *regs;
512ce36bfaSGuo Ren 
522ce36bfaSGuo Ren 	regs = task_pt_regs(tsk);
532ce36bfaSGuo Ren 	regs->sr = (regs->sr & TRACE_MODE_MASK) | TRACE_MODE_SI;
54c2e59d1fSGuo Ren 
55c2e59d1fSGuo Ren 	/* Disable irq */
56c2e59d1fSGuo Ren 	regs->sr &= ~BIT(6);
572ce36bfaSGuo Ren }
582ce36bfaSGuo Ren 
592ce36bfaSGuo Ren /*
602ce36bfaSGuo Ren  * Make sure the single step bit is set.
612ce36bfaSGuo Ren  */
user_enable_single_step(struct task_struct * child)622ce36bfaSGuo Ren void user_enable_single_step(struct task_struct *child)
632ce36bfaSGuo Ren {
642ce36bfaSGuo Ren 	singlestep_enable(child);
652ce36bfaSGuo Ren }
662ce36bfaSGuo Ren 
user_disable_single_step(struct task_struct * child)672ce36bfaSGuo Ren void user_disable_single_step(struct task_struct *child)
682ce36bfaSGuo Ren {
692ce36bfaSGuo Ren 	singlestep_disable(child);
702ce36bfaSGuo Ren }
712ce36bfaSGuo Ren 
722ce36bfaSGuo Ren enum csky_regset {
732ce36bfaSGuo Ren 	REGSET_GPR,
742ce36bfaSGuo Ren 	REGSET_FPR,
752ce36bfaSGuo Ren };
762ce36bfaSGuo Ren 
gpr_get(struct task_struct * target,const struct user_regset * regset,struct membuf to)772ce36bfaSGuo Ren static int gpr_get(struct task_struct *target,
782ce36bfaSGuo Ren 		   const struct user_regset *regset,
79dcad7854SAl Viro 		   struct membuf to)
802ce36bfaSGuo Ren {
81dcad7854SAl Viro 	struct pt_regs *regs = task_pt_regs(target);
822ce36bfaSGuo Ren 
832ce36bfaSGuo Ren 	/* Abiv1 regs->tls is fake and we need sync here. */
842ce36bfaSGuo Ren 	regs->tls = task_thread_info(target)->tp_value;
852ce36bfaSGuo Ren 
868bfb6764SZhenzhong Duan 	return membuf_write(&to, regs, sizeof(*regs));
872ce36bfaSGuo Ren }
882ce36bfaSGuo Ren 
gpr_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)892ce36bfaSGuo Ren static int gpr_set(struct task_struct *target,
902ce36bfaSGuo Ren 		    const struct user_regset *regset,
912ce36bfaSGuo Ren 		    unsigned int pos, unsigned int count,
922ce36bfaSGuo Ren 		    const void *kbuf, const void __user *ubuf)
932ce36bfaSGuo Ren {
942ce36bfaSGuo Ren 	int ret;
952ce36bfaSGuo Ren 	struct pt_regs regs;
962ce36bfaSGuo Ren 
972ce36bfaSGuo Ren 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &regs, 0, -1);
982ce36bfaSGuo Ren 	if (ret)
992ce36bfaSGuo Ren 		return ret;
1002ce36bfaSGuo Ren 
101af89ebaaSGuo Ren 	/* BIT(0) of regs.sr is Condition Code/Carry bit */
102af89ebaaSGuo Ren 	regs.sr = (regs.sr & BIT(0)) | (task_pt_regs(target)->sr & ~BIT(0));
103789154c2SGuo Ren #ifdef CONFIG_CPU_HAS_HILO
104789154c2SGuo Ren 	regs.dcsr = task_pt_regs(target)->dcsr;
105789154c2SGuo Ren #endif
1062ce36bfaSGuo Ren 	task_thread_info(target)->tp_value = regs.tls;
1072ce36bfaSGuo Ren 
1082ce36bfaSGuo Ren 	*task_pt_regs(target) = regs;
1092ce36bfaSGuo Ren 
1102ce36bfaSGuo Ren 	return 0;
1112ce36bfaSGuo Ren }
1122ce36bfaSGuo Ren 
fpr_get(struct task_struct * target,const struct user_regset * regset,struct membuf to)1132ce36bfaSGuo Ren static int fpr_get(struct task_struct *target,
1142ce36bfaSGuo Ren 		   const struct user_regset *regset,
115dcad7854SAl Viro 		   struct membuf to)
1162ce36bfaSGuo Ren {
1172ce36bfaSGuo Ren 	struct user_fp *regs = (struct user_fp *)&target->thread.user_fp;
1182ce36bfaSGuo Ren 
1192ce36bfaSGuo Ren #if defined(CONFIG_CPU_HAS_FPUV2) && !defined(CONFIG_CPU_HAS_VDSP)
1202ce36bfaSGuo Ren 	int i;
1212ce36bfaSGuo Ren 	struct user_fp tmp = *regs;
1222ce36bfaSGuo Ren 
1232ce36bfaSGuo Ren 	for (i = 0; i < 16; i++) {
1242ce36bfaSGuo Ren 		tmp.vr[i*4] = regs->vr[i*2];
1252ce36bfaSGuo Ren 		tmp.vr[i*4 + 1] = regs->vr[i*2 + 1];
1262ce36bfaSGuo Ren 	}
1272ce36bfaSGuo Ren 
1282ce36bfaSGuo Ren 	for (i = 0; i < 32; i++)
1292ce36bfaSGuo Ren 		tmp.vr[64 + i] = regs->vr[32 + i];
1302ce36bfaSGuo Ren 
131dcad7854SAl Viro 	return membuf_write(&to, &tmp, sizeof(tmp));
1322ce36bfaSGuo Ren #else
133dcad7854SAl Viro 	return membuf_write(&to, regs, sizeof(*regs));
1342ce36bfaSGuo Ren #endif
1352ce36bfaSGuo Ren }
1362ce36bfaSGuo Ren 
fpr_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)1372ce36bfaSGuo Ren static int fpr_set(struct task_struct *target,
1382ce36bfaSGuo Ren 		   const struct user_regset *regset,
1392ce36bfaSGuo Ren 		   unsigned int pos, unsigned int count,
1402ce36bfaSGuo Ren 		   const void *kbuf, const void __user *ubuf)
1412ce36bfaSGuo Ren {
1422ce36bfaSGuo Ren 	int ret;
1432ce36bfaSGuo Ren 	struct user_fp *regs = (struct user_fp *)&target->thread.user_fp;
1442ce36bfaSGuo Ren 
1452ce36bfaSGuo Ren #if defined(CONFIG_CPU_HAS_FPUV2) && !defined(CONFIG_CPU_HAS_VDSP)
1462ce36bfaSGuo Ren 	int i;
1472ce36bfaSGuo Ren 	struct user_fp tmp;
1482ce36bfaSGuo Ren 
1492ce36bfaSGuo Ren 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &tmp, 0, -1);
1502ce36bfaSGuo Ren 
1512ce36bfaSGuo Ren 	*regs = tmp;
1522ce36bfaSGuo Ren 
1532ce36bfaSGuo Ren 	for (i = 0; i < 16; i++) {
1542ce36bfaSGuo Ren 		regs->vr[i*2] = tmp.vr[i*4];
1552ce36bfaSGuo Ren 		regs->vr[i*2 + 1] = tmp.vr[i*4 + 1];
1562ce36bfaSGuo Ren 	}
1572ce36bfaSGuo Ren 
1582ce36bfaSGuo Ren 	for (i = 0; i < 32; i++)
1592ce36bfaSGuo Ren 		regs->vr[32 + i] = tmp.vr[64 + i];
1602ce36bfaSGuo Ren #else
1612ce36bfaSGuo Ren 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, regs, 0, -1);
1622ce36bfaSGuo Ren #endif
1632ce36bfaSGuo Ren 
1642ce36bfaSGuo Ren 	return ret;
1652ce36bfaSGuo Ren }
1662ce36bfaSGuo Ren 
1672ce36bfaSGuo Ren static const struct user_regset csky_regsets[] = {
1682ce36bfaSGuo Ren 	[REGSET_GPR] = {
1692ce36bfaSGuo Ren 		.core_note_type = NT_PRSTATUS,
1709216cd72SGuo Ren 		.n = sizeof(struct pt_regs) / sizeof(u32),
1712ce36bfaSGuo Ren 		.size = sizeof(u32),
1722ce36bfaSGuo Ren 		.align = sizeof(u32),
173dcad7854SAl Viro 		.regset_get = gpr_get,
174dcad7854SAl Viro 		.set = gpr_set,
1752ce36bfaSGuo Ren 	},
1762ce36bfaSGuo Ren 	[REGSET_FPR] = {
1772ce36bfaSGuo Ren 		.core_note_type = NT_PRFPREG,
1782ce36bfaSGuo Ren 		.n = sizeof(struct user_fp) / sizeof(u32),
1792ce36bfaSGuo Ren 		.size = sizeof(u32),
1802ce36bfaSGuo Ren 		.align = sizeof(u32),
181dcad7854SAl Viro 		.regset_get = fpr_get,
182dcad7854SAl Viro 		.set = fpr_set,
1832ce36bfaSGuo Ren 	},
1842ce36bfaSGuo Ren };
1852ce36bfaSGuo Ren 
1862ce36bfaSGuo Ren static const struct user_regset_view user_csky_view = {
1872ce36bfaSGuo Ren 	.name = "csky",
1882ce36bfaSGuo Ren 	.e_machine = ELF_ARCH,
1892ce36bfaSGuo Ren 	.regsets = csky_regsets,
1902ce36bfaSGuo Ren 	.n = ARRAY_SIZE(csky_regsets),
1912ce36bfaSGuo Ren };
1922ce36bfaSGuo Ren 
task_user_regset_view(struct task_struct * task)1932ce36bfaSGuo Ren const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1942ce36bfaSGuo Ren {
1952ce36bfaSGuo Ren 	return &user_csky_view;
1962ce36bfaSGuo Ren }
1972ce36bfaSGuo Ren 
198bfe47f35SGuo Ren struct pt_regs_offset {
199bfe47f35SGuo Ren 	const char *name;
200bfe47f35SGuo Ren 	int offset;
201bfe47f35SGuo Ren };
202bfe47f35SGuo Ren 
203bfe47f35SGuo Ren #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
204bfe47f35SGuo Ren #define REG_OFFSET_END {.name = NULL, .offset = 0}
205bfe47f35SGuo Ren 
206bfe47f35SGuo Ren static const struct pt_regs_offset regoffset_table[] = {
207bfe47f35SGuo Ren 	REG_OFFSET_NAME(tls),
208bfe47f35SGuo Ren 	REG_OFFSET_NAME(lr),
209bfe47f35SGuo Ren 	REG_OFFSET_NAME(pc),
210bfe47f35SGuo Ren 	REG_OFFSET_NAME(sr),
211bfe47f35SGuo Ren 	REG_OFFSET_NAME(usp),
212bfe47f35SGuo Ren 	REG_OFFSET_NAME(orig_a0),
213bfe47f35SGuo Ren 	REG_OFFSET_NAME(a0),
214bfe47f35SGuo Ren 	REG_OFFSET_NAME(a1),
215bfe47f35SGuo Ren 	REG_OFFSET_NAME(a2),
216bfe47f35SGuo Ren 	REG_OFFSET_NAME(a3),
217bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[0]),
218bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[1]),
219bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[2]),
220bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[3]),
221bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[4]),
222bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[5]),
223bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[6]),
224bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[7]),
225bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[8]),
226bfe47f35SGuo Ren 	REG_OFFSET_NAME(regs[9]),
227bfe47f35SGuo Ren #if defined(__CSKYABIV2__)
228bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[0]),
229bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[1]),
230bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[2]),
231bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[3]),
232bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[4]),
233bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[5]),
234bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[6]),
235bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[7]),
236bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[8]),
237bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[9]),
238bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[10]),
239bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[11]),
240bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[12]),
241bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[13]),
242bfe47f35SGuo Ren 	REG_OFFSET_NAME(exregs[14]),
243bfe47f35SGuo Ren 	REG_OFFSET_NAME(rhi),
244bfe47f35SGuo Ren 	REG_OFFSET_NAME(rlo),
245bfe47f35SGuo Ren 	REG_OFFSET_NAME(dcsr),
246bfe47f35SGuo Ren #endif
247bfe47f35SGuo Ren 	REG_OFFSET_END,
248bfe47f35SGuo Ren };
249bfe47f35SGuo Ren 
250bfe47f35SGuo Ren /**
251bfe47f35SGuo Ren  * regs_query_register_offset() - query register offset from its name
252bfe47f35SGuo Ren  * @name:	the name of a register
253bfe47f35SGuo Ren  *
254bfe47f35SGuo Ren  * regs_query_register_offset() returns the offset of a register in struct
255bfe47f35SGuo Ren  * pt_regs from its name. If the name is invalid, this returns -EINVAL;
256bfe47f35SGuo Ren  */
regs_query_register_offset(const char * name)257bfe47f35SGuo Ren int regs_query_register_offset(const char *name)
258bfe47f35SGuo Ren {
259bfe47f35SGuo Ren 	const struct pt_regs_offset *roff;
260bfe47f35SGuo Ren 
261bfe47f35SGuo Ren 	for (roff = regoffset_table; roff->name != NULL; roff++)
262bfe47f35SGuo Ren 		if (!strcmp(roff->name, name))
263bfe47f35SGuo Ren 			return roff->offset;
264bfe47f35SGuo Ren 	return -EINVAL;
265bfe47f35SGuo Ren }
266bfe47f35SGuo Ren 
267bfe47f35SGuo Ren /**
268bfe47f35SGuo Ren  * regs_within_kernel_stack() - check the address in the stack
269bfe47f35SGuo Ren  * @regs:      pt_regs which contains kernel stack pointer.
270bfe47f35SGuo Ren  * @addr:      address which is checked.
271bfe47f35SGuo Ren  *
272bfe47f35SGuo Ren  * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
273bfe47f35SGuo Ren  * If @addr is within the kernel stack, it returns true. If not, returns false.
274bfe47f35SGuo Ren  */
regs_within_kernel_stack(struct pt_regs * regs,unsigned long addr)275bfe47f35SGuo Ren static bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
276bfe47f35SGuo Ren {
277bfe47f35SGuo Ren 	return (addr & ~(THREAD_SIZE - 1))  ==
278bfe47f35SGuo Ren 		(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1));
279bfe47f35SGuo Ren }
280bfe47f35SGuo Ren 
281bfe47f35SGuo Ren /**
282bfe47f35SGuo Ren  * regs_get_kernel_stack_nth() - get Nth entry of the stack
283bfe47f35SGuo Ren  * @regs:	pt_regs which contains kernel stack pointer.
284bfe47f35SGuo Ren  * @n:		stack entry number.
285bfe47f35SGuo Ren  *
286bfe47f35SGuo Ren  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
287bfe47f35SGuo Ren  * is specified by @regs. If the @n th entry is NOT in the kernel stack,
288bfe47f35SGuo Ren  * this returns 0.
289bfe47f35SGuo Ren  */
regs_get_kernel_stack_nth(struct pt_regs * regs,unsigned int n)290bfe47f35SGuo Ren unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
291bfe47f35SGuo Ren {
292bfe47f35SGuo Ren 	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
293bfe47f35SGuo Ren 
294bfe47f35SGuo Ren 	addr += n;
295bfe47f35SGuo Ren 	if (regs_within_kernel_stack(regs, (unsigned long)addr))
296bfe47f35SGuo Ren 		return *addr;
297bfe47f35SGuo Ren 	else
298bfe47f35SGuo Ren 		return 0;
299bfe47f35SGuo Ren }
300bfe47f35SGuo Ren 
ptrace_disable(struct task_struct * child)3012ce36bfaSGuo Ren void ptrace_disable(struct task_struct *child)
3022ce36bfaSGuo Ren {
3032ce36bfaSGuo Ren 	singlestep_disable(child);
3042ce36bfaSGuo Ren }
3052ce36bfaSGuo Ren 
arch_ptrace(struct task_struct * child,long request,unsigned long addr,unsigned long data)3062ce36bfaSGuo Ren long arch_ptrace(struct task_struct *child, long request,
3072ce36bfaSGuo Ren 		 unsigned long addr, unsigned long data)
3082ce36bfaSGuo Ren {
3092ce36bfaSGuo Ren 	long ret = -EIO;
3102ce36bfaSGuo Ren 
3112ce36bfaSGuo Ren 	switch (request) {
3122ce36bfaSGuo Ren 	default:
3132ce36bfaSGuo Ren 		ret = ptrace_request(child, request, addr, data);
3142ce36bfaSGuo Ren 		break;
3152ce36bfaSGuo Ren 	}
3162ce36bfaSGuo Ren 
3172ce36bfaSGuo Ren 	return ret;
3182ce36bfaSGuo Ren }
3192ce36bfaSGuo Ren 
syscall_trace_enter(struct pt_regs * regs)320e95a4f8cSGuo Ren asmlinkage int syscall_trace_enter(struct pt_regs *regs)
3212ce36bfaSGuo Ren {
3222f7932b0SGuo Ren 	if (test_thread_flag(TIF_SYSCALL_TRACE))
323*153474baSEric W. Biederman 		if (ptrace_report_syscall_entry(regs))
324e95a4f8cSGuo Ren 			return -1;
325e95a4f8cSGuo Ren 
326e95a4f8cSGuo Ren 	if (secure_computing() == -1)
327e95a4f8cSGuo Ren 		return -1;
3282ce36bfaSGuo Ren 
3292f7932b0SGuo Ren 	if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3302f7932b0SGuo Ren 		trace_sys_enter(regs, syscall_get_nr(current, regs));
3312ce36bfaSGuo Ren 
3322f7932b0SGuo Ren 	audit_syscall_entry(regs_syscallid(regs), regs->a0, regs->a1, regs->a2, regs->a3);
333e95a4f8cSGuo Ren 	return 0;
3342ce36bfaSGuo Ren }
3352ce36bfaSGuo Ren 
syscall_trace_exit(struct pt_regs * regs)3362f7932b0SGuo Ren asmlinkage void syscall_trace_exit(struct pt_regs *regs)
3372f7932b0SGuo Ren {
3382f7932b0SGuo Ren 	audit_syscall_exit(regs);
3392f7932b0SGuo Ren 
3402f7932b0SGuo Ren 	if (test_thread_flag(TIF_SYSCALL_TRACE))
341*153474baSEric W. Biederman 		ptrace_report_syscall_exit(regs, 0);
3422f7932b0SGuo Ren 
3432f7932b0SGuo Ren 	if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3442f7932b0SGuo Ren 		trace_sys_exit(regs, syscall_get_return_value(current, regs));
3452ce36bfaSGuo Ren }
3462ce36bfaSGuo Ren 
3471152cb5aSGuo Ren #ifdef CONFIG_CPU_CK860
show_iutlb(void)3481152cb5aSGuo Ren static void show_iutlb(void)
3491152cb5aSGuo Ren {
3501152cb5aSGuo Ren 	int entry, i;
3511152cb5aSGuo Ren 	unsigned long flags;
3521152cb5aSGuo Ren 	unsigned long oldpid;
3531152cb5aSGuo Ren 	unsigned long entryhi[16], entrylo0[16], entrylo1[16];
3541152cb5aSGuo Ren 
3551152cb5aSGuo Ren 	oldpid = read_mmu_entryhi();
3561152cb5aSGuo Ren 
3571152cb5aSGuo Ren 	entry = 0x8000;
3581152cb5aSGuo Ren 
3591152cb5aSGuo Ren 	local_irq_save(flags);
3601152cb5aSGuo Ren 
3611152cb5aSGuo Ren 	for (i = 0; i < 16; i++) {
3621152cb5aSGuo Ren 		write_mmu_index(entry);
3631152cb5aSGuo Ren 		tlb_read();
3641152cb5aSGuo Ren 		entryhi[i]  = read_mmu_entryhi();
3651152cb5aSGuo Ren 		entrylo0[i] = read_mmu_entrylo0();
3661152cb5aSGuo Ren 		entrylo1[i] = read_mmu_entrylo1();
3671152cb5aSGuo Ren 
3681152cb5aSGuo Ren 		entry++;
3691152cb5aSGuo Ren 	}
3701152cb5aSGuo Ren 
3711152cb5aSGuo Ren 	local_irq_restore(flags);
3721152cb5aSGuo Ren 
3731152cb5aSGuo Ren 	write_mmu_entryhi(oldpid);
3741152cb5aSGuo Ren 
3751152cb5aSGuo Ren 	printk("\n\n\n");
3761152cb5aSGuo Ren 	for (i = 0; i < 16; i++)
3771152cb5aSGuo Ren 		printk("iutlb[%d]:	entryhi - 0x%lx;	entrylo0 - 0x%lx;"
3781152cb5aSGuo Ren 		       "	entrylo1 - 0x%lx\n",
3791152cb5aSGuo Ren 			 i, entryhi[i], entrylo0[i], entrylo1[i]);
3801152cb5aSGuo Ren 	printk("\n\n\n");
3811152cb5aSGuo Ren }
3821152cb5aSGuo Ren 
show_dutlb(void)3831152cb5aSGuo Ren static void show_dutlb(void)
3841152cb5aSGuo Ren {
3851152cb5aSGuo Ren 	int entry, i;
3861152cb5aSGuo Ren 	unsigned long flags;
3871152cb5aSGuo Ren 	unsigned long oldpid;
3881152cb5aSGuo Ren 	unsigned long entryhi[16], entrylo0[16], entrylo1[16];
3891152cb5aSGuo Ren 
3901152cb5aSGuo Ren 	oldpid = read_mmu_entryhi();
3911152cb5aSGuo Ren 
3921152cb5aSGuo Ren 	entry = 0x4000;
3931152cb5aSGuo Ren 
3941152cb5aSGuo Ren 	local_irq_save(flags);
3951152cb5aSGuo Ren 
3961152cb5aSGuo Ren 	for (i = 0; i < 16; i++) {
3971152cb5aSGuo Ren 		write_mmu_index(entry);
3981152cb5aSGuo Ren 		tlb_read();
3991152cb5aSGuo Ren 		entryhi[i]  = read_mmu_entryhi();
4001152cb5aSGuo Ren 		entrylo0[i] = read_mmu_entrylo0();
4011152cb5aSGuo Ren 		entrylo1[i] = read_mmu_entrylo1();
4021152cb5aSGuo Ren 
4031152cb5aSGuo Ren 		entry++;
4041152cb5aSGuo Ren 	}
4051152cb5aSGuo Ren 
4061152cb5aSGuo Ren 	local_irq_restore(flags);
4071152cb5aSGuo Ren 
4081152cb5aSGuo Ren 	write_mmu_entryhi(oldpid);
4091152cb5aSGuo Ren 
4101152cb5aSGuo Ren 	printk("\n\n\n");
4111152cb5aSGuo Ren 	for (i = 0; i < 16; i++)
4121152cb5aSGuo Ren 		printk("dutlb[%d]:	entryhi - 0x%lx;	entrylo0 - 0x%lx;"
4131152cb5aSGuo Ren 		       "	entrylo1 - 0x%lx\n",
4141152cb5aSGuo Ren 			 i, entryhi[i], entrylo0[i], entrylo1[i]);
4151152cb5aSGuo Ren 	printk("\n\n\n");
4161152cb5aSGuo Ren }
4171152cb5aSGuo Ren 
4181152cb5aSGuo Ren static unsigned long entryhi[1024], entrylo0[1024], entrylo1[1024];
show_jtlb(void)4191152cb5aSGuo Ren static void show_jtlb(void)
4201152cb5aSGuo Ren {
4211152cb5aSGuo Ren 	int entry;
4221152cb5aSGuo Ren 	unsigned long flags;
4231152cb5aSGuo Ren 	unsigned long oldpid;
4241152cb5aSGuo Ren 
4251152cb5aSGuo Ren 	oldpid = read_mmu_entryhi();
4261152cb5aSGuo Ren 
4271152cb5aSGuo Ren 	entry = 0;
4281152cb5aSGuo Ren 
4291152cb5aSGuo Ren 	local_irq_save(flags);
4301152cb5aSGuo Ren 	while (entry < 1024) {
4311152cb5aSGuo Ren 		write_mmu_index(entry);
4321152cb5aSGuo Ren 		tlb_read();
4331152cb5aSGuo Ren 		entryhi[entry]  = read_mmu_entryhi();
4341152cb5aSGuo Ren 		entrylo0[entry] = read_mmu_entrylo0();
4351152cb5aSGuo Ren 		entrylo1[entry] = read_mmu_entrylo1();
4361152cb5aSGuo Ren 
4371152cb5aSGuo Ren 		entry++;
4381152cb5aSGuo Ren 	}
4391152cb5aSGuo Ren 	local_irq_restore(flags);
4401152cb5aSGuo Ren 
4411152cb5aSGuo Ren 	write_mmu_entryhi(oldpid);
4421152cb5aSGuo Ren 
4431152cb5aSGuo Ren 	printk("\n\n\n");
4441152cb5aSGuo Ren 
4451152cb5aSGuo Ren 	for (entry = 0; entry < 1024; entry++)
4461152cb5aSGuo Ren 		printk("jtlb[%x]:	entryhi - 0x%lx;	entrylo0 - 0x%lx;"
4471152cb5aSGuo Ren 		       "	entrylo1 - 0x%lx\n",
4481152cb5aSGuo Ren 			 entry, entryhi[entry], entrylo0[entry], entrylo1[entry]);
4491152cb5aSGuo Ren 	printk("\n\n\n");
4501152cb5aSGuo Ren }
4511152cb5aSGuo Ren 
show_tlb(void)4521152cb5aSGuo Ren static void show_tlb(void)
4531152cb5aSGuo Ren {
4541152cb5aSGuo Ren 	show_iutlb();
4551152cb5aSGuo Ren 	show_dutlb();
4561152cb5aSGuo Ren 	show_jtlb();
4571152cb5aSGuo Ren }
4581152cb5aSGuo Ren #else
show_tlb(void)4591152cb5aSGuo Ren static void show_tlb(void)
4601152cb5aSGuo Ren {
4611152cb5aSGuo Ren 	return;
4621152cb5aSGuo Ren }
4631152cb5aSGuo Ren #endif
4641152cb5aSGuo Ren 
show_regs(struct pt_regs * fp)4652ce36bfaSGuo Ren void show_regs(struct pt_regs *fp)
4662ce36bfaSGuo Ren {
4672ce36bfaSGuo Ren 	pr_info("\nCURRENT PROCESS:\n\n");
4682ce36bfaSGuo Ren 	pr_info("COMM=%s PID=%d\n", current->comm, current->pid);
4692ce36bfaSGuo Ren 
4702ce36bfaSGuo Ren 	if (current->mm) {
4712ce36bfaSGuo Ren 		pr_info("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
4722ce36bfaSGuo Ren 		       (int) current->mm->start_code,
4732ce36bfaSGuo Ren 		       (int) current->mm->end_code,
4742ce36bfaSGuo Ren 		       (int) current->mm->start_data,
4752ce36bfaSGuo Ren 		       (int) current->mm->end_data,
4762ce36bfaSGuo Ren 		       (int) current->mm->end_data,
4772ce36bfaSGuo Ren 		       (int) current->mm->brk);
4782ce36bfaSGuo Ren 		pr_info("USER-STACK=%08x  KERNEL-STACK=%08x\n\n",
4792ce36bfaSGuo Ren 		       (int) current->mm->start_stack,
4802ce36bfaSGuo Ren 		       (int) (((unsigned long) current) + 2 * PAGE_SIZE));
4812ce36bfaSGuo Ren 	}
4822ce36bfaSGuo Ren 
4838f4f1639SGuo Ren 	pr_info("PC: 0x%08lx (%pS)\n", (long)fp->pc, (void *)fp->pc);
4848f4f1639SGuo Ren 	pr_info("LR: 0x%08lx (%pS)\n", (long)fp->lr, (void *)fp->lr);
48551748e77SGuo Ren 	pr_info("SP: 0x%08lx\n", (long)fp->usp);
4862ce36bfaSGuo Ren 	pr_info("PSR: 0x%08lx\n", (long)fp->sr);
48751748e77SGuo Ren 	pr_info("orig_a0: 0x%08lx\n", fp->orig_a0);
48851748e77SGuo Ren 	pr_info("PT_REGS: 0x%08lx\n", (long)fp);
4892ce36bfaSGuo Ren 
4902ce36bfaSGuo Ren 	pr_info(" a0: 0x%08lx   a1: 0x%08lx   a2: 0x%08lx   a3: 0x%08lx\n",
4912ce36bfaSGuo Ren 		fp->a0, fp->a1, fp->a2, fp->a3);
4922ce36bfaSGuo Ren #if defined(__CSKYABIV2__)
4932ce36bfaSGuo Ren 	pr_info(" r4: 0x%08lx   r5: 0x%08lx   r6: 0x%08lx   r7: 0x%08lx\n",
4942ce36bfaSGuo Ren 		fp->regs[0], fp->regs[1], fp->regs[2], fp->regs[3]);
4952ce36bfaSGuo Ren 	pr_info(" r8: 0x%08lx   r9: 0x%08lx  r10: 0x%08lx  r11: 0x%08lx\n",
4962ce36bfaSGuo Ren 		fp->regs[4], fp->regs[5], fp->regs[6], fp->regs[7]);
4978f4f1639SGuo Ren 	pr_info("r12: 0x%08lx  r13: 0x%08lx  r15: 0x%08lx\n",
4982ce36bfaSGuo Ren 		fp->regs[8], fp->regs[9], fp->lr);
4992ce36bfaSGuo Ren 	pr_info("r16: 0x%08lx  r17: 0x%08lx  r18: 0x%08lx  r19: 0x%08lx\n",
5002ce36bfaSGuo Ren 		fp->exregs[0], fp->exregs[1], fp->exregs[2], fp->exregs[3]);
5018f4f1639SGuo Ren 	pr_info("r20: 0x%08lx  r21: 0x%08lx  r22: 0x%08lx  r23: 0x%08lx\n",
5022ce36bfaSGuo Ren 		fp->exregs[4], fp->exregs[5], fp->exregs[6], fp->exregs[7]);
5038f4f1639SGuo Ren 	pr_info("r24: 0x%08lx  r25: 0x%08lx  r26: 0x%08lx  r27: 0x%08lx\n",
5042ce36bfaSGuo Ren 		fp->exregs[8], fp->exregs[9], fp->exregs[10], fp->exregs[11]);
5058f4f1639SGuo Ren 	pr_info("r28: 0x%08lx  r29: 0x%08lx  r30: 0x%08lx  tls: 0x%08lx\n",
5062ce36bfaSGuo Ren 		fp->exregs[12], fp->exregs[13], fp->exregs[14], fp->tls);
5078f4f1639SGuo Ren 	pr_info(" hi: 0x%08lx   lo: 0x%08lx\n",
5082ce36bfaSGuo Ren 		fp->rhi, fp->rlo);
5092ce36bfaSGuo Ren #else
5102ce36bfaSGuo Ren 	pr_info(" r6: 0x%08lx   r7: 0x%08lx   r8: 0x%08lx   r9: 0x%08lx\n",
5112ce36bfaSGuo Ren 		fp->regs[0], fp->regs[1], fp->regs[2], fp->regs[3]);
5122ce36bfaSGuo Ren 	pr_info("r10: 0x%08lx  r11: 0x%08lx  r12: 0x%08lx  r13: 0x%08lx\n",
5132ce36bfaSGuo Ren 		fp->regs[4], fp->regs[5], fp->regs[6], fp->regs[7]);
5145bc46ce2SGuo Ren 	pr_info("r14: 0x%08lx   r1: 0x%08lx\n",
5155bc46ce2SGuo Ren 		fp->regs[8], fp->regs[9]);
5162ce36bfaSGuo Ren #endif
5172ce36bfaSGuo Ren 
5181152cb5aSGuo Ren 	show_tlb();
5191152cb5aSGuo Ren 
5208f4f1639SGuo Ren 	return;
5212ce36bfaSGuo Ren }
522