source: rtems/cpukit/score/cpu/i386/cpu.c @ d0279f6e

4.9
Last change on this file since d0279f6e was 917f816, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/05/08 at 06:38:12

Stop using old-style defs.

  • Property mode set to 100644
File size: 5.5 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 *    thread_dispatch - address of disptaching routine
30 */
31
32
33void _CPU_Initialize(
34  void      (*thread_dispatch)      /* ignored on this CPU */
35)
36{
37#if CPU_HARDWARE_FP
38  register uint16_t             fp_status asm ("ax");
39  register Context_Control_fp  *fp_context;
40#endif
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 WAIT form of the coprocessor instructions
50   *        MUST be used in case there is not a coprocessor
51   *        to wait for.
52   */
53
54#if CPU_HARDWARE_FP
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
61    fp_context = &_CPU_Null_fp_context;
62
63    asm volatile( "fsave (%0)" : "=r" (fp_context)
64                               : "0"  (fp_context)
65                );
66  }
67#endif
68
69}
70
71/*PAGE
72 *
73 *  _CPU_ISR_Get_level
74 */
75
76uint32_t   _CPU_ISR_Get_level( void )
77{
78  uint32_t   level;
79
80  i386_get_interrupt_level( level );
81
82  return level;
83}
84
85void *_CPU_Thread_Idle_body (uint32_t ignored)
86{
87  while(1){
88    asm volatile ("hlt");
89  }
90  return NULL;
91}
92
93void _defaultExcHandler (CPU_Exception_frame *ctx)
94{
95  unsigned int faultAddr = 0;
96  printk("----------------------------------------------------------\n");
97  printk("Exception %d caught at PC %x by thread %d\n",
98         ctx->idtIndex,
99         ctx->eip,
100         _Thread_Executing->Object.id);
101  printk("----------------------------------------------------------\n");
102  printk("Processor execution context at time of the fault was  :\n");
103  printk("----------------------------------------------------------\n");
104  printk(" EAX = %x     EBX = %x        ECX = %x        EDX = %x\n",
105         ctx->eax, ctx->ebx, ctx->ecx, ctx->edx);
106  printk(" ESI = %x     EDI = %x        EBP = %x        ESP = %x\n",
107         ctx->esi, ctx->edi, ctx->ebp, ctx->esp0);
108  printk("----------------------------------------------------------\n");
109  printk("Error code pushed by processor itself (if not 0) = %x\n",
110         ctx->faultCode);
111  printk("----------------------------------------------------------\n");
112  if (ctx->idtIndex == I386_EXCEPTION_PAGE_FAULT){
113    faultAddr = i386_get_cr2();
114    printk("Page fault linear address (CR2) = %x\n", faultAddr);
115    printk("----------------------------------------------------------\n\n");
116  }
117 if (_ISR_Nest_level > 0) {
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");
124    _CPU_Fatal_halt(faultAddr);
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  }
134}
135
136cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
137
138extern void rtems_exception_prologue_0(void);
139extern void rtems_exception_prologue_1(void);
140extern void rtems_exception_prologue_2(void);
141extern void rtems_exception_prologue_3(void);
142extern void rtems_exception_prologue_4(void);
143extern void rtems_exception_prologue_5(void);
144extern void rtems_exception_prologue_6(void);
145extern void rtems_exception_prologue_7(void);
146extern void rtems_exception_prologue_8(void);
147extern void rtems_exception_prologue_9(void);
148extern void rtems_exception_prologue_10(void);
149extern void rtems_exception_prologue_11(void);
150extern void rtems_exception_prologue_12(void);
151extern void rtems_exception_prologue_13(void);
152extern void rtems_exception_prologue_14(void);
153extern void rtems_exception_prologue_16(void);
154extern void rtems_exception_prologue_17(void);
155extern void rtems_exception_prologue_18(void);
156
157static 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
178void rtems_exception_init_mngt(void)
179{
180      size_t                     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 (&currentIdtEntry, &limit);
188
189      _CPU_ISR_Disable(level);
190      for (j = 0; j < i; j++) {
191        create_interrupt_gate_descriptor (&currentIdtEntry[j], tbl[j]);
192      }
193      _CPU_ISR_Enable(level);
194}
Note: See TracBrowser for help on using the repository browser.