Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:09

0001 /*
0002  *
0003  * Support for gnat/rtems interrupts and exception handling.
0004  * Jiri Gaisler, ESA/ESTEC, 17-02-1999.
0005  *
0006  */
0007 
0008 #include <unistd.h> /* getpid */
0009 
0010 #include <bsp.h>
0011 #include <rtems/bspIo.h>
0012 #include <signal.h>
0013 #include <stdlib.h>
0014 #include <bsp/gnatcommon.h>
0015 
0016 /*
0017  * Synchronous trap handler. Map the trap number of SIGFPE, SIGSEGV
0018  * or SIGILL to generate the corresponding Ada exception.
0019  */
0020 static rtems_isr
0021 __gnat_exception_handler(rtems_vector_number trap)
0022 {
0023   uint32_t         real_trap;
0024   uint32_t         signal;
0025 
0026   real_trap = SPARC_REAL_TRAP_NUMBER (trap);
0027   switch (real_trap)
0028     {
0029     case 0x08:          /* FPU exception */
0030     case 0x0A:          /* TAG overflow */
0031     case 0x82:          /* divide by zero */
0032       signal = SIGFPE;      /* Will cause Constraint_Error */
0033       break;
0034     case 0x01:          /* Instruction access exception */
0035     case 0x09:          /* Data access exception */
0036       signal = SIGSEGV;     /* Will cause Storage_Error */
0037       break;
0038     default:            /* Anything else ... */
0039       signal = SIGILL;      /* Will cause Program_Error */
0040       break;
0041     }
0042   kill (getpid (), signal);
0043 }
0044 
0045 /*
0046  * Asynchronous trap handler. As it happens, the interrupt trap numbers for
0047  * SPARC is 17 - 31, so we just map then directly on the same signal number.
0048  */
0049 static rtems_isr
0050 __gnat_interrupt_handler (rtems_vector_number trap)
0051 {
0052   uint32_t         real_trap;
0053 
0054   real_trap = SPARC_REAL_TRAP_NUMBER (trap);
0055 
0056   kill (getpid (), real_trap);
0057 
0058 }
0059 
0060 /*
0061  * Default signal handler with error reporting
0062  */
0063 
0064 static void
0065 __gnat_signals_Abnormal_termination_handler (int signo)
0066 {
0067   switch (signo)
0068     {
0069     case SIGFPE:
0070       printk("\nConstraint_Error\n");
0071       break;
0072     case SIGSEGV:
0073       printk("\nStorage_Error\n");
0074       break;
0075     default:
0076       printk("\nProgram_Error\n");
0077       break;
0078     }
0079   exit (1);
0080 }
0081 
0082 const struct sigaction __gnat_error_vector =
0083 {0, -1,
0084  {__gnat_signals_Abnormal_termination_handler}};
0085 
0086 void
0087 __gnat_install_handler_common (int t1, int t2)
0088 {
0089   uint32_t         trap;
0090   rtems_isr_entry previous_isr;
0091 
0092   sigaction (SIGSEGV, &__gnat_error_vector, NULL);
0093   sigaction (SIGFPE, &__gnat_error_vector, NULL);
0094   sigaction (SIGILL, &__gnat_error_vector, NULL);
0095 
0096   for (trap = 0; trap < 256; trap++)
0097     {
0098 
0099       /*
0100          *  Skip window overflow, underflow, and flush as well as software
0101          *  trap 0 which we will use as a shutdown. Also avoid trap 0x70 - 0x7f
0102          *  which cannot happen and where some of the space is used to pass
0103          *  paramaters to the program.  0x80 for system traps and
0104      *  0x81 - 0x83 by the remote debugging stub.
0105      *  Avoid two bsp specific interrupts which normally are used
0106      *  by the real-time clock and UART B.
0107        */
0108 
0109       if ((trap >= 0x11) && (trap <= 0x1f))
0110     {
0111       if ((trap != t1) && (trap != t2))
0112         rtems_interrupt_catch (__gnat_interrupt_handler, trap, &previous_isr);
0113     }
0114       else if ((trap != 5 && trap != 6) && ((trap < 0x70) || (trap > 0x83)))
0115     set_vector (__gnat_exception_handler, SPARC_SYNCHRONOUS_TRAP (trap), 1);
0116     }
0117 }