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

4.104.114.84.9
Last change on this file since a324355 was a324355, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 12, 2002 at 3:08:13 PM

2002-03-29 Ralf Corsepius <corsepiu@…>

  • rtems/score/idtr.h: New file, extracted from libcpu/cpu.h.
  • rtems/score/interrupts.h: New file, extracted from libcpu/cpu.h.
  • rtems/score/registers.h: New file, moved from libcpu.
  • Makefile.am: Reflect changes above.
  • cpu.c: Don't include cpuModel.h, #include <rtems.h>, #include <rtems/score/i386types.h>, #include <rtems/score/idtr.h>.
  • rtems/score/cpu.h: Don't include libcpu/cpu.h. #include <rtems/score/interrupts.h>, #include <rtems/score/registers.h>.
  • 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.OARcorp.com/rtems/license.html.
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 unsigned16  fp_status asm ("ax");
41  register void       *fp_context;
42#endif
43
44  _CPU_Table = *cpu_table;
45
46  /*
47   *  The following code saves a NULL i387 context which is given
48   *  to each task at start and restart time.  The following code
49   *  is based upon that provided in the i386 Programmer's
50   *  Manual and should work on any coprocessor greater than
51   *  the i80287.
52   *
53   *  NOTE: The NO WAIT form of the coprocessor instructions
54   *        MUST be used in case there is not a coprocessor
55   *        to wait for.
56   */
57
58#if CPU_HARDWARE_FP
59  fp_status = 0xa5a5;
60  asm volatile( "fninit" );
61  asm volatile( "fnstsw %0" : "=a" (fp_status) : "0" (fp_status) );
62
63  if ( fp_status ==  0 ) {
64
65    fp_context = &_CPU_Null_fp_context;
66
67    asm volatile( "fsave (%0)" : "=r" (fp_context)
68                               : "0"  (fp_context)
69                );
70  }
71#endif
72
73}
74
75/*PAGE
76 *
77 *  _CPU_ISR_Get_level
78 */
79 
80unsigned32 _CPU_ISR_Get_level( void )
81{
82  unsigned32 level;
83 
84  i386_get_interrupt_level( level );
85 
86  return level;
87}
88
89void _CPU_Thread_Idle_body ()
90{
91  while(1){
92    asm volatile ("hlt");
93  }
94}
95
96void _defaultExcHandler (CPU_Exception_frame *ctx)
97{
98  unsigned int faultAddr = 0;
99  printk("----------------------------------------------------------\n");
100  printk("Exception %d caught at PC %x by thread %d\n",
101         ctx->idtIndex,
102         ctx->eip,
103         _Thread_Executing->Object.id);
104  printk("----------------------------------------------------------\n");
105  printk("Processor execution context at time of the fault was  :\n");
106  printk("----------------------------------------------------------\n");
107  printk(" EAX = %x     EBX = %x        ECX = %x        EDX = %x\n",
108         ctx->eax, ctx->ebx, ctx->ecx, ctx->edx);
109  printk(" ESI = %x     EDI = %x        EBP = %x        ESP = %x\n",
110         ctx->esi, ctx->edi, ctx->ebp, ctx->esp0);
111  printk("----------------------------------------------------------\n");
112  printk("Error code pushed by processor itself (if not 0) = %x\n",
113         ctx->faultCode);
114  printk("----------------------------------------------------------\n");
115  if (ctx->idtIndex == I386_EXCEPTION_PAGE_FAULT){
116    faultAddr = i386_get_cr2();
117    printk("Page fault linear address (CR2) = %x\n", faultAddr);
118    printk("----------------------------------------------------------\n\n");
119  }
120 if (_ISR_Nest_level > 0) {
121    /*
122     * In this case we shall not delete the task interrupted as
123     * it has nothing to do with the fault. We cannot return either
124     * because the eip points to the faulty instruction so...
125     */
126    printk("Exception while executing ISR!!!. System locked\n");
127    _CPU_Fatal_halt(faultAddr);
128  }
129  else {
130    /*
131     * OK I could probably use a simplified version but at least this
132     * should work.
133     */
134    printk(" ************ FAULTY THREAD WILL BE DELETED **************\n");
135    rtems_task_delete(_Thread_Executing->Object.id);
136  }
137}
138
139cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
140
141extern void rtems_exception_prologue_0();
142extern void rtems_exception_prologue_1();
143extern void rtems_exception_prologue_2();
144extern void rtems_exception_prologue_3();
145extern void rtems_exception_prologue_4();
146extern void rtems_exception_prologue_5();
147extern void rtems_exception_prologue_6();
148extern void rtems_exception_prologue_7();
149extern void rtems_exception_prologue_8();
150extern void rtems_exception_prologue_9();
151extern void rtems_exception_prologue_10();
152extern void rtems_exception_prologue_11();
153extern void rtems_exception_prologue_12();
154extern void rtems_exception_prologue_13();
155extern void rtems_exception_prologue_14();
156extern void rtems_exception_prologue_16();
157extern void rtems_exception_prologue_17();
158extern void rtems_exception_prologue_18();
159
160static rtems_raw_irq_hdl tbl[] = {
161         rtems_exception_prologue_0,
162         rtems_exception_prologue_1,
163         rtems_exception_prologue_2,
164         rtems_exception_prologue_3,
165         rtems_exception_prologue_4,
166         rtems_exception_prologue_5,
167         rtems_exception_prologue_6,
168         rtems_exception_prologue_7,
169         rtems_exception_prologue_8,
170         rtems_exception_prologue_9,
171         rtems_exception_prologue_10,
172         rtems_exception_prologue_11,
173         rtems_exception_prologue_12,
174         rtems_exception_prologue_13,
175         rtems_exception_prologue_14,
176         rtems_exception_prologue_16,
177         rtems_exception_prologue_17,
178         rtems_exception_prologue_18,
179};
180
181void rtems_exception_init_mngt()
182{
183      unsigned int               i,j;
184      interrupt_gate_descriptor  *currentIdtEntry;
185      unsigned                   limit;
186      unsigned                   level;
187     
188      i = sizeof(tbl) / sizeof (rtems_raw_irq_hdl);
189
190      i386_get_info_from_IDTR (&currentIdtEntry, &limit);
191
192      _CPU_ISR_Disable(level);
193      for (j = 0; j < i; j++) {
194        create_interrupt_gate_descriptor (&currentIdtEntry[j], tbl[j]);
195      }
196      _CPU_ISR_Enable(level);
197}
198     
Note: See TracBrowser for help on using the repository browser.