Revisión | 19b1a13b2a464f74d99750a611ab2f5100b9666b (tree) |
---|---|
Tiempo | 2019-06-16 22:29:04 |
Autor | Yoshinori Sato <ysato@user...> |
Commiter | Yoshinori Sato |
target/rx: CPU definition
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190607091116.49044-4-ysato@users.sourceforge.jp>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
[PMD: Use newer QOM style, split cpu-qom.h, restrict access to
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
@@ -0,0 +1,42 @@ | ||
1 | +#ifndef QEMU_SUPERH_CPU_QOM_H | |
2 | +#define QEMU_SUPERH_CPU_QOM_H | |
3 | + | |
4 | +#include "qom/cpu.h" | |
5 | +/* | |
6 | + * RX CPU | |
7 | + * | |
8 | + * Copyright (c) 2019 Yoshinori Sato | |
9 | + * SPDX-License-Identifier: LGPL-2.0+ | |
10 | + */ | |
11 | + | |
12 | +#define TYPE_RX_CPU "rx-cpu" | |
13 | + | |
14 | +#define TYPE_RX62N_CPU RX_CPU_TYPE_NAME("rx62n") | |
15 | + | |
16 | +#define RXCPU_CLASS(klass) \ | |
17 | + OBJECT_CLASS_CHECK(RXCPUClass, (klass), TYPE_RX_CPU) | |
18 | +#define RXCPU(obj) \ | |
19 | + OBJECT_CHECK(RXCPU, (obj), TYPE_RX_CPU) | |
20 | +#define RXCPU_GET_CLASS(obj) \ | |
21 | + OBJECT_GET_CLASS(RXCPUClass, (obj), TYPE_RX_CPU) | |
22 | + | |
23 | +/* | |
24 | + * RXCPUClass: | |
25 | + * @parent_realize: The parent class' realize handler. | |
26 | + * @parent_reset: The parent class' reset handler. | |
27 | + * | |
28 | + * A RX CPU model. | |
29 | + */ | |
30 | +typedef struct RXCPUClass { | |
31 | + /*< private >*/ | |
32 | + CPUClass parent_class; | |
33 | + /*< public >*/ | |
34 | + | |
35 | + DeviceRealize parent_realize; | |
36 | + void (*parent_reset)(CPUState *cpu); | |
37 | + | |
38 | +} RXCPUClass; | |
39 | + | |
40 | +#define CPUArchState struct CPURXState | |
41 | + | |
42 | +#endif |
@@ -0,0 +1,252 @@ | ||
1 | +/* | |
2 | + * QEMU RX CPU | |
3 | + * | |
4 | + * Copyright (c) 2019 Yoshinori Sato | |
5 | + * | |
6 | + * This program is free software; you can redistribute it and/or modify it | |
7 | + * under the terms and conditions of the GNU General Public License, | |
8 | + * version 2 or later, as published by the Free Software Foundation. | |
9 | + * | |
10 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | + * more details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU General Public License along with | |
16 | + * this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | + */ | |
18 | + | |
19 | +#include "qemu/osdep.h" | |
20 | +#include "qemu/qemu-print.h" | |
21 | +#include "qapi/error.h" | |
22 | +#include "cpu.h" | |
23 | +#include "qemu-common.h" | |
24 | +#include "migration/vmstate.h" | |
25 | +#include "exec/exec-all.h" | |
26 | +#include "hw/loader.h" | |
27 | +#include "fpu/softfloat.h" | |
28 | + | |
29 | +static void rx_cpu_set_pc(CPUState *cs, vaddr value) | |
30 | +{ | |
31 | + RXCPU *cpu = RXCPU(cs); | |
32 | + | |
33 | + cpu->env.pc = value; | |
34 | +} | |
35 | + | |
36 | +static void rx_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb) | |
37 | +{ | |
38 | + RXCPU *cpu = RXCPU(cs); | |
39 | + | |
40 | + cpu->env.pc = tb->pc; | |
41 | +} | |
42 | + | |
43 | +static bool rx_cpu_has_work(CPUState *cs) | |
44 | +{ | |
45 | + return cs->interrupt_request & | |
46 | + (CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIR); | |
47 | +} | |
48 | + | |
49 | +static void rx_cpu_reset(CPUState *s) | |
50 | +{ | |
51 | + RXCPU *cpu = RXCPU(s); | |
52 | + RXCPUClass *rcc = RXCPU_GET_CLASS(cpu); | |
53 | + CPURXState *env = &cpu->env; | |
54 | + uint32_t *resetvec; | |
55 | + | |
56 | + rcc->parent_reset(s); | |
57 | + | |
58 | + memset(env, 0, offsetof(CPURXState, end_reset_fields)); | |
59 | + | |
60 | + resetvec = rom_ptr(0xfffffffc, 4); | |
61 | + if (resetvec) { | |
62 | + /* In the case of kernel, it is ignored because it is not set. */ | |
63 | + env->pc = ldl_p(resetvec); | |
64 | + } | |
65 | + rx_cpu_unpack_psw(env, 0, 1); | |
66 | + env->regs[0] = env->isp = env->usp = 0; | |
67 | + env->fpsw = 0; | |
68 | + set_flush_to_zero(1, &env->fp_status); | |
69 | + set_flush_inputs_to_zero(1, &env->fp_status); | |
70 | +} | |
71 | + | |
72 | +static void rx_cpu_list_entry(gpointer data, gpointer user_data) | |
73 | +{ | |
74 | + const char *typename = object_class_get_name(OBJECT_CLASS(data)); | |
75 | + int len = strlen(typename) - strlen(RX_CPU_TYPE_SUFFIX); | |
76 | + | |
77 | + qemu_printf("%.*s\n", len, typename); | |
78 | +} | |
79 | + | |
80 | +void rx_cpu_list(void) | |
81 | +{ | |
82 | + GSList *list; | |
83 | + list = object_class_get_list_sorted(TYPE_RX_CPU, false); | |
84 | + g_slist_foreach(list, rx_cpu_list_entry, NULL); | |
85 | + g_slist_free(list); | |
86 | +} | |
87 | + | |
88 | +static ObjectClass *rx_cpu_class_by_name(const char *cpu_model) | |
89 | +{ | |
90 | + ObjectClass *oc; | |
91 | + char *typename; | |
92 | + | |
93 | + oc = object_class_by_name(cpu_model); | |
94 | + if (oc != NULL && object_class_dynamic_cast(oc, TYPE_RX_CPU) != NULL && | |
95 | + !object_class_is_abstract(oc)) { | |
96 | + return oc; | |
97 | + } | |
98 | + | |
99 | + typename = g_strdup_printf(RX_CPU_TYPE_NAME("%s"), cpu_model); | |
100 | + oc = object_class_by_name(typename); | |
101 | + if (oc != NULL && object_class_is_abstract(oc)) { | |
102 | + oc = NULL; | |
103 | + } | |
104 | + g_free(typename); | |
105 | + | |
106 | + if (!oc) { | |
107 | + /* default to rx62n */ | |
108 | + oc = object_class_by_name(TYPE_RX62N_CPU); | |
109 | + } | |
110 | + | |
111 | + return oc; | |
112 | +} | |
113 | + | |
114 | +static void rx_cpu_realize(DeviceState *dev, Error **errp) | |
115 | +{ | |
116 | + CPUState *cs = CPU(dev); | |
117 | + RXCPUClass *rcc = RXCPU_GET_CLASS(dev); | |
118 | + Error *local_err = NULL; | |
119 | + | |
120 | + cpu_exec_realizefn(cs, &local_err); | |
121 | + if (local_err != NULL) { | |
122 | + error_propagate(errp, local_err); | |
123 | + return; | |
124 | + } | |
125 | + | |
126 | + cpu_reset(cs); | |
127 | + qemu_init_vcpu(cs); | |
128 | + | |
129 | + rcc->parent_realize(dev, errp); | |
130 | +} | |
131 | + | |
132 | +static void rx_cpu_set_irq(void *opaque, int no, int request) | |
133 | +{ | |
134 | + RXCPU *cpu = opaque; | |
135 | + CPUState *cs = CPU(cpu); | |
136 | + int irq = request & 0xff; | |
137 | + | |
138 | + static const int mask[] = { | |
139 | + [RX_CPU_IRQ] = CPU_INTERRUPT_HARD, | |
140 | + [RX_CPU_FIR] = CPU_INTERRUPT_FIR, | |
141 | + }; | |
142 | + if (irq) { | |
143 | + cpu->env.req_irq = irq; | |
144 | + cpu->env.req_ipl = (request >> 8) & 0x0f; | |
145 | + cpu_interrupt(cs, mask[no]); | |
146 | + } else { | |
147 | + cpu_reset_interrupt(cs, mask[no]); | |
148 | + } | |
149 | +} | |
150 | + | |
151 | +static void rx_cpu_disas_set_info(CPUState *cpu, disassemble_info *info) | |
152 | +{ | |
153 | + info->mach = bfd_mach_rx; | |
154 | + info->print_insn = print_insn_rx; | |
155 | +} | |
156 | + | |
157 | +static bool rx_cpu_tlb_fill(CPUState *cs, vaddr addr, int size, | |
158 | + MMUAccessType access_type, int mmu_idx, | |
159 | + bool probe, uintptr_t retaddr) | |
160 | +{ | |
161 | + uint32_t address, physical, prot; | |
162 | + | |
163 | + /* Linear mapping */ | |
164 | + address = physical = addr & TARGET_PAGE_MASK; | |
165 | + prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; | |
166 | + tlb_set_page(cs, address, physical, prot, mmu_idx, TARGET_PAGE_SIZE); | |
167 | + return true; | |
168 | +} | |
169 | + | |
170 | +static void rx_cpu_init(Object *obj) | |
171 | +{ | |
172 | + CPUState *cs = CPU(obj); | |
173 | + RXCPU *cpu = RXCPU(obj); | |
174 | + CPURXState *env = &cpu->env; | |
175 | + | |
176 | + cs->env_ptr = env; | |
177 | + qdev_init_gpio_in(DEVICE(cpu), rx_cpu_set_irq, 2); | |
178 | +} | |
179 | + | |
180 | +static void rx_cpu_class_init(ObjectClass *klass, void *data) | |
181 | +{ | |
182 | + DeviceClass *dc = DEVICE_CLASS(klass); | |
183 | + CPUClass *cc = CPU_CLASS(klass); | |
184 | + RXCPUClass *rcc = RXCPU_CLASS(klass); | |
185 | + | |
186 | + device_class_set_parent_realize(dc, rx_cpu_realize, | |
187 | + &rcc->parent_realize); | |
188 | + | |
189 | + rcc->parent_reset = cc->reset; | |
190 | + cc->reset = rx_cpu_reset; | |
191 | + | |
192 | + cc->class_by_name = rx_cpu_class_by_name; | |
193 | + cc->has_work = rx_cpu_has_work; | |
194 | + cc->do_interrupt = rx_cpu_do_interrupt; | |
195 | + cc->cpu_exec_interrupt = rx_cpu_exec_interrupt; | |
196 | + cc->dump_state = rx_cpu_dump_state; | |
197 | + cc->set_pc = rx_cpu_set_pc; | |
198 | + cc->synchronize_from_tb = rx_cpu_synchronize_from_tb; | |
199 | + cc->gdb_read_register = rx_cpu_gdb_read_register; | |
200 | + cc->gdb_write_register = rx_cpu_gdb_write_register; | |
201 | + cc->get_phys_page_debug = rx_cpu_get_phys_page_debug; | |
202 | + cc->disas_set_info = rx_cpu_disas_set_info; | |
203 | + cc->tcg_initialize = rx_translate_init; | |
204 | + cc->tlb_fill = rx_cpu_tlb_fill; | |
205 | + | |
206 | + cc->gdb_num_core_regs = 26; | |
207 | +} | |
208 | + | |
209 | +static const TypeInfo rx_cpu_info = { | |
210 | + .name = TYPE_RX_CPU, | |
211 | + .parent = TYPE_CPU, | |
212 | + .instance_size = sizeof(RXCPU), | |
213 | + .instance_init = rx_cpu_init, | |
214 | + .abstract = true, | |
215 | + .class_size = sizeof(RXCPUClass), | |
216 | + .class_init = rx_cpu_class_init, | |
217 | +}; | |
218 | + | |
219 | +static const TypeInfo rx62n_rx_cpu_info = { | |
220 | + .name = TYPE_RX62N_CPU, | |
221 | + .parent = TYPE_RX_CPU, | |
222 | +}; | |
223 | + | |
224 | +static void rx_cpu_register_types(void) | |
225 | +{ | |
226 | + type_register_static(&rx_cpu_info); | |
227 | + type_register_static(&rx62n_rx_cpu_info); | |
228 | +} | |
229 | + | |
230 | +type_init(rx_cpu_register_types) | |
231 | + | |
232 | +void rx_load_image(RXCPU *cpu, const char *filename, | |
233 | + uint32_t start, uint32_t size) | |
234 | +{ | |
235 | + static uint32_t extable[32]; | |
236 | + long kernel_size; | |
237 | + int i; | |
238 | + | |
239 | + kernel_size = load_image_targphys(filename, start, size); | |
240 | + if (kernel_size < 0) { | |
241 | + fprintf(stderr, "qemu: could not load kernel '%s'\n", filename); | |
242 | + exit(1); | |
243 | + } | |
244 | + cpu->env.pc = start; | |
245 | + | |
246 | + /* setup exception trap trampoline */ | |
247 | + /* linux kernel only works little-endian mode */ | |
248 | + for (i = 0; i < ARRAY_SIZE(extable); i++) { | |
249 | + extable[i] = cpu_to_le32(0x10 + i * 4); | |
250 | + } | |
251 | + rom_add_blob_fixed("extable", extable, sizeof(extable), 0xffffff80); | |
252 | +} |
@@ -0,0 +1,201 @@ | ||
1 | +/* | |
2 | + * RX emulation definition | |
3 | + * | |
4 | + * Copyright (c) 2019 Yoshinori Sato | |
5 | + * | |
6 | + * This program is free software; you can redistribute it and/or modify it | |
7 | + * under the terms and conditions of the GNU General Public License, | |
8 | + * version 2 or later, as published by the Free Software Foundation. | |
9 | + * | |
10 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | + * more details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU General Public License along with | |
16 | + * this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | + */ | |
18 | + | |
19 | +#ifndef RX_CPU_H | |
20 | +#define RX_CPU_H | |
21 | + | |
22 | +#include "qemu/bitops.h" | |
23 | +#include "qemu-common.h" | |
24 | +#include "hw/registerfields.h" | |
25 | +#include "cpu-qom.h" | |
26 | +#include "qom/cpu.h" | |
27 | + | |
28 | +#define TARGET_LONG_BITS 32 | |
29 | +#define TARGET_PAGE_BITS 12 | |
30 | + | |
31 | +#include "exec/cpu-defs.h" | |
32 | + | |
33 | +#define TARGET_PHYS_ADDR_SPACE_BITS 32 | |
34 | +#define TARGET_VIRT_ADDR_SPACE_BITS 32 | |
35 | + | |
36 | +/* PSW define */ | |
37 | +REG32(PSW, 0) | |
38 | +FIELD(PSW, C, 0, 1) | |
39 | +FIELD(PSW, Z, 1, 1) | |
40 | +FIELD(PSW, S, 2, 1) | |
41 | +FIELD(PSW, O, 3, 1) | |
42 | +FIELD(PSW, I, 16, 1) | |
43 | +FIELD(PSW, U, 17, 1) | |
44 | +FIELD(PSW, PM, 20, 1) | |
45 | +FIELD(PSW, IPL, 24, 4) | |
46 | + | |
47 | +/* FPSW define */ | |
48 | +REG32(FPSW, 0) | |
49 | +FIELD(FPSW, RM, 0, 2) | |
50 | +FIELD(FPSW, CV, 2, 1) | |
51 | +FIELD(FPSW, CO, 3, 1) | |
52 | +FIELD(FPSW, CZ, 4, 1) | |
53 | +FIELD(FPSW, CU, 5, 1) | |
54 | +FIELD(FPSW, CX, 6, 1) | |
55 | +FIELD(FPSW, CE, 7, 1) | |
56 | +FIELD(FPSW, CAUSE, 2, 6) | |
57 | +FIELD(FPSW, DN, 8, 1) | |
58 | +FIELD(FPSW, EV, 10, 1) | |
59 | +FIELD(FPSW, EO, 11, 1) | |
60 | +FIELD(FPSW, EZ, 12, 1) | |
61 | +FIELD(FPSW, EU, 13, 1) | |
62 | +FIELD(FPSW, EX, 14, 1) | |
63 | +FIELD(FPSW, ENABLE, 10, 5) | |
64 | +FIELD(FPSW, FV, 26, 1) | |
65 | +FIELD(FPSW, FO, 27, 1) | |
66 | +FIELD(FPSW, FZ, 28, 1) | |
67 | +FIELD(FPSW, FU, 29, 1) | |
68 | +FIELD(FPSW, FX, 30, 1) | |
69 | +FIELD(FPSW, FLAGS, 26, 4) | |
70 | +FIELD(FPSW, FS, 31, 1) | |
71 | + | |
72 | +#define NB_MMU_MODES 1 | |
73 | +#define MMU_MODE0_SUFFIX _all | |
74 | + | |
75 | +enum { | |
76 | + NUM_REGS = 16, | |
77 | +}; | |
78 | + | |
79 | +typedef struct CPURXState { | |
80 | + /* CPU registers */ | |
81 | + uint32_t regs[NUM_REGS]; /* general registers */ | |
82 | + uint32_t psw_o; /* O bit of status register */ | |
83 | + uint32_t psw_s; /* S bit of status register */ | |
84 | + uint32_t psw_z; /* Z bit of status register */ | |
85 | + uint32_t psw_c; /* C bit of status register */ | |
86 | + uint32_t psw_u; | |
87 | + uint32_t psw_i; | |
88 | + uint32_t psw_pm; | |
89 | + uint32_t psw_ipl; | |
90 | + uint32_t bpsw; /* backup status */ | |
91 | + uint32_t bpc; /* backup pc */ | |
92 | + uint32_t isp; /* global base register */ | |
93 | + uint32_t usp; /* vector base register */ | |
94 | + uint32_t pc; /* program counter */ | |
95 | + uint32_t intb; /* interrupt vector */ | |
96 | + uint32_t fintv; | |
97 | + uint32_t fpsw; | |
98 | + uint64_t acc; | |
99 | + | |
100 | + /* Fields up to this point are cleared by a CPU reset */ | |
101 | + struct {} end_reset_fields; | |
102 | + | |
103 | + /* Internal use */ | |
104 | + uint32_t in_sleep; | |
105 | + uint32_t req_irq; /* Requested interrupt no (hard) */ | |
106 | + uint32_t req_ipl; /* Requested interrupt level */ | |
107 | + uint32_t ack_irq; /* execute irq */ | |
108 | + uint32_t ack_ipl; /* execute ipl */ | |
109 | + float_status fp_status; | |
110 | + qemu_irq ack; /* Interrupt acknowledge */ | |
111 | + | |
112 | + CPU_COMMON | |
113 | +} CPURXState; | |
114 | + | |
115 | +/* | |
116 | + * RXCPU: | |
117 | + * @env: #CPURXState | |
118 | + * | |
119 | + * A RX CPU | |
120 | + */ | |
121 | +struct RXCPU { | |
122 | + /*< private >*/ | |
123 | + CPUState parent_obj; | |
124 | + /*< public >*/ | |
125 | + | |
126 | + CPURXState env; | |
127 | +}; | |
128 | + | |
129 | +typedef struct RXCPU RXCPU; | |
130 | +typedef RXCPU ArchCPU; | |
131 | + | |
132 | +static inline RXCPU *rx_env_get_cpu(CPURXState *env) | |
133 | +{ | |
134 | + return container_of(env, RXCPU, env); | |
135 | +} | |
136 | + | |
137 | +#define ENV_GET_CPU(e) CPU(rx_env_get_cpu(e)) | |
138 | + | |
139 | +#define ENV_OFFSET offsetof(RXCPU, env) | |
140 | + | |
141 | +#define RX_CPU_TYPE_SUFFIX "-" TYPE_RX_CPU | |
142 | +#define RX_CPU_TYPE_NAME(model) model RX_CPU_TYPE_SUFFIX | |
143 | +#define CPU_RESOLVING_TYPE TYPE_RX_CPU | |
144 | + | |
145 | +extern const char rx_crname[][6]; | |
146 | + | |
147 | +void rx_cpu_do_interrupt(CPUState *cpu); | |
148 | +bool rx_cpu_exec_interrupt(CPUState *cpu, int int_req); | |
149 | +void rx_cpu_dump_state(CPUState *cpu, FILE *f, int flags); | |
150 | +int rx_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); | |
151 | +int rx_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); | |
152 | +hwaddr rx_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); | |
153 | + | |
154 | +void rx_translate_init(void); | |
155 | +int cpu_rx_signal_handler(int host_signum, void *pinfo, | |
156 | + void *puc); | |
157 | + | |
158 | +void rx_cpu_list(void); | |
159 | +void rx_load_image(RXCPU *cpu, const char *filename, | |
160 | + uint32_t start, uint32_t size); | |
161 | +void rx_cpu_unpack_psw(CPURXState *env, uint32_t psw, int rte); | |
162 | + | |
163 | +#define cpu_signal_handler cpu_rx_signal_handler | |
164 | +#define cpu_list rx_cpu_list | |
165 | + | |
166 | +#include "exec/cpu-all.h" | |
167 | + | |
168 | +#define CPU_INTERRUPT_SOFT CPU_INTERRUPT_TGT_INT_0 | |
169 | +#define CPU_INTERRUPT_FIR CPU_INTERRUPT_TGT_INT_1 | |
170 | + | |
171 | +#define RX_CPU_IRQ 0 | |
172 | +#define RX_CPU_FIR 1 | |
173 | + | |
174 | +static inline void cpu_get_tb_cpu_state(CPURXState *env, target_ulong *pc, | |
175 | + target_ulong *cs_base, uint32_t *flags) | |
176 | +{ | |
177 | + *pc = env->pc; | |
178 | + *cs_base = 0; | |
179 | + *flags = FIELD_DP32(0, PSW, PM, env->psw_pm); | |
180 | +} | |
181 | + | |
182 | +static inline int cpu_mmu_index(CPURXState *env, bool ifetch) | |
183 | +{ | |
184 | + return 0; | |
185 | +} | |
186 | + | |
187 | +static inline uint32_t rx_cpu_pack_psw(CPURXState *env) | |
188 | +{ | |
189 | + uint32_t psw = 0; | |
190 | + psw = FIELD_DP32(psw, PSW, IPL, env->psw_ipl); | |
191 | + psw = FIELD_DP32(psw, PSW, PM, env->psw_pm); | |
192 | + psw = FIELD_DP32(psw, PSW, U, env->psw_u); | |
193 | + psw = FIELD_DP32(psw, PSW, I, env->psw_i); | |
194 | + psw = FIELD_DP32(psw, PSW, O, env->psw_o >> 31); | |
195 | + psw = FIELD_DP32(psw, PSW, S, env->psw_s >> 31); | |
196 | + psw = FIELD_DP32(psw, PSW, Z, env->psw_z == 0); | |
197 | + psw = FIELD_DP32(psw, PSW, C, env->psw_c); | |
198 | + return psw; | |
199 | +} | |
200 | + | |
201 | +#endif /* RX_CPU_H */ |
@@ -0,0 +1,112 @@ | ||
1 | +/* | |
2 | + * RX gdb server stub | |
3 | + * | |
4 | + * Copyright (c) 2019 Yoshinori Sato | |
5 | + * | |
6 | + * This program is free software; you can redistribute it and/or modify it | |
7 | + * under the terms and conditions of the GNU General Public License, | |
8 | + * version 2 or later, as published by the Free Software Foundation. | |
9 | + * | |
10 | + * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | + * more details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU General Public License along with | |
16 | + * this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | + */ | |
18 | +#include "qemu/osdep.h" | |
19 | +#include "qemu-common.h" | |
20 | +#include "cpu.h" | |
21 | +#include "exec/gdbstub.h" | |
22 | + | |
23 | +int rx_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) | |
24 | +{ | |
25 | + RXCPU *cpu = RXCPU(cs); | |
26 | + CPURXState *env = &cpu->env; | |
27 | + | |
28 | + switch (n) { | |
29 | + case 0 ... 15: | |
30 | + return gdb_get_regl(mem_buf, env->regs[n]); | |
31 | + case 16: | |
32 | + return gdb_get_regl(mem_buf, (env->psw_u) ? env->regs[0] : env->usp); | |
33 | + case 17: | |
34 | + return gdb_get_regl(mem_buf, (!env->psw_u) ? env->regs[0] : env->isp); | |
35 | + case 18: | |
36 | + return gdb_get_regl(mem_buf, rx_cpu_pack_psw(env)); | |
37 | + case 19: | |
38 | + return gdb_get_regl(mem_buf, env->pc); | |
39 | + case 20: | |
40 | + return gdb_get_regl(mem_buf, env->intb); | |
41 | + case 21: | |
42 | + return gdb_get_regl(mem_buf, env->bpsw); | |
43 | + case 22: | |
44 | + return gdb_get_regl(mem_buf, env->bpc); | |
45 | + case 23: | |
46 | + return gdb_get_regl(mem_buf, env->fintv); | |
47 | + case 24: | |
48 | + return gdb_get_regl(mem_buf, env->fpsw); | |
49 | + case 25: | |
50 | + return 0; | |
51 | + } | |
52 | + return 0; | |
53 | +} | |
54 | + | |
55 | +int rx_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) | |
56 | +{ | |
57 | + RXCPU *cpu = RXCPU(cs); | |
58 | + CPURXState *env = &cpu->env; | |
59 | + uint32_t psw; | |
60 | + switch (n) { | |
61 | + case 0 ... 15: | |
62 | + env->regs[n] = ldl_p(mem_buf); | |
63 | + if (n == 0) { | |
64 | + if (env->psw_u) { | |
65 | + env->usp = env->regs[0]; | |
66 | + } else { | |
67 | + env->isp = env->regs[0]; | |
68 | + } | |
69 | + } | |
70 | + break; | |
71 | + case 16: | |
72 | + env->usp = ldl_p(mem_buf); | |
73 | + if (env->psw_u) { | |
74 | + env->regs[0] = ldl_p(mem_buf); | |
75 | + } | |
76 | + break; | |
77 | + case 17: | |
78 | + env->isp = ldl_p(mem_buf); | |
79 | + if (!env->psw_u) { | |
80 | + env->regs[0] = ldl_p(mem_buf); | |
81 | + } | |
82 | + break; | |
83 | + case 18: | |
84 | + psw = ldl_p(mem_buf); | |
85 | + rx_cpu_unpack_psw(env, psw, 1); | |
86 | + break; | |
87 | + case 19: | |
88 | + env->pc = ldl_p(mem_buf); | |
89 | + break; | |
90 | + case 20: | |
91 | + env->intb = ldl_p(mem_buf); | |
92 | + break; | |
93 | + case 21: | |
94 | + env->bpsw = ldl_p(mem_buf); | |
95 | + break; | |
96 | + case 22: | |
97 | + env->bpc = ldl_p(mem_buf); | |
98 | + break; | |
99 | + case 23: | |
100 | + env->fintv = ldl_p(mem_buf); | |
101 | + break; | |
102 | + case 24: | |
103 | + env->fpsw = ldl_p(mem_buf); | |
104 | + break; | |
105 | + case 25: | |
106 | + return 8; | |
107 | + default: | |
108 | + return 0; | |
109 | + } | |
110 | + | |
111 | + return 4; | |
112 | +} |
@@ -0,0 +1,38 @@ | ||
1 | +/* | |
2 | + * QEMU monitor | |
3 | + * | |
4 | + * Copyright (c) 2003-2004 Fabrice Bellard | |
5 | + * | |
6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | + * of this software and associated documentation files (the "Software"), to deal | |
8 | + * in the Software without restriction, including without limitation the rights | |
9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | + * copies of the Software, and to permit persons to whom the Software is | |
11 | + * furnished to do so, subject to the following conditions: | |
12 | + * | |
13 | + * The above copyright notice and this permission notice shall be included in | |
14 | + * all copies or substantial portions of the Software. | |
15 | + * | |
16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | + * THE SOFTWARE. | |
23 | + */ | |
24 | +#include "qemu/osdep.h" | |
25 | +#include "cpu.h" | |
26 | +#include "monitor/monitor.h" | |
27 | +#include "monitor/hmp-target.h" | |
28 | +#include "hmp.h" | |
29 | + | |
30 | +void hmp_info_tlb(Monitor *mon, const QDict *qdict) | |
31 | +{ | |
32 | + CPUArchState *env = mon_get_cpu_env(); | |
33 | + | |
34 | + if (!env) { | |
35 | + monitor_printf(mon, "No CPU available\n"); | |
36 | + return; | |
37 | + } | |
38 | +} |