Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 2 | /* |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 3 | * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle |
| 4 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 5 | */ |
| 6 | #ifndef _ASM_PTRACE_H |
| 7 | #define _ASM_PTRACE_H |
| 8 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 9 | #include <linux/compiler.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <asm/isadep.h> |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 12 | |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 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. |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 16 | * |
| 17 | * If you add a register here, also add it to regoffset_table[] in |
| 18 | * arch/mips/kernel/ptrace.c. |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 19 | */ |
| 20 | struct pt_regs { |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 21 | #ifdef CONFIG_32BIT |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 22 | /* Pad bytes for argument save space on the stack. */ |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 23 | unsigned long pad0[8]; |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 24 | #endif |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 25 | |
| 26 | /* Saved main processor registers. */ |
| 27 | unsigned long regs[32]; |
| 28 | |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 29 | /* Saved special registers. */ |
| 30 | unsigned long cp0_status; |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 31 | unsigned long hi; |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 32 | unsigned long lo; |
| 33 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 34 | unsigned long acx; |
| 35 | #endif |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 36 | unsigned long cp0_badvaddr; |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 37 | unsigned long cp0_cause; |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 38 | unsigned long cp0_epc; |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 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); |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 45 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 46 | static inline unsigned long kernel_stack_pointer(struct pt_regs *regs) |
| 47 | { |
| 48 | return regs->regs[31]; |
| 49 | } |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 50 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 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 | */ |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 55 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 56 | static inline void instruction_pointer_set(struct pt_regs *regs, |
| 57 | unsigned long val) |
| 58 | { |
| 59 | regs->cp0_epc = val; |
| 60 | } |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 61 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 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)) |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 65 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 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; |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 80 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 81 | return *(unsigned long *)((unsigned long)regs + offset); |
| 82 | } |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 83 | |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 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) |
Shinya Kuribayashi | c824af8 | 2008-03-25 11:43:17 +0900 | [diff] [blame] | 90 | #define profile_pc(regs) instruction_pointer(regs) |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 91 | |
Daniel Schwierzeck | a6dae71 | 2016-01-12 21:48:26 +0100 | [diff] [blame] | 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 | } |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 104 | |
| 105 | #endif /* _ASM_PTRACE_H */ |