2 * Xtensa gdb server stub
4 * Copyright (c) 2003-2005 Fabrice Bellard
5 * Copyright (c) 2013 SUSE LINUX Products GmbH
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.1 of the License, or (at your option) any later version.
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.
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/>.
20 #include "qemu/osdep.h"
22 #include "gdbstub/helpers.h"
26 xtRegisterTypeArRegfile
= 1, /* Register File ar0..arXX. */
27 xtRegisterTypeSpecialReg
, /* CPU states, such as PS, Booleans, (rsr). */
28 xtRegisterTypeUserReg
, /* User defined registers (rur). */
29 xtRegisterTypeTieRegfile
, /* User define register files. */
30 xtRegisterTypeTieState
, /* TIE States (mapped on user regs). */
31 xtRegisterTypeMapped
, /* Mapped on Special Registers. */
32 xtRegisterTypeUnmapped
, /* Special case of masked registers. */
33 xtRegisterTypeWindow
, /* Live window registers (a0..a15). */
34 xtRegisterTypeVirtual
, /* PC, FP. */
38 #define XTENSA_REGISTER_FLAGS_PRIVILEGED 0x0001
39 #define XTENSA_REGISTER_FLAGS_READABLE 0x0002
40 #define XTENSA_REGISTER_FLAGS_WRITABLE 0x0004
41 #define XTENSA_REGISTER_FLAGS_VOLATILE 0x0008
43 void xtensa_count_regs(const XtensaConfig
*config
,
44 unsigned *n_regs
, unsigned *n_core_regs
)
47 bool count_core_regs
= true;
49 for (i
= 0; config
->gdb_regmap
.reg
[i
].targno
>= 0; ++i
) {
50 if (config
->gdb_regmap
.reg
[i
].type
!= xtRegisterTypeTieState
&&
51 config
->gdb_regmap
.reg
[i
].type
!= xtRegisterTypeMapped
&&
52 config
->gdb_regmap
.reg
[i
].type
!= xtRegisterTypeUnmapped
) {
54 if (count_core_regs
) {
55 if ((config
->gdb_regmap
.reg
[i
].flags
&
56 XTENSA_REGISTER_FLAGS_PRIVILEGED
) == 0) {
59 count_core_regs
= false;
66 int xtensa_cpu_gdb_read_register(CPUState
*cs
, GByteArray
*mem_buf
, int n
)
68 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
69 CPUXtensaState
*env
= &cpu
->env
;
70 const XtensaGdbReg
*reg
= env
->config
->gdb_regmap
.reg
+ n
;
71 #ifdef CONFIG_USER_ONLY
72 int num_regs
= env
->config
->gdb_regmap
.num_core_regs
;
74 int num_regs
= env
->config
->gdb_regmap
.num_regs
;
78 if (n
< 0 || n
>= num_regs
) {
83 case xtRegisterTypeVirtual
: /*pc*/
84 return gdb_get_reg32(mem_buf
, env
->pc
);
86 case xtRegisterTypeArRegfile
: /*ar*/
87 xtensa_sync_phys_from_window(env
);
88 return gdb_get_reg32(mem_buf
, env
->phys_regs
[(reg
->targno
& 0xff)
89 % env
->config
->nareg
]);
91 case xtRegisterTypeSpecialReg
: /*SR*/
92 return gdb_get_reg32(mem_buf
, env
->sregs
[reg
->targno
& 0xff]);
94 case xtRegisterTypeUserReg
: /*UR*/
95 return gdb_get_reg32(mem_buf
, env
->uregs
[reg
->targno
& 0xff]);
97 case xtRegisterTypeTieRegfile
: /*f*/
98 i
= reg
->targno
& 0x0f;
101 return gdb_get_reg32(mem_buf
,
102 float32_val(env
->fregs
[i
].f32
[FP_F32_LOW
]));
104 return gdb_get_reg64(mem_buf
, float64_val(env
->fregs
[i
].f64
));
106 qemu_log_mask(LOG_UNIMP
, "%s from reg %d of unsupported size %d\n",
107 __func__
, n
, reg
->size
);
108 return gdb_get_zeroes(mem_buf
, reg
->size
);
111 case xtRegisterTypeWindow
: /*a*/
112 return gdb_get_reg32(mem_buf
, env
->regs
[reg
->targno
& 0x0f]);
115 qemu_log_mask(LOG_UNIMP
, "%s from reg %d of unsupported type %d\n",
116 __func__
, n
, reg
->type
);
117 return gdb_get_zeroes(mem_buf
, reg
->size
);
121 int xtensa_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
123 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
124 CPUXtensaState
*env
= &cpu
->env
;
126 const XtensaGdbReg
*reg
= env
->config
->gdb_regmap
.reg
+ n
;
127 #ifdef CONFIG_USER_ONLY
128 int num_regs
= env
->config
->gdb_regmap
.num_core_regs
;
130 int num_regs
= env
->config
->gdb_regmap
.num_regs
;
133 if (n
< 0 || n
>= num_regs
) {
137 tmp
= ldl_p(mem_buf
);
140 case xtRegisterTypeVirtual
: /*pc*/
144 case xtRegisterTypeArRegfile
: /*ar*/
145 env
->phys_regs
[(reg
->targno
& 0xff) % env
->config
->nareg
] = tmp
;
146 xtensa_sync_window_from_phys(env
);
149 case xtRegisterTypeSpecialReg
: /*SR*/
150 env
->sregs
[reg
->targno
& 0xff] = tmp
;
153 case xtRegisterTypeUserReg
: /*UR*/
154 env
->uregs
[reg
->targno
& 0xff] = tmp
;
157 case xtRegisterTypeTieRegfile
: /*f*/
160 env
->fregs
[reg
->targno
& 0x0f].f32
[FP_F32_LOW
] = make_float32(tmp
);
163 env
->fregs
[reg
->targno
& 0x0f].f64
= make_float64(tmp
);
166 qemu_log_mask(LOG_UNIMP
, "%s to reg %d of unsupported size %d\n",
167 __func__
, n
, reg
->size
);
171 case xtRegisterTypeWindow
: /*a*/
172 env
->regs
[reg
->targno
& 0x0f] = tmp
;
176 qemu_log_mask(LOG_UNIMP
, "%s to reg %d of unsupported type %d\n",
177 __func__
, n
, reg
->type
);