blob: 6d5b781ad5180893490f009d9d9247ac89435490 [file] [log] [blame]
Paul Burton432c6ba2016-07-08 11:06:19 +01001/*
2 * Copyright (C) 2016 Imagination Technologies
Paul Burtonfb615d62017-10-25 17:04:33 -07003 * Author: Paul Burton <paul.burton@mips.com>
Paul Burton432c6ba2016-07-08 11:06:19 +01004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#ifndef __MIPS_ASM_DSEMUL_H__
12#define __MIPS_ASM_DSEMUL_H__
13
14#include <asm/break.h>
15#include <asm/inst.h>
16
17/* Break instruction with special math emu break code set */
18#define BREAK_MATH(micromips) (((micromips) ? 0x7 : 0xd) | (BRK_MEMU << 16))
19
20/* When used as a frame index, indicates the lack of a frame */
21#define BD_EMUFRAME_NONE ((int)BIT(31))
22
23struct mm_struct;
24struct pt_regs;
25struct task_struct;
26
27/**
28 * mips_dsemul() - 'Emulate' an instruction from a branch delay slot
29 * @regs: User thread register context.
30 * @ir: The instruction to be 'emulated'.
31 * @branch_pc: The PC of the branch instruction.
32 * @cont_pc: The PC to continue at following 'emulation'.
33 *
34 * Emulate or execute an arbitrary MIPS instruction within the context of
35 * the current user thread. This is used primarily to handle instructions
36 * in the delay slots of emulated branch instructions, for example FP
37 * branch instructions on systems without an FPU.
38 *
39 * Return: Zero on success, negative if ir is a NOP, signal number on failure.
40 */
41extern int mips_dsemul(struct pt_regs *regs, mips_instruction ir,
42 unsigned long branch_pc, unsigned long cont_pc);
43
44/**
45 * do_dsemulret() - Return from a delay slot 'emulation' frame
46 * @xcp: User thread register context.
47 *
48 * Call in response to the BRK_MEMU break instruction used to return to
49 * the kernel from branch delay slot 'emulation' frames following a call
50 * to mips_dsemul(). Restores the user thread PC to the value that was
51 * passed as the cpc parameter to mips_dsemul().
52 *
53 * Return: True if an emulation frame was returned from, else false.
54 */
Paul Burton42b10812018-11-07 23:14:10 +000055#ifdef CONFIG_MIPS_FP_SUPPORT
Paul Burton432c6ba2016-07-08 11:06:19 +010056extern bool do_dsemulret(struct pt_regs *xcp);
Paul Burton42b10812018-11-07 23:14:10 +000057#else
58static inline bool do_dsemulret(struct pt_regs *xcp)
59{
60 return false;
61}
62#endif
Paul Burton432c6ba2016-07-08 11:06:19 +010063
64/**
65 * dsemul_thread_cleanup() - Cleanup thread 'emulation' frame
66 * @tsk: The task structure associated with the thread
67 *
68 * If the thread @tsk has a branch delay slot 'emulation' frame
69 * allocated to it then free that frame.
70 *
71 * Return: True if a frame was freed, else false.
72 */
Paul Burton42b10812018-11-07 23:14:10 +000073#ifdef CONFIG_MIPS_FP_SUPPORT
Paul Burton432c6ba2016-07-08 11:06:19 +010074extern bool dsemul_thread_cleanup(struct task_struct *tsk);
Paul Burton42b10812018-11-07 23:14:10 +000075#else
76static inline bool dsemul_thread_cleanup(struct task_struct *tsk)
77{
78 return false;
79}
80#endif
Paul Burton432c6ba2016-07-08 11:06:19 +010081/**
82 * dsemul_thread_rollback() - Rollback from an 'emulation' frame
83 * @regs: User thread register context.
84 *
85 * If the current thread, whose register context is represented by @regs,
86 * is executing within a delay slot 'emulation' frame then exit that
87 * frame. The PC will be rolled back to the branch if the instruction
88 * that was being 'emulated' has not yet executed, or advanced to the
89 * continuation PC if it has.
90 *
91 * Return: True if a frame was exited, else false.
92 */
Paul Burton42b10812018-11-07 23:14:10 +000093#ifdef CONFIG_MIPS_FP_SUPPORT
Paul Burton432c6ba2016-07-08 11:06:19 +010094extern bool dsemul_thread_rollback(struct pt_regs *regs);
Paul Burton42b10812018-11-07 23:14:10 +000095#else
96static inline bool dsemul_thread_rollback(struct pt_regs *regs)
97{
98 return false;
99}
100#endif
Paul Burton432c6ba2016-07-08 11:06:19 +0100101
102/**
103 * dsemul_mm_cleanup() - Cleanup per-mm delay slot 'emulation' state
104 * @mm: The struct mm_struct to cleanup state for.
105 *
106 * Cleanup state for the given @mm, ensuring that any memory allocated
107 * for delay slot 'emulation' book-keeping is freed. This is to be called
108 * before @mm is freed in order to avoid memory leaks.
109 */
Paul Burton42b10812018-11-07 23:14:10 +0000110#ifdef CONFIG_MIPS_FP_SUPPORT
Paul Burton432c6ba2016-07-08 11:06:19 +0100111extern void dsemul_mm_cleanup(struct mm_struct *mm);
Paul Burton42b10812018-11-07 23:14:10 +0000112#else
113static inline void dsemul_mm_cleanup(struct mm_struct *mm)
114{
115 /* no-op */
116}
117#endif
Paul Burton432c6ba2016-07-08 11:06:19 +0100118
119#endif /* __MIPS_ASM_DSEMUL_H__ */