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