source: rtems/cpukit/score/cpu/i386/cpu.c @ 60f016f

4.104.114.84.95
Last change on this file since 60f016f was 60f016f, checked in by Joel Sherrill <joel.sherrill@…>, on May 22, 2007 at 8:57:34 PM

2007-05-22 Joel Sherrill <joel.sherrill@…>

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