ptrace.h (c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2) ptrace.h (bfe47f358ad298a1efb9b8f8299a81541d90df87)
1/* SPDX-License-Identifier: GPL-2.0 */
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#ifndef __ASM_CSKY_PTRACE_H
5#define __ASM_CSKY_PTRACE_H
6
7#include <uapi/asm/ptrace.h>
8#include <asm/traps.h>
9#include <linux/types.h>
1/* SPDX-License-Identifier: GPL-2.0 */
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#ifndef __ASM_CSKY_PTRACE_H
5#define __ASM_CSKY_PTRACE_H
6
7#include <uapi/asm/ptrace.h>
8#include <asm/traps.h>
9#include <linux/types.h>
10#include <linux/compiler.h>
10
11#ifndef __ASSEMBLY__
12
13#define PS_S 0x80000000 /* Supervisor Mode */
14
15#define arch_has_single_step() (1)
16#define current_pt_regs() \
17({ (struct pt_regs *)((char *)current_thread_info() + THREAD_SIZE) - 1; })
18
19#define user_stack_pointer(regs) ((regs)->usp)
20
21#define user_mode(regs) (!((regs)->sr & PS_S))
22#define instruction_pointer(regs) ((regs)->pc)
23#define profile_pc(regs) instruction_pointer(regs)
24
11
12#ifndef __ASSEMBLY__
13
14#define PS_S 0x80000000 /* Supervisor Mode */
15
16#define arch_has_single_step() (1)
17#define current_pt_regs() \
18({ (struct pt_regs *)((char *)current_thread_info() + THREAD_SIZE) - 1; })
19
20#define user_stack_pointer(regs) ((regs)->usp)
21
22#define user_mode(regs) (!((regs)->sr & PS_S))
23#define instruction_pointer(regs) ((regs)->pc)
24#define profile_pc(regs) instruction_pointer(regs)
25
26static inline void instruction_pointer_set(struct pt_regs *regs,
27 unsigned long val)
28{
29 regs->pc = val;
30}
31
32#if defined(__CSKYABIV2__)
33#define MAX_REG_OFFSET offsetof(struct pt_regs, dcsr)
34#else
35#define MAX_REG_OFFSET offsetof(struct pt_regs, regs[9])
36#endif
37
25static inline bool in_syscall(struct pt_regs const *regs)
26{
27 return ((regs->sr >> 16) & 0xff) == VEC_TRAP0;
28}
29
30static inline void forget_syscall(struct pt_regs *regs)
31{
32 regs->sr &= ~(0xff << 16);
33}
34
35static inline unsigned long regs_return_value(struct pt_regs *regs)
36{
37 return regs->a0;
38}
39
38static inline bool in_syscall(struct pt_regs const *regs)
39{
40 return ((regs->sr >> 16) & 0xff) == VEC_TRAP0;
41}
42
43static inline void forget_syscall(struct pt_regs *regs)
44{
45 regs->sr &= ~(0xff << 16);
46}
47
48static inline unsigned long regs_return_value(struct pt_regs *regs)
49{
50 return regs->a0;
51}
52
53/* Valid only for Kernel mode traps. */
54static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
55{
56 return regs->usp;
57}
58
59extern int regs_query_register_offset(const char *name);
60extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
61 unsigned int n);
62
63/*
64 * regs_get_register() - get register value from its offset
65 * @regs: pt_regs from which register value is gotten
66 * @offset: offset of the register.
67 *
68 * regs_get_register returns the value of a register whose offset from @regs.
69 * The @offset is the offset of the register in struct pt_regs.
70 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
71 */
72static inline unsigned long regs_get_register(struct pt_regs *regs,
73 unsigned int offset)
74{
75 if (unlikely(offset > MAX_REG_OFFSET))
76 return 0;
77
78 return *(unsigned long *)((unsigned long)regs + offset);
79}
80
40#endif /* __ASSEMBLY__ */
41#endif /* __ASM_CSKY_PTRACE_H */
81#endif /* __ASSEMBLY__ */
82#endif /* __ASM_CSKY_PTRACE_H */