source: rtems/cpukit/score/cpu/mips/cpu.c @ f799b452

Last change on this file since f799b452 was 2b32146, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/21 at 07:33:52

Remove superfluous <rtems/score/wkspace.h> includes

  • Property mode set to 100644
File size: 6.8 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/score/isr.h>
54
55#if CPU_HARDWARE_FP
56Context_Control_fp _CPU_Null_fp_context;
57#endif
58
59/*
60** Exception stack frame pointer used in cpu_asm to pass the exception stack frame
61** address to the context switch code.
62*/
63#if (__mips == 1) || (__mips == 32)
64typedef uint32_t ESF_PTR_TYPE;
65#elif (__mips == 3)
66typedef uint64_t ESF_PTR_TYPE;
67#else
68#error "unknown MIPS ISA"
69#endif
70
71ESF_PTR_TYPE __exceptionStackFrame = 0;
72/*  _CPU_Initialize
73 *
74 *  This routine performs processor dependent initialization.
75 *
76 *    thread_dispatch - address of dispatching routine
77 */
78
79void _CPU_Initialize(void)
80{
81  /*
82   *  If there is not an easy way to initialize the FP context
83   *  during Context_Initialize, then it is usually easier to
84   *  save an "uninitialized" FP context here and copy it to
85   *  the task's during Context_Initialize.
86   */
87
88#if CPU_HARDWARE_FP
89  /* FP context initialization support goes here */
90  _CPU_Null_fp_context.fpcs = 0x1000000;        /* Set FS flag in floating point coprocessor
91                                                   control register to prevent underflow and
92                                                   inexact exceptions */
93#endif
94}
95
96uint32_t   _CPU_ISR_Get_level( void )
97{
98  unsigned int sr;
99
100  mips_get_sr(sr);
101
102  /* printf("current sr=%08X, ",sr); */
103
104#if (__mips == 3) || (__mips == 32)
105/* IE bit and shift down hardware ints into bits 1 thru 6 */
106  sr = (sr & SR_IE) | ((sr & mips_interrupt_mask()) >> 9);
107
108#elif __mips == 1
109/* IEC bit and shift down hardware ints into bits 1 thru 6 */
110  sr = (sr & SR_IEC) | ((sr & mips_interrupt_mask()) >> 9);
111
112#else
113#error "CPU ISR level: unknown MIPS level for SR handling"
114#endif
115  return sr;
116}
117void _CPU_ISR_Set_level( uint32_t   new_level )
118{
119  unsigned int sr, srbits;
120
121  /*
122  ** mask off the int level bits only so we can
123  ** preserve software int settings and FP enable
124  ** for this thread.  Note we don't force software ints
125  ** enabled when changing level, they were turned on
126  ** when this task was created, but may have been turned
127  ** off since, so we'll just leave them alone.
128  */
129
130  new_level &= 0xff;
131
132  mips_get_sr(sr);
133
134#if (__mips == 3) || (__mips == 32)
135  mips_set_sr( (sr & ~SR_IE) );                 /* first disable ie bit (recommended) */
136
137   srbits = sr & ~(0xfc00 | SR_IE);
138
139   sr = srbits | ((new_level==0)? (mips_interrupt_mask() | SR_IE): \
140                 (((new_level<<9) & mips_interrupt_mask()) | \
141                   ((new_level & 1)?SR_IE:0)));
142/*
143  if ( (new_level & SR_EXL) == (sr & SR_EXL) )
144    return;
145
146  if ( (new_level & SR_EXL) == 0 ) {
147    sr &= ~SR_EXL;                    * clear the EXL bit *
148    mips_set_sr(sr);
149  } else {
150
151    sr |= SR_EXL|SR_IE;              * enable exception level *
152    mips_set_sr(sr);                 * first disable ie bit (recommended) *
153  }
154*/
155
156#elif __mips == 1
157  mips_set_sr( (sr & ~SR_IEC) );
158  srbits = sr & ~(0xfc00 | SR_IEC);
159  sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc00) | \
160                                         (new_level & SR_IEC)));
161#else
162#error "CPU ISR level: unknown MIPS level for SR handling"
163#endif
164  mips_set_sr( sr );
165}
166
167void _CPU_Context_Initialize(
168  Context_Control  *the_context,
169  uintptr_t        *stack_base,
170  uint32_t          size,
171  uint32_t          new_level,
172  void             *entry_point,
173  bool              is_fp,
174  void             *tls_area
175)
176{
177  uintptr_t             stack_tmp;
178  __MIPS_REGISTER_TYPE  intlvl = new_level & 0xff;
179  __MIPS_REGISTER_TYPE  c0_sr;
180
181  stack_tmp  = (uintptr_t)stack_base;
182  stack_tmp += ((size) - CPU_STACK_ALIGNMENT);
183  stack_tmp &= (__MIPS_REGISTER_TYPE) ~(CPU_STACK_ALIGNMENT - 1);
184
185  the_context->sp = (__MIPS_REGISTER_TYPE) stack_tmp;
186  the_context->fp = (__MIPS_REGISTER_TYPE) stack_tmp;
187  the_context->ra = (__MIPS_REGISTER_TYPE) (uintptr_t)entry_point;
188
189  c0_sr =
190    ((intlvl==0)? (mips_interrupt_mask() | 0x300 | _INTON):
191      ( ((intlvl<<9) & mips_interrupt_mask()) | 0x300 |
192      ((intlvl & 1)?_INTON:0)) ) |
193      SR_CU0 | _EXTRABITS;
194#if MIPS_HAS_FPU == 1
195  if ( is_fp ) {
196    c0_sr |= SR_CU1;
197  }
198#endif
199  the_context->c0_sr = c0_sr;
200}
201/*
202 *  _CPU_Internal_threads_Idle_thread_body
203 *
204 *  NOTES:
205 *
206 *  1. This is the same as the regular CPU independent algorithm.
207 *
208 *  2. If you implement this using a "halt", "idle", or "shutdown"
209 *     instruction, then don't forget to put it in an infinite loop.
210 *
211 *  3. Be warned. Some processors with onboard DMA have been known
212 *     to stop the DMA if the CPU were put in IDLE mode.  This might
213 *     also be a problem with other on-chip peripherals.  So use this
214 *     hook with caution.
215 */
216
217void *_CPU_Thread_Idle_body( uintptr_t ignored )
218{
219#if (__mips == 3) || (__mips == 32)
220   for( ; ; )
221     __asm__ volatile("wait"); /* use wait to enter low power mode */
222#elif __mips == 1
223   for( ; ; )
224     ;
225#else
226#error "IDLE: __mips not set to 1 or 3"
227#endif
228}
Note: See TracBrowser for help on using the repository browser.