Msg/ClobberedRegs: Difference between revisions

From CPUlator Wiki

< Msg
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
_start:
_start:
bl Func
bl Func
    nop
nop
      
      
Func:
Func:
add r4, #1 // Modify a callee-saved register
add r4, #1 // Modify a callee-saved register
    bx lr
bx lr
</syntaxhighlight>
</syntaxhighlight>


==== Nios II ====
<syntaxhighlight lang="Asm" line highlight="8">
.global _start
_start:
call Func
nop
   
Func:
addi r16, r16, 1 # Modify a callee-saved register
ret
</syntaxhighlight>
==== MIPS ====
<syntaxhighlight lang="Asm" line highlight="8">
.global _start
_start:
    jal Func
    nop
Func:
    addiu $s0, $s0, 1 # Modify a callee-saved register
    jr $ra
</syntaxhighlight>


=== Debugging ===
=== Debugging ===

Latest revision as of 03:52, 17 March 2019

A calling convention defines which registers a function is allowed to modify (caller-saved), and which registers a function should preserve (callee-saved). Clobbering a register means overwriting its value. This message tells you that there were callee-saved registers (those a function should not modify) that were changed inside the current function.

Examples

ARMv7

.global _start
_start:
	bl Func
	nop
    
Func:
	add r4, #1			// Modify a callee-saved register
	bx lr

Nios II

.global _start
_start:
	call Func
	nop
    
Func:
	addi r16, r16, 1			# Modify a callee-saved register
	ret

MIPS

.global _start
_start:
    jal Func
    nop

Func:
    addiu $s0, $s0, 1	# Modify a callee-saved register
    jr $ra

Debugging

  • This message is complaining that one or more registers differ between the start of the function and at the function return. Use breakpoints and make a note of the value of those registers at both the function entry and return. Are they the same?
  • If your function wants to (temporarily) modify callee-saved registers, it should preserve its value first, usually by storing the old value onto the stack and restoring it just before leaving the function. Saving and restoring (also called spilling and filling) can go wrong in many ways, such placing the stack at a location that doesn't contain memory.

Implementation

The simulator identifies idiomatic call and return instructions executed at runtime. It records the values of registers when executing call instructions, and verifies that callee-saved registers haven't changed when executing the matching function return. This warning is generated at the return instruction.

Disabling this message

This debugging check can be disabled in the Debugging Checks section of the Settings box: Function clobbered callee-saved register. The main reason you might consider disabling this warning is if you are intentionally using a non-standard calling convention.