[981b99f] | 1 | /* |
---|
| 2 | ************************************************************************** |
---|
| 3 | * |
---|
| 4 | * Component = |
---|
| 5 | * |
---|
| 6 | * Synopsis = rdbg/powerpc/excep_f.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 | |
---|
[40cf43ea] | 20 | int |
---|
| 21 | ExcepToSig (Exception_context * ctx) |
---|
[981b99f] | 22 | { |
---|
| 23 | int excep = getExcNum (ctx); |
---|
[40cf43ea] | 24 | |
---|
[981b99f] | 25 | switch (excep) { |
---|
[40cf43ea] | 26 | case ASM_FLOAT_VECTOR: |
---|
| 27 | return SIGFPE; |
---|
| 28 | |
---|
| 29 | case ASM_TRACE_VECTOR: |
---|
| 30 | case ASM_PROG_VECTOR: |
---|
| 31 | case ASM_SYS_VECTOR: |
---|
| 32 | return SIGTRAP; |
---|
| 33 | |
---|
| 34 | case ASM_ISI_VECTOR: |
---|
| 35 | return SIGSEGV; |
---|
| 36 | |
---|
| 37 | case ASM_RESET_VECTOR: |
---|
| 38 | case ASM_MACH_VECTOR: |
---|
| 39 | case ASM_EXT_VECTOR: |
---|
| 40 | case ASM_ALIGN_VECTOR: |
---|
| 41 | return SIGILL; |
---|
| 42 | |
---|
| 43 | default: |
---|
| 44 | break; |
---|
| 45 | } |
---|
| 46 | return SIGKILL; |
---|
[981b99f] | 47 | } |
---|
| 48 | |
---|
| 49 | /*----- Breakpoint Exception management -----*/ |
---|
| 50 | |
---|
| 51 | /* |
---|
| 52 | * Handler for Breakpoint Exceptions : |
---|
| 53 | * software breakpoints. |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | void |
---|
[40cf43ea] | 57 | BreakPointExcHdl (CPU_Exception_frame * ctx) |
---|
[981b99f] | 58 | { |
---|
| 59 | rtems_status_code status; |
---|
| 60 | rtems_id continueSemId; |
---|
| 61 | |
---|
[40cf43ea] | 62 | /* |
---|
| 63 | * we must re-enable the floating point engine |
---|
| 64 | * if the interrupted thread is FP. Otherwise, |
---|
| 65 | * the semaphore primitives may crash when they |
---|
| 66 | * try to save FP context while switching this |
---|
| 67 | * thread... NB : deferred fp context switching |
---|
| 68 | * would 1) avoid to have to save FP, make this code |
---|
| 69 | * obsolete. |
---|
[b077dc4] | 70 | */ |
---|
[40cf43ea] | 71 | if (ctx->EXC_SRR1 & MSR_FP) { |
---|
| 72 | register unsigned long msr; |
---|
| 73 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr)); |
---|
| 74 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr | MSR_FP)); |
---|
[b077dc4] | 75 | } |
---|
| 76 | |
---|
[40cf43ea] | 77 | if ((justSaveContext) && (ctx->_EXC_number == ASM_SYS_VECTOR)) { |
---|
[981b99f] | 78 | PushSavedExceptCtx (_Thread_Executing->Object.id, ctx); |
---|
| 79 | justSaveContext = 0; |
---|
[40cf43ea] | 80 | } else { |
---|
| 81 | if (ctx->_EXC_number != ASM_TRACE_VECTOR) { |
---|
[981b99f] | 82 | NbSerializedCtx++; |
---|
[40cf43ea] | 83 | rtems_semaphore_obtain (serializeSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
[981b99f] | 84 | NbSerializedCtx--; |
---|
| 85 | } |
---|
[40cf43ea] | 86 | |
---|
[981b99f] | 87 | currentTargetThread = _Thread_Executing->Object.id; |
---|
| 88 | |
---|
| 89 | #ifdef DDEBUG |
---|
[40cf43ea] | 90 | printk ("----------------------------------------------------------\n"); |
---|
| 91 | printk ("Exception %d caught at PC %x by thread %d\n", |
---|
| 92 | ctx->_EXC_number, ctx->EXC_SRR0, _Thread_Executing->Object.id); |
---|
| 93 | printk ("----------------------------------------------------------\n"); |
---|
| 94 | printk ("Processor execution context at time of the fault was :\n"); |
---|
| 95 | printk ("----------------------------------------------------------\n"); |
---|
| 96 | printk ("\t R0 = %x\n", ctx->GPR0); |
---|
| 97 | printk ("\t R1 = %x\n", ctx->GPR1); |
---|
| 98 | printk ("\t R2 = %x\n", ctx->GPR2); |
---|
| 99 | printk ("\t R3 = %x\n", ctx->GPR3); |
---|
| 100 | printk ("\t R4 = %x\n", ctx->GPR4); |
---|
| 101 | printk ("\t R5 = %x\n", ctx->GPR5); |
---|
| 102 | printk ("\t R6 = %x\n", ctx->GPR6); |
---|
| 103 | printk ("\t R7 = %x\n", ctx->GPR7); |
---|
| 104 | printk ("\t R8 = %x\n", ctx->GPR8); |
---|
| 105 | printk ("\t R9 = %x\n", ctx->GPR9); |
---|
| 106 | printk ("\t R10 = %x\n", ctx->GPR10); |
---|
| 107 | printk ("\t R11 = %x\n", ctx->GPR11); |
---|
| 108 | printk ("\t R12 = %x\n", ctx->GPR12); |
---|
| 109 | printk ("\t R13 = %x\n", ctx->GPR13); |
---|
| 110 | printk ("\t R14 = %x\n", ctx->GPR14); |
---|
| 111 | printk ("\t R15 = %x\n", ctx->GPR15); |
---|
| 112 | printk ("\t R16 = %x\n", ctx->GPR16); |
---|
| 113 | printk ("\t R17 = %x\n", ctx->GPR17); |
---|
| 114 | printk ("\t R18 = %x\n", ctx->GPR18); |
---|
| 115 | printk ("\t R19 = %x\n", ctx->GPR19); |
---|
| 116 | printk ("\t R20 = %x\n", ctx->GPR20); |
---|
| 117 | printk ("\t R21 = %x\n", ctx->GPR21); |
---|
| 118 | printk ("\t R22 = %x\n", ctx->GPR22); |
---|
| 119 | printk ("\t R23 = %x\n", ctx->GPR23); |
---|
| 120 | printk ("\t R24 = %x\n", ctx->GPR24); |
---|
| 121 | printk ("\t R25 = %x\n", ctx->GPR25); |
---|
| 122 | printk ("\t R26 = %x\n", ctx->GPR26); |
---|
| 123 | printk ("\t R27 = %x\n", ctx->GPR27); |
---|
| 124 | printk ("\t R28 = %x\n", ctx->GPR28); |
---|
| 125 | printk ("\t R29 = %x\n", ctx->GPR29); |
---|
| 126 | printk ("\t R30 = %x\n", ctx->GPR30); |
---|
| 127 | printk ("\t R31 = %x\n", ctx->GPR31); |
---|
| 128 | printk ("\t CR = %x\n", ctx->EXC_CR); |
---|
| 129 | printk ("\t CTR = %x\n", ctx->EXC_CTR); |
---|
| 130 | printk ("\t XER = %x\n", ctx->EXC_XER); |
---|
| 131 | printk ("\t LR = %x\n", ctx->EXC_LR); |
---|
| 132 | printk ("\t MSR = %x\n", ctx->EXC_SRR1); |
---|
[981b99f] | 133 | #endif |
---|
| 134 | |
---|
[40cf43ea] | 135 | status = rtems_semaphore_create (rtems_build_name ('D', 'B', 'G', 'c'), |
---|
| 136 | 0, |
---|
| 137 | RTEMS_FIFO | |
---|
| 138 | RTEMS_COUNTING_SEMAPHORE | |
---|
| 139 | RTEMS_NO_INHERIT_PRIORITY | |
---|
| 140 | RTEMS_NO_PRIORITY_CEILING | |
---|
| 141 | RTEMS_LOCAL, 0, &continueSemId); |
---|
[981b99f] | 142 | if (status != RTEMS_SUCCESSFUL) |
---|
[40cf43ea] | 143 | rtems_panic ("Can't create continue semaphore: `%s'\n", |
---|
| 144 | rtems_status_text (status)); |
---|
[981b99f] | 145 | |
---|
| 146 | PushExceptCtx (_Thread_Executing->Object.id, continueSemId, ctx); |
---|
[40cf43ea] | 147 | |
---|
| 148 | switch (ctx->_EXC_number) { |
---|
| 149 | case ASM_TRACE_VECTOR: |
---|
| 150 | DPRINTF ((" TRACE EXCEPTION !!!\n")); |
---|
[981b99f] | 151 | ctx->EXC_SRR1 &= ~MSR_SE; |
---|
[40cf43ea] | 152 | ExitForSingleStep--; |
---|
| 153 | rtems_semaphore_release (wakeupEventSemId); |
---|
| 154 | break; |
---|
[981b99f] | 155 | |
---|
[40cf43ea] | 156 | case ASM_PROG_VECTOR: |
---|
| 157 | DPRINTF ((" BREAKPOINT EXCEPTION !!!\n")); |
---|
| 158 | rtems_semaphore_release (wakeupEventSemId); |
---|
| 159 | break; |
---|
[981b99f] | 160 | |
---|
[40cf43ea] | 161 | case ASM_SYS_VECTOR: |
---|
| 162 | DPRINTF ((" ENTER RDBG !!!\n")); |
---|
| 163 | rtems_semaphore_release (wakeupEventSemId); |
---|
[981b99f] | 164 | break; |
---|
| 165 | |
---|
| 166 | default: |
---|
[40cf43ea] | 167 | DPRINTF ((" OTHER EXCEPTION !!!\n")); |
---|
| 168 | rtems_semaphore_release (wakeupEventSemId); |
---|
[981b99f] | 169 | break; |
---|
| 170 | } |
---|
| 171 | |
---|
[40cf43ea] | 172 | rtems_semaphore_obtain (continueSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
| 173 | |
---|
[981b99f] | 174 | PopExceptCtx (_Thread_Executing->Object.id); |
---|
[40cf43ea] | 175 | rtems_semaphore_delete (continueSemId); |
---|
[981b99f] | 176 | } |
---|
| 177 | } |
---|