source: rtems/cpukit/score/cpu/mips/rtems/score/cpu.h @ 524055a9

4.104.115
Last change on this file since 524055a9 was 524055a9, checked in by Joel Sherrill <joel.sherrill@…>, on 04/25/10 at 14:58:27

2010-04-25 Joel Sherrill <joel.sherrilL@…>

  • rtems/score/cpu.h: Remove warning in _CPU_Context_Initialize.
  • Property mode set to 100644
File size: 42.3 KB
Line 
1/*
2 *  Mips CPU Dependent Header File
3 *
4 *  Conversion to MIPS port by Alan Cudmore <alanc@linuxstart.com> and
5 *           Joel Sherrill <joel@OARcorp.com>.
6 *
7 *    These changes made the code conditional on standard cpp predefines,
8 *    merged the mips1 and mips3 code sequences as much as possible,
9 *    and moved some of the assembly code to C.  Alan did much of the
10 *    initial analysis and rework.  Joel took over from there and
11 *    wrote the JMR3904 BSP so this could be tested.  Joel also
12 *    added the new interrupt vectoring support in libcpu and
13 *    tried to better support the various interrupt controllers.
14 *
15 *  Original MIP64ORION port by Craig Lebakken <craigl@transition.com>
16 *           COPYRIGHT (c) 1996 by Transition Networks Inc.
17 *
18 *    To anyone who acknowledges that this file is provided "AS IS"
19 *    without any express or implied warranty:
20 *      permission to use, copy, modify, and distribute this file
21 *      for any purpose is hereby granted without fee, provided that
22 *      the above copyright notice and this notice appears in all
23 *      copies, and that the name of Transition Networks not be used in
24 *      advertising or publicity pertaining to distribution of the
25 *      software without specific, written prior permission.
26 *      Transition Networks makes no representations about the suitability
27 *      of this software for any purpose.
28 *
29 *  COPYRIGHT (c) 1989-2006.
30 *  On-Line Applications Research Corporation (OAR).
31 *
32 *  The license and distribution terms for this file may be
33 *  found in the file LICENSE in this distribution or at
34 *  http://www.rtems.com/license/LICENSE.
35 *
36 *  $Id$
37 */
38
39#ifndef _RTEMS_SCORE_CPU_H
40#define _RTEMS_SCORE_CPU_H
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#include <rtems/score/mips.h>       /* pick up machine definitions */
47#ifndef ASM
48#include <rtems/score/types.h>
49#endif
50
51#ifndef TRUE
52#define TRUE 1
53#endif
54#ifndef FALSE
55#define FALSE 0
56#endif
57
58
59/* conditional compilation parameters */
60
61/*
62 *  Should the calls to _Thread_Enable_dispatch be inlined?
63 *
64 *  If TRUE, then they are inlined.
65 *  If FALSE, then a subroutine call is made.
66 *
67 *  Basically this is an example of the classic trade-off of size
68 *  versus speed.  Inlining the call (TRUE) typically increases the
69 *  size of RTEMS while speeding up the enabling of dispatching.
70 *  [NOTE: In general, the _Thread_Dispatch_disable_level will
71 *  only be 0 or 1 unless you are in an interrupt handler and that
72 *  interrupt handler invokes the executive.]  When not inlined
73 *  something calls _Thread_Enable_dispatch which in turns calls
74 *  _Thread_Dispatch.  If the enable dispatch is inlined, then
75 *  one subroutine call is avoided entirely.]
76 */
77
78#define CPU_INLINE_ENABLE_DISPATCH       FALSE
79
80/*
81 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
82 *  be unrolled one time?  In unrolled each iteration of the loop examines
83 *  two "nodes" on the chain being searched.  Otherwise, only one node
84 *  is examined per iteration.
85 *
86 *  If TRUE, then the loops are unrolled.
87 *  If FALSE, then the loops are not unrolled.
88 *
89 *  The primary factor in making this decision is the cost of disabling
90 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
91 *  body of the loop.  On some CPUs, the flash is more expensive than
92 *  one iteration of the loop body.  In this case, it might be desirable
93 *  to unroll the loop.  It is important to note that on some CPUs, this
94 *  code is the longest interrupt disable period in RTEMS.  So it is
95 *  necessary to strike a balance when setting this parameter.
96 */
97
98#define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
99
100/*
101 *  Does RTEMS manage a dedicated interrupt stack in software?
102 *
103 *  If TRUE, then a stack is allocated in _Interrupt_Manager_initialization.
104 *  If FALSE, nothing is done.
105 *
106 *  If the CPU supports a dedicated interrupt stack in hardware,
107 *  then it is generally the responsibility of the BSP to allocate it
108 *  and set it up.
109 *
110 *  If the CPU does not support a dedicated interrupt stack, then
111 *  the porter has two options: (1) execute interrupts on the
112 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
113 *  interrupt stack.
114 *
115 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
116 *
117 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
118 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
119 *  possible that both are FALSE for a particular CPU.  Although it
120 *  is unclear what that would imply about the interrupt processing
121 *  procedure on that CPU.
122 */
123
124#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
125
126/*
127 *  Does the CPU follow the simple vectored interrupt model?
128 *
129 *  If TRUE, then RTEMS allocates the vector table it internally manages.
130 *  If FALSE, then the BSP is assumed to allocate and manage the vector
131 *  table
132 *
133 *  MIPS Specific Information:
134 *
135 *  XXX document implementation including references if appropriate
136 */
137#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
138
139/*
140 *  Does this CPU have hardware support for a dedicated interrupt stack?
141 *
142 *  If TRUE, then it must be installed during initialization.
143 *  If FALSE, then no installation is performed.
144 *
145 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
146 *
147 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
148 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
149 *  possible that both are FALSE for a particular CPU.  Although it
150 *  is unclear what that would imply about the interrupt processing
151 *  procedure on that CPU.
152 */
153
154#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
155
156/*
157 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
158 *
159 *  If TRUE, then the memory is allocated during initialization.
160 *  If FALSE, then the memory is allocated during initialization.
161 *
162 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
163 */
164
165#define CPU_ALLOCATE_INTERRUPT_STACK FALSE
166
167/*
168 *  Does the RTEMS invoke the user's ISR with the vector number and
169 *  a pointer to the saved interrupt frame (1) or just the vector
170 *  number (0)?
171 *
172 */
173
174#define CPU_ISR_PASSES_FRAME_POINTER 1
175
176
177
178/*
179 *  Does the CPU have hardware floating point?
180 *
181 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
182 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
183 *
184 *  If there is a FP coprocessor such as the i387 or mc68881, then
185 *  the answer is TRUE.
186 *
187 *  The macro name "MIPS_HAS_FPU" should be made CPU specific.
188 *  It indicates whether or not this CPU model has FP support.  For
189 *  example, it would be possible to have an i386_nofp CPU model
190 *  which set this to false to indicate that you have an i386 without
191 *  an i387 and wish to leave floating point support out of RTEMS.
192 */
193
194#if ( MIPS_HAS_FPU == 1 )
195#define CPU_HARDWARE_FP     TRUE
196#else
197#define CPU_HARDWARE_FP     FALSE
198#endif
199
200/*
201 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
202 *
203 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
204 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
205 *
206 *  So far, the only CPU in which this option has been used is the
207 *  HP PA-RISC.  The HP C compiler and gcc both implicitly use the
208 *  floating point registers to perform integer multiplies.  If
209 *  a function which you would not think utilize the FP unit DOES,
210 *  then one can not easily predict which tasks will use the FP hardware.
211 *  In this case, this option should be TRUE.
212 *
213 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
214 */
215
216#define CPU_ALL_TASKS_ARE_FP    FALSE
217
218/*
219 *  Should the IDLE task have a floating point context?
220 *
221 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
222 *  and it has a floating point context which is switched in and out.
223 *  If FALSE, then the IDLE task does not have a floating point context.
224 *
225 *  Setting this to TRUE negatively impacts the time required to preempt
226 *  the IDLE task from an interrupt because the floating point context
227 *  must be saved as part of the preemption.
228 */
229
230#define CPU_IDLE_TASK_IS_FP      FALSE
231
232/*
233 *  Should the saving of the floating point registers be deferred
234 *  until a context switch is made to another different floating point
235 *  task?
236 *
237 *  If TRUE, then the floating point context will not be stored until
238 *  necessary.  It will remain in the floating point registers and not
239 *  disturned until another floating point task is switched to.
240 *
241 *  If FALSE, then the floating point context is saved when a floating
242 *  point task is switched out and restored when the next floating point
243 *  task is restored.  The state of the floating point registers between
244 *  those two operations is not specified.
245 *
246 *  If the floating point context does NOT have to be saved as part of
247 *  interrupt dispatching, then it should be safe to set this to TRUE.
248 *
249 *  Setting this flag to TRUE results in using a different algorithm
250 *  for deciding when to save and restore the floating point context.
251 *  The deferred FP switch algorithm minimizes the number of times
252 *  the FP context is saved and restored.  The FP context is not saved
253 *  until a context switch is made to another, different FP task.
254 *  Thus in a system with only one FP task, the FP context will never
255 *  be saved or restored.
256 */
257
258#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
259
260/*
261 *  Does this port provide a CPU dependent IDLE task implementation?
262 *
263 *  If TRUE, then the routine _CPU_Internal_threads_Idle_thread_body
264 *  must be provided and is the default IDLE thread body instead of
265 *  _Internal_threads_Idle_thread_body.
266 *
267 *  If FALSE, then use the generic IDLE thread body if the BSP does
268 *  not provide one.
269 *
270 *  This is intended to allow for supporting processors which have
271 *  a low power or idle mode.  When the IDLE thread is executed, then
272 *  the CPU can be powered down.
273 *
274 *  The order of precedence for selecting the IDLE thread body is:
275 *
276 *    1.  BSP provided
277 *    2.  CPU dependent (if provided)
278 *    3.  generic (if no BSP and no CPU dependent)
279 */
280
281/* we can use the low power wait instruction for the IDLE thread */
282#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
283
284/*
285 *  Does the stack grow up (toward higher addresses) or down
286 *  (toward lower addresses)?
287 *
288 *  If TRUE, then the grows upward.
289 *  If FALSE, then the grows toward smaller addresses.
290 */
291
292/* our stack grows down */
293#define CPU_STACK_GROWS_UP               FALSE
294
295/*
296 *  The following is the variable attribute used to force alignment
297 *  of critical RTEMS structures.  On some processors it may make
298 *  sense to have these aligned on tighter boundaries than
299 *  the minimum requirements of the compiler in order to have as
300 *  much of the critical data area as possible in a cache line.
301 *
302 *  The placement of this macro in the declaration of the variables
303 *  is based on the syntactically requirements of the GNU C
304 *  "__attribute__" extension.  For example with GNU C, use
305 *  the following to force a structures to a 32 byte boundary.
306 *
307 *      __attribute__ ((aligned (32)))
308 *
309 *  NOTE:  Currently only the Priority Bit Map table uses this feature.
310 *         To benefit from using this, the data must be heavily
311 *         used so it will stay in the cache and used frequently enough
312 *         in the executive to justify turning this on.
313 */
314
315/* our cache line size is 16 bytes */
316#if __GNUC__
317#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (16)))
318#else
319#define CPU_STRUCTURE_ALIGNMENT
320#endif
321
322/*
323 *  Define what is required to specify how the network to host conversion
324 *  routines are handled.
325 */
326
327/* __MIPSEB__ or __MIPSEL__ is defined by GCC based on -EB or -EL command line options */
328#if defined(__MIPSEB__)
329#define CPU_BIG_ENDIAN                           TRUE
330#define CPU_LITTLE_ENDIAN                        FALSE
331#elif defined(__MIPSEL__)
332#define CPU_BIG_ENDIAN                           FALSE
333#define CPU_LITTLE_ENDIAN                        TRUE
334#else
335#error "Unknown endianness"
336#endif
337
338/*
339 *  The following defines the number of bits actually used in the
340 *  interrupt field of the task mode.  How those bits map to the
341 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
342 */
343
344#define CPU_MODES_INTERRUPT_MASK   0x000000ff
345
346/*
347 *  Processor defined structures
348 *
349 *  Examples structures include the descriptor tables from the i386
350 *  and the processor control structure on the i960ca.
351 */
352
353/* may need to put some structures here.  */
354
355/*
356 * Contexts
357 *
358 *  Generally there are 2 types of context to save.
359 *     1. Interrupt registers to save
360 *     2. Task level registers to save
361 *
362 *  This means we have the following 3 context items:
363 *     1. task level context stuff::  Context_Control
364 *     2. floating point task stuff:: Context_Control_fp
365 *     3. special interrupt level context :: Context_Control_interrupt
366 *
367 *  On some processors, it is cost-effective to save only the callee
368 *  preserved registers during a task context switch.  This means
369 *  that the ISR code needs to save those registers which do not
370 *  persist across function calls.  It is not mandatory to make this
371 *  distinctions between the caller/callee saves registers for the
372 *  purpose of minimizing context saved during task switch and on interrupts.
373 *  If the cost of saving extra registers is minimal, simplicity is the
374 *  choice.  Save the same context on interrupt entry as for tasks in
375 *  this case.
376 *
377 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
378 *  care should be used in designing the context area.
379 *
380 *  On some CPUs with hardware floating point support, the Context_Control_fp
381 *  structure will not be used or it simply consist of an array of a
382 *  fixed number of bytes.   This is done when the floating point context
383 *  is dumped by a "FP save context" type instruction and the format
384 *  is not really defined by the CPU.  In this case, there is no need
385 *  to figure out the exact format -- only the size.  Of course, although
386 *  this is enough information for RTEMS, it is probably not enough for
387 *  a debugger such as gdb.  But that is another problem.
388 */
389
390#ifndef ASSEMBLY_ONLY
391
392/* WARNING: If this structure is modified, the constants in cpu.h must be updated. */
393#if (__mips == 1) || (__mips == 32)
394#define __MIPS_REGISTER_TYPE     uint32_t
395#define __MIPS_FPU_REGISTER_TYPE uint32_t
396#elif __mips == 3
397#define __MIPS_REGISTER_TYPE     uint64_t
398#define __MIPS_FPU_REGISTER_TYPE uint64_t
399#else
400#error "mips register size: unknown architecture level!!"
401#endif
402typedef struct {
403    __MIPS_REGISTER_TYPE s0;
404    __MIPS_REGISTER_TYPE s1;
405    __MIPS_REGISTER_TYPE s2;
406    __MIPS_REGISTER_TYPE s3;
407    __MIPS_REGISTER_TYPE s4;
408    __MIPS_REGISTER_TYPE s5;
409    __MIPS_REGISTER_TYPE s6;
410    __MIPS_REGISTER_TYPE s7;
411    __MIPS_REGISTER_TYPE sp;
412    __MIPS_REGISTER_TYPE fp;
413    __MIPS_REGISTER_TYPE ra;
414    __MIPS_REGISTER_TYPE c0_sr;
415    __MIPS_REGISTER_TYPE c0_epc;
416} Context_Control;
417
418#define _CPU_Context_Get_SP( _context ) \
419  (_context)->sp
420
421/* WARNING: If this structure is modified, the constants in cpu.h
422 *          must also be updated.
423 */
424
425typedef struct {
426#if ( CPU_HARDWARE_FP == TRUE )
427    __MIPS_FPU_REGISTER_TYPE fp0;
428    __MIPS_FPU_REGISTER_TYPE fp1;
429    __MIPS_FPU_REGISTER_TYPE fp2;
430    __MIPS_FPU_REGISTER_TYPE fp3;
431    __MIPS_FPU_REGISTER_TYPE fp4;
432    __MIPS_FPU_REGISTER_TYPE fp5;
433    __MIPS_FPU_REGISTER_TYPE fp6;
434    __MIPS_FPU_REGISTER_TYPE fp7;
435    __MIPS_FPU_REGISTER_TYPE fp8;
436    __MIPS_FPU_REGISTER_TYPE fp9;
437    __MIPS_FPU_REGISTER_TYPE fp10;
438    __MIPS_FPU_REGISTER_TYPE fp11;
439    __MIPS_FPU_REGISTER_TYPE fp12;
440    __MIPS_FPU_REGISTER_TYPE fp13;
441    __MIPS_FPU_REGISTER_TYPE fp14;
442    __MIPS_FPU_REGISTER_TYPE fp15;
443    __MIPS_FPU_REGISTER_TYPE fp16;
444    __MIPS_FPU_REGISTER_TYPE fp17;
445    __MIPS_FPU_REGISTER_TYPE fp18;
446    __MIPS_FPU_REGISTER_TYPE fp19;
447    __MIPS_FPU_REGISTER_TYPE fp20;
448    __MIPS_FPU_REGISTER_TYPE fp21;
449    __MIPS_FPU_REGISTER_TYPE fp22;
450    __MIPS_FPU_REGISTER_TYPE fp23;
451    __MIPS_FPU_REGISTER_TYPE fp24;
452    __MIPS_FPU_REGISTER_TYPE fp25;
453    __MIPS_FPU_REGISTER_TYPE fp26;
454    __MIPS_FPU_REGISTER_TYPE fp27;
455    __MIPS_FPU_REGISTER_TYPE fp28;
456    __MIPS_FPU_REGISTER_TYPE fp29;
457    __MIPS_FPU_REGISTER_TYPE fp30;
458    __MIPS_FPU_REGISTER_TYPE fp31;
459    uint32_t fpcs;
460#endif
461} Context_Control_fp;
462
463/*
464 *  This struct reflects the stack frame employed in ISR_Handler.  Note
465 *  that the ISR routine save some of the registers to this frame for
466 *  all interrupts and exceptions.  Other registers are saved only on
467 *  exceptions, while others are not touched at all.  The untouched
468 *  registers are not normally disturbed by high-level language
469 *  programs so they can be accessed when required.
470 *
471 *  The registers and their ordering in this struct must directly
472 *  correspond to the layout and ordering of * shown in iregdef.h,
473 *  as cpu_asm.S uses those definitions to fill the stack frame.
474 *  This struct provides access to the stack frame for C code.
475 *
476 *  Similarly, this structure is used by debugger stubs and exception
477 *  processing routines so be careful when changing the format.
478 *
479 *  NOTE: The comments with this structure and cpu_asm.S should be kept
480 *        in sync.  When in doubt, look in the  code to see if the
481 *        registers you're interested in are actually treated as expected.
482 *        The order of the first portion of this structure follows the
483 *        order of registers expected by gdb.
484 */
485
486typedef struct
487{
488  __MIPS_REGISTER_TYPE  r0;       /*  0 -- NOT FILLED IN */
489  __MIPS_REGISTER_TYPE  at;       /*  1 -- saved always */
490  __MIPS_REGISTER_TYPE  v0;       /*  2 -- saved always */
491  __MIPS_REGISTER_TYPE  v1;       /*  3 -- saved always */
492  __MIPS_REGISTER_TYPE  a0;       /*  4 -- saved always */
493  __MIPS_REGISTER_TYPE  a1;       /*  5 -- saved always */
494  __MIPS_REGISTER_TYPE  a2;       /*  6 -- saved always */
495  __MIPS_REGISTER_TYPE  a3;       /*  7 -- saved always */
496  __MIPS_REGISTER_TYPE  t0;       /*  8 -- saved always */
497  __MIPS_REGISTER_TYPE  t1;       /*  9 -- saved always */
498  __MIPS_REGISTER_TYPE  t2;       /* 10 -- saved always */
499  __MIPS_REGISTER_TYPE  t3;       /* 11 -- saved always */
500  __MIPS_REGISTER_TYPE  t4;       /* 12 -- saved always */
501  __MIPS_REGISTER_TYPE  t5;       /* 13 -- saved always */
502  __MIPS_REGISTER_TYPE  t6;       /* 14 -- saved always */
503  __MIPS_REGISTER_TYPE  t7;       /* 15 -- saved always */
504  __MIPS_REGISTER_TYPE  s0;       /* 16 -- saved on exceptions */
505  __MIPS_REGISTER_TYPE  s1;       /* 17 -- saved on exceptions */
506  __MIPS_REGISTER_TYPE  s2;       /* 18 -- saved on exceptions */
507  __MIPS_REGISTER_TYPE  s3;       /* 19 -- saved on exceptions */
508  __MIPS_REGISTER_TYPE  s4;       /* 20 -- saved on exceptions */
509  __MIPS_REGISTER_TYPE  s5;       /* 21 -- saved on exceptions */
510  __MIPS_REGISTER_TYPE  s6;       /* 22 -- saved on exceptions */
511  __MIPS_REGISTER_TYPE  s7;       /* 23 -- saved on exceptions */
512  __MIPS_REGISTER_TYPE  t8;       /* 24 -- saved always */
513  __MIPS_REGISTER_TYPE  t9;       /* 25 -- saved always */
514  __MIPS_REGISTER_TYPE  k0;       /* 26 -- NOT FILLED IN, kernel tmp reg */
515  __MIPS_REGISTER_TYPE  k1;       /* 27 -- NOT FILLED IN, kernel tmp reg */
516  __MIPS_REGISTER_TYPE  gp;       /* 28 -- saved always */
517  __MIPS_REGISTER_TYPE  sp;       /* 29 -- saved on exceptions NOT RESTORED */
518  __MIPS_REGISTER_TYPE  fp;       /* 30 -- saved always */
519  __MIPS_REGISTER_TYPE  ra;       /* 31 -- saved always */
520  __MIPS_REGISTER_TYPE  c0_sr;    /* 32 -- saved always, some bits are */
521                                  /*    manipulated per-thread          */
522  __MIPS_REGISTER_TYPE  mdlo;     /* 33 -- saved always */
523  __MIPS_REGISTER_TYPE  mdhi;     /* 34 -- saved always */
524  __MIPS_REGISTER_TYPE  badvaddr; /* 35 -- saved on exceptions, read-only */
525  __MIPS_REGISTER_TYPE  cause;    /* 36 -- saved on exceptions NOT restored */
526  __MIPS_REGISTER_TYPE  epc;      /* 37 -- saved always, read-only register */
527                                  /*        but logically restored */
528  __MIPS_FPU_REGISTER_TYPE f0;    /* 38 -- saved if FP enabled */
529  __MIPS_FPU_REGISTER_TYPE f1;    /* 39 -- saved if FP enabled */
530  __MIPS_FPU_REGISTER_TYPE f2;    /* 40 -- saved if FP enabled */
531  __MIPS_FPU_REGISTER_TYPE f3;    /* 41 -- saved if FP enabled */
532  __MIPS_FPU_REGISTER_TYPE f4;    /* 42 -- saved if FP enabled */
533  __MIPS_FPU_REGISTER_TYPE f5;    /* 43 -- saved if FP enabled */
534  __MIPS_FPU_REGISTER_TYPE f6;    /* 44 -- saved if FP enabled */
535  __MIPS_FPU_REGISTER_TYPE f7;    /* 45 -- saved if FP enabled */
536  __MIPS_FPU_REGISTER_TYPE f8;    /* 46 -- saved if FP enabled */
537  __MIPS_FPU_REGISTER_TYPE f9;    /* 47 -- saved if FP enabled */
538  __MIPS_FPU_REGISTER_TYPE f10;   /* 48 -- saved if FP enabled */
539  __MIPS_FPU_REGISTER_TYPE f11;   /* 49 -- saved if FP enabled */
540  __MIPS_FPU_REGISTER_TYPE f12;   /* 50 -- saved if FP enabled */
541  __MIPS_FPU_REGISTER_TYPE f13;   /* 51 -- saved if FP enabled */
542  __MIPS_FPU_REGISTER_TYPE f14;   /* 52 -- saved if FP enabled */
543  __MIPS_FPU_REGISTER_TYPE f15;   /* 53 -- saved if FP enabled */
544  __MIPS_FPU_REGISTER_TYPE f16;   /* 54 -- saved if FP enabled */
545  __MIPS_FPU_REGISTER_TYPE f17;   /* 55 -- saved if FP enabled */
546  __MIPS_FPU_REGISTER_TYPE f18;   /* 56 -- saved if FP enabled */
547  __MIPS_FPU_REGISTER_TYPE f19;   /* 57 -- saved if FP enabled */
548  __MIPS_FPU_REGISTER_TYPE f20;   /* 58 -- saved if FP enabled */
549  __MIPS_FPU_REGISTER_TYPE f21;   /* 59 -- saved if FP enabled */
550  __MIPS_FPU_REGISTER_TYPE f22;   /* 60 -- saved if FP enabled */
551  __MIPS_FPU_REGISTER_TYPE f23;   /* 61 -- saved if FP enabled */
552  __MIPS_FPU_REGISTER_TYPE f24;   /* 62 -- saved if FP enabled */
553  __MIPS_FPU_REGISTER_TYPE f25;   /* 63 -- saved if FP enabled */
554  __MIPS_FPU_REGISTER_TYPE f26;   /* 64 -- saved if FP enabled */
555  __MIPS_FPU_REGISTER_TYPE f27;   /* 65 -- saved if FP enabled */
556  __MIPS_FPU_REGISTER_TYPE f28;   /* 66 -- saved if FP enabled */
557  __MIPS_FPU_REGISTER_TYPE f29;   /* 67 -- saved if FP enabled */
558  __MIPS_FPU_REGISTER_TYPE f30;   /* 68 -- saved if FP enabled */
559  __MIPS_FPU_REGISTER_TYPE f31;   /* 69 -- saved if FP enabled */
560  __MIPS_REGISTER_TYPE     fcsr;  /* 70 -- saved on exceptions */
561                                  /*    (oddly not documented on MGV) */
562  __MIPS_REGISTER_TYPE     feir;  /* 71 -- saved on exceptions */
563                                  /*    (oddly not documented on MGV) */
564
565  /* GDB does not seem to care about anything past this point */
566
567  __MIPS_REGISTER_TYPE  tlbhi;    /* 72 - NOT FILLED IN, doesn't exist on */
568                                  /*         all MIPS CPUs (at least MGV) */
569#if __mips == 1
570  __MIPS_REGISTER_TYPE  tlblo;    /* 73 - NOT FILLED IN, doesn't exist on */
571                                  /*         all MIPS CPUs (at least MGV) */
572#endif
573#if  (__mips == 3) || (__mips == 32)
574  __MIPS_REGISTER_TYPE  tlblo0;   /* 73 - NOT FILLED IN, doesn't exist on */
575                                  /*         all MIPS CPUs (at least MGV) */
576#endif
577
578  __MIPS_REGISTER_TYPE  inx;      /* 74 -- NOT FILLED IN, doesn't exist on */
579                                  /*         all MIPS CPUs (at least MGV) */
580  __MIPS_REGISTER_TYPE  rand;     /* 75 -- NOT FILLED IN, doesn't exist on */
581                                  /*         all MIPS CPUs (at least MGV) */
582  __MIPS_REGISTER_TYPE  ctxt;     /* 76 -- NOT FILLED IN, doesn't exist on */
583                                  /*         all MIPS CPUs (at least MGV) */
584  __MIPS_REGISTER_TYPE  exctype;  /* 77 -- NOT FILLED IN (not enough info) */
585  __MIPS_REGISTER_TYPE  mode;     /* 78 -- NOT FILLED IN (not enough info) */
586  __MIPS_REGISTER_TYPE  prid;     /* 79 -- NOT FILLED IN (not need to do so) */
587  __MIPS_REGISTER_TYPE  tar ;     /* 80 -- target address register, filled on exceptions */
588  /* end of __mips == 1 so NREGS == 81 */
589#if  (__mips == 3) || (__mips == 32)
590  __MIPS_REGISTER_TYPE  tlblo1;   /* 81 -- NOT FILLED IN */
591  __MIPS_REGISTER_TYPE  pagemask; /* 82 -- NOT FILLED IN */
592  __MIPS_REGISTER_TYPE  wired;    /* 83 -- NOT FILLED IN */
593  __MIPS_REGISTER_TYPE  count;    /* 84 -- NOT FILLED IN */
594  __MIPS_REGISTER_TYPE  compare;  /* 85 -- NOT FILLED IN */
595  __MIPS_REGISTER_TYPE  config;   /* 86 -- NOT FILLED IN */
596  __MIPS_REGISTER_TYPE  lladdr;   /* 87 -- NOT FILLED IN */
597  __MIPS_REGISTER_TYPE  watchlo;  /* 88 -- NOT FILLED IN */
598  __MIPS_REGISTER_TYPE  watchhi;  /* 89 -- NOT FILLED IN */
599  __MIPS_REGISTER_TYPE  ecc;      /* 90 -- NOT FILLED IN */
600  __MIPS_REGISTER_TYPE  cacheerr; /* 91 -- NOT FILLED IN */
601  __MIPS_REGISTER_TYPE  taglo;    /* 92 -- NOT FILLED IN */
602  __MIPS_REGISTER_TYPE  taghi;    /* 93 -- NOT FILLED IN */
603  __MIPS_REGISTER_TYPE  errpc;    /* 94 -- NOT FILLED IN */
604  __MIPS_REGISTER_TYPE  xctxt;    /* 95 -- NOT FILLED IN */
605 /* end of __mips == 3 so NREGS == 96 */
606#endif
607
608} CPU_Interrupt_frame;
609
610/*
611 *  This variable is optional.  It is used on CPUs on which it is difficult
612 *  to generate an "uninitialized" FP context.  It is filled in by
613 *  _CPU_Initialize and copied into the task's FP context area during
614 *  _CPU_Context_Initialize.
615 */
616
617SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
618
619/*
620 *  On some CPUs, RTEMS supports a software managed interrupt stack.
621 *  This stack is allocated by the Interrupt Manager and the switch
622 *  is performed in _ISR_Handler.  These variables contain pointers
623 *  to the lowest and highest addresses in the chunk of memory allocated
624 *  for the interrupt stack.  Since it is unknown whether the stack
625 *  grows up or down (in general), this give the CPU dependent
626 *  code the option of picking the version it wants to use.
627 *
628 *  NOTE: These two variables are required if the macro
629 *        CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
630 */
631
632SCORE_EXTERN void               *_CPU_Interrupt_stack_low;
633SCORE_EXTERN void               *_CPU_Interrupt_stack_high;
634
635/*
636 *  Nothing prevents the porter from declaring more CPU specific variables.
637 */
638
639/* XXX: if needed, put more variables here */
640
641/*
642 *  The size of the floating point context area.  On some CPUs this
643 *  will not be a "sizeof" because the format of the floating point
644 *  area is not defined -- only the size is.  This is usually on
645 *  CPUs with a "floating point save context" instruction.
646 */
647
648#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
649
650/*
651 *  Amount of extra stack (above minimum stack size) required by
652 *  system initialization thread.  Remember that in a multiprocessor
653 *  system the system intialization thread becomes the MP server thread.
654 */
655
656#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
657
658/*
659 *  This defines the number of entries in the ISR_Vector_table managed
660 *  by RTEMS.
661 */
662
663extern unsigned int mips_interrupt_number_of_vectors;
664#define CPU_INTERRUPT_NUMBER_OF_VECTORS      (mips_interrupt_number_of_vectors)
665#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
666
667/*
668 *  Should be large enough to run all RTEMS tests.  This ensures
669 *  that a "reasonable" small application should not have any problems.
670 */
671
672#define CPU_STACK_MINIMUM_SIZE          (8 * 1024)
673
674/*
675 *  CPU's worst alignment requirement for data types on a byte boundary.  This
676 *  alignment does not take into account the requirements for the stack.
677 */
678
679#define CPU_ALIGNMENT              8
680
681/*
682 *  This number corresponds to the byte alignment requirement for the
683 *  heap handler.  This alignment requirement may be stricter than that
684 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
685 *  common for the heap to follow the same alignment requirement as
686 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
687 *  then this should be set to CPU_ALIGNMENT.
688 *
689 *  NOTE:  This does not have to be a power of 2.  It does have to
690 *         be greater or equal to than CPU_ALIGNMENT.
691 */
692
693#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
694
695/*
696 *  This number corresponds to the byte alignment requirement for memory
697 *  buffers allocated by the partition manager.  This alignment requirement
698 *  may be stricter than that for the data types alignment specified by
699 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
700 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
701 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
702 *
703 *  NOTE:  This does not have to be a power of 2.  It does have to
704 *         be greater or equal to than CPU_ALIGNMENT.
705 */
706
707#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
708
709/*
710 *  This number corresponds to the byte alignment requirement for the
711 *  stack.  This alignment requirement may be stricter than that for the
712 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
713 *  is strict enough for the stack, then this should be set to 0.
714 *
715 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
716 */
717
718#define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
719
720/*
721 *  ISR handler macros
722 */
723
724/*
725 *  Support routine to initialize the RTEMS vector table after it is allocated.
726 */
727
728#define _CPU_Initialize_vectors()
729
730/*
731 *  Declare the function that is present in the shared libcpu directory,
732 *  that returns the processor dependent interrupt mask.
733 */
734
735uint32_t mips_interrupt_mask( void );
736
737/*
738 *  Disable all interrupts for an RTEMS critical section.  The previous
739 *  level is returned in _level.
740 */
741
742#define _CPU_ISR_Disable( _level ) \
743  do { \
744    unsigned int _scratch; \
745    mips_get_sr( _scratch ); \
746    mips_set_sr( _scratch & ~SR_INTERRUPT_ENABLE_BITS ); \
747    _level = _scratch & SR_INTERRUPT_ENABLE_BITS; \
748  } while(0)
749
750/*
751 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
752 *  This indicates the end of an RTEMS critical section.  The parameter
753 *  _level is not modified.
754 */
755
756#define _CPU_ISR_Enable( _level )  \
757  do { \
758    unsigned int _scratch; \
759    mips_get_sr( _scratch ); \
760    mips_set_sr( (_scratch & ~SR_INTERRUPT_ENABLE_BITS) | (_level & SR_INTERRUPT_ENABLE_BITS) ); \
761  } while(0)
762
763/*
764 *  This temporarily restores the interrupt to _level before immediately
765 *  disabling them again.  This is used to divide long RTEMS critical
766 *  sections into two or more parts.  The parameter _level is not
767 *  modified.
768 */
769
770#define _CPU_ISR_Flash( _xlevel ) \
771  do { \
772    unsigned int _scratch2 = _xlevel; \
773    _CPU_ISR_Enable( _scratch2 ); \
774    _CPU_ISR_Disable( _scratch2 ); \
775    _xlevel = _scratch2; \
776  } while(0)
777
778/*
779 *  Map interrupt level in task mode onto the hardware that the CPU
780 *  actually provides.  Currently, interrupt levels which do not
781 *  map onto the CPU in a generic fashion are undefined.  Someday,
782 *  it would be nice if these were "mapped" by the application
783 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
784 *  8 - 255 would be available for bsp/application specific meaning.
785 *  This could be used to manage a programmable interrupt controller
786 *  via the rtems_task_mode directive.
787 *
788 *  On the MIPS, 0 is all on.  Non-zero is all off.  This only
789 *  manipulates the IEC.
790 */
791
792uint32_t   _CPU_ISR_Get_level( void );  /* in cpu.c */
793
794void _CPU_ISR_Set_level( uint32_t   );  /* in cpu.c */
795
796/* end of ISR handler macros */
797
798/* Context handler macros */
799
800/*
801 *  Initialize the context to a state suitable for starting a
802 *  task after a context restore operation.  Generally, this
803 *  involves:
804 *
805 *     - setting a starting address
806 *     - preparing the stack
807 *     - preparing the stack and frame pointers
808 *     - setting the proper interrupt level in the context
809 *     - initializing the floating point context
810 *
811 *  This routine generally does not set any unnecessary register
812 *  in the context.  The state of the "general data" registers is
813 *  undefined at task start time.
814 *
815 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
816 *        point thread.  This is typically only used on CPUs where the
817 *        FPU may be easily disabled by software such as on the SPARC
818 *        where the PSR contains an enable FPU bit.
819 *
820 *  The per-thread status register holds the interrupt enable, FP enable
821 *  and global interrupt enable for that thread.  It means each thread can
822 *  enable its own set of interrupts.  If interrupts are disabled, RTEMS
823 *  can still dispatch via blocking calls.  This is the function of the
824 *  "Interrupt Level", and on the MIPS, it controls the IEC bit and all
825 *  the hardware interrupts as defined in the SR.  Software ints
826 *  are automatically enabled for all threads, as they will only occur under
827 *  program control anyhow.  Besides, the interrupt level parm is only 8 bits,
828 *  and controlling the software ints plus the others would require 9.
829 *
830 *  If the Interrupt Level is 0, all ints are on.  Otherwise, the
831 *  Interrupt Level should supply a bit pattern to impose on the SR
832 *  interrupt bits; bit 0 applies to the mips1 IEC bit/mips3 EXL&IE, bits 1 thru 6
833 *  apply to the SR register Intr bits from bit 10 thru bit 15.  Bit 7 of
834 *  the Interrupt Level parameter is unused at this time.
835 *
836 *  These are the only per-thread SR bits, the others are maintained
837 *  globally & explicitly preserved by the Context Switch code in cpu_asm.s
838 */
839
840
841#if (__mips == 3) || (__mips == 32)
842#define _INTON          SR_IE
843#if __mips_fpr==64
844#define _EXTRABITS      SR_FR
845#else
846#define _EXTRABITS      0
847#endif /* __mips_fpr==64 */
848#endif /* __mips == 3 */
849#if __mips == 1
850#define _INTON          SR_IEC
851#define _EXTRABITS      0  /* make sure we're in user mode on MIPS1 processors */
852#endif /* __mips == 1 */
853
854#define _CPU_Context_Initialize( _the_context, _stack_base, _size, _isr, _entry_point, _is_fp ) \
855  { \
856        uintptr_t  _stack_tmp = \
857           (uintptr_t)(_stack_base) + (_size) - CPU_STACK_ALIGNMENT; \
858        uintptr_t  _intlvl = _isr & 0xff; \
859        _stack_tmp &= ~(CPU_STACK_ALIGNMENT - 1); \
860        (_the_context)->sp = (__MIPS_REGISTER_TYPE) _stack_tmp; \
861        (_the_context)->fp = (__MIPS_REGISTER_TYPE) _stack_tmp; \
862        (_the_context)->ra = (__MIPS_REGISTER_TYPE)_entry_point; \
863        (_the_context)->c0_sr = ((_intlvl==0)?(mips_interrupt_mask() | 0x300 | _INTON): \
864                ( ((_intlvl<<9) & mips_interrupt_mask()) | 0x300 | ((_intlvl & 1)?_INTON:0)) ) | \
865                                SR_CU0 | ((_is_fp)?SR_CU1:0) | _EXTRABITS; \
866  }
867
868
869
870/*
871 *  This routine is responsible for somehow restarting the currently
872 *  executing task.  If you are lucky, then all that is necessary
873 *  is restoring the context.  Otherwise, there will need to be
874 *  a special assembly routine which does something special in this
875 *  case.  Context_Restore should work most of the time.  It will
876 *  not work if restarting self conflicts with the stack frame
877 *  assumptions of restoring a context.
878 */
879
880#define _CPU_Context_Restart_self( _the_context ) \
881   _CPU_Context_restore( (_the_context) );
882
883/*
884 *  The purpose of this macro is to allow the initial pointer into
885 *  A floating point context area (used to save the floating point
886 *  context) to be at an arbitrary place in the floating point
887 *  context area.
888 *
889 *  This is necessary because some FP units are designed to have
890 *  their context saved as a stack which grows into lower addresses.
891 *  Other FP units can be saved by simply moving registers into offsets
892 *  from the base of the context area.  Finally some FP units provide
893 *  a "dump context" instruction which could fill in from high to low
894 *  or low to high based on the whim of the CPU designers.
895 */
896
897#define _CPU_Context_Fp_start( _base, _offset ) \
898   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
899
900/*
901 *  This routine initializes the FP context area passed to it to.
902 *  There are a few standard ways in which to initialize the
903 *  floating point context.  The code included for this macro assumes
904 *  that this is a CPU in which a "initial" FP context was saved into
905 *  _CPU_Null_fp_context and it simply copies it to the destination
906 *  context passed to it.
907 *
908 *  Other models include (1) not doing anything, and (2) putting
909 *  a "null FP status word" in the correct place in the FP context.
910 */
911
912#if ( CPU_HARDWARE_FP == TRUE )
913#define _CPU_Context_Initialize_fp( _destination ) \
914  { \
915   *(*(_destination)) = _CPU_Null_fp_context; \
916  }
917#endif
918
919/* end of Context handler macros */
920
921/* Fatal Error manager macros */
922
923/*
924 *  This routine copies _error into a known place -- typically a stack
925 *  location or a register, optionally disables interrupts, and
926 *  halts/stops the CPU.
927 */
928
929#define _CPU_Fatal_halt( _error ) \
930  do { \
931    unsigned int _level; \
932    _CPU_ISR_Disable(_level); \
933    loop: goto loop; \
934  } while (0)
935
936
937extern void mips_break( int error );
938
939/* Bitfield handler macros */
940
941/*
942 *  This routine sets _output to the bit number of the first bit
943 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
944 *  This type may be either 16 or 32 bits wide although only the 16
945 *  least significant bits will be used.
946 *
947 *  There are a number of variables in using a "find first bit" type
948 *  instruction.
949 *
950 *    (1) What happens when run on a value of zero?
951 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
952 *    (3) The numbering may be zero or one based.
953 *    (4) The "find first bit" instruction may search from MSB or LSB.
954 *
955 *  RTEMS guarantees that (1) will never happen so it is not a concern.
956 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
957 *  _CPU_Priority_bits_index().  These three form a set of routines
958 *  which must logically operate together.  Bits in the _value are
959 *  set and cleared based on masks built by _CPU_Priority_mask().
960 *  The basic major and minor values calculated by _Priority_Major()
961 *  and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
962 *  to properly range between the values returned by the "find first bit"
963 *  instruction.  This makes it possible for _Priority_Get_highest() to
964 *  calculate the major and directly index into the minor table.
965 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
966 *  is the first bit found.
967 *
968 *  This entire "find first bit" and mapping process depends heavily
969 *  on the manner in which a priority is broken into a major and minor
970 *  components with the major being the 4 MSB of a priority and minor
971 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
972 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
973 *  to the lowest priority.
974 *
975 *  If your CPU does not have a "find first bit" instruction, then
976 *  there are ways to make do without it.  Here are a handful of ways
977 *  to implement this in software:
978 *
979 *    - a series of 16 bit test instructions
980 *    - a "binary search using if's"
981 *    - _number = 0
982 *      if _value > 0x00ff
983 *        _value >>=8
984 *        _number = 8;
985 *
986 *      if _value > 0x0000f
987 *        _value >=8
988 *        _number += 4
989 *
990 *      _number += bit_set_table[ _value ]
991 *
992 *    where bit_set_table[ 16 ] has values which indicate the first
993 *      bit set
994 */
995
996#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
997#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
998
999#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1000
1001#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
1002  { \
1003    (_output) = 0;   /* do something to prevent warnings */ \
1004  }
1005
1006#endif
1007
1008/* end of Bitfield handler macros */
1009
1010/*
1011 *  This routine builds the mask which corresponds to the bit fields
1012 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
1013 *  for that routine.
1014 */
1015
1016#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1017
1018#define _CPU_Priority_Mask( _bit_number ) \
1019  ( 1 << (_bit_number) )
1020
1021#endif
1022
1023/*
1024 *  This routine translates the bit numbers returned by
1025 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
1026 *  a major or minor component of a priority.  See the discussion
1027 *  for that routine.
1028 */
1029
1030#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1031
1032#define _CPU_Priority_bits_index( _priority ) \
1033  (_priority)
1034
1035#endif
1036
1037/* end of Priority handler macros */
1038
1039/* functions */
1040
1041/*
1042 *  _CPU_Initialize
1043 *
1044 *  This routine performs CPU dependent initialization.
1045 */
1046
1047void _CPU_Initialize(void);
1048
1049/*
1050 *  _CPU_ISR_install_raw_handler
1051 *
1052 *  This routine installs a "raw" interrupt handler directly into the
1053 *  processor's vector table.
1054 */
1055
1056void _CPU_ISR_install_raw_handler(
1057  uint32_t    vector,
1058  proc_ptr    new_handler,
1059  proc_ptr   *old_handler
1060);
1061
1062/*
1063 *  _CPU_ISR_install_vector
1064 *
1065 *  This routine installs an interrupt vector.
1066 */
1067
1068void _CPU_ISR_install_vector(
1069  uint32_t    vector,
1070  proc_ptr    new_handler,
1071  proc_ptr   *old_handler
1072);
1073
1074/*
1075 *  _CPU_Install_interrupt_stack
1076 *
1077 *  This routine installs the hardware interrupt stack pointer.
1078 *
1079 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
1080 *         is TRUE.
1081 */
1082
1083void _CPU_Install_interrupt_stack( void );
1084
1085/*
1086 *  _CPU_Internal_threads_Idle_thread_body
1087 *
1088 *  This routine is the CPU dependent IDLE thread body.
1089 *
1090 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
1091 *         is TRUE.
1092 */
1093
1094void *_CPU_Thread_Idle_body( uintptr_t ignored );
1095
1096/*
1097 *  _CPU_Context_switch
1098 *
1099 *  This routine switches from the run context to the heir context.
1100 */
1101
1102void _CPU_Context_switch(
1103  Context_Control  *run,
1104  Context_Control  *heir
1105);
1106
1107/*
1108 *  _CPU_Context_restore
1109 *
1110 *  This routine is generally used only to restart self in an
1111 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
1112 *
1113 *  NOTE: May be unnecessary to reload some registers.
1114 */
1115
1116void _CPU_Context_restore(
1117  Context_Control *new_context
1118);
1119
1120/*
1121 *  _CPU_Context_save_fp
1122 *
1123 *  This routine saves the floating point context passed to it.
1124 */
1125
1126void _CPU_Context_save_fp(
1127  Context_Control_fp **fp_context_ptr
1128);
1129
1130/*
1131 *  _CPU_Context_restore_fp
1132 *
1133 *  This routine restores the floating point context passed to it.
1134 */
1135
1136void _CPU_Context_restore_fp(
1137  Context_Control_fp **fp_context_ptr
1138);
1139
1140/*  The following routine swaps the endian format of an unsigned int.
1141 *  It must be static because it is referenced indirectly.
1142 *
1143 *  This version will work on any processor, but if there is a better
1144 *  way for your CPU PLEASE use it.  The most common way to do this is to:
1145 *
1146 *     swap least significant two bytes with 16-bit rotate
1147 *     swap upper and lower 16-bits
1148 *     swap most significant two bytes with 16-bit rotate
1149 *
1150 *  Some CPUs have special instructions which swap a 32-bit quantity in
1151 *  a single instruction (e.g. i486).  It is probably best to avoid
1152 *  an "endian swapping control bit" in the CPU.  One good reason is
1153 *  that interrupts would probably have to be disabled to ensure that
1154 *  an interrupt does not try to access the same "chunk" with the wrong
1155 *  endian.  Another good reason is that on some CPUs, the endian bit
1156 *  endianness for ALL fetches -- both code and data -- so the code
1157 *  will be fetched incorrectly.
1158 */
1159
1160static inline uint32_t CPU_swap_u32(
1161  uint32_t value
1162)
1163{
1164  uint32_t   byte1, byte2, byte3, byte4, swapped;
1165
1166  byte4 = (value >> 24) & 0xff;
1167  byte3 = (value >> 16) & 0xff;
1168  byte2 = (value >> 8)  & 0xff;
1169  byte1 =  value        & 0xff;
1170
1171  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1172  return( swapped );
1173}
1174
1175#define CPU_swap_u16( value ) \
1176  (((value&0xff) << 8) | ((value >> 8)&0xff))
1177
1178
1179#endif
1180
1181
1182
1183#ifdef __cplusplus
1184}
1185#endif
1186
1187#endif
Note: See TracBrowser for help on using the repository browser.