Skip to content

Commit 27a4a30

Browse files
ysat0philmd
authored andcommitted
target/rx: CPU definitions
Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Yoshinori Sato <[email protected]> Signed-off-by: Richard Henderson <[email protected]> [PMD: Use newer QOM style, split cpu-qom.h, restrict access to extable array, use rx_cpu_tlb_fill() extracted from patch of Yoshinori Sato 'Convert to CPUClass::tlb_fill', call cpu_reset after qemu_init_vcpu, make rx_crname a function] Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Acked-by: Igor Mammedov <[email protected]> Message-Id: <[email protected]> Acked-by: Richard Henderson <[email protected]> [PMD: Use GByteArray in gdbstub (rebase commit a010bdb), use device_class_set_parent_reset (rebase commit 781c67c)] Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
1 parent 075d047 commit 27a4a30

File tree

8 files changed

+682
-6
lines changed

8 files changed

+682
-6
lines changed

gdb-xml/rx-core.xml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0"?>
2+
<!-- Copyright (C) 2019 Free Software Foundation, Inc.
3+
4+
Copying and distribution of this file, with or without modification,
5+
are permitted in any medium without royalty provided the copyright
6+
notice and this notice are preserved. -->
7+
8+
<!DOCTYPE feature SYSTEM "gdb-target.dtd">
9+
<feature name="org.gnu.gdb.rx.core">
10+
<reg name="r0" bitsize="32" type="data_ptr"/>
11+
<reg name="r1" bitsize="32" type="uint32"/>
12+
<reg name="r2" bitsize="32" type="uint32"/>
13+
<reg name="r3" bitsize="32" type="uint32"/>
14+
<reg name="r4" bitsize="32" type="uint32"/>
15+
<reg name="r5" bitsize="32" type="uint32"/>
16+
<reg name="r6" bitsize="32" type="uint32"/>
17+
<reg name="r7" bitsize="32" type="uint32"/>
18+
<reg name="r8" bitsize="32" type="uint32"/>
19+
<reg name="r9" bitsize="32" type="uint32"/>
20+
<reg name="r10" bitsize="32" type="uint32"/>
21+
<reg name="r11" bitsize="32" type="uint32"/>
22+
<reg name="r12" bitsize="32" type="uint32"/>
23+
<reg name="r13" bitsize="32" type="uint32"/>
24+
<reg name="r14" bitsize="32" type="uint32"/>
25+
<reg name="r15" bitsize="32" type="uint32"/>
26+
27+
<flags id="psw_flags" size="4">
28+
<field name="C" start="0" end="0"/>
29+
<field name="Z" start="1" end="1"/>
30+
<field name="S" start="2" end="2"/>
31+
<field name="O" start="3" end="3"/>
32+
<field name="I" start="16" end="16"/>
33+
<field name="U" start="17" end="17"/>
34+
<field name="PM" start="20" end="20"/>
35+
<field name="IPL" start="24" end="27"/>
36+
</flags>
37+
38+
<flags id="fpsw_flags" size="4">
39+
<field name="RM" start="0" end="1"/>
40+
<field name="CV" start="2" end="2"/>
41+
<field name="CO" start="3" end="3"/>
42+
<field name="CZ" start="4" end="4"/>
43+
<field name="CU" start="5" end="5"/>
44+
<field name="CX" start="6" end="6"/>
45+
<field name="CE" start="7" end="7"/>
46+
<field name="DN" start="8" end="8"/>
47+
<field name="EV" start="10" end="10"/>
48+
<field name="EO" start="11" end="11"/>
49+
<field name="EZ" start="12" end="12"/>
50+
<field name="EU" start="13" end="13"/>
51+
<field name="EX" start="14" end="14"/>
52+
<field name="FV" start="26" end="26"/>
53+
<field name="FO" start="27" end="27"/>
54+
<field name="FZ" start="28" end="28"/>
55+
<field name="FU" start="29" end="29"/>
56+
<field name="FX" start="30" end="30"/>
57+
<field name="FS" start="31" end="31"/>
58+
</flags>
59+
60+
<reg name="usp" bitsize="32" type="data_ptr"/>
61+
<reg name="isp" bitsize="32" type="data_ptr"/>
62+
<reg name="psw" bitsize="32" type="psw_flags"/>
63+
<reg name="pc" bitsize="32" type="code_ptr"/>
64+
<reg name="intb" bitsize="32" type="data_ptr"/>
65+
<reg name="bpsw" bitsize="32" type="psw_flags"/>
66+
<reg name="bpc" bitsize="32" type="code_ptr"/>
67+
<reg name="fintv" bitsize="32" type="code_ptr"/>
68+
<reg name="fpsw" bitsize="32" type="fpsw_flags"/>
69+
<reg name="acc" bitsize="64" type="uint64"/>
70+
</feature>

target/rx/Makefile.objs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
obj-y += translate.o op_helper.o helper.o cpu.o gdbstub.o disas.o
2-
obj-$(CONFIG_SOFTMMU) += monitor.o
32

43
DECODETREE = $(SRC_PATH)/scripts/decodetree.py
54

target/rx/cpu-param.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* RX cpu parameters
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_PARAM_H
20+
#define RX_CPU_PARAM_H
21+
22+
#define TARGET_LONG_BITS 32
23+
#define TARGET_PAGE_BITS 12
24+
25+
#define TARGET_PHYS_ADDR_SPACE_BITS 32
26+
#define TARGET_VIRT_ADDR_SPACE_BITS 32
27+
28+
#define NB_MMU_MODES 1
29+
30+
#endif

target/rx/cpu-qom.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* 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+
#ifndef RX_CPU_QOM_H
20+
#define RX_CPU_QOM_H
21+
22+
#include "hw/core/cpu.h"
23+
24+
#define TYPE_RX_CPU "rx-cpu"
25+
26+
#define TYPE_RX62N_CPU RX_CPU_TYPE_NAME("rx62n")
27+
28+
#define RXCPU_CLASS(klass) \
29+
OBJECT_CLASS_CHECK(RXCPUClass, (klass), TYPE_RX_CPU)
30+
#define RXCPU(obj) \
31+
OBJECT_CHECK(RXCPU, (obj), TYPE_RX_CPU)
32+
#define RXCPU_GET_CLASS(obj) \
33+
OBJECT_GET_CLASS(RXCPUClass, (obj), TYPE_RX_CPU)
34+
35+
/*
36+
* RXCPUClass:
37+
* @parent_realize: The parent class' realize handler.
38+
* @parent_reset: The parent class' reset handler.
39+
*
40+
* A RX CPU model.
41+
*/
42+
typedef struct RXCPUClass {
43+
/*< private >*/
44+
CPUClass parent_class;
45+
/*< public >*/
46+
47+
DeviceRealize parent_realize;
48+
DeviceReset parent_reset;
49+
} RXCPUClass;
50+
51+
#define CPUArchState struct CPURXState
52+
53+
#endif

target/rx/cpu.c

+225
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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(DeviceState *dev)
50+
{
51+
RXCPU *cpu = RXCPU(dev);
52+
RXCPUClass *rcc = RXCPU_GET_CLASS(cpu);
53+
CPURXState *env = &cpu->env;
54+
uint32_t *resetvec;
55+
56+
rcc->parent_reset(dev);
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+
ObjectClass *oc = data;
75+
76+
qemu_printf(" %s\n", object_class_get_name(oc));
77+
}
78+
79+
void rx_cpu_list(void)
80+
{
81+
GSList *list;
82+
list = object_class_get_list_sorted(TYPE_RX_CPU, false);
83+
qemu_printf("Available CPUs:\n");
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+
typename = g_strdup_printf(RX_CPU_TYPE_NAME("%s"), cpu_model);
99+
oc = object_class_by_name(typename);
100+
g_free(typename);
101+
if (oc != NULL && object_class_is_abstract(oc)) {
102+
oc = NULL;
103+
}
104+
105+
return oc;
106+
}
107+
108+
static void rx_cpu_realize(DeviceState *dev, Error **errp)
109+
{
110+
CPUState *cs = CPU(dev);
111+
RXCPUClass *rcc = RXCPU_GET_CLASS(dev);
112+
Error *local_err = NULL;
113+
114+
cpu_exec_realizefn(cs, &local_err);
115+
if (local_err != NULL) {
116+
error_propagate(errp, local_err);
117+
return;
118+
}
119+
120+
qemu_init_vcpu(cs);
121+
cpu_reset(cs);
122+
123+
rcc->parent_realize(dev, errp);
124+
}
125+
126+
static void rx_cpu_set_irq(void *opaque, int no, int request)
127+
{
128+
RXCPU *cpu = opaque;
129+
CPUState *cs = CPU(cpu);
130+
int irq = request & 0xff;
131+
132+
static const int mask[] = {
133+
[RX_CPU_IRQ] = CPU_INTERRUPT_HARD,
134+
[RX_CPU_FIR] = CPU_INTERRUPT_FIR,
135+
};
136+
if (irq) {
137+
cpu->env.req_irq = irq;
138+
cpu->env.req_ipl = (request >> 8) & 0x0f;
139+
cpu_interrupt(cs, mask[no]);
140+
} else {
141+
cpu_reset_interrupt(cs, mask[no]);
142+
}
143+
}
144+
145+
static void rx_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
146+
{
147+
info->mach = bfd_mach_rx;
148+
info->print_insn = print_insn_rx;
149+
}
150+
151+
static bool rx_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,
152+
MMUAccessType access_type, int mmu_idx,
153+
bool probe, uintptr_t retaddr)
154+
{
155+
uint32_t address, physical, prot;
156+
157+
/* Linear mapping */
158+
address = physical = addr & TARGET_PAGE_MASK;
159+
prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
160+
tlb_set_page(cs, address, physical, prot, mmu_idx, TARGET_PAGE_SIZE);
161+
return true;
162+
}
163+
164+
static void rx_cpu_init(Object *obj)
165+
{
166+
CPUState *cs = CPU(obj);
167+
RXCPU *cpu = RXCPU(obj);
168+
CPURXState *env = &cpu->env;
169+
170+
cpu_set_cpustate_pointers(cpu);
171+
cs->env_ptr = env;
172+
qdev_init_gpio_in(DEVICE(cpu), rx_cpu_set_irq, 2);
173+
}
174+
175+
static void rx_cpu_class_init(ObjectClass *klass, void *data)
176+
{
177+
DeviceClass *dc = DEVICE_CLASS(klass);
178+
CPUClass *cc = CPU_CLASS(klass);
179+
RXCPUClass *rcc = RXCPU_CLASS(klass);
180+
181+
device_class_set_parent_realize(dc, rx_cpu_realize,
182+
&rcc->parent_realize);
183+
device_class_set_parent_reset(dc, rx_cpu_reset,
184+
&rcc->parent_reset);
185+
186+
cc->class_by_name = rx_cpu_class_by_name;
187+
cc->has_work = rx_cpu_has_work;
188+
cc->do_interrupt = rx_cpu_do_interrupt;
189+
cc->cpu_exec_interrupt = rx_cpu_exec_interrupt;
190+
cc->dump_state = rx_cpu_dump_state;
191+
cc->set_pc = rx_cpu_set_pc;
192+
cc->synchronize_from_tb = rx_cpu_synchronize_from_tb;
193+
cc->gdb_read_register = rx_cpu_gdb_read_register;
194+
cc->gdb_write_register = rx_cpu_gdb_write_register;
195+
cc->get_phys_page_debug = rx_cpu_get_phys_page_debug;
196+
cc->disas_set_info = rx_cpu_disas_set_info;
197+
cc->tcg_initialize = rx_translate_init;
198+
cc->tlb_fill = rx_cpu_tlb_fill;
199+
200+
cc->gdb_num_core_regs = 26;
201+
cc->gdb_core_xml_file = "rx-core.xml";
202+
}
203+
204+
static const TypeInfo rx_cpu_info = {
205+
.name = TYPE_RX_CPU,
206+
.parent = TYPE_CPU,
207+
.instance_size = sizeof(RXCPU),
208+
.instance_init = rx_cpu_init,
209+
.abstract = true,
210+
.class_size = sizeof(RXCPUClass),
211+
.class_init = rx_cpu_class_init,
212+
};
213+
214+
static const TypeInfo rx62n_rx_cpu_info = {
215+
.name = TYPE_RX62N_CPU,
216+
.parent = TYPE_RX_CPU,
217+
};
218+
219+
static void rx_cpu_register_types(void)
220+
{
221+
type_register_static(&rx_cpu_info);
222+
type_register_static(&rx62n_rx_cpu_info);
223+
}
224+
225+
type_init(rx_cpu_register_types)

0 commit comments

Comments
 (0)