Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2016-06

How do I find out which registers are actually used in an interrupt procedure and need to get pushed

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Ring

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

Reply by email

Jonas Maebe
to Michael Ring

Michael Ring wrote on Thu, 30 Jun 2016:

Show quoted text 8 lines
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.

You'll probably want to modify
tcpuparamanager.get_volatile_registers_(int/fpu) in compiler/mips/cpupara.pas based on the passed calloption.

Volatile registers are registers that do not need to be saved by the callee according to the ABI, even if they are modified by the callee. For interrupt routines, you'll probably want to return an empty set there.

Jonas

Reply by email

Michael Ring
to Jonas Maebe

This tip worked just fine, I was too blind to see how this works .....

Thank you Jonas!

Michael

Jonas Maebe wrote 26 lines
Michael Ring wrote on Thu, 30 Jun 2016: > 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. You'll probably want to modify tcpuparamanager.get_volatile_registers_(int/fpu) in compiler/mips/cpupara.pas based on the passed calloption. Volatile registers are registers that do not need to be saved by the callee according to the ABI, even if they are modified by the callee. For interrupt routines, you'll probably want to return an empty set there. Jonas _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email