Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * SuperH 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 | */ |
Peter Maydell | 9d4c994 | 2016-01-26 18:17:20 +0000 | [diff] [blame] | 20 | #include "qemu/osdep.h" |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 21 | #include "qemu-common.h" |
Paolo Bonzini | 33c1187 | 2016-03-15 16:58:45 +0100 | [diff] [blame] | 22 | #include "cpu.h" |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 23 | #include "exec/gdbstub.h" |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 24 | |
| 25 | /* Hint: Use "set architecture sh4" in GDB to see fpu registers */ |
| 26 | /* FIXME: We should use XML for this. */ |
| 27 | |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 28 | int superh_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 29 | { |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 30 | SuperHCPU *cpu = SUPERH_CPU(cs); |
| 31 | CPUSH4State *env = &cpu->env; |
| 32 | |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 33 | switch (n) { |
| 34 | case 0 ... 7: |
Aurelien Jarno | 5ed9a25 | 2015-05-25 01:28:56 +0200 | [diff] [blame] | 35 | if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) { |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 36 | return gdb_get_regl(mem_buf, env->gregs[n + 16]); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 37 | } else { |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 38 | return gdb_get_regl(mem_buf, env->gregs[n]); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 39 | } |
| 40 | case 8 ... 15: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 41 | return gdb_get_regl(mem_buf, env->gregs[n]); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 42 | case 16: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 43 | return gdb_get_regl(mem_buf, env->pc); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 44 | case 17: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 45 | return gdb_get_regl(mem_buf, env->pr); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 46 | case 18: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 47 | return gdb_get_regl(mem_buf, env->gbr); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 48 | case 19: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 49 | return gdb_get_regl(mem_buf, env->vbr); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 50 | case 20: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 51 | return gdb_get_regl(mem_buf, env->mach); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 52 | case 21: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 53 | return gdb_get_regl(mem_buf, env->macl); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 54 | case 22: |
Aurelien Jarno | 3408694 | 2015-05-25 01:28:56 +0200 | [diff] [blame] | 55 | return gdb_get_regl(mem_buf, cpu_read_sr(env)); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 56 | case 23: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 57 | return gdb_get_regl(mem_buf, env->fpul); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 58 | case 24: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 59 | return gdb_get_regl(mem_buf, env->fpscr); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 60 | case 25 ... 40: |
| 61 | if (env->fpscr & FPSCR_FR) { |
| 62 | stfl_p(mem_buf, env->fregs[n - 9]); |
| 63 | } else { |
| 64 | stfl_p(mem_buf, env->fregs[n - 25]); |
| 65 | } |
| 66 | return 4; |
| 67 | case 41: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 68 | return gdb_get_regl(mem_buf, env->ssr); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 69 | case 42: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 70 | return gdb_get_regl(mem_buf, env->spc); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 71 | case 43 ... 50: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 72 | return gdb_get_regl(mem_buf, env->gregs[n - 43]); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 73 | case 51 ... 58: |
Andreas Färber | 986a299 | 2013-07-07 13:05:05 +0200 | [diff] [blame] | 74 | return gdb_get_regl(mem_buf, env->gregs[n - (51 - 16)]); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 80 | int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 81 | { |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 82 | SuperHCPU *cpu = SUPERH_CPU(cs); |
| 83 | CPUSH4State *env = &cpu->env; |
| 84 | |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 85 | switch (n) { |
| 86 | case 0 ... 7: |
Aurelien Jarno | 5ed9a25 | 2015-05-25 01:28:56 +0200 | [diff] [blame] | 87 | if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) { |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 88 | env->gregs[n + 16] = ldl_p(mem_buf); |
| 89 | } else { |
| 90 | env->gregs[n] = ldl_p(mem_buf); |
| 91 | } |
| 92 | break; |
| 93 | case 8 ... 15: |
| 94 | env->gregs[n] = ldl_p(mem_buf); |
| 95 | break; |
| 96 | case 16: |
| 97 | env->pc = ldl_p(mem_buf); |
| 98 | break; |
| 99 | case 17: |
| 100 | env->pr = ldl_p(mem_buf); |
| 101 | break; |
| 102 | case 18: |
| 103 | env->gbr = ldl_p(mem_buf); |
| 104 | break; |
| 105 | case 19: |
| 106 | env->vbr = ldl_p(mem_buf); |
| 107 | break; |
| 108 | case 20: |
| 109 | env->mach = ldl_p(mem_buf); |
| 110 | break; |
| 111 | case 21: |
| 112 | env->macl = ldl_p(mem_buf); |
| 113 | break; |
| 114 | case 22: |
Aurelien Jarno | 3408694 | 2015-05-25 01:28:56 +0200 | [diff] [blame] | 115 | cpu_write_sr(env, ldl_p(mem_buf)); |
Andreas Färber | 2f93773 | 2013-07-07 12:42:52 +0200 | [diff] [blame] | 116 | break; |
| 117 | case 23: |
| 118 | env->fpul = ldl_p(mem_buf); |
| 119 | break; |
| 120 | case 24: |
| 121 | env->fpscr = ldl_p(mem_buf); |
| 122 | break; |
| 123 | case 25 ... 40: |
| 124 | if (env->fpscr & FPSCR_FR) { |
| 125 | env->fregs[n - 9] = ldfl_p(mem_buf); |
| 126 | } else { |
| 127 | env->fregs[n - 25] = ldfl_p(mem_buf); |
| 128 | } |
| 129 | break; |
| 130 | case 41: |
| 131 | env->ssr = ldl_p(mem_buf); |
| 132 | break; |
| 133 | case 42: |
| 134 | env->spc = ldl_p(mem_buf); |
| 135 | break; |
| 136 | case 43 ... 50: |
| 137 | env->gregs[n - 43] = ldl_p(mem_buf); |
| 138 | break; |
| 139 | case 51 ... 58: |
| 140 | env->gregs[n - (51 - 16)] = ldl_p(mem_buf); |
| 141 | break; |
| 142 | default: |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | return 4; |
| 147 | } |