]> git.proxmox.com Git - mirror_qemu.git/blame - target-s390x/gdbstub.c
s390x/mmu: Use access type definitions instead of magic values
[mirror_qemu.git] / target-s390x / gdbstub.c
CommitLineData
cfae5c90
AF
1/*
2 * s390x 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 */
5b50e790
AF
20#include "config.h"
21#include "qemu-common.h"
22#include "exec/gdbstub.h"
23#include "qemu/bitops.h"
cfae5c90 24
5b50e790 25int s390_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
cfae5c90 26{
5b50e790
AF
27 S390CPU *cpu = S390_CPU(cs);
28 CPUS390XState *env = &cpu->env;
cfae5c90
AF
29 uint64_t val;
30 int cc_op;
31
32 switch (n) {
33 case S390_PSWM_REGNUM:
97fa52f0
DH
34 if (tcg_enabled()) {
35 cc_op = calc_cc(env, env->cc_op, env->cc_src, env->cc_dst,
36 env->cc_vr);
37 val = deposit64(env->psw.mask, 44, 2, cc_op);
38 return gdb_get_regl(mem_buf, val);
39 }
40 return gdb_get_regl(mem_buf, env->psw.mask);
cfae5c90 41 case S390_PSWA_REGNUM:
986a2998 42 return gdb_get_regl(mem_buf, env->psw.addr);
cfae5c90 43 case S390_R0_REGNUM ... S390_R15_REGNUM:
218829db 44 return gdb_get_regl(mem_buf, env->regs[n - S390_R0_REGNUM]);
cfae5c90 45 }
cfae5c90
AF
46 return 0;
47}
48
5b50e790 49int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
cfae5c90 50{
5b50e790
AF
51 S390CPU *cpu = S390_CPU(cs);
52 CPUS390XState *env = &cpu->env;
73d510c9 53 target_ulong tmpl = ldtul_p(mem_buf);
cfae5c90
AF
54
55 switch (n) {
56 case S390_PSWM_REGNUM:
57 env->psw.mask = tmpl;
97fa52f0
DH
58 if (tcg_enabled()) {
59 env->cc_op = extract64(tmpl, 44, 2);
60 }
cfae5c90
AF
61 break;
62 case S390_PSWA_REGNUM:
63 env->psw.addr = tmpl;
64 break;
65 case S390_R0_REGNUM ... S390_R15_REGNUM:
218829db 66 env->regs[n - S390_R0_REGNUM] = tmpl;
cfae5c90 67 break;
73d510c9
DH
68 default:
69 return 0;
70 }
71 return 8;
72}
73
74/* the values represent the positions in s390-acr.xml */
75#define S390_A0_REGNUM 0
76#define S390_A15_REGNUM 15
77/* total number of registers in s390-acr.xml */
78#define S390_NUM_AC_REGS 16
79
80static int cpu_read_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
81{
82 switch (n) {
cfae5c90 83 case S390_A0_REGNUM ... S390_A15_REGNUM:
73d510c9
DH
84 return gdb_get_reg32(mem_buf, env->aregs[n]);
85 default:
86 return 0;
87 }
88}
89
90static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
91{
92 switch (n) {
93 case S390_A0_REGNUM ... S390_A15_REGNUM:
94 env->aregs[n] = ldl_p(mem_buf);
95 return 4;
96 default:
97 return 0;
98 }
99}
100
101/* the values represent the positions in s390-fpr.xml */
102#define S390_FPC_REGNUM 0
103#define S390_F0_REGNUM 1
104#define S390_F15_REGNUM 16
105/* total number of registers in s390-fpr.xml */
106#define S390_NUM_FP_REGS 17
107
108static int cpu_read_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
109{
110 switch (n) {
cfae5c90 111 case S390_FPC_REGNUM:
73d510c9 112 return gdb_get_reg32(mem_buf, env->fpc);
cfae5c90 113 case S390_F0_REGNUM ... S390_F15_REGNUM:
73d510c9 114 return gdb_get_reg64(mem_buf, env->fregs[n - S390_F0_REGNUM].ll);
cfae5c90
AF
115 default:
116 return 0;
117 }
73d510c9
DH
118}
119
120static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
121{
122 switch (n) {
123 case S390_FPC_REGNUM:
124 env->fpc = ldl_p(mem_buf);
125 return 4;
126 case S390_F0_REGNUM ... S390_F15_REGNUM:
127 env->fregs[n - S390_F0_REGNUM].ll = ldtul_p(mem_buf);
128 return 8;
129 default:
130 return 0;
131 }
132}
133
134void s390_cpu_gdb_init(CPUState *cs)
135{
136 gdb_register_coprocessor(cs, cpu_read_ac_reg,
137 cpu_write_ac_reg,
138 S390_NUM_AC_REGS, "s390-acr.xml", 0);
139
140 gdb_register_coprocessor(cs, cpu_read_fp_reg,
141 cpu_write_fp_reg,
142 S390_NUM_FP_REGS, "s390-fpr.xml", 0);
cfae5c90 143}