Gary-Hobson commented on code in PR #18150:
URL: https://github.com/apache/nuttx/pull/18150#discussion_r2758166959


##########
libs/libc/machine/arm/arch_mcount.S:
##########
@@ -29,6 +29,22 @@
 
        .type   __gnu_mcount_nc, %function
 __gnu_mcount_nc:
+#if defined(CONFIG_ARCH_CORTEXM0) || defined(CONFIG_ARCH_CORTEXM23)
+       /* Cortex-M0/M0+/M23 - ARMv6-M and ARMv8-M Baseline */
+       /* These cores only support limited Thumb-1 instruction set */
+       push    {r0, r1, r2, r3, lr}            /* Save registers */
+       mov     r1, lr
+       movs    r2, #1
+       bics    r1, r2                          /* R1 contains callee address, 
with thumb bit cleared */
+       ldr     r0, [sp, #20]                   /* R0 contains caller address */
+       movs    r2, #1
+       bics    r0, r2                          /* Clear thumb bit */
+       bl      mcount_internal                 /* Jump to internal _mcount() 
implementation */
+       pop     {r0, r1, r2, r3}                /* Restore r0-r3 */
+       pop     {r1}                            /* Pop saved lr into r1 */

Review Comment:
   This is the test result from using QEMU with the micro:bit (Cortex-M0). It 
can correctly collect data without modifying the caller's registers.
   ```
   qemu-system-arm  -M microbit -kernel mcount.elf -nographic -s -S
   
   Breakpoint 1, mcount_internal (frompc=0x398 <main+28>, selfpc=0x318 
<mcount_test+12>) at mcount.c:155
   155             print("mcount_internal:: frompc: ");
   (gdb) bt
   #0  mcount_internal (frompc=0x398 <main+28>, selfpc=0x318 <mcount_test+12>) 
at mcount.c:155
   #1  0x000003c6 in __gnu_mcount_nc () at startup.s:91
   #2  0x00000318 in mcount_test (a=17, b=0, c=1040) at mcount.c:164
   #3  0x00000398 in main () at mcount.c:180
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to