kgdb.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AArch64 KGDB support
  4. *
  5. * Based on arch/arm/include/kgdb.h
  6. *
  7. * Copyright (C) 2013 Cavium Inc.
  8. * Author: Vijaya Kumar K <[email protected]>
  9. */
  10. #ifndef __ARM_KGDB_H
  11. #define __ARM_KGDB_H
  12. #include <linux/ptrace.h>
  13. #include <asm/debug-monitors.h>
  14. #ifndef __ASSEMBLY__
  15. static inline void arch_kgdb_breakpoint(void)
  16. {
  17. asm ("brk %0" : : "I" (KGDB_COMPILED_DBG_BRK_IMM));
  18. }
  19. extern void kgdb_handle_bus_error(void);
  20. extern int kgdb_fault_expected;
  21. #endif /* !__ASSEMBLY__ */
  22. /*
  23. * gdb remote procotol (well most versions of it) expects the following
  24. * register layout.
  25. *
  26. * General purpose regs:
  27. * r0-r30: 64 bit
  28. * sp,pc : 64 bit
  29. * pstate : 32 bit
  30. * Total: 33 + 1
  31. * FPU regs:
  32. * f0-f31: 128 bit
  33. * fpsr & fpcr: 32 bit
  34. * Total: 32 + 2
  35. *
  36. * To expand a little on the "most versions of it"... when the gdb remote
  37. * protocol for AArch64 was developed it depended on a statement in the
  38. * Architecture Reference Manual that claimed "SPSR_ELx is a 32-bit register".
  39. * and, as a result, allocated only 32-bits for the PSTATE in the remote
  40. * protocol. In fact this statement is still present in ARM DDI 0487A.i.
  41. *
  42. * Unfortunately "is a 32-bit register" has a very special meaning for
  43. * system registers. It means that "the upper bits, bits[63:32], are
  44. * RES0.". RES0 is heavily used in the ARM architecture documents as a
  45. * way to leave space for future architecture changes. So to translate a
  46. * little for people who don't spend their spare time reading ARM architecture
  47. * manuals, what "is a 32-bit register" actually means in this context is
  48. * "is a 64-bit register but one with no meaning allocated to any of the
  49. * upper 32-bits... *yet*".
  50. *
  51. * Perhaps then we should not be surprised that this has led to some
  52. * confusion. Specifically a patch, influenced by the above translation,
  53. * that extended PSTATE to 64-bit was accepted into gdb-7.7 but the patch
  54. * was reverted in gdb-7.8.1 and all later releases, when this was
  55. * discovered to be an undocumented protocol change.
  56. *
  57. * So... it is *not* wrong for us to only allocate 32-bits to PSTATE
  58. * here even though the kernel itself allocates 64-bits for the same
  59. * state. That is because this bit of code tells the kernel how the gdb
  60. * remote protocol (well most versions of it) describes the register state.
  61. *
  62. * Note that if you are using one of the versions of gdb that supports
  63. * the gdb-7.7 version of the protocol you cannot use kgdb directly
  64. * without providing a custom register description (gdb can load new
  65. * protocol descriptions at runtime).
  66. */
  67. #define _GP_REGS 33
  68. #define _FP_REGS 32
  69. #define _EXTRA_REGS 3
  70. /*
  71. * general purpose registers size in bytes.
  72. * pstate is only 4 bytes. subtract 4 bytes
  73. */
  74. #define GP_REG_BYTES (_GP_REGS * 8)
  75. #define DBG_MAX_REG_NUM (_GP_REGS + _FP_REGS + _EXTRA_REGS)
  76. /*
  77. * Size of I/O buffer for gdb packet.
  78. * considering to hold all register contents, size is set
  79. */
  80. #define BUFMAX 2048
  81. /*
  82. * Number of bytes required for gdb_regs buffer.
  83. * _GP_REGS: 8 bytes, _FP_REGS: 16 bytes and _EXTRA_REGS: 4 bytes each
  84. * GDB fails to connect for size beyond this with error
  85. * "'g' packet reply is too long"
  86. */
  87. #define NUMREGBYTES ((_GP_REGS * 8) + (_FP_REGS * 16) + \
  88. (_EXTRA_REGS * 4))
  89. #endif /* __ASM_KGDB_H */