@@ -245,3 +245,46 @@ void __mcount(unsigned int frompc, unsigned int selfpc)
245245 arc -> count ++ ;
246246 }
247247}
248+
249+ __asm__
250+ (
251+ "\t" ".set push" "\n"
252+ "\t" ".set noreorder" "\n"
253+ "\t" ".set noat" "\n"
254+
255+ "\t" ".global _mcount" "\n"
256+ "\t" ".ent _mcount" "\n"
257+
258+ "\t" "_mcount:" "\n"
259+
260+ // Generated code already substracts 8 bytes
261+ // We store our ra, at and a0-a3
262+ "\t" "\t" "daddiu $sp, $sp, -56" "\n" // Adjust stack pointer for 64-bit registers, 7 registers * 8 bytes each
263+ "\t" "\t" "sd $ra, 0($sp)" "\n" // store ra
264+ "\t" "\t" "sd $at, 8($sp)" "\n" // at = ra of caller
265+ "\t" "\t" "sd $a0, 16($sp)" "\n"
266+ "\t" "\t" "sd $a1, 24($sp)" "\n"
267+ "\t" "\t" "sd $a2, 32($sp)" "\n"
268+ "\t" "\t" "sd $a3, 40($sp)" "\n"
269+
270+ // Call internal C handler
271+ "\t" "\t" "move $a0, $at" "\n"
272+ "\t" "\t" "move $a1, $ra" "\n"
273+ "\t" "\t" "jal __mcount" "\n"
274+ "\t" "\t" "nop" "\n"
275+
276+ // Restore registers
277+ "\t" "\t" "ld $ra, 0($sp)" "\n"
278+ "\t" "\t" "ld $at, 8($sp)" "\n"
279+ "\t" "\t" "ld $a0, 16($sp)" "\n"
280+ "\t" "\t" "ld $a1, 24($sp)" "\n"
281+ "\t" "\t" "ld $a2, 32($sp)" "\n"
282+ "\t" "\t" "ld $a3, 40($sp)" "\n"
283+ "\t" "\t" "daddiu $sp, $sp, 56" "\n" // Adjust stack pointer back
284+ "\t" "\t" "jr $ra" "\n"
285+ "\t" "\t" "move $ra, $at" "\n" // restore caller's ra
286+
287+ "\t" ".end _mcount" "\n"
288+
289+ "\t" ".set pop" "\n"
290+ );
0 commit comments