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 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"
21 #include "qemu-common.h"
23 #include "exec/gdbstub.h"
27 xtRegisterTypeArRegfile
= 1, /* Register File ar0..arXX. */
28 xtRegisterTypeSpecialReg
, /* CPU states, such as PS, Booleans, (rsr). */
29 xtRegisterTypeUserReg
, /* User defined registers (rur). */
30 xtRegisterTypeTieRegfile
, /* User define register files. */
31 xtRegisterTypeTieState
, /* TIE States (mapped on user regs). */
32 xtRegisterTypeMapped
, /* Mapped on Special Registers. */
33 xtRegisterTypeUnmapped
, /* Special case of masked registers. */
34 xtRegisterTypeWindow
, /* Live window registers (a0..a15). */
35 xtRegisterTypeVirtual
, /* PC, FP. */
39 #define XTENSA_REGISTER_FLAGS_PRIVILEGED 0x0001
40 #define XTENSA_REGISTER_FLAGS_READABLE 0x0002
41 #define XTENSA_REGISTER_FLAGS_WRITABLE 0x0004
42 #define XTENSA_REGISTER_FLAGS_VOLATILE 0x0008
44 void xtensa_count_regs(const XtensaConfig
*config
,
45 unsigned *n_regs
, unsigned *n_core_regs
)
48 bool count_core_regs
= true;
50 for (i
= 0; config
->gdb_regmap
.reg
[i
].targno
>= 0; ++i
) {
51 if (config
->gdb_regmap
.reg
[i
].type
!= xtRegisterTypeTieState
&&
52 config
->gdb_regmap
.reg
[i
].type
!= xtRegisterTypeMapped
&&
53 config
->gdb_regmap
.reg
[i
].type
!= xtRegisterTypeUnmapped
) {
55 if (count_core_regs
) {
56 if ((config
->gdb_regmap
.reg
[i
].flags
&
57 XTENSA_REGISTER_FLAGS_PRIVILEGED
) == 0) {
60 count_core_regs
= false;
67 int xtensa_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
69 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
70 CPUXtensaState
*env
= &cpu
->env
;
71 const XtensaGdbReg
*reg
= env
->config
->gdb_regmap
.reg
+ n
;
72 #ifdef CONFIG_USER_ONLY
73 int num_regs
= env
->config
->gdb_regmap
.num_core_regs
;
75 int num_regs
= env
->config
->gdb_regmap
.num_regs
;
79 if (n
< 0 || n
>= num_regs
) {
84 case xtRegisterTypeVirtual
: /*pc*/
85 return gdb_get_reg32(mem_buf
, env
->pc
);
87 case xtRegisterTypeArRegfile
: /*ar*/
88 xtensa_sync_phys_from_window(env
);
89 return gdb_get_reg32(mem_buf
, env
->phys_regs
[(reg
->targno
& 0xff)
90 % env
->config
->nareg
]);
92 case xtRegisterTypeSpecialReg
: /*SR*/
93 return gdb_get_reg32(mem_buf
, env
->sregs
[reg
->targno
& 0xff]);
95 case xtRegisterTypeUserReg
: /*UR*/
96 return gdb_get_reg32(mem_buf
, env
->uregs
[reg
->targno
& 0xff]);
98 case xtRegisterTypeTieRegfile
: /*f*/
99 i
= reg
->targno
& 0x0f;
102 return gdb_get_reg32(mem_buf
,
103 float32_val(env
->fregs
[i
].f32
[FP_F32_LOW
]));
105 return gdb_get_reg64(mem_buf
, float64_val(env
->fregs
[i
].f64
));
107 qemu_log_mask(LOG_UNIMP
, "%s from reg %d of unsupported size %d\n",
108 __func__
, n
, reg
->size
);
109 memset(mem_buf
, 0, reg
->size
);
113 case xtRegisterTypeWindow
: /*a*/
114 return gdb_get_reg32(mem_buf
, env
->regs
[reg
->targno
& 0x0f]);
117 qemu_log_mask(LOG_UNIMP
, "%s from reg %d of unsupported type %d\n",
118 __func__
, n
, reg
->type
);
119 memset(mem_buf
, 0, reg
->size
);
124 int xtensa_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
126 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
127 CPUXtensaState
*env
= &cpu
->env
;
129 const XtensaGdbReg
*reg
= env
->config
->gdb_regmap
.reg
+ n
;
130 #ifdef CONFIG_USER_ONLY
131 int num_regs
= env
->config
->gdb_regmap
.num_core_regs
;
133 int num_regs
= env
->config
->gdb_regmap
.num_regs
;
136 if (n
< 0 || n
>= num_regs
) {
140 tmp
= ldl_p(mem_buf
);
143 case xtRegisterTypeVirtual
: /*pc*/
147 case xtRegisterTypeArRegfile
: /*ar*/
148 env
->phys_regs
[(reg
->targno
& 0xff) % env
->config
->nareg
] = tmp
;
149 xtensa_sync_window_from_phys(env
);
152 case xtRegisterTypeSpecialReg
: /*SR*/
153 env
->sregs
[reg
->targno
& 0xff] = tmp
;
156 case xtRegisterTypeUserReg
: /*UR*/
157 env
->uregs
[reg
->targno
& 0xff] = tmp
;
160 case xtRegisterTypeTieRegfile
: /*f*/
163 env
->fregs
[reg
->targno
& 0x0f].f32
[FP_F32_LOW
] = make_float32(tmp
);
166 env
->fregs
[reg
->targno
& 0x0f].f64
= make_float64(tmp
);
169 qemu_log_mask(LOG_UNIMP
, "%s to reg %d of unsupported size %d\n",
170 __func__
, n
, reg
->size
);
174 case xtRegisterTypeWindow
: /*a*/
175 env
->regs
[reg
->targno
& 0x0f] = tmp
;
179 qemu_log_mask(LOG_UNIMP
, "%s to reg %d of unsupported type %d\n",
180 __func__
, n
, reg
->type
);