source: rtems/cpukit/score/cpu/i386/cpu.c @ 1dfc188e

4.104.114.84.95
Last change on this file since 1dfc188e was 1dfc188e, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/00 at 13:58:47

Removed unitialized variable warning.

  • 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.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/score/isr.h>
17#include <bspIo.h>
18#include <rtems/score/thread.h>
19#include <libcpu/cpuModel.h>
20
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
32void _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");
38  register void       *fp_context;
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 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 
76unsigned32 _CPU_ISR_Get_level( void )
77{
78  unsigned32 level;
79 
80  i386_get_interrupt_level( level );
81 
82  return level;
83}
84
85void _CPU_Thread_Idle_body ()
86{
87  while(1){
88    asm volatile ("hlt");
89  }
90}
91
92void _defaultExcHandler (CPU_Exception_frame *ctx)
93{
94  unsigned int faultAddr = 0;
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);
110  printk("----------------------------------------------------------\n");
111  if (ctx->idtIndex == I386_EXCEPTION_PAGE_FAULT){
112    faultAddr = i386_get_cr2();
113    printk("Page fault linear address (CR2) = %x\n", faultAddr);
114    printk("----------------------------------------------------------\n\n");
115  }
116 if (_ISR_Nest_level > 0) {
117    /*
118     * In this case we shall not delete the task interrupted as
119     * it has nothing to do with the fault. We cannot return either
120     * because the eip points to the faulty instruction so...
121     */
122    printk("Exception while executing ISR!!!. System locked\n");
123    _CPU_Fatal_halt(faultAddr);
124  }
125  else {
126    /*
127     * OK I could probably use a simplified version but at least this
128     * should work.
129     */
130    printk(" ************ FAULTY THREAD WILL BE DELETED **************\n");
131    rtems_task_delete(_Thread_Executing->Object.id);
132  }
133}
134
135cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
136
137extern void rtems_exception_prologue_0();
138extern void rtems_exception_prologue_1();
139extern void rtems_exception_prologue_2();
140extern void rtems_exception_prologue_3();
141extern void rtems_exception_prologue_4();
142extern void rtems_exception_prologue_5();
143extern void rtems_exception_prologue_6();
144extern void rtems_exception_prologue_7();
145extern void rtems_exception_prologue_8();
146extern void rtems_exception_prologue_9();
147extern void rtems_exception_prologue_10();
148extern void rtems_exception_prologue_11();
149extern void rtems_exception_prologue_12();
150extern void rtems_exception_prologue_13();
151extern void rtems_exception_prologue_14();
152extern void rtems_exception_prologue_16();
153extern void rtems_exception_prologue_17();
154extern void rtems_exception_prologue_18();
155
156static rtems_raw_irq_hdl tbl[] = {
157         rtems_exception_prologue_0,
158         rtems_exception_prologue_1,
159         rtems_exception_prologue_2,
160         rtems_exception_prologue_3,
161         rtems_exception_prologue_4,
162         rtems_exception_prologue_5,
163         rtems_exception_prologue_6,
164         rtems_exception_prologue_7,
165         rtems_exception_prologue_8,
166         rtems_exception_prologue_9,
167         rtems_exception_prologue_10,
168         rtems_exception_prologue_11,
169         rtems_exception_prologue_12,
170         rtems_exception_prologue_13,
171         rtems_exception_prologue_14,
172         rtems_exception_prologue_16,
173         rtems_exception_prologue_17,
174         rtems_exception_prologue_18,
175};
176
177void rtems_exception_init_mngt()
178{
179      unsigned int               i,j;
180      interrupt_gate_descriptor  *currentIdtEntry;
181      unsigned                   limit;
182      unsigned                   level;
183     
184      i = sizeof(tbl) / sizeof (rtems_raw_irq_hdl);
185
186      i386_get_info_from_IDTR (&currentIdtEntry, &limit);
187
188      _CPU_ISR_Disable(level);
189      for (j = 0; j < i; j++) {
190        create_interrupt_gate_descriptor (&currentIdtEntry[j], tbl[j]);
191      }
192      _CPU_ISR_Enable(level);
193}
194     
Note: See TracBrowser for help on using the repository browser.