source: rtems/cpukit/score/cpu/v850/include/rtems/score/cpu.h @ 8776bb9

5
Last change on this file since 8776bb9 was 8776bb9, checked in by Sebastian Huber <sebastian.huber@…>, on 09/26/18 at 04:34:54

score: Remove CPU_PROVIDES_IDLE_THREAD_BODY

Remove the CPU_PROVIDES_IDLE_THREAD_BODY option to avoid unnecessary
conditional compilation.

Close #3539.

  • Property mode set to 100644
File size: 25.2 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/basedefs.h>
27#include <rtems/score/v850.h>
28
29/* conditional compilation parameters */
30
31/**
32 * Does the CPU follow the simple vectored interrupt model?
33 *
34 * If TRUE, then RTEMS allocates the vector table it internally manages.
35 * If FALSE, then the BSP is assumed to allocate and manage the vector
36 * table
37 *
38 * Port Specific Information:
39 *
40 * This port uses the Progammable Interrupt Controller interrupt model.
41 */
42#define CPU_SIMPLE_VECTORED_INTERRUPTS FALSE
43
44/**
45 * @def CPU_HARDWARE_FP
46 *
47 * Does the CPU have hardware floating point?
48 *
49 * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
50 * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
51 *
52 * If there is a FP coprocessor such as the i387 or mc68881, then
53 * the answer is TRUE.
54 *
55 * The macro name "V850_HAS_FPU" should be made CPU specific.
56 * It indicates whether or not this CPU model has FP support.  For
57 * example, it would be possible to have an i386_nofp CPU model
58 * which set this to false to indicate that you have an i386 without
59 * an i387 and wish to leave floating point support out of RTEMS.
60 */
61
62/**
63 * @def CPU_SOFTWARE_FP
64 *
65 * Does the CPU have no hardware floating point and GCC provides a
66 * software floating point implementation which must be context
67 * switched?
68 *
69 * This feature conditional is used to indicate whether or not there
70 * is software implemented floating point that must be context
71 * switched.  The determination of whether or not this applies
72 * is very tool specific and the state saved/restored is also
73 * compiler specific.
74 *
75 * Port Specific Information:
76 *
77 * Some v850 models do have IEEE hardware floating point support but
78 * they do not have any special registers to save or bit(s) which
79 * determine if the FPU is enabled. In short, there appears to be nothing
80 * related to the floating point operations which impact the RTEMS
81 * thread context switch. Thus from an RTEMS perspective, there is really
82 * no FPU to manage.
83 */
84#define CPU_HARDWARE_FP     FALSE
85#define CPU_SOFTWARE_FP     FALSE
86
87/**
88 * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
89 *
90 * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
91 * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
92 *
93 * So far, the only CPUs in which this option has been used are the
94 * HP PA-RISC and PowerPC.  On the PA-RISC, The HP C compiler and
95 * gcc both implicitly used the floating point registers to perform
96 * integer multiplies.  Similarly, the PowerPC port of gcc has been
97 * seen to allocate floating point local variables and touch the FPU
98 * even when the flow through a subroutine (like vfprintf()) might
99 * not use floating point formats.
100 *
101 * If a function which you would not think utilize the FP unit DOES,
102 * then one can not easily predict which tasks will use the FP hardware.
103 * In this case, this option should be TRUE.
104 *
105 * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
106 *
107 * Port Specific Information:
108 *
109 * This should be false until it has been demonstrated that gcc for the
110 * v850 generates FPU code when it is unexpected. But even this would
111 * not matter since there are no FP specific registers or bits which
112 * would be corrupted if an FP operation occurred in an integer only
113 * thread.
114 */
115#define CPU_ALL_TASKS_ARE_FP     FALSE
116
117/**
118 * Should the IDLE task have a floating point context?
119 *
120 * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
121 * and it has a floating point context which is switched in and out.
122 * If FALSE, then the IDLE task does not have a floating point context.
123 *
124 * Setting this to TRUE negatively impacts the time required to preempt
125 * the IDLE task from an interrupt because the floating point context
126 * must be saved as part of the preemption.
127 *
128 * Port Specific Information:
129 *
130 * The IDLE thread should not be using the FPU. Leave this off.
131 */
132#define CPU_IDLE_TASK_IS_FP      FALSE
133
134/**
135 * Should the saving of the floating point registers be deferred
136 * until a context switch is made to another different floating point
137 * task?
138 *
139 * If TRUE, then the floating point context will not be stored until
140 * necessary.  It will remain in the floating point registers and not
141 * disturned until another floating point task is switched to.
142 *
143 * If FALSE, then the floating point context is saved when a floating
144 * point task is switched out and restored when the next floating point
145 * task is restored.  The state of the floating point registers between
146 * those two operations is not specified.
147 *
148 * If the floating point context does NOT have to be saved as part of
149 * interrupt dispatching, then it should be safe to set this to TRUE.
150 *
151 * Setting this flag to TRUE results in using a different algorithm
152 * for deciding when to save and restore the floating point context.
153 * The deferred FP switch algorithm minimizes the number of times
154 * the FP context is saved and restored.  The FP context is not saved
155 * until a context switch is made to another, different FP task.
156 * Thus in a system with only one FP task, the FP context will never
157 * be saved or restored.
158 *
159 * Port Specific Information:
160 *
161 * See earlier comments. There is no FPU state to manage.
162 */
163#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
164
165#define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE
166
167/**
168 * Does the stack grow up (toward higher addresses) or down
169 * (toward lower addresses)?
170 *
171 * If TRUE, then the grows upward.
172 * If FALSE, then the grows toward smaller addresses.
173 *
174 * Port Specific Information:
175 *
176 * The v850 stack grows from high addresses to low addresses.
177 */
178#define CPU_STACK_GROWS_UP               FALSE
179
180/* FIXME: Is this the right value? */
181#define CPU_CACHE_LINE_BYTES 32
182
183#define CPU_STRUCTURE_ALIGNMENT
184
185/**
186 * @ingroup CPUInterrupt
187 * The following defines the number of bits actually used in the
188 * interrupt field of the task mode.  How those bits map to the
189 * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
190 *
191 * Port Specific Information:
192 *
193 * The v850 only has a single bit in the CPU for interrupt disable/enable.
194 */
195#define CPU_MODES_INTERRUPT_MASK   0x00000001
196
197#define CPU_MAXIMUM_PROCESSORS 32
198
199/**
200 * @defgroup CPUContext Processor Dependent Context Management
201 *
202 * From the highest level viewpoint, there are 2 types of context to save.
203 *
204 *    -# Interrupt registers to save
205 *    -# Task level registers to save
206 *
207 * Since RTEMS handles integer and floating point contexts separately, this
208 * means we have the following 3 context items:
209 *
210 *    -# task level context stuff::  Context_Control
211 *    -# floating point task stuff:: Context_Control_fp
212 *    -# special interrupt level context :: CPU_Interrupt_frame
213 *
214 * On some processors, it is cost-effective to save only the callee
215 * preserved registers during a task context switch.  This means
216 * that the ISR code needs to save those registers which do not
217 * persist across function calls.  It is not mandatory to make this
218 * distinctions between the caller/callee saves registers for the
219 * purpose of minimizing context saved during task switch and on interrupts.
220 * If the cost of saving extra registers is minimal, simplicity is the
221 * choice.  Save the same context on interrupt entry as for tasks in
222 * this case.
223 *
224 * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
225 * care should be used in designing the context area.
226 *
227 * On some CPUs with hardware floating point support, the Context_Control_fp
228 * structure will not be used or it simply consist of an array of a
229 * fixed number of bytes.   This is done when the floating point context
230 * is dumped by a "FP save context" type instruction and the format
231 * is not really defined by the CPU.  In this case, there is no need
232 * to figure out the exact format -- only the size.  Of course, although
233 * this is enough information for RTEMS, it is probably not enough for
234 * a debugger such as gdb.  But that is another problem.
235 *
236 * Port Specific Information:
237 *
238 * On the v850, this port saves special registers and those that are
239 * callee saved.
240 */
241/**@{**/
242
243/**
244 * This defines the minimal set of integer and processor state registers
245 * that must be saved during a voluntary context switch from one thread
246 * to another.
247 */
248typedef struct {
249    uint32_t   r1;
250    /** This field is the stack pointer (e.g. r3).  */
251    uint32_t   r3_stack_pointer;
252    uint32_t   r20;
253    uint32_t   r21;
254    uint32_t   r22;
255    uint32_t   r23;
256    uint32_t   r24;
257    uint32_t   r25;
258    uint32_t   r26;
259    uint32_t   r27;
260    uint32_t   r28;
261    uint32_t   r29;
262    uint32_t   r31;
263    uint32_t   psw;
264} Context_Control;
265
266/**
267 * This macro returns the stack pointer associated with @a _context.
268 *
269 * @param[in] _context is the thread context area to access
270 *
271 * @return This method returns the stack pointer.
272 */
273#define _CPU_Context_Get_SP( _context ) \
274  (_context)->r3_stack_pointer
275
276/**
277 * This defines the complete set of floating point registers that must
278 * be saved during any context switch from one thread to another.
279 */
280typedef struct {
281    /** FPU registers are listed here */
282    double      some_float_register;
283} Context_Control_fp;
284
285/**
286 * This defines the set of integer and processor state registers that must
287 * be saved during an interrupt.  This set does not include any which are
288 * in @ref Context_Control.
289 */
290typedef struct {
291    /** This field is a hint that a port will have a number of integer
292     * registers that need to be saved when an interrupt occurs or
293     * when a context switch occurs at the end of an ISR.
294     */
295    uint32_t   special_interrupt_register;
296} CPU_Interrupt_frame;
297
298/** @} */
299
300/**
301 * @defgroup CPUInterrupt Processor Dependent Interrupt Management
302 */
303/**@{**/
304
305/**
306 * @ingroup CPUContext
307 * The size of the floating point context area.  On some CPUs this
308 * will not be a "sizeof" because the format of the floating point
309 * area is not defined -- only the size is.  This is usually on
310 * CPUs with a "floating point save context" instruction.
311 *
312 * Port Specific Information:
313 *
314 * The v850 does not need a floating point context but this needs to be
315 * defined so confdefs.h.
316 */
317/* #define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp ) */
318#define CPU_CONTEXT_FP_SIZE 0
319
320/**
321 * Amount of extra stack (above minimum stack size) required by
322 * MPCI receive server thread.  Remember that in a multiprocessor
323 * system this thread must exist and be able to process all directives.
324 *
325 * Port Specific Information:
326 *
327 * There is no reason to think the v850 needs extra MPCI receive
328 * server stack.
329 */
330#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
331
332/**
333 * This is defined if the port has a special way to report the ISR nesting
334 * level.  Most ports maintain the variable @a _ISR_Nest_level.
335 */
336#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
337
338/** @} */
339
340/**
341 * @ingroup CPUContext
342 * Should be large enough to run all RTEMS tests.  This ensures
343 * that a "reasonable" small application should not have any problems.
344 *
345 * Port Specific Information:
346 *
347 * This should be very conservative on the v850.
348 */
349#define CPU_STACK_MINIMUM_SIZE          (1024*4)
350
351#define CPU_SIZEOF_POINTER 4
352
353/**
354 * CPU's worst alignment requirement for data types on a byte boundary.  This
355 * alignment does not take into account the requirements for the stack.
356 *
357 * Port Specific Information:
358 *
359 * There is no apparent reason why this should be larger than 8.
360 */
361#define CPU_ALIGNMENT              8
362
363/**
364 * This number corresponds to the byte alignment requirement for the
365 * heap handler.  This alignment requirement may be stricter than that
366 * for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
367 * common for the heap to follow the same alignment requirement as
368 * @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
369 * the heap, then this should be set to @ref CPU_ALIGNMENT.
370 *
371 * @note  This does not have to be a power of 2 although it should be
372 *        a multiple of 2 greater than or equal to 2.  The requirement
373 *        to be a multiple of 2 is because the heap uses the least
374 *        significant field of the front and back flags to indicate
375 *        that a block is in use or free.  So you do not want any odd
376 *        length blocks really putting length data in that bit.
377 *
378 *        On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
379 *        have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
380 *        elements allocated from the heap meet all restrictions.
381 *
382 * Port Specific Information:
383 *
384 * There is no apparent reason why this should be larger than CPU_ALIGNMENT.
385 */
386#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
387
388/**
389 * This number corresponds to the byte alignment requirement for the
390 * stack.  This alignment requirement may be stricter than that for the
391 * data types alignment specified by @ref CPU_ALIGNMENT.  If the
392 * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
393 * set to 0.
394 *
395 * @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
396 *
397 * Port Specific Information:
398 *
399 * The v850 has enough RAM where alignment to 16 may be desirable depending
400 * on the cache properties. But this remains to be demonstrated.
401 */
402#define CPU_STACK_ALIGNMENT        4
403
404#define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
405
406/*
407 *  ISR handler macros
408 */
409
410/**
411 * @addtogroup CPUInterrupt
412 */
413/**@{**/
414
415/**
416 * Disable all interrupts for an RTEMS critical section.  The previous
417 * level is returned in @a _isr_cookie.
418 *
419 * @param[out] _isr_cookie will contain the previous level cookie
420 *
421 * Port Specific Information:
422 *
423 * On the v850, we need to save the PSW and use "di" to disable interrupts.
424 */
425#define _CPU_ISR_Disable( _isr_cookie ) \
426  do { \
427    unsigned int _psw; \
428    \
429    v850_get_psw( _psw ); \
430    __asm__ __volatile__( "di" ); \
431    _isr_cookie = _psw; \
432  } while (0)
433
434/**
435 * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
436 * This indicates the end of an RTEMS critical section.  The parameter
437 * @a _isr_cookie is not modified.
438 *
439 * @param[in] _isr_cookie contain the previous level cookie
440 *
441 * Port Specific Information:
442 *
443 * On the v850, we simply need to restore the PSW.
444 */
445#define _CPU_ISR_Enable( _isr_cookie )  \
446  do { \
447    unsigned int _psw = (_isr_cookie); \
448    \
449    v850_set_psw( _psw ); \
450  } while (0)
451
452/**
453 * This temporarily restores the interrupt to @a _isr_cookie before immediately
454 * disabling them again.  This is used to divide long RTEMS critical
455 * sections into two or more parts.  The parameter @a _isr_cookie is not
456 * modified.
457 *
458 * @param[in] _isr_cookie contain the previous level cookie
459 *
460 * Port Specific Information:
461 *
462 * This saves at least one instruction over using enable/disable back to back.
463 */
464#define _CPU_ISR_Flash( _isr_cookie ) \
465  do { \
466    unsigned int _psw = (_isr_cookie); \
467    v850_set_psw( _psw ); \
468    __asm__ __volatile__( "di" ); \
469  } while (0)
470
471RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level )
472{
473  return ( level & V850_PSW_INTERRUPT_DISABLE_MASK )
474    != V850_PSW_INTERRUPT_DISABLE;
475}
476
477/**
478 * This routine and @ref _CPU_ISR_Get_level
479 * Map the interrupt level in task mode onto the hardware that the CPU
480 * actually provides.  Currently, interrupt levels which do not
481 * map onto the CPU in a generic fashion are undefined.  Someday,
482 * it would be nice if these were "mapped" by the application
483 * via a callout.  For example, m68k has 8 levels 0 - 7, levels
484 * 8 - 255 would be available for bsp/application specific meaning.
485 * This could be used to manage a programmable interrupt controller
486 * via the rtems_task_mode directive.
487 *
488 * Port Specific Information:
489 *
490 * On the v850, level 0 is enabled. Non-zero is disabled.
491 */
492#define _CPU_ISR_Set_level( new_level ) \
493  do { \
494    if ( new_level ) \
495      __asm__ __volatile__( "di" ); \
496    else \
497      __asm__ __volatile__( "ei" ); \
498  } while (0)
499
500/**
501 * Return the current interrupt disable level for this task in
502 * the format used by the interrupt level portion of the task mode.
503 *
504 * @note This routine usually must be implemented as a subroutine.
505 *
506 * Port Specific Information:
507 *
508 * This method is implemented in C on the v850.
509 */
510uint32_t   _CPU_ISR_Get_level( void );
511
512/* end of ISR handler macros */
513
514/** @} */
515
516/* Context handler macros */
517
518/**
519 * @ingroup CPUContext
520 * Initialize the context to a state suitable for starting a
521 * task after a context restore operation.  Generally, this
522 * involves:
523 *
524 *    - setting a starting address
525 *    - preparing the stack
526 *    - preparing the stack and frame pointers
527 *    - setting the proper interrupt level in the context
528 *    - initializing the floating point context
529 *
530 * This routine generally does not set any unnecessary register
531 * in the context.  The state of the "general data" registers is
532 * undefined at task start time.
533 *
534 * @param[in] _the_context is the context structure to be initialized
535 * @param[in] _stack_base is the lowest physical address of this task's stack
536 * @param[in] _size is the size of this task's stack
537 * @param[in] _isr is the interrupt disable level
538 * @param[in] _entry_point is the thread's entry point.  This is
539 *        always @a _Thread_Handler
540 * @param[in] _is_fp is TRUE if the thread is to be a floating
541 *       point thread.  This is typically only used on CPUs where the
542 *       FPU may be easily disabled by software such as on the SPARC
543 *       where the PSR contains an enable FPU bit.
544 * @param[in] tls_area is the thread-local storage (TLS) area
545 *
546 * Port Specific Information:
547 *
548 * This method is implemented in C on the v850.
549 */
550void _CPU_Context_Initialize(
551  Context_Control  *the_context,
552  uint32_t         *stack_base,
553  uint32_t          size,
554  uint32_t          new_level,
555  void             *entry_point,
556  bool              is_fp,
557  void             *tls_area
558);
559
560/**
561 * This routine is responsible for somehow restarting the currently
562 * executing task.  If you are lucky, then all that is necessary
563 * is restoring the context.  Otherwise, there will need to be
564 * a special assembly routine which does something special in this
565 * case.  For many ports, simply adding a label to the restore path
566 * of @ref _CPU_Context_switch will work.  On other ports, it may be
567 * possibly to load a few arguments and jump to the restore path. It will
568 * not work if restarting self conflicts with the stack frame
569 * assumptions of restoring a context.
570 *
571 * Port Specific Information:
572 *
573 * On the v850, we require a special entry point to restart a task.
574 */
575#define _CPU_Context_Restart_self( _the_context ) \
576   _CPU_Context_restore( (_the_context) );
577
578/* XXX this should be possible to remove */
579#if 0
580/**
581 * This routine initializes the FP context area passed to it to.
582 * There are a few standard ways in which to initialize the
583 * floating point context.  The code included for this macro assumes
584 * that this is a CPU in which a "initial" FP context was saved into
585 * @a _CPU_Null_fp_context and it simply copies it to the destination
586 * context passed to it.
587 *
588 * Other floating point context save/restore models include:
589 *   -# not doing anything, and
590 *   -# putting a "null FP status word" in the correct place in the FP context.
591 *
592 * @param[in] _destination is the floating point context area
593 *
594 * Port Specific Information:
595 *
596 * XXX document implementation including references if appropriate
597 */
598#define _CPU_Context_Initialize_fp( _destination ) \
599  { \
600  }
601#endif
602
603/* end of Context handler macros */
604
605/* Fatal Error manager macros */
606
607/**
608 * This routine copies _error into a known place -- typically a stack
609 * location or a register, optionally disables interrupts, and
610 * halts/stops the CPU.
611 *
612 * Port Specific Information:
613 *
614 * Move the error code into r10, disable interrupts and halt.
615 */
616#define _CPU_Fatal_halt( _source, _error ) \
617  do { \
618    __asm__ __volatile__ ( "di" ); \
619    __asm__ __volatile__ ( "mov %0, r10; " : "=r" ((_error)) ); \
620    __asm__ __volatile__ ( "halt" ); \
621  } while (0)
622
623/* end of Fatal Error manager macros */
624
625#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
626
627/* functions */
628
629/**
630 * @brief CPU initialize.
631 * This routine performs CPU dependent initialization.
632 *
633 * Port Specific Information:
634 *
635 * This is implemented in C.
636 *
637 * v850 CPU Dependent Source
638 */
639void _CPU_Initialize(void);
640
641void *_CPU_Thread_Idle_body( uintptr_t ignored );
642
643/**
644 * @addtogroup CPUContext
645 */
646/**@{**/
647
648/**
649 * This routine switches from the run context to the heir context.
650 *
651 * @param[in] run points to the context of the currently executing task
652 * @param[in] heir points to the context of the heir task
653 *
654 * Port Specific Information:
655 *
656 * This is implemented in assembly on the v850.
657 */
658void _CPU_Context_switch(
659  Context_Control  *run,
660  Context_Control  *heir
661);
662
663/**
664 * This routine is generally used only to restart self in an
665 * efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
666 *
667 * @param[in] new_context points to the context to be restored.
668 *
669 * @note May be unnecessary to reload some registers.
670 *
671 * Port Specific Information:
672 *
673 * This is implemented in assembly on the v850.
674 */
675void _CPU_Context_restore(
676  Context_Control *new_context
677) RTEMS_NO_RETURN;
678
679/* XXX this should be possible to remove */
680#if 0
681/**
682 * This routine saves the floating point context passed to it.
683 *
684 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
685 * point context area
686 *
687 * @return on output @a *fp_context_ptr will contain the address that
688 * should be used with @ref _CPU_Context_restore_fp to restore this context.
689 *
690 * Port Specific Information:
691 *
692 * XXX document implementation including references if appropriate
693 */
694void _CPU_Context_save_fp(
695  Context_Control_fp **fp_context_ptr
696);
697#endif
698
699/* XXX this should be possible to remove */
700#if 0
701/**
702 * This routine restores the floating point context passed to it.
703 *
704 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
705 * point context area to restore
706 *
707 * @return on output @a *fp_context_ptr will contain the address that
708 * should be used with @ref _CPU_Context_save_fp to save this context.
709 *
710 * Port Specific Information:
711 *
712 * XXX document implementation including references if appropriate
713 */
714void _CPU_Context_restore_fp(
715  Context_Control_fp **fp_context_ptr
716);
717#endif
718
719/** @} */
720
721/* FIXME */
722typedef CPU_Interrupt_frame CPU_Exception_frame;
723
724void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
725
726/**
727 * @ingroup CPUEndian
728 * The following routine swaps the endian format of an unsigned int.
729 * It must be static because it is referenced indirectly.
730 *
731 * This version will work on any processor, but if there is a better
732 * way for your CPU PLEASE use it.  The most common way to do this is to:
733 *
734 *    swap least significant two bytes with 16-bit rotate
735 *    swap upper and lower 16-bits
736 *    swap most significant two bytes with 16-bit rotate
737 *
738 * Some CPUs have special instructions which swap a 32-bit quantity in
739 * a single instruction (e.g. i486).  It is probably best to avoid
740 * an "endian swapping control bit" in the CPU.  One good reason is
741 * that interrupts would probably have to be disabled to ensure that
742 * an interrupt does not try to access the same "chunk" with the wrong
743 * endian.  Another good reason is that on some CPUs, the endian bit
744 * endianness for ALL fetches -- both code and data -- so the code
745 * will be fetched incorrectly.
746 *
747 * @param[in] value is the value to be swapped
748 * @return the value after being endian swapped
749 *
750 * Port Specific Information:
751 *
752 * The v850 has a single instruction to swap endianness on a 32 bit quantity.
753 */
754static inline uint32_t CPU_swap_u32(
755  uint32_t value
756)
757{
758  unsigned int swapped;
759
760  #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1)
761    unsigned int v;
762
763    v = value;
764    __asm__ __volatile__ ("bsw %0, %1" : "=r" (v), "=&r" (swapped) );
765  #else
766    uint32_t byte1, byte2, byte3, byte4;
767
768    byte4 = (value >> 24) & 0xff;
769    byte3 = (value >> 16) & 0xff;
770    byte2 = (value >> 8)  & 0xff;
771    byte1 =  value        & 0xff;
772
773    swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
774  #endif
775  return swapped;
776}
777
778/**
779 * @ingroup CPUEndian
780 * This routine swaps a 16 bir quantity.
781 *
782 * @param[in] value is the value to be swapped
783 * @return the value after being endian swapped
784 *
785 * Port Specific Information:
786 *
787 * The v850 has a single instruction to swap endianness on a 16 bit quantity.
788 */
789static inline uint16_t CPU_swap_u16( uint16_t value )
790{
791  unsigned int swapped;
792
793  #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1)
794    unsigned int v;
795
796    v = value;
797    __asm__ __volatile__ ("bsh %0, %1" : "=r" (v), "=&r" (swapped) );
798  #else
799    swapped = ((value & 0xff) << 8) | ((value >> 8) & 0xff);
800  #endif
801  return swapped;
802}
803
804typedef uint32_t CPU_Counter_ticks;
805
806uint32_t _CPU_Counter_frequency( void );
807
808CPU_Counter_ticks _CPU_Counter_read( void );
809
810static inline CPU_Counter_ticks _CPU_Counter_difference(
811  CPU_Counter_ticks second,
812  CPU_Counter_ticks first
813)
814{
815  return second - first;
816}
817
818/** Type that can store a 32-bit integer or a pointer. */
819typedef uintptr_t CPU_Uint32ptr;
820
821#ifdef __cplusplus
822}
823#endif
824
825#endif
Note: See TracBrowser for help on using the repository browser.