source: rtems/cpukit/score/cpu/h8300/rtems/score/cpu.h @ 2fd427c

4.104.114.95
Last change on this file since 2fd427c was 2fd427c, checked in by Joel Sherrill <joel.sherrill@…>, on 06/05/08 at 14:30:07

2008-06-05 Joel Sherrill <joel.sherrill@…>

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