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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
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 208 chris
 *  $Id: cpu.c,v 1.2 2001-09-27 11:59:26 chris Exp $
13 158 chris
 */
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
 
32
void _CPU_Initialize(
33
  rtems_cpu_table  *cpu_table,
34
  void      (*thread_dispatch)      /* ignored on this CPU */
35
)
36
{
37
#if CPU_HARDWARE_FP
38
  register unsigned16  fp_status asm ("ax");
39
  register void       *fp_context;
40
#endif
41
 
42
  _CPU_Table = *cpu_table;
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
 
78
unsigned32 _CPU_ISR_Get_level( void )
79
{
80
  unsigned32 level;
81
 
82
  i386_get_interrupt_level( level );
83
 
84
  return level;
85
}
86
 
87
void _CPU_Thread_Idle_body ()
88
{
89
  while(1){
90
    asm volatile ("hlt");
91
  }
92
}
93
 
94
void _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
 
137
cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
138
 
139
extern void rtems_exception_prologue_0();
140
extern void rtems_exception_prologue_1();
141
extern void rtems_exception_prologue_2();
142
extern void rtems_exception_prologue_3();
143
extern void rtems_exception_prologue_4();
144
extern void rtems_exception_prologue_5();
145
extern void rtems_exception_prologue_6();
146
extern void rtems_exception_prologue_7();
147
extern void rtems_exception_prologue_8();
148
extern void rtems_exception_prologue_9();
149
extern void rtems_exception_prologue_10();
150
extern void rtems_exception_prologue_11();
151
extern void rtems_exception_prologue_12();
152
extern void rtems_exception_prologue_13();
153
extern void rtems_exception_prologue_14();
154
extern void rtems_exception_prologue_16();
155
extern void rtems_exception_prologue_17();
156
extern void rtems_exception_prologue_18();
157
 
158
static 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
 
179
void 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
}
196
 

powered by: WebSVN 2.1.0

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