Skip to contentSkip to conversation

sh4: system emulator patches

Qemu-devel Magnus Damm 1 participant 1 message Sep 28, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi everyone,

Here comes a batch of sh4 system emulator patches. Main features are rewrites of TMU and SCI/SCIF device emulation and other minor fixes to get some basic parts of the linux kernel booting up.

The curious user can try the attached kernel config to build a sh4 kernel (2.6.23-rc/2.6.24-pre) which at least starts booting inside of qemu. Use the following options to get the serial ports right:

$ qemu-system-sh4 -kernel ~/kernel/git/sh-2.6/arch/sh/boot/zImage -M
r2d -nographic -monitor null -serial null -serial stdio

The kernel currently hangs on waiting for timer interrupts. So I'm currently working on fixing up proper interrupt support.

Patches in this batch:

sh: add R2D-PLUS support
sh: add stand alone TMU emulation code
sh: add stand alone SCI/SCIF emulation code
sh: add INTC controller prototype
sh: add FRQCR read support
sh: fix rte opcode
sh: add sh4-softmmu and sh4-linux-user to --target-list

Please apply!

/ magnus

sh: add R2D-PLUS support

This patch adds basic emulation of R2D-PLUS to the sh4-softmmu target. Only a few on-chip sh7750 devices plus memory are supported for now. In the future code for FPGA registers and PCI devices should be added.

---

 Makefile.target |    2 -
 hw/r2d.c        |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c            |    1 
 vl.h            |    3 ++
 4 files changed, 69 insertions(+), 1 deletion(-)
Makefile.target +1 -1
@@ -476,7 +476,7 @@ VL_OBJS+= omap.o omap_lcdc.o omap1_clk.o
 CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), sh4)
-VL_OBJS+= shix.o sh7750.o sh7750_regnames.o tc58128.o
+VL_OBJS+= shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o
 endif
 ifeq ($(TARGET_BASE_ARCH), m68k)
 VL_OBJS+= an5206.o mcf5206.o ptimer.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
hw/r2d.c new file +64 -0

64 lines not on this page · raw message

vl.c +1 -0
@@ -7383,6 +7383,7 @@ void register_machines(void)
     qemu_register_machine(&palmte_machine);
 #elif defined(TARGET_SH4)
     qemu_register_machine(&shix_machine);
+    qemu_register_machine(&r2d_machine);
 #elif defined(TARGET_ALPHA)
     /* XXX: TODO */
 #elif defined(TARGET_M68K)
vl.h +3 -0
@@ -1198,6 +1198,9 @@ extern void cpu_mips_irqctrl_init (void)
 /* shix.c */
 extern QEMUMachine shix_machine;
 
+/* r2d.c */
+extern QEMUMachine r2d_machine;
+
 #ifdef TARGET_PPC
 /* PowerPC hardware exceptions management helpers */
 typedef void (*clk_setup_cb)(void *opaque, uint32_t freq);

sh: add stand alone TMU emulation code

This patch removes the old timer code and adds separate code in hw/sh_timer.c that emulates a TMU block consisting of two or three timer channels. Only basic free running mode is supported yet - and no interrupts. This new code is based on ptimer.c which made it easy to support timer value read out.

---

 Makefile.target      |    1 
 hw/sh7750.c          |  102 ---------------
 hw/sh7750_regnames.c |   12 -
 hw/sh7750_regs.h     |   88 -------------
 hw/sh_timer.c        |  323 ++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.h                 |    6 
 6 files changed, 336 insertions(+), 196 deletions(-)
Makefile.target +1 -0
@@ -477,6 +477,7 @@ CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), sh4)
 VL_OBJS+= shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o
+VL_OBJS+= sh_timer.o ptimer.o
 endif
 ifeq ($(TARGET_BASE_ARCH), m68k)
 VL_OBJS+= an5206.o mcf5206.o ptimer.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
hw/sh7750.c +6 -96

145 lines not on this page · raw message

hw/sh7750_regnames.c +0 -12
@@ -42,18 +42,6 @@ static regname_t regnames[] = {
 	REGNAME(SH7750_RMONAR_A7)
 	REGNAME(SH7750_RCR1_A7)
 	REGNAME(SH7750_RCR2_A7)
-	REGNAME(SH7750_TOCR_A7)
-	REGNAME(SH7750_TSTR_A7)
-	REGNAME(SH7750_TCOR0_A7)
-	REGNAME(SH7750_TCOR1_A7)
-	REGNAME(SH7750_TCOR2_A7)
-	REGNAME(SH7750_TCNT0_A7)
-	REGNAME(SH7750_TCNT1_A7)
-	REGNAME(SH7750_TCNT2_A7)
-	REGNAME(SH7750_TCR0_A7)
-	REGNAME(SH7750_TCR1_A7)
-	REGNAME(SH7750_TCR2_A7)
-	REGNAME(SH7750_TCPR2_A7)
 	REGNAME(SH7750_BCR1_A7)
 	REGNAME(SH7750_BCR2_A7)
 	REGNAME(SH7750_WCR1_A7)
hw/sh7750_regs.h +0 -88

94 lines not on this page · raw message

hw/sh_timer.c new file +323 -0

323 lines not on this page · raw message

vl.h +6 -0
@@ -1509,6 +1509,12 @@ typedef struct {
 
 int sh7750_register_io_device(struct SH7750State *s,
 			      sh7750_io_device * device);
+/* sh_timer.c */
+#define TMU012_FEAT_TOCR   (1 << 0)
+#define TMU012_FEAT_3CHAN  (1 << 1)
+#define TMU012_FEAT_EXTCLK (1 << 2)
+void tmu012_init(uint32_t base, int feat, uint32_t freq);
+
 /* tc58128.c */
 int tc58128_init(struct SH7750State *s, char *zone1, char *zone2);
 

sh: add stand alone SCI/SCIF emulation code

This patch removes the old serial port code and adds separate code in hw/sh_serial.c that emulates SCI/SCIF serial devices. Only a few things are supported yet, but this is enough to get early printk working on SCIF. In the future we need support for rx, interrupts and rx fifo among other things.

---

 Makefile.target      |    2 
 hw/sh7750.c          |  345 --------------------------------------------------
 hw/sh7750_regnames.c |   18 --
 hw/sh7750_regs.h     |  225 --------------------------------
 hw/sh_serial.c       |  315 +++++++++++++++++++++++++++++++++++++++++++++
 vl.h                 |    5 
 6 files changed, 325 insertions(+), 585 deletions(-)
Makefile.target +1 -1
@@ -477,7 +477,7 @@ CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), sh4)
 VL_OBJS+= shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o
-VL_OBJS+= sh_timer.o ptimer.o
+VL_OBJS+= sh_timer.o ptimer.o sh_serial.o
 endif
 ifeq ($(TARGET_BASE_ARCH), m68k)
 VL_OBJS+= an5206.o mcf5206.o ptimer.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
hw/sh7750.c +4 -341

412 lines not on this page · raw message

hw/sh7750_regnames.c +0 -18
@@ -70,24 +70,6 @@ static regname_t regnames[] = {
 	REGNAME(SH7750_CHCR2_A7)
 	REGNAME(SH7750_CHCR3_A7)
 	REGNAME(SH7750_DMAOR_A7)
-	REGNAME(SH7750_SCRDR1_A7)
-	REGNAME(SH7750_SCRDR2_A7)
-	REGNAME(SH7750_SCTDR1_A7)
-	REGNAME(SH7750_SCTDR2_A7)
-	REGNAME(SH7750_SCSMR1_A7)
-	REGNAME(SH7750_SCSMR2_A7)
-	REGNAME(SH7750_SCSCR1_A7)
-	REGNAME(SH7750_SCSCR2_A7)
-	REGNAME(SH7750_SCSSR1_A7)
-	REGNAME(SH7750_SCSFR2_A7)
-	REGNAME(SH7750_SCSPTR1_A7)
-	REGNAME(SH7750_SCSPTR2_A7)
-	REGNAME(SH7750_SCBRR1_A7)
-	REGNAME(SH7750_SCBRR2_A7)
-	REGNAME(SH7750_SCFCR2_A7)
-	REGNAME(SH7750_SCFDR2_A7)
-	REGNAME(SH7750_SCLSR2_A7)
-	REGNAME(SH7750_SCSCMR1_A7)
 	REGNAME(SH7750_PCTRA_A7)
 	REGNAME(SH7750_PDTRA_A7)
 	REGNAME(SH7750_PCTRB_A7)
hw/sh7750_regs.h +0 -225

231 lines not on this page · raw message

hw/sh_serial.c new file +315 -0

315 lines not on this page · raw message

vl.h +5 -0
@@ -1515,6 +1515,11 @@ int sh7750_register_io_device(struct SH7
 #define TMU012_FEAT_EXTCLK (1 << 2)
 void tmu012_init(uint32_t base, int feat, uint32_t freq);
 
+/* sh_serial.c */
+#define SH_SERIAL_FEAT_SCIF (1 << 0)
+void sh_serial_init (target_phys_addr_t base, int feat,
+		     uint32_t freq, CharDriverState *chr);
+
 /* tc58128.c */
 int tc58128_init(struct SH7750State *s, char *zone1, char *zone2);
 

sh: add INTC controller prototype

This patch adds code to emulate all INTC registers. We don't support enabling of interrupts yet, but this is a good first step.

---

 hw/sh7750.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
hw/sh7750.c +51 -0

81 lines not on this page · raw message

sh: add FRQCR read support

This patch adds code to accept FRQCR read operations and return 0. In the future we should keep track of clocks and emulate this properly. Until then - this is enough to get Linux moving.

---

 hw/sh7750.c |    2 ++
 1 file changed, 2 insertions(+)
hw/sh7750.c +2 -0
@@ -207,6 +207,8 @@ static uint32_t sh7750_mem_readw(void *o
     SH7750State *s = opaque;
 
     switch (addr) {
+    case SH7750_FRQCR_A7:
+	return 0;
     case SH7750_RFCR_A7:
 	fprintf(stderr,
 		"Read access to refresh count register, incrementing\n");

sh: fix rte opcode

The opcode for rte is incorrect without this patch.

---

 target-sh4/translate.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target-sh4/translate.c +1 -1
@@ -277,7 +277,7 @@ void decode_opc(DisasContext * ctx)
     case 0x0038:		/* ldtlb */
 	assert(0);		/* XXXXX */
 	return;
-    case 0x004b:		/* rte */
+    case 0x002b:		/* rte */
 	CHECK_NOT_DELAY_SLOT gen_op_rte();
 	ctx->flags |= DELAY_SLOT;
 	ctx->delayed_pc = (uint32_t) - 1;

sh: add sh4-softmmu and sh4-linux-user to --target-list

This patch adds sh4-softmmu and sh4-linux-user to the default build.

---

 configure |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure +2 -2
@@ -497,11 +497,11 @@ fi
 if test -z "$target_list" ; then
 # these targets are portable
     if [ "$softmmu" = "yes" ] ; then
-        target_list="i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu mipsel-softmmu mips64-softmmu mips64el-softmmu arm-softmmu ppc64-softmmu ppcemb-softmmu m68k-softmmu"
+        target_list="i386-softmmu ppc-softmmu sparc-softmmu x86_64-softmmu mips-softmmu mipsel-softmmu mips64-softmmu mips64el-softmmu arm-softmmu ppc64-softmmu ppcemb-softmmu m68k-softmmu sh4-softmmu"
     fi
 # the following are Linux specific
     if [ "$linux_user" = "yes" ] ; then
-        target_list="i386-linux-user arm-linux-user armeb-linux-user sparc-linux-user ppc-linux-user mips-linux-user mipsel-linux-user m68k-linux-user alpha-linux-user ppc64-linux-user $target_list"
+        target_list="i386-linux-user arm-linux-user armeb-linux-user sparc-linux-user ppc-linux-user mips-linux-user mipsel-linux-user m68k-linux-user alpha-linux-user ppc64-linux-user sh4-linux-user $target_list"
     fi
 # the following are Darwin specific
     if [ "$darwin_user" = "yes" ] ; then