kgdb.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2023 Loongson Technology Corporation Limited
  4. */
  5. #ifndef _ASM_LOONGARCH_KGDB_H
  6. #define _ASM_LOONGARCH_KGDB_H
  7. #define GDB_SIZEOF_REG sizeof(u64)
  8. /* gdb remote procotol expects the following register layout. */
  9. /*
  10. * General purpose registers:
  11. * r0-r31: 64 bit
  12. * orig_a0: 64 bit
  13. * pc : 64 bit
  14. * csr_badvaddr: 64 bit
  15. */
  16. #define DBG_PT_REGS_BASE 0
  17. #define DBG_PT_REGS_NUM 35
  18. #define DBG_PT_REGS_END (DBG_PT_REGS_BASE + DBG_PT_REGS_NUM - 1)
  19. /*
  20. * Floating point registers:
  21. * f0-f31: 64 bit
  22. */
  23. #define DBG_FPR_BASE (DBG_PT_REGS_END + 1)
  24. #define DBG_FPR_NUM 32
  25. #define DBG_FPR_END (DBG_FPR_BASE + DBG_FPR_NUM - 1)
  26. /*
  27. * Condition Flag registers:
  28. * fcc0-fcc8: 8 bit
  29. */
  30. #define DBG_FCC_BASE (DBG_FPR_END + 1)
  31. #define DBG_FCC_NUM 8
  32. #define DBG_FCC_END (DBG_FCC_BASE + DBG_FCC_NUM - 1)
  33. /*
  34. * Floating-point Control and Status registers:
  35. * fcsr: 32 bit
  36. */
  37. #define DBG_FCSR_NUM 1
  38. #define DBG_FCSR (DBG_FCC_END + 1)
  39. #define DBG_MAX_REG_NUM (DBG_FCSR + 1)
  40. /*
  41. * Size of I/O buffer for gdb packet.
  42. * considering to hold all register contents, size is set
  43. */
  44. #define BUFMAX 2048
  45. /*
  46. * Number of bytes required for gdb_regs buffer.
  47. * PT_REGS and FPR: 8 bytes; FCSR: 4 bytes; FCC: 1 bytes.
  48. * GDB fails to connect for size beyond this with error
  49. * "'g' packet reply is too long"
  50. */
  51. #define NUMREGBYTES ((DBG_PT_REGS_NUM + DBG_FPR_NUM) * GDB_SIZEOF_REG + DBG_FCC_NUM * 1 + DBG_FCSR_NUM * 4)
  52. #define BREAK_INSTR_SIZE 4
  53. #define CACHE_FLUSH_IS_SAFE 0
  54. /* Register numbers of various important registers. */
  55. enum dbg_loongarch_regnum {
  56. DBG_LOONGARCH_ZERO = 0,
  57. DBG_LOONGARCH_RA,
  58. DBG_LOONGARCH_TP,
  59. DBG_LOONGARCH_SP,
  60. DBG_LOONGARCH_A0,
  61. DBG_LOONGARCH_FP = 22,
  62. DBG_LOONGARCH_S0,
  63. DBG_LOONGARCH_S1,
  64. DBG_LOONGARCH_S2,
  65. DBG_LOONGARCH_S3,
  66. DBG_LOONGARCH_S4,
  67. DBG_LOONGARCH_S5,
  68. DBG_LOONGARCH_S6,
  69. DBG_LOONGARCH_S7,
  70. DBG_LOONGARCH_S8,
  71. DBG_LOONGARCH_ORIG_A0,
  72. DBG_LOONGARCH_PC,
  73. DBG_LOONGARCH_BADV
  74. };
  75. void kgdb_breakinst(void);
  76. void arch_kgdb_breakpoint(void);
  77. #ifdef CONFIG_KGDB
  78. bool kgdb_breakpoint_handler(struct pt_regs *regs);
  79. #else /* !CONFIG_KGDB */
  80. static inline bool kgdb_breakpoint_handler(struct pt_regs *regs) { return false; }
  81. #endif /* CONFIG_KGDB */
  82. #endif /* __ASM_KGDB_H_ */