source: rtems/c/src/exec/score/cpu/i386/cpu.c @ e029467

4.104.114.84.95
Last change on this file since e029467 was e029467, checked in by Joel Sherrill <joel.sherrill@…>, on 02/18/99 at 15:16:37

Patch from Emmanuel Raguet <raguet@…>:

You will find enclosed a patch which contains, for Intel PC386 target :

  • an Ethernet driver for DEC21140 device based boards.
  • a simple cache management with paging mechanism.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 *  Intel i386 Dependent Source
3 *
4 *
5 *  COPYRIGHT (c) 1989-1998.
6 *  On-Line Applications Research Corporation (OAR).
7 *  Copyright assigned to U.S. Government, 1994.
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/score/isr.h>
18#include <bspIo.h>
19#include <rtems/score/thread.h>
20#include <libcpu/cpuModel.h>
21
22
23/*  _CPU_Initialize
24 *
25 *  This routine performs processor dependent initialization.
26 *
27 *  INPUT PARAMETERS:
28 *    cpu_table       - CPU table to initialize
29 *    thread_dispatch - address of disptaching routine
30 */
31
32
33void _CPU_Initialize(
34  rtems_cpu_table  *cpu_table,
35  void      (*thread_dispatch)      /* ignored on this CPU */
36)
37{
38  register unsigned16  fp_status asm ("ax");
39  register void       *fp_context;
40
41  _CPU_Table = *cpu_table;
42
43  /*
44   *  The following code saves a NULL i387 context which is given
45   *  to each task at start and restart time.  The following code
46   *  is based upon that provided in the i386 Programmer's
47   *  Manual and should work on any coprocessor greater than
48   *  the i80287.
49   *
50   *  NOTE: The NO RTEMS_WAIT form of the coprocessor instructions
51   *        MUST be used in case there is not a coprocessor
52   *        to wait for.
53   */
54
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}
68
69/*PAGE
70 *
71 *  _CPU_ISR_Get_level
72 */
73 
74unsigned32 _CPU_ISR_Get_level( void )
75{
76  unsigned32 level;
77 
78  i386_get_interrupt_level( level );
79 
80  return level;
81}
82
83void _CPU_Thread_Idle_body ()
84{
85  while(1){
86    asm volatile ("hlt");
87  }
88}
89
90void _defaultExcHandler (CPU_Exception_frame *ctx)
91{
92  unsigned int faultAddr;
93  printk("----------------------------------------------------------\n");
94  printk("Exception %d caught at PC %x by thread %d\n",
95         ctx->idtIndex,
96         ctx->eip,
97         _Thread_Executing->Object.id);
98  printk("----------------------------------------------------------\n");
99  printk("Processor execution context at time of the fault was  :\n");
100  printk("----------------------------------------------------------\n");
101  printk(" EAX = %x     EBX = %x        ECX = %x        EDX = %x\n",
102         ctx->eax, ctx->ebx, ctx->ecx, ctx->edx);
103  printk(" ESI = %x     EDI = %x        EBP = %x        ESP = %x\n",
104         ctx->esi, ctx->edi, ctx->ebp, ctx->esp0);
105  printk("----------------------------------------------------------\n");
106  printk("Error code pushed by processor itself (if not 0) = %x\n",
107         ctx->faultCode);
108  printk("----------------------------------------------------------\n");
109  if (ctx->idtIndex == PAGE_FAULT){
110    faultAddr = i386_get_cr2();
111    printk("Page fault linear address (CR2) = %x\n",
112           faultAddr);
113  printk("----------------------------------------------------------\n\n");
114  }
115 if (_ISR_Nest_level > 0) {
116    /*
117     * In this case we shall not delete the task interrupted as
118     * it has nothing to do with the fault. We cannot return either
119     * because the eip points to the faulty instruction so...
120     */
121    printk("Exception while executing ISR!!!. System locked\n");
122    while(1);
123  }
124  else {
125    /*
126     * OK I could probably use a simplified version but at least this
127     * should work.
128     */
129    printk(" ************ FAULTY THREAD WILL BE DELETED **************\n");
130    rtems_task_delete(_Thread_Executing->Object.id);
131  }
132}
133
134cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
135
136extern void rtems_exception_prologue_0();
137extern void rtems_exception_prologue_1();
138extern void rtems_exception_prologue_2();
139extern void rtems_exception_prologue_3();
140extern void rtems_exception_prologue_4();
141extern void rtems_exception_prologue_5();
142extern void rtems_exception_prologue_6();
143extern void rtems_exception_prologue_7();
144extern void rtems_exception_prologue_8();
145extern void rtems_exception_prologue_9();
146extern void rtems_exception_prologue_10();
147extern void rtems_exception_prologue_11();
148extern void rtems_exception_prologue_12();
149extern void rtems_exception_prologue_13();
150extern void rtems_exception_prologue_14();
151extern void rtems_exception_prologue_16();
152extern void rtems_exception_prologue_17();
153extern void rtems_exception_prologue_18();
154
155static rtems_raw_irq_hdl tbl[] = {
156         rtems_exception_prologue_0,
157         rtems_exception_prologue_1,
158         rtems_exception_prologue_2,
159         rtems_exception_prologue_3,
160         rtems_exception_prologue_4,
161         rtems_exception_prologue_5,
162         rtems_exception_prologue_6,
163         rtems_exception_prologue_7,
164         rtems_exception_prologue_8,
165         rtems_exception_prologue_9,
166         rtems_exception_prologue_10,
167         rtems_exception_prologue_11,
168         rtems_exception_prologue_12,
169         rtems_exception_prologue_13,
170         rtems_exception_prologue_14,
171         rtems_exception_prologue_16,
172         rtems_exception_prologue_17,
173         rtems_exception_prologue_18,
174};
175
176void rtems_exception_init_mngt()
177{
178      unsigned int               i,j;
179      interrupt_gate_descriptor  *currentIdtEntry;
180      unsigned                   limit;
181      unsigned                   level;
182     
183      i = sizeof(tbl) / sizeof (rtems_raw_irq_hdl);
184
185      i386_get_info_from_IDTR (&currentIdtEntry, &limit);
186
187      _CPU_ISR_Disable(level);
188      for (j = 0; j < i; j++) {
189        create_interrupt_gate_descriptor (&currentIdtEntry[j], tbl[j]);
190      }
191      _CPU_ISR_Enable(level);
192}
193     
Note: See TracBrowser for help on using the repository browser.