]> git.proxmox.com Git - qemu.git/blob - target-cris/gdbstub.c
cpu: Introduce CPUClass::gdb_{read,write}_register()
[qemu.git] / target-cris / gdbstub.c
1 /*
2 * CRIS 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
24 static int
25 read_register_crisv10(CPUCRISState *env, uint8_t *mem_buf, int n)
26 {
27 if (n < 15) {
28 return gdb_get_reg32(mem_buf, env->regs[n]);
29 }
30
31 if (n == 15) {
32 return gdb_get_reg32(mem_buf, env->pc);
33 }
34
35 if (n < 32) {
36 switch (n) {
37 case 16:
38 return gdb_get_reg8(mem_buf, env->pregs[n - 16]);
39 case 17:
40 return gdb_get_reg8(mem_buf, env->pregs[n - 16]);
41 case 20:
42 case 21:
43 return gdb_get_reg16(mem_buf, env->pregs[n - 16]);
44 default:
45 if (n >= 23) {
46 return gdb_get_reg32(mem_buf, env->pregs[n - 16]);
47 }
48 break;
49 }
50 }
51 return 0;
52 }
53
54 int cris_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
55 {
56 CRISCPU *cpu = CRIS_CPU(cs);
57 CPUCRISState *env = &cpu->env;
58 uint8_t srs;
59
60 if (env->pregs[PR_VR] < 32) {
61 return read_register_crisv10(env, mem_buf, n);
62 }
63
64 srs = env->pregs[PR_SRS];
65 if (n < 16) {
66 return gdb_get_reg32(mem_buf, env->regs[n]);
67 }
68
69 if (n >= 21 && n < 32) {
70 return gdb_get_reg32(mem_buf, env->pregs[n - 16]);
71 }
72 if (n >= 33 && n < 49) {
73 return gdb_get_reg32(mem_buf, env->sregs[srs][n - 33]);
74 }
75 switch (n) {
76 case 16:
77 return gdb_get_reg8(mem_buf, env->pregs[0]);
78 case 17:
79 return gdb_get_reg8(mem_buf, env->pregs[1]);
80 case 18:
81 return gdb_get_reg32(mem_buf, env->pregs[2]);
82 case 19:
83 return gdb_get_reg8(mem_buf, srs);
84 case 20:
85 return gdb_get_reg16(mem_buf, env->pregs[4]);
86 case 32:
87 return gdb_get_reg32(mem_buf, env->pc);
88 }
89
90 return 0;
91 }
92
93 int cris_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
94 {
95 CRISCPU *cpu = CRIS_CPU(cs);
96 CPUCRISState *env = &cpu->env;
97 uint32_t tmp;
98
99 if (n > 49) {
100 return 0;
101 }
102
103 tmp = ldl_p(mem_buf);
104
105 if (n < 16) {
106 env->regs[n] = tmp;
107 }
108
109 if (n >= 21 && n < 32) {
110 env->pregs[n - 16] = tmp;
111 }
112
113 /* FIXME: Should support function regs be writable? */
114 switch (n) {
115 case 16:
116 return 1;
117 case 17:
118 return 1;
119 case 18:
120 env->pregs[PR_PID] = tmp;
121 break;
122 case 19:
123 return 1;
124 case 20:
125 return 2;
126 case 32:
127 env->pc = tmp;
128 break;
129 }
130
131 return 4;
132 }