xref: /openbmc/qemu/target/hppa/gdbstub.c (revision fe44dc91)
1 /*
2  * HPPA gdb server stub
3  *
4  * Copyright (c) 2016 Richard Henderson <rth@twiddle.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
22 #include "cpu.h"
23 #include "exec/gdbstub.h"
24 
25 int hppa_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
26 {
27     HPPACPU *cpu = HPPA_CPU(cs);
28     CPUHPPAState *env = &cpu->env;
29     target_ulong val;
30 
31     switch (n) {
32     case 0:
33         val = cpu_hppa_get_psw(env);
34         break;
35     case 1 ... 31:
36         val = env->gr[n];
37         break;
38     case 32:
39         val = env->sar;
40         break;
41     case 33:
42         val = env->iaoq_f;
43         break;
44     case 35:
45         val = env->iaoq_b;
46         break;
47     case 59:
48         val = env->cr26;
49         break;
50     case 60:
51         val = env->cr27;
52         break;
53     case 64 ... 127:
54         val = extract64(env->fr[(n - 64) / 2], (n & 1 ? 0 : 32), 32);
55         break;
56     default:
57         if (n < 128) {
58             val = 0;
59         } else {
60             return 0;
61         }
62         break;
63     }
64     return gdb_get_regl(mem_buf, val);
65 }
66 
67 int hppa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
68 {
69     HPPACPU *cpu = HPPA_CPU(cs);
70     CPUHPPAState *env = &cpu->env;
71     target_ulong val = ldtul_p(mem_buf);
72 
73     switch (n) {
74     case 0:
75         cpu_hppa_put_psw(env, val);
76         break;
77     case 1 ... 31:
78         env->gr[n] = val;
79         break;
80     case 32:
81         env->sar = val;
82         break;
83     case 33:
84         env->iaoq_f = val;
85         break;
86     case 35:
87         env->iaoq_b = val;
88     case 59:
89         env->cr26 = val;
90         break;
91     case 60:
92         env->cr27 = val;
93         break;
94     case 64:
95         env->fr[0] = deposit64(env->fr[0], 32, 32, val);
96         cpu_hppa_loaded_fr0(env);
97         break;
98     case 65 ... 127:
99         {
100             uint64_t *fr = &env->fr[(n - 64) / 2];
101             *fr = deposit64(*fr, val, (n & 1 ? 0 : 32), 32);
102         }
103         break;
104     default:
105         if (n >= 128) {
106             return 0;
107         }
108         break;
109     }
110     return sizeof(target_ulong);
111 }
112