source: rtems/cpukit/score/cpu/mips/cpu.c @ 859251a

5
Last change on this file since 859251a was d638aca, checked in by Sebastian Huber <sebastian.huber@…>, on 02/03/16 at 10:41:29

mips: Avoid SCORE_EXTERN

Update #2559.

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief MIPS CPU Dependent Source
5 */
6
7/*
8 * MIPS CPU Dependent Source
9 *
10 *  2002:       Greg Menke (gregory.menke@gsfc.nasa.gov)
11 *      Overhauled interrupt level and interrupt enable/disable code
12 *      to more exactly support MIPS.  Our mods were for MIPS1 processors
13 *      MIPS3 ports are affected, though apps written to the old behavior
14 *      should still work OK.
15 *
16 *  Conversion to MIPS port by Alan Cudmore <alanc@linuxstart.com> and
17 *           Joel Sherrill <joel@OARcorp.com>.
18 *
19 *    These changes made the code conditional on standard cpp predefines,
20 *    merged the mips1 and mips3 code sequences as much as possible,
21 *    and moved some of the assembly code to C.  Alan did much of the
22 *    initial analysis and rework.  Joel took over from there and
23 *    wrote the JMR3904 BSP so this could be tested.  Joel also
24 *    added the new interrupt vectoring support in libcpu and
25 *    tried to better support the various interrupt controllers.
26 *
27 *  Original MIP64ORION port by Craig Lebakken <craigl@transition.com>
28 *           COPYRIGHT (c) 1996 by Transition Networks Inc.
29 *
30 *         To anyone who acknowledges that this file is provided "AS IS"
31 *         without any express or implied warranty:
32 *             permission to use, copy, modify, and distribute this file
33 *             for any purpose is hereby granted without fee, provided that
34 *             the above copyright notice and this notice appears in all
35 *             copies, and that the name of Transition Networks not be used in
36 *             advertising or publicity pertaining to distribution of the
37 *             software without specific, written prior permission.
38 *             Transition Networks makes no representations about the
39 *             suitability of this software for any purpose.
40 *
41 *  COPYRIGHT (c) 1989-2012.
42 *  On-Line Applications Research Corporation (OAR).
43 *
44 *  The license and distribution terms for this file may be
45 *  found in the file LICENSE in this distribution or at
46 *  http://www.rtems.org/license/LICENSE.
47 */
48
49#ifdef HAVE_CONFIG_H
50#include "config.h"
51#endif
52
53#include <rtems/system.h>
54#include <rtems/score/isr.h>
55#include <rtems/score/wkspace.h>
56
57#if CPU_HARDWARE_FP
58Context_Control_fp _CPU_Null_fp_context;
59#endif
60
61/*
62** Exception stack frame pointer used in cpu_asm to pass the exception stack frame
63** address to the context switch code.
64*/
65#if (__mips == 1) || (__mips == 32)
66typedef uint32_t ESF_PTR_TYPE;
67#elif (__mips == 3)
68typedef uint64_t ESF_PTR_TYPE;
69#else
70#error "unknown MIPS ISA"
71#endif
72
73ESF_PTR_TYPE __exceptionStackFrame = 0;
74/*  _CPU_Initialize
75 *
76 *  This routine performs processor dependent initialization.
77 *
78 *    thread_dispatch - address of dispatching routine
79 */
80
81void _CPU_Initialize(void)
82{
83  /*
84   *  If there is not an easy way to initialize the FP context
85   *  during Context_Initialize, then it is usually easier to
86   *  save an "uninitialized" FP context here and copy it to
87   *  the task's during Context_Initialize.
88   */
89
90#if CPU_HARDWARE_FP
91  /* FP context initialization support goes here */
92  _CPU_Null_fp_context.fpcs = 0x1000000;        /* Set FS flag in floating point coprocessor
93                                                   control register to prevent underflow and
94                                                   inexact exceptions */
95#endif
96}
97
98uint32_t   _CPU_ISR_Get_level( void )
99{
100  unsigned int sr;
101
102  mips_get_sr(sr);
103
104  /* printf("current sr=%08X, ",sr); */
105
106#if (__mips == 3) || (__mips == 32)
107/* IE bit and shift down hardware ints into bits 1 thru 6 */
108  sr = (sr & SR_IE) | ((sr & mips_interrupt_mask()) >> 9);
109
110#elif __mips == 1
111/* IEC bit and shift down hardware ints into bits 1 thru 6 */
112  sr = (sr & SR_IEC) | ((sr & mips_interrupt_mask()) >> 9);
113
114#else
115#error "CPU ISR level: unknown MIPS level for SR handling"
116#endif
117  return sr;
118}
119void _CPU_ISR_Set_level( uint32_t   new_level )
120{
121  unsigned int sr, srbits;
122
123  /*
124  ** mask off the int level bits only so we can
125  ** preserve software int settings and FP enable
126  ** for this thread.  Note we don't force software ints
127  ** enabled when changing level, they were turned on
128  ** when this task was created, but may have been turned
129  ** off since, so we'll just leave them alone.
130  */
131
132  new_level &= 0xff;
133
134  mips_get_sr(sr);
135
136#if (__mips == 3) || (__mips == 32)
137  mips_set_sr( (sr & ~SR_IE) );                 /* first disable ie bit (recommended) */
138
139   srbits = sr & ~(0xfc00 | SR_IE);
140
141   sr = srbits | ((new_level==0)? (mips_interrupt_mask() | SR_IE): \
142                 (((new_level<<9) & mips_interrupt_mask()) | \
143                   ((new_level & 1)?SR_IE:0)));
144/*
145  if ( (new_level & SR_EXL) == (sr & SR_EXL) )
146    return;
147
148  if ( (new_level & SR_EXL) == 0 ) {
149    sr &= ~SR_EXL;                    * clear the EXL bit *
150    mips_set_sr(sr);
151  } else {
152
153    sr |= SR_EXL|SR_IE;              * enable exception level *
154    mips_set_sr(sr);                 * first disable ie bit (recommended) *
155  }
156*/
157
158#elif __mips == 1
159  mips_set_sr( (sr & ~SR_IEC) );
160  srbits = sr & ~(0xfc00 | SR_IEC);
161  sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc00) | \
162                                         (new_level & SR_IEC)));
163#else
164#error "CPU ISR level: unknown MIPS level for SR handling"
165#endif
166  mips_set_sr( sr );
167}
168
169void _CPU_Install_interrupt_stack( void )
170{
171/* we don't support this yet */
172}
173
174void _CPU_Context_Initialize(
175  Context_Control  *the_context,
176  uintptr_t        *stack_base,
177  uint32_t          size,
178  uint32_t          new_level,
179  void             *entry_point,
180  bool              is_fp,
181  void             *tls_area
182)
183{
184  uintptr_t             stack_tmp;
185  __MIPS_REGISTER_TYPE  intlvl = new_level & 0xff;
186  __MIPS_REGISTER_TYPE  c0_sr;
187
188  stack_tmp  = (uintptr_t)stack_base;
189  stack_tmp += ((size) - CPU_STACK_ALIGNMENT);
190  stack_tmp &= (__MIPS_REGISTER_TYPE) ~(CPU_STACK_ALIGNMENT - 1);
191
192  the_context->sp = (__MIPS_REGISTER_TYPE) stack_tmp;
193  the_context->fp = (__MIPS_REGISTER_TYPE) stack_tmp;
194  the_context->ra = (__MIPS_REGISTER_TYPE) (uintptr_t)entry_point;
195
196  c0_sr =
197    ((intlvl==0)? (mips_interrupt_mask() | 0x300 | _INTON):
198      ( ((intlvl<<9) & mips_interrupt_mask()) | 0x300 |
199      ((intlvl & 1)?_INTON:0)) ) |
200      SR_CU0 | _EXTRABITS;
201#if MIPS_HAS_FPU == 1
202  if ( is_fp ) {
203    c0_sr |= SR_CU1;
204  }
205#endif
206  the_context->c0_sr = c0_sr;
207}
208/*
209 *  _CPU_Internal_threads_Idle_thread_body
210 *
211 *  NOTES:
212 *
213 *  1. This is the same as the regular CPU independent algorithm.
214 *
215 *  2. If you implement this using a "halt", "idle", or "shutdown"
216 *     instruction, then don't forget to put it in an infinite loop.
217 *
218 *  3. Be warned. Some processors with onboard DMA have been known
219 *     to stop the DMA if the CPU were put in IDLE mode.  This might
220 *     also be a problem with other on-chip peripherals.  So use this
221 *     hook with caution.
222 */
223
224void *_CPU_Thread_Idle_body( uintptr_t ignored )
225{
226#if (__mips == 3) || (__mips == 32)
227   for( ; ; )
228     __asm__ volatile("wait"); /* use wait to enter low power mode */
229#elif __mips == 1
230   for( ; ; )
231     ;
232#else
233#error "IDLE: __mips not set to 1 or 3"
234#endif
235}
Note: See TracBrowser for help on using the repository browser.