[fpc-devel] How do I find out which registers are actually used in an interrupt procedure and need to get pushed

Michael Ring mail at michael-ring.org
Thu Jun 30 15:36:11 CEST 2016


Hi!

I am trying to make the interrupt keyword work for mipsel (to use with 
pic32mx)

I have found the appropriate places in cgcpu.pas and I have the basics 
up and running, correct code for mipsel is generated.

One issue I have at the moment is that I waste quite a number of 
precious memory for saving all standard and Floating-Point Registers of 
the CPU because I do not know which actually need saving.

So far I understood the fpc code that registers s0-s7 are automagically 
flagged when used as those are the registers that must be saved in the 
context of a standard procedure/function call.

Same does apply for some of the Floating Point Registers.

But when I look at the list of registers to be saved the registers like 
$v0 and $v1 are not included, but usually used. Things get worse with 
floating point, there I also do not get info when e.g. $f2 is used, so I 
cannot decide if it is necessary to push the floatingpoint registers to 
the stack or to skip that step because no floating point is used in the 
interupt handler.


For example:

This simple code:

procedure SysTick_interrupt; interrupt; [public, alias: 
'CORE_TIMER_VECTOR_interrupt'];
var
//  local1 : real;
begin
   Inc(SysTickCounter, TSystemCore.TimerIntResolution);
//  local1 := SysTickCounter * 1.05;
end;

compiles to:

.Ll2:
         lui     $v0,%hi(TC_$MBF.SYSTEMCORE_$$_SYSTICKCOUNTER)
         lw      $v0,%lo(TC_$MBF.SYSTEMCORE_$$_SYSTICKCOUNTER)($v0)
         addiu   $v0,$v0,1000
         lui     $v1,%hi(TC_$MBF.SYSTEMCORE_$$_SYSTICKCOUNTER)
         sw      $v0,%lo(TC_$MBF.SYSTEMCORE_$$_SYSTICKCOUNTER)($v1)


so in this case only $v0,$v1 registers need to get pushed, no need to 
push any Floating Point Registers, but those two are not in the list of 
the used registers for this procedure

When I uncomment the two lines in the example I additionally see that 
$f2 is used, but also not reported as used (which makes sense in the 
context of a normal procedure, but for an Interrupt Routine this means 
all the Flotingpoint registers need to be saved unconditionally as I 
cannot detect if floats are used.

Any help & insight appreceated,

Michael





More information about the fpc-devel mailing list