target/avr: Ignore unimplemented WDR opcode
PATCH 1/1 target/avr: Ignore unimplemented WDR opcode
Running the WDR opcode triggers a segfault:
$ cat > foo.S << EOF
Quoted 3 lines
__start:
wdr
EOF
$ avr-gcc -nostdlib -nostartfiles -mmcu=avr6 foo.S -o foo.elf
$ qemu-system-avr -serial mon:stdio -nographic -no-reboot \
-M mega -bios foo.elf -d in_asm --singlestep
IN:
0x00000000: WDR
Segmentation fault (core dumped)(gdb) bt
#0 0x00005555add0b23a in gdb_get_cpu_pid (cpu=0x5555af5a4af0) at ../gdbstub.c:718
#1 0x00005555add0b2dd in gdb_get_cpu_process (cpu=0x5555af5a4af0) at ../gdbstub.c:743
#2 0x00005555add0e477 in gdb_set_stop_cpu (cpu=0x5555af5a4af0) at ../gdbstub.c:2742
#3 0x00005555adc99b96 in cpu_handle_guest_debug (cpu=0x5555af5a4af0) at ../softmmu/cpus.c:306
#4 0x00005555adcc66ab in rr_cpu_thread_fn (arg=0x5555af5a4af0) at ../accel/tcg/tcg-accel-ops-rr.c:224
#5 0x00005555adefaf12 in qemu_thread_start (args=0x5555af5d9870) at ../util/qemu-thread-posix.c:521
#6 0x00007f692d940ea5 in start_thread () from /lib64/libpthread.so.0
#7 0x00007f692d6699fd in clone () from /lib64/libc.so.6Since the watchdog peripheral is not implemented, simply log the opcode as unimplemented and keep going.
--- target/avr/helper.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
target/avr/helper.c +1 -5
@@ -188,11 +188,7 @@ void helper_break(CPUAVRState *env)void helper_wdr (CPUAVRState *env) { -CPUState *cs =env_cpu (env); - -/* WD is not implemented yet, placeholder */ - cs->exception_index =EXCP_DEBUG ; -cpu_loop_exit (cs); +qemu_log_mask (LOG_UNIMP ,"WDG reset (not implemented)\n" ); }/*
Signature · 1 line
2.26.3
Le 5/2/21 à 9:09 PM, Philippe Mathieu-Daudé a écrit :
Quoted 37 lines
Running the WDR opcode triggers a segfault:
$ cat > foo.S << EOFQuoted 3 lines
__start:
wdr
EOF$ avr-gcc -nostdlib -nostartfiles -mmcu=avr6 foo.S -o foo.elf $ qemu-system-avr -serial mon:stdio -nographic -no-reboot \ -M mega -bios foo.elf -d in_asm --singlestep IN: 0x00000000: WDR Segmentation fault (core dumped)(gdb) bt #0 0x00005555add0b23a in gdb_get_cpu_pid (cpu=0x5555af5a4af0) at ../gdbstub.c:718 #1 0x00005555add0b2dd in gdb_get_cpu_process (cpu=0x5555af5a4af0) at ../gdbstub.c:743 #2 0x00005555add0e477 in gdb_set_stop_cpu (cpu=0x5555af5a4af0) at ../gdbstub.c:2742 #3 0x00005555adc99b96 in cpu_handle_guest_debug (cpu=0x5555af5a4af0) at ../softmmu/cpus.c:306 #4 0x00005555adcc66ab in rr_cpu_thread_fn (arg=0x5555af5a4af0) at ../accel/tcg/tcg-accel-ops-rr.c:224 #5 0x00005555adefaf12 in qemu_thread_start (args=0x5555af5d9870) at ../util/qemu-thread-posix.c:521 #6 0x00007f692d940ea5 in start_thread () from /lib64/libpthread.so.0 #7 0x00007f692d6699fd in clone () from /lib64/libc.so.6Since the watchdog peripheral is not implemented, simply log the opcode as unimplemented and keep going.
Reported-by Fred Konrad <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/avr/helper.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)target/avr/helper.c +0
-0
target/avr/helper.c void helper_break(CPUAVRState *env) · line 192
Quoted 10 lines
target/avr/helper.c +1
-5@@ -188,11 +188,7 @@ void helper_break(CPUAVRState *env)void helper_wdr (CPUAVRState *env) { -CPUState *cs =env_cpu (env); - -/* WD is not implemented yet, placeholder */ - cs->exception_index =EXCP_DEBUG ; -cpu_loop_exit (cs); +qemu_log_mask (LOG_UNIMP ,"WDG reset (not implemented)\n" ); }
Seems ok to me, at least better than having a segfault.
Quoted 3 lines
target/avr/helper.c +0
-0/*
Cc'ing qemu-trivial@
Quoted 62 lines · Fred Konrad
Le 5/2/21 à 9:09 PM, Philippe Mathieu-Daudé a écrit :
Quoted 44 lines
Running the WDR opcode triggers a segfault:
$ cat > foo.S << EOF > __start: > wdr > EOF $ avr-gcc -nostdlib -nostartfiles -mmcu=avr6 foo.S -o foo.elf $ qemu-system-avr -serial mon:stdio -nographic -no-reboot \ -M mega -bios foo.elf -d in_asm --singlestep IN: 0x00000000: WDR Segmentation fault (core dumped)(gdb) bt
#00x00005555add0b23aingdb_get_cpu_pid(cpu=0x5555af5a4af0) at../gdbstub.c:718
#10x00005555add0b2ddingdb_get_cpu_process(cpu=0x5555af5a4af0) at../gdbstub.c:743
#20x00005555add0e477ingdb_set_stop_cpu(cpu=0x5555af5a4af0) at../gdbstub.c:2742
#30x00005555adc99b96incpu_handle_guest_debug(cpu=0x5555af5a4af0) at../softmmu/cpus.c:306
#40x00005555adcc66abinrr_cpu_thread_fn(arg=0x5555af5a4af0) at../accel/tcg/tcg-accel-ops-rr.c:224
#50x00005555adefaf12inqemu_thread_start(args=0x5555af5d9870) at../util/qemu-thread-posix.c:521#60x00007f692d940ea5instart_thread() from/lib64/libpthread.so.0
#70x00007f692d6699fdin clone () from/lib64/libc.so.6Since the watchdog peripheral is not implemented, simply log the opcode as unimplemented and keep going.
Reported-by Fred Konrad <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/avr/helper.c| 6 +-----1 file changed, 1 insertion(+), 5 deletions(-)target/avr/helper.c +0
-0target/avr/helper.c void helper_break(CPUAVRState *env) · line 191
Quoted 9 lines
target/avr/helper.c +1
-5@@ -188,11 +188,7 @@ void helper_break(CPUAVRState *env) void helper_wdr(CPUAVRState *env) { - CPUState *cs = env_cpu(env); - - /* WD is not implemented yet, placeholder */ - cs->exception_index = EXCP_DEBUG; - cpu_loop_exit(cs); + qemu_log_mask(LOG_UNIMP, "WDG reset (not implemented)\n"); }Seems ok to me, at least better than having a segfault.
Reviewed-by KONRAD Frederic <[email protected]>Quoted 2 lines
target/avr/helper.c +0
-0/*
Laurent Vivier
AppliedLe 13/05/2021 à 19:04, Philippe Mathieu-Daudé a écrit :
Quoted 1 line
Cc'ing qemu-trivial@
Applied to my trivial-patches branch.
Thanks,
Laurent
Quoted 64 lines · Fred Konrad
Quoted 62 lines
Le 5/2/21 à 9:09 PM, Philippe Mathieu-Daudé a écrit :
Quoted 44 lines
Running the WDR opcode triggers a segfault:
$ cat > foo.S << EOF > __start: > wdr > EOF $ avr-gcc -nostdlib -nostartfiles -mmcu=avr6 foo.S -o foo.elf $ qemu-system-avr -serial mon:stdio -nographic -no-reboot \ -M mega -bios foo.elf -d in_asm --singlestep IN: 0x00000000: WDR Segmentation fault (core dumped)(gdb) bt
#00x00005555add0b23aingdb_get_cpu_pid(cpu=0x5555af5a4af0) at../gdbstub.c:718
#10x00005555add0b2ddingdb_get_cpu_process(cpu=0x5555af5a4af0) at../gdbstub.c:743
#20x00005555add0e477ingdb_set_stop_cpu(cpu=0x5555af5a4af0) at../gdbstub.c:2742
#30x00005555adc99b96incpu_handle_guest_debug(cpu=0x5555af5a4af0) at../softmmu/cpus.c:306
#40x00005555adcc66abinrr_cpu_thread_fn(arg=0x5555af5a4af0) at../accel/tcg/tcg-accel-ops-rr.c:224
#50x00005555adefaf12inqemu_thread_start(args=0x5555af5d9870) at../util/qemu-thread-posix.c:521#60x00007f692d940ea5instart_thread() from/lib64/libpthread.so.0
#70x00007f692d6699fdin clone () from/lib64/libc.so.6Since the watchdog peripheral is not implemented, simply log the opcode as unimplemented and keep going.
Reported-by Fred Konrad <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/avr/helper.c| 6 +-----1 file changed, 1 insertion(+), 5 deletions(-)target/avr/helper.c +0
-0target/avr/helper.c void helper_break(CPUAVRState *env) · line 191
Quoted 9 lines
target/avr/helper.c +1
-5@@ -188,11 +188,7 @@ void helper_break(CPUAVRState *env) void helper_wdr(CPUAVRState *env) { - CPUState *cs = env_cpu(env); - - /* WD is not implemented yet, placeholder */ - cs->exception_index = EXCP_DEBUG; - cpu_loop_exit(cs); + qemu_log_mask(LOG_UNIMP, "WDG reset (not implemented)\n"); }Seems ok to me, at least better than having a segfault.
Reviewed-by KONRAD Frederic <[email protected]>Quoted 2 lines
target/avr/helper.c +0
-0/*