source: rtems/cpukit/score/cpu/microblaze/rtems/score/cpu.h @ 0f62af0e

Last change on this file since 0f62af0e was 0f62af0e, checked in by Hesham ALMatary <heshamelmatary@…>, on 09/30/21 at 21:33:48

bsps: Add MicroBlaze? FPGA BSP

  • Property mode set to 100644
File size: 42.0 KB
Line 
1/*
2 *  Copyright (c) 2015, Hesham Almatary
3 *  COPYRIGHT (c) 1989-2008.
4 *  On-Line Applications Research Corporation (OAR).
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *   notice, this list of conditions and the following disclaimer in the
13 *   documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/**
29 * @file rtems/score/cpu.h
30 */
31
32/*
33 *  This include file contains information pertaining to the XXX
34 *  processor.
35 *
36 *  @note This file is part of a porting template that is intended
37 *  to be used as the starting point when porting RTEMS to a new
38 *  CPU family.  The following needs to be done when using this as
39 *  the starting point for a new port:
40 *
41 *  + Anywhere there is an XXX, it should be replaced
42 *    with information about the CPU family being ported to.
43 *
44 *  + At the end of each comment section, there is a heading which
45 *    says "Port Specific Information:".  When porting to RTEMS,
46 *    add CPU family specific information in this section
47 */
48
49#ifndef _RTEMS_SCORE_CPU_H
50#define _RTEMS_SCORE_CPU_H
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56#include <rtems/score/types.h>
57#include <rtems/score/microblaze.h>
58
59/* conditional compilation parameters */
60
61/**
62 *  Should the calls to @ref _Thread_Enable_dispatch be inlined?
63 *
64 *  If TRUE, then they are inlined.
65 *  If FALSE, then a subroutine call is made.
66 *
67 *  This conditional 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 *
71 *  @note In general, the @ref _Thread_Dispatch_disable_level will
72 *  only be 0 or 1 unless you are in an interrupt handler and that
73 *  interrupt handler invokes the executive.]  When not inlined
74 *  something calls @ref _Thread_Enable_dispatch which in turns calls
75 *  @ref _Thread_Dispatch.  If the enable dispatch is inlined, then
76 *  one subroutine call is avoided entirely.
77 *
78 *  Port Specific Information:
79 *
80 *  XXX document implementation including references if appropriate
81 */
82#define CPU_INLINE_ENABLE_DISPATCH       FALSE
83
84/**
85 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
86 *  be unrolled one time?  In unrolled each iteration of the loop examines
87 *  two "nodes" on the chain being searched.  Otherwise, only one node
88 *  is examined per iteration.
89 *
90 *  If TRUE, then the loops are unrolled.
91 *  If FALSE, then the loops are not unrolled.
92 *
93 *  The primary factor in making this decision is the cost of disabling
94 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
95 *  body of the loop.  On some CPUs, the flash is more expensive than
96 *  one iteration of the loop body.  In this case, it might be desirable
97 *  to unroll the loop.  It is important to note that on some CPUs, this
98 *  code is the longest interrupt disable period in RTEMS.  So it is
99 *  necessary to strike a balance when setting this parameter.
100 *
101 *  Port Specific Information:
102 *
103 *  XXX document implementation including references if appropriate
104 */
105#define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
106
107/**
108 *  Does RTEMS manage a dedicated interrupt stack in software?
109 *
110 *  If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
111 *  If FALSE, nothing is done.
112 *
113 *  If the CPU supports a dedicated interrupt stack in hardware,
114 *  then it is generally the responsibility of the BSP to allocate it
115 *  and set it up.
116 *
117 *  If the CPU does not support a dedicated interrupt stack, then
118 *  the porter has two options: (1) execute interrupts on the
119 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
120 *  interrupt stack.
121 *
122 *  If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
123 *
124 *  Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
125 *  @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
126 *  possible that both are FALSE for a particular CPU.  Although it
127 *  is unclear what that would imply about the interrupt processing
128 *  procedure on that CPU.
129 *
130 *  Port Specific Information:
131 *
132 *  XXX document implementation including references if appropriate
133 */
134#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
135
136/**
137 *  Does the CPU follow the simple vectored interrupt model?
138 *
139 *  If TRUE, then RTEMS allocates the vector table it internally manages.
140 *  If FALSE, then the BSP is assumed to allocate and manage the vector
141 *  table
142 *
143 *  Port Specific Information:
144 *
145 *  XXX document implementation including references if appropriate
146 */
147#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
148
149/**
150 *  Does this CPU have hardware support for a dedicated interrupt stack?
151 *
152 *  If TRUE, then it must be installed during initialization.
153 *  If FALSE, then no installation is performed.
154 *
155 *  If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
156 *
157 *  Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
158 *  @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
159 *  possible that both are FALSE for a particular CPU.  Although it
160 *  is unclear what that would imply about the interrupt processing
161 *  procedure on that CPU.
162 *
163 *  Port Specific Information:
164 *
165 *  XXX document implementation including references if appropriate
166 */
167#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
168
169/**
170 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
171 *
172 *  If TRUE, then the memory is allocated during initialization.
173 *  If FALSE, then the memory is allocated during initialization.
174 *
175 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
176 *
177 *  Port Specific Information:
178 *
179 *  XXX document implementation including references if appropriate
180 */
181#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
182
183/**
184 *  Does the RTEMS invoke the user's ISR with the vector number and
185 *  a pointer to the saved interrupt frame (1) or just the vector
186 *  number (0)?
187 *
188 *  Port Specific Information:
189 *
190 *  XXX document implementation including references if appropriate
191 */
192#define CPU_ISR_PASSES_FRAME_POINTER 0
193
194/**
195 *  @def CPU_HARDWARE_FP
196 *
197 *  Does the CPU have hardware floating point?
198 *
199 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
200 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
201 *
202 *  If there is a FP coprocessor such as the i387 or mc68881, then
203 *  the answer is TRUE.
204 *
205 *  The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
206 *  It indicates whether or not this CPU model has FP support.  For
207 *  example, it would be possible to have an i386_nofp CPU model
208 *  which set this to false to indicate that you have an i386 without
209 *  an i387 and wish to leave floating point support out of RTEMS.
210 */
211
212/**
213 *  @def CPU_SOFTWARE_FP
214 *
215 *  Does the CPU have no hardware floating point and GCC provides a
216 *  software floating point implementation which must be context
217 *  switched?
218 *
219 *  This feature conditional is used to indicate whether or not there
220 *  is software implemented floating point that must be context
221 *  switched.  The determination of whether or not this applies
222 *  is very tool specific and the state saved/restored is also
223 *  compiler specific.
224 *
225 *  Port Specific Information:
226 *
227 *  XXX document implementation including references if appropriate
228 */
229#if ( NO_CPU_HAS_FPU == 1 )
230#define CPU_HARDWARE_FP     TRUE
231#else
232#define CPU_HARDWARE_FP     FALSE
233#endif
234#define CPU_SOFTWARE_FP     FALSE
235
236/**
237 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
238 *
239 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
240 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
241 *
242 *  So far, the only CPUs in which this option has been used are the
243 *  HP PA-RISC and PowerPC.  On the PA-RISC, The HP C compiler and
244 *  gcc both implicitly used the floating point registers to perform
245 *  integer multiplies.  Similarly, the PowerPC port of gcc has been
246 *  seen to allocate floating point local variables and touch the FPU
247 *  even when the flow through a subroutine (like vfprintf()) might
248 *  not use floating point formats.
249 *
250 *  If a function which you would not think utilize the FP unit DOES,
251 *  then one can not easily predict which tasks will use the FP hardware.
252 *  In this case, this option should be TRUE.
253 *
254 *  If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
255 *
256 *  Port Specific Information:
257 *
258 *  XXX document implementation including references if appropriate
259 */
260#define CPU_ALL_TASKS_ARE_FP     TRUE
261
262/**
263 *  Should the IDLE task have a floating point context?
264 *
265 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
266 *  and it has a floating point context which is switched in and out.
267 *  If FALSE, then the IDLE task does not have a floating point context.
268 *
269 *  Setting this to TRUE negatively impacts the time required to preempt
270 *  the IDLE task from an interrupt because the floating point context
271 *  must be saved as part of the preemption.
272 *
273 *  Port Specific Information:
274 *
275 *  XXX document implementation including references if appropriate
276 */
277#define CPU_IDLE_TASK_IS_FP      FALSE
278
279/**
280 *  Should the saving of the floating point registers be deferred
281 *  until a context switch is made to another different floating point
282 *  task?
283 *
284 *  If TRUE, then the floating point context will not be stored until
285 *  necessary.  It will remain in the floating point registers and not
286 *  disturned until another floating point task is switched to.
287 *
288 *  If FALSE, then the floating point context is saved when a floating
289 *  point task is switched out and restored when the next floating point
290 *  task is restored.  The state of the floating point registers between
291 *  those two operations is not specified.
292 *
293 *  If the floating point context does NOT have to be saved as part of
294 *  interrupt dispatching, then it should be safe to set this to TRUE.
295 *
296 *  Setting this flag to TRUE results in using a different algorithm
297 *  for deciding when to save and restore the floating point context.
298 *  The deferred FP switch algorithm minimizes the number of times
299 *  the FP context is saved and restored.  The FP context is not saved
300 *  until a context switch is made to another, different FP task.
301 *  Thus in a system with only one FP task, the FP context will never
302 *  be saved or restored.
303 *
304 *  Port Specific Information:
305 *
306 *  XXX document implementation including references if appropriate
307 */
308#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
309
310/**
311 *  Does this port provide a CPU dependent IDLE task implementation?
312 *
313 *  If TRUE, then the routine @ref _CPU_Thread_Idle_body
314 *  must be provided and is the default IDLE thread body instead of
315 *  @ref _CPU_Thread_Idle_body.
316 *
317 *  If FALSE, then use the generic IDLE thread body if the BSP does
318 *  not provide one.
319 *
320 *  This is intended to allow for supporting processors which have
321 *  a low power or idle mode.  When the IDLE thread is executed, then
322 *  the CPU can be powered down.
323 *
324 *  The order of precedence for selecting the IDLE thread body is:
325 *
326 *    -#  BSP provided
327 *    -#  CPU dependent (if provided)
328 *    -#  generic (if no BSP and no CPU dependent)
329 *
330 *  Port Specific Information:
331 *
332 *  XXX document implementation including references if appropriate
333 */
334#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
335
336/**
337 *  Does the stack grow up (toward higher addresses) or down
338 *  (toward lower addresses)?
339 *
340 *  If TRUE, then the grows upward.
341 *  If FALSE, then the grows toward smaller addresses.
342 *
343 *  Port Specific Information:
344 *
345 *  XXX document implementation including references if appropriate
346 */
347#define CPU_STACK_GROWS_UP               TRUE
348
349/**
350 *  The following is the variable attribute used to force alignment
351 *  of critical RTEMS structures.  On some processors it may make
352 *  sense to have these aligned on tighter boundaries than
353 *  the minimum requirements of the compiler in order to have as
354 *  much of the critical data area as possible in a cache line.
355 *
356 *  The placement of this macro in the declaration of the variables
357 *  is based on the syntactically requirements of the GNU C
358 *  "__attribute__" extension.  For example with GNU C, use
359 *  the following to force a structures to a 32 byte boundary.
360 *
361 *      __attribute__ ((aligned (32)))
362 *
363 *  @note Currently only the Priority Bit Map table uses this feature.
364 *        To benefit from using this, the data must be heavily
365 *        used so it will stay in the cache and used frequently enough
366 *        in the executive to justify turning this on.
367 *
368 *  Port Specific Information:
369 *
370 *  XXX document implementation including references if appropriate
371 */
372#define CPU_STRUCTURE_ALIGNMENT
373
374/**
375 *  @defgroup CPUEndian Processor Dependent Endianness Support
376 *
377 *  This group assists in issues related to processor endianness.
378 */
379
380/**
381 *  @ingroup CPUEndian
382 *  Define what is required to specify how the network to host conversion
383 *  routines are handled.
384 *
385 *  @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
386 *  same values.
387 *
388 *  @see CPU_LITTLE_ENDIAN
389 *
390 *  Port Specific Information:
391 *
392 *  XXX document implementation including references if appropriate
393 */
394#define CPU_BIG_ENDIAN                           TRUE
395
396/**
397 *  @ingroup CPUEndian
398 *  Define what is required to specify how the network to host conversion
399 *  routines are handled.
400 *
401 *  @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
402 *  same values.
403 *
404 *  @see CPU_BIG_ENDIAN
405 *
406 *  Port Specific Information:
407 *
408 *  XXX document implementation including references if appropriate
409 */
410#define CPU_LITTLE_ENDIAN                        FALSE
411
412/**
413 *  @ingroup CPUInterrupt
414 *  The following defines the number of bits actually used in the
415 *  interrupt field of the task mode.  How those bits map to the
416 *  CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
417 *
418 *  Port Specific Information:
419 *
420 *  XXX document implementation including references if appropriate
421 */
422#define CPU_MODES_INTERRUPT_MASK   0x00000001
423
424/*
425 *  Processor defined structures required for cpukit/score.
426 *
427 *  Port Specific Information:
428 *
429 *  XXX document implementation including references if appropriate
430 */
431
432/* may need to put some structures here.  */
433
434/**
435 * @defgroup CPUContext Processor Dependent Context Management
436 *
437 *  From the highest level viewpoint, there are 2 types of context to save.
438 *
439 *     -# Interrupt registers to save
440 *     -# Task level registers to save
441 *
442 *  Since RTEMS handles integer and floating point contexts separately, this
443 *  means we have the following 3 context items:
444 *
445 *     -# task level context stuff::  Context_Control
446 *     -# floating point task stuff:: Context_Control_fp
447 *     -# special interrupt level context :: CPU_Interrupt_frame
448 *
449 *  On some processors, it is cost-effective to save only the callee
450 *  preserved registers during a task context switch.  This means
451 *  that the ISR code needs to save those registers which do not
452 *  persist across function calls.  It is not mandatory to make this
453 *  distinctions between the caller/callee saves registers for the
454 *  purpose of minimizing context saved during task switch and on interrupts.
455 *  If the cost of saving extra registers is minimal, simplicity is the
456 *  choice.  Save the same context on interrupt entry as for tasks in
457 *  this case.
458 *
459 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
460 *  care should be used in designing the context area.
461 *
462 *  On some CPUs with hardware floating point support, the Context_Control_fp
463 *  structure will not be used or it simply consist of an array of a
464 *  fixed number of bytes.   This is done when the floating point context
465 *  is dumped by a "FP save context" type instruction and the format
466 *  is not really defined by the CPU.  In this case, there is no need
467 *  to figure out the exact format -- only the size.  Of course, although
468 *  this is enough information for RTEMS, it is probably not enough for
469 *  a debugger such as gdb.  But that is another problem.
470 *
471 *  Port Specific Information:
472 *
473 *  XXX document implementation including references if appropriate
474 */
475
476/**
477 *  @ingroup CPUContext Management
478 *  This defines the minimal set of integer and processor state registers
479 *  that must be saved during a voluntary context switch from one thread
480 *  to another.
481 */
482typedef struct {
483    uint32_t r[32];
484} Context_Control;
485
486/**
487 *  @ingroup CPUContext Management
488 *
489 *  This macro returns the stack pointer associated with @a _context.
490 *
491 *  @param[in] _context is the thread context area to access
492 *
493 *  @return This method returns the stack pointer.
494 */
495#define _CPU_Context_Get_SP( _context ) \
496  (_context)->r[0]
497
498/**
499 *  @ingroup CPUContext Management
500 *  This defines the complete set of floating point registers that must
501 *  be saved during any context switch from one thread to another.
502 */
503typedef struct {
504    /** FPU registers are listed here */
505    double      some_float_register;
506} Context_Control_fp;
507
508/**
509 *  @ingroup CPUContext Management
510 *  This defines the set of integer and processor state registers that must
511 *  be saved during an interrupt.  This set does not include any which are
512 *  in @ref Context_Control.
513 */
514typedef struct {
515    /** This field is a hint that a port will have a number of integer
516     *  registers that need to be saved when an interrupt occurs or
517     *  when a context switch occurs at the end of an ISR.
518     */
519    uint32_t   special_interrupt_register;
520} CPU_Interrupt_frame;
521
522/**
523 *  This variable is optional.  It is used on CPUs on which it is difficult
524 *  to generate an "uninitialized" FP context.  It is filled in by
525 *  @ref _CPU_Initialize and copied into the task's FP context area during
526 *  @ref _CPU_Context_Initialize.
527 *
528 *  Port Specific Information:
529 *
530 *  XXX document implementation including references if appropriate
531 */
532SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
533
534/**
535 *  @defgroup CPUInterrupt Processor Dependent Interrupt Management
536 *
537 *  On some CPUs, RTEMS supports a software managed interrupt stack.
538 *  This stack is allocated by the Interrupt Manager and the switch
539 *  is performed in @ref _ISR_Handler.  These variables contain pointers
540 *  to the lowest and highest addresses in the chunk of memory allocated
541 *  for the interrupt stack.  Since it is unknown whether the stack
542 *  grows up or down (in general), this give the CPU dependent
543 *  code the option of picking the version it wants to use.
544 *
545 *  @note These two variables are required if the macro
546 *        @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
547 *
548 *  Port Specific Information:
549 *
550 *  XXX document implementation including references if appropriate
551 */
552
553/*
554 *  Nothing prevents the porter from declaring more CPU specific variables.
555 *
556 *  Port Specific Information:
557 *
558 *  XXX document implementation including references if appropriate
559 */
560
561/* XXX: if needed, put more variables here */
562
563/**
564 *  @ingroup CPUContext
565 *  The size of the floating point context area.  On some CPUs this
566 *  will not be a "sizeof" because the format of the floating point
567 *  area is not defined -- only the size is.  This is usually on
568 *  CPUs with a "floating point save context" instruction.
569 *
570 *  Port Specific Information:
571 *
572 *  XXX document implementation including references if appropriate
573 */
574#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
575
576/**
577 *  Amount of extra stack (above minimum stack size) required by
578 *  MPCI receive server thread.  Remember that in a multiprocessor
579 *  system this thread must exist and be able to process all directives.
580 *
581 *  Port Specific Information:
582 *
583 *  XXX document implementation including references if appropriate
584 */
585#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
586
587/**
588 *  @ingroup CPUInterrupt
589 *  This defines the number of entries in the @ref _ISR_Vector_table managed
590 *  by RTEMS.
591 *
592 *  Port Specific Information:
593 *
594 *  XXX document implementation including references if appropriate
595 */
596#define CPU_INTERRUPT_NUMBER_OF_VECTORS      32
597
598/**
599 *  @ingroup CPUInterrupt
600 *  This defines the highest interrupt vector number for this port.
601 */
602#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
603
604/**
605 *  @ingroup CPUInterrupt
606 *  This is defined if the port has a special way to report the ISR nesting
607 *  level.  Most ports maintain the variable @a _ISR_Nest_level.
608 */
609#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
610
611/**
612 *  @ingroup CPUContext
613 *  Should be large enough to run all RTEMS tests.  This ensures
614 *  that a "reasonable" small application should not have any problems.
615 *
616 *  Port Specific Information:
617 *
618 *  XXX document implementation including references if appropriate
619 */
620#define CPU_STACK_MINIMUM_SIZE          (1024*4)
621
622/**
623 *  CPU's worst alignment requirement for data types on a byte boundary.  This
624 *  alignment does not take into account the requirements for the stack.
625 *
626 *  Port Specific Information:
627 *
628 *  XXX document implementation including references if appropriate
629 */
630#define CPU_ALIGNMENT              8
631
632/**
633 *  This number corresponds to the byte alignment requirement for the
634 *  heap handler.  This alignment requirement may be stricter than that
635 *  for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
636 *  common for the heap to follow the same alignment requirement as
637 *  @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
638 *  the heap, then this should be set to @ref CPU_ALIGNMENT.
639 *
640 *  @note  This does not have to be a power of 2 although it should be
641 *         a multiple of 2 greater than or equal to 2.  The requirement
642 *         to be a multiple of 2 is because the heap uses the least
643 *         significant field of the front and back flags to indicate
644 *         that a block is in use or free.  So you do not want any odd
645 *         length blocks really putting length data in that bit.
646 *
647 *         On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
648 *         have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
649 *         elements allocated from the heap meet all restrictions.
650 *
651 *  Port Specific Information:
652 *
653 *  XXX document implementation including references if appropriate
654 */
655#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
656
657/**
658 *  This number corresponds to the byte alignment requirement for memory
659 *  buffers allocated by the partition manager.  This alignment requirement
660 *  may be stricter than that for the data types alignment specified by
661 *  @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
662 *  alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
663 *  strict enough for the partition, then this should be set to
664 *  @ref CPU_ALIGNMENT.
665 *
666 *  @note  This does not have to be a power of 2.  It does have to
667 *         be greater or equal to than @ref CPU_ALIGNMENT.
668 *
669 *  Port Specific Information:
670 *
671 *  XXX document implementation including references if appropriate
672 */
673#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
674
675/**
676 *  This number corresponds to the byte alignment requirement for the
677 *  stack.  This alignment requirement may be stricter than that for the
678 *  data types alignment specified by @ref CPU_ALIGNMENT.  If the
679 *  @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
680 *  set to 0.
681 *
682 *  @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
683 *
684 *  Port Specific Information:
685 *
686 *  XXX document implementation including references if appropriate
687 */
688#define CPU_STACK_ALIGNMENT        0
689
690/*
691 *  ISR handler macros
692 */
693
694/**
695 *  @ingroup CPUInterrupt
696 *  Support routine to initialize the RTEMS vector table after it is allocated.
697 *
698 *  Port Specific Information:
699 *
700 *  XXX document implementation including references if appropriate
701 */
702#define _CPU_Initialize_vectors()
703
704/**
705 *  @ingroup CPUInterrupt
706 *  Disable all interrupts for an RTEMS critical section.  The previous
707 *  level is returned in @a _isr_cookie.
708 *
709 *  @param[out] _isr_cookie will contain the previous level cookie
710 *
711 *  Port Specific Information:
712 *
713 *  XXX document implementation including references if appropriate
714 */
715#define _CPU_MSR_GET( _msr_value ) \
716  do { \
717    _msr_value = 0; \
718    __asm__ volatile ("mfs %0, rmsr" : "=&r" ((_msr_value)) : "0" ((_msr_value))); \
719  } while (0)
720
721#define _CPU_MSR_SET( _msr_value ) \
722{ __asm__ volatile ("mts rmsr, %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); }
723
724#define _CPU_ISR_Disable( _isr_cookie ) \
725  { \
726    unsigned int _new_msr;  \
727    _CPU_MSR_GET(_isr_cookie); \
728    _new_msr = _isr_cookie & ~0x02; \
729    _CPU_MSR_SET(_new_msr); \
730  }
731
732/**
733 *  @ingroup CPUInterrupt
734 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
735 *  This indicates the end of an RTEMS critical section.  The parameter
736 *  @a _isr_cookie is not modified.
737 *
738 *  @param[in] _isr_cookie contain the previous level cookie
739 *
740 *  Port Specific Information:
741 *
742 *  XXX document implementation including references if appropriate
743 */
744#define _CPU_ISR_Enable( _isr_cookie )  \
745  { \
746    _CPU_MSR_SET(_isr_cookie); \
747  }
748
749/**
750 *  @ingroup CPUInterrupt
751 *  This temporarily restores the interrupt to @a _isr_cookie before immediately
752 *  disabling them again.  This is used to divide long RTEMS critical
753 *  sections into two or more parts.  The parameter @a _isr_cookie is not
754 *  modified.
755 *
756 *  @param[in] _isr_cookie contain the previous level cookie
757 *
758 *  Port Specific Information:
759 *
760 *  XXX document implementation including references if appropriate
761 */
762#define _CPU_ISR_Flash( _isr_cookie ) \
763  { \
764    unsigned int _new_msr;  \
765    _CPU_MSR_SET(_isr_cookie); \
766    _new_msr = _isr_cookie & ~0x02; \
767    _CPU_MSR_SET(_new_msr); \
768  }
769
770/**
771 *  @ingroup CPUInterrupt
772 *
773 *  This routine and @ref _CPU_ISR_Get_level
774 *  Map the interrupt level in task mode onto the hardware that the CPU
775 *  actually provides.  Currently, interrupt levels which do not
776 *  map onto the CPU in a generic fashion are undefined.  Someday,
777 *  it would be nice if these were "mapped" by the application
778 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
779 *  8 - 255 would be available for bsp/application specific meaning.
780 *  This could be used to manage a programmable interrupt controller
781 *  via the rtems_task_mode directive.
782 *
783 *  Port Specific Information:
784 *
785 *  XXX document implementation including references if appropriate
786 */
787#define _CPU_ISR_Set_level( new_level ) \
788  { \
789  }
790
791/**
792 *  @ingroup CPUInterrupt
793 *  Return the current interrupt disable level for this task in
794 *  the format used by the interrupt level portion of the task mode.
795 *
796 *  @note This routine usually must be implemented as a subroutine.
797 *
798 *  Port Specific Information:
799 *
800 *  XXX document implementation including references if appropriate
801 */
802uint32_t   _CPU_ISR_Get_level( void );
803
804/* end of ISR handler macros */
805
806/**
807 * @brief Initializes the CPU context.
808 *
809 * The following steps are performed:
810 *  - setting a starting address
811 *  - preparing the stack
812 *  - preparing the stack and frame pointers
813 *  - setting the proper interrupt level in the context
814 *
815 * @param[in] context points to the context area
816 * @param[in] stack_area_begin is the low address of the allocated stack area
817 * @param[in] stack_area_size is the size of the stack area in bytes
818 * @param[in] new_level is the interrupt level for the task
819 * @param[in] entry_point is the task's entry point
820 * @param[in] is_fp is set to @c true if the task is a floating point task
821 * @param[in] tls_area is the thread-local storage (TLS) area
822 */
823void _CPU_Context_Initialize(
824  Context_Control *context,
825  void *stack_area_begin,
826  size_t stack_area_size,
827  uint32_t new_level,
828  void (*entry_point)( void ),
829  bool is_fp,
830  void *tls_area
831);
832
833/**
834 *  This routine is responsible for somehow restarting the currently
835 *  executing task.  If you are lucky, then all that is necessary
836 *  is restoring the context.  Otherwise, there will need to be
837 *  a special assembly routine which does something special in this
838 *  case.  For many ports, simply adding a label to the restore path
839 *  of @ref _CPU_Context_switch will work.  On other ports, it may be
840 *  possibly to load a few arguments and jump to the restore path. It will
841 *  not work if restarting self conflicts with the stack frame
842 *  assumptions of restoring a context.
843 *
844 *  Port Specific Information:
845 *
846 *  XXX document implementation including references if appropriate
847 */
848#define _CPU_Context_Restart_self( _the_context ) \
849   _CPU_Context_restore( (_the_context) );
850
851/**
852 *  @ingroup CPUContext
853 *  The purpose of this macro is to allow the initial pointer into
854 *  a floating point context area (used to save the floating point
855 *  context) to be at an arbitrary place in the floating point
856 *  context area.
857 *
858 *  This is necessary because some FP units are designed to have
859 *  their context saved as a stack which grows into lower addresses.
860 *  Other FP units can be saved by simply moving registers into offsets
861 *  from the base of the context area.  Finally some FP units provide
862 *  a "dump context" instruction which could fill in from high to low
863 *  or low to high based on the whim of the CPU designers.
864 *
865 *  @param[in] _base is the lowest physical address of the floating point
866 *         context area
867 *  @param[in] _offset is the offset into the floating point area
868 *
869 *  Port Specific Information:
870 *
871 *  XXX document implementation including references if appropriate
872 */
873#define _CPU_Context_Fp_start( _base, _offset ) \
874   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
875
876/**
877 *  This routine initializes the FP context area passed to it to.
878 *  There are a few standard ways in which to initialize the
879 *  floating point context.  The code included for this macro assumes
880 *  that this is a CPU in which a "initial" FP context was saved into
881 *  @a _CPU_Null_fp_context and it simply copies it to the destination
882 *  context passed to it.
883 *
884 *  Other floating point context save/restore models include:
885 *    -# not doing anything, and
886 *    -# putting a "null FP status word" in the correct place in the FP context.
887 *
888 *  @param[in] _destination is the floating point context area
889 *
890 *  Port Specific Information:
891 *
892 *  XXX document implementation including references if appropriate
893 */
894#define _CPU_Context_Initialize_fp( _destination ) \
895  { \
896   *(*(_destination)) = _CPU_Null_fp_context; \
897  }
898
899/* end of Context handler macros */
900
901/* Fatal Error manager macros */
902
903/**
904 *  This routine copies _error into a known place -- typically a stack
905 *  location or a register, optionally disables interrupts, and
906 *  halts/stops the CPU.
907 *
908 *  Port Specific Information:
909 *
910 *  XXX document implementation including references if appropriate
911 */
912#define _CPU_Fatal_halt(_source, _error ) \
913        printk("Fatal Error %d.%d Halted\n",_source, _error); \
914        for(;;)
915
916/* end of Fatal Error manager macros */
917
918/* Bitfield handler macros */
919
920/**
921 *  @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
922 *
923 *  This set of routines are used to implement fast searches for
924 *  the most important ready task.
925 */
926
927/**
928 *  @ingroup CPUBitfield
929 *  This definition is set to TRUE if the port uses the generic bitfield
930 *  manipulation implementation.
931 */
932#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
933
934/**
935 *  @ingroup CPUBitfield
936 *  This definition is set to TRUE if the port uses the data tables provided
937 *  by the generic bitfield manipulation implementation.
938 *  This can occur when actually using the generic bitfield manipulation
939 *  implementation or when implementing the same algorithm in assembly
940 *  language for improved performance.  It is unlikely that a port will use
941 *  the data if it has a bitfield scan instruction.
942 */
943#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
944
945/**
946 *  @ingroup CPUBitfield
947 *  This routine sets @a _output to the bit number of the first bit
948 *  set in @a _value.  @a _value is of CPU dependent type
949 *  @a Priority_bit_map_Control.  This type may be either 16 or 32 bits
950 *  wide although only the 16 least significant bits will be used.
951 *
952 *  There are a number of variables in using a "find first bit" type
953 *  instruction.
954 *
955 *    -# What happens when run on a value of zero?
956 *    -# Bits may be numbered from MSB to LSB or vice-versa.
957 *    -# The numbering may be zero or one based.
958 *    -# The "find first bit" instruction may search from MSB or LSB.
959 *
960 *  RTEMS guarantees that (1) will never happen so it is not a concern.
961 *  (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
962 *  @ref _CPU_Priority_bits_index.  These three form a set of routines
963 *  which must logically operate together.  Bits in the _value are
964 *  set and cleared based on masks built by @ref _CPU_Priority_Mask.
965 *  The basic major and minor values calculated by @ref _Priority_Major
966 *  and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
967 *  to properly range between the values returned by the "find first bit"
968 *  instruction.  This makes it possible for @ref _Priority_Get_highest to
969 *  calculate the major and directly index into the minor table.
970 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
971 *  is the first bit found.
972 *
973 *  This entire "find first bit" and mapping process depends heavily
974 *  on the manner in which a priority is broken into a major and minor
975 *  components with the major being the 4 MSB of a priority and minor
976 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
977 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
978 *  to the lowest priority.
979 *
980 *  If your CPU does not have a "find first bit" instruction, then
981 *  there are ways to make do without it.  Here are a handful of ways
982 *  to implement this in software:
983 *
984@verbatim
985      - a series of 16 bit test instructions
986      - a "binary search using if's"
987      - _number = 0
988        if _value > 0x00ff
989          _value >>=8
990          _number = 8;
991
992        if _value > 0x0000f
993          _value >=8
994          _number += 4
995
996        _number += bit_set_table[ _value ]
997@endverbatim
998
999 *    where bit_set_table[ 16 ] has values which indicate the first
1000 *      bit set
1001 *
1002 *  @param[in] _value is the value to be scanned
1003 *  @param[in] _output is the first bit set
1004 *
1005 *  Port Specific Information:
1006 *
1007 *  XXX document implementation including references if appropriate
1008 */
1009
1010#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1011#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
1012  { \
1013    (_output) = 0;   /* do something to prevent warnings */ \
1014  }
1015#endif
1016
1017/* end of Bitfield handler macros */
1018
1019/**
1020 *  This routine builds the mask which corresponds to the bit fields
1021 *  as searched by @ref _CPU_Bitfield_Find_first_bit.  See the discussion
1022 *  for that routine.
1023 *
1024 *  Port Specific Information:
1025 *
1026 *  XXX document implementation including references if appropriate
1027 */
1028#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1029
1030#define _CPU_Priority_Mask( _bit_number ) \
1031  ( 1 << (_bit_number) )
1032
1033#endif
1034
1035/**
1036 *  @ingroup CPUBitfield
1037 *  This routine translates the bit numbers returned by
1038 *  @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
1039 *  a major or minor component of a priority.  See the discussion
1040 *  for that routine.
1041 *
1042 *  @param[in] _priority is the major or minor number to translate
1043 *
1044 *  Port Specific Information:
1045 *
1046 *  XXX document implementation including references if appropriate
1047 */
1048#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1049
1050#define _CPU_Priority_bits_index( _priority ) \
1051  (_priority)
1052
1053#endif
1054
1055#define CPU_TIMESTAMP_USE_STRUCT_TIMESPEC FALSE
1056#define CPU_TIMESTAMP_USE_INT64 TRUE
1057#define CPU_TIMESTAMP_USE_INT64_INLINE FALSE
1058
1059typedef struct {
1060/* There is no CPU specific per-CPU state */
1061} CPU_Per_CPU_control;
1062
1063#define CPU_SIZEOF_POINTER 4
1064#define CPU_PER_CPU_CONTROL_SIZE 0
1065
1066typedef struct {
1067  uint32_t r[32];
1068} CPU_Exception_frame;
1069
1070/* end of Priority handler macros */
1071
1072/* functions */
1073
1074/**
1075 *  This routine performs CPU dependent initialization.
1076 *
1077 *  Port Specific Information:
1078 *
1079 *  XXX document implementation including references if appropriate
1080 */
1081void _CPU_Initialize(void);
1082
1083/**
1084 *  @ingroup CPUInterrupt
1085 *  This routine installs a "raw" interrupt handler directly into the
1086 *  processor's vector table.
1087 *
1088 *  @param[in] vector is the vector number
1089 *  @param[in] new_handler is the raw ISR handler to install
1090 *  @param[in] old_handler is the previously installed ISR Handler
1091 *
1092 *  Port Specific Information:
1093 *
1094 *  XXX document implementation including references if appropriate
1095 */
1096void _CPU_ISR_install_raw_handler(
1097  uint32_t    vector,
1098  proc_ptr    new_handler,
1099  proc_ptr   *old_handler
1100);
1101
1102/**
1103 *  @ingroup CPUInterrupt
1104 *  This routine installs an interrupt vector.
1105 *
1106 *  @param[in] vector is the vector number
1107 *  @param[in] new_handler is the RTEMS ISR handler to install
1108 *  @param[in] old_handler is the previously installed ISR Handler
1109 *
1110 *  Port Specific Information:
1111 *
1112 *  XXX document implementation including references if appropriate
1113 */
1114void _CPU_ISR_install_vector(
1115  uint32_t    vector,
1116  proc_ptr    new_handler,
1117  proc_ptr   *old_handler
1118);
1119
1120/**
1121 *  @ingroup CPUInterrupt
1122 *  This routine installs the hardware interrupt stack pointer.
1123 *
1124 *  @note  It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
1125 *         is TRUE.
1126 *
1127 *  Port Specific Information:
1128 *
1129 *  XXX document implementation including references if appropriate
1130 */
1131void _CPU_Install_interrupt_stack( void );
1132
1133/**
1134 *  This routine is the CPU dependent IDLE thread body.
1135 *
1136 *  @note  It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
1137 *         is TRUE.
1138 *
1139 *  Port Specific Information:
1140 *
1141 *  XXX document implementation including references if appropriate
1142 */
1143void *_CPU_Thread_Idle_body( uintptr_t ignored );
1144
1145/**
1146 *  @ingroup CPUContext
1147 *  This routine switches from the run context to the heir context.
1148 *
1149 *  @param[in] run points to the context of the currently executing task
1150 *  @param[in] heir points to the context of the heir task
1151 *
1152 *  Port Specific Information:
1153 *
1154 *  XXX document implementation including references if appropriate
1155 */
1156void _CPU_Context_switch(
1157  Context_Control  *run,
1158  Context_Control  *heir
1159);
1160
1161/**
1162 *  @ingroup CPUContext
1163 *  This routine is generally used only to restart self in an
1164 *  efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
1165 *
1166 *  @param[in] new_context points to the context to be restored.
1167 *
1168 *  @note May be unnecessary to reload some registers.
1169 *
1170 *  Port Specific Information:
1171 *
1172 *  XXX document implementation including references if appropriate
1173 */
1174void _CPU_Context_restore(
1175  Context_Control *new_context
1176) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
1177
1178/**
1179 *  @ingroup CPUContext
1180 *  This routine saves the floating point context passed to it.
1181 *
1182 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1183 *  point context area
1184 *
1185 *  @return on output @a *fp_context_ptr will contain the address that
1186 *  should be used with @ref _CPU_Context_restore_fp to restore this context.
1187 *
1188 *  Port Specific Information:
1189 *
1190 *  XXX document implementation including references if appropriate
1191 */
1192void _CPU_Context_save_fp(
1193  Context_Control_fp **fp_context_ptr
1194);
1195
1196/**
1197 *  @ingroup CPUContext
1198 *  This routine restores the floating point context passed to it.
1199 *
1200 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1201 *  point context area to restore
1202 *
1203 *  @return on output @a *fp_context_ptr will contain the address that
1204 *  should be used with @ref _CPU_Context_save_fp to save this context.
1205 *
1206 *  Port Specific Information:
1207 *
1208 *  XXX document implementation including references if appropriate
1209 */
1210void _CPU_Context_restore_fp(
1211  Context_Control_fp **fp_context_ptr
1212);
1213
1214/**
1215 *  @ingroup CPUEndian
1216 *  The following routine swaps the endian format of an unsigned int.
1217 *  It must be static because it is referenced indirectly.
1218 *
1219 *  This version will work on any processor, but if there is a better
1220 *  way for your CPU PLEASE use it.  The most common way to do this is to:
1221 *
1222 *     swap least significant two bytes with 16-bit rotate
1223 *     swap upper and lower 16-bits
1224 *     swap most significant two bytes with 16-bit rotate
1225 *
1226 *  Some CPUs have special instructions which swap a 32-bit quantity in
1227 *  a single instruction (e.g. i486).  It is probably best to avoid
1228 *  an "endian swapping control bit" in the CPU.  One good reason is
1229 *  that interrupts would probably have to be disabled to ensure that
1230 *  an interrupt does not try to access the same "chunk" with the wrong
1231 *  endian.  Another good reason is that on some CPUs, the endian bit
1232 *  endianness for ALL fetches -- both code and data -- so the code
1233 *  will be fetched incorrectly.
1234 *
1235 *  @param[in] value is the value to be swapped
1236 *  @return the value after being endian swapped
1237 *
1238 *  Port Specific Information:
1239 *
1240 *  XXX document implementation including references if appropriate
1241 */
1242static inline uint32_t CPU_swap_u32(
1243  uint32_t value
1244)
1245{
1246  uint32_t byte1, byte2, byte3, byte4, swapped;
1247
1248  byte4 = (value >> 24) & 0xff;
1249  byte3 = (value >> 16) & 0xff;
1250  byte2 = (value >> 8)  & 0xff;
1251  byte1 =  value        & 0xff;
1252
1253  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1254  return swapped;
1255}
1256
1257/**
1258 *  @ingroup CPUEndian
1259 *  This routine swaps a 16 bir quantity.
1260 *
1261 *  @param[in] value is the value to be swapped
1262 *  @return the value after being endian swapped
1263 */
1264#define CPU_swap_u16( value ) \
1265  (((value&0xff) << 8) | ((value >> 8)&0xff))
1266
1267typedef uint32_t CPU_Counter_ticks;
1268
1269CPU_Counter_ticks _CPU_Counter_read( void );
1270
1271CPU_Counter_ticks _CPU_Counter_difference(
1272  CPU_Counter_ticks second,
1273  CPU_Counter_ticks first
1274);
1275
1276#ifdef __cplusplus
1277}
1278#endif
1279
1280#endif
Note: See TracBrowser for help on using the repository browser.