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