branch.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include <asm/cpu-features.h>
  11. #include <asm/mipsregs.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/inst.h>
  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);
  19. extern int __MIPS16e_compute_return_epc(struct pt_regs *regs);
  20. /*
  21. * microMIPS bitfields
  22. */
  23. #define MM_POOL32A_MINOR_MASK 0x3f
  24. #define MM_POOL32A_MINOR_SHIFT 0x6
  25. #define MM_MIPS32_COND_FC 0x30
  26. extern int __mm_isBranchInstr(struct pt_regs *regs,
  27. struct mm_decoded_insn dec_insn, unsigned long *contpc);
  28. static inline int mm_isBranchInstr(struct pt_regs *regs,
  29. struct mm_decoded_insn dec_insn, unsigned long *contpc)
  30. {
  31. if (!cpu_has_mmips)
  32. return 0;
  33. return __mm_isBranchInstr(regs, dec_insn, contpc);
  34. }
  35. static inline int delay_slot(struct pt_regs *regs)
  36. {
  37. return regs->cp0_cause & CAUSEF_BD;
  38. }
  39. static inline void clear_delay_slot(struct pt_regs *regs)
  40. {
  41. regs->cp0_cause &= ~CAUSEF_BD;
  42. }
  43. static inline void set_delay_slot(struct pt_regs *regs)
  44. {
  45. regs->cp0_cause |= CAUSEF_BD;
  46. }
  47. static inline unsigned long exception_epc(struct pt_regs *regs)
  48. {
  49. if (likely(!delay_slot(regs)))
  50. return regs->cp0_epc;
  51. if (get_isa16_mode(regs->cp0_epc))
  52. return __isa_exception_epc(regs);
  53. return regs->cp0_epc + 4;
  54. }
  55. #define BRANCH_LIKELY_TAKEN 0x0001
  56. static inline int compute_return_epc(struct pt_regs *regs)
  57. {
  58. if (get_isa16_mode(regs->cp0_epc)) {
  59. if (cpu_has_mmips)
  60. return __microMIPS_compute_return_epc(regs);
  61. if (cpu_has_mips16)
  62. return __MIPS16e_compute_return_epc(regs);
  63. } else if (!delay_slot(regs)) {
  64. regs->cp0_epc += 4;
  65. return 0;
  66. }
  67. return __compute_return_epc(regs);
  68. }
  69. static inline int MIPS16e_compute_return_epc(struct pt_regs *regs,
  70. union mips16e_instruction *inst)
  71. {
  72. if (likely(!delay_slot(regs))) {
  73. if (inst->ri.opcode == MIPS16e_extend_op) {
  74. regs->cp0_epc += 4;
  75. return 0;
  76. }
  77. regs->cp0_epc += 2;
  78. return 0;
  79. }
  80. return __MIPS16e_compute_return_epc(regs);
  81. }
  82. #endif /* _ASM_BRANCH_H */