[ac7d5ef0] | 1 | /* |
---|
| 2 | * Intel i386 Dependent Source |
---|
| 3 | * |
---|
| 4 | * |
---|
[08311cc3] | 5 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 6 | * On-Line Applications Research Corporation (OAR). |
---|
| 7 | * |
---|
[98e4ebf5] | 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include <rtems/system.h> |
---|
[5e9b32b] | 16 | #include <rtems/score/isr.h> |
---|
[eb562f2] | 17 | #include <bspIo.h> |
---|
| 18 | #include <rtems/score/thread.h> |
---|
[e029467] | 19 | #include <libcpu/cpuModel.h> |
---|
[eb562f2] | 20 | |
---|
[ac7d5ef0] | 21 | |
---|
| 22 | /* _CPU_Initialize |
---|
| 23 | * |
---|
| 24 | * This routine performs processor dependent initialization. |
---|
| 25 | * |
---|
| 26 | * INPUT PARAMETERS: |
---|
| 27 | * cpu_table - CPU table to initialize |
---|
| 28 | * thread_dispatch - address of disptaching routine |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | void _CPU_Initialize( |
---|
| 33 | rtems_cpu_table *cpu_table, |
---|
| 34 | void (*thread_dispatch) /* ignored on this CPU */ |
---|
| 35 | ) |
---|
| 36 | { |
---|
| 37 | register unsigned16 fp_status asm ("ax"); |
---|
[3652ad35] | 38 | register void *fp_context; |
---|
[ac7d5ef0] | 39 | |
---|
| 40 | _CPU_Table = *cpu_table; |
---|
| 41 | |
---|
| 42 | /* |
---|
| 43 | * The following code saves a NULL i387 context which is given |
---|
| 44 | * to each task at start and restart time. The following code |
---|
| 45 | * is based upon that provided in the i386 Programmer's |
---|
| 46 | * Manual and should work on any coprocessor greater than |
---|
| 47 | * the i80287. |
---|
| 48 | * |
---|
[6805640e] | 49 | * NOTE: The NO WAIT form of the coprocessor instructions |
---|
[ac7d5ef0] | 50 | * MUST be used in case there is not a coprocessor |
---|
| 51 | * to wait for. |
---|
| 52 | */ |
---|
| 53 | |
---|
[6805640e] | 54 | #if CPU_HARDWARE_FP |
---|
[ac7d5ef0] | 55 | fp_status = 0xa5a5; |
---|
| 56 | asm volatile( "fninit" ); |
---|
| 57 | asm volatile( "fnstsw %0" : "=a" (fp_status) : "0" (fp_status) ); |
---|
| 58 | |
---|
| 59 | if ( fp_status == 0 ) { |
---|
| 60 | |
---|
[3652ad35] | 61 | fp_context = &_CPU_Null_fp_context; |
---|
[ac7d5ef0] | 62 | |
---|
| 63 | asm volatile( "fsave (%0)" : "=r" (fp_context) |
---|
| 64 | : "0" (fp_context) |
---|
| 65 | ); |
---|
| 66 | } |
---|
[6805640e] | 67 | #endif |
---|
| 68 | |
---|
[ac7d5ef0] | 69 | } |
---|
| 70 | |
---|
[3a4ae6c] | 71 | /*PAGE |
---|
| 72 | * |
---|
| 73 | * _CPU_ISR_Get_level |
---|
| 74 | */ |
---|
| 75 | |
---|
| 76 | unsigned32 _CPU_ISR_Get_level( void ) |
---|
| 77 | { |
---|
| 78 | unsigned32 level; |
---|
| 79 | |
---|
| 80 | i386_get_interrupt_level( level ); |
---|
| 81 | |
---|
| 82 | return level; |
---|
| 83 | } |
---|
[8b2ee37c] | 84 | |
---|
| 85 | void _CPU_Thread_Idle_body () |
---|
| 86 | { |
---|
| 87 | while(1){ |
---|
| 88 | asm volatile ("hlt"); |
---|
| 89 | } |
---|
| 90 | } |
---|
[eb562f2] | 91 | |
---|
| 92 | void _defaultExcHandler (CPU_Exception_frame *ctx) |
---|
| 93 | { |
---|
[e029467] | 94 | unsigned int faultAddr; |
---|
[eb562f2] | 95 | printk("----------------------------------------------------------\n"); |
---|
| 96 | printk("Exception %d caught at PC %x by thread %d\n", |
---|
| 97 | ctx->idtIndex, |
---|
| 98 | ctx->eip, |
---|
| 99 | _Thread_Executing->Object.id); |
---|
| 100 | printk("----------------------------------------------------------\n"); |
---|
| 101 | printk("Processor execution context at time of the fault was :\n"); |
---|
| 102 | printk("----------------------------------------------------------\n"); |
---|
| 103 | printk(" EAX = %x EBX = %x ECX = %x EDX = %x\n", |
---|
| 104 | ctx->eax, ctx->ebx, ctx->ecx, ctx->edx); |
---|
| 105 | printk(" ESI = %x EDI = %x EBP = %x ESP = %x\n", |
---|
| 106 | ctx->esi, ctx->edi, ctx->ebp, ctx->esp0); |
---|
| 107 | printk("----------------------------------------------------------\n"); |
---|
| 108 | printk("Error code pushed by processor itself (if not 0) = %x\n", |
---|
| 109 | ctx->faultCode); |
---|
[e029467] | 110 | printk("----------------------------------------------------------\n"); |
---|
[6dfebd9] | 111 | if (ctx->idtIndex == I386_EXCEPTION_PAGE_FAULT){ |
---|
[e029467] | 112 | faultAddr = i386_get_cr2(); |
---|
| 113 | printk("Page fault linear address (CR2) = %x\n", |
---|
| 114 | faultAddr); |
---|
[eb562f2] | 115 | printk("----------------------------------------------------------\n\n"); |
---|
[e029467] | 116 | } |
---|
| 117 | if (_ISR_Nest_level > 0) { |
---|
[b285860] | 118 | /* |
---|
| 119 | * In this case we shall not delete the task interrupted as |
---|
| 120 | * it has nothing to do with the fault. We cannot return either |
---|
| 121 | * because the eip points to the faulty instruction so... |
---|
| 122 | */ |
---|
| 123 | printk("Exception while executing ISR!!!. System locked\n"); |
---|
[8f3c1d20] | 124 | _CPU_Fatal_halt(faultAddr); |
---|
[b285860] | 125 | } |
---|
| 126 | else { |
---|
| 127 | /* |
---|
| 128 | * OK I could probably use a simplified version but at least this |
---|
| 129 | * should work. |
---|
| 130 | */ |
---|
| 131 | printk(" ************ FAULTY THREAD WILL BE DELETED **************\n"); |
---|
| 132 | rtems_task_delete(_Thread_Executing->Object.id); |
---|
| 133 | } |
---|
[eb562f2] | 134 | } |
---|
| 135 | |
---|
| 136 | cpuExcHandlerType _currentExcHandler = _defaultExcHandler; |
---|
| 137 | |
---|
| 138 | extern void rtems_exception_prologue_0(); |
---|
| 139 | extern void rtems_exception_prologue_1(); |
---|
| 140 | extern void rtems_exception_prologue_2(); |
---|
| 141 | extern void rtems_exception_prologue_3(); |
---|
| 142 | extern void rtems_exception_prologue_4(); |
---|
| 143 | extern void rtems_exception_prologue_5(); |
---|
| 144 | extern void rtems_exception_prologue_6(); |
---|
| 145 | extern void rtems_exception_prologue_7(); |
---|
| 146 | extern void rtems_exception_prologue_8(); |
---|
| 147 | extern void rtems_exception_prologue_9(); |
---|
| 148 | extern void rtems_exception_prologue_10(); |
---|
| 149 | extern void rtems_exception_prologue_11(); |
---|
| 150 | extern void rtems_exception_prologue_12(); |
---|
| 151 | extern void rtems_exception_prologue_13(); |
---|
| 152 | extern void rtems_exception_prologue_14(); |
---|
| 153 | extern void rtems_exception_prologue_16(); |
---|
| 154 | extern void rtems_exception_prologue_17(); |
---|
| 155 | extern void rtems_exception_prologue_18(); |
---|
| 156 | |
---|
| 157 | static rtems_raw_irq_hdl tbl[] = { |
---|
| 158 | rtems_exception_prologue_0, |
---|
| 159 | rtems_exception_prologue_1, |
---|
| 160 | rtems_exception_prologue_2, |
---|
| 161 | rtems_exception_prologue_3, |
---|
| 162 | rtems_exception_prologue_4, |
---|
| 163 | rtems_exception_prologue_5, |
---|
| 164 | rtems_exception_prologue_6, |
---|
| 165 | rtems_exception_prologue_7, |
---|
| 166 | rtems_exception_prologue_8, |
---|
| 167 | rtems_exception_prologue_9, |
---|
| 168 | rtems_exception_prologue_10, |
---|
| 169 | rtems_exception_prologue_11, |
---|
| 170 | rtems_exception_prologue_12, |
---|
| 171 | rtems_exception_prologue_13, |
---|
| 172 | rtems_exception_prologue_14, |
---|
| 173 | rtems_exception_prologue_16, |
---|
| 174 | rtems_exception_prologue_17, |
---|
| 175 | rtems_exception_prologue_18, |
---|
| 176 | }; |
---|
| 177 | |
---|
| 178 | void rtems_exception_init_mngt() |
---|
| 179 | { |
---|
| 180 | unsigned int i,j; |
---|
| 181 | interrupt_gate_descriptor *currentIdtEntry; |
---|
| 182 | unsigned limit; |
---|
| 183 | unsigned level; |
---|
| 184 | |
---|
| 185 | i = sizeof(tbl) / sizeof (rtems_raw_irq_hdl); |
---|
| 186 | |
---|
| 187 | i386_get_info_from_IDTR (¤tIdtEntry, &limit); |
---|
| 188 | |
---|
| 189 | _CPU_ISR_Disable(level); |
---|
| 190 | for (j = 0; j < i; j++) { |
---|
| 191 | create_interrupt_gate_descriptor (¤tIdtEntry[j], tbl[j]); |
---|
| 192 | } |
---|
| 193 | _CPU_ISR_Enable(level); |
---|
| 194 | } |
---|
| 195 | |
---|