[ac7d5ef0] | 1 | /* |
---|
| 2 | * Intel i386 Dependent Source |
---|
| 3 | * |
---|
| 4 | * |
---|
[60b791ad] | 5 | * COPYRIGHT (c) 1989-1998. |
---|
[ac7d5ef0] | 6 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 7 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 8 | * |
---|
[98e4ebf5] | 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 11 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include <rtems/system.h> |
---|
[5e9b32b] | 17 | #include <rtems/score/isr.h> |
---|
[eb562f2] | 18 | #include <bspIo.h> |
---|
| 19 | #include <rtems/score/thread.h> |
---|
| 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 | * |
---|
| 49 | * NOTE: The NO RTEMS_WAIT form of the coprocessor instructions |
---|
| 50 | * MUST be used in case there is not a coprocessor |
---|
| 51 | * to wait for. |
---|
| 52 | */ |
---|
| 53 | |
---|
| 54 | fp_status = 0xa5a5; |
---|
| 55 | asm volatile( "fninit" ); |
---|
| 56 | asm volatile( "fnstsw %0" : "=a" (fp_status) : "0" (fp_status) ); |
---|
| 57 | |
---|
| 58 | if ( fp_status == 0 ) { |
---|
| 59 | |
---|
[3652ad35] | 60 | fp_context = &_CPU_Null_fp_context; |
---|
[ac7d5ef0] | 61 | |
---|
| 62 | asm volatile( "fsave (%0)" : "=r" (fp_context) |
---|
| 63 | : "0" (fp_context) |
---|
| 64 | ); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
[3a4ae6c] | 68 | /*PAGE |
---|
| 69 | * |
---|
| 70 | * _CPU_ISR_Get_level |
---|
| 71 | */ |
---|
| 72 | |
---|
| 73 | unsigned32 _CPU_ISR_Get_level( void ) |
---|
| 74 | { |
---|
| 75 | unsigned32 level; |
---|
| 76 | |
---|
| 77 | i386_get_interrupt_level( level ); |
---|
| 78 | |
---|
| 79 | return level; |
---|
| 80 | } |
---|
[8b2ee37c] | 81 | |
---|
| 82 | void _CPU_Thread_Idle_body () |
---|
| 83 | { |
---|
| 84 | while(1){ |
---|
| 85 | asm volatile ("hlt"); |
---|
| 86 | } |
---|
| 87 | } |
---|
[eb562f2] | 88 | |
---|
| 89 | void _defaultExcHandler (CPU_Exception_frame *ctx) |
---|
| 90 | { |
---|
| 91 | printk("----------------------------------------------------------\n"); |
---|
| 92 | printk("Exception %d caught at PC %x by thread %d\n", |
---|
| 93 | ctx->idtIndex, |
---|
| 94 | ctx->eip, |
---|
| 95 | _Thread_Executing->Object.id); |
---|
| 96 | printk("----------------------------------------------------------\n"); |
---|
| 97 | printk("Processor execution context at time of the fault was :\n"); |
---|
| 98 | printk("----------------------------------------------------------\n"); |
---|
| 99 | printk(" EAX = %x EBX = %x ECX = %x EDX = %x\n", |
---|
| 100 | ctx->eax, ctx->ebx, ctx->ecx, ctx->edx); |
---|
| 101 | printk(" ESI = %x EDI = %x EBP = %x ESP = %x\n", |
---|
| 102 | ctx->esi, ctx->edi, ctx->ebp, ctx->esp0); |
---|
| 103 | printk("----------------------------------------------------------\n"); |
---|
| 104 | printk("Error code pushed by processor itself (if not 0) = %x\n", |
---|
| 105 | ctx->faultCode); |
---|
| 106 | printk("----------------------------------------------------------\n\n"); |
---|
[b285860] | 107 | if (_ISR_Nest_level > 0) { |
---|
| 108 | /* |
---|
| 109 | * In this case we shall not delete the task interrupted as |
---|
| 110 | * it has nothing to do with the fault. We cannot return either |
---|
| 111 | * because the eip points to the faulty instruction so... |
---|
| 112 | */ |
---|
| 113 | printk("Exception while executing ISR!!!. System locked\n"); |
---|
| 114 | while(1); |
---|
| 115 | } |
---|
| 116 | else { |
---|
| 117 | /* |
---|
| 118 | * OK I could probably use a simplified version but at least this |
---|
| 119 | * should work. |
---|
| 120 | */ |
---|
| 121 | printk(" ************ FAULTY THREAD WILL BE DELETED **************\n"); |
---|
| 122 | rtems_task_delete(_Thread_Executing->Object.id); |
---|
| 123 | } |
---|
[eb562f2] | 124 | } |
---|
| 125 | |
---|
| 126 | cpuExcHandlerType _currentExcHandler = _defaultExcHandler; |
---|
| 127 | |
---|
| 128 | extern void rtems_exception_prologue_0(); |
---|
| 129 | extern void rtems_exception_prologue_1(); |
---|
| 130 | extern void rtems_exception_prologue_2(); |
---|
| 131 | extern void rtems_exception_prologue_3(); |
---|
| 132 | extern void rtems_exception_prologue_4(); |
---|
| 133 | extern void rtems_exception_prologue_5(); |
---|
| 134 | extern void rtems_exception_prologue_6(); |
---|
| 135 | extern void rtems_exception_prologue_7(); |
---|
| 136 | extern void rtems_exception_prologue_8(); |
---|
| 137 | extern void rtems_exception_prologue_9(); |
---|
| 138 | extern void rtems_exception_prologue_10(); |
---|
| 139 | extern void rtems_exception_prologue_11(); |
---|
| 140 | extern void rtems_exception_prologue_12(); |
---|
| 141 | extern void rtems_exception_prologue_13(); |
---|
| 142 | extern void rtems_exception_prologue_14(); |
---|
| 143 | extern void rtems_exception_prologue_16(); |
---|
| 144 | extern void rtems_exception_prologue_17(); |
---|
| 145 | extern void rtems_exception_prologue_18(); |
---|
| 146 | |
---|
| 147 | static rtems_raw_irq_hdl tbl[] = { |
---|
| 148 | rtems_exception_prologue_0, |
---|
| 149 | rtems_exception_prologue_1, |
---|
| 150 | rtems_exception_prologue_2, |
---|
| 151 | rtems_exception_prologue_3, |
---|
| 152 | rtems_exception_prologue_4, |
---|
| 153 | rtems_exception_prologue_5, |
---|
| 154 | rtems_exception_prologue_6, |
---|
| 155 | rtems_exception_prologue_7, |
---|
| 156 | rtems_exception_prologue_8, |
---|
| 157 | rtems_exception_prologue_9, |
---|
| 158 | rtems_exception_prologue_10, |
---|
| 159 | rtems_exception_prologue_11, |
---|
| 160 | rtems_exception_prologue_12, |
---|
| 161 | rtems_exception_prologue_13, |
---|
| 162 | rtems_exception_prologue_14, |
---|
| 163 | rtems_exception_prologue_16, |
---|
| 164 | rtems_exception_prologue_17, |
---|
| 165 | rtems_exception_prologue_18, |
---|
| 166 | }; |
---|
| 167 | |
---|
| 168 | void rtems_exception_init_mngt() |
---|
| 169 | { |
---|
| 170 | unsigned int i,j; |
---|
| 171 | interrupt_gate_descriptor *currentIdtEntry; |
---|
| 172 | unsigned limit; |
---|
| 173 | unsigned level; |
---|
| 174 | |
---|
| 175 | i = sizeof(tbl) / sizeof (rtems_raw_irq_hdl); |
---|
| 176 | |
---|
| 177 | i386_get_info_from_IDTR (¤tIdtEntry, &limit); |
---|
| 178 | |
---|
| 179 | _CPU_ISR_Disable(level); |
---|
| 180 | for (j = 0; j < i; j++) { |
---|
| 181 | create_interrupt_gate_descriptor (¤tIdtEntry[j], tbl[j]); |
---|
| 182 | } |
---|
| 183 | _CPU_ISR_Enable(level); |
---|
| 184 | } |
---|
| 185 | |
---|