powerpc: Support prefixed instructions in alignment handler
[linux-2.6-block.git] / arch / powerpc / include / asm / sstep.h
CommitLineData
2874c5fd 1/* SPDX-License-Identifier: GPL-2.0-or-later */
1da177e4
LT
2/*
3 * Copyright (C) 2004 Paul Mackerras <paulus@au.ibm.com>, IBM
1da177e4 4 */
94afd069 5#include <asm/inst.h>
1da177e4
LT
6
7struct pt_regs;
8
9/*
10 * We don't allow single-stepping an mtmsrd that would clear
11 * MSR_RI, since that would make the exception unrecoverable.
12 * Since we need to single-step to proceed from a breakpoint,
13 * we don't allow putting a breakpoint on an mtmsrd instruction.
14 * Similarly we don't allow breakpoints on rfid instructions.
15 * These macros tell us if an instruction is a mtmsrd or rfid.
c032524f
PM
16 * Note that IS_MTMSRD returns true for both an mtmsr (32-bit)
17 * and an mtmsrd (64-bit).
1da177e4 18 */
777e26f0
JN
19#define IS_MTMSRD(instr) ((ppc_inst_val(instr) & 0xfc0007be) == 0x7c000124)
20#define IS_RFID(instr) ((ppc_inst_val(instr) & 0xfc0007fe) == 0x4c000024)
21#define IS_RFI(instr) ((ppc_inst_val(instr) & 0xfc0007fe) == 0x4c000064)
1da177e4 22
be96f633
PM
23enum instruction_type {
24 COMPUTE, /* arith/logical/CR op, etc. */
d120cdbc 25 LOAD, /* load and store types need to be contiguous */
be96f633
PM
26 LOAD_MULTI,
27 LOAD_FP,
28 LOAD_VMX,
29 LOAD_VSX,
30 STORE,
31 STORE_MULTI,
32 STORE_FP,
33 STORE_VMX,
34 STORE_VSX,
35 LARX,
36 STCX,
37 BRANCH,
38 MFSPR,
39 MTSPR,
40 CACHEOP,
41 BARRIER,
42 SYSCALL,
43 MFMSR,
44 MTMSR,
45 RFI,
46 INTERRUPT,
47 UNKNOWN
48};
49
50#define INSTR_TYPE_MASK 0x1f
51
d120cdbc
PM
52#define OP_IS_LOAD_STORE(type) (LOAD <= (type) && (type) <= STCX)
53
3cdfcbfd
PM
54/* Compute flags, ORed in with type */
55#define SETREG 0x20
56#define SETCC 0x40
57#define SETXER 0x80
58
59/* Branch flags, ORed in with type */
60#define SETLK 0x20
61#define BRTAKEN 0x40
62#define DECCTR 0x80
63
be96f633
PM
64/* Load/store flags, ORed in with type */
65#define SIGNEXT 0x20
66#define UPDATE 0x40 /* matches bit in opcode 31 instructions */
67#define BYTEREV 0x80
d2b65ac6 68#define FPCONV 0x100
be96f633 69
3cdfcbfd
PM
70/* Barrier type field, ORed in with type */
71#define BARRIER_MASK 0xe0
72#define BARRIER_SYNC 0x00
73#define BARRIER_ISYNC 0x20
74#define BARRIER_EIEIO 0x40
75#define BARRIER_LWSYNC 0x60
76#define BARRIER_PTESYNC 0x80
77
be96f633
PM
78/* Cacheop values, ORed in with type */
79#define CACHEOP_MASK 0x700
80#define DCBST 0
81#define DCBF 0x100
82#define DCBTST 0x200
83#define DCBT 0x300
cf87c3f6 84#define ICBI 0x400
b2543f7b 85#define DCBZ 0x500
be96f633 86
350779a2
PM
87/* VSX flags values */
88#define VSX_FPCONV 1 /* do floating point SP/DP conversion */
89#define VSX_SPLAT 2 /* store loaded value into all elements */
90#define VSX_LDLEFT 4 /* load VSX register from left */
91#define VSX_CHECK_VEC 8 /* check MSR_VEC not MSR_VSX for reg >= 32 */
92
be96f633 93/* Size field in type word */
d2b65ac6
PM
94#define SIZE(n) ((n) << 12)
95#define GETSIZE(w) ((w) >> 12)
be96f633 96
e6684d07
RB
97#define GETTYPE(t) ((t) & INSTR_TYPE_MASK)
98
be96f633
PM
99#define MKOP(t, f, s) ((t) | (f) | SIZE(s))
100
101struct instruction_op {
102 int type;
103 int reg;
104 unsigned long val;
105 /* For LOAD/STORE/LARX/STCX */
106 unsigned long ea;
107 int update_reg;
108 /* For MFSPR */
109 int spr;
3cdfcbfd
PM
110 u32 ccval;
111 u32 xerval;
350779a2
PM
112 u8 element_size; /* for VSX/VMX loads/stores */
113 u8 vsx_flags;
114};
115
116union vsx_reg {
117 u8 b[16];
118 u16 h[8];
119 u32 w[4];
120 unsigned long d[2];
121 float fp[4];
122 double dp[2];
c22435a5 123 __vector128 v;
be96f633
PM
124};
125
3cdfcbfd
PM
126/*
127 * Decode an instruction, and return information about it in *op
128 * without changing *regs.
129 *
130 * Return value is 1 if the instruction can be emulated just by
131 * updating *regs with the information in *op, -1 if we need the
132 * GPRs but *regs doesn't contain the full register set, or 0
133 * otherwise.
134 */
135extern int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
94afd069 136 struct ppc_inst instr);
3cdfcbfd
PM
137
138/*
139 * Emulate an instruction that can be executed just by updating
140 * fields in *regs.
141 */
142void emulate_update_regs(struct pt_regs *reg, struct instruction_op *op);
143
144/*
145 * Emulate instructions that cause a transfer of control,
146 * arithmetic/logical instructions, loads and stores,
147 * cache operations and barriers.
148 *
149 * Returns 1 if the instruction was emulated successfully,
150 * 0 if it could not be emulated, or -1 for an instruction that
151 * should not be emulated (rfid, mtmsrd clearing MSR_RI, etc.).
152 */
94afd069 153extern int emulate_step(struct pt_regs *regs, struct ppc_inst instr);
3cdfcbfd 154
a53d5182
PM
155/*
156 * Emulate a load or store instruction by reading/writing the
157 * memory of the current process. FP/VMX/VSX registers are assumed
158 * to hold live values if the appropriate enable bit in regs->msr is
159 * set; otherwise this will use the saved values in the thread struct
160 * for user-mode accesses.
161 */
162extern int emulate_loadstore(struct pt_regs *regs, struct instruction_op *op);
163
350779a2 164extern void emulate_vsx_load(struct instruction_op *op, union vsx_reg *reg,
d955189a
PM
165 const void *mem, bool cross_endian);
166extern void emulate_vsx_store(struct instruction_op *op,
167 const union vsx_reg *reg, void *mem,
168 bool cross_endian);
b2543f7b 169extern int emulate_dcbz(unsigned long ea, struct pt_regs *regs);