target-or32: fix masking in openrisc_pic_cpu_handler()
A message that is not in the archive (sent off-list or not yet received): [email protected]
Il 22/01/2013 16:57, Xi Wang ha scritto:
Quoted 35 lines
A correct mask should be
x & (1 << i)', rather thanx && (1 << i)'.Also, in C99 signed shift (1 << 31) is undefined behavior, since the result exceeds
INT_MAX; use 1U instead.Signed-off-by Xi Wang <[email protected]>--- hw/openrisc_pic.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)hw/openrisc_pic.c +3
-1@@ -26,12 +26,14 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) {OpenRISCCPU *cpu = (OpenRISCCPU *)opaque;int i; -uint32_t irq_bit =1 << irq; +uint32_t irq_bit;if (irq >31 || irq <0 ) {return ; } + irq_bit =1U << irq; +if (level) { cpu->env.picsr |= irq_bit; }else {@@ -39,11 +41,11 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) }for (i =0 ; i <32 ; i++) {
hw/openrisc_pic.c static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) · line 51
Quoted 10 lines
hw/openrisc_pic.c +2
-2-if ((cpu->env.picsr && (1 << i)) && (cpu->env.picmr && (1 << i))) { +if ((cpu->env.picsr & (1U << i)) && (cpu->env.picmr & (1U << i))) {cpu_interrupt (&cpu->env,CPU_INTERRUPT_HARD ); }else {cpu_reset_interrupt (&cpu->env,CPU_INTERRUPT_HARD ); - cpu->env.picsr &= ~(1 << i); + cpu->env.picsr &= ~(1U << i); } } }
Ping.
Paolo
Hi Xi,
Quoted 17 lines · Xi Wang
A correct mask should be
x & (1 << i)', rather thanx && (1 << i)'.Also, in C99 signed shift (1 << 31) is undefined behavior, since the result exceeds
INT_MAX; use 1U instead.Signed-off-by Xi Wang <[email protected]>--- hw/openrisc_pic.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)hw/openrisc_pic.c +0
-0@@ -26,12 +26,14 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) {OpenRISCCPU *cpu = (OpenRISCCPU *)opaque;
hw/openrisc_pic.c static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) · line 36
Quoted 10 lines
hw/openrisc_pic.c +3
-1int i; -uint32_t irq_bit =1 << irq; +uint32_t irq_bit;if (irq >31 || irq <0 ) {return ; } + irq_bit =1U << irq; +
Thanks, this part is OK.
Quoted 4 lines
hw/openrisc_pic.c +0
-0if (level) { cpu->env.picsr |= irq_bit; }else {
hw/openrisc_pic.c static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) · line 48
Quoted 10 lines
hw/openrisc_pic.c +2
-2@@ -39,11 +41,11 @@ static void openrisc_pic_cpu_handler(void *opaque, int irq, int level) }for (i =0 ; i <32 ; i++) { -if ((cpu->env.picsr && (1 << i)) && (cpu->env.picmr && (1 << i))) { +if ((cpu->env.picsr & (1U << i)) && (cpu->env.picmr & (1U << i))) {cpu_interrupt (&cpu->env,CPU_INTERRUPT_HARD ); }else {cpu_reset_interrupt (&cpu->env,CPU_INTERRUPT_HARD ); - cpu->env.picsr &= ~(1 << i); + cpu->env.picsr &= ~(1U << i);
May you please test it? Your change here make qemu-system-or32 can not boot Linux.
You can download pre-compiled Linux form here:
https://docs.google.com/file/d/0BxeTrz3x0CBLbTNmU0lrV1Y0V0U/edit?usp=sharing
or build one yourself.
Quoted 6 lines
hw/openrisc_pic.c +0
-1} } } --1.7.10.4
At last, openrisc_pic.c is renamed into pic_cpu.c, please update your patch.
Regards,
Jia.