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