gdbstub.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * LM32 gdb server stub
  3. *
  4. * Copyright (c) 2003-2005 Fabrice Bellard
  5. * Copyright (c) 2013 SUSE LINUX Products GmbH
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "config.h"
  21. #include "qemu-common.h"
  22. #include "exec/gdbstub.h"
  23. #include "hw/lm32/lm32_pic.h"
  24. int lm32_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
  25. {
  26. LM32CPU *cpu = LM32_CPU(cs);
  27. CPULM32State *env = &cpu->env;
  28. if (n < 32) {
  29. return gdb_get_reg32(mem_buf, env->regs[n]);
  30. } else {
  31. switch (n) {
  32. case 32:
  33. return gdb_get_reg32(mem_buf, env->pc);
  34. /* FIXME: put in right exception ID */
  35. case 33:
  36. return gdb_get_reg32(mem_buf, 0);
  37. case 34:
  38. return gdb_get_reg32(mem_buf, env->eba);
  39. case 35:
  40. return gdb_get_reg32(mem_buf, env->deba);
  41. case 36:
  42. return gdb_get_reg32(mem_buf, env->ie);
  43. case 37:
  44. return gdb_get_reg32(mem_buf, lm32_pic_get_im(env->pic_state));
  45. case 38:
  46. return gdb_get_reg32(mem_buf, lm32_pic_get_ip(env->pic_state));
  47. }
  48. }
  49. return 0;
  50. }
  51. int lm32_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
  52. {
  53. LM32CPU *cpu = LM32_CPU(cs);
  54. CPUClass *cc = CPU_GET_CLASS(cs);
  55. CPULM32State *env = &cpu->env;
  56. uint32_t tmp;
  57. if (n > cc->gdb_num_core_regs) {
  58. return 0;
  59. }
  60. tmp = ldl_p(mem_buf);
  61. if (n < 32) {
  62. env->regs[n] = tmp;
  63. } else {
  64. switch (n) {
  65. case 32:
  66. env->pc = tmp;
  67. break;
  68. case 34:
  69. env->eba = tmp;
  70. break;
  71. case 35:
  72. env->deba = tmp;
  73. break;
  74. case 36:
  75. env->ie = tmp;
  76. break;
  77. case 37:
  78. lm32_pic_set_im(env->pic_state, tmp);
  79. break;
  80. case 38:
  81. lm32_pic_set_ip(env->pic_state, tmp);
  82. break;
  83. }
  84. }
  85. return 4;
  86. }