source: rtems/cpukit/score/cpu/h8300/rtems/score/cpu.h @ 4ac56fbb

4.115
Last change on this file since 4ac56fbb was 4ac56fbb, checked in by Sebastian Huber <sebastian.huber@…>, on 07/27/10 at 11:03:38

2010-07-27 Sebastian Huber <sebastian.huber@…>

  • rtems/score/cpu.h: Assembler compatibility fixes.
  • Property mode set to 100644
File size: 31.6 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  This include file contains information pertaining to the H8300
7 *  processor.
8 *
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 *
16 *  $Id$
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/h8300.h>
28#ifndef ASM
29  #include <rtems/bspIo.h>
30#endif
31
32/* conditional compilation parameters */
33
34/*
35 *  Should the calls to _Thread_Enable_dispatch be inlined?
36 *
37 *  If TRUE, then they are inlined.
38 *  If FALSE, then a subroutine call is made.
39 *
40 *  Basically this is an example of the classic trade-off of size
41 *  versus speed.  Inlining the call (TRUE) typically increases the
42 *  size of RTEMS while speeding up the enabling of dispatching.
43 *  [NOTE: In general, the _Thread_Dispatch_disable_level will
44 *  only be 0 or 1 unless you are in an interrupt handler and that
45 *  interrupt handler invokes the executive.]  When not inlined
46 *  something calls _Thread_Enable_dispatch which in turns calls
47 *  _Thread_Dispatch.  If the enable dispatch is inlined, then
48 *  one subroutine call is avoided entirely.]
49 *
50 *  H8300 Specific Information:
51 *
52 *  XXX
53 */
54
55#define CPU_INLINE_ENABLE_DISPATCH       FALSE
56
57/*
58 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
59 *  be unrolled one time?  In unrolled each iteration of the loop examines
60 *  two "nodes" on the chain being searched.  Otherwise, only one node
61 *  is examined per iteration.
62 *
63 *  If TRUE, then the loops are unrolled.
64 *  If FALSE, then the loops are not unrolled.
65 *
66 *  The primary factor in making this decision is the cost of disabling
67 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
68 *  body of the loop.  On some CPUs, the flash is more expensive than
69 *  one iteration of the loop body.  In this case, it might be desirable
70 *  to unroll the loop.  It is important to note that on some CPUs, this
71 *  code is the longest interrupt disable period in RTEMS.  So it is
72 *  necessary to strike a balance when setting this parameter.
73 *
74 *  H8300 Specific Information:
75 *
76 *  XXX
77 */
78
79#define CPU_UNROLL_ENQUEUE_PRIORITY      FALSE
80
81/*
82 *  Should this target use 16 or 32 bit object Ids?
83 *
84 */
85#define RTEMS_USE_16_BIT_OBJECT
86
87/*
88 *  Does RTEMS manage a dedicated interrupt stack in software?
89 *
90 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
91 *  If FALSE, nothing is done.
92 *
93 *  If the CPU supports a dedicated interrupt stack in hardware,
94 *  then it is generally the responsibility of the BSP to allocate it
95 *  and set it up.
96 *
97 *  If the CPU does not support a dedicated interrupt stack, then
98 *  the porter has two options: (1) execute interrupts on the
99 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
100 *  interrupt stack.
101 *
102 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
103 *
104 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
105 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
106 *  possible that both are FALSE for a particular CPU.  Although it
107 *  is unclear what that would imply about the interrupt processing
108 *  procedure on that CPU.
109 *
110 *  H8300 Specific Information:
111 *
112 *  XXX
113 */
114
115#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
116
117/*
118 *  Does the CPU follow the simple vectored interrupt model?
119 *
120 *  If TRUE, then RTEMS allocates the vector table it internally manages.
121 *  If FALSE, then the BSP is assumed to allocate and manage the vector
122 *  table
123 *
124 *  H8300 Specific Information:
125 *
126 *  XXX document implementation including references if appropriate
127 */
128#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
129
130/*
131 *  Does this CPU have hardware support for a dedicated interrupt stack?
132 *
133 *  If TRUE, then it must be installed during initialization.
134 *  If FALSE, then no installation is performed.
135 *
136 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
137 *
138 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
139 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
140 *  possible that both are FALSE for a particular CPU.  Although it
141 *  is unclear what that would imply about the interrupt processing
142 *  procedure on that CPU.
143 *
144 *  H8300 Specific Information:
145 *
146 *  XXX
147 */
148
149#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
150
151/*
152 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
153 *
154 *  If TRUE, then the memory is allocated during initialization.
155 *  If FALSE, then the memory is allocated during initialization.
156 *
157 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
158 *
159 *  H8300 Specific Information:
160 *
161 *  XXX
162 */
163
164#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
165
166/*
167 *  Does the CPU have hardware floating point?
168 *
169 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
170 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
171 *
172 *  If there is a FP coprocessor such as the i387 or mc68881, then
173 *  the answer is TRUE.
174 *
175 *  The macro name "H8300_HAS_FPU" should be made CPU specific.
176 *  It indicates whether or not this CPU model has FP support.  For
177 *  example, it would be possible to have an i386_nofp CPU model
178 *  which set this to false to indicate that you have an i386 without
179 *  an i387 and wish to leave floating point support out of RTEMS.
180 *
181 *  H8300 Specific Information:
182 *
183 *  XXX
184 */
185
186#define CPU_HARDWARE_FP     FALSE
187
188/*
189 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
190 *
191 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
192 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
193 *
194 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
195 *
196 *  H8300 Specific Information:
197 *
198 *  XXX
199 */
200
201#define CPU_ALL_TASKS_ARE_FP     FALSE
202
203/*
204 *  Should the IDLE task have a floating point context?
205 *
206 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
207 *  and it has a floating point context which is switched in and out.
208 *  If FALSE, then the IDLE task does not have a floating point context.
209 *
210 *  Setting this to TRUE negatively impacts the time required to preempt
211 *  the IDLE task from an interrupt because the floating point context
212 *  must be saved as part of the preemption.
213 *
214 *  H8300 Specific Information:
215 *
216 *  XXX
217 */
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 *  H8300 Specific Information:
247 *
248 *  XXX
249 */
250
251#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
252
253/*
254 *  Does this port provide a CPU dependent IDLE task implementation?
255 *
256 *  If TRUE, then the routine _CPU_Internal_threads_Idle_thread_body
257 *  must be provided and is the default IDLE thread body instead of
258 *  _Internal_threads_Idle_thread_body.
259 *
260 *  If FALSE, then use the generic IDLE thread body if the BSP does
261 *  not provide one.
262 *
263 *  This is intended to allow for supporting processors which have
264 *  a low power or idle mode.  When the IDLE thread is executed, then
265 *  the CPU can be powered down.
266 *
267 *  The order of precedence for selecting the IDLE thread body is:
268 *
269 *    1.  BSP provided
270 *    2.  CPU dependent (if provided)
271 *    3.  generic (if no BSP and no CPU dependent)
272 *
273 *  H8300 Specific Information:
274 *
275 *  XXX
276 *  The port initially called a BSP dependent routine called
277 *  IDLE_Monitor.  The idle task body can be overridden by
278 *  the BSP in newer versions of RTEMS.
279 */
280
281#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
282
283/*
284 *  Does the stack grow up (toward higher addresses) or down
285 *  (toward lower addresses)?
286 *
287 *  If TRUE, then the grows upward.
288 *  If FALSE, then the grows toward smaller addresses.
289 *
290 *  H8300 Specific Information:
291 *
292 *  XXX
293 */
294
295#define CPU_STACK_GROWS_UP               FALSE
296
297/*
298 *  The following is the variable attribute used to force alignment
299 *  of critical RTEMS structures.  On some processors it may make
300 *  sense to have these aligned on tighter boundaries than
301 *  the minimum requirements of the compiler in order to have as
302 *  much of the critical data area as possible in a cache line.
303 *
304 *  The placement of this macro in the declaration of the variables
305 *  is based on the syntactically requirements of the GNU C
306 *  "__attribute__" extension.  For example with GNU C, use
307 *  the following to force a structures to a 32 byte boundary.
308 *
309 *      __attribute__ ((aligned (32)))
310 *
311 *  NOTE:  Currently only the Priority Bit Map table uses this feature.
312 *         To benefit from using this, the data must be heavily
313 *         used so it will stay in the cache and used frequently enough
314 *         in the executive to justify turning this on.
315 *
316 *  H8300 Specific Information:
317 *
318 *  XXX
319 */
320
321#define CPU_STRUCTURE_ALIGNMENT
322
323/*
324 *  Define what is required to specify how the network to host conversion
325 *  routines are handled.
326 */
327
328#define CPU_BIG_ENDIAN                           TRUE
329#define CPU_LITTLE_ENDIAN                        FALSE
330
331/*
332 *  The following defines the number of bits actually used in the
333 *  interrupt field of the task mode.  How those bits map to the
334 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
335 *
336 *  H8300 Specific Information:
337 *
338 *  XXX
339 */
340
341#define CPU_MODES_INTERRUPT_MASK   0x00000001
342
343/*
344 *  Processor defined structures required for cpukit/score.
345 *
346 *  H8300 Specific Information:
347 *
348 *  XXX
349 */
350
351/* may need to put some structures here.  */
352
353/*
354 * Contexts
355 *
356 *  Generally there are 2 types of context to save.
357 *     1. Interrupt registers to save
358 *     2. Task level registers to save
359 *
360 *  This means we have the following 3 context items:
361 *     1. task level context stuff::  Context_Control
362 *     2. floating point task stuff:: Context_Control_fp
363 *     3. special interrupt level context :: Context_Control_interrupt
364 *
365 *  On some processors, it is cost-effective to save only the callee
366 *  preserved registers during a task context switch.  This means
367 *  that the ISR code needs to save those registers which do not
368 *  persist across function calls.  It is not mandatory to make this
369 *  distinctions between the caller/callee saves registers for the
370 *  purpose of minimizing context saved during task switch and on interrupts.
371 *  If the cost of saving extra registers is minimal, simplicity is the
372 *  choice.  Save the same context on interrupt entry as for tasks in
373 *  this case.
374 *
375 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
376 *  care should be used in designing the context area.
377 *
378 *  On some CPUs with hardware floating point support, the Context_Control_fp
379 *  structure will not be used or it simply consist of an array of a
380 *  fixed number of bytes.   This is done when the floating point context
381 *  is dumped by a "FP save context" type instruction and the format
382 *  is not really defined by the CPU.  In this case, there is no need
383 *  to figure out the exact format -- only the size.  Of course, although
384 *  this is enough information for RTEMS, it is probably not enough for
385 *  a debugger such as gdb.  But that is another problem.
386 *
387 *  H8300 Specific Information:
388 *
389 *  XXX
390 */
391
392#ifndef ASM
393
394#define nogap __attribute__ ((packed))
395
396typedef struct {
397    uint16_t    ccr nogap;
398    void        *er7 nogap;
399    void        *er6 nogap;
400    uint32_t    er5 nogap;
401    uint32_t    er4 nogap;
402    uint32_t    er3 nogap;
403    uint32_t    er2 nogap;
404    uint32_t    er1 nogap;
405    uint32_t    er0 nogap;
406    uint32_t    xxx nogap;
407} Context_Control;
408
409#define _CPU_Context_Get_SP( _context ) \
410  (_context)->er7
411
412typedef struct {
413    double      some_float_register[2];
414} Context_Control_fp;
415
416typedef struct {
417    uint32_t   special_interrupt_register;
418} CPU_Interrupt_frame;
419
420/*
421 *  This variable is optional.  It is used on CPUs on which it is difficult
422 *  to generate an "uninitialized" FP context.  It is filled in by
423 *  _CPU_Initialize and copied into the task's FP context area during
424 *  _CPU_Context_Initialize.
425 *
426 *  H8300 Specific Information:
427 *
428 *  XXX
429 */
430
431SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
432
433/*
434 *  Nothing prevents the porter from declaring more CPU specific variables.
435 *
436 *  H8300 Specific Information:
437 *
438 *  XXX
439 */
440
441/* XXX: if needed, put more variables here */
442
443/*
444 *  The size of the floating point context area.  On some CPUs this
445 *  will not be a "sizeof" because the format of the floating point
446 *  area is not defined -- only the size is.  This is usually on
447 *  CPUs with a "floating point save context" instruction.
448 *
449 *  H8300 Specific Information:
450 *
451 *  XXX
452 */
453
454#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
455
456#endif /* ASM */
457
458/*
459 *  Amount of extra stack (above minimum stack size) required by
460 *  system initialization thread.  Remember that in a multiprocessor
461 *  system the system intialization thread becomes the MP server thread.
462 *
463 *  H8300 Specific Information:
464 *
465 *  It is highly unlikely the H8300 will get used in a multiprocessor system.
466 */
467
468#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
469
470/*
471 *  This defines the number of entries in the ISR_Vector_table managed
472 *  by RTEMS.
473 *
474 *  H8300 Specific Information:
475 *
476 *  XXX
477 */
478
479#define CPU_INTERRUPT_NUMBER_OF_VECTORS      64
480#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
481
482/*
483 *  This is defined if the port has a special way to report the ISR nesting
484 *  level.  Most ports maintain the variable _ISR_Nest_level.
485 */
486
487#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
488
489/*
490 *  Should be large enough to run all RTEMS tests.  This ensures
491 *  that a "reasonable" small application should not have any problems.
492 *
493 *  H8300 Specific Information:
494 *
495 *  XXX
496 */
497
498#define CPU_STACK_MINIMUM_SIZE          (1536)
499
500/*
501 *  CPU's worst alignment requirement for data types on a byte boundary.  This
502 *  alignment does not take into account the requirements for the stack.
503 *
504 *  H8300 Specific Information:
505 *
506 *  XXX
507 */
508
509#define CPU_ALIGNMENT              8
510
511/*
512 *  This number corresponds to the byte alignment requirement for the
513 *  heap handler.  This alignment requirement may be stricter than that
514 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
515 *  common for the heap to follow the same alignment requirement as
516 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
517 *  then this should be set to CPU_ALIGNMENT.
518 *
519 *  NOTE:  This does not have to be a power of 2.  It does have to
520 *         be greater or equal to than CPU_ALIGNMENT.
521 *
522 *  H8300 Specific Information:
523 *
524 *  XXX
525 */
526
527#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
528
529/*
530 *  This number corresponds to the byte alignment requirement for memory
531 *  buffers allocated by the partition manager.  This alignment requirement
532 *  may be stricter than that for the data types alignment specified by
533 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
534 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
535 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
536 *
537 *  NOTE:  This does not have to be a power of 2.  It does have to
538 *         be greater or equal to than CPU_ALIGNMENT.
539 *
540 *  H8300 Specific Information:
541 *
542 *  XXX
543 */
544
545#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
546
547/*
548 *  This number corresponds to the byte alignment requirement for the
549 *  stack.  This alignment requirement may be stricter than that for the
550 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
551 *  is strict enough for the stack, then this should be set to 0.
552 *
553 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
554 *
555 *  H8300 Specific Information:
556 *
557 *  XXX
558 */
559
560#define CPU_STACK_ALIGNMENT        2
561
562/*
563 *  ISR handler macros
564 */
565
566/*
567 *  Support routine to initialize the RTEMS vector table after it is allocated.
568 */
569
570#define _CPU_Initialize_vectors()
571
572/* COPE With Brain dead version of GCC distributed with Hitachi HIView Tools.
573   Note requires ISR_Level be uint16_t or assembler croaks.
574*/
575
576#if (__GNUC__ == 2 && __GNUC_MINOR__ == 7 )
577
578
579/*
580 *  Disable all interrupts for an RTEMS critical section.  The previous
581 *  level is returned in _level.
582 */
583
584#define _CPU_ISR_Disable( _isr_cookie ) \
585  do { \
586    asm volatile( "stc.w ccr, @-er7 ;\n orc #0xC0,ccr ;\n mov.w @er7+,%0" :  : "r" (_isr_cookie) ); \
587  } while (0)
588
589
590/*
591 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
592 *  This indicates the end of an RTEMS critical section.  The parameter
593 *  _level is not modified.
594 */
595
596
597#define _CPU_ISR_Enable( _isr_cookie )  \
598  do { \
599    asm volatile( "mov.w %0,@-er7 ;\n ldc.w @er7+, ccr" :  : "r" (_isr_cookie) ); \
600  } while (0)
601
602
603/*
604 *  This temporarily restores the interrupt to _level before immediately
605 *  disabling them again.  This is used to divide long RTEMS critical
606 *  sections into two or more parts.  The parameter _level is not
607 * modified.
608 */
609
610
611#define _CPU_ISR_Flash( _isr_cookie ) \
612  do { \
613    asm volatile( "mov.w %0,@-er7 ;\n ldc.w @er7+, ccr ;\n orc #0xC0,ccr" :  : "r" (_isr_cookie) ); \
614  } while (0)
615
616/* end of ISR handler macros */
617
618#else /* modern gcc version */
619
620/*
621 *  Disable all interrupts for an RTEMS critical section.  The previous
622 *  level is returned in _level.
623 *
624 *  H8300 Specific Information:
625 *
626 *  XXX
627 */
628
629#if defined(__H8300H__) || defined(__H8300S__)
630#define _CPU_ISR_Disable( _isr_cookie ) \
631  do { \
632    unsigned char __ccr; \
633    asm volatile( "stc ccr, %0 ; orc #0x80,ccr " \
634             : "=m" (__ccr) /* : "0" (__ccr) */ ); \
635    (_isr_cookie) = __ccr; \
636  } while (0)
637#else
638#define _CPU_ISR_Disable( _isr_cookie ) (_isr_cookie) = 0
639#endif
640
641
642/*
643 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
644 *  This indicates the end of an RTEMS critical section.  The parameter
645 *  _level is not modified.
646 *
647 *  H8300 Specific Information:
648 *
649 *  XXX
650 */
651
652#if defined(__H8300H__) || defined(__H8300S__)
653#define _CPU_ISR_Enable( _isr_cookie )  \
654  do { \
655    unsigned char __ccr = (unsigned char) (_isr_cookie); \
656    asm volatile( "ldc %0, ccr" :  : "m" (__ccr) ); \
657  } while (0)
658#else
659#define _CPU_ISR_Enable( _isr_cookie )
660#endif
661
662/*
663 *  This temporarily restores the interrupt to _level before immediately
664 *  disabling them again.  This is used to divide long RTEMS critical
665 *  sections into two or more parts.  The parameter _level is not
666 *  modified.
667 *
668 *  H8300 Specific Information:
669 *
670 *  XXX
671 */
672
673#if defined(__H8300H__) || defined(__H8300S__)
674#define _CPU_ISR_Flash( _isr_cookie ) \
675  do { \
676    unsigned char __ccr = (unsigned char) (_isr_cookie); \
677    asm volatile( "ldc %0, ccr ; orc #0x80,ccr " :  : "m" (__ccr) ); \
678  } while (0)
679#else
680#define _CPU_ISR_Flash( _isr_cookie )
681#endif
682
683#endif /* end of old gcc */
684
685
686/*
687 *  Map interrupt level in task mode onto the hardware that the CPU
688 *  actually provides.  Currently, interrupt levels which do not
689 *  map onto the CPU in a generic fashion are undefined.  Someday,
690 *  it would be nice if these were "mapped" by the application
691 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
692 *  8 - 255 would be available for bsp/application specific meaning.
693 *  This could be used to manage a programmable interrupt controller
694 *  via the rtems_task_mode directive.
695 *
696 *  H8300 Specific Information:
697 *
698 *  XXX
699 */
700
701#define _CPU_ISR_Set_level( _new_level ) \
702  { \
703    if ( _new_level ) asm volatile ( "orc #0x80,ccr\n" ); \
704    else              asm volatile ( "andc #0x7f,ccr\n" ); \
705  }
706
707#ifndef ASM
708
709uint32_t   _CPU_ISR_Get_level( void );
710
711/* end of ISR handler macros */
712
713/* Context handler macros */
714
715/*
716 *  Initialize the context to a state suitable for starting a
717 *  task after a context restore operation.  Generally, this
718 *  involves:
719 *
720 *     - setting a starting address
721 *     - preparing the stack
722 *     - preparing the stack and frame pointers
723 *     - setting the proper interrupt level in the context
724 *     - initializing the floating point context
725 *
726 *  This routine generally does not set any unnecessary register
727 *  in the context.  The state of the "general data" registers is
728 *  undefined at task start time.
729 *
730 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
731 *        point thread.  This is typically only used on CPUs where the
732 *        FPU may be easily disabled by software such as on the SPARC
733 *        where the PSR contains an enable FPU bit.
734 *
735 *  H8300 Specific Information:
736 *
737 *  XXX
738 */
739
740
741#define CPU_CCR_INTERRUPTS_ON  0x80
742#define CPU_CCR_INTERRUPTS_OFF 0x00
743
744#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
745                                   _isr, _entry_point, _is_fp ) \
746  /* Locate Me */ \
747  do { \
748    uintptr_t   _stack; \
749    \
750    if ( (_isr) ) (_the_context)->ccr = CPU_CCR_INTERRUPTS_OFF; \
751    else          (_the_context)->ccr = CPU_CCR_INTERRUPTS_ON; \
752    \
753    _stack = ((uintptr_t)(_stack_base)) + (_size) - 4; \
754    *((proc_ptr *)(_stack)) = (_entry_point); \
755     (_the_context)->er7     = (void *) _stack; \
756     (_the_context)->er6     = (void *) _stack; \
757     (_the_context)->er5     = 0; \
758     (_the_context)->er4     = 1; \
759     (_the_context)->er3     = 2; \
760  } while (0)
761
762
763/*
764 *  This routine is responsible for somehow restarting the currently
765 *  executing task.  If you are lucky, then all that is necessary
766 *  is restoring the context.  Otherwise, there will need to be
767 *  a special assembly routine which does something special in this
768 *  case.  Context_Restore should work most of the time.  It will
769 *  not work if restarting self conflicts with the stack frame
770 *  assumptions of restoring a context.
771 *
772 *  H8300 Specific Information:
773 *
774 *  XXX
775 */
776
777#define _CPU_Context_Restart_self( _the_context ) \
778   _CPU_Context_restore( (_the_context) );
779
780/*
781 *  The purpose of this macro is to allow the initial pointer into
782 *  a floating point context area (used to save the floating point
783 *  context) to be at an arbitrary place in the floating point
784 *  context area.
785 *
786 *  This is necessary because some FP units are designed to have
787 *  their context saved as a stack which grows into lower addresses.
788 *  Other FP units can be saved by simply moving registers into offsets
789 *  from the base of the context area.  Finally some FP units provide
790 *  a "dump context" instruction which could fill in from high to low
791 *  or low to high based on the whim of the CPU designers.
792 *
793 *  H8300 Specific Information:
794 *
795 *  XXX
796 */
797
798#define _CPU_Context_Fp_start( _base, _offset ) \
799   ( (void *) (_base) + (_offset) )
800
801/*
802 *  This routine initializes the FP context area passed to it to.
803 *  There are a few standard ways in which to initialize the
804 *  floating point context.  The code included for this macro assumes
805 *  that this is a CPU in which a "initial" FP context was saved into
806 *  _CPU_Null_fp_context and it simply copies it to the destination
807 *  context passed to it.
808 *
809 *  Other models include (1) not doing anything, and (2) putting
810 *  a "null FP status word" in the correct place in the FP context.
811 *
812 *  H8300 Specific Information:
813 *
814 *  XXX
815 */
816
817#define _CPU_Context_Initialize_fp( _destination ) \
818  { \
819   *(*(_destination)) = _CPU_Null_fp_context; \
820  }
821
822/* end of Context handler macros */
823
824/* Fatal Error manager macros */
825
826/*
827 *  This routine copies _error into a known place -- typically a stack
828 *  location or a register, optionally disables interrupts, and
829 *  halts/stops the CPU.
830 *
831 *  H8300 Specific Information:
832 *
833 *  XXX
834 */
835
836#define _CPU_Fatal_halt( _error ) \
837        printk("Fatal Error %d Halted\n",_error); \
838        for(;;)
839
840
841/* end of Fatal Error manager macros */
842
843/* Bitfield handler macros */
844
845/*
846 *  This routine sets _output to the bit number of the first bit
847 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
848 *  This type may be either 16 or 32 bits wide although only the 16
849 *  least significant bits will be used.
850 *
851 *  There are a number of variables in using a "find first bit" type
852 *  instruction.
853 *
854 *    (1) What happens when run on a value of zero?
855 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
856 *    (3) The numbering may be zero or one based.
857 *    (4) The "find first bit" instruction may search from MSB or LSB.
858 *
859 *  RTEMS guarantees that (1) will never happen so it is not a concern.
860 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
861 *  _CPU_Priority_bits_index().  These three form a set of routines
862 *  which must logically operate together.  Bits in the _value are
863 *  set and cleared based on masks built by _CPU_Priority_mask().
864 *  The basic major and minor values calculated by _Priority_Major()
865 *  and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
866 *  to properly range between the values returned by the "find first bit"
867 *  instruction.  This makes it possible for _Priority_Get_highest() to
868 *  calculate the major and directly index into the minor table.
869 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
870 *  is the first bit found.
871 *
872 *  This entire "find first bit" and mapping process depends heavily
873 *  on the manner in which a priority is broken into a major and minor
874 *  components with the major being the 4 MSB of a priority and minor
875 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
876 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
877 *  to the lowest priority.
878 *
879 *  If your CPU does not have a "find first bit" instruction, then
880 *  there are ways to make do without it.  Here are a handful of ways
881 *  to implement this in software:
882 *
883 *    - a series of 16 bit test instructions
884 *    - a "binary search using if's"
885 *    - _number = 0
886 *      if _value > 0x00ff
887 *        _value >>=8
888 *        _number = 8;
889 *
890 *      if _value > 0x0000f
891 *        _value >=8
892 *        _number += 4
893 *
894 *      _number += bit_set_table[ _value ]
895 *
896 *    where bit_set_table[ 16 ] has values which indicate the first
897 *      bit set
898 *
899 *  H8300 Specific Information:
900 *
901 *  XXX
902 */
903
904#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
905#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
906
907#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
908
909#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
910  { \
911    (_output) = 0;   /* do something to prevent warnings */ \
912  }
913
914#endif
915
916/* end of Bitfield handler macros */
917
918/*
919 *  This routine builds the mask which corresponds to the bit fields
920 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
921 *  for that routine.
922 *
923 *  H8300 Specific Information:
924 *
925 *  XXX
926 */
927
928#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
929
930#define _CPU_Priority_Mask( _bit_number ) \
931  ( 1 << (_bit_number) )
932
933#endif
934
935/*
936 *  This routine translates the bit numbers returned by
937 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
938 *  a major or minor component of a priority.  See the discussion
939 *  for that routine.
940 *
941 *  H8300 Specific Information:
942 *
943 *  XXX
944 */
945
946#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
947
948#define _CPU_Priority_bits_index( _priority ) \
949  (_priority)
950
951#endif
952
953/* end of Priority handler macros */
954
955/* functions */
956
957/*
958 *  _CPU_Initialize
959 *
960 *  This routine performs CPU dependent initialization.
961 *
962 *  H8300 Specific Information:
963 *
964 *  XXX
965 */
966
967void _CPU_Initialize(void);
968
969/*
970 *  _CPU_ISR_install_raw_handler
971 *
972 *  This routine installs a "raw" interrupt handler directly into the
973 *  processor's vector table.
974 *
975 *  H8300 Specific Information:
976 *
977 *  XXX
978 */
979
980void _CPU_ISR_install_raw_handler(
981  uint32_t    vector,
982  proc_ptr    new_handler,
983  proc_ptr   *old_handler
984);
985
986/*
987 *  _CPU_ISR_install_vector
988 *
989 *  This routine installs an interrupt vector.
990 *
991 *  H8300 Specific Information:
992 *
993 *  XXX
994 */
995
996void _CPU_ISR_install_vector(
997  uint32_t    vector,
998  proc_ptr    new_handler,
999  proc_ptr   *old_handler
1000);
1001
1002/*
1003 *  _CPU_Install_interrupt_stack
1004 *
1005 *  This routine installs the hardware interrupt stack pointer.
1006 *
1007 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
1008 *         is TRUE.
1009 *
1010 *  H8300 Specific Information:
1011 *
1012 *  XXX
1013 */
1014
1015void _CPU_Install_interrupt_stack( void );
1016
1017/*
1018 *  _CPU_Internal_threads_Idle_thread_body
1019 *
1020 *  This routine is the CPU dependent IDLE thread body.
1021 *
1022 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
1023 *         is TRUE.
1024 *
1025 *  H8300 Specific Information:
1026 *
1027 *  XXX
1028 */
1029
1030void *_CPU_Thread_Idle_body( uint32_t );
1031
1032/*
1033 *  _CPU_Context_switch
1034 *
1035 *  This routine switches from the run context to the heir context.
1036 *
1037 *  H8300 Specific Information:
1038 *
1039 *  XXX
1040 */
1041
1042void _CPU_Context_switch(
1043  Context_Control  *run,
1044  Context_Control  *heir
1045);
1046
1047/*
1048 *  _CPU_Context_restore
1049 *
1050 *  This routine is generallu used only to restart self in an
1051 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
1052 *
1053 *  NOTE: May be unnecessary to reload some registers.
1054 *
1055 *  H8300 Specific Information:
1056 *
1057 *  XXX
1058 */
1059
1060void _CPU_Context_restore(
1061  Context_Control *new_context
1062);
1063
1064/*
1065 *  _CPU_Context_save_fp
1066 *
1067 *  This routine saves the floating point context passed to it.
1068 *
1069 *  H8300 Specific Information:
1070 *
1071 *  XXX
1072 */
1073
1074void _CPU_Context_save_fp(
1075  Context_Control_fp **fp_context_ptr
1076);
1077
1078/*
1079 *  _CPU_Context_restore_fp
1080 *
1081 *  This routine restores the floating point context passed to it.
1082 *
1083 *  H8300 Specific Information:
1084 *
1085 *  XXX
1086 */
1087
1088void _CPU_Context_restore_fp(
1089  Context_Control_fp **fp_context_ptr
1090);
1091
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 *  H8300 Specific Information:
1112 *
1113 *  This is the generic implementation.
1114 */
1115
1116static inline uint32_t   CPU_swap_u32(
1117  uint32_t   value
1118)
1119{
1120  uint32_t   byte1, byte2, byte3, byte4, swapped;
1121
1122  byte4 = (value >> 24) & 0xff;
1123  byte3 = (value >> 16) & 0xff;
1124  byte2 = (value >> 8)  & 0xff;
1125  byte1 =  value        & 0xff;
1126
1127  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1128  return( swapped );
1129}
1130
1131#define CPU_swap_u16( value ) \
1132  (((value&0xff) << 8) | ((value >> 8)&0xff))
1133
1134/* to be provided by the BSP */
1135extern void H8BD_Install_IRQ(
1136  uint32_t      vector,
1137  proc_ptr      new_handler,
1138  proc_ptr      *old_handler );
1139
1140#endif /* ASM */
1141
1142#ifdef __cplusplus
1143}
1144#endif
1145
1146#endif
Note: See TracBrowser for help on using the repository browser.