source: rtems/cpukit/score/cpu/m32c/include/rtems/score/cpu.h @ 511dc4b

5
Last change on this file since 511dc4b was 511dc4b, checked in by Sebastian Huber <sebastian.huber@…>, on 06/19/18 at 07:09:51

Rework initialization and interrupt stack support

Statically initialize the interrupt stack area
(_Configuration_Interrupt_stack_area_begin,
_Configuration_Interrupt_stack_area_end, and
_Configuration_Interrupt_stack_size) via <rtems/confdefs.h>. Place the
interrupt stack area in a special section ".rtemsstack.interrupt". Let
BSPs define the optimal placement of this section in their linker
command files (e.g. in a fast on-chip memory).

This change makes makes the CPU_HAS_SOFTWARE_INTERRUPT_STACK and
CPU_HAS_HARDWARE_INTERRUPT_STACK CPU port defines superfluous, since the
low level initialization code has all information available via global
symbols.

This change makes the CPU_ALLOCATE_INTERRUPT_STACK CPU port define
superfluous, since the interrupt stacks are allocated by confdefs.h for
all architectures. There is no need for BSP-specific linker command
file magic (except the section placement), see previous ARM linker
command file as a bad example.

Remove _CPU_Install_interrupt_stack(). Initialize the hardware
interrupt stack in _CPU_Initialize() if necessary (e.g.
m68k_install_interrupt_stack()).

The optional _CPU_Interrupt_stack_setup() is still useful to customize
the registration of the interrupt stack area in the per-CPU information.

The initialization stack can reuse the interrupt stack, since

  • interrupts are disabled during the sequential system initialization, and
  • the boot_card() function does not return.

This stack resuse saves memory.

Changes per architecture:

arm:

  • Mostly replace the linker symbol based configuration of stacks with the standard <rtems/confdefs.h> configuration via CONFIGURE_INTERRUPT_STACK_SIZE. The size of the FIQ, ABT and UND mode stack is still defined via linker symbols. These modes are rarely used in applications and the default values provided by the BSP should be sufficient in most cases.
  • Remove the bsp_processor_count linker symbol hack used for the SMP support. This is possible since the interrupt stack area is now allocated by the linker and not allocated from the heap. This makes some configure.ac stuff obsolete. Remove the now superfluous BSP variants altcycv_devkit_smp and realview_pbx_a9_qemu_smp.

bfin:

  • Remove unused magic linker command file allocation of initialization stack. Maybe a previous linker command file copy and paste problem? In the start.S the initialization stack is set to a hard coded value.

lm32, m32c, mips, nios2, riscv, sh, v850:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.

m68k:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.

powerpc:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.
  • Used dedicated memory region (REGION_RTEMSSTACK) for the interrupt stack on BSPs using the shared linkcmds.base (replacement for REGION_RWEXTRA).

sparc:

  • Remove the hard coded initialization stack. Use the interrupt stack for the initialization stack on the boot processor. This saves 16KiB of RAM.

Update #3459.

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