Skip to content

Commit 2ce36bf

Browse files
committed
csky: Debug and Ptrace GDB
This patch adds arch ptrace implementation, stack dump and bug.h. Signed-off-by: Guo Ren <ren_guo@c-sky.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent da55128 commit 2ce36bf

4 files changed

Lines changed: 510 additions & 0 deletions

File tree

‎arch/csky/include/asm/bug.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3+
4+
#ifndef __ASM_CSKY_BUG_H
5+
#define __ASM_CSKY_BUG_H
6+
7+
#include <linux/compiler.h>
8+
#include <linux/const.h>
9+
#include <linux/types.h>
10+
11+
#define BUG() \
12+
do { \
13+
asm volatile ("bkpt\n"); \
14+
unreachable(); \
15+
} while (0)
16+
17+
#define HAVE_ARCH_BUG
18+
19+
#include <asm-generic/bug.h>
20+
21+
struct pt_regs;
22+
23+
void die_if_kernel(char *str, struct pt_regs *regs, int nr);
24+
void show_regs(struct pt_regs *regs);
25+
26+
#endif /* __ASM_CSKY_BUG_H */
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3+
4+
#ifndef _CSKY_PTRACE_H
5+
#define _CSKY_PTRACE_H
6+
7+
#ifndef __ASSEMBLY__
8+
9+
struct pt_regs {
10+
unsigned long tls;
11+
unsigned long lr;
12+
unsigned long pc;
13+
unsigned long sr;
14+
unsigned long usp;
15+
16+
/*
17+
* a0, a1, a2, a3:
18+
* abiv1: r2, r3, r4, r5
19+
* abiv2: r0, r1, r2, r3
20+
*/
21+
unsigned long orig_a0;
22+
unsigned long a0;
23+
unsigned long a1;
24+
unsigned long a2;
25+
unsigned long a3;
26+
27+
/*
28+
* ABIV2: r4 ~ r13
29+
* ABIV1: r6 ~ r14, r1
30+
*/
31+
unsigned long regs[10];
32+
33+
#if defined(__CSKYABIV2__)
34+
/* r16 ~ r30 */
35+
unsigned long exregs[15];
36+
37+
unsigned long rhi;
38+
unsigned long rlo;
39+
unsigned long pad; /* reserved */
40+
#endif
41+
};
42+
43+
struct user_fp {
44+
unsigned long vr[96];
45+
unsigned long fcr;
46+
unsigned long fesr;
47+
unsigned long fid;
48+
unsigned long reserved;
49+
};
50+
51+
/*
52+
* Switch stack for switch_to after push pt_regs.
53+
*
54+
* ABI_CSKYV2: r4 ~ r11, r15 ~ r17, r26 ~ r30;
55+
* ABI_CSKYV1: r8 ~ r14, r15;
56+
*/
57+
struct switch_stack {
58+
#if defined(__CSKYABIV2__)
59+
unsigned long r4;
60+
unsigned long r5;
61+
unsigned long r6;
62+
unsigned long r7;
63+
unsigned long r8;
64+
unsigned long r9;
65+
unsigned long r10;
66+
unsigned long r11;
67+
#else
68+
unsigned long r8;
69+
unsigned long r9;
70+
unsigned long r10;
71+
unsigned long r11;
72+
unsigned long r12;
73+
unsigned long r13;
74+
unsigned long r14;
75+
#endif
76+
unsigned long r15;
77+
#if defined(__CSKYABIV2__)
78+
unsigned long r16;
79+
unsigned long r17;
80+
unsigned long r26;
81+
unsigned long r27;
82+
unsigned long r28;
83+
unsigned long r29;
84+
unsigned long r30;
85+
#endif
86+
};
87+
88+
#ifdef __KERNEL__
89+
90+
#define PS_S 0x80000000 /* Supervisor Mode */
91+
92+
#define arch_has_single_step() (1)
93+
#define current_pt_regs() \
94+
({ (struct pt_regs *)((char *)current_thread_info() + THREAD_SIZE) - 1; })
95+
96+
#define user_stack_pointer(regs) ((regs)->usp)
97+
98+
#define user_mode(regs) (!((regs)->sr & PS_S))
99+
#define instruction_pointer(regs) ((regs)->pc)
100+
#define profile_pc(regs) instruction_pointer(regs)
101+
102+
#endif /* __KERNEL__ */
103+
#endif /* __ASSEMBLY__ */
104+
#endif /* _CSKY_PTRACE_H */

‎arch/csky/kernel/dumpstack.c‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3+
4+
#include <linux/ptrace.h>
5+
6+
int kstack_depth_to_print = 48;
7+
8+
void show_trace(unsigned long *stack)
9+
{
10+
unsigned long *endstack;
11+
unsigned long addr;
12+
int i;
13+
14+
pr_info("Call Trace:\n");
15+
addr = (unsigned long)stack + THREAD_SIZE - 1;
16+
endstack = (unsigned long *)(addr & -THREAD_SIZE);
17+
i = 0;
18+
while (stack + 1 <= endstack) {
19+
addr = *stack++;
20+
/*
21+
* If the address is either in the text segment of the
22+
* kernel, or in the region which contains vmalloc'ed
23+
* memory, it *may* be the address of a calling
24+
* routine; if so, print it so that someone tracing
25+
* down the cause of the crash will be able to figure
26+
* out the call path that was taken.
27+
*/
28+
if (__kernel_text_address(addr)) {
29+
#ifndef CONFIG_KALLSYMS
30+
if (i % 5 == 0)
31+
pr_cont("\n ");
32+
#endif
33+
pr_cont(" [<%08lx>] %pS\n", addr, (void *)addr);
34+
i++;
35+
}
36+
}
37+
pr_cont("\n");
38+
}
39+
40+
void show_stack(struct task_struct *task, unsigned long *stack)
41+
{
42+
unsigned long *p;
43+
unsigned long *endstack;
44+
int i;
45+
46+
if (!stack) {
47+
if (task)
48+
stack = (unsigned long *)task->thread.esp0;
49+
else
50+
stack = (unsigned long *)&stack;
51+
}
52+
endstack = (unsigned long *)
53+
(((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE);
54+
55+
pr_info("Stack from %08lx:", (unsigned long)stack);
56+
p = stack;
57+
for (i = 0; i < kstack_depth_to_print; i++) {
58+
if (p + 1 > endstack)
59+
break;
60+
if (i % 8 == 0)
61+
pr_cont("\n ");
62+
pr_cont(" %08lx", *p++);
63+
}
64+
pr_cont("\n");
65+
show_trace(stack);
66+
}

0 commit comments

Comments
 (0)