1 | /* |
---|
2 | ************************************************************************** |
---|
3 | * |
---|
4 | * Component = |
---|
5 | * |
---|
6 | * Synopsis = rdbg/i386/excep.c |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | * |
---|
10 | ************************************************************************** |
---|
11 | */ |
---|
12 | |
---|
13 | #include <rtems.h> |
---|
14 | #include <rtems/error.h> |
---|
15 | #include <assert.h> |
---|
16 | #include <errno.h> |
---|
17 | #include <rdbg/rdbg.h> |
---|
18 | #include <rdbg/servrpc.h> |
---|
19 | |
---|
20 | /* ----------------------------------------------------------------- |
---|
21 | Maping of hardware exceptions into Unix-like signal numbers. |
---|
22 | It is identical to the one used by the PM and the AM. |
---|
23 | ----------------------------------------------------------------- */ |
---|
24 | |
---|
25 | int |
---|
26 | ExcepToSig (Exception_context * ctx) |
---|
27 | { |
---|
28 | int excep = getExcNum (ctx); |
---|
29 | |
---|
30 | switch (excep) { |
---|
31 | |
---|
32 | case I386_EXCEPTION_MATH_COPROC_UNAVAIL: |
---|
33 | case I386_EXCEPTION_I386_COPROC_SEG_ERR: |
---|
34 | case I386_EXCEPTION_FLOAT_ERROR: |
---|
35 | case I386_EXCEPTION_BOUND: |
---|
36 | return SIGFPE; |
---|
37 | |
---|
38 | case I386_EXCEPTION_DEBUG: |
---|
39 | case I386_EXCEPTION_BREAKPOINT: |
---|
40 | case I386_EXCEPTION_ENTER_RDBG: |
---|
41 | return SIGTRAP; |
---|
42 | |
---|
43 | case I386_EXCEPTION_OVERFLOW: |
---|
44 | case I386_EXCEPTION_DIVIDE_BY_ZERO: |
---|
45 | case I386_EXCEPTION_ILLEGAL_INSTR: |
---|
46 | return SIGILL; |
---|
47 | |
---|
48 | case I386_EXCEPTION_SEGMENT_NOT_PRESENT: |
---|
49 | case I386_EXCEPTION_STACK_SEGMENT_FAULT: |
---|
50 | case I386_EXCEPTION_GENERAL_PROT_ERR: |
---|
51 | case I386_EXCEPTION_PAGE_FAULT: |
---|
52 | return SIGSEGV; |
---|
53 | |
---|
54 | default: |
---|
55 | break; |
---|
56 | } |
---|
57 | return SIGKILL; |
---|
58 | } |
---|
59 | |
---|
60 | /*----- Breakpoint Exception management -----*/ |
---|
61 | |
---|
62 | /* |
---|
63 | * Handler for Breakpoint Exceptions : |
---|
64 | * software breakpoints. |
---|
65 | */ |
---|
66 | |
---|
67 | void |
---|
68 | BreakPointExcHdl (CPU_Exception_frame * ctx) |
---|
69 | { |
---|
70 | rtems_status_code status; |
---|
71 | rtems_id continueSemId; |
---|
72 | |
---|
73 | if ((justSaveContext) && (ctx->idtIndex == I386_EXCEPTION_ENTER_RDBG)) { |
---|
74 | PushSavedExceptCtx (_Thread_Executing->Object.id, ctx); |
---|
75 | justSaveContext = 0; |
---|
76 | } else { |
---|
77 | if (ctx->idtIndex != I386_EXCEPTION_DEBUG) { |
---|
78 | NbSerializedCtx++; |
---|
79 | rtems_semaphore_obtain (serializeSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
80 | NbSerializedCtx--; |
---|
81 | } |
---|
82 | |
---|
83 | currentTargetThread = _Thread_Executing->Object.id; |
---|
84 | |
---|
85 | #ifdef DDEBUG |
---|
86 | printk ("----------------------------------------------------------\n"); |
---|
87 | printk ("Exception %d caught at PC %x by thread %d\n", |
---|
88 | ctx->idtIndex, ctx->eip, _Thread_Executing->Object.id); |
---|
89 | printk ("----------------------------------------------------------\n"); |
---|
90 | printk ("Processor execution context at time of the fault was :\n"); |
---|
91 | printk ("----------------------------------------------------------\n"); |
---|
92 | printk (" EAX = %x EBX = %x ECX = %x EDX = %x\n", |
---|
93 | ctx->eax, ctx->ebx, ctx->ecx, ctx->edx); |
---|
94 | printk (" ESI = %x EDI = %x EBP = %x ESP = %x\n", |
---|
95 | ctx->esi, ctx->edi, ctx->ebp, ctx->esp0); |
---|
96 | printk ("----------------------------------------------------------\n"); |
---|
97 | printk ("Error code pushed by processor itself (if not 0) = %x\n", |
---|
98 | ctx->faultCode); |
---|
99 | printk ("----------------------------------------------------------\n\n"); |
---|
100 | #endif |
---|
101 | |
---|
102 | status = rtems_semaphore_create (rtems_build_name ('D', 'B', 'G', 'c'), |
---|
103 | 0, |
---|
104 | RTEMS_FIFO | |
---|
105 | RTEMS_COUNTING_SEMAPHORE | |
---|
106 | RTEMS_NO_INHERIT_PRIORITY | |
---|
107 | RTEMS_NO_PRIORITY_CEILING | |
---|
108 | RTEMS_LOCAL, 0, &continueSemId); |
---|
109 | if (status != RTEMS_SUCCESSFUL) |
---|
110 | rtems_panic ("Can't create continue semaphore: `%s'\n", |
---|
111 | rtems_status_text (status)); |
---|
112 | |
---|
113 | PushExceptCtx (_Thread_Executing->Object.id, continueSemId, ctx); |
---|
114 | |
---|
115 | switch (ctx->idtIndex) { |
---|
116 | case I386_EXCEPTION_DEBUG: |
---|
117 | DPRINTF ((" DEBUG EXCEPTION !!!\n")); |
---|
118 | ctx->eflags &= ~EFLAGS_TF; |
---|
119 | ExitForSingleStep--; |
---|
120 | rtems_semaphore_release (wakeupEventSemId); |
---|
121 | break; |
---|
122 | |
---|
123 | case I386_EXCEPTION_BREAKPOINT: |
---|
124 | DPRINTF ((" BREAKPOINT EXCEPTION !!!\n")); |
---|
125 | rtems_semaphore_release (wakeupEventSemId); |
---|
126 | break; |
---|
127 | |
---|
128 | case I386_EXCEPTION_ENTER_RDBG: |
---|
129 | DPRINTF ((" ENTER RDBG !!!\n")); |
---|
130 | rtems_semaphore_release (wakeupEventSemId); |
---|
131 | break; |
---|
132 | |
---|
133 | default: |
---|
134 | DPRINTF ((" OTHER EXCEPTION !!!\n")); |
---|
135 | rtems_semaphore_release (wakeupEventSemId); |
---|
136 | break; |
---|
137 | } |
---|
138 | |
---|
139 | rtems_semaphore_obtain (continueSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
140 | |
---|
141 | PopExceptCtx (_Thread_Executing->Object.id); |
---|
142 | rtems_semaphore_delete (continueSemId); |
---|
143 | } |
---|
144 | } |
---|