gdb_machdep.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 2006 Marcel Moolenaar
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include <sys/cdefs.h>
  29. __FBSDID("$FreeBSD$");
  30. #include <sys/param.h>
  31. #include <sys/systm.h>
  32. #include <sys/kdb.h>
  33. #include <sys/kernel.h>
  34. #include <sys/proc.h>
  35. #include <sys/signal.h>
  36. #include <machine/gdb_machdep.h>
  37. #include <machine/pcb.h>
  38. #include <machine/reg.h>
  39. #include <machine/hid.h>
  40. #include <machine/spr.h>
  41. #include <machine/trap.h>
  42. #include <gdb/gdb.h>
  43. #include <gdb/gdb_int.h>
  44. extern vm_offset_t __startkernel;
  45. void *
  46. gdb_cpu_getreg(int regnum, size_t *regsz)
  47. {
  48. *regsz = gdb_cpu_regsz(regnum);
  49. if (kdb_thread == curthread) {
  50. if (regnum == 0 || (regnum >= 2 && regnum <= 31))
  51. return (kdb_frame->fixreg + regnum);
  52. if (regnum == 64)
  53. return (&kdb_frame->srr0);
  54. if (regnum == 67)
  55. return (&kdb_frame->lr);
  56. }
  57. if (regnum == 1)
  58. return (&kdb_thrctx->pcb_sp);
  59. if (regnum == 2 && *regsz == 8)
  60. return (&kdb_thrctx->pcb_toc);
  61. if (regnum >= 12 && regnum <= 31)
  62. return (kdb_thrctx->pcb_context + (regnum - 12));
  63. if (regnum == 64)
  64. return (&kdb_thrctx->pcb_lr);
  65. return (NULL);
  66. }
  67. void
  68. gdb_cpu_setreg(int regnum, void *val)
  69. {
  70. switch (regnum) {
  71. case GDB_REG_PC:
  72. break;
  73. }
  74. }
  75. int
  76. gdb_cpu_signal(int vector, int dummy __unused)
  77. {
  78. #if defined(BOOKE)
  79. if (vector == EXC_DEBUG || vector == EXC_PGM)
  80. return (SIGTRAP);
  81. #else
  82. if (vector == EXC_TRC || vector == EXC_RUNMODETRC)
  83. return (SIGTRAP);
  84. #endif
  85. return (SIGEMT);
  86. }
  87. void
  88. gdb_cpu_do_offsets(void)
  89. {
  90. /*
  91. * On PowerPC, .text starts at KERNBASE + SIZEOF_HEADERS and
  92. * text segment at KERNBASE - SIZEOF_HEADERS.
  93. * On PowerPC64, .text starts at KERNBASE and text segment at
  94. * KERNBASE - 0x100.
  95. * In both cases, the text segment offset is aligned to 64KB.
  96. *
  97. * The __startkernel variable holds the relocated KERNBASE offset.
  98. * Thus, as long as SIZEOF_HEADERS doesn't get bigger than 0x100
  99. * (which would lead to other issues), aligning __startkernel to
  100. * 64KB gives the text segment offset.
  101. *
  102. * TODO: Add DataSeg to response. On PowerPC64 all sections reside
  103. * in a single LOAD segment, but on PowerPC modifiable data reside
  104. * in a separate segment, that GDB should also relocate.
  105. */
  106. gdb_tx_begin(0);
  107. gdb_tx_str("TextSeg=");
  108. gdb_tx_varhex(__startkernel & ~0xffff);
  109. gdb_tx_end();
  110. }