Skip to content

Conversation

@agatti
Copy link
Contributor

@agatti agatti commented Sep 6, 2024

Summary

The NETDUINO2 and MICROBIT boards would not run the test suite in their current form. The former would make the test runner bail out before a REPL is ready, the latter would trigger a CPU hard fault due to Qemu's soft MMU enabled for that particular machine definition (see details).

As a bonus, Thumb targets now have a slightly more appealing crash reporting, with the exception cause and the registers content dumped to STDOUT.

(armv7m_nvic_neg_prio_requested triggers the exception - a NVIC priority of -1 signals a hard fault)

Thread 1 "qemu-system-arm" hit Breakpoint 1, 0x0000565ed7ad5fb4 in armv7m_nvic_neg_prio_requested (secure=<optimized out>, opaque=<optimized out>) at ../../hw/intc/armv7m_nvic.c:404
404     ../../hw/intc/armv7m_nvic.c: No such file or directory.
(gdb) bt
#0  0x0000565ed7ad5fb4 in armv7m_nvic_neg_prio_requested (secure=<optimized out>, opaque=<optimized out>) at ../../hw/intc/armv7m_nvic.c:404
#1  arm_v7m_mmu_idx_for_secstate_and_priv (priv=<optimized out>, secstate=<optimized out>, env=<optimized out>) at ../../target/arm/m_helper.c:2889
#2  arm_v7m_mmu_idx_for_secstate (env=0x565ef2870940, secstate=false) at ../../target/arm/m_helper.c:2900
#3  0x0000565ed7acff9c in arm_mmu_idx (env=0x565ef2870940) at ../../target/arm/helper.c:13063
#4  arm_cpu_get_phys_page_attrs_debug (cs=<optimized out>, addr=70656, attrs=0x7fff80f5be64) at ../../target/arm/helper.c:12591
#5  0x0000565ed7b9d2dc in cpu_memory_rw_debug (cpu=<optimized out>, addr=70952, ptr=<optimized out>, len=2, is_write=<optimized out>)
    at ../../softmmu/physmem.c:3473
#6  0x0000565ed7bb8ddb in target_memory_rw_debug (is_write=false, len=2, buf=0x565ef2b84d40 "", addr=70952, cpu=0x565ef2866bc0) at ../../gdbstub.c:85
#7  target_memory_rw_debug (is_write=false, len=2, buf=0x565ef2b84d40 "", addr=70952, cpu=0x565ef2866bc0) at ../../gdbstub.c:65
#8  handle_read_mem (user_ctx=<optimized out>, params=<optimized out>) at ../../gdbstub.c:1803
#9  handle_read_mem (params=<optimized out>, user_ctx=<optimized out>) at ../../gdbstub.c:1787
#10 0x0000565ed7e677de in process_string_cmd.constprop.0 (data=<optimized out>, cmds=<optimized out>, num_cmds=<optimized out>, user_ctx=0x0)
    at ../../gdbstub.c:1499
#11 0x0000565ed7bbaa0f in run_cmd_parser (data=<optimized out>, cmd=0x565ed8357c80 <read_mem_cmd_desc>) at ../../gdbstub.c:1517
#12 gdb_handle_packet (line_buf=<optimized out>) at ../../gdbstub.c:2728
#13 gdb_read_byte (ch=99 'c') at ../../gdbstub.c:3064
#14 gdb_chr_receive (opaque=<optimized out>, buf=<optimized out>, size=<optimized out>) at ../../gdbstub.c:3365
#15 0x0000565ed7dacc02 in tcp_chr_read (chan=<optimized out>, cond=<optimized out>, opaque=<optimized out>) at ../../chardev/char-socket.c:564
#16 0x0000781affd56c44 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#17 0x0000565ed7e56248 in glib_pollfds_poll () at ../../util/main-loop.c:232
#18 os_host_main_loop_wait (timeout=1000000000) at ../../util/main-loop.c:255
#19 main_loop_wait (nonblocking=<optimized out>) at ../../util/main-loop.c:531
#20 0x0000565ed7ba222c in qemu_main_loop () at ../../softmmu/runstate.c:726
#21 0x0000565ed771ffb2 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../../softmmu/main.c:50

Testing

Ran the tests for the two boards in question under Qemu (where else?).

Trade-offs and Alternatives

There should be a better way to disable soft MMU in Qemu and let MICROBIT still emit native code, but I haven't found a proper solution at the moment.

@github-actions
Copy link

github-actions bot commented Sep 6, 2024

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@agatti agatti force-pushed the fix-qemu-arm-boards branch from 7dd1535 to 60f33a8 Compare September 16, 2024 11:45
@codecov
Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.58%. Comparing base (d533c90) to head (3225c1b).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15803   +/-   ##
=======================================
  Coverage   98.58%   98.58%           
=======================================
  Files         167      167           
  Lines       21596    21596           
=======================================
  Hits        21291    21291           
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@agatti
Copy link
Contributor Author

agatti commented Dec 26, 2024

This PR is focused on making the two boards in question run the test suite, although whilst NETDUINO2 tests pass MICROBIT ones now yield failures when running inline asm tests (expected) but "framebuf_polygon", "int_big_div", and "int_big_mul" also fail - which as far as I can remember they used to pass before (but don't quote me on that).

The asm tests issues are going to disappear once the inline asm detector in "run-tests.py" gets merged from the inline rv32 asm PR, but no real clue about the other test failures - haven't attached gdb yet. Will do soon.

Turns out my VM is too slow for those tests to finish in time - wonder why that happens only on the microbit board and not on others, go figure...

@agatti agatti force-pushed the fix-qemu-arm-boards branch from 697fcd3 to 8cdea3a Compare December 26, 2024 22:58
@agatti agatti force-pushed the fix-qemu-arm-boards branch from 8cdea3a to b6d3509 Compare January 13, 2025 17:31
@agatti agatti force-pushed the fix-qemu-arm-boards branch from b6d3509 to 5090f44 Compare January 15, 2025 08:56
agatti and others added 3 commits January 16, 2025 12:10
Some PTY targets, namely `NETDUINO2` and `MICROBIT` under Qemu, take a bit
more time to present a REPL than usual.  The pyboard tool is a bit too
impatient and would bail out before any of those targets had a chance to
respond to the raw REPL request.

Co-authored-by: Damien George <damien@micropython.org>
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
When a CPU exception is raised when emulating a Thumb-capable processor,
the default exception handler would simply enter in an endless loop without
providing any further information.

This commit adds a more complete exception handler that dumps to STDOUT the
exception cause and the status of the registers at the moment of the
exception.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
The Micro:Bit machine definition in Qemu has soft MMU support enabled,
which is currently not compatible with the way MicroPython generates code
that needs to call back into non-emitted code.

As a stop-gap solution, the native code emitter for the MICROBIT board is
turned off.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
@dpgeorge dpgeorge force-pushed the fix-qemu-arm-boards branch from 5090f44 to 3225c1b Compare January 16, 2025 01:11
@dpgeorge dpgeorge merged commit 3225c1b into micropython:master Jan 16, 2025
65 checks passed
@agatti agatti deleted the fix-qemu-arm-boards branch January 16, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants