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

4.115
Last change on this file since 52f6502 was 52f6502, checked in by Daniel Cederman <cederman@…>, on Mar 13, 2014 at 1:13:55 PM

bsps/sparc: Add common gnat handler function prototype.

Moved prototype for gnat_install_handler and gnat_install_handler_common to common header file. Placed header file in bsp namespace.

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