target-xtensa: fix guest hang on masked CCOMPARE interrupt
PATCH 1/1 target-xtensa: fix guest hang on masked CCOMPARE interrupt
QEMU timer is used to post CCOMPARE interrupt when the core is halted. If that CCOMPARE interrupt is masked off then the timer must be rearmed in the callback, otherwise it will be rearmed next time the core goes to halt by the waiti instruction.
Add test case into timer testsuite.
--- hw/xtensa_pic.c | 27 ++++++++++++++++++- target-xtensa/cpu.h | 1 + target-xtensa/op_helper.c | 18 ++---------- tests/xtensa/test_timer.S | 63 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 16 deletions(-)
hw/xtensa_pic.c +26 -1
@@ -116,10 +116,35 @@ void xtensa_timer_irq(CPUState *env, uint32_t id, uint32_t active)qemu_set_irq (env->irq_inputs[env->config->timerint[id]], active); } +void xtensa_rearm_ccompare_timer (CPUState *env) +{ +int i; +uint32_t wake_ccount = env->sregs[CCOUNT ] -1 ; + +for (i =0 ; i < env->config->nccompare; ++i) { +if (env->sregs[CCOMPARE + i] - env->sregs[CCOUNT ] < + wake_ccount - env->sregs[CCOUNT ]) { + wake_ccount = env->sregs[CCOMPARE + i]; + } + } + env->wake_ccount = wake_ccount; +qemu_mod_timer (env->ccompare_timer, env->halt_clock + +muldiv64 (wake_ccount - env->sregs[CCOUNT ], +1000000 , env->config->clock_freq_khz)); +} +static void xtensa_ccompare_cb (void *opaque) {CPUState *env = opaque; -xtensa_advance_ccount (env, env->wake_ccount - env->sregs[CCOUNT ]); + +if (env->halted) { + env->halt_clock =qemu_get_clock_ns (vm_clock); +xtensa_advance_ccount (env, env->wake_ccount - env->sregs[CCOUNT ]); +if (!cpu_has_work (env)) { + env->sregs[CCOUNT ] = env->wake_ccount +1 ; +xtensa_rearm_ccompare_timer (env); + } + } }void xtensa_irq_init (CPUState *env)
target-xtensa/cpu.h +1 -0
@@ -313,6 +313,7 @@ void check_interrupts(CPUXtensaState *s);void xtensa_irq_init (CPUState *env);void xtensa_advance_ccount (CPUState *env,uint32_t d);void xtensa_timer_irq (CPUState *env,uint32_t id,uint32_t active); +void xtensa_rearm_ccompare_timer (CPUState *env);int cpu_xtensa_signal_handler (int host_signum,void *pinfo,void *puc);void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf);void xtensa_sync_window_from_phys (CPUState *env);
target-xtensa/op_helper.c +3 -15
@@ -370,23 +370,11 @@ void HELPER(waiti)(uint32_t pc, uint32_t intlevel)return ; } -if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT )) { -int i; -uint32_t wake_ccount = env->sregs[CCOUNT ] -1 ; - -for (i =0 ; i < env->config->nccompare; ++i) { -if (env->sregs[CCOMPARE + i] - env->sregs[CCOUNT ] < - wake_ccount - env->sregs[CCOUNT ]) { - wake_ccount = env->sregs[CCOMPARE + i]; - } - } - env->wake_ccount = wake_ccount; -qemu_mod_timer (env->ccompare_timer,qemu_get_clock_ns (vm_clock) + -muldiv64 (wake_ccount - env->sregs[CCOUNT ], -1000000 , env->config->clock_freq_khz)); - } env->halt_clock =qemu_get_clock_ns (vm_clock); env->halted =1 ; +if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT )) { +xtensa_rearm_ccompare_timer (env); + }HELPER (exception)(EXCP_HLT ); }
tests/xtensa/test_timer.S +63 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.6.4
PATCH 1/1 target-xtensa: update qemu-doc.texi
--- qemu-doc.texi | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-tech.texi | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 88 insertions(+), 7 deletions(-)
qemu-doc.texi +55 -0
@@ -110,6 +110,7 @@ For system emulation, the following hardware targets are supported: @item Syborg SVP base model (ARM Cortex-A8). @item AXIS-Devboard88 (CRISv32 ETRAX-FS). @item Petalogix Spartan 3aDSP1800 MMU ref design (MicroBlaze). +@item Avnet LX60/LX110/LX200 boards (Xtensa) @end itemize @cindex supported user mode targets
@@ -1446,6 +1447,7 @@ differences are mentioned in the following sections. * Cris System emulator:: * Microblaze System emulator:: * SH4 System emulator:: +* Xtensa System emulator:: @end menu @node PowerPC System emulator
@@ -2124,6 +2126,59 @@ TODO TODO +@node Xtensa System emulator +@section Xtensa System emulator +@cindex system emulation (Xtensa) + +Two executables cover simulation of both Xtensa endian options, +@file{qemu-system-xtensa} and @file{qemu-system-xtensaeb}. +Two different machine types are emulated: + +@itemize @minus +@item +Xtensa emulator pseudo board "sim" +@item +Avnet LX60/LX110/LX200 board +@end itemize + +The sim pseudo board emulation provides an environment similiar +to one provided by the proprietary Tensilica ISS. +It supports: + +@itemize @minus +@item +A range of Xtensa CPUs, default is the DC232B +@item +Console and filesystem access via semihosting calls +@end itemize + +The Avnet LX60/LX110/LX200 emulation supports: + +@itemize @minus +@item +A range of Xtensa CPUs, default is the DC232B +@item +16550 UART +@item +OpenCores 10/100 Mbps Ethernet MAC +@end itemize + +@c man begin OPTIONS + +The following options are specific to the Xtensa emulation: + +@table @option + +@item -semihosting +Enable semihosting syscall emulation. + +Xtensa semihosting provides basic file IO calls, such as open/read/write/seek/select. +Tensilica baremetal libc for ISS and linux platform "sim" use this interface. + +Note that this allows guest direct access to the host filesystem, +so should only be used with trusted guest OS. + +@end table @node QEMU User space emulator @chapter QEMU User space emulator
qemu-tech.texi +33 -7
@@ -42,13 +42,14 @@ @chapter Introduction @menu -* intro_features:: Features -* intro_x86_emulation:: x86 and x86-64 emulation -* intro_arm_emulation:: ARM emulation -* intro_mips_emulation:: MIPS emulation -* intro_ppc_emulation:: PowerPC emulation -* intro_sparc_emulation:: Sparc32 and Sparc64 emulation -* intro_other_emulation:: Other CPU emulation +* intro_features:: Features +* intro_x86_emulation:: x86 and x86-64 emulation +* intro_arm_emulation:: ARM emulation +* intro_mips_emulation:: MIPS emulation +* intro_ppc_emulation:: PowerPC emulation +* intro_sparc_emulation:: Sparc32 and Sparc64 emulation +* intro_xtensa_emulation:: MIPS emulation +* intro_other_emulation:: Other CPU emulation @end menu @node intro_features
@@ -259,6 +260,31 @@ Current QEMU limitations: @end itemize +@node intro_xtensa_emulation +@section Xtensa emulation + +@itemize + +@item Core Xtensa ISA emulation, including most options: code density, +loop, extended L32R, 16- and 32-bit multiplication, 32-bit division, +MAC16, miscellaneous operations, boolean, multiprocessor synchronization, +conditional store, exceptions, relocatable vectors, unaligned exception, +interrupts (including high priority and timer), hardware alignment, +region protection, region translation, MMU, windowed registers, thread +pointer, processor ID. + +@item Not implemented options: FP coprocessor, coprocessor context, +data/instruction cache (including cache prefetch and locking), XLMI, +processor interface, debug. Also options not covered by the core ISA +(e.g. FLIX, wide branches) are not implemented. + +@item Can run most Xtensa Linux binaries. + +@item New core configuration that requires no additional instructions +may be created from overlay with minimal amount of hand-written code. + +@end itemize + @node intro_other_emulation @section Other CPU emulation
Signature · 1 line
1.7.6.4
PATCH v2 1/1 target-xtensa: update qemu-doc.texi
---
v1 -> v2 change: fix menu item text in qemu-tech.texi
--- qemu-doc.texi | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-tech.texi | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 88 insertions(+), 7 deletions(-)
qemu-doc.texi +55 -0
@@ -110,6 +110,7 @@ For system emulation, the following hardware targets are supported: @item Syborg SVP base model (ARM Cortex-A8). @item AXIS-Devboard88 (CRISv32 ETRAX-FS). @item Petalogix Spartan 3aDSP1800 MMU ref design (MicroBlaze). +@item Avnet LX60/LX110/LX200 boards (Xtensa) @end itemize @cindex supported user mode targets
@@ -1446,6 +1447,7 @@ differences are mentioned in the following sections. * Cris System emulator:: * Microblaze System emulator:: * SH4 System emulator:: +* Xtensa System emulator:: @end menu @node PowerPC System emulator
@@ -2124,6 +2126,59 @@ TODO TODO +@node Xtensa System emulator +@section Xtensa System emulator +@cindex system emulation (Xtensa) + +Two executables cover simulation of both Xtensa endian options, +@file{qemu-system-xtensa} and @file{qemu-system-xtensaeb}. +Two different machine types are emulated: + +@itemize @minus +@item +Xtensa emulator pseudo board "sim" +@item +Avnet LX60/LX110/LX200 board +@end itemize + +The sim pseudo board emulation provides an environment similiar +to one provided by the proprietary Tensilica ISS. +It supports: + +@itemize @minus +@item +A range of Xtensa CPUs, default is the DC232B +@item +Console and filesystem access via semihosting calls +@end itemize + +The Avnet LX60/LX110/LX200 emulation supports: + +@itemize @minus +@item +A range of Xtensa CPUs, default is the DC232B +@item +16550 UART +@item +OpenCores 10/100 Mbps Ethernet MAC +@end itemize + +@c man begin OPTIONS + +The following options are specific to the Xtensa emulation: + +@table @option + +@item -semihosting +Enable semihosting syscall emulation. + +Xtensa semihosting provides basic file IO calls, such as open/read/write/seek/select. +Tensilica baremetal libc for ISS and linux platform "sim" use this interface. + +Note that this allows guest direct access to the host filesystem, +so should only be used with trusted guest OS. + +@end table @node QEMU User space emulator @chapter QEMU User space emulator
qemu-tech.texi +33 -7
@@ -42,13 +42,14 @@ @chapter Introduction @menu -* intro_features:: Features -* intro_x86_emulation:: x86 and x86-64 emulation -* intro_arm_emulation:: ARM emulation -* intro_mips_emulation:: MIPS emulation -* intro_ppc_emulation:: PowerPC emulation -* intro_sparc_emulation:: Sparc32 and Sparc64 emulation -* intro_other_emulation:: Other CPU emulation +* intro_features:: Features +* intro_x86_emulation:: x86 and x86-64 emulation +* intro_arm_emulation:: ARM emulation +* intro_mips_emulation:: MIPS emulation +* intro_ppc_emulation:: PowerPC emulation +* intro_sparc_emulation:: Sparc32 and Sparc64 emulation +* intro_xtensa_emulation:: Xtensa emulation +* intro_other_emulation:: Other CPU emulation @end menu @node intro_features
@@ -259,6 +260,31 @@ Current QEMU limitations: @end itemize +@node intro_xtensa_emulation +@section Xtensa emulation + +@itemize + +@item Core Xtensa ISA emulation, including most options: code density, +loop, extended L32R, 16- and 32-bit multiplication, 32-bit division, +MAC16, miscellaneous operations, boolean, multiprocessor synchronization, +conditional store, exceptions, relocatable vectors, unaligned exception, +interrupts (including high priority and timer), hardware alignment, +region protection, region translation, MMU, windowed registers, thread +pointer, processor ID. + +@item Not implemented options: FP coprocessor, coprocessor context, +data/instruction cache (including cache prefetch and locking), XLMI, +processor interface, debug. Also options not covered by the core ISA +(e.g. FLIX, wide branches) are not implemented. + +@item Can run most Xtensa Linux binaries. + +@item New core configuration that requires no additional instructions +may be created from overlay with minimal amount of hand-written code. + +@end itemize + @node intro_other_emulation @section Other CPU emulation
Signature · 1 line
1.7.2.5
Blue Swirl
AppliedThanks, applied.
Quoted 204 lines · Max Filippov
QEMU timer is used to post CCOMPARE interrupt when the core is halted. If that CCOMPARE interrupt is masked off then the timer must be rearmed in the callback, otherwise it will be rearmed next time the core goes to halt by the waiti instruction.
Add test case into timer testsuite.
Signed-off-by Max Filippov <[email protected]>---
hw/xtensa_pic.c | 27 ++++++++++++++++++-target-xtensa/cpu.h| 1 +
target-xtensa/op_helper.c | 18 ++----------tests/xtensa/test_timer.S| 63 +++++++++++++++++++++++++++++++++++++++++++++4 files changed, 93 insertions(+), 16 deletions(-)hw/xtensa_pic.c +26
-1@@ -116,10 +116,35 @@ void xtensa_timer_irq(CPUState *env, uint32_t id, uint32_t active) qemu_set_irq(env->irq_inputs[env->config->timerint[id]], active); } +void xtensa_rearm_ccompare_timer (CPUState *env) +{ + int i; + uint32_t wake_ccount = env->sregs[CCOUNT] - 1; + + for (i = 0; i < env->config->nccompare; ++i) { + if (env->sregs[CCOMPARE + i] - env->sregs[CCOUNT] < + wake_ccount - env->sregs[CCOUNT]) { + wake_ccount = env->sregs[CCOMPARE + i]; + } + } + env->wake_ccount = wake_ccount; + qemu_mod_timer(env->ccompare_timer, env->halt_clock + + muldiv64(wake_ccount - env->sregs[CCOUNT], + 1000000, env->config->clock_freq_khz)); +} + static void xtensa_ccompare_cb(void *opaque) { CPUState *env = opaque; - xtensa_advance_ccount(env, env->wake_ccount - env->sregs[CCOUNT]); + + if (env->halted) { + env->halt_clock = qemu_get_clock_ns(vm_clock); + xtensa_advance_ccount(env, env->wake_ccount - env->sregs[CCOUNT]); + if (!cpu_has_work(env)) { + env->sregs[CCOUNT] = env->wake_ccount + 1; + xtensa_rearm_ccompare_timer(env); + } + } } void xtensa_irq_init(CPUState *env)target-xtensa/cpu.h +1
-0@@ -313,6 +313,7 @@ void check_interrupts(CPUXtensaState *s); void xtensa_irq_init(CPUState *env); void xtensa_advance_ccount(CPUState *env, uint32_t d); void xtensa_timer_irq(CPUState *env, uint32_t id, uint32_t active); +void xtensa_rearm_ccompare_timer (CPUState *env); int cpu_xtensa_signal_handler(int host_signum, void *pinfo, void *puc); void xtensa_cpu_list(FILE *f, fprintf_function cpu_fprintf); void xtensa_sync_window_from_phys(CPUState *env);target-xtensa/op_helper.c +3
-15@@ -370,23 +370,11 @@ void HELPER(waiti)(uint32_t pc, uint32_t intlevel) return; } - if (xtensa_option_enabled(env->config, XTENSA_OPTION_TIMER_INTERRUPT)) { - int i; - uint32_t wake_ccount = env->sregs[CCOUNT] - 1; - - for (i = 0; i < env->config->nccompare; ++i) { - if (env->sregs[CCOMPARE + i] - env->sregs[CCOUNT] < - wake_ccount - env->sregs[CCOUNT]) { - wake_ccount = env->sregs[CCOMPARE + i]; - } - } - env->wake_ccount = wake_ccount; - qemu_mod_timer(env->ccompare_timer, qemu_get_clock_ns(vm_clock) + - muldiv64(wake_ccount - env->sregs[CCOUNT], - 1000000, env->config->clock_freq_khz)); - } env->halt_clock = qemu_get_clock_ns(vm_clock); env->halted = 1; + if (xtensa_option_enabled(env->config, XTENSA_OPTION_TIMER_INTERRUPT)) { + xtensa_rearm_ccompare_timer(env); + } HELPER(exception)(EXCP_HLT); }tests/xtensa/test_timer.S +0
-0@@ -14,6 +14,7 @@ test ccomparewsr a2, intenable
rsr a2, interrupt
wsr a2, intclear
+ movi a2, 0
wsr a2, ccompare1
wsr a2, ccompare2tests/xtensa/test_timer.S +0
-0@@ -37,6 +38,7 @@ test ccompare0_interruptwsr a2, intenable
rsr a2, interrupt
wsr a2, intclear
+ movi a2, 0
wsr a2, ccompare1
wsr a2, ccompare2tests/xtensa/test_timer.S +0
-0@@ -66,6 +68,7 @@ test ccompare1_interruptwsr a2, intenable
rsr a2, interrupt
wsr a2, intclear
+ movi a2, 0
wsr a2, ccompare0
wsr a2, ccompare2tests/xtensa/test_timer.S +0
-0@@ -92,6 +95,7 @@ test ccompare2_interruptwsr a2, intenable
rsr a2, interrupt
wsr a2, intclear
+ movi a2, 0
wsr a2, ccompare0
wsr a2, ccompare1tests/xtensa/test_timer.S +0
-0@@ -112,4 +116,63 @@ test ccompare2_interrupt2:
test_endtests/xtensa/test_timer.S +59
-0+test ccompare_interrupt_masked + set_vector kernel, 2f + movi a2, 0 + wsr a2, intenable + rsr a2, interrupt + wsr a2, intclear + movi a2, 0 + wsr a2, ccompare2 + + movi a3, 40 + rsr a2, ccount + addi a2, a2, 20 + wsr a2, ccompare1 + addi a2, a2, 20 + wsr a2, ccompare0 + rsync + rsr a2, interrupt + assert eqi, a2, 0 + + movi a2, 0x40 + wsr a2, intenable + rsil a2, 0 + loop a3, 1f + nop +1: + test_fail +2: + rsr a2, exccause + assert eqi, a2, 4 /* LEVEL1_INTERRUPT_CAUSE */ +test_end + +test ccompare_interrupt_masked_waiti + set_vector kernel, 2f + movi a2, 0 + wsr a2, intenable + rsr a2, interrupt + wsr a2, intclear + movi a2, 0 + wsr a2, ccompare2 + + movi a3, 40 + rsr a2, ccount + addi a2, a2, 20 + wsr a2, ccompare1 + addi a2, a2, 20 + wsr a2, ccompare0 + rsync + rsr a2, interrupt + assert eqi, a2, 0 + + movi a2, 0x40 + wsr a2, intenable + waiti 0 + test_fail +2: + rsr a2, exccause + assert eqi, a2, 4 /* LEVEL1_INTERRUPT_CAUSE */ +test_end +test_suite_end
--
1.7.6.4
Blue Swirl
AppliedRe: [Qemu-devel] [PATCH] target-xtensa: update qemu-doc.texi
In reply to Max FilippovThanks, applied.
Quoted 149 lines · Max Filippov
Signed-off-by Max Filippov <[email protected]>---
qemu-doc.texi | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-tech.texi | 40 +++++++++++++++++++++++++++++++++-------2 files changed, 88 insertions(+), 7 deletions(-)qemu-doc.texi +0
-0@@ -110,6 +110,7 @@ For system emulation, the following hardware targets are supported:@item Syborg SVP base model (ARM Cortex-A8).
@item AXIS-Devboard88 (CRISv32 ETRAX-FS).
@item Petalogix Spartan 3aDSP1800 MMU ref design (MicroBlaze). +@item Avnet LX60/LX110/LX200 boards (Xtensa)
@end itemize@cindex supported user mode targets
qemu-doc.texi +1
-0@@ -1446,6 +1447,7 @@ differences are mentioned in the following sections. * Cris System emulator:: * Microblaze System emulator:: * SH4 System emulator:: +* Xtensa System emulator::@end menu
@node PowerPC System emulator
qemu-doc.texi +0
-0@@ -2124,6 +2126,59 @@ TODOTODO
+@node Xtensa System emulator
+@section Xtensa System emulator
+@cindex system emulation (Xtensa)qemu-doc.texi +50
-0+ +Two executables cover simulation of both Xtensa endian options, +@file{qemu-system-xtensa} and @file{qemu-system-xtensaeb}. +Two different machine types are emulated: + +@itemize @minus +@item +Xtensa emulator pseudo board "sim" +@item +Avnet LX60/LX110/LX200 board +@end itemize + +The sim pseudo board emulation provides an environment similiar +to one provided by the proprietary Tensilica ISS. +It supports: + +@itemize @minus +@item +A range of Xtensa CPUs, default is the DC232B +@item +Console and filesystem access via semihosting calls +@end itemize + +The Avnet LX60/LX110/LX200 emulation supports: + +@itemize @minus +@item +A range of Xtensa CPUs, default is the DC232B +@item +16550 UART +@item +OpenCores 10/100 Mbps Ethernet MAC +@end itemize + +@c man begin OPTIONS + +The following options are specific to the Xtensa emulation: + +@table @option + +@item -semihosting +Enable semihosting syscall emulation. + +Xtensa semihosting provides basic file IO calls, such as open/read/write/seek/select. +Tensilica baremetal libc for ISS and linux platform "sim" use this interface. + +Note that this allows guest direct access to the host filesystem, +so should only be used with trusted guest OS. + +@end table@node QEMU User space emulator
@chapter QEMU User space emulatorqemu-tech.texi +0
-0@@ -42,13 +42,14 @@@chapter Introduction
@menu
qemu-tech.texi +8
-7-* intro_features:: Features -* intro_x86_emulation:: x86 and x86-64 emulation -* intro_arm_emulation:: ARM emulation -* intro_mips_emulation:: MIPS emulation -* intro_ppc_emulation:: PowerPC emulation -* intro_sparc_emulation:: Sparc32 and Sparc64 emulation -* intro_other_emulation:: Other CPU emulation +* intro_features:: Features +* intro_x86_emulation:: x86 and x86-64 emulation +* intro_arm_emulation:: ARM emulation +* intro_mips_emulation:: MIPS emulation +* intro_ppc_emulation:: PowerPC emulation +* intro_sparc_emulation:: Sparc32 and Sparc64 emulation +* intro_xtensa_emulation:: MIPS emulation +* intro_other_emulation:: Other CPU emulation@end menu
@node
intro_featuresqemu-tech.texi +0
-0@@ -259,6 +260,31 @@ Current QEMU limitations:@end itemize
+@node
intro_xtensa_emulation
+@section Xtensa emulationqemu-tech.texi +23
-0+ +@itemize + +@item Core Xtensa ISA emulation, including most options: code density, +loop, extended L32R, 16- and 32-bit multiplication, 32-bit division, +MAC16, miscellaneous operations, boolean, multiprocessor synchronization, +conditional store, exceptions, relocatable vectors, unaligned exception, +interrupts (including high priority and timer), hardware alignment, +region protection, region translation, MMU, windowed registers, thread +pointer, processor ID. + +@item Not implemented options: FP coprocessor, coprocessor context, +data/instruction cache (including cache prefetch and locking), XLMI, +processor interface, debug. Also options not covered by the core ISA +(e.g. FLIX, wide branches) are not implemented. + +@item Can run most Xtensa Linux binaries. + +@item New core configuration that requires no additional instructions +may be created from overlay with minimal amount of hand-written code. + +@end itemize +@node
intro_other_emulation
@section Other CPU emulation--
1.7.6.4