[PATCH v3 2/6] mips: Adapt mcount for microMIPSr6

Jovan Dmitrovic jovan.dmitrovic@htecgroup.com
Wed Sep 3 13:53:26 GMT 2025


Changes a few MIPS instructions in the mcount function to appropriate
microMIPSr6 counterparts.
---
 sysdeps/mips/machine-gmon.h | 84 +++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/sysdeps/mips/machine-gmon.h b/sysdeps/mips/machine-gmon.h
index 1f9af72d6b..5537f40288 100644
--- a/sysdeps/mips/machine-gmon.h
+++ b/sysdeps/mips/machine-gmon.h
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <sgidefs.h>
+#include <sysdep.h>
 
 #define _MCOUNT_DECL(frompc,selfpc) \
 static void __attribute_used__ __mcount (u_long frompc, u_long selfpc)
@@ -34,6 +35,43 @@ static void __attribute_used__ __mcount (u_long frompc, u_long selfpc)
 # define CPRESTORE
 #endif
 
+#if __mips_isa_rev > 5 && defined (__mips_micromips)
+#define MCOUNT asm(\
+	".globl _mcount;\n\t" \
+	".align 2;\n\t" \
+	".set push;\n\t" \
+	".set nomips16;\n\t" \
+	".type _mcount,@function;\n\t" \
+	".ent _mcount\n\t" \
+        "_mcount:\n\t" \
+        ".frame $sp,44,$31\n\t" \
+        ".set noreorder;\n\t" \
+        ".set noat;\n\t" \
+        CPLOAD \
+	"subu $29,$29,48;\n\t" \
+	CPRESTORE \
+        "sw $4,24($29);\n\t" \
+        "sw $5,28($29);\n\t" \
+        "sw $6,32($29);\n\t" \
+        "sw $7,36($29);\n\t" \
+        "sw $2,40($29);\n\t" \
+        "sw $1,16($29);\n\t" \
+        "sw $31,20($29);\n\t" \
+        "move $5,$31;\n\t" \
+        "move $4,$1;\n\t" \
+        "balc __mcount;\n\t" \
+        "lw $4,24($29);\n\t" \
+        "lw $5,28($29);\n\t" \
+        "lw $6,32($29);\n\t" \
+        "lw $7,36($29);\n\t" \
+        "lw $2,40($29);\n\t" \
+        "lw $1,20($29);\n\t" \
+        "lw $31,16($29);\n\t" \
+        "addu $29,$29,56;\n\t" \
+        "jrc $1;\n\t" \
+	".end _mcount;\n\t" \
+	".set pop");
+#else
 #define MCOUNT asm(\
 	".globl _mcount;\n\t" \
 	".align 2;\n\t" \
@@ -71,6 +109,7 @@ static void __attribute_used__ __mcount (u_long frompc, u_long selfpc)
         "move $31,$1;\n\t" \
 	".end _mcount;\n\t" \
 	".set pop");
+#endif
 
 #else
 
@@ -97,6 +136,50 @@ static void __attribute_used__ __mcount (u_long frompc, u_long selfpc)
 # error "Unknown ABI"
 #endif
 
+#if __mips_isa_rev > 5 && defined (__mips_micromips)
+#define MCOUNT asm(\
+	".globl _mcount;\n\t" \
+	".align 3;\n\t" \
+	".set push;\n\t" \
+	".set nomips16;\n\t" \
+	".type _mcount,@function;\n\t" \
+	".ent _mcount\n\t" \
+        "_mcount:\n\t" \
+        ".frame $sp,88,$31\n\t" \
+        ".set noat;\n\t" \
+        PTR_SUBU_STRING " $29,$29,96;\n\t" \
+        CPSETUP \
+        "sd $4,24($29);\n\t" \
+        "sd $5,32($29);\n\t" \
+        "sd $6,40($29);\n\t" \
+        "sd $7,48($29);\n\t" \
+        "sd $8,56($29);\n\t" \
+        "sd $9,64($29);\n\t" \
+        "sd $10,72($29);\n\t" \
+        "sd $11,80($29);\n\t" \
+        "sd $2,16($29);\n\t" \
+        "sd $1,0($29);\n\t" \
+        "sd $31,8($29);\n\t" \
+        "move $5,$31;\n\t" \
+        "move $4,$1;\n\t" \
+        "balc __mcount;\n\t" \
+        "ld $4,24($29);\n\t" \
+        "ld $5,32($29);\n\t" \
+        "ld $6,40($29);\n\t" \
+        "ld $7,48($29);\n\t" \
+        "ld $8,56($29);\n\t" \
+        "ld $9,64($29);\n\t" \
+        "ld $10,72($29);\n\t" \
+        "ld $11,80($29);\n\t" \
+        "ld $2,16($29);\n\t" \
+        "ld $1,8($29);\n\t" \
+        "ld $31,0($29);\n\t" \
+        CPRETURN \
+        PTR_ADDU_STRING " $29,$29,96;\n\t" \
+        "jrc $1;\n\t" \
+	".end _mcount;\n\t" \
+	".set pop");
+#else
 #define MCOUNT asm(\
 	".globl _mcount;\n\t" \
 	".align 3;\n\t" \
@@ -142,5 +225,6 @@ static void __attribute_used__ __mcount (u_long frompc, u_long selfpc)
         "move $31,$1;\n\t" \
 	".end _mcount;\n\t" \
 	".set pop");
+#endif
 
 #endif
-- 
2.34.1


More information about the Libc-alpha mailing list