OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [score/] [cpu/] [i386/] [cpu.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  cpu.c,v 1.28 2002/04/12 15:08:12 joel Exp
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
 
34
void _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
 
80
unsigned32 _CPU_ISR_Get_level( void )
81
{
82
  unsigned32 level;
83
 
84
  i386_get_interrupt_level( level );
85
 
86
  return level;
87
}
88
 
89
void _CPU_Thread_Idle_body ()
90
{
91
  while(1){
92
    asm volatile ("hlt");
93
  }
94
}
95
 
96
void _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
 
139
cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
140
 
141
extern void rtems_exception_prologue_0();
142
extern void rtems_exception_prologue_1();
143
extern void rtems_exception_prologue_2();
144
extern void rtems_exception_prologue_3();
145
extern void rtems_exception_prologue_4();
146
extern void rtems_exception_prologue_5();
147
extern void rtems_exception_prologue_6();
148
extern void rtems_exception_prologue_7();
149
extern void rtems_exception_prologue_8();
150
extern void rtems_exception_prologue_9();
151
extern void rtems_exception_prologue_10();
152
extern void rtems_exception_prologue_11();
153
extern void rtems_exception_prologue_12();
154
extern void rtems_exception_prologue_13();
155
extern void rtems_exception_prologue_14();
156
extern void rtems_exception_prologue_16();
157
extern void rtems_exception_prologue_17();
158
extern void rtems_exception_prologue_18();
159
 
160
static 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
 
181
void 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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.