blob: cb88d6d4f9f9279d90a08dcdb5aad881f8f64e3a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
wdenk4fc95692003-02-28 00:49:47 +00002/*
Shinya Kuribayashic824af82008-03-25 11:43:17 +09003 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle
4 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
wdenk4fc95692003-02-28 00:49:47 +00005 */
6#ifndef _ASM_PTRACE_H
7#define _ASM_PTRACE_H
8
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01009#include <linux/compiler.h>
10#include <linux/types.h>
11#include <asm/isadep.h>
wdenk4fc95692003-02-28 00:49:47 +000012
wdenk4fc95692003-02-28 00:49:47 +000013/*
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 Schwierzecka6dae712016-01-12 21:48:26 +010016 *
17 * If you add a register here, also add it to regoffset_table[] in
18 * arch/mips/kernel/ptrace.c.
wdenk4fc95692003-02-28 00:49:47 +000019 */
20struct pt_regs {
Shinya Kuribayashic824af82008-03-25 11:43:17 +090021#ifdef CONFIG_32BIT
wdenk4fc95692003-02-28 00:49:47 +000022 /* Pad bytes for argument save space on the stack. */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010023 unsigned long pad0[8];
Shinya Kuribayashic824af82008-03-25 11:43:17 +090024#endif
wdenk4fc95692003-02-28 00:49:47 +000025
26 /* Saved main processor registers. */
27 unsigned long regs[32];
28
Shinya Kuribayashic824af82008-03-25 11:43:17 +090029 /* Saved special registers. */
30 unsigned long cp0_status;
wdenk4fc95692003-02-28 00:49:47 +000031 unsigned long hi;
Shinya Kuribayashic824af82008-03-25 11:43:17 +090032 unsigned long lo;
33#ifdef CONFIG_CPU_HAS_SMARTMIPS
34 unsigned long acx;
35#endif
wdenk4fc95692003-02-28 00:49:47 +000036 unsigned long cp0_badvaddr;
wdenk4fc95692003-02-28 00:49:47 +000037 unsigned long cp0_cause;
Shinya Kuribayashic824af82008-03-25 11:43:17 +090038 unsigned long cp0_epc;
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010039#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);
wdenk4fc95692003-02-28 00:49:47 +000045
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010046static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
47{
48 return regs->regs[31];
49}
wdenk4fc95692003-02-28 00:49:47 +000050
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010051/*
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 */
wdenk4fc95692003-02-28 00:49:47 +000055
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010056static inline void instruction_pointer_set(struct pt_regs *regs,
57 unsigned long val)
58{
59 regs->cp0_epc = val;
60}
wdenk4fc95692003-02-28 00:49:47 +000061
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010062/* Query offset/name of register from its name/offset */
63extern int regs_query_register_offset(const char *name);
64#define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
wdenk4fc95692003-02-28 00:49:47 +000065
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010066/**
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 */
75static 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;
wdenk4fc95692003-02-28 00:49:47 +000080
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010081 return *(unsigned long *)((unsigned long)regs + offset);
82}
Shinya Kuribayashic824af82008-03-25 11:43:17 +090083
wdenk4fc95692003-02-28 00:49:47 +000084/*
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 Kuribayashic824af82008-03-25 11:43:17 +090090#define profile_pc(regs) instruction_pointer(regs)
wdenk4fc95692003-02-28 00:49:47 +000091
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010092/* Helpers for working with the user stack pointer */
93
94static inline unsigned long user_stack_pointer(struct pt_regs *regs)
95{
96 return regs->regs[29];
97}
98
99static inline void user_stack_pointer_set(struct pt_regs *regs,
100 unsigned long val)
101{
102 regs->regs[29] = val;
103}
wdenk4fc95692003-02-28 00:49:47 +0000104
105#endif /* _ASM_PTRACE_H */