source: rtems/cpukit/score/cpu/v850/rtems/score/cpu.h @ a8865f8

5
Last change on this file since a8865f8 was a8865f8, checked in by Sebastian Huber <sebastian.huber@…>, on 01/25/16 at 09:20:28

score: Introduce CPU_CACHE_LINE_BYTES

Add CPU_CACHE_LINE_BYTES for the maximum cache line size in bytes. The
actual processor may use no cache or a smaller cache line size.

  • Property mode set to 100644
File size: 37.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/* FIXME: Is this the right value? */
293#define CPU_CACHE_LINE_BYTES 32
294
295#define CPU_STRUCTURE_ALIGNMENT
296
297/**
298 * @defgroup CPUEndian Processor Dependent Endianness Support
299 *
300 * This group assists in issues related to processor endianness.
301 *
302 */
303/**@{**/
304
305/**
306 * Define what is required to specify how the network to host conversion
307 * routines are handled.
308 *
309 * @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
310 * same values.
311 *
312 * @see CPU_LITTLE_ENDIAN
313 *
314 * Port Specific Information:
315 *
316 * The v850 is little endian.
317 */
318#define CPU_BIG_ENDIAN  FALSE
319
320/**
321 * Define what is required to specify how the network to host conversion
322 * routines are handled.
323 *
324 * @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
325 * same values.
326 *
327 * @see CPU_BIG_ENDIAN
328 *
329 * Port Specific Information:
330 *
331 * The v850 is little endian.
332 */
333#define CPU_LITTLE_ENDIAN TRUE
334
335/** @} */
336
337/**
338 * @ingroup CPUInterrupt
339 * The following defines the number of bits actually used in the
340 * interrupt field of the task mode.  How those bits map to the
341 * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
342 *
343 * Port Specific Information:
344 *
345 * The v850 only has a single bit in the CPU for interrupt disable/enable.
346 */
347#define CPU_MODES_INTERRUPT_MASK   0x00000001
348
349#define CPU_PER_CPU_CONTROL_SIZE 0
350
351typedef struct {
352  /* There is no CPU specific per-CPU state */
353} CPU_Per_CPU_control;
354
355/**
356 * @defgroup CPUContext Processor Dependent Context Management
357 *
358 * From the highest level viewpoint, there are 2 types of context to save.
359 *
360 *    -# Interrupt registers to save
361 *    -# Task level registers to save
362 *
363 * Since RTEMS handles integer and floating point contexts separately, this
364 * means we have the following 3 context items:
365 *
366 *    -# task level context stuff::  Context_Control
367 *    -# floating point task stuff:: Context_Control_fp
368 *    -# special interrupt level context :: CPU_Interrupt_frame
369 *
370 * On some processors, it is cost-effective to save only the callee
371 * preserved registers during a task context switch.  This means
372 * that the ISR code needs to save those registers which do not
373 * persist across function calls.  It is not mandatory to make this
374 * distinctions between the caller/callee saves registers for the
375 * purpose of minimizing context saved during task switch and on interrupts.
376 * If the cost of saving extra registers is minimal, simplicity is the
377 * choice.  Save the same context on interrupt entry as for tasks in
378 * this case.
379 *
380 * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
381 * care should be used in designing the context area.
382 *
383 * On some CPUs with hardware floating point support, the Context_Control_fp
384 * structure will not be used or it simply consist of an array of a
385 * fixed number of bytes.   This is done when the floating point context
386 * is dumped by a "FP save context" type instruction and the format
387 * is not really defined by the CPU.  In this case, there is no need
388 * to figure out the exact format -- only the size.  Of course, although
389 * this is enough information for RTEMS, it is probably not enough for
390 * a debugger such as gdb.  But that is another problem.
391 *
392 * Port Specific Information:
393 *
394 * On the v850, this port saves special registers and those that are
395 * callee saved.
396 */
397/**@{**/
398
399/**
400 * This defines the minimal set of integer and processor state registers
401 * that must be saved during a voluntary context switch from one thread
402 * to another.
403 */
404typedef struct {
405    uint32_t   r1;
406    /** This field is the stack pointer (e.g. r3).  */
407    uint32_t   r3_stack_pointer;
408    uint32_t   r20;
409    uint32_t   r21;
410    uint32_t   r22;
411    uint32_t   r23;
412    uint32_t   r24;
413    uint32_t   r25;
414    uint32_t   r26;
415    uint32_t   r27;
416    uint32_t   r28;
417    uint32_t   r29;
418    uint32_t   r31;
419    uint32_t   psw;
420} Context_Control;
421
422/**
423 * This macro returns the stack pointer associated with @a _context.
424 *
425 * @param[in] _context is the thread context area to access
426 *
427 * @return This method returns the stack pointer.
428 */
429#define _CPU_Context_Get_SP( _context ) \
430  (_context)->r3_stack_pointer
431
432/**
433 * This defines the complete set of floating point registers that must
434 * be saved during any context switch from one thread to another.
435 */
436typedef struct {
437    /** FPU registers are listed here */
438    double      some_float_register;
439} Context_Control_fp;
440
441/**
442 * This defines the set of integer and processor state registers that must
443 * be saved during an interrupt.  This set does not include any which are
444 * in @ref Context_Control.
445 */
446typedef struct {
447    /** This field is a hint that a port will have a number of integer
448     * registers that need to be saved when an interrupt occurs or
449     * when a context switch occurs at the end of an ISR.
450     */
451    uint32_t   special_interrupt_register;
452} CPU_Interrupt_frame;
453
454/** @} */
455
456/**
457 * @defgroup CPUInterrupt Processor Dependent Interrupt Management
458 *
459 * On some CPUs, RTEMS supports a software managed interrupt stack.
460 * This stack is allocated by the Interrupt Manager and the switch
461 * is performed in @ref _ISR_Handler.  These variables contain pointers
462 * to the lowest and highest addresses in the chunk of memory allocated
463 * for the interrupt stack.  Since it is unknown whether the stack
464 * grows up or down (in general), this give the CPU dependent
465 * code the option of picking the version it wants to use.
466 *
467 * @note These two variables are required if the macro
468 *       @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
469 *
470 * Port Specific Information:
471 *
472 * XXX document implementation including references if appropriate
473 */
474/**@{**/
475
476/**
477 * @ingroup CPUContext
478 * The size of the floating point context area.  On some CPUs this
479 * will not be a "sizeof" because the format of the floating point
480 * area is not defined -- only the size is.  This is usually on
481 * CPUs with a "floating point save context" instruction.
482 *
483 * Port Specific Information:
484 *
485 * The v850 does not need a floating point context but this needs to be
486 * defined so confdefs.h.
487 */
488/* #define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp ) */
489#define CPU_CONTEXT_FP_SIZE 0
490
491/**
492 * Amount of extra stack (above minimum stack size) required by
493 * MPCI receive server thread.  Remember that in a multiprocessor
494 * system this thread must exist and be able to process all directives.
495 *
496 * Port Specific Information:
497 *
498 * There is no reason to think the v850 needs extra MPCI receive
499 * server stack.
500 */
501#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
502
503/**
504 * This is defined if the port has a special way to report the ISR nesting
505 * level.  Most ports maintain the variable @a _ISR_Nest_level.
506 */
507#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
508
509/** @} */
510
511/**
512 * @ingroup CPUContext
513 * Should be large enough to run all RTEMS tests.  This ensures
514 * that a "reasonable" small application should not have any problems.
515 *
516 * Port Specific Information:
517 *
518 * This should be very conservative on the v850.
519 */
520#define CPU_STACK_MINIMUM_SIZE          (1024*4)
521
522#define CPU_SIZEOF_POINTER 4
523
524/**
525 * CPU's worst alignment requirement for data types on a byte boundary.  This
526 * alignment does not take into account the requirements for the stack.
527 *
528 * Port Specific Information:
529 *
530 * There is no apparent reason why this should be larger than 8.
531 */
532#define CPU_ALIGNMENT              8
533
534/**
535 * This number corresponds to the byte alignment requirement for the
536 * heap handler.  This alignment requirement may be stricter than that
537 * for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
538 * common for the heap to follow the same alignment requirement as
539 * @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
540 * the heap, then this should be set to @ref CPU_ALIGNMENT.
541 *
542 * @note  This does not have to be a power of 2 although it should be
543 *        a multiple of 2 greater than or equal to 2.  The requirement
544 *        to be a multiple of 2 is because the heap uses the least
545 *        significant field of the front and back flags to indicate
546 *        that a block is in use or free.  So you do not want any odd
547 *        length blocks really putting length data in that bit.
548 *
549 *        On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
550 *        have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
551 *        elements allocated from the heap meet all restrictions.
552 *
553 * Port Specific Information:
554 *
555 * There is no apparent reason why this should be larger than CPU_ALIGNMENT.
556 */
557#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
558
559/**
560 * This number corresponds to the byte alignment requirement for memory
561 * buffers allocated by the partition manager.  This alignment requirement
562 * may be stricter than that for the data types alignment specified by
563 * @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
564 * alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
565 * strict enough for the partition, then this should be set to
566 * @ref CPU_ALIGNMENT.
567 *
568 * @note  This does not have to be a power of 2.  It does have to
569 *        be greater or equal to than @ref CPU_ALIGNMENT.
570 *
571 * Port Specific Information:
572 *
573 * There is no apparent reason why this should be larger than CPU_ALIGNMENT.
574 */
575#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
576
577/**
578 * This number corresponds to the byte alignment requirement for the
579 * stack.  This alignment requirement may be stricter than that for the
580 * data types alignment specified by @ref CPU_ALIGNMENT.  If the
581 * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
582 * set to 0.
583 *
584 * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
585 *
586 * Port Specific Information:
587 *
588 * The v850 has enough RAM where alignment to 16 may be desirable depending
589 * on the cache properties. But this remains to be demonstrated.
590 */
591#define CPU_STACK_ALIGNMENT        4
592
593/*
594 *  ISR handler macros
595 */
596
597/**
598 * @addtogroup CPUInterrupt
599 */
600/**@{**/
601
602/**
603 * Disable all interrupts for an RTEMS critical section.  The previous
604 * level is returned in @a _isr_cookie.
605 *
606 * @param[out] _isr_cookie will contain the previous level cookie
607 *
608 * Port Specific Information:
609 *
610 * On the v850, we need to save the PSW and use "di" to disable interrupts.
611 */
612#define _CPU_ISR_Disable( _isr_cookie ) \
613  do { \
614    unsigned int _psw; \
615    \
616    v850_get_psw( _psw ); \
617    __asm__ __volatile__( "di" ); \
618    _isr_cookie = _psw; \
619  } while (0)
620
621/**
622 * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
623 * This indicates the end of an RTEMS critical section.  The parameter
624 * @a _isr_cookie is not modified.
625 *
626 * @param[in] _isr_cookie contain the previous level cookie
627 *
628 * Port Specific Information:
629 *
630 * On the v850, we simply need to restore the PSW.
631 */
632#define _CPU_ISR_Enable( _isr_cookie )  \
633  do { \
634    unsigned int _psw = (_isr_cookie); \
635    \
636    v850_set_psw( _psw ); \
637  } while (0)
638
639/**
640 * This temporarily restores the interrupt to @a _isr_cookie before immediately
641 * disabling them again.  This is used to divide long RTEMS critical
642 * sections into two or more parts.  The parameter @a _isr_cookie is not
643 * modified.
644 *
645 * @param[in] _isr_cookie contain the previous level cookie
646 *
647 * Port Specific Information:
648 *
649 * This saves at least one instruction over using enable/disable back to back.
650 */
651#define _CPU_ISR_Flash( _isr_cookie ) \
652  do { \
653    unsigned int _psw = (_isr_cookie); \
654    v850_set_psw( _psw ); \
655    __asm__ __volatile__( "di" ); \
656  } while (0)
657
658/**
659 * This routine and @ref _CPU_ISR_Get_level
660 * Map the interrupt level in task mode onto the hardware that the CPU
661 * actually provides.  Currently, interrupt levels which do not
662 * map onto the CPU in a generic fashion are undefined.  Someday,
663 * it would be nice if these were "mapped" by the application
664 * via a callout.  For example, m68k has 8 levels 0 - 7, levels
665 * 8 - 255 would be available for bsp/application specific meaning.
666 * This could be used to manage a programmable interrupt controller
667 * via the rtems_task_mode directive.
668 *
669 * Port Specific Information:
670 *
671 * On the v850, level 0 is enabled. Non-zero is disabled.
672 */
673#define _CPU_ISR_Set_level( new_level ) \
674  do { \
675    if ( new_level ) \
676      __asm__ __volatile__( "di" ); \
677    else \
678      __asm__ __volatile__( "ei" ); \
679  } while (0)
680
681/**
682 * Return the current interrupt disable level for this task in
683 * the format used by the interrupt level portion of the task mode.
684 *
685 * @note This routine usually must be implemented as a subroutine.
686 *
687 * Port Specific Information:
688 *
689 * This method is implemented in C on the v850.
690 */
691uint32_t   _CPU_ISR_Get_level( void );
692
693/* end of ISR handler macros */
694
695/** @} */
696
697/* Context handler macros */
698
699/**
700 * @ingroup CPUContext
701 * Initialize the context to a state suitable for starting a
702 * task after a context restore operation.  Generally, this
703 * involves:
704 *
705 *    - setting a starting address
706 *    - preparing the stack
707 *    - preparing the stack and frame pointers
708 *    - setting the proper interrupt level in the context
709 *    - initializing the floating point context
710 *
711 * This routine generally does not set any unnecessary register
712 * in the context.  The state of the "general data" registers is
713 * undefined at task start time.
714 *
715 * @param[in] _the_context is the context structure to be initialized
716 * @param[in] _stack_base is the lowest physical address of this task's stack
717 * @param[in] _size is the size of this task's stack
718 * @param[in] _isr is the interrupt disable level
719 * @param[in] _entry_point is the thread's entry point.  This is
720 *        always @a _Thread_Handler
721 * @param[in] _is_fp is TRUE if the thread is to be a floating
722 *       point thread.  This is typically only used on CPUs where the
723 *       FPU may be easily disabled by software such as on the SPARC
724 *       where the PSR contains an enable FPU bit.
725 * @param[in] tls_area is the thread-local storage (TLS) area
726 *
727 * Port Specific Information:
728 *
729 * This method is implemented in C on the v850.
730 */
731void _CPU_Context_Initialize(
732  Context_Control  *the_context,
733  uint32_t         *stack_base,
734  uint32_t          size,
735  uint32_t          new_level,
736  void             *entry_point,
737  bool              is_fp,
738  void             *tls_area
739);
740
741/**
742 * This routine is responsible for somehow restarting the currently
743 * executing task.  If you are lucky, then all that is necessary
744 * is restoring the context.  Otherwise, there will need to be
745 * a special assembly routine which does something special in this
746 * case.  For many ports, simply adding a label to the restore path
747 * of @ref _CPU_Context_switch will work.  On other ports, it may be
748 * possibly to load a few arguments and jump to the restore path. It will
749 * not work if restarting self conflicts with the stack frame
750 * assumptions of restoring a context.
751 *
752 * Port Specific Information:
753 *
754 * On the v850, we require a special entry point to restart a task.
755 */
756#define _CPU_Context_Restart_self( _the_context ) \
757   _CPU_Context_restore( (_the_context) );
758
759/* XXX this should be possible to remove */
760#if 0
761/**
762 * @ingroup CPUContext
763 * The purpose of this macro is to allow the initial pointer into
764 * a floating point context area (used to save the floating point
765 * context) to be at an arbitrary place in the floating point
766 * context area.
767 *
768 * This is necessary because some FP units are designed to have
769 * their context saved as a stack which grows into lower addresses.
770 * Other FP units can be saved by simply moving registers into offsets
771 * from the base of the context area.  Finally some FP units provide
772 * a "dump context" instruction which could fill in from high to low
773 * or low to high based on the whim of the CPU designers.
774 *
775 * @param[in] _base is the lowest physical address of the floating point
776 *        context area
777 * @param[in] _offset is the offset into the floating point area
778 *
779 * Port Specific Information:
780 *
781 * XXX document implementation including references if appropriate
782 */
783#define _CPU_Context_Fp_start( _base, _offset ) \
784   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
785#endif
786
787/* XXX this should be possible to remove */
788#if 0
789/**
790 * This routine initializes the FP context area passed to it to.
791 * There are a few standard ways in which to initialize the
792 * floating point context.  The code included for this macro assumes
793 * that this is a CPU in which a "initial" FP context was saved into
794 * @a _CPU_Null_fp_context and it simply copies it to the destination
795 * context passed to it.
796 *
797 * Other floating point context save/restore models include:
798 *   -# not doing anything, and
799 *   -# putting a "null FP status word" in the correct place in the FP context.
800 *
801 * @param[in] _destination is the floating point context area
802 *
803 * Port Specific Information:
804 *
805 * XXX document implementation including references if appropriate
806 */
807#define _CPU_Context_Initialize_fp( _destination ) \
808  { \
809  }
810#endif
811
812/* end of Context handler macros */
813
814/* Fatal Error manager macros */
815
816/**
817 * This routine copies _error into a known place -- typically a stack
818 * location or a register, optionally disables interrupts, and
819 * halts/stops the CPU.
820 *
821 * Port Specific Information:
822 *
823 * Move the error code into r10, disable interrupts and halt.
824 */
825#define _CPU_Fatal_halt( _source, _error ) \
826  do { \
827    __asm__ __volatile__ ( "di" ); \
828    __asm__ __volatile__ ( "mov %0, r10; " : "=r" ((_error)) ); \
829    __asm__ __volatile__ ( "halt" ); \
830  } while (0)
831
832/* end of Fatal Error manager macros */
833
834/* Bitfield handler macros */
835
836/**
837 * @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
838 *
839 * This set of routines are used to implement fast searches for
840 * the most important ready task.
841 */
842/**@{**/
843
844/**
845 * This definition is set to TRUE if the port uses the generic bitfield
846 * manipulation implementation.
847 */
848#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
849
850/**
851 * This definition is set to TRUE if the port uses the data tables provided
852 * by the generic bitfield manipulation implementation.
853 * This can occur when actually using the generic bitfield manipulation
854 * implementation or when implementing the same algorithm in assembly
855 * language for improved performance.  It is unlikely that a port will use
856 * the data if it has a bitfield scan instruction.
857 *
858 * Port Specific Information:
859 *
860 * There is no single v850 instruction to do a bit scan so there is
861 * no CPU specific implementation of bit field scanning. The empty
862 * stub routines are left as a place holder in case someone figures
863 * out how to do a v850 implementation better than the generic algorithm.
864 */
865#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
866
867/**
868 * This routine sets @a _output to the bit number of the first bit
869 * set in @a _value.  @a _value is of CPU dependent type
870 * @a Priority_bit_map_Word.  This type may be either 16 or 32 bits
871 * wide although only the 16 least significant bits will be used.
872 *
873 * There are a number of variables in using a "find first bit" type
874 * instruction.
875 *
876 *   -# What happens when run on a value of zero?
877 *   -# Bits may be numbered from MSB to LSB or vice-versa.
878 *   -# The numbering may be zero or one based.
879 *   -# The "find first bit" instruction may search from MSB or LSB.
880 *
881 * RTEMS guarantees that (1) will never happen so it is not a concern.
882 * (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
883 * @ref _CPU_Priority_bits_index.  These three form a set of routines
884 * which must logically operate together.  Bits in the _value are
885 * set and cleared based on masks built by @ref _CPU_Priority_Mask.
886 * The basic major and minor values calculated by @ref _Priority_Major
887 * and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
888 * to properly range between the values returned by the "find first bit"
889 * instruction.  This makes it possible for @ref _Priority_Get_highest to
890 * calculate the major and directly index into the minor table.
891 * This mapping is necessary to ensure that 0 (a high priority major/minor)
892 * is the first bit found.
893 *
894 * This entire "find first bit" and mapping process depends heavily
895 * on the manner in which a priority is broken into a major and minor
896 * components with the major being the 4 MSB of a priority and minor
897 * the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
898 * priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
899 * to the lowest priority.
900 *
901 * If your CPU does not have a "find first bit" instruction, then
902 * there are ways to make do without it.  Here are a handful of ways
903 * to implement this in software:
904 *
905@verbatim
906      - a series of 16 bit test instructions
907      - a "binary search using if's"
908      - _number = 0
909        if _value > 0x00ff
910          _value >>=8
911          _number = 8;
912
913        if _value > 0x0000f
914          _value >=8
915          _number += 4
916
917        _number += bit_set_table[ _value ]
918@endverbatim
919
920 *   where bit_set_table[ 16 ] has values which indicate the first
921 *     bit set
922 *
923 * @param[in] _value is the value to be scanned
924 * @param[in] _output is the first bit set
925 *
926 * Port Specific Information:
927 *
928 * There is no single v850 instruction to do a bit scan so there is
929 * no CPU specific implementation of bit field scanning.
930 */
931#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
932#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
933  { \
934    (_output) = 0;   /* do something to prevent warnings */ \
935  }
936#endif
937
938/* end of Bitfield handler macros */
939
940/**
941 * This routine builds the mask which corresponds to the bit fields
942 * as searched by @ref _CPU_Bitfield_Find_first_bit.  See the discussion
943 * for that routine.
944 *
945 * Port Specific Information:
946 *
947 * There is no single v850 instruction to do a bit scan so there is
948 * no CPU specific implementation of bit field scanning.
949 */
950#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
951
952#define _CPU_Priority_Mask( _bit_number ) \
953  ( 1 << (_bit_number) )
954
955#endif
956
957/**
958 * This routine translates the bit numbers returned by
959 * @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
960 * a major or minor component of a priority.  See the discussion
961 * for that routine.
962 *
963 * @param[in] _priority is the major or minor number to translate
964 *
965 * Port Specific Information:
966 *
967 * There is no single v850 instruction to do a bit scan so there is
968 * no CPU specific implementation of bit field scanning.
969 */
970#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
971
972#define _CPU_Priority_bits_index( _priority ) \
973  (_priority)
974
975#endif
976
977/* end of Priority handler macros */
978
979/** @} */
980
981/* functions */
982
983/**
984 * @brief CPU initialize.
985 * This routine performs CPU dependent initialization.
986 *
987 * Port Specific Information:
988 *
989 * This is implemented in C.
990 *
991 * v850 CPU Dependent Source
992 */
993void _CPU_Initialize(void);
994
995/**
996 * @addtogroup CPUContext
997 */
998/**@{**/
999
1000/**
1001 * This routine switches from the run context to the heir context.
1002 *
1003 * @param[in] run points to the context of the currently executing task
1004 * @param[in] heir points to the context of the heir task
1005 *
1006 * Port Specific Information:
1007 *
1008 * This is implemented in assembly on the v850.
1009 */
1010void _CPU_Context_switch(
1011  Context_Control  *run,
1012  Context_Control  *heir
1013);
1014
1015/**
1016 * This routine is generally used only to restart self in an
1017 * efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
1018 *
1019 * @param[in] new_context points to the context to be restored.
1020 *
1021 * @note May be unnecessary to reload some registers.
1022 *
1023 * Port Specific Information:
1024 *
1025 * This is implemented in assembly on the v850.
1026 */
1027void _CPU_Context_restore(
1028  Context_Control *new_context
1029) RTEMS_NO_RETURN;
1030
1031/* XXX this should be possible to remove */
1032#if 0
1033/**
1034 * This routine saves the floating point context passed to it.
1035 *
1036 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
1037 * point context area
1038 *
1039 * @return on output @a *fp_context_ptr will contain the address that
1040 * should be used with @ref _CPU_Context_restore_fp to restore this context.
1041 *
1042 * Port Specific Information:
1043 *
1044 * XXX document implementation including references if appropriate
1045 */
1046void _CPU_Context_save_fp(
1047  Context_Control_fp **fp_context_ptr
1048);
1049#endif
1050
1051/* XXX this should be possible to remove */
1052#if 0
1053/**
1054 * This routine restores the floating point context passed to it.
1055 *
1056 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
1057 * point context area to restore
1058 *
1059 * @return on output @a *fp_context_ptr will contain the address that
1060 * should be used with @ref _CPU_Context_save_fp to save this context.
1061 *
1062 * Port Specific Information:
1063 *
1064 * XXX document implementation including references if appropriate
1065 */
1066void _CPU_Context_restore_fp(
1067  Context_Control_fp **fp_context_ptr
1068);
1069#endif
1070
1071static inline void _CPU_Context_volatile_clobber( uintptr_t pattern )
1072{
1073  /* TODO */
1074}
1075
1076static inline void _CPU_Context_validate( uintptr_t pattern )
1077{
1078  while (1) {
1079    /* TODO */
1080  }
1081}
1082
1083/** @} */
1084
1085/* FIXME */
1086typedef CPU_Interrupt_frame CPU_Exception_frame;
1087
1088void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
1089
1090/**
1091 * @ingroup CPUEndian
1092 * The following routine swaps the endian format of an unsigned int.
1093 * It must be static because it is referenced indirectly.
1094 *
1095 * This version will work on any processor, but if there is a better
1096 * way for your CPU PLEASE use it.  The most common way to do this is to:
1097 *
1098 *    swap least significant two bytes with 16-bit rotate
1099 *    swap upper and lower 16-bits
1100 *    swap most significant two bytes with 16-bit rotate
1101 *
1102 * Some CPUs have special instructions which swap a 32-bit quantity in
1103 * a single instruction (e.g. i486).  It is probably best to avoid
1104 * an "endian swapping control bit" in the CPU.  One good reason is
1105 * that interrupts would probably have to be disabled to ensure that
1106 * an interrupt does not try to access the same "chunk" with the wrong
1107 * endian.  Another good reason is that on some CPUs, the endian bit
1108 * endianness for ALL fetches -- both code and data -- so the code
1109 * will be fetched incorrectly.
1110 *
1111 * @param[in] value is the value to be swapped
1112 * @return the value after being endian swapped
1113 *
1114 * Port Specific Information:
1115 *
1116 * The v850 has a single instruction to swap endianness on a 32 bit quantity.
1117 */
1118static inline uint32_t CPU_swap_u32(
1119  uint32_t value
1120)
1121{
1122  unsigned int swapped;
1123
1124  #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1)
1125    unsigned int v;
1126
1127    v = value;
1128    __asm__ __volatile__ ("bsw %0, %1" : "=r" (v), "=&r" (swapped) );
1129  #else
1130    uint32_t byte1, byte2, byte3, byte4;
1131
1132    byte4 = (value >> 24) & 0xff;
1133    byte3 = (value >> 16) & 0xff;
1134    byte2 = (value >> 8)  & 0xff;
1135    byte1 =  value        & 0xff;
1136
1137    swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1138  #endif
1139  return swapped;
1140}
1141
1142/**
1143 * @ingroup CPUEndian
1144 * This routine swaps a 16 bir quantity.
1145 *
1146 * @param[in] value is the value to be swapped
1147 * @return the value after being endian swapped
1148 *
1149 * Port Specific Information:
1150 *
1151 * The v850 has a single instruction to swap endianness on a 16 bit quantity.
1152 */
1153static inline uint16_t CPU_swap_u16( uint16_t value )
1154{
1155  unsigned int swapped;
1156
1157  #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1)
1158    unsigned int v;
1159
1160    v = value;
1161    __asm__ __volatile__ ("bsh %0, %1" : "=r" (v), "=&r" (swapped) );
1162  #else
1163    swapped = ((value & 0xff) << 8) | ((value >> 8) & 0xff);
1164  #endif
1165  return swapped;
1166}
1167
1168typedef uint32_t CPU_Counter_ticks;
1169
1170CPU_Counter_ticks _CPU_Counter_read( void );
1171
1172static inline CPU_Counter_ticks _CPU_Counter_difference(
1173  CPU_Counter_ticks second,
1174  CPU_Counter_ticks first
1175)
1176{
1177  return second - first;
1178}
1179
1180#ifdef __cplusplus
1181}
1182#endif
1183
1184#endif
Note: See TracBrowser for help on using the repository browser.