1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Non-emulated single-stepping support (currently limited to basic integer
4 * computations) used to validate the instruction emulation infrastructure.
6 * Copyright (C) 2019 IBM Corporation
9 #include <asm/asm-offsets.h>
10 #include <asm/ppc_asm.h>
11 #include <asm/code-patching-asm.h>
12 #include <linux/errno.h>
14 /* int exec_instr(struct pt_regs *regs) */
18 * Stack frame layout (INT_FRAME_SIZE bytes)
19 * In-memory pt_regs (SP + STACK_FRAME_OVERHEAD)
20 * Scratch space (SP + 8)
25 * Allocate a new stack frame with enough space to hold the register
26 * states in an in-memory pt_regs and also create the back chain to
27 * the caller's stack frame.
29 stdu r1, -INT_FRAME_SIZE(r1)
32 * Save non-volatile GPRs on stack. This includes TOC pointer (GPR2)
33 * and local variables (GPR14 to GPR31). The register for the pt_regs
34 * parameter (GPR3) is saved additionally to ensure that the resulting
35 * register state can still be saved even if GPR3 gets overwritten
36 * when loading the initial register state for the test instruction.
37 * The stack pointer (GPR1) and the thread pointer (GPR13) are not
38 * saved as these should not be modified anyway.
44 * Save LR on stack to ensure that the return address is available
45 * even if it gets overwritten by the test instruction.
51 * Save CR on stack. For simplicity, the entire register is saved
52 * even though only fields 2 to 4 are non-volatile.
58 * Load register state for the test instruction without touching the
59 * critical non-volatile registers. The register state is passed as a
60 * pointer to a pt_regs instance.
64 /* Load LR from pt_regs */
68 /* Load CR from pt_regs */
72 /* Load XER from pt_regs */
76 /* Load GPRs from pt_regs */
82 /* Placeholder for the test instruction */
84 patch_site 1b patch__exec_instr
87 * Since GPR3 is overwritten, temporarily restore it back to its
88 * original state, i.e. the pointer to pt_regs, to ensure that the
89 * resulting register state can be saved. Before doing this, a copy
90 * of it is created in the scratch space which is used later on to
96 /* Save resulting GPR state to pt_regs */
104 /* Save resulting LR to pt_regs */
108 /* Save resulting CR to pt_regs */
112 /* Save resulting XER to pt_regs */
116 /* Restore resulting GPR3 from scratch space and save it to pt_regs */
120 /* Set return value to denote execution success */
126 /* Set return value to denote execution failure */
129 /* Restore the non-volatile GPRs from stack */
133 /* Restore LR from stack to be able to return */
137 /* Restore CR from stack */
141 /* Tear down stack frame */
142 addi r1, r1, INT_FRAME_SIZE
147 /* Setup exception table */
150 _ASM_NOKPROBE_SYMBOL(exec_instr)