Skip to contentSkip to conversation

SH: Improve the interrupt controller 2

Qemu-devel Vladimir Prus 1 participant 2 messages Mar 31, 2009 – May 11, 2009

lore
Share & tools
lore
#0 lore raw

Hello,

this patch is a revision of the patch I have posted at:

	http://article.gmane.org/gmane.comp.emulators.qemu/34204

The original patch was necessary to get SH7785 emulation working, but broke 7750. Takashi Yoshi investigated and a revised patch in:

	http://article.gmane.org/gmane.comp.emulators.qemu/37891

with further refinements in:

	http://article.gmane.org/gmane.comp.emulators.qemu/38459
	http://article.gmane.org/gmane.comp.emulators.qemu/39662

The patch I am posting here is a mechanical composition of all of above. I have previously said that it does not work for 7785, but the problem turned out to be in my 7785 code, so, to the best of my knowledge, this works for both 7750 and 7785. The patch is against SVN r6963. It took quite a number of iterations and time to arrive here, so I hope this patch can go in.

- Volodya

commit be3026950d578cf035931e10035b79f80255df48

Author: Vladimir Prus <[email protected]>
Date:   Mon Mar 30 22:49:44 2009 +0400

Improve the interrupt controller.

hw/sh7750.c +15 -14
index 423c43f..addd435 100644
@@ -502,13 +502,13 @@ static struct intc_group groups[] = {
 };
 
 static struct intc_prio_reg prio_registers[] = {
-	{ 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
-	{ 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
-	{ 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
-	{ 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
-	{ 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
-						 TMU4, TMU3,
-						 PCIC1, PCIC0_PCISERR } },
+       { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
+       { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
+       { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
+       { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 }, 0xda74 },
+       { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
+                                                TMU4, TMU3,
+                                                PCIC1, PCIC0_PCISERR } },
 };
 
 /* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
@@ -730,11 +730,11 @@ SH7750State *sh7750_init(CPUSH4State * cpu)
 						     sh7750_mmct_read,
 						     sh7750_mmct_write, s);
     cpu_register_physical_memory(0xf0000000, 0x08000000,
-				 sh7750_mm_cache_and_tlb);
+                                sh7750_mm_cache_and_tlb);
 
-    sh_intc_init(&s->intc, NR_SOURCES,
-		 _INTC_ARRAY(mask_registers),
-		 _INTC_ARRAY(prio_registers));
+    sh_intc_init(&s->intc, 0x1fd00000, NR_SOURCES,
+                _INTC_ARRAY(mask_registers),
+                _INTC_ARRAY(prio_registers));
 
     sh_intc_register_sources(&s->intc,
 			     _INTC_ARRAY(vectors),
@@ -806,7 +806,8 @@ SH7750State *sh7750_init(CPUSH4State * cpu)
 
 qemu_irq sh7750_irl(SH7750State *s)
 {
-    sh_intc_toggle_source(sh_intc_source(&s->intc, IRL), 1, 0); /* enable */
-    return qemu_allocate_irqs(sh_intc_set_irl, sh_intc_source(&s->intc, IRL),
-                               1)[0];
+    struct intc_source *irl = sh_intc_source(&s->intc, IRL);
+
+    sh_intc_init_irl_priorities(irl);
+    return qemu_allocate_irqs(sh_intc_set_irl, irl, 1)[0];
 }
hw/sh_intc.c +160 -81

363 lines not on this page · raw message

hw/sh_intc.h +7 -1
index a9750ae..83b646e 100644
@@ -42,6 +42,7 @@ struct intc_source {
     int enable_count;
     int enable_max;
     int pending; /* emulates the result of signal and masking */
+    int priority;
     struct intc_desc *parent;
 };
 
@@ -55,9 +56,11 @@ struct intc_desc {
     int nr_prio_regs;
     int iomemtype;
     int pending; /* number of interrupt sources that has pending set */
+    target_phys_addr_t base;
+    unsigned icr0;
 };
 
-int sh_intc_get_pending_vector(struct intc_desc *desc, int imask);
+int sh_intc_get_pending_vector(struct intc_desc *desc, int *priority);
 struct intc_source *sh_intc_source(struct intc_desc *desc, intc_enum id);
 void sh_intc_toggle_source(struct intc_source *source,
 			   int enable_adj, int assert_adj);
@@ -69,6 +72,7 @@ void sh_intc_register_sources(struct intc_desc *desc,
 			      int nr_groups);
 
 int sh_intc_init(struct intc_desc *desc,
+		 target_phys_addr_t base,
 		 int nr_sources,
 		 struct intc_mask_reg *mask_regs,
 		 int nr_mask_regs,
@@ -77,4 +81,6 @@ int sh_intc_init(struct intc_desc *desc,
 
 void sh_intc_set_irl(void *opaque, int n, int level);
 
+void sh_intc_init_irl_priorities(struct intc_source *s);
+
 #endif /* __SH_INTC_H__ */
target-sh4/cpu.h +1 -0
index aea7108..e9eee2c 100644
@@ -141,6 +141,7 @@ typedef struct CPUSH4State {
     uint32_t pvr;		/* Processor Version Register */
     uint32_t prr;		/* Processor Revision Register */
     uint32_t cvr;		/* Cache Version Register */
+    uint32_t opm;              /* CPU Operation Mode Register */
 
     uint32_t ldst;
 
target-sh4/helper.c +9 -1
index c506086..f1feca7 100644
@@ -81,6 +81,7 @@ void do_interrupt(CPUState * env)
 {
     int do_irq = env->interrupt_request & CPU_INTERRUPT_HARD;
     int do_exp, irq_vector = env->exception_index;
+    int priority = (env->sr >> 4) & 0xf;
 
     /* prioritize exceptions over interrupts */
 
@@ -99,7 +100,7 @@ void do_interrupt(CPUState * env)
 
     if (do_irq) {
         irq_vector = sh_intc_get_pending_vector(env->intc_handle,
-						(env->sr >> 4) & 0xf);
+						&priority);
         if (irq_vector == -1) {
             return; /* masked */
 	}
@@ -157,6 +158,13 @@ void do_interrupt(CPUState * env)
     }
 
     env->ssr = env->sr;
+
+    if (env->opm & (1 << 3)) {
+       unsigned mask = 0xf << 4;
+       env->ssr &= ~mask;
+       env->ssr |= (priority << 4) & mask;
+    }
+
     env->spc = env->pc;
     env->sgr = env->gregs[15];
     env->sr |= SR_BL | SR_MD | SR_RB;
#1 lore raw
Quoted 17 lines · On Wednesday 01 April 2009 01:11:05 Vladimir Prus wrote:

Hello,

this patch is a revision of the patch I have posted at:

	http://article.gmane.org/gmane.comp.emulators.qemu/34204

The original patch was necessary to get SH7785 emulation working, but broke 7750. Takashi Yoshi investigated and a revised patch in:

	http://article.gmane.org/gmane.comp.emulators.qemu/37891

with further refinements in:

	http://article.gmane.org/gmane.comp.emulators.qemu/38459
	http://article.gmane.org/gmane.comp.emulators.qemu/39662
Quoted 6 lines

The patch I am posting here is a mechanical composition of all of above. I have previously said that it does not work for 7785, but the problem turned out to be in my 7785 code, so, to the best of my knowledge, this works for both 7750 and 7785. The patch is against SVN r6963. It took quite a number of iterations and time to arrive here, so I hope this patch can go in.

PING?

- Volodya