source: rtems/cpukit/score/cpu/mips/rtems/score/cpu.h @ 18e29faf

5
Last change on this file since 18e29faf was 18e29faf, checked in by Sebastian Huber <sebastian.huber@…>, on 06/08/16 at 08:10:40

score: Delete CPU_USE_GENERIC_BITFIELD_DATA

Rename log2table into _Bitfield_Leading_zeros since it acually returns
the count of leading zeros of an 8-bit integer. The value for zero is a
bit odd. Provide it unconditionally.

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