Skip to contentSkip to conversation

target/rx: RX disassembler

RFC PATCH Superseded Yoshinori Sato 4 participants 20 messages Mar 2, 2019 – Mar 8, 2019 1 message not in the archive

v3 of 32 Superseded Latest is v32 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

v3 cover Add RX archtecture support

Hello.
This patch series is added Renesas RX target emulation.

My git repository is bellow.
git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.git

Since my understanding is not enough,
I want many comments to make this a good one.

Thanks.

Changes v2
Rewrite translate. using decodetree.py

Yoshinori Sato (11):
target/rx: TCG Translation
target/rx: TCG helper
target/rx: CPU definition
target/rx: RX disassembler
target/rx: miscellaneous functions
RX62N interrupt contorol uint
RX62N internal timer modules
RX62N internal serial communication interface
RX Target hardware definition
Add rx-softmmu
MAINTAINERS: Add RX entry.

 MAINTAINERS                    |   20 +
 arch_init.c                    |    2 +
 configure                      |    8 +
 default-configs/rx-softmmu.mak |    7 +
 hw/char/Makefile.objs          |    2 +-
 hw/char/renesas_sci.c          |  288 ++++++
 hw/intc/Makefile.objs          |    1 +
 hw/intc/rx_icu.c               |  323 ++++++
 hw/rx/Makefile.objs            |    1 +
 hw/rx/rx62n.c                  |  227 ++++
 hw/rx/rxqemu.c                 |  100 ++
 hw/timer/Makefile.objs         |    2 +
 hw/timer/renesas_cmt.c         |  235 +++++
 hw/timer/renesas_tmr.c         |  412 ++++++++
 include/disas/bfd.h            |    5 +
 include/hw/char/renesas_sci.h  |   42 +
 include/hw/intc/rx_icu.h       |   49 +
 include/hw/rx/rx.h             |    7 +
 include/hw/rx/rx62n.h          |   54 +
 include/hw/timer/renesas_cmt.h |   33 +
 include/hw/timer/renesas_tmr.h |   42 +
 include/sysemu/arch_init.h     |    1 +
 target/rx/Makefile.objs        |   11 +
 target/rx/cpu-qom.h            |   52 +
 target/rx/cpu.c                |  224 ++++
 target/rx/cpu.h                |  214 ++++
 target/rx/disas.c              | 1570 ++++++++++++++++++++++++++++
 target/rx/gdbstub.c            |  113 ++
 target/rx/helper.c             |  252 +++++
 target/rx/helper.h             |   39 +
 target/rx/insns.decode         |  336 ++++++
 target/rx/monitor.c            |   38 +
 target/rx/op_helper.c          |  602 +++++++++++
 target/rx/translate.c          | 2220 ++++++++++++++++++++++++++++++++++++++++
 34 files changed, 7531 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/rx-softmmu.mak
 create mode 100644 hw/char/renesas_sci.c
 create mode 100644 hw/intc/rx_icu.c
 create mode 100644 hw/rx/Makefile.objs
 create mode 100644 hw/rx/rx62n.c
 create mode 100644 hw/rx/rxqemu.c
 create mode 100644 hw/timer/renesas_cmt.c
 create mode 100644 hw/timer/renesas_tmr.c
 create mode 100644 include/hw/char/renesas_sci.h
 create mode 100644 include/hw/intc/rx_icu.h
 create mode 100644 include/hw/rx/rx.h
 create mode 100644 include/hw/rx/rx62n.h
 create mode 100644 include/hw/timer/renesas_cmt.h
 create mode 100644 include/hw/timer/renesas_tmr.h
 create mode 100644 target/rx/Makefile.objs
 create mode 100644 target/rx/cpu-qom.h
 create mode 100644 target/rx/cpu.c
 create mode 100644 target/rx/cpu.h
 create mode 100644 target/rx/disas.c
 create mode 100644 target/rx/gdbstub.c
 create mode 100644 target/rx/helper.c
 create mode 100644 target/rx/helper.h
 create mode 100644 target/rx/insns.decode
 create mode 100644 target/rx/monitor.c
 create mode 100644 target/rx/op_helper.c
 create mode 100644 target/rx/translate.c
Signature · 1 line
2.11.0
#2 lore raw

RFC PATCH v3 1/11 target/rx: TCG Translation

This part only supported RXv1 instructions.
Instruction manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01us0032ej0120_rxsm.pdf

---
 target/rx/insns.decode |  336 ++++++++
 target/rx/translate.c  | 2220 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 2556 insertions(+)
 create mode 100644 target/rx/insns.decode
 create mode 100644 target/rx/translate.c
target/rx/insns.decode new file +336 -0
new file mode 100644
index 0000000000..59de4566e0
@@ -0,0 +1,336 @@
+&bcnd		cd dsp
+&jdsp		dsp
+&jreg		rs
+&rr		rd rs
+&ri		rd imm
+&rrr		rd rs rs2
+&rri		rd imm rs2 len
+&rrli		rd rs2 imm
+&rm		rd rs ld mi
+&mi		rs ld mi imm
+&mr		rs ld mi rs2
+
+########
+
+%b2_r_0		16:4
+%b2_li_2	18:2 !function=li
+%b2_li_8	24:2 !function=li
+%b2_dsp5_3	23:4 19:1
+
+@b2_rds		.... .... .... rd:4		&rr rs=255
+@b2_rds_li	.... .... .... rd:4		&rrli rs2=%b2_r_0 imm=%b2_li_8
+@b2_rds_uimm4	.... .... imm:4 rd:4		&rri rs2=255 len=2
+@b2_rds_imm5	.... ... imm:5 rd:4		&rri rs2=255 len=2
+@b2_rd_rs_li	.... .... rs2:4 rd:4		&rrli imm=%b2_li_8
+@b2_rd_ld_ub	.... .. ld:2 rs:4 rd:4		&rm mi=4
+@b2_ld_imm3	.... .. ld:2 rs:4 . imm:3	&mi mi=4
+
+########
+
+%b3_r_0		8:4
+%b3_li_10	18:2 !function=li
+%b3_dsp5_8	23:1 16:4
+
+@b3_rd_rs	.... .... .... .... rs:4 rd:4		&rr
+@b3_rd_li	.... .... .... .... .... rd:4 \
+		&rrli rs2=%b3_r_0 imm=%b3_li_10
+@b3_rd_ld	.... .... mi:2 .... ld:2 rs:4 rd:4	&rm
+@b3_rd_ld_ub	.... .... .... .. ld:2 rs:4 rd:4	&rm mi=4
+@b3_rd_ld_ul	.... .... .... .. ld:2 rs:4 rd:4	&rm mi=2
+@b3_rd_rs_rs2	.... .... .... rd:4 rs:4 rs2:4		&rrr
+@b3_ld_rs2	.... .... .... .. ld:2 rs:4 rs2:4	&mr
+@b3_rds_imm5	.... .... ....... imm:5 rd:4		&rri rs2=%b3_r_0 len=2
+@b3_rd_rs_imm5	.... .... ... imm:5 rs2:4 rd:4		&rri len=2
+
+########
+
+%b4_li_18	18:2 !function=li
+
+@b4_rd_ldmi	.... .... mi:2 .... ld:2 .... .... rs:4 rd:4	&rm
+
+########
+
+ABS_rr		0111 1110 0010 ....			@b2_rds
+ABS_rr		1111 1100 0000 1111 .... ....		@b3_rd_rs
+
+ADC_rli		1111 1101 0111 ..00 0010 ....		@b3_rd_li
+ADC_rr		1111 1100 0000 1011 .... ....		@b3_rd_rs
+# Note only mi==2 allowed.
+ADC_rl		0000 0110 ..10 00.. 0000 0010 .... ....	@b4_rd_ldmi
+
+ADD_rri		0110 0010 .... ....			@b2_rds_uimm4
+ADD_rrli	0111 00.. .... ....			@b2_rd_rs_li
+ADD_rl		0100 10.. .... ....			@b2_rd_ld_ub
+ADD_rl		0000 0110 ..00 10.. .... ....		@b3_rd_ld
+ADD_rrr		1111 1111 0010 .... .... ....		@b3_rd_rs_rs2
+
+AND_ri		0110 0100 .... ....			@b2_rds_uimm4
+AND_rli		0111 01.. 0010 ....			@b2_rds_li
+AND_rl		0101 00.. .... ....			@b2_rd_ld_ub
+AND_rl		0000 0110 ..01 00.. .... ....		@b3_rd_ld
+AND_rrr		1111 1111 0100 .... .... ....		@b3_rd_rs_rs2
+
+BCLR_li		1111 00.. .... 1...			@b2_ld_imm3
+BCLR_ri		0111 101. .... ....			@b2_rds_imm5
+BCLR_lr		1111 1100 0110 01.. .... ....		@b3_ld_rs2 mi=4
+
+BCnd_s		0001 cd:1 dsp:3				&bcnd
+BCnd_b		0010 cd:4 dsp:8				&bcnd
+BCnd_w		0011 101 cd:1 dsp:16			&bcnd
+
+# Note that BNOT has cd = 15
+BMCnd_BNOT_mi	1111 1100 111 imm:3 ld:2 rd:4 cd:4
+BMCnd_BNOT_ri	1111 1101 111 imm:5 cd:4 rd:4
+
+BNOT_lr		1111 1100 0110 11.. .... ....		@b3_ld_rs2 mi=2
+
+BRA_s		0000 1 dsp:3				&jdsp
+#BRA_b		0010 1110 dsp:8		# overlaps BCnd_b
+BRA_w		0011 1000 dsp:16			&jdsp
+BRA_a		0000 0100 dsp:24			&jdsp
+BRA_l		0111 1111 0100 rd:4
+
+BRK		0000 0000
+
+BSET_li		1111 00.. .... 0...			@b2_ld_imm3
+BSET_ri		0111 100. .... ....			@b2_rds_imm5
+BSET_lr		1111 1100 0110 00.. .... ....		@b3_ld_rs2 mi=4
+
+BSR_w		0011 1001 dsp:16			&jdsp
+BSR_a		0000 0101 dsp:24			&jdsp
+BSR_l		0111 1111 0101 rd:4
+
+BTST_li		1111 01.. .... 0...			@b2_ld_imm3
+BTST_ri		0111 110. .... ....			@b2_rds_imm5
+BTST_lr		1111 1100 0110 10.. .... ....		@b3_ld_rs2 mi=4
+
+CLRPSW		0111 1111 1011 cb:4
+
+CMP_ri		0110 0001 .... ....			@b2_rds_uimm4
+CMP_ri		0111 0101 0101 rs2:4 imm:8		&rri rd=0 len=3
+CMP_rli		0111 01.. 0000 rs2:4			&rrli imm=%b2_li_8 rd=0
+CMP_rl		0100 01.. .... ....			@b2_rd_ld_ub
+CMP_rl		0000 0110 ..00 01.. .... ....		@b3_rd_ld
+
+DIV_ri		1111 1101 0111 ..00 1000 ....		@b3_rd_li
+DIV_rl		1111 1100 0010 00.. .... ....		@b3_rd_ld_ub
+DIV_rl		0000 0110 ..10 00.. 0000 1000 .... ....	@b4_rd_ldmi
+
+DIVU_ri		1111 1101 0111 ..00 1001 ....		@b3_rd_li
+DIVU_rl		1111 1100 0010 01.. .... ....		@b3_rd_ld_ub
+DIVU_rl		0000 0110 ..10 00.. 0000 1001 .... ....	@b4_rd_ldmi
+
+EMUL_ri		1111 1101 0111 ..00 0110 ....		@b3_rd_li
+EMUL_rl		1111 1100 0001 10.. .... ....		@b3_rd_ld_ub
+EMUL_rl		0000 0110 ..10 00.. 0000 0110 .... ....	@b4_rd_ldmi
+
+EMULU_ri	1111 1101 0111 ..00 0111 ....		@b3_rd_li
+EMULU_rl	1111 1100 0001 11.. .... ....		@b3_rd_ld_ub
+EMULU_rl	0000 0110 ..10 00.. 0000 0111 .... ....	@b4_rd_ldmi
+
+FADD_ri		1111 1101 0111 0010 0010 rd:4
+FADD_rl		1111 1100 1000 10.. .... ....		@b3_rd_ld_ul
+
+FCMP_ri		1111 1101 0111 0010 0001 rd:4
+FCMP_rl		1111 1100 1000 01.. .... ....		@b3_rd_ld_ul
+
+FDIV_ri		1111 1101 0111 0010 0100 rd:4
+FDIV_rl		1111 1100 1001 00.. .... ....		@b3_rd_ld_ul
+
+FMUL_ri		1111 1101 0111 0010 0011 rd:4
+FMUL_rl		1111 1100 1000 11.. .... ....		@b3_rd_ld_ul
+
+FSUB_ri		1111 1101 0111 0010 0000 rd:4
+FSUB_rl		1111 1100 1000 00.. .... ....		@b3_rd_ld_ul
+
+FTOI		1111 1100 1001 01.. .... ....		@b3_rd_ld_ul
+
+INT		0111 0101 0110 0000 imm:8
+
+ITOF		1111 1100 0100 01.. .... ....		@b3_rd_ld_ub
+ITOF		0000 0110 ..10 00.. 0001 0001 .... ....	@b4_rd_ldmi
+
+JMP		0111 1111 0000 rs:4			&jreg
+JSR		0111 1111 0001 rs:4			&jreg
+
+MACHI		1111 1101 0000 0100 rs:4 rs2:4
+MACLO		1111 1101 0000 0101 rs:4 rs2:4
+
+MAX_ri		1111 1101 0111 ..00 0100 ....		@b3_rd_li
+MAX_rl		1111 1100 0001 00.. .... ....		@b3_rd_ld_ub
+MAX_rl		0000 0110 ..10 00.. 0000 0100 .... ....	@b4_rd_ldmi
+
+MIN_ri		1111 1101 0111 ..00 0101 ....		@b3_rd_li
+MIN_rl		1111 1100 0001 01.. .... ....		@b3_rd_ld_ub
+MIN_rl		0000 0110 ..10 00.. 0000 0101 .... ....	@b4_rd_ldmi
+
+MOV_mr		1000 0 .... rd:3 . rs:3			dsp=%b2_dsp5_3 sz=0
+MOV_mr		1001 0 .... rd:3 . rs:3			dsp=%b2_dsp5_3 sz=1
+MOV_mr		1010 0 .... rd:3 . rs:3			dsp=%b2_dsp5_3 sz=2
+MOV_rm		1000 1 .... rs:3 . rd:3			dsp=%b2_dsp5_3 sz=0
+MOV_rm		1001 1 .... rs:3 . rd:3			dsp=%b2_dsp5_3 sz=1
+MOV_rm		1010 1 .... rs:3 . rd:3			dsp=%b2_dsp5_3 sz=2
+MOV_ri		0110 0110 imm:4 rd:4 len=2
+MOV_mi		0011 1100 . rd:3 .... imm:8		sz=0 dsp=%b3_dsp5_8
+MOV_mi		0011 1101 . rd:3 .... imm:8		sz=1 dsp=%b3_dsp5_8
+MOV_mi		0011 1110 . rd:3 .... imm:8		sz=2 dsp=%b3_dsp5_8
+MOV_ri		0111 0101 0100 rd:4 imm:8 len=3
+MOV_rli		1111 1011 rd:4 .. 10			imm=%b2_li_2
+MOV_mli		1111 1000 rd:4 .. sz:2			dsp=0 imm=%b2_li_2 ld=0
+MOV_mli		1111 1001 rd:4 .. sz:2 dsp:8		imm=%b3_li_10 ld=1
+MOV_mli		1111 1010 rd:4 .. sz:2 dsp:16		imm=%b4_li_18 ld=2
+MOV_ra		1111 1110 01 sz:2 ri:4 rb:4 rd:4
+MOV_ar		1111 1110 00 sz:2 ri:4 rb:4 rs:4
+# Note ldd=3 and lds=3 indicate register src or dst
+MOV_ll		1100 ldd:2 lds:2 rs:4 rd:4		sz=0
+MOV_ll		1101 ldd:2 lds:2 rs:4 rd:4		sz=1
+MOV_ll		1110 ldd:2 lds:2 rs:4 rd:4		sz=2
+MOV_pr		1111 1101 0010 0 ad:1 sz:2 rd:4 rs:4
+MOV_rp		1111 1101 0010 1 ad:1 sz:2 rd:4 rs:4
+
+MOVU_rm		1011 sz:1 ... . rs:3 . rd:3		dsp=%b2_dsp5_3
+MOVU_rl		0101 1 sz:1 ld:2 rs:4 rd:4
+MOVU_ra		1111 1110 110 sz:1 ri:4 rb:4 rd:4
+MOVU_rp		1111 1101 0011 1 ad:1 0 sz:1 rs:4 rd:4
+
+MUL_ri		0110 0011 .... ....			@b2_rds_uimm4
+MUL_rli		0111 01.. 0001 ....			@b2_rds_li
+MUL_rl		0100 11.. .... ....			@b2_rd_ld_ub
+MUL_rl		0000 0110 ..00 11.. .... ....		@b3_rd_ld
+MUL_rrr		1111 1111 0011 .... .... ....		@b3_rd_rs_rs2
+
+MULHI		1111 1101 0000 0000 rs:4 rs2:4
+MULLO		1111 1101 0000 0001 rs:4 rs2:4
+
+MVFACHI		1111 1101 0001 1111 0000 rd:4
+MVFACMI		1111 1101 0001 1111 0010 rd:4
+
+MVFC		1111 1101 0110 1010 cr:4 rd:4
+
+MVTACHI		1111 1101 0001 0111 0000 rs:4
+MVTACLO		1111 1101 0001 0111 0001 rs:4
+
+MVTC_i		1111 1101 0111 ..11 0000 cr:4		imm=%b3_li_10
+MVTC_r		1111 1101 0110 1000 rs:4 cr:4
+
+MVTIPL		0111 0101 0111 0000 0000 imm:4
+
+NEG_rr		0111 1110 0001 ....			@b2_rds
+NEG_rr		1111 1100 0000 0111 .... ....		@b3_rd_rs
+
+NOP		0000 0011
+
+NOT_rr		0111 1110 0000 ....			@b2_rds
+NOT_rr		1111 1100 0011 1011 .... ....		@b3_rd_rs
+
+OR_ri		0110 0101 .... ....			@b2_rds_uimm4
+OR_rli		0111 01.. 0011 ....			@b2_rds_li
+OR_rl		0101 01.. .... ....			@b2_rd_ld_ub
+OR_rl		0000 0110 .. 0101 .. .... ....		@b3_rd_ld
+OR_rrr		1111 1111 0101 .... .... ....		@b3_rd_rs_rs2
+
+POP		0111 1110 1011 rd:4
+POPC		0111 1110 1110 cr:4
+POPM		0110 1111 rd:4 rd2:4
+
+PUSH_r		0111 1110 1000 rs:4			sz=0
+PUSH_r		0111 1110 1001 rs:4			sz=1
+PUSH_r		0111 1110 1010 rs:4			sz=2
+PUSH_m		1111 01 ld:2 rs:4 10 sz:2
+PUSHC		0111 1110 1100 cr:4
+PUSHM		0110 1110 rs:4 rs2:4
+
+RACW		1111 1101 0001 1000 000 imm:1 0000
+
+REVL		1111 1101 0110 0111 rs:4 rd:4
+REVW		1111 1101 0110 0101 rs:4 rd:4
+
+# Note that sz=3 overlaps SMOVF
+RMPA		0111 1111 1000 1100			sz=0
+RMPA		0111 1111 1000 1101			sz=1
+RMPA		0111 1111 1000 1110			sz=2
+
+ROLC		0111 1110 0101 ....			@b2_rds
+RORC		0111 1110 0100 ....			@b2_rds
+
+ROTL_ri		1111 1101 0110 111. .... ....		@b3_rds_imm5
+ROTL_rr		1111 1101 0110 0110 .... ....		@b3_rd_rs
+
+ROTR_ri		1111 1101 0110 110. .... ....		@b3_rds_imm5
+ROTR_rr		1111 1101 0110 0100 .... ....		@b3_rd_rs
+
+ROUND		1111 1100 1001 10 ld:2 rs:4 rd:4
+
+RTE		0111 1111 1001 0101
+
+RTFI		0111 1111 1001 0100
+
+RTS		0000 0010
+
+RTSD_i		0110 0111 imm:8
+RTSD_irr	0011 1111 rd:4 rd2:4 imm:8
+
+SAT		0111 1110 0011 ....			@b2_rds
+SATR		0111 1111 1001 0011
+
+SBB_rr		1111 1100 0000 0011 .... ....		@b3_rd_rs
+# Note only mi==2 allowed.
+SBB_rl		0000 0110 ..10 00.. 0000 0000 .... ....	@b4_rd_ldmi
+
+SCCnd		1111 1100 1101 sz:2 ld:2 rd:4 cd:4
+
+SCMPU		0111 1111 1000 0011
+
+SETPSW		0111 1111 1010 cb:4
+
+SHAR_rri	0110 101. .... ....			@b2_rds_imm5
+SHAR_rri	1111 1101 101. .... .... ....		@b3_rd_rs_imm5
+SHAR_rr		1111 1101 0110 0001 .... ....		@b3_rd_rs
+
+SHLL_rri	0110 110. .... ....			@b2_rds_imm5
+SHLL_rri	1111 1101 110. .... .... ....		@b3_rd_rs_imm5
+SHLL_rr		1111 1101 0110 0010 .... ....		@b3_rd_rs
+
+SHLR_rri	0110 100. .... ....			@b2_rds_imm5
+SHLR_rri	1111 1101 100. .... .... ....		@b3_rd_rs_imm5
+SHLR_rr		1111 1101 0110 0000 .... ....		@b3_rd_rs
+
+SMOVB		0111 1111 1000 1011
+SMOVF		0111 1111 1000 1111
+SMOVU		0111 1111 1000 0111
+
+# Note that sz=3 overlaps SMOVB
+SSTR		0111 1111 1000 1000			sz=0
+SSTR		0111 1111 1000 1001			sz=1
+SSTR		0111 1111 1000 1010			sz=2
+
+STNZ		1111 1101 0111 ..00 1111 ....		@b3_rd_li
+STZ		1111 1101 0111 ..00 1110 ....		@b3_rd_li
+
+SUB_ri		0110 0000 .... ....			@b2_rds_uimm4
+SUB_rl		0100 00.. .... ....			@b2_rd_ld_ub
+SUB_rl		0000 0110 ..00 00.. .... ....		@b3_rd_ld
+SUB_rrr		1111 1111 0000 .... .... ....		@b3_rd_rs_rs2
+
+# Note that sz=3 overlaps SCMPU
+SUNTIL		0111 1111 1000 0000			sz=0
+SUNTIL		0111 1111 1000 0001			sz=1
+SUNTIL		0111 1111 1000 0010			sz=2
+
+# Note that sz=3 overlaps SMOVU
+SWHILE		0111 1111 1000 0100			sz=0
+SWHILE		0111 1111 1000 0101			sz=1
+SWHILE		0111 1111 1000 0110			sz=2
+
+TST_rli		1111 1101 0111 ..00 1100 ....		@b3_rd_li
+TST_rl		1111 1100 0011 00.. .... ....		@b3_rd_ld_ub
+TST_rl		0000 0110 ..10 00.. 0000 1100 .... .... @b4_rd_ldmi
+
+WAIT		0111 1111 1001 0110
+
+XCHG_rl		1111 1100 0100 00.. .... ....		@b3_rd_ld_ub
+XCHG_rl		0000 0110 ..10 00.. 0001 0000 .... ....	@b4_rd_ldmi
+
+XOR_rli		1111 1101 0111 ..00 1101 ....		@b3_rd_li
+XOR_rl		1111 1100 0011 01.. .... ....		@b3_rd_ld_ub
+XOR_rl		0000 0110 ..10 00.. 0000 1101 .... ....	@b4_rd_ldmi
target/rx/translate.c new file +2220 -0

2,220 lines not on this page · raw message

Signature · 1 line
2.11.0
#3 lore raw

RFC PATCH v3 2/11 target/rx: TCG helper

In reply to Yoshinori Sato
---
 target/rx/helper.c    | 252 +++++++++++++++++++++
 target/rx/helper.h    |  39 ++++
 target/rx/op_helper.c | 602 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 893 insertions(+)
 create mode 100644 target/rx/helper.c
 create mode 100644 target/rx/helper.h
 create mode 100644 target/rx/op_helper.c
target/rx/helper.c new file +252 -0
new file mode 100644
index 0000000000..9b0d0eacb4
@@ -0,0 +1,252 @@
+/*
+ *  RX emulation
+ *
+ *  Copyright (c) 2019 Yoshinori Sato
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+
+#include "cpu.h"
+#include "exec/log.h"
+#include "exec/cpu_ldst.h"
+#include "sysemu/sysemu.h"
+
+uint32_t update_psw_o(CPURXState *env)
+{
+    int o;
+
+    switch (env->psw_op) {
+    case RX_PSW_OP_NONE:
+        return env->psw_o;
+    case RX_PSW_OP_ADD: {
+        uint32_t r1, r2;
+        r1 = ~(env->psw_v[0] ^ env->psw_v[1]);
+        r2 = (env->psw_v[0] ^ env->psw_v[2]);
+        o = (r1 & r2) >> 31;
+        break;
+    }
+    case RX_PSW_OP_SUB: {
+        uint32_t r1, r2;
+        r1 = (env->psw_v[0] ^ env->psw_v[1]);
+        r2 = (env->psw_v[0] ^ env->psw_v[2]);
+        o = (r1 & r2) >> 31;
+        break;
+    }
+    case RX_PSW_OP_SHLL: {
+        uint32_t m, v;
+        m = (1 << env->psw_v[1]) - 1;
+        v = env->psw_v[0] >> (32 - env->psw_v[1]);
+        o = (v == 0) || (v == m);
+        break;
+    }
+    default:
+        g_assert_not_reached();
+        return -1;
+    }
+    env->psw_o = o;
+    env->psw_op = RX_PSW_OP_NONE;
+    return o;
+}
+
+uint32_t rx_get_psw_low(CPURXState *env)
+{
+    return (update_psw_o(env) << 3) |
+        (env->psw_s << 2) |
+        (env->psw_z << 1) |
+        (env->psw_c << 0);
+}
+
+uint32_t psw_cond(CPURXState *env, uint32_t cond)
+{
+    uint32_t c, z, s, o;
+
+    switch (cond) {
+    case 0: /* z */
+        return env->psw_z != 0;
+    case 1: /* nz */
+        return env->psw_z == 0;
+    case 2: /* c */
+        return env->psw_c != 0;
+    case 3: /* nc */
+        return env->psw_c == 0;
+    case 4: /* gtu (C&^Z) == 1 */
+    case 5: /* leu (C&^Z) == 0 */
+        c = env->psw_c != 0;
+        z = env->psw_z != 0;
+        return (c && !z) == (5 - cond);
+    case 6: /* pz (S == 0) */
+        return env->psw_s == 0;
+    case 7: /* n (S == 1) */
+        return env->psw_s != 0;
+    case 8: /* ge (S^O)==0 */
+    case 9: /* lt (S^O)==1 */
+        s = env->psw_s != 0;
+        o = update_psw_o(env);
+        return (s | o) == (cond - 8);
+    case 10: /* gt ((S^O)|Z)==0 */
+    case 11: /* le ((S^O)|Z)==1 */
+        s = env->psw_s != 0;
+        o = update_psw_o(env);
+        z = env->psw_z != 0;
+        return ((s ^ o) | z) == (cond - 10);
+    case 12: /* o */
+        return update_psw_o(env) != 0;
+    case 13: /* no */
+        return update_psw_o(env) == 0;
+    case 14: /* always true */
+        return 1;
+    case 15:
+        return 0;
+    default:
+        g_assert_not_reached();
+        return -1;
+    }
+}
+
+void rx_cpu_unpack_psw(CPURXState *env, int all)
+{
+    if (env->psw_pm == 0) {
+        env->psw_ipl = (env->psw >> 24) & 15;
+        if (all) {
+            env->psw_pm = (env->psw >> 20) & 1;
+        }
+        env->psw_u =  (env->psw >> 17) & 1;
+        env->psw_i =  (env->psw >> 16) & 1;
+    }
+    env->psw_o =  (env->psw >> 3) & 1;
+    env->psw_s =  (env->psw >> 2) & 1;
+    env->psw_z =  (env->psw >> 1) & 1;
+    env->psw_c =  (env->psw >> 0) & 1;
+    env->psw_op = RX_PSW_OP_NONE;
+}
+
+void rx_cpu_do_interrupt(CPUState *cs)
+{
+    RXCPU *cpu = RXCPU(cs);
+    CPURXState *env = &cpu->env;
+    int do_irq = cs->interrupt_request &
+        (CPU_INTERRUPT_HARD | CPU_INTERRUPT_SOFT | CPU_INTERRUPT_FIR);
+    int irq_vector = -1;
+
+    env->in_sleep = 0;
+
+    if (do_irq & CPU_INTERRUPT_HARD) {
+        irq_vector = env->irq;
+        cs->interrupt_request &= ~CPU_INTERRUPT_HARD;
+    }
+    if (irq_vector == -1 && do_irq & CPU_INTERRUPT_SOFT) {
+        irq_vector = env->sirq;
+        cs->interrupt_request &= ~CPU_INTERRUPT_SOFT;
+    }
+
+    if (qemu_loglevel_mask(CPU_LOG_INT)) {
+        if (cs->exception_index < 0x100) {
+            const char *expname;
+            switch (cs->exception_index) {
+            case 20:
+                expname = "previlage_violation";
+                break;
+            case 21:
+                expname = "access_exception";
+                break;
+            case 23:
+                expname = "illegal_instruction";
+                break;
+            case 25:
+                expname = "fpu_exception";
+                break;
+            case 30:
+                expname = "NMI_interrupt";
+                break;
+            }
+            qemu_log("exception 0x%02x [%s] raised\n",
+                     cs->exception_index, expname);
+        } else {
+            if (do_irq & CPU_INTERRUPT_FIR)
+                qemu_log("fast interrupt raised\n");
+            else
+                qemu_log("interrupt 0x%02x raised\n",
+                         irq_vector);
+        }
+        log_cpu_state(cs, 0);
+    }
+    if (env->psw_u) {
+        env->usp = env->regs[0];
+    } else {
+        env->isp = env->regs[0];
+    }
+    update_psw_o(env);
+    env->psw = pack_psw(env);
+    if ((do_irq & CPU_INTERRUPT_FIR) == 0) {
+        env->isp -= 4;
+        cpu_stl_all(env, env->isp, env->psw);
+        env->isp -= 4;
+        cpu_stl_all(env, env->isp, env->pc);
+    } else {
+        env->bpc = env->pc;
+        env->bpsw = env->psw;
+    }
+    env->psw_pm = env->psw_i = env->psw_u = 0;
+    env->regs[0] = env->isp;
+    if (do_irq) {
+        if (do_irq & CPU_INTERRUPT_FIR) {
+            env->pc = env->fintv;
+            env->psw_ipl = 15;
+            cs->interrupt_request &= ~CPU_INTERRUPT_FIR;
+            qemu_set_irq(env->ack, 0);
+            return;
+        } else if (do_irq & CPU_INTERRUPT_HARD) {
+            env->psw_ipl = env->intlevel;
+            qemu_set_irq(env->ack, 0);
+        }
+        env->pc = cpu_ldl_all(env, env->intb + irq_vector * 4);
+        return;
+    } else {
+        uint32_t vec = cs->exception_index;
+        env->pc = cpu_ldl_all(env, 0xffffffc0 + vec * 4);
+        return;
+    }
+}
+
+bool rx_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
+{
+    RXCPU *cpu = RXCPU(cs);
+    CPURXState *env = &cpu->env;
+    int accept = 0;
+    /* software interrupt */
+    if (interrupt_request & CPU_INTERRUPT_SOFT) {
+        accept = 1;
+    }
+    /* hardware interrupt (Normal) */
+    if ((interrupt_request & CPU_INTERRUPT_HARD) &&
+        env->psw_i && (env->psw_ipl < env->intlevel)) {
+        accept = 1;
+    }
+    /* hardware interrupt (FIR) */
+    if ((interrupt_request & CPU_INTERRUPT_FIR) &&
+        env->psw_i && (env->psw_ipl < 15)) {
+        accept = 1;
+    }
+    if (accept) {
+        rx_cpu_do_interrupt(cs);
+        return true;
+    }
+    return false;
+}
+
+hwaddr rx_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
+{
+    return addr;
+}
target/rx/helper.h new file +39 -0
new file mode 100644
index 0000000000..06a3d29486
@@ -0,0 +1,39 @@
+DEF_HELPER_1(raise_illegal_instruction, noreturn, env)
+DEF_HELPER_1(raise_access_fault, noreturn, env)
+DEF_HELPER_1(raise_privilege_violation, noreturn, env)
+DEF_HELPER_1(wait, noreturn, env)
+DEF_HELPER_1(debug, noreturn, env)
+DEF_HELPER_2(rxint, noreturn, env, i32)
+DEF_HELPER_1(rxbrk, noreturn, env)
+DEF_HELPER_FLAGS_3(fadd, TCG_CALL_NO_WG, f32, env, f32, f32)
+DEF_HELPER_FLAGS_3(fsub, TCG_CALL_NO_WG, f32, env, f32, f32)
+DEF_HELPER_FLAGS_3(fmul, TCG_CALL_NO_WG, f32, env, f32, f32)
+DEF_HELPER_FLAGS_3(fdiv, TCG_CALL_NO_WG, f32, env, f32, f32)
+DEF_HELPER_FLAGS_3(fcmp, TCG_CALL_NO_WG, void, env, f32, f32)
+DEF_HELPER_FLAGS_2(ftoi, TCG_CALL_NO_WG, i32, env, f32)
+DEF_HELPER_FLAGS_2(round, TCG_CALL_NO_WG, i32, env, f32)
+DEF_HELPER_FLAGS_2(itof, TCG_CALL_NO_WG, f32, env, i32)
+DEF_HELPER_FLAGS_2(racw, TCG_CALL_NO_WG, void, env, i32)
+DEF_HELPER_1(psw_o, i32, env)
+DEF_HELPER_3(mvtc, void, env, i32, i32)
+DEF_HELPER_2(mvfc, i32, env, i32)
+DEF_HELPER_FLAGS_2(sccond, TCG_CALL_NO_WG, i32, env, i32)
+DEF_HELPER_FLAGS_4(brcond, TCG_CALL_NO_WG, i32, env, i32, i32, i32)
+DEF_HELPER_FLAGS_4(bmcond, TCG_CALL_NO_WG, i32, env, i32, i32, i32)
+DEF_HELPER_1(unpack_psw, void, env)
+DEF_HELPER_FLAGS_3(div, TCG_CALL_NO_WG, i32, env, i32, i32)
+DEF_HELPER_FLAGS_3(divu, TCG_CALL_NO_WG, i32, env, i32, i32)
+DEF_HELPER_FLAGS_1(scmpu, TCG_CALL_NO_WG, void, env)
+DEF_HELPER_1(smovu, void, env)
+DEF_HELPER_1(smovf, void, env)
+DEF_HELPER_1(smovb, void, env)
+DEF_HELPER_2(sstr, void, env, i32)
+DEF_HELPER_FLAGS_2(swhile, TCG_CALL_NO_WG, void, env, i32)
+DEF_HELPER_FLAGS_2(suntil, TCG_CALL_NO_WG, void, env, i32)
+DEF_HELPER_FLAGS_2(rmpa, TCG_CALL_NO_WG, void, env, i32)
+DEF_HELPER_2(mulhi, void, env, i32)
+DEF_HELPER_2(mullo, void, env, i32)
+DEF_HELPER_2(machi, void, env, i32)
+DEF_HELPER_2(maclo, void, env, i32)
+DEF_HELPER_2(sat, void, env, i32)
+DEF_HELPER_1(satr, void, env)
target/rx/op_helper.c new file +602 -0

602 lines not on this page · raw message

Signature · 1 line
2.11.0
#4 lore raw

RFC PATCH v3 3/11 target/rx: CPU definition

In reply to Yoshinori Sato
---
 target/rx/cpu-qom.h |  52 ++++++++++++
 target/rx/cpu.c     | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 target/rx/cpu.h     | 214 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 490 insertions(+)
 create mode 100644 target/rx/cpu-qom.h
 create mode 100644 target/rx/cpu.c
 create mode 100644 target/rx/cpu.h
target/rx/cpu-qom.h new file +52 -0
new file mode 100644
index 0000000000..bad6d2c75d
@@ -0,0 +1,52 @@
+/*
+ * QEMU RX CPU
+ *
+ * Copyright (c) 2019 Yoshinori Sato
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef QEMU_RX_CPU_QOM_H
+#define QEMU_RX_CPU_QOM_H
+
+#include "qom/cpu.h"
+
+#define TYPE_RXCPU "rxcpu"
+
+#define RXCPU_CLASS(klass)                                     \
+    OBJECT_CLASS_CHECK(RXCPUClass, (klass), TYPE_RXCPU)
+#define RXCPU(obj) \
+    OBJECT_CHECK(RXCPU, (obj), TYPE_RXCPU)
+#define RXCPU_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(RXCPUClass, (obj), TYPE_RXCPU)
+
+/*
+ * RXCPUClass:
+ * @parent_realize: The parent class' realize handler.
+ * @parent_reset: The parent class' reset handler.
+ *
+ * A RX CPU model.
+ */
+typedef struct RXCPUClass {
+    /*< private >*/
+    CPUClass parent_class;
+    /*< public >*/
+
+    DeviceRealize parent_realize;
+    void (*parent_reset)(CPUState *cpu);
+
+} RXCPUClass;
+
+typedef struct RXCPU RXCPU;
+
+#endif
target/rx/cpu.c new file +224 -0

224 lines not on this page · raw message

target/rx/cpu.h new file +214 -0

214 lines not on this page · raw message

Signature · 1 line
2.11.0
#5 lore raw

RFC PATCH v3 4/11 target/rx: RX disassembler

In reply to Yoshinori Sato
---
 include/disas/bfd.h |    5 +
 target/rx/disas.c   | 1570 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1575 insertions(+)
 create mode 100644 target/rx/disas.c
include/disas/bfd.h +5 -0
index 41b61c85f9..b2c34274dd 100644
@@ -228,6 +228,10 @@ enum bfd_architecture
 #define bfd_mach_nios2r2        2
   bfd_arch_lm32,       /* Lattice Mico32 */
 #define bfd_mach_lm32 1
+  bfd_arch_rx,       /* Renesas RX */
+#define bfd_mach_rx            0x75
+#define bfd_mach_rx_v2         0x76
+#define bfd_mach_rx_v3         0x77
   bfd_arch_last
   };
 #define bfd_mach_s390_31 31
@@ -432,6 +436,7 @@ int print_insn_little_nios2     (bfd_vma, disassemble_info*);
 int print_insn_xtensa           (bfd_vma, disassemble_info*);
 int print_insn_riscv32          (bfd_vma, disassemble_info*);
 int print_insn_riscv64          (bfd_vma, disassemble_info*);
+int print_insn_rx(bfd_vma, disassemble_info *);
 
 #if 0
 /* Fetch the disassembler for a given BFD, if that support is available.  */
target/rx/disas.c new file +1570 -0

1,570 lines not on this page · raw message

Signature · 1 line
2.11.0
#6 lore raw

RFC PATCH v3 5/11 target/rx: miscellaneous functions

In reply to Yoshinori Sato
---
 target/rx/Makefile.objs |  11 +++++
 target/rx/gdbstub.c     | 113 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/rx/monitor.c     |  38 ++++++++++++++++
 3 files changed, 162 insertions(+)
 create mode 100644 target/rx/Makefile.objs
 create mode 100644 target/rx/gdbstub.c
 create mode 100644 target/rx/monitor.c
target/rx/Makefile.objs new file +11 -0
new file mode 100644
index 0000000000..f63e1ca43f
@@ -0,0 +1,11 @@
+obj-y += translate.o op_helper.o helper.o cpu.o gdbstub.o disas.o
+obj-$(CONFIG_SOFTMMU) += monitor.o
+
+DECODETREE = $(SRC_PATH)/scripts/decodetree.py
+
+target/rx/decode.inc.c: \
+  $(SRC_PATH)/target/rx/insns.decode $(DECODETREE)
+	$(call quiet-command,\
+	  $(PYTHON) $(DECODETREE) --varinsnwidth 32 -o $@ $<, "GEN", $(TARGET_DIR)$@)
+
+target/rx/translate.o: target/rx/decode.inc.c
target/rx/gdbstub.c new file +113 -0

113 lines not on this page · raw message

target/rx/monitor.c new file +38 -0
new file mode 100644
index 0000000000..5d7a1e58b5
@@ -0,0 +1,38 @@
+/*
+ * QEMU monitor
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp-target.h"
+#include "hmp.h"
+
+void hmp_info_tlb(Monitor *mon, const QDict *qdict)
+{
+    CPUArchState *env = mon_get_cpu_env();
+
+    if (!env) {
+        monitor_printf(mon, "No CPU available\n");
+        return;
+    }
+}
Signature · 1 line
2.11.0
#7 lore raw

RFC PATCH v3 6/11 RX62N interrupt contorol uint

In reply to Yoshinori Sato

This implementation supported only ICUa.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf?key=086621e01bd70347c18ea7f794aa9cc3

---
 hw/intc/Makefile.objs    |   1 +
 hw/intc/rx_icu.c         | 323 +++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/intc/rx_icu.h |  49 +++++++
 3 files changed, 373 insertions(+)
 create mode 100644 hw/intc/rx_icu.c
 create mode 100644 include/hw/intc/rx_icu.h
hw/intc/Makefile.objs +1 -0
index 301a8e972d..ff79edb54b 100644
@@ -48,3 +48,4 @@ obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o
 obj-$(CONFIG_MIPS_CPS) += mips_gic.o
 obj-$(CONFIG_NIOS2) += nios2_iic.o
 obj-$(CONFIG_OMPIC) += ompic.o
+obj-$(CONFIG_RX) += rx_icu.o
hw/intc/rx_icu.c new file +323 -0

323 lines not on this page · raw message

include/hw/intc/rx_icu.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.11.0
#8 lore raw

RFC PATCH v3 7/11 RX62N internal timer modules

In reply to Yoshinori Sato

renesas_tmr: 8bit timer modules.
renesas_cmt: 16bit compare match timer modules.
This part use many renesas's CPU.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf?key=086621e01bd70347c18ea7f794aa9cc3

---
 hw/timer/Makefile.objs         |   2 +
 hw/timer/renesas_cmt.c         | 235 +++++++++++++++++++++++
 hw/timer/renesas_tmr.c         | 412 +++++++++++++++++++++++++++++++++++++++++
 include/hw/timer/renesas_cmt.h |  33 ++++
 include/hw/timer/renesas_tmr.h |  42 +++++
 5 files changed, 724 insertions(+)
 create mode 100644 hw/timer/renesas_cmt.c
 create mode 100644 hw/timer/renesas_tmr.c
 create mode 100644 include/hw/timer/renesas_cmt.h
 create mode 100644 include/hw/timer/renesas_tmr.h
hw/timer/Makefile.objs +2 -0
index 0e9a4530f8..e11aaf5bf5 100644
@@ -40,6 +40,8 @@ obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
 
 obj-$(CONFIG_ALLWINNER_A10_PIT) += allwinner-a10-pit.o
 
+obj-$(CONFIG_RX) += renesas_tmr.o renesas_cmt.o
+
 common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o
 common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o
 
hw/timer/renesas_cmt.c new file +235 -0

235 lines not on this page · raw message

hw/timer/renesas_tmr.c new file +412 -0

412 lines not on this page · raw message

include/hw/timer/renesas_cmt.h new file +33 -0
new file mode 100644
index 0000000000..764759d4ad
@@ -0,0 +1,33 @@
+/*
+ * Renesas Compare-match timer Object
+ *
+ * Copyright (c) 2018 Yoshinori Sato
+ *
+ * This code is licensed under the GPL version 2 or later.
+ *
+ */
+
+#ifndef HW_RENESAS_CMT_H
+#define HW_RENESAS_CMT_H
+
+#include "hw/sysbus.h"
+
+#define TYPE_RENESAS_CMT "renesas-cmt"
+#define RCMT(obj) OBJECT_CHECK(RCMTState, (obj), TYPE_RENESAS_CMT)
+
+typedef struct RCMTState {
+    SysBusDevice parent_obj;
+
+    uint64_t input_freq;
+    MemoryRegion memory;
+
+    uint16_t cmstr;
+    uint16_t cmcr[2];
+    uint16_t cmcnt[2];
+    uint16_t cmcor[2];
+    int64_t tick[2];
+    qemu_irq cmi[2];
+    QEMUTimer *timer[2];
+} RCMTState;
+
+#endif
include/hw/timer/renesas_tmr.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.11.0
#9 lore raw

RFC PATCH v3 8/11 RX62N internal serial communication interface

In reply to Yoshinori Sato

This module supported only non FIFO type.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf?key=086621e01bd70347c18ea7f794aa9cc3

---
 hw/char/Makefile.objs         |   2 +-
 hw/char/renesas_sci.c         | 288 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/char/renesas_sci.h |  42 ++++++
 3 files changed, 331 insertions(+), 1 deletion(-)
 create mode 100644 hw/char/renesas_sci.c
 create mode 100644 include/hw/char/renesas_sci.h
hw/char/Makefile.objs +1 -1
index c4947d7ae7..68eae7b9a5 100644
@@ -15,7 +15,7 @@ common-obj-$(CONFIG_CADENCE) += cadence_uart.o
 obj-$(CONFIG_EXYNOS4) += exynos4210_uart.o
 obj-$(CONFIG_COLDFIRE) += mcf_uart.o
 obj-$(CONFIG_OMAP) += omap_uart.o
-obj-$(CONFIG_SH4) += sh_serial.o
+obj-$(CONFIG_RENESAS_SCI) += renesas_sci.o
 obj-$(CONFIG_PSERIES) += spapr_vty.o
 obj-$(CONFIG_DIGIC) += digic-uart.o
 obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o
hw/char/renesas_sci.c new file +288 -0

288 lines not on this page · raw message

include/hw/char/renesas_sci.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.11.0
#10 lore raw

Re: [Qemu-devel] [PATCH RFC v3 08/11] RX62N internal serial communication interface

Hi Yoshinori,

Quoted 3 lines · Yoshinori Sato

This module supported only non FIFO type.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf?key=086621e01bd70347c18ea7f794aa9cc3

This link also works without the trailing
"?key=086621e01bd70347c18ea7f794aa9cc3".

Quoted 6 lines
---
 hw/char/Makefile.objs         |   2 +-
 hw/char/renesas_sci.c         | 288 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/char/renesas_sci.h |  42 ++++++

QEMU provides a git config helper to improve git diff by showing headers first and C sources after: scripts/git.orderfile
I recommend you to look at it.

I'll review the header, then back to source.

Quoted 23 lines
 3 files changed, 331 insertions(+), 1 deletion(-)
 create mode 100644 hw/char/renesas_sci.c
 create mode 100644 include/hw/char/renesas_sci.h
hw/char/Makefile.objs +1 -1
index c4947d7ae7..68eae7b9a5 100644
@@ -15,7 +15,7 @@ common-obj-$(CONFIG_CADENCE) += cadence_uart.o
 obj-$(CONFIG_EXYNOS4) += exynos4210_uart.o
 obj-$(CONFIG_COLDFIRE) += mcf_uart.o
 obj-$(CONFIG_OMAP) += omap_uart.o
-obj-$(CONFIG_SH4) += sh_serial.o
+obj-$(CONFIG_RENESAS_SCI) += renesas_sci.o
 obj-$(CONFIG_PSERIES) += spapr_vty.o
 obj-$(CONFIG_DIGIC) += digic-uart.o
 obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o
hw/char/renesas_sci.c new file +0 -0
new file mode 100644
index 0000000000..56d070a329

hw/char/renesas_sci.c line 2

Quoted 2 lines
hw/char/renesas_sci.c new file +2 -0
@@ -0,0 +1,288 @@
+/*
+ * Renesas Serial Communication Interface

I'd add here:

Datasheet: RX62N Group, RX621 Group User's Manual: Hardware (Rev.1.40 R01UH0033EJ0140)

Quoted 15 lines
hw/char/renesas_sci.c new file +15 -0
+ *
+ * Copyright (c) 2019 Yoshinori Sato
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */

hw/char/renesas_sci.c line 27

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "cpu.h"
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/char/renesas_sci.h"
+#include "qemu/error-report.h"
+
+#define freq_to_ns(freq) (1000000000LL / freq)

You can directly use NANOSECONDS_PER_SECOND in update_trtime().

hw/char/renesas_sci.c line 35

Quoted 8 lines
hw/char/renesas_sci.c new file +8 -0
+
+static int can_receive(void *opaque)
+{
+    RSCIState *sci = RSCI(opaque);
+    if (sci->rx_next > qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) {
+        return 0;
+    } else {
+        return sci->scr & 0x10;

It is way easier to review a code using definitions generated by the "hw/registerfields.h" API, a recent example is hw/char/cmsdk-apb-uart.c.

Quoted 8 lines
hw/char/renesas_sci.c new file +8 -0
+    }
+}
+
+static void receive(void *opaque, const uint8_t *buf, int size)
+{
+    RSCIState *sci = RSCI(opaque);
+    sci->rdr = buf[0];
+    if (sci->ssr & 0x40 || size > 1) {

hw/char/renesas_sci.c line 53

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+        sci->ssr |= 0x20;
+        if (sci->scr & 0x40) {
+            qemu_set_irq(sci->irq[ERI], 1);
+        }
+    } else {
+        sci->ssr |= 0x40;
+        sci->rx_next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + sci->trtime;
+        if (sci->scr & 0x40) {
+            qemu_set_irq(sci->irq[RXI], 1);
+            qemu_set_irq(sci->irq[RXI], 0);

Both lines are equivalent to:

               qemu_irq_pulse(sci->irq[RXI]);
Quoted 33 lines
hw/char/renesas_sci.c new file +33 -0
+        }
+    }
+}
+
+static void send_byte(RSCIState *sci)
+{
+    if (qemu_chr_fe_backend_connected(&sci->chr)) {
+        qemu_chr_fe_write_all(&sci->chr, &sci->tdr, 1);
+    }
+    timer_mod(sci->timer,
+              qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + sci->trtime);
+    sci->ssr &= ~0x04;
+    sci->ssr |= 0x80;
+    qemu_set_irq(sci->irq[TEI], 0);
+    if (sci->scr & 0x80) {
+        qemu_set_irq(sci->irq[TXI], 1);
+        qemu_set_irq(sci->irq[TXI], 0);
+    }
+}
+
+static void txend(void *opaque)
+{
+    RSCIState *sci = RSCI(opaque);
+    if ((sci->ssr & 0x80) == 0) {
+        send_byte(sci);
+    } else {
+        sci->ssr |= 0x04;
+        if (sci->scr & 0x04) {
+            qemu_set_irq(sci->irq[TEI], 1);
+        }
+    }
+}
+

hw/char/renesas_sci.c line 96

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+static void update_trtime(RSCIState *sci)
+{
+    static const int div[] = {1, 4, 16, 64};
+    int w;
+
+    w = (sci->smr & 0x40) ? 7 : 8;      /* CHR */
+    w += (sci->smr >> 5) & 1;           /* PE */
+    w += (sci->smr & 0x08) ? 2 : 1;     /* STOP */
+    sci->trtime = w * freq_to_ns(sci->input_freq) *
+        32 * div[sci->smr & 0x03] * sci->brr;

Or:

       sci->trtime   = (sci->smr & 0x40) ? 7 : 8;
       sci->trtime  += (sci->smr >> 5) & 1;
       sci->trtime  += (sci->smr & 0x08) ? 2 : 1;
       sci->trtime  *= 32 * sci->brr;
       sci->trtime <<= 2 * (sci->smr & 0x03);
       sci->trtime  *= NANOSECONDS_PER_SECOND;
       sci->trtime  /= sci->input_freq;

hw/char/renesas_sci.c line 101

Quoted 5 lines
hw/char/renesas_sci.c new file +5 -0
+}
+
+static void sci_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    hwaddr offset = addr & 0x07;

You create the region with memory_region_init_io(size=8), so no need to &=7.

Quoted 30 lines
hw/char/renesas_sci.c new file +30 -0
+    RSCIState *sci = RSCI(opaque);
+    int error = 0;
+
+    switch (offset) {
+    case 0: /* SMR */
+        if ((sci->scr & 0x30) == 0) {
+            sci->smr = val;
+            update_trtime(sci);
+        }
+        break;
+    case 1: /* BRR */
+        if ((sci->scr & 0x30) == 0) {
+            sci->brr = val;
+            update_trtime(sci);
+        }
+        break;
+    case 2: /* SCR */
+        sci->scr = val;
+        if (sci->scr & 0x20) {
+            sci->ssr |= 0x84;
+            qemu_set_irq(sci->irq[TXI], 1);
+            qemu_set_irq(sci->irq[TXI], 0);
+        }
+        if ((sci->scr & 0x04) == 0) {
+            qemu_set_irq(sci->irq[TEI], 0);
+        }
+        if ((sci->scr & 0x40) == 0) {
+            qemu_set_irq(sci->irq[ERI], 0);
+        }
+        break;

hw/char/renesas_sci.c line 141

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+    case 3: /* TDR */
+        sci->tdr = val;
+        if (sci->ssr & 0x04) {
+            send_byte(sci);
+        } else{
+            sci->ssr &= ~0x80;
+        }
+        break;
+    case 4: /* SSR */
+        sci->ssr &= ~0x38 | (val & 0x38);

This expression is not clear... Don't you want:

           sci->ssr &= ~0x38;
           sci->ssr |= val & 0x38;

hw/char/renesas_sci.c line 143

Quoted 2 lines
hw/char/renesas_sci.c new file +2 -0
+        if (((sci->read_ssr & 0x38) ^ (sci->ssr & 0x38)) &&
+            (sci->ssr & 0x38) == 0) {

Is this equivalent to:

           if ((sci->ssr & 0x38) == 0 && (sci->read_ssr & 0x38) != 0) {

hw/char/renesas_sci.c line 148

Quoted 5 lines
hw/char/renesas_sci.c new file +5 -0
+            qemu_set_irq(sci->irq[ERI], 0);
+        }
+        break;
+    case 5: /* RDR */
+        error = 1; break;

Here error is due to read-only register, QEMU provides:

qemu_log_mask(LOG_GUEST_ERROR, "Read only register: "...

hw/char/renesas_sci.c line 156

Quoted 8 lines
hw/char/renesas_sci.c new file +8 -0
+    case 6: /* SCMR */
+        sci->scmr = val; break;
+    case 7: /* SEMR */
+        sci->semr = val; break;
+    }
+
+    if (error) {
+        error_report("rsci: unsupported write request to %08lx", addr);

"unsupported" is not very clear, for unimplemented you can use:

           qemu_log_mask(LOG_UNIMP,
                         "Register XX not implemented\n");
Quoted 31 lines
hw/char/renesas_sci.c new file +31 -0
+    }
+}
+
+static uint64_t sci_read(void *opaque, hwaddr addr, unsigned size)
+{
+    hwaddr offset = addr & 0x07;
+    RSCIState *sci = RSCI(opaque);
+    int error = 0;
+    switch (offset) {
+    case 0: /* SMR */
+        return sci->smr;
+    case 1: /* BRR */
+        return sci->brr;
+    case 2: /* SCR */
+        return sci->scr;
+    case 3: /* TDR */
+        return sci->tdr;
+    case 4: /* SSR */
+        sci->read_ssr = sci->ssr;
+        return sci->ssr;
+    case 5: /* RDR */
+        sci->ssr &= ~0x40;
+        return sci->rdr;
+    case 6: /* SCMR */
+        return sci->scmr;
+    case 7: /* SEMR */
+        return sci->semr;
+    }
+
+    if (error) {
+        error_report("rsci: unsupported write request to %08lx", addr);

hw/char/renesas_sci.c line 197

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+    }
+    return -1;
+}
+
+static const MemoryRegionOps sci_ops = {
+    .write = sci_write,
+    .read  = sci_read,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,

You can drop the implicit ".min_access_size = 1".

Quoted 24 lines
hw/char/renesas_sci.c new file +24 -0
+        .max_access_size = 1,
+    },
+};
+
+static void rsci_reset(DeviceState *dev)
+{
+    RSCIState *sci = RSCI(dev);
+    sci->smr = sci->scr = 0x00;
+    sci->brr = 0xff;
+    sci->tdr = 0xff;
+    sci->rdr = 0x00;
+    sci->ssr = 0x84;
+    sci->scmr = 0x00;
+    sci->semr = 0x00;
+    sci->rx_next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+}
+
+static void sci_event(void *opaque, int event)
+{
+    RSCIState *sci = RSCI(opaque);
+    if (event == CHR_EVENT_BREAK) {
+        sci->ssr |= 0x10;
+        if (sci->scr & 0x40) {
+            qemu_set_irq(sci->irq[ERI], 1);

hw/char/renesas_sci.c line 231

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+        }
+    }
+}
+
+static void rsci_realize(DeviceState *dev, Error **errp)
+{
+    RSCIState *sci = RSCI(dev);
+
+    qemu_chr_fe_set_handlers(&sci->chr, can_receive, receive,
+                             sci_event, NULL, sci, NULL, true);

You might want to check s->input_freq != 0 here.

hw/char/renesas_sci.c line 244

Quoted 13 lines
hw/char/renesas_sci.c new file +13 -0
+}
+
+static void rsci_init(Object *obj)
+{
+    SysBusDevice *d = SYS_BUS_DEVICE(obj);
+    RSCIState *sci = RSCI(obj);
+    int i;
+
+    memory_region_init_io(&sci->memory, OBJECT(sci), &sci_ops,
+                          sci, "renesas-sci", 0x8);
+    sysbus_init_mmio(d, &sci->memory);
+
+    for (i = 0; i < 4; i++) {

4 -> ARRAY_COUNT(sci->irq) or SCI_IRQ_COUNT.

Quoted 56 lines
hw/char/renesas_sci.c new file +44 -0
+        sysbus_init_irq(d, &sci->irq[i]);
+    }
+    sci->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, txend, sci);
+}
+
+static const VMStateDescription vmstate_rcmt = {
+    .name = "renesas-sci",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property rsci_properties[] = {
+    DEFINE_PROP_UINT64("input-freq", RSCIState, input_freq, 0),
+    DEFINE_PROP_CHR("chardev", RSCIState, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void rsci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = rsci_realize;
+    dc->props = rsci_properties;
+    dc->vmsd = &vmstate_rcmt;
+    dc->reset = rsci_reset;
+}
+
+static const TypeInfo rsci_info = {
+    .name       = TYPE_RENESAS_SCI,
+    .parent     = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(RSCIState),
+    .instance_init = rsci_init,
+    .class_init = rsci_class_init,
+};
+
+static void rsci_register_types(void)
+{
+    type_register_static(&rsci_info);
+}
+
+type_init(rsci_register_types)
include/hw/char/renesas_sci.h new file +6 -0
new file mode 100644
index 0000000000..47e3e7a5d7
@@ -0,0 +1,42 @@
+/*
+ * Renesas Serial Communication Interface
+ *
+ * Copyright (c) 2018 Yoshinori Sato
+ *
+ * This code is licensed under the GPL version 2 or later.

include/hw/char/renesas_sci.h line 16

Quoted 10 lines
include/hw/char/renesas_sci.h new file +10 -0
+ *
+ */
+
+#include "chardev/char-fe.h"
+#include "qemu/timer.h"
+#include "hw/sysbus.h"
+
+#define TYPE_RENESAS_SCI "renesas-sci"
+#define RSCI(obj) OBJECT_CHECK(RSCIState, (obj), TYPE_RENESAS_SCI)
+

Since those definitions are related, I recommend using:

enum SciIrqIndex {
    ERI = 0,
    RXI = 1,
    ...

include/hw/char/renesas_sci.h line 20

Quoted 4 lines
include/hw/char/renesas_sci.h new file +4 -0
+#define ERI 0
+#define RXI 1
+#define TXI 2
+#define TEI 3

SCI_IRQ_COUNT = 4
};

Quoted 7 lines
include/hw/char/renesas_sci.h new file +7 -0
+
+typedef struct {
+    SysBusDevice parent_obj;
+    MemoryRegion memory;
+
+    uint8_t smr;
+    uint8_t brr;

include/hw/char/renesas_sci.h line 37

Quoted 10 lines
include/hw/char/renesas_sci.h new file +10 -0
+    uint8_t scr;
+    uint8_t tdr;
+    uint8_t ssr;
+    uint8_t rdr;
+    uint8_t scmr;
+    uint8_t semr;
+
+    uint8_t read_ssr;
+    long long trtime;
+    long long rx_next;

Can you use int64_t to keep both consistent?

include/hw/char/renesas_sci.h line 41

Quoted 4 lines
include/hw/char/renesas_sci.h new file +4 -0
+    QEMUTimer *timer;
+    CharBackend chr;
+    uint64_t input_freq;
+    qemu_irq irq[4];

Now you can use irq[SCI_IRQ_COUNT];

include/hw/char/renesas_sci.h line 42

Quoted 2 lines
include/hw/char/renesas_sci.h new file +1 -0
+} RSCIState;

Regards,

Phil.

#11 lore raw

Re: [Qemu-devel] [PATCH RFC v3 08/11] RX62N internal serial communication interface

Quoted 10 lines · Philippe Mathieu-Daudé

Hi Yoshinori,

Quoted 3 lines · Yoshinori Sato

This module supported only non FIFO type.
Hardware manual.
https://www.renesas.com/us/en/doc/products/mpumcu/doc/rx_family/r01uh0033ej0140_rx62n.pdf?key=086621e01bd70347c18ea7f794aa9cc3

This link also works without the trailing
"?key=086621e01bd70347c18ea7f794aa9cc3".

OK.
It is probably a parameter for searching. remove it.

Quoted 10 lines
Quoted 6 lines
---
 hw/char/Makefile.objs         |   2 +-
 hw/char/renesas_sci.c         | 288 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/char/renesas_sci.h |  42 ++++++

QEMU provides a git config helper to improve git diff by showing headers first and C sources after: scripts/git.orderfile
I recommend you to look at it.

OK.

Quoted 30 lines

I'll review the header, then back to source.

Quoted 23 lines
 3 files changed, 331 insertions(+), 1 deletion(-)
 create mode 100644 hw/char/renesas_sci.c
 create mode 100644 include/hw/char/renesas_sci.h
hw/char/Makefile.objs +1 -1
index c4947d7ae7..68eae7b9a5 100644
@@ -15,7 +15,7 @@ common-obj-$(CONFIG_CADENCE) += cadence_uart.o
 obj-$(CONFIG_EXYNOS4) += exynos4210_uart.o
 obj-$(CONFIG_COLDFIRE) += mcf_uart.o
 obj-$(CONFIG_OMAP) += omap_uart.o
-obj-$(CONFIG_SH4) += sh_serial.o
+obj-$(CONFIG_RENESAS_SCI) += renesas_sci.o
 obj-$(CONFIG_PSERIES) += spapr_vty.o
 obj-$(CONFIG_DIGIC) += digic-uart.o
 obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o
hw/char/renesas_sci.c new file +0 -0
new file mode 100644
index 0000000000..56d070a329

hw/char/renesas_sci.c line 2

Quoted 2 lines
hw/char/renesas_sci.c new file +2 -0
@@ -0,0 +1,288 @@
+/*
+ * Renesas Serial Communication Interface

I'd add here:

Quoted 2 lines

Datasheet: RX62N Group, RX621 Group User's Manual: Hardware (Rev.1.40 R01UH0033EJ0140)

OK.

Quoted 19 lines
Quoted 19 lines
hw/char/renesas_sci.c new file +19 -0
+ *
+ * Copyright (c) 2019 Yoshinori Sato
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "cpu.h"
Quoted 8 lines

hw/char/renesas_sci.c line 27

Quoted 6 lines
hw/char/renesas_sci.c new file +6 -0
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/char/renesas_sci.h"
+#include "qemu/error-report.h"
+
+#define freq_to_ns(freq) (1000000000LL / freq)

You can directly use NANOSECONDS_PER_SECOND in update_trtime().

OK.

Quoted 11 lines

hw/char/renesas_sci.c line 35

Quoted 8 lines
hw/char/renesas_sci.c new file +8 -0
+
+static int can_receive(void *opaque)
+{
+    RSCIState *sci = RSCI(opaque);
+    if (sci->rx_next > qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) {
+        return 0;
+    } else {
+        return sci->scr & 0x10;

It is way easier to review a code using definitions generated by the "hw/registerfields.h" API, a recent example is hw/char/cmsdk-apb-uart.c.

OK.
Other part have same code. I will update it as well.

Quoted 21 lines
Quoted 8 lines
hw/char/renesas_sci.c new file +8 -0
+    }
+}
+
+static void receive(void *opaque, const uint8_t *buf, int size)
+{
+    RSCIState *sci = RSCI(opaque);
+    sci->rdr = buf[0];
+    if (sci->ssr & 0x40 || size > 1) {

hw/char/renesas_sci.c line 53

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+        sci->ssr |= 0x20;
+        if (sci->scr & 0x40) {
+            qemu_set_irq(sci->irq[ERI], 1);
+        }
+    } else {
+        sci->ssr |= 0x40;
+        sci->rx_next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + sci->trtime;
+        if (sci->scr & 0x40) {
+            qemu_set_irq(sci->irq[RXI], 1);
+            qemu_set_irq(sci->irq[RXI], 0);

Both lines are equivalent to:

Quoted 1 line
               qemu_irq_pulse(sci->irq[RXI]);

OK.

Quoted 47 lines
Quoted 34 lines
hw/char/renesas_sci.c new file +33 -0
+        }
+    }
+}
+
+static void send_byte(RSCIState *sci)
+{
+    if (qemu_chr_fe_backend_connected(&sci->chr)) {
+        qemu_chr_fe_write_all(&sci->chr, &sci->tdr, 1);
+    }
+    timer_mod(sci->timer,
+              qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + sci->trtime);
+    sci->ssr &= ~0x04;
+    sci->ssr |= 0x80;
+    qemu_set_irq(sci->irq[TEI], 0);
+    if (sci->scr & 0x80) {
+        qemu_set_irq(sci->irq[TXI], 1);
+        qemu_set_irq(sci->irq[TXI], 0);
+    }
+}
+
+static void txend(void *opaque)
+{
+    RSCIState *sci = RSCI(opaque);
+    if ((sci->ssr & 0x80) == 0) {
+        send_byte(sci);
+    } else {
+        sci->ssr |= 0x04;
+        if (sci->scr & 0x04) {
+            qemu_set_irq(sci->irq[TEI], 1);
+        }
+    }
+}
+

hw/char/renesas_sci.c line 96

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+static void update_trtime(RSCIState *sci)
+{
+    static const int div[] = {1, 4, 16, 64};
+    int w;
+
+    w = (sci->smr & 0x40) ? 7 : 8;      /* CHR */
+    w += (sci->smr >> 5) & 1;           /* PE */
+    w += (sci->smr & 0x08) ? 2 : 1;     /* STOP */
+    sci->trtime = w * freq_to_ns(sci->input_freq) *
+        32 * div[sci->smr & 0x03] * sci->brr;

Or:

Quoted 7 lines
       sci->trtime   = (sci->smr & 0x40) ? 7 : 8;
       sci->trtime  += (sci->smr >> 5) & 1;
       sci->trtime  += (sci->smr & 0x08) ? 2 : 1;
       sci->trtime  *= 32 * sci->brr;
       sci->trtime <<= 2 * (sci->smr & 0x03);
       sci->trtime  *= NANOSECONDS_PER_SECOND;
       sci->trtime  /= sci->input_freq;

OK.

Quoted 7 lines

hw/char/renesas_sci.c line 101

Quoted 5 lines
hw/char/renesas_sci.c new file +5 -0
+}
+
+static void sci_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    hwaddr offset = addr & 0x07;

You create the region with memory_region_init_io(size=8), so no need to &=7.

OK.

Quoted 41 lines
Quoted 30 lines
hw/char/renesas_sci.c new file +30 -0
+    RSCIState *sci = RSCI(opaque);
+    int error = 0;
+
+    switch (offset) {
+    case 0: /* SMR */
+        if ((sci->scr & 0x30) == 0) {
+            sci->smr = val;
+            update_trtime(sci);
+        }
+        break;
+    case 1: /* BRR */
+        if ((sci->scr & 0x30) == 0) {
+            sci->brr = val;
+            update_trtime(sci);
+        }
+        break;
+    case 2: /* SCR */
+        sci->scr = val;
+        if (sci->scr & 0x20) {
+            sci->ssr |= 0x84;
+            qemu_set_irq(sci->irq[TXI], 1);
+            qemu_set_irq(sci->irq[TXI], 0);
+        }
+        if ((sci->scr & 0x04) == 0) {
+            qemu_set_irq(sci->irq[TEI], 0);
+        }
+        if ((sci->scr & 0x40) == 0) {
+            qemu_set_irq(sci->irq[ERI], 0);
+        }
+        break;

hw/char/renesas_sci.c line 141

Quoted 10 lines
hw/char/renesas_sci.c new file +10 -0
+    case 3: /* TDR */
+        sci->tdr = val;
+        if (sci->ssr & 0x04) {
+            send_byte(sci);
+        } else{
+            sci->ssr &= ~0x80;
+        }
+        break;
+    case 4: /* SSR */
+        sci->ssr &= ~0x38 | (val & 0x38);
Quoted 4 lines

This expression is not clear... Don't you want:

           sci->ssr &= ~0x38;
           sci->ssr |= val & 0x38;

Yes.
It more clearly.

Quoted 6 lines

hw/char/renesas_sci.c line 143

Quoted 2 lines
hw/char/renesas_sci.c new file +2 -0
+        if (((sci->read_ssr & 0x38) ^ (sci->ssr & 0x38)) &&
+            (sci->ssr & 0x38) == 0) {

Is this equivalent to:

           if ((sci->ssr & 0x38) == 0 && (sci->read_ssr & 0x38) != 0) {

OK.

Quoted 9 lines

hw/char/renesas_sci.c line 148

Quoted 5 lines
hw/char/renesas_sci.c new file +5 -0
+            qemu_set_irq(sci->irq[ERI], 0);
+        }
+        break;
+    case 5: /* RDR */
+        error = 1; break;

Here error is due to read-only register, QEMU provides:

qemu_log_mask(LOG_GUEST_ERROR, "Read only register: "...

OK.

Quoted 9 lines

hw/char/renesas_sci.c line 156

Quoted 8 lines
hw/char/renesas_sci.c new file +8 -0
+    case 6: /* SCMR */
+        sci->scmr = val; break;
+    case 7: /* SEMR */
+        sci->semr = val; break;
+    }
+
+    if (error) {
+        error_report("rsci: unsupported write request to %08lx", addr);
Quoted 4 lines

"unsupported" is not very clear, for unimplemented you can use:

           qemu_log_mask(LOG_UNIMP,
                         "Register XX not implemented\n");

OK.

Quoted 35 lines
Quoted 35 lines
hw/char/renesas_sci.c new file +35 -0
+    }
+}
+
+static uint64_t sci_read(void *opaque, hwaddr addr, unsigned size)
+{
+    hwaddr offset = addr & 0x07;
+    RSCIState *sci = RSCI(opaque);
+    int error = 0;
+    switch (offset) {
+    case 0: /* SMR */
+        return sci->smr;
+    case 1: /* BRR */
+        return sci->brr;
+    case 2: /* SCR */
+        return sci->scr;
+    case 3: /* TDR */
+        return sci->tdr;
+    case 4: /* SSR */
+        sci->read_ssr = sci->ssr;
+        return sci->ssr;
+    case 5: /* RDR */
+        sci->ssr &= ~0x40;
+        return sci->rdr;
+    case 6: /* SCMR */
+        return sci->scmr;
+    case 7: /* SEMR */
+        return sci->semr;
+    }
+
+    if (error) {
+        error_report("rsci: unsupported write request to %08lx", addr);
+    }
+    return -1;
+}
+
Quoted 8 lines

hw/char/renesas_sci.c line 197

Quoted 6 lines
hw/char/renesas_sci.c new file +6 -0
+static const MemoryRegionOps sci_ops = {
+    .write = sci_write,
+    .read  = sci_read,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,

You can drop the implicit ".min_access_size = 1".

OK.

Quoted 28 lines
Quoted 28 lines
hw/char/renesas_sci.c new file +28 -0
+        .max_access_size = 1,
+    },
+};
+
+static void rsci_reset(DeviceState *dev)
+{
+    RSCIState *sci = RSCI(dev);
+    sci->smr = sci->scr = 0x00;
+    sci->brr = 0xff;
+    sci->tdr = 0xff;
+    sci->rdr = 0x00;
+    sci->ssr = 0x84;
+    sci->scmr = 0x00;
+    sci->semr = 0x00;
+    sci->rx_next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+}
+
+static void sci_event(void *opaque, int event)
+{
+    RSCIState *sci = RSCI(opaque);
+    if (event == CHR_EVENT_BREAK) {
+        sci->ssr |= 0x10;
+        if (sci->scr & 0x40) {
+            qemu_set_irq(sci->irq[ERI], 1);
+        }
+    }
+}
+
Quoted 8 lines

hw/char/renesas_sci.c line 231

Quoted 6 lines
hw/char/renesas_sci.c new file +6 -0
+static void rsci_realize(DeviceState *dev, Error **errp)
+{
+    RSCIState *sci = RSCI(dev);
+
+    qemu_chr_fe_set_handlers(&sci->chr, can_receive, receive,
+                             sci_event, NULL, sci, NULL, true);

You might want to check s->input_freq != 0 here.

OK.

Quoted 7 lines
Quoted 7 lines
hw/char/renesas_sci.c new file +7 -0
+}
+
+static void rsci_init(Object *obj)
+{
+    SysBusDevice *d = SYS_BUS_DEVICE(obj);
+    RSCIState *sci = RSCI(obj);
+    int i;
Quoted 8 lines

hw/char/renesas_sci.c line 244

Quoted 6 lines
hw/char/renesas_sci.c new file +6 -0
+
+    memory_region_init_io(&sci->memory, OBJECT(sci), &sci_ops,
+                          sci, "renesas-sci", 0x8);
+    sysbus_init_mmio(d, &sci->memory);
+
+    for (i = 0; i < 4; i++) {

4 -> ARRAY_COUNT(sci->irq) or SCI_IRQ_COUNT.

OK.

Quoted 74 lines
Quoted 56 lines
hw/char/renesas_sci.c new file +44 -0
+        sysbus_init_irq(d, &sci->irq[i]);
+    }
+    sci->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, txend, sci);
+}
+
+static const VMStateDescription vmstate_rcmt = {
+    .name = "renesas-sci",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property rsci_properties[] = {
+    DEFINE_PROP_UINT64("input-freq", RSCIState, input_freq, 0),
+    DEFINE_PROP_CHR("chardev", RSCIState, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void rsci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = rsci_realize;
+    dc->props = rsci_properties;
+    dc->vmsd = &vmstate_rcmt;
+    dc->reset = rsci_reset;
+}
+
+static const TypeInfo rsci_info = {
+    .name       = TYPE_RENESAS_SCI,
+    .parent     = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(RSCIState),
+    .instance_init = rsci_init,
+    .class_init = rsci_class_init,
+};
+
+static void rsci_register_types(void)
+{
+    type_register_static(&rsci_info);
+}
+
+type_init(rsci_register_types)
include/hw/char/renesas_sci.h new file +6 -0
new file mode 100644
index 0000000000..47e3e7a5d7
@@ -0,0 +1,42 @@
+/*
+ * Renesas Serial Communication Interface
+ *
+ * Copyright (c) 2018 Yoshinori Sato
+ *
+ * This code is licensed under the GPL version 2 or later.

include/hw/char/renesas_sci.h line 16

Quoted 10 lines
include/hw/char/renesas_sci.h new file +10 -0
+ *
+ */
+
+#include "chardev/char-fe.h"
+#include "qemu/timer.h"
+#include "hw/sysbus.h"
+
+#define TYPE_RENESAS_SCI "renesas-sci"
+#define RSCI(obj) OBJECT_CHECK(RSCIState, (obj), TYPE_RENESAS_SCI)
+

Since those definitions are related, I recommend using:

enum SciIrqIndex {
    ERI = 0,
    RXI = 1,
    ...
Quoted 7 lines

include/hw/char/renesas_sci.h line 20

Quoted 4 lines
include/hw/char/renesas_sci.h new file +4 -0
+#define ERI 0
+#define RXI 1
+#define TXI 2
+#define TEI 3

SCI_IRQ_COUNT = 4
};

OK.

Quoted 11 lines
Quoted 11 lines
include/hw/char/renesas_sci.h new file +11 -0
+
+typedef struct {
+    SysBusDevice parent_obj;
+    MemoryRegion memory;
+
+    uint8_t smr;
+    uint8_t brr;
+    uint8_t scr;
+    uint8_t tdr;
+    uint8_t ssr;
+    uint8_t rdr;
Quoted 8 lines

include/hw/char/renesas_sci.h line 37

Quoted 6 lines
include/hw/char/renesas_sci.h new file +6 -0
+    uint8_t scmr;
+    uint8_t semr;
+
+    uint8_t read_ssr;
+    long long trtime;
+    long long rx_next;

Can you use int64_t to keep both consistent?

OK.

Quoted 6 lines

include/hw/char/renesas_sci.h line 41

Quoted 4 lines
include/hw/char/renesas_sci.h new file +4 -0
+    QEMUTimer *timer;
+    CharBackend chr;
+    uint64_t input_freq;
+    qemu_irq irq[4];

Now you can use irq[SCI_IRQ_COUNT];

OK.

Quoted 7 lines

include/hw/char/renesas_sci.h line 42

Quoted 2 lines
include/hw/char/renesas_sci.h new file +1 -0
+} RSCIState;

Regards,

Phil.

Your comment is very useful.
Thank you.

Signature · 1 line
Yosinori Sato
#12 lore raw

RFC PATCH v3 9/11 RX Target hardware definition

In reply to Yoshinori Sato

rx62n - RX62N cpu.
rxqemu - QEMU virtual target.

---
 hw/rx/Makefile.objs   |   1 +
 hw/rx/rx62n.c         | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/rx/rxqemu.c        | 100 ++++++++++++++++++++++
 include/hw/rx/rx.h    |   7 ++
 include/hw/rx/rx62n.h |  54 ++++++++++++
 5 files changed, 389 insertions(+)
 create mode 100644 hw/rx/Makefile.objs
 create mode 100644 hw/rx/rx62n.c
 create mode 100644 hw/rx/rxqemu.c
 create mode 100644 include/hw/rx/rx.h
 create mode 100644 include/hw/rx/rx62n.h
hw/rx/Makefile.objs new file +1 -0
new file mode 100644
index 0000000000..e2edbb527e
@@ -0,0 +1 @@
+obj-y += rx62n.o rxqemu.o
hw/rx/rx62n.c new file +227 -0

227 lines not on this page · raw message

hw/rx/rxqemu.c new file +100 -0

100 lines not on this page · raw message

include/hw/rx/rx.h new file +7 -0
new file mode 100644
index 0000000000..ff5924b81f
@@ -0,0 +1,7 @@
+#ifndef QEMU_RX_H
+#define QEMU_RX_H
+/* Definitions for RX board emulation.  */
+
+#include "target/rx/cpu-qom.h"
+
+#endif
include/hw/rx/rx62n.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.11.0
#13 lore raw

RFC PATCH v3 10/11 Add rx-softmmu

In reply to Yoshinori Sato
---
 arch_init.c                    | 2 ++
 configure                      | 8 ++++++++
 default-configs/rx-softmmu.mak | 7 +++++++
 include/sysemu/arch_init.h     | 1 +
 4 files changed, 18 insertions(+)
 create mode 100644 default-configs/rx-softmmu.mak
arch_init.c +2 -0
index f4f3f610c8..cc25ddd7ca 100644
@@ -74,6 +74,8 @@ int graphic_depth = 32;
 #define QEMU_ARCH QEMU_ARCH_PPC
 #elif defined(TARGET_RISCV)
 #define QEMU_ARCH QEMU_ARCH_RISCV
+#elif defined(TARGET_RX)
+#define QEMU_ARCH QEMU_ARCH_RX
 #elif defined(TARGET_S390X)
 #define QEMU_ARCH QEMU_ARCH_S390X
 #elif defined(TARGET_SH4)
configure +8 -0
index 540bee19ba..6bae0d4e97 100755
@@ -7306,6 +7306,11 @@ case "$target_name" in
     mttcg=yes
     target_compiler=$cross_cc_riscv64
   ;;
+  rx)
+    TARGET_ARCH=rx
+    bflt="yes"
+    target_compiler=$cross_cc_rx
+  ;;
   sh4|sh4eb)
     TARGET_ARCH=sh4
     bflt="yes"
@@ -7526,6 +7531,9 @@ for i in $ARCH $TARGET_BASE_ARCH ; do
   riscv*)
     disas_config "RISCV"
   ;;
+  rx)
+    disas_config "RX"
+  ;;
   s390*)
     disas_config "S390"
   ;;
default-configs/rx-softmmu.mak new file +7 -0
new file mode 100644
index 0000000000..0aaa8d4332
@@ -0,0 +1,7 @@
+# Default configuration for rx-softmmu
+
+CONFIG_SERIAL=y
+CONFIG_PTIMER=y
+CONFIG_RX=y
+CONFIG_RENESAS_SCI=y
+CONFIG_RX_DIS=y
include/sysemu/arch_init.h +1 -0
index 10cbafe970..3f4f844f7b 100644
@@ -25,6 +25,7 @@ enum {
     QEMU_ARCH_NIOS2 = (1 << 17),
     QEMU_ARCH_HPPA = (1 << 18),
     QEMU_ARCH_RISCV = (1 << 19),
+    QEMU_ARCH_RX = (1 << 20),
 };
 
 extern const uint32_t arch_type;
Signature · 1 line
2.11.0
#14 lore raw

RFC PATCH v3 11/11 MAINTAINERS: Add RX entry.

In reply to Yoshinori Sato
---
 MAINTAINERS | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
MAINTAINERS +20 -0
index 5040d9dfb1..141c4994b9 100644
@@ -270,6 +270,14 @@ F: include/hw/riscv/
 F: linux-user/host/riscv32/
 F: linux-user/host/riscv64/
 
+RX
+M: Yoshinori Sato <[email protected]>
+S: Maintained
+F: target/rx/
+F: hw/rx/
+F: include/hw/rx/
+F: disas/rx.c
+
 S390
 M: Richard Henderson <[email protected]>
 M: David Hildenbrand <[email protected]>
@@ -1084,6 +1092,18 @@ F: pc-bios/canyonlands.dt[sb]
 F: pc-bios/u-boot-sam460ex-20100605.bin
 F: roms/u-boot-sam460ex
 
+RX Machines
+-----------
+RX-QEMU
+M: Yoshinori Sato <[email protected]>
+S: Maintained
+F: hw/rx/rxqemu.c
+F: hw/intc/rx_icu.c
+F: hw/timer/renesas_*.c
+F: hw/char/renesas_sci.c
+F: include/hw/timer/renesas_*.h
+F: include/hw/char/renesas_sci.h
+
 SH4 Machines
 ------------
 R2D
Signature · 1 line
2.11.0
#15 lore raw

Re: [Qemu-devel] [PATCH RFC v3 11/11] MAINTAINERS: Add RX entry.

Quoted 10 lines · Yoshinori Sato
---
 MAINTAINERS | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
MAINTAINERS +0 -0
index 5040d9dfb1..141c4994b9 100644

MAINTAINERS F: include/hw/riscv/ · line 273

Quoted 4 lines
MAINTAINERS +1 -0
@@ -270,6 +270,14 @@ F: include/hw/riscv/
 F: linux-user/host/riscv32/
 F: linux-user/host/riscv64/
 
+RX

RX sounds very generic, what about:

Renesas Extreme (RX)

Or

RX (Renesas Extreme)

Quoted 30 lines
MAINTAINERS +19 -0
+M: Yoshinori Sato <[email protected]>
+S: Maintained
+F: target/rx/
+F: hw/rx/
+F: include/hw/rx/
+F: disas/rx.c
+
 S390
 M: Richard Henderson <[email protected]>
 M: David Hildenbrand <[email protected]>
@@ -1084,6 +1092,18 @@ F: pc-bios/canyonlands.dt[sb]
 F: pc-bios/u-boot-sam460ex-20100605.bin
 F: roms/u-boot-sam460ex
 
+RX Machines
+-----------
+RX-QEMU
+M: Yoshinori Sato <[email protected]>
+S: Maintained
+F: hw/rx/rxqemu.c
+F: hw/intc/rx_icu.c
+F: hw/timer/renesas_*.c
+F: hw/char/renesas_sci.c
+F: include/hw/timer/renesas_*.h
+F: include/hw/char/renesas_sci.h
+
 SH4 Machines
 ------------
 R2D
#16 lore raw

Re: [Qemu-devel] [PATCH RFC v3 11/11] MAINTAINERS: Add RX entry.

Quoted 39 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Yoshinori Sato
---
 MAINTAINERS | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
MAINTAINERS +0 -0
index 5040d9dfb1..141c4994b9 100644

MAINTAINERS F: include/hw/riscv/ · line 273

Quoted 4 lines
MAINTAINERS +1 -0
@@ -270,6 +270,14 @@ F: include/hw/riscv/
 F: linux-user/host/riscv32/
 F: linux-user/host/riscv64/
 
+RX

RX sounds very generic, what about:

Renesas Extreme (RX)

Or

RX (Renesas Extreme)

Quoted 14 lines
MAINTAINERS +7 -0
+M: Yoshinori Sato <[email protected]>
+S: Maintained
+F: target/rx/
+F: hw/rx/
+F: include/hw/rx/
+F: disas/rx.c
+
 S390
 M: Richard Henderson <[email protected]>
 M: David Hildenbrand <[email protected]>
@@ -1084,6 +1092,18 @@ F: pc-bios/canyonlands.dt[sb]
 F: pc-bios/u-boot-sam460ex-20100605.bin
 F: roms/u-boot-sam460ex
 
Quoted 17 lines
Quoted 6 lines
MAINTAINERS +5 -0
+RX Machines
+-----------
+RX-QEMU
+M: Yoshinori Sato <[email protected]>
+S: Maintained

MAINTAINERS F: pc-bios/canyonlands.dt[sb] · line 1109

Quoted 10 lines
MAINTAINERS +7 -0
+F: hw/rx/rxqemu.c
+F: hw/intc/rx_icu.c
+F: hw/timer/renesas_*.c
+F: hw/char/renesas_sci.c
+F: include/hw/timer/renesas_*.h
+F: include/hw/char/renesas_sci.h
+
 SH4 Machines
 ------------
 R2D

OK.
I will update entry.
RENESAS RX

Thanks.

Signature · 1 line
Yosinori Sato
#17 lore raw

Re: [Qemu-devel] [PATCH RFC v3 00/11] Add RX archtecture support

In reply to Yoshinori Sato
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH RFC v3 00/11] Add RX archtecture support

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
e60fbb35e6 MAINTAINERS: Add RX entry. 3bdc16f591 Add rx-softmmu
38c0424e72 RX Target hardware definition a6ec852164 RX62N internal serial communication interface 179739cb93 RX62N internal timer modules 52c62d9d30 RX62N interrupt contorol uint cee296b1c3 target/rx: miscellaneous functions d2050c0e82 target/rx: RX disassembler 823a75d919 target/rx: CPU definition
d5927fc378 target/rx: TCG helper
6c80d5cc68 target/rx: TCG Translation

=== OUTPUT BEGIN ===
1/11 Checking commit 6c80d5cc686a (target/rx: TCG Translation)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #15:
new file mode 100644

ERROR: spaces required around that '*' (ctx:WxV) #2089: FILE: target/rx/translate.c:1728:
+static bool trans_FCMP_ri(DisasContext *ctx, arg_FCMP_ri *a)

                                                          ^

ERROR: spaces required around that '*' (ctx:WxV) #2111: FILE: target/rx/translate.c:1750:
+static bool trans_ITOF(DisasContext *ctx, arg_ITOF *a)

                                                    ^

ERROR: spaces required around that '*' (ctx:WxV) #2232: FILE: target/rx/translate.c:1871:
+static bool trans_BNOT_lr(DisasContext *ctx, arg_BNOT_lr *a)

                                                          ^

total: 3 errors, 1 warnings, 2556 lines checked

Patch 1/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

2/11 Checking commit d5927fc378e5 (target/rx: TCG helper)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #11:
new file mode 100644

total: 0 errors, 1 warnings, 893 lines checked

Patch 2/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
3/11 Checking commit 823a75d91989 (target/rx: CPU definition)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #11:
new file mode 100644

total: 0 errors, 1 warnings, 490 lines checked

Patch 3/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
4/11 Checking commit d2050c0e8217 (target/rx: RX disassembler)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #34:
new file mode 100644

total: 0 errors, 1 warnings, 1587 lines checked

Patch 4/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/11 Checking commit cee296b1c31c (target/rx: miscellaneous functions)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #11:
new file mode 100644

total: 0 errors, 1 warnings, 162 lines checked

Patch 5/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/11 Checking commit 52c62d9d30d9 (RX62N interrupt contorol uint)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #24:
new file mode 100644

total: 0 errors, 1 warnings, 376 lines checked

Patch 6/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
7/11 Checking commit 179739cb93ee (RX62N internal timer modules)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #30:
new file mode 100644

total: 0 errors, 1 warnings, 730 lines checked

Patch 7/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
8/11 Checking commit a6ec852164ae (RX62N internal serial communication interface)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #28:
new file mode 100644

total: 0 errors, 1 warnings, 338 lines checked

Patch 8/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
9/11 Checking commit 38c0424e72dd (RX Target hardware definition)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #14:
new file mode 100644

total: 0 errors, 1 warnings, 389 lines checked

Patch 9/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
10/11 Checking commit 3bdc16f591b9 (Add rx-softmmu)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #50:
new file mode 100644

total: 0 errors, 1 warnings, 42 lines checked

Patch 10/11 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
11/11 Checking commit e60fbb35e686 (MAINTAINERS: Add RX entry.) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#18 lore raw

Re: [Qemu-devel] [PATCH RFC v3 00/11] Add RX archtecture support

In reply to Yoshinori Sato

Hi Yoshinori,

Quoted 8 lines · Yoshinori Sato

Hello.
This patch series is added Renesas RX target emulation.

My git repository is bellow.
git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.git

Since my understanding is not enough,
I want many comments to make this a good one.

OK :)

Can you provide notes about how to test your port?
Such: links to toolchains, how to build, what firmware/OS we can run...

Quoted 81 lines

Thanks.

Changes v2
Rewrite translate. using decodetree.py

Yoshinori Sato (11):
target/rx: TCG Translation
target/rx: TCG helper
target/rx: CPU definition
target/rx: RX disassembler
target/rx: miscellaneous functions
RX62N interrupt contorol uint
RX62N internal timer modules
RX62N internal serial communication interface
RX Target hardware definition
Add rx-softmmu
MAINTAINERS: Add RX entry.

 MAINTAINERS                    |   20 +
 arch_init.c                    |    2 +
 configure                      |    8 +
 default-configs/rx-softmmu.mak |    7 +
 hw/char/Makefile.objs          |    2 +-
 hw/char/renesas_sci.c          |  288 ++++++
 hw/intc/Makefile.objs          |    1 +
 hw/intc/rx_icu.c               |  323 ++++++
 hw/rx/Makefile.objs            |    1 +
 hw/rx/rx62n.c                  |  227 ++++
 hw/rx/rxqemu.c                 |  100 ++
 hw/timer/Makefile.objs         |    2 +
 hw/timer/renesas_cmt.c         |  235 +++++
 hw/timer/renesas_tmr.c         |  412 ++++++++
 include/disas/bfd.h            |    5 +
 include/hw/char/renesas_sci.h  |   42 +
 include/hw/intc/rx_icu.h       |   49 +
 include/hw/rx/rx.h             |    7 +
 include/hw/rx/rx62n.h          |   54 +
 include/hw/timer/renesas_cmt.h |   33 +
 include/hw/timer/renesas_tmr.h |   42 +
 include/sysemu/arch_init.h     |    1 +
 target/rx/Makefile.objs        |   11 +
 target/rx/cpu-qom.h            |   52 +
 target/rx/cpu.c                |  224 ++++
 target/rx/cpu.h                |  214 ++++
 target/rx/disas.c              | 1570 ++++++++++++++++++++++++++++
 target/rx/gdbstub.c            |  113 ++
 target/rx/helper.c             |  252 +++++
 target/rx/helper.h             |   39 +
 target/rx/insns.decode         |  336 ++++++
 target/rx/monitor.c            |   38 +
 target/rx/op_helper.c          |  602 +++++++++++
 target/rx/translate.c          | 2220 ++++++++++++++++++++++++++++++++++++++++
 34 files changed, 7531 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/rx-softmmu.mak
 create mode 100644 hw/char/renesas_sci.c
 create mode 100644 hw/intc/rx_icu.c
 create mode 100644 hw/rx/Makefile.objs
 create mode 100644 hw/rx/rx62n.c
 create mode 100644 hw/rx/rxqemu.c
 create mode 100644 hw/timer/renesas_cmt.c
 create mode 100644 hw/timer/renesas_tmr.c
 create mode 100644 include/hw/char/renesas_sci.h
 create mode 100644 include/hw/intc/rx_icu.h
 create mode 100644 include/hw/rx/rx.h
 create mode 100644 include/hw/rx/rx62n.h
 create mode 100644 include/hw/timer/renesas_cmt.h
 create mode 100644 include/hw/timer/renesas_tmr.h
 create mode 100644 target/rx/Makefile.objs
 create mode 100644 target/rx/cpu-qom.h
 create mode 100644 target/rx/cpu.c
 create mode 100644 target/rx/cpu.h
 create mode 100644 target/rx/disas.c
 create mode 100644 target/rx/gdbstub.c
 create mode 100644 target/rx/helper.c
 create mode 100644 target/rx/helper.h
 create mode 100644 target/rx/insns.decode
 create mode 100644 target/rx/monitor.c
 create mode 100644 target/rx/op_helper.c
 create mode 100644 target/rx/translate.c
#19 lore raw

Re: [Qemu-devel] [PATCH RFC v3 00/11] Add RX archtecture support

Quoted 10 lines · Philippe Mathieu-Daudé

Hi Yoshinori,

Quoted 6 lines · Yoshinori Sato

Hello.
This patch series is added Renesas RX target emulation.

My git repository is bellow.
git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.git

Quoted 7 lines
Quoted 2 lines

Since my understanding is not enough,
I want many comments to make this a good one.

OK :)

Can you provide notes about how to test your port?
Such: links to toolchains, how to build, what firmware/OS we can run...

OK.
toolchain - rx-unknown-linux
binutils-2.32 include rx-unknown-linux support.

$ configure --target=rx-unknown-linux
$ make

gcc - please use my git repo.
git://git.pf.osdn.net/gitroot/y/ys/ysato/gcc.git rx-trunk

$ configure --target=rx-unknown-linux --enable-languages=c --disable-shared \
--disable-threads --with-uclibc --disable-libssp --disable-libquadmath \
--disable-libgomp --disable-libatomic
$ make

This toolchain can build u-boot / linux.

target program.
u-boot
git://git.pf.osdn.net/gitroot/y/ys/ysato/uboot.git rx pre build binary in bellow.
https://osdn.net/users/ysato/pf/qemu/dl/u-boot.bin

linux
git://git.osdn.net/gitroot/uclinux-h8/linux.git rx
https://osdn.net/users/ysato/pf/qemu/dl/zImage

Since linux is still incomplete, it may be problematic.

Quoted 82 lines
Quoted 81 lines

Thanks.

Changes v2
Rewrite translate. using decodetree.py

Yoshinori Sato (11):
target/rx: TCG Translation
target/rx: TCG helper
target/rx: CPU definition
target/rx: RX disassembler
target/rx: miscellaneous functions
RX62N interrupt contorol uint
RX62N internal timer modules
RX62N internal serial communication interface
RX Target hardware definition
Add rx-softmmu
MAINTAINERS: Add RX entry.

 MAINTAINERS                    |   20 +
 arch_init.c                    |    2 +
 configure                      |    8 +
 default-configs/rx-softmmu.mak |    7 +
 hw/char/Makefile.objs          |    2 +-
 hw/char/renesas_sci.c          |  288 ++++++
 hw/intc/Makefile.objs          |    1 +
 hw/intc/rx_icu.c               |  323 ++++++
 hw/rx/Makefile.objs            |    1 +
 hw/rx/rx62n.c                  |  227 ++++
 hw/rx/rxqemu.c                 |  100 ++
 hw/timer/Makefile.objs         |    2 +
 hw/timer/renesas_cmt.c         |  235 +++++
 hw/timer/renesas_tmr.c         |  412 ++++++++
 include/disas/bfd.h            |    5 +
 include/hw/char/renesas_sci.h  |   42 +
 include/hw/intc/rx_icu.h       |   49 +
 include/hw/rx/rx.h             |    7 +
 include/hw/rx/rx62n.h          |   54 +
 include/hw/timer/renesas_cmt.h |   33 +
 include/hw/timer/renesas_tmr.h |   42 +
 include/sysemu/arch_init.h     |    1 +
 target/rx/Makefile.objs        |   11 +
 target/rx/cpu-qom.h            |   52 +
 target/rx/cpu.c                |  224 ++++
 target/rx/cpu.h                |  214 ++++
 target/rx/disas.c              | 1570 ++++++++++++++++++++++++++++
 target/rx/gdbstub.c            |  113 ++
 target/rx/helper.c             |  252 +++++
 target/rx/helper.h             |   39 +
 target/rx/insns.decode         |  336 ++++++
 target/rx/monitor.c            |   38 +
 target/rx/op_helper.c          |  602 +++++++++++
 target/rx/translate.c          | 2220 ++++++++++++++++++++++++++++++++++++++++
 34 files changed, 7531 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/rx-softmmu.mak
 create mode 100644 hw/char/renesas_sci.c
 create mode 100644 hw/intc/rx_icu.c
 create mode 100644 hw/rx/Makefile.objs
 create mode 100644 hw/rx/rx62n.c
 create mode 100644 hw/rx/rxqemu.c
 create mode 100644 hw/timer/renesas_cmt.c
 create mode 100644 hw/timer/renesas_tmr.c
 create mode 100644 include/hw/char/renesas_sci.h
 create mode 100644 include/hw/intc/rx_icu.h
 create mode 100644 include/hw/rx/rx.h
 create mode 100644 include/hw/rx/rx62n.h
 create mode 100644 include/hw/timer/renesas_cmt.h
 create mode 100644 include/hw/timer/renesas_tmr.h
 create mode 100644 target/rx/Makefile.objs
 create mode 100644 target/rx/cpu-qom.h
 create mode 100644 target/rx/cpu.c
 create mode 100644 target/rx/cpu.h
 create mode 100644 target/rx/disas.c
 create mode 100644 target/rx/gdbstub.c
 create mode 100644 target/rx/helper.c
 create mode 100644 target/rx/helper.h
 create mode 100644 target/rx/insns.decode
 create mode 100644 target/rx/monitor.c
 create mode 100644 target/rx/op_helper.c
 create mode 100644 target/rx/translate.c
Signature · 1 line
Yosinori Sato
#20 lore raw

Re: [Qemu-devel] [PATCH RFC v3 00/11] Add RX archtecture support

In reply to Yoshinori Sato
Quoted 2 lines · Yoshinori Sato

My git repository is bellow.
git://git.pf.osdn.net/gitroot/y/ys/ysato/qemu.git

Somehow patch 1 did not arrive, so I am reviewing based on rebasing this branch against master, and then looking at the diff.

Quoted 1 line

+struct CCop;

Unused?

Review

Quoted 7 lines
(quoted diff) +7 -0
+static inline void cpu_get_tb_cpu_state(CPURXState *env, target_ulong *pc,
+                                        target_ulong *cs_base, uint32_t *flags)
+{
+    *pc = env->pc;
+    *cs_base = 0;
+    *flags = 0;
+}

*flags should contain PSW[PM], I think, so that knowledge of the privilege level is given to the translator.

Looking forward I see that you're currently testing cpu_psw_pm dynamically for instructions that require privs, so what you have is not wrong, but this is exactly the sort of thing that TB flags are for.

Quoted 1 line

+#define RX_PSW_OP_NEG 4

Unused?

Review

Quoted 3 lines
(quoted diff) +3 -0
+#define RX_BYTE 0
+#define RX_WORD 1
+#define RX_LONG 2

Redundant with TCGMemOps: MO_8, MO_16, MO_32?

Quoted 1 line

+++ b/target/rx/insns.decode

Should have a copyright + license notice.

Quoted 1 line

+BCnd_b 0010 cd:4 dsp:8 &bcnd

...

Quoted 1 line

+#BRA_b 0010 1110 dsp:8 # overlaps BCnd_b

FYI, using pattern groups this can be written

{
BRA_b 0010 1110 dsp:8
Bcnd_b 0010 cd:4 dsp:8
}

I expect to have pattern groups merged this week.

Review

Quoted 6 lines
(quoted diff) +6 -0
+static void rx_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
+{
+    DisasContext *ctx = container_of(dcbase, DisasContext, base);
+
+    ctx->src = tcg_temp_new();
+}

This allocation will not survive across a branch or label. So, after any SHIFTR_REG, for instance.

I think you need to allocate this on demand each insn, and free it as necessary after each insn.

(Although avoiding branches in tcg is always helpful.)

Review

Quoted 10 lines
(quoted diff) +10 -0
+/* generic load / store wrapper */
+static inline void rx_gen_ldst(unsigned int size, unsigned int dir,
+                        TCGv reg, TCGv mem)
+{
+    if (dir) {
+        tcg_gen_qemu_ld_i32(reg, mem, 0, size | MO_SIGN | MO_TE);
+    } else {
+        tcg_gen_qemu_st_i32(reg, mem, 0, size | MO_TE);
+    }
+}

It would probably be worthwhile to split this function, and drop the "dir" parameter. It is always a constant, so instead of

  rx_gen_ldst(mi, RX_MEMORY_LD, ctx->src, ctx->src);
  rx_gen_ldst(a->sz, RX_MEMORY_ST, cpu_regs[a->rs], ctx->src);

use the shorter

  rx_gen_ld(mi, ctx->src, ctx->src);
  rx_gen_st(a->sz, cpu_regs[a->rs], ctx->src);

Review

Quoted 7 lines
(quoted diff) +7 -0
+/* mov.l #uimm4,rd */
+/* mov.l #uimm8,rd */
+static bool trans_MOV_ri(DisasContext *ctx, arg_MOV_ri *a)
+{
+    tcg_gen_movi_i32(cpu_regs[a->rd], a->imm & 0xff);
+    return true;
+}

a->imm will already have been masked by the decode. You can drop the & 0xff here.

Review

Quoted 6 lines
(quoted diff) +6 -0
+/* mov.l #imm,rd */
+static bool trans_MOV_rli(DisasContext *ctx, arg_MOV_rli *a)
+{
+    tcg_gen_movi_i32(cpu_regs[a->rd], a->imm);
+    return true;
+}

As written, this function is redundant. We should be using the same MOV_ri, with the immediate loaded from %b2_li_2.

Likewise for trans_MOV_mi vs trans_MOV_mli. That said...

Review

Quoted 6 lines
(quoted diff) +6 -0
+static bool trans_MOV_mli(DisasContext *ctx, arg_MOV_mli *a)
+{
+    TCGv imm = tcg_const_i32(a->imm);
+    if (a->ld == 2) {
+        a->dsp = bswap_16(a->dsp);
+    }

This suggests that the decode is incorrect. Or perhaps the construction of the 32-bit insn passed into decode. In decode_load_bytes, we construct a big-endian value, so it would seem this dsp field should be loaded as a little-endian value.

This could be fixed by not attempting to load the LI constant in decodetree (for this insn), which would in turn not require that you decode the LD operand by hand in decodetree. E.g.

static bool trans_MOV_mli(DisasContext *ctx, arg_MOV_mli *a)

{
    TCGv imm;

    /* dsp operand comes before immediate operand */
    rx_index_addr(a->ld, a->sz, a->rd, s);
    imm = tcg_const_i32(li(s, a->li));
    rx_gen_st(a->sz, imm, ctx->src);
    tcg_temp_free_i32(imm);
    return true;
}

This will be easiest if you ever support the big-endian version of RX.

Review

Quoted 12 lines
(quoted diff) +12 -0
+/* push rs */
+static bool trans_PUSH_r(DisasContext *ctx, arg_PUSH_r *a)
+{
+    if (a->rs != 0) {
+        tcg_gen_subi_i32(cpu_regs[0], cpu_regs[0], 4);
+        rx_gen_ldst(a->sz, RX_MEMORY_ST, cpu_regs[a->rs], cpu_regs[0]);
+    } else {
+        tcg_gen_mov_i32(ctx->src, cpu_regs[a->rs]);
+        tcg_gen_subi_i32(cpu_regs[0], cpu_regs[0], 4);
+        rx_gen_ldst(a->sz, RX_MEMORY_ST, ctx->src, cpu_regs[0]);
+    }
+    return true;

As far as I can see the THEN and ELSE cases have identical operation.

Quoted 21 lines
(quoted diff) +21 -0
+static bool trans_XCHG_rl(DisasContext *ctx, arg_XCHG_rl *a)
+{
+    int sz;
+    TCGv tmp;
+    tmp = tcg_temp_new();
+    if (a->ld == 3) {
+       /* xchg rs,rd */
+        tcg_gen_mov_i32(tmp, cpu_regs[a->rs]);
+        tcg_gen_mov_i32(cpu_regs[a->rs], cpu_regs[a->rd]);
+        tcg_gen_mov_i32(cpu_regs[a->rd], tmp);
+    } else {
+        switch (a->mi) {
+        case 0 ... 2:
+            rx_index_addr(a->ld, a->mi, a->rs, ctx);
+            rx_gen_ldst(a->mi, RX_MEMORY_LD, tmp, ctx->src);
+            sz = a->mi;
+            break;
+        case 3:
+            rx_index_addr(a->ld, RX_MEMORY_WORD, a->rs, ctx);
+            rx_gen_ldu(RX_MEMORY_WORD, tmp, ctx->src);
+            sz = RX_MEMORY_WORD;

Review

Quoted 10 lines
(quoted diff) +10 -0
+            break;
+        case 4:
+            rx_index_addr(a->ld, RX_MEMORY_BYTE, a->rs, ctx);
+            rx_gen_ldu(RX_MEMORY_BYTE, tmp, ctx->src);
+            sz = RX_MEMORY_BYTE;
+            break;
+        }
+        rx_gen_ldst(sz, RX_MEMORY_ST, cpu_regs[a->rd], ctx->src);
+        tcg_gen_mov_i32(cpu_regs[a->rd], tmp);
+    }

While I doubt that there is an SMP RX cpu, I think this should still implement an atomic xchg operation. This will allow rx-linux-user to run on SMP host cpus. Thus use

static inline TCGMemOp mi_to_mop(unsigned mi)

{
    static const TCGMemOp mop[5] = { MO_SB, MO_SW, MO_UL, MO_UH, MO_UB };
    tcg_debug_assert(mi < 5);
    return mop[mi];
}
  tcg_gen_atomic_xchg_i32(cpu_regs[a->rd], ctx->src, cpu_regs[a->rd],
                          0, mi_to_mop(a->mi));

Review

Quoted 8 lines
(quoted diff) +8 -0
+#define STCOND(cond)                                                    \
+    do {                                                                \
+        tcg_gen_movi_i32(ctx->imm, a->imm);            \
+        tcg_gen_movi_i32(ctx->one, 1);                                  \
+        tcg_gen_movcond_i32(cond, cpu_regs[a->rd], cpu_psw_z,           \
+                            ctx->one, ctx->imm, cpu_regs[a->rd]);       \
+        return true;                                                    \
+    } while(0)

Unused? This seems close to what you wanted instead of...

Review

Quoted 13 lines
(quoted diff) +13 -0
+#define STZFN(maskop)                                                   \
+    do {                                                                \
+        TCGv mask, imm;                                                 \
+        mask = tcg_temp_new();                                          \
+        imm = tcg_temp_new();                                           \
+        maskop;                                                         \
+        tcg_gen_andi_i32(imm, mask, a->imm);                            \
+        tcg_gen_andc_i32(cpu_regs[a->rd], cpu_regs[a->rd], mask);       \
+        tcg_gen_or_i32(cpu_regs[a->rd], cpu_regs[a->rd], imm);          \
+        tcg_temp_free(mask);                                            \
+        tcg_temp_free(imm);                                             \
+        return true;                                                    \
+    } while(0)

... this.

  TCGv zero = tcg_const_i32(0);
  TCGv imm = tcg_const_i32(a->imm);
  tcg_gen_movcond(COND, cpu_regs[a->rd], cpu_psw_z, zero,
                  imm, cpu_regs[a->rd]);

where trans_STZ passes TCG_COND_NE and STNZ passes TCG_COND_EQ.

In addition, there's no point in using a #define when a function would work just as well.

Review

Quoted 6 lines
(quoted diff) +6 -0
+#define GEN_LOGIC_OP(opr, ret, arg1, arg2) \
+    do {                                                                \
+        opr(ret, arg1, arg2);                                       \
+        tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_psw_z, ret, 0);           \
+        tcg_gen_setcondi_i32(TCG_COND_GEU, cpu_psw_s, ret, 0x80000000UL); \
+    } while(0)

Note that the second is the same as

tcg_gen_setcondi_i32(TCG_COND_LT, cpu_psw_s, ret, 0);
or
tcg_gen_shri_i32(cpu_psw_s, ret, 31);

That said, this extra computation is exactly why ARM (and others) represent the flag differently in the field. The inline setting would be

  tcg_gen_mov_i32(cpu_psw_z, ret);
  tcg_gen_mov_i32(cpu_psw_s, ret);

And then whenever we *use* these flags, we only look at the sign bit of S, and we see if the whole of Z is zero/non-zero. Similarly, the overflow flag is also stored in the sign bit of O, so that is computed more easily:

O = (ret ^ in1) & ~(in1 & in2)

with no right-shift required at the end.

This also means that we've reduced the amount of inline computation to the point that there is no point in *not* doing the computation every time it is required, and so update_psw_o and cpu->psw_v[] goes away.

Again, no reason for a macro when a function will do. They are easier to debug.

Quoted 1 line

+ rs = (a->rs2 < 16) ? a->rs2 : a->rd;

Is this due to

Quoted 1 line

@b2_rds_uimm4 .... .... imm:4 rd:4 &rri rs2=255 len=2

this? A better decode is

@b2_rds_uimm4 .... .... imm:4 rd:4 &rri rs2=%b2_r_0 len=2

i.e. extract the rd field twice. Once directly into rd and again from the same bits into rs2.

Quoted 6 lines
(quoted diff) +6 -0
+/* revw rs, rd */
+static bool trans_REVW(DisasContext *ctx, arg_REVW *a)
+{
+    TCGv hi, lo;
+
+    hi = tcg_temp_new();

Review

Quoted 10 lines
(quoted diff) +10 -0
+    lo = tcg_temp_new();
+    tcg_gen_shri_i32(hi, cpu_regs[a->rs], 16);
+    tcg_gen_bswap16_i32(hi, hi);
+    tcg_gen_shli_i32(hi, hi, 16);
+    tcg_gen_bswap16_i32(lo, cpu_regs[a->rs]);
+    tcg_gen_or_i32(cpu_regs[a->rd], hi, lo);
+    tcg_temp_free(hi);
+    tcg_temp_free(lo);
+    return true;
+}

The bswap16 primitive requires the input to be zero-extended. Thus this second bswap16 may fail. Perhaps better as

  T0 = 0x00ff00ff;
  T1 = RS & T0;
  T2 = RS >> 8;
  T1 = T1 << 8;
  T2 = T2 & T0;
  RD = T1 | T2;

Review

Quoted 6 lines
(quoted diff) +6 -0
+/* conditional branch helper */
+static void rx_bcnd_main(DisasContext *ctx, int cd, int dst, int len)
+{
+        TCGv t, f, cond;
+        switch(cd) {
+        case 0 ... 13:

Indentation is off?

Review

Quoted 4 lines
(quoted diff) +4 -0
+static bool trans_BCnd_s(DisasContext *ctx, arg_BCnd_s *a)
+{
+    if (a->dsp < 3)
+        a->dsp += 8;

This bit should probably be in the decode, via !function.

Review

Quoted 13 lines
(quoted diff) +13 -0
+static int16_t rev16(uint16_t dsp)
+{
+    return ((dsp << 8) & 0xff00) | ((dsp >> 8) & 0x00ff);
+}
+
+static int32_t rev24(uint32_t dsp)
+{
+    dsp = ((dsp << 16) & 0xff0000) |
+        (dsp & 0x00ff00) |
+        ((dsp >> 16) & 0x0000ff);
+    dsp |= (dsp & 0x00800000) ? 0xff000000 : 0x00000000;
+    return dsp;
+}

These could also be in the decode, probably with %some_field. But as with MOV above, maybe ought to be done via an explicit call to li(), in order to get a (potential) big-endian RX to work.

Also, watch out for CODING_STYLE violations. Please recheck everything with ./scripts/checkpatch.pl.

Review

Quoted 12 lines
(quoted diff) +12 -0
+/* mvtachi rs */
+static bool trans_MVTACHI(DisasContext *ctx, arg_MVTACHI *a)
+{
+    TCGv_i32 hi, lo;
+    hi = tcg_temp_new_i32();
+    lo = tcg_temp_new_i32();
+    tcg_gen_extr_i64_i32(lo, hi, cpu_acc);
+    tcg_gen_concat_i32_i64(cpu_acc, lo, cpu_regs[a->rs]);
+    tcg_temp_free_i32(hi);
+    tcg_temp_free_i32(lo);
+    return true;
+}

Hmm. How about

   TCGv_i64 rs64 = tcg_temp_new_i64();
   tcg_gen_extu_i32_i64(rs64, cpu_regs[a->rs]);
   tcg_gen_deposit_i64(cpu_acc, cpu_acc, rs64, 32, 32);
Quoted 8 lines
(quoted diff) +8 -0
+static inline void clrsetpsw(int dst, int mode)
+{
+    TCGv psw[] = {
+        cpu_psw_c, cpu_psw_z, cpu_psw_s, cpu_psw_o,
+        NULL, NULL, NULL, NULL,
+        cpu_psw_i, cpu_psw_u, NULL, NULL,
+        NULL, NULL, NULL, NULL
+    };

Review

Quoted 10 lines
(quoted diff) +10 -0
+    TCGLabel *skip;
+
+    skip = gen_new_label();
+    if (dst >= 8)
+        tcg_gen_brcondi_i32(TCG_COND_NE, cpu_psw_pm, 0, skip);
+    tcg_gen_movi_i32(psw[dst], mode);
+    if (dst == 3)
+        tcg_gen_movi_i32(cpu_pswop, RX_PSW_OP_NONE);
+    gen_set_label(skip);
+}

When clearing psw_i, you'll need to exit to the main loop so that any pending interrupts are recognized. Otherwise you risk going around in a loop and never delivering the interrupt at all.

Review

Quoted 10 lines
(quoted diff) +10 -0
+/* rtfi */
+static bool trans_RTFI(DisasContext *ctx, arg_RTFI *a)
+{
+    check_previleged();
+    tcg_gen_mov_i32(cpu_pc, cpu_bpc);
+    tcg_gen_mov_i32(cpu_psw, cpu_bpsw);
+    gen_helper_unpack_psw(cpu_env);
+    ctx->base.is_jmp = DISAS_JUMP;
+    return true;
+}

Likewise, you need to exit to the main loop, because psw_i changed.

Review

Quoted 5 lines
(quoted diff) +5 -0
+    cpu_pswop = tcg_global_mem_new_i32(cpu_env,
+                                     offsetof(CPURXState, psw_op), "");
+    for (i = 0; i < 3; i++) {
+        cpu_pswop_v[i] = tcg_global_mem_new_i32(cpu_env,
+                                                offsetof(CPURXState, psw_v[i]), "");

Using the empty string for the name of a temp is cruel. That'll be very hard to debug.

Quoted 1 line

+uint32_t psw_cond(CPURXState *env, uint32_t cond)

In general this can be inlined fairly easily. See, for instance, target/arm/translate.c, arm_test_cc.

Review

Quoted 7 lines
(quoted diff) +7 -0
+uint32_t helper_div(CPURXState *env, uint32_t num, uint32_t den)
+{
+    uint32_t ret = num;
+    if (den != 0) {
+        ret = (int32_t)num / (int32_t)den;
+    }
+    env->psw_o = (ret == 0 || den == 0);

That is not the correct overflow condition. ret == 0 is irrelevant, but INT_MIN / -1 is relevant.

Finally, this was way too big to review properly. This patch set will need to be broken up into smaller pieces. Perhaps introducing just one, or a few related instructions with each patch.

r~