source: rtems/cpukit/score/cpu/v850/rtems/score/cpu.h @ 143696a

5
Last change on this file since 143696a was 143696a, checked in by Sebastian Huber <sebastian.huber@…>, on 10/16/15 at 06:15:03

basedefs.h: Add and use RTEMS_NO_RETURN

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