xref: /openbmc/u-boot/arch/mips/include/asm/ptrace.h (revision cbd2fba1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
4  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
5  */
6 #ifndef _ASM_PTRACE_H
7 #define _ASM_PTRACE_H
8 
9 #include <linux/compiler.h>
10 #include <linux/types.h>
11 #include <asm/isadep.h>
12 
13 /*
14  * This struct defines the way the registers are stored on the stack during a
15  * system call/exception. As usual the registers k0/k1 aren't being saved.
16  *
17  * If you add a register here, also add it to regoffset_table[] in
18  * arch/mips/kernel/ptrace.c.
19  */
20 struct pt_regs {
21 #ifdef CONFIG_32BIT
22 	/* Pad bytes for argument save space on the stack. */
23 	unsigned long pad0[8];
24 #endif
25 
26 	/* Saved main processor registers. */
27 	unsigned long regs[32];
28 
29 	/* Saved special registers. */
30 	unsigned long cp0_status;
31 	unsigned long hi;
32 	unsigned long lo;
33 #ifdef CONFIG_CPU_HAS_SMARTMIPS
34 	unsigned long acx;
35 #endif
36 	unsigned long cp0_badvaddr;
37 	unsigned long cp0_cause;
38 	unsigned long cp0_epc;
39 #ifdef CONFIG_CPU_CAVIUM_OCTEON
40 	unsigned long long mpl[6];        /* MTM{0-5} */
41 	unsigned long long mtp[6];        /* MTP{0-5} */
42 #endif
43 	unsigned long __last[0];
44 } __aligned(8);
45 
46 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
47 {
48 	return regs->regs[31];
49 }
50 
51 /*
52  * Don't use asm-generic/ptrace.h it defines FP accessors that don't make
53  * sense on MIPS.  We rather want an error if they get invoked.
54  */
55 
56 static inline void instruction_pointer_set(struct pt_regs *regs,
57 						unsigned long val)
58 {
59 	regs->cp0_epc = val;
60 }
61 
62 /* Query offset/name of register from its name/offset */
63 extern int regs_query_register_offset(const char *name);
64 #define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
65 
66 /**
67  * regs_get_register() - get register value from its offset
68  * @regs:       pt_regs from which register value is gotten.
69  * @offset:     offset number of the register.
70  *
71  * regs_get_register returns the value of a register. The @offset is the
72  * offset of the register in struct pt_regs address which specified by @regs.
73  * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
74  */
75 static inline unsigned long regs_get_register(struct pt_regs *regs,
76 						unsigned int offset)
77 {
78 	if (unlikely(offset > MAX_REG_OFFSET))
79 		return 0;
80 
81 	return *(unsigned long *)((unsigned long)regs + offset);
82 }
83 
84 /*
85  * Does the process account for user or for system time?
86  */
87 #define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER)
88 
89 #define instruction_pointer(regs) ((regs)->cp0_epc)
90 #define profile_pc(regs) instruction_pointer(regs)
91 
92 /* Helpers for working with the user stack pointer */
93 
94 static inline unsigned long user_stack_pointer(struct pt_regs *regs)
95 {
96 	return regs->regs[29];
97 }
98 
99 static inline void user_stack_pointer_set(struct pt_regs *regs,
100 						unsigned long val)
101 {
102 	regs->regs[29] = val;
103 }
104 
105 #endif /* _ASM_PTRACE_H */
106