1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include "qemu/osdep.h"
20#include "cpu.h"
21#include "exec/gdbstub.h"
22#include "internals.h"
23
24#ifndef CONFIG_USER_ONLY
25
26
27static void map_a32_to_a64_regs(CPUARMState *env)
28{
29 unsigned int i;
30
31 for (i = 0; i < 13; i++) {
32 env->xregs[i] = env->regs[i];
33 }
34 env->xregs[13] = env->banked_r13[bank_number(ARM_CPU_MODE_USR)];
35 env->xregs[14] = env->banked_r14[bank_number(ARM_CPU_MODE_USR)];
36
37 for (i = 0; i < ARRAY_SIZE(env->fiq_regs); i++) {
38 env->xregs[i + 24] = env->fiq_regs[i];
39 }
40 env->xregs[29] = env->banked_r13[bank_number(ARM_CPU_MODE_FIQ)];
41 env->xregs[30] = env->banked_r14[bank_number(ARM_CPU_MODE_FIQ)];
42
43
44 env->xregs[31] = env->regs[13];
45
46 env->pc = env->regs[15];
47 pstate_write(env, env->spsr | (1 << 4));
48}
49
50static void map_a64_to_a32_regs(CPUARMState *env)
51{
52 unsigned int i = 0;
53
54 for (i = 0; i < 13; i++) {
55 env->regs[i] = env->xregs[i];
56 }
57 env->banked_r13[bank_number(ARM_CPU_MODE_USR)] = env->xregs[13];
58 env->banked_r14[bank_number(ARM_CPU_MODE_USR)] = env->xregs[14];
59
60 for (i = 0; i < ARRAY_SIZE(env->usr_regs); i++) {
61 env->fiq_regs[i] = env->xregs[i + 24];
62 }
63 env->banked_r13[bank_number(ARM_CPU_MODE_FIQ)] = env->xregs[29];
64 env->banked_r14[bank_number(ARM_CPU_MODE_FIQ)] = env->xregs[30];
65
66 env->regs[15] = env->pc;
67}
68
69#endif
70
71int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
72{
73 ARMCPU *cpu = ARM_CPU(cs);
74 CPUARMState *env = &cpu->env;
75
76#ifndef CONFIG_USER_ONLY
77 if (!is_a64(env)) {
78 map_a32_to_a64_regs(env);
79 }
80#endif
81
82 if (n < 31) {
83
84 return gdb_get_reg64(mem_buf, env->xregs[n]);
85 }
86 switch (n) {
87 case 31:
88 {
89 unsigned int cur_el = arm_current_el(env);
90 uint64_t sp;
91
92 aarch64_save_sp(env, cur_el);
93 switch (env->debug_ctx) {
94 case DEBUG_EL0:
95 sp = env->sp_el[0];
96 break;
97 case DEBUG_EL1:
98 sp = env->sp_el[1];
99 break;
100 case DEBUG_EL2:
101 sp = env->sp_el[2];
102 break;
103 case DEBUG_EL3:
104 sp = env->sp_el[3];
105 break;
106 default:
107 sp = env->xregs[31];
108 break;
109 }
110 return gdb_get_reg64(mem_buf, sp);
111 }
112 case 32:
113 return gdb_get_reg64(mem_buf, env->pc);
114 case 33:
115 return gdb_get_reg32(mem_buf, pstate_read(env));
116 }
117
118 return 0;
119}
120
121int aarch64_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
122{
123 ARMCPU *cpu = ARM_CPU(cs);
124 CPUARMState *env = &cpu->env;
125 uint64_t tmp;
126 int rlen = 0;
127
128#ifndef CONFIG_USER_ONLY
129 if (!is_a64(env)) {
130 map_a32_to_a64_regs(env);
131 }
132#endif
133
134 tmp = ldq_p(mem_buf);
135
136 if (n < 31) {
137
138 env->xregs[n] = tmp;
139 rlen = 8;
140 }
141 switch (n) {
142 case 31: {
143 unsigned int cur_el = arm_current_el(env);
144
145 aarch64_save_sp(env, cur_el);
146 switch (env->debug_ctx) {
147 case DEBUG_EL0:
148 env->sp_el[0] = tmp;
149 break;
150 case DEBUG_EL1:
151 env->sp_el[1] = tmp;
152 break;
153 case DEBUG_EL2:
154 env->sp_el[2] = tmp;
155 break;
156 case DEBUG_EL3:
157 env->sp_el[3] = tmp;
158 break;
159 default:
160 env->xregs[31] = tmp;
161 break;
162 }
163 aarch64_restore_sp(env, cur_el);
164 rlen = 8;
165 break;
166 }
167 case 32:
168 env->pc = tmp;
169 rlen = 8;
170 break;
171 case 33:
172
173 pstate_write(env, tmp);
174 rlen = 4;
175 break;
176 }
177
178#ifndef CONFIG_USER_ONLY
179 if (!is_a64(env)) {
180 map_a64_to_a32_regs(env);
181 }
182#endif
183
184
185 return rlen;
186}
187