This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

math context save for floating point coprocessor and context save switch for interrupt attribute patch.


I fount the interrupt attribute patch from Michael Schwingen and Kai Ruottu an excellent initiative. It is extremely helpful when you want to write exception handlers and interrupt handlers in "C" without the need for any complex assembler macros. I found however a few details in it that I have changed somewhat to solve a few possible problems when compiled for 68020 and successors.

 

Let us suppose the following example:

 

static void __attribute__ ((interrupt)) interrupt_test (void)

 {

  static int n=0;

 

  n++;

  DoSomething("Test");

 }

 

with the original patch it is translated into:

 

interrupt_test:

      link.w %a6,#0

      fmovm #0x3,-(%sp)

      movm.l #0xc0c1,-(%sp)

      addq.l #1,n.12

      pea .LC2

      jsr DoSomething

      movm.l -44(%a6),#0x8303

      fmovm -24(%a6),#0xc0

      unlk %a6

      rte

 

Which is fine at first sight except that when the interrupt occurs in the middle of a floating point instruction, it could generate a serious problem because the math coprocessor context is not saved. With this corrected patch, it will be translated into (with the "-mefpucs" switch on):

 

interrupt_test:

      fsave -(%sp)

      fmoveml %fpcr/%fpsr/%fpiar,-(%sp)

      link.w %a6,#0

      fmovm #0x3,-(%sp)

      movm.l #0xc0c1,-(%sp)

      addq.l #1,n.12

      pea .LC2

      jsr DoSomething

      movm.l -44(%a6),#0x8303

      fmovm -24(%a6),#0xc0

      unlk %a6

      fmoveml (%sp)+,%fpcr/%fpsr/%fpiar

      frestore (%sp)+

      rte

 

 

and into (with no "-mefpucs" switch on, or with "-mnoefpucs"):

 

interrupt_test:

      link.w %a6,#0

      movm.l #0xc0c1,-(%sp)

      addq.l #1,n.12

      pea .LC2

      jsr DoSomething

      movm.l -20(%a6),#0x8303

      unlk %a6

      rte

 

The original patch did not save the math coprocessor context. The compiler will add a fsave -(%sp) and fmoveml %fpcr/%fpsr/%fpiar,-(%sp) instructions into the prologue and the fmoveml (%sp)+,%fpcr/%fpsr/%fpiar and frestore (%sp)+ in the epilogue of the exception handling (interrupt) function. These will only be generated if a floating point variable or an other function is called. The above case shows a typical case where an other function is called inside the exception (interrupt) handler. Since the compiler does not know what is happening in the "DoSomething()" function, it assumes the worst case and generates a math coprocessor context save and some floating point registers are saved also. These floating point operations take some time and could create to much overhead is some cases. Since in most cases there are not nessasary, because there are no floating point instructions to be handeled inside an exception or interrupt handler, I have added a new compiler switch, called "-mefpucs" (Motorola Exception Floating Point Unit Context Save). Basically it turns on and off the context save and restore sequences inside an exception (interrupt) handler. So that it can be turned on and off at will. This switch is only useful if the target system has a floating-point unit present (on 68020 or 68030 with 68881or 68882, 68040 or 68060). This switch not required when a software floating point library is used (on 68000, 683XX or dragonball).

 

The patch is made for the gcc-2.95.2 release compiler. Please contact me if you find any problems with it.

 

I hope this is useful for someone,

 

Ken

 

int_attr.patch

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]