Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1996, 1997, 1998, 2001 by Ralf Baechle |
| 7 | */ |
| 8 | #ifndef _ASM_BRANCH_H |
| 9 | #define _ASM_BRANCH_H |
| 10 | |
| 11 | #include <asm/ptrace.h> |
Maneesh Soni | d8d4e3a | 2011-11-08 17:07:11 +0530 | [diff] [blame] | 12 | #include <asm/inst.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Leonid Yegoshin | fb6883e | 2013-03-25 13:08:40 -0500 | [diff] [blame] | 14 | extern int __isa_exception_epc(struct pt_regs *regs); |
| 15 | extern int __compute_return_epc(struct pt_regs *regs); |
| 16 | extern int __compute_return_epc_for_insn(struct pt_regs *regs, |
| 17 | union mips_instruction insn); |
| 18 | extern int __microMIPS_compute_return_epc(struct pt_regs *regs); |
Steven J. Hill | 8508488 | 2013-03-25 13:45:19 -0500 | [diff] [blame] | 19 | extern int __MIPS16e_compute_return_epc(struct pt_regs *regs); |
Leonid Yegoshin | fb6883e | 2013-03-25 13:08:40 -0500 | [diff] [blame] | 20 | |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static inline int delay_slot(struct pt_regs *regs) |
| 23 | { |
| 24 | return regs->cp0_cause & CAUSEF_BD; |
| 25 | } |
| 26 | |
| 27 | static inline unsigned long exception_epc(struct pt_regs *regs) |
| 28 | { |
Leonid Yegoshin | fb6883e | 2013-03-25 13:08:40 -0500 | [diff] [blame] | 29 | if (likely(!delay_slot(regs))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | return regs->cp0_epc; |
| 31 | |
Leonid Yegoshin | fb6883e | 2013-03-25 13:08:40 -0500 | [diff] [blame] | 32 | if (get_isa16_mode(regs->cp0_epc)) |
| 33 | return __isa_exception_epc(regs); |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | return regs->cp0_epc + 4; |
| 36 | } |
| 37 | |
Maneesh Soni | d8d4e3a | 2011-11-08 17:07:11 +0530 | [diff] [blame] | 38 | #define BRANCH_LIKELY_TAKEN 0x0001 |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static inline int compute_return_epc(struct pt_regs *regs) |
| 41 | { |
Leonid Yegoshin | fb6883e | 2013-03-25 13:08:40 -0500 | [diff] [blame] | 42 | if (get_isa16_mode(regs->cp0_epc)) { |
| 43 | if (cpu_has_mmips) |
| 44 | return __microMIPS_compute_return_epc(regs); |
Steven J. Hill | 8508488 | 2013-03-25 13:45:19 -0500 | [diff] [blame] | 45 | if (cpu_has_mips16) |
| 46 | return __MIPS16e_compute_return_epc(regs); |
Leonid Yegoshin | fb6883e | 2013-03-25 13:08:40 -0500 | [diff] [blame] | 47 | return regs->cp0_epc; |
| 48 | } |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | if (!delay_slot(regs)) { |
| 51 | regs->cp0_epc += 4; |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | return __compute_return_epc(regs); |
| 56 | } |
| 57 | |
Steven J. Hill | 8508488 | 2013-03-25 13:45:19 -0500 | [diff] [blame] | 58 | static inline int MIPS16e_compute_return_epc(struct pt_regs *regs, |
| 59 | union mips16e_instruction *inst) |
| 60 | { |
| 61 | if (likely(!delay_slot(regs))) { |
| 62 | if (inst->ri.opcode == MIPS16e_extend_op) { |
| 63 | regs->cp0_epc += 4; |
| 64 | return 0; |
| 65 | } |
| 66 | regs->cp0_epc += 2; |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | return __MIPS16e_compute_return_epc(regs); |
| 71 | } |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #endif /* _ASM_BRANCH_H */ |