source: rtems/cpukit/score/cpu/h8300/rtems/score/cpu.h @ 5bb38e15

4.104.115
Last change on this file since 5bb38e15 was 5bb38e15, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/04/09 at 05:25:30

Whitespace removal.

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