Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Imagination Technologies |
Paul Burton | fb615d6 | 2017-10-25 17:04:33 -0700 | [diff] [blame] | 4 | * Author: Paul Burton <paul.burton@mips.com> |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __MIPS_ASM_DSEMUL_H__ |
| 8 | #define __MIPS_ASM_DSEMUL_H__ |
| 9 | |
| 10 | #include <asm/break.h> |
| 11 | #include <asm/inst.h> |
| 12 | |
| 13 | /* Break instruction with special math emu break code set */ |
| 14 | #define BREAK_MATH(micromips) (((micromips) ? 0x7 : 0xd) | (BRK_MEMU << 16)) |
| 15 | |
| 16 | /* When used as a frame index, indicates the lack of a frame */ |
| 17 | #define BD_EMUFRAME_NONE ((int)BIT(31)) |
| 18 | |
| 19 | struct mm_struct; |
| 20 | struct pt_regs; |
| 21 | struct task_struct; |
| 22 | |
| 23 | /** |
| 24 | * mips_dsemul() - 'Emulate' an instruction from a branch delay slot |
| 25 | * @regs: User thread register context. |
| 26 | * @ir: The instruction to be 'emulated'. |
| 27 | * @branch_pc: The PC of the branch instruction. |
| 28 | * @cont_pc: The PC to continue at following 'emulation'. |
| 29 | * |
| 30 | * Emulate or execute an arbitrary MIPS instruction within the context of |
| 31 | * the current user thread. This is used primarily to handle instructions |
| 32 | * in the delay slots of emulated branch instructions, for example FP |
| 33 | * branch instructions on systems without an FPU. |
| 34 | * |
| 35 | * Return: Zero on success, negative if ir is a NOP, signal number on failure. |
| 36 | */ |
| 37 | extern int mips_dsemul(struct pt_regs *regs, mips_instruction ir, |
| 38 | unsigned long branch_pc, unsigned long cont_pc); |
| 39 | |
| 40 | /** |
| 41 | * do_dsemulret() - Return from a delay slot 'emulation' frame |
| 42 | * @xcp: User thread register context. |
| 43 | * |
| 44 | * Call in response to the BRK_MEMU break instruction used to return to |
| 45 | * the kernel from branch delay slot 'emulation' frames following a call |
| 46 | * to mips_dsemul(). Restores the user thread PC to the value that was |
| 47 | * passed as the cpc parameter to mips_dsemul(). |
| 48 | * |
| 49 | * Return: True if an emulation frame was returned from, else false. |
| 50 | */ |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 51 | #ifdef CONFIG_MIPS_FP_SUPPORT |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 52 | extern bool do_dsemulret(struct pt_regs *xcp); |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 53 | #else |
| 54 | static inline bool do_dsemulret(struct pt_regs *xcp) |
| 55 | { |
| 56 | return false; |
| 57 | } |
| 58 | #endif |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * dsemul_thread_cleanup() - Cleanup thread 'emulation' frame |
| 62 | * @tsk: The task structure associated with the thread |
| 63 | * |
| 64 | * If the thread @tsk has a branch delay slot 'emulation' frame |
| 65 | * allocated to it then free that frame. |
| 66 | * |
| 67 | * Return: True if a frame was freed, else false. |
| 68 | */ |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 69 | #ifdef CONFIG_MIPS_FP_SUPPORT |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 70 | extern bool dsemul_thread_cleanup(struct task_struct *tsk); |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 71 | #else |
| 72 | static inline bool dsemul_thread_cleanup(struct task_struct *tsk) |
| 73 | { |
| 74 | return false; |
| 75 | } |
| 76 | #endif |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 77 | /** |
| 78 | * dsemul_thread_rollback() - Rollback from an 'emulation' frame |
| 79 | * @regs: User thread register context. |
| 80 | * |
| 81 | * If the current thread, whose register context is represented by @regs, |
| 82 | * is executing within a delay slot 'emulation' frame then exit that |
| 83 | * frame. The PC will be rolled back to the branch if the instruction |
| 84 | * that was being 'emulated' has not yet executed, or advanced to the |
| 85 | * continuation PC if it has. |
| 86 | * |
| 87 | * Return: True if a frame was exited, else false. |
| 88 | */ |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 89 | #ifdef CONFIG_MIPS_FP_SUPPORT |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 90 | extern bool dsemul_thread_rollback(struct pt_regs *regs); |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 91 | #else |
| 92 | static inline bool dsemul_thread_rollback(struct pt_regs *regs) |
| 93 | { |
| 94 | return false; |
| 95 | } |
| 96 | #endif |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * dsemul_mm_cleanup() - Cleanup per-mm delay slot 'emulation' state |
| 100 | * @mm: The struct mm_struct to cleanup state for. |
| 101 | * |
| 102 | * Cleanup state for the given @mm, ensuring that any memory allocated |
| 103 | * for delay slot 'emulation' book-keeping is freed. This is to be called |
| 104 | * before @mm is freed in order to avoid memory leaks. |
| 105 | */ |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 106 | #ifdef CONFIG_MIPS_FP_SUPPORT |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 107 | extern void dsemul_mm_cleanup(struct mm_struct *mm); |
Paul Burton | 42b1081 | 2018-11-07 23:14:10 +0000 | [diff] [blame] | 108 | #else |
| 109 | static inline void dsemul_mm_cleanup(struct mm_struct *mm) |
| 110 | { |
| 111 | /* no-op */ |
| 112 | } |
| 113 | #endif |
Paul Burton | 432c6ba | 2016-07-08 11:06:19 +0100 | [diff] [blame] | 114 | |
| 115 | #endif /* __MIPS_ASM_DSEMUL_H__ */ |