source: rtems/c/src/lib/libbsp/sparc/shared/gnatcommon.c @ cba119c9

4.104.114.84.95
Last change on this file since cba119c9 was 6128a4a, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 21, 2004 at 10:43:04 AM

Remove stray white spaces.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *
3 * Support for gnat/rtems interrupts and exception handling.
4 * Jiri Gaisler, ESA/ESTEC, 17-02-1999.
5 *
6 */
7
8#include <bsp.h>
9#include <signal.h>
10#include <stdlib.h>
11
12/*
13 * Synchronous trap handler. Map the trap number of SIGFPE, SIGSEGV
14 * or SIGILL to generate the corresponding Ada exception.
15 */
16
17rtems_isr __gnat_exception_handler
18  (rtems_vector_number trap)
19{
20  uint32_t         real_trap;
21  uint32_t         signal;
22
23  real_trap = SPARC_REAL_TRAP_NUMBER (trap);
24  switch (real_trap)
25    {
26    case 0x08:                  /* FPU exception */
27    case 0x0A:                  /* TAG overflow */
28    case 0x82:                  /* divide by zero */
29      signal = SIGFPE;          /* Will cause Constraint_Error */
30      break;
31    case 0x01:                  /* Instruction access exception */
32    case 0x09:                  /* Data access exception */
33      signal = SIGSEGV;         /* Will cause Storage_Error */
34      break;
35    default:                    /* Anything else ... */
36      signal = SIGILL;          /* Will cause Program_Error */
37      break;
38    }
39  kill (getpid (), signal);
40}
41
42/*
43 * Asynchronous trap handler. As it happens, the interrupt trap numbers for
44 * SPARC is 17 - 31, so we just map then directly on the same signal number.
45 */
46
47rtems_isr __gnat_interrupt_handler
48  (rtems_vector_number trap)
49{
50  uint32_t         real_trap;
51
52  real_trap = SPARC_REAL_TRAP_NUMBER (trap);
53
54  kill (getpid (), real_trap);
55
56}
57
58/*
59 * Default signal handler with error reporting
60 */
61
62void
63__gnat_signals_Abnormal_termination_handler (int signo)
64{
65  switch (signo)
66    {
67    case SIGFPE:
68      DEBUG_puts ("\nConstraint_Error\n");
69      break;
70    case SIGSEGV:
71      DEBUG_puts ("\nStorage_Error\n");
72      break;
73    default:
74      DEBUG_puts ("\nProgram_Error\n");
75      break;
76    }
77  exit (1);
78}
79
80const struct sigaction __gnat_error_vector =
81{0, -1,
82 {__gnat_signals_Abnormal_termination_handler}};
83
84void
85__gnat_install_handler_common (int t1, int t2)
86{
87  uint32_t         trap;
88  rtems_isr_entry previous_isr;
89
90  sigaction (SIGSEGV, &__gnat_error_vector, NULL);
91  sigaction (SIGFPE, &__gnat_error_vector, NULL);
92  sigaction (SIGILL, &__gnat_error_vector, NULL);
93
94  for (trap = 0; trap < 256; trap++)
95    {
96
97      /*
98         *  Skip window overflow, underflow, and flush as well as software
99         *  trap 0 which we will use as a shutdown. Also avoid trap 0x70 - 0x7f
100         *  which cannot happen and where some of the space is used to pass
101         *  paramaters to the program.  0x80 for system traps and
102         *  0x81 - 0x83 by the remote debugging stub.
103         *  Avoid two bsp specific interrupts which normally are used
104         *  by the real-time clock and UART B.
105       */
106
107      if ((trap >= 0x11) && (trap <= 0x1f))
108        {
109          if ((trap != t1) && (trap != t2))
110            rtems_interrupt_catch (__gnat_interrupt_handler, trap, &previous_isr);
111        }
112      else if ((trap != 5 && trap != 6) && ((trap < 0x70) || (trap > 0x83)))
113        set_vector (__gnat_exception_handler, SPARC_SYNCHRONOUS_TRAP (trap), 1);
114    }
115}
Note: See TracBrowser for help on using the repository browser.