source: rtems/cpukit/score/cpu/h8300/rtems/score/cpu.h @ 224fbcd

Last change on this file since 224fbcd was 224fbcd, checked in by Joel Sherrill <joel.sherrill@…>, on 08/14/03 at 13:17:46

2003-08-14 Joel Sherrill <joel@…>

PR 455/bsps

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