source: rtems/cpukit/score/cpu/moxie/include/rtems/score/cpu.h @ 26a09f2c

Last change on this file since 26a09f2c was 26a09f2c, checked in by Sebastian Huber <sebastian.huber@…>, on 06/22/21 at 13:08:37

score: Remove _CPU_Initialize_vectors()

This CPU port macro was not used. Since the _ISR_Vector_table[] is statically
allocated, CPU ports could initialize this table in _CPU_Initialize() if
necessary. Remove _CPU_Initialize_vectors() to simplify the CPU port
interface.

  • Property mode set to 100644
File size: 15.4 KB
Line 
1/**
2 * @file
3 *
4 * @addtogroup RTEMSScoreCPUMoxie
5 */
6
7/*
8 *  This include file contains information pertaining to the Moxie
9 *  processor.
10 *
11 *  Copyright (c) 2013  Anthony Green
12 *
13 *  Based on code with the following copyright..
14 *  COPYRIGHT (c) 1989-2006, 2010.
15 *  On-Line Applications Research Corporation (OAR).
16 *
17 *  The license and distribution terms for this file may be
18 *  found in the file LICENSE in this distribution or at
19 *  http://www.rtems.org/license/LICENSE.
20 */
21
22#ifndef _RTEMS_SCORE_CPU_H
23#define _RTEMS_SCORE_CPU_H
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#include <rtems/score/basedefs.h>
30#include <rtems/score/moxie.h>  /* pick up machine definitions */
31
32#include <rtems/bspIo.h>        /* printk */
33
34/* conditional compilation parameters */
35
36/*
37 *  Should this target use 16 or 32 bit object Ids?
38 *
39 */
40#define RTEMS_USE_32_BIT_OBJECT
41
42/*
43 *  Does the CPU follow the simple vectored interrupt model?
44 *
45 *  If TRUE, then RTEMS allocates the vector table it internally manages.
46 *  If FALSE, then the BSP is assumed to allocate and manage the vector
47 *  table
48 *
49 *  MOXIE Specific Information:
50 *
51 *  XXX document implementation including references if appropriate
52 */
53#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
54
55#define CPU_HARDWARE_FP FALSE
56
57#define CPU_SOFTWARE_FP FALSE
58
59#define CPU_ALL_TASKS_ARE_FP FALSE
60
61#define CPU_IDLE_TASK_IS_FP FALSE
62
63#define CPU_USE_DEFERRED_FP_SWITCH FALSE
64
65#define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE
66
67/*
68 *  Does the stack grow up (toward higher addresses) or down
69 *  (toward lower addresses)?
70 *
71 *  If TRUE, then the grows upward.
72 *  If FALSE, then the grows toward smaller addresses.
73 *
74 *  MOXIE Specific Information:
75 *
76 *  XXX
77 */
78#define CPU_STACK_GROWS_UP               FALSE
79
80/* FIXME: Is this the right value? */
81#define CPU_CACHE_LINE_BYTES 32
82
83#define CPU_STRUCTURE_ALIGNMENT
84
85/*
86 *  The following defines the number of bits actually used in the
87 *  interrupt field of the task mode.  How those bits map to the
88 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
89 *
90 *  MOXIE Specific Information:
91 *
92 *  XXX
93 */
94#define CPU_MODES_INTERRUPT_MASK   0x00000001
95
96#define CPU_MAXIMUM_PROCESSORS 32
97
98/*
99 *  Processor defined structures required for cpukit/score.
100 *
101 *  MOXIE Specific Information:
102 *
103 *  XXX
104 */
105
106/* may need to put some structures here.  */
107
108/*
109 * Contexts
110 *
111 *  Generally there are 2 types of context to save.
112 *     1. Interrupt registers to save
113 *     2. Task level registers to save
114 *
115 *  This means we have the following 3 context items:
116 *     1. task level context stuff::  Context_Control
117 *     2. floating point task stuff:: Context_Control_fp
118 *     3. special interrupt level context :: Context_Control_interrupt
119 *
120 *  On some processors, it is cost-effective to save only the callee
121 *  preserved registers during a task context switch.  This means
122 *  that the ISR code needs to save those registers which do not
123 *  persist across function calls.  It is not mandatory to make this
124 *  distinctions between the caller/callee saves registers for the
125 *  purpose of minimizing context saved during task switch and on interrupts.
126 *  If the cost of saving extra registers is minimal, simplicity is the
127 *  choice.  Save the same context on interrupt entry as for tasks in
128 *  this case.
129 *
130 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
131 *  care should be used in designing the context area.
132 *
133 *  On some CPUs with hardware floating point support, the Context_Control_fp
134 *  structure will not be used or it simply consist of an array of a
135 *  fixed number of bytes.   This is done when the floating point context
136 *  is dumped by a "FP save context" type instruction and the format
137 *  is not really defined by the CPU.  In this case, there is no need
138 *  to figure out the exact format -- only the size.  Of course, although
139 *  this is enough information for RTEMS, it is probably not enough for
140 *  a debugger such as gdb.  But that is another problem.
141 *
142 *  MOXIE Specific Information:
143 *
144 *  XXX
145 */
146
147#define nogap __attribute__ ((packed))
148
149typedef struct {
150    void        *fp nogap;
151    void        *sp nogap;
152    uint32_t    r0 nogap;
153    uint32_t    r1 nogap;
154    uint32_t    r2 nogap;
155    uint32_t    r3 nogap;
156    uint32_t    r4 nogap;
157    uint32_t    r5 nogap;
158    uint32_t    r6 nogap;
159    uint32_t    r7 nogap;
160    uint32_t    r8 nogap;
161    uint32_t    r9 nogap;
162    uint32_t    r10 nogap;
163    uint32_t    r11 nogap;
164    uint32_t    r12 nogap;
165    uint32_t    r13 nogap;
166} Context_Control;
167
168#define _CPU_Context_Get_SP( _context ) \
169  (_context)->sp
170
171typedef struct {
172    uint32_t   special_interrupt_register;
173} CPU_Interrupt_frame;
174
175/*
176 *  Amount of extra stack (above minimum stack size) required by
177 *  system initialization thread.  Remember that in a multiprocessor
178 *  system the system intialization thread becomes the MP server thread.
179 *
180 *  MOXIE Specific Information:
181 *
182 *  It is highly unlikely the MOXIE will get used in a multiprocessor system.
183 */
184#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
185
186/*
187 *  This defines the number of entries in the ISR_Vector_table managed
188 *  by RTEMS.
189 *
190 *  MOXIE Specific Information:
191 *
192 *  XXX
193 */
194#define CPU_INTERRUPT_NUMBER_OF_VECTORS      64
195#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER \
196    (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
197
198/*
199 *  This is defined if the port has a special way to report the ISR nesting
200 *  level.  Most ports maintain the variable _ISR_Nest_level.
201 */
202#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
203
204/*
205 *  Should be large enough to run all RTEMS tests.  This ensures
206 *  that a "reasonable" small application should not have any problems.
207 *
208 *  MOXIE Specific Information:
209 *
210 *  XXX
211 */
212#define CPU_STACK_MINIMUM_SIZE          (1536)
213
214/**
215 * Size of a pointer.
216 *
217 * This must be an integer literal that can be used by the assembler.  This
218 * value will be used to calculate offsets of structure members.  These
219 * offsets will be used in assembler code.
220 */
221#define CPU_SIZEOF_POINTER         4
222
223/*
224 *  CPU's worst alignment requirement for data types on a byte boundary.  This
225 *  alignment does not take into account the requirements for the stack.
226 *
227 *  MOXIE Specific Information:
228 *
229 *  XXX
230 */
231#define CPU_ALIGNMENT              8
232
233/*
234 *  This number corresponds to the byte alignment requirement for the
235 *  heap handler.  This alignment requirement may be stricter than that
236 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
237 *  common for the heap to follow the same alignment requirement as
238 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
239 *  then this should be set to CPU_ALIGNMENT.
240 *
241 *  NOTE:  This does not have to be a power of 2.  It does have to
242 *         be greater or equal to than CPU_ALIGNMENT.
243 *
244 *  MOXIE Specific Information:
245 *
246 *  XXX
247 */
248#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
249
250#define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
251
252#define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
253
254/*
255 *  ISR handler macros
256 */
257
258/*
259 *  Disable all interrupts for an RTEMS critical section.  The previous
260 *  level is returned in _level.
261 *
262 *  MOXIE Specific Information:
263 *
264 *  TODO: As of 7 October 2014, this method is not implemented.
265 */
266#define _CPU_ISR_Disable( _isr_cookie ) \
267  do { \
268    (_isr_cookie) = 0; \
269  } while (0)
270
271/*
272 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
273 *  This indicates the end of an RTEMS critical section.  The parameter
274 *  _level is not modified.
275 *
276 *  MOXIE Specific Information:
277 *
278 *  TODO: As of 7 October 2014, this method is not implemented.
279 */
280#define _CPU_ISR_Enable( _isr_cookie ) \
281  do { \
282    (_isr_cookie) = (_isr_cookie); \
283  } while (0)
284
285/*
286 *  This temporarily restores the interrupt to _level before immediately
287 *  disabling them again.  This is used to divide long RTEMS critical
288 *  sections into two or more parts.  The parameter _level is not
289 *  modified.
290 *
291 *  MOXIE Specific Information:
292 *
293 *  TODO: As of 7 October 2014, this method is not implemented.
294 */
295#define _CPU_ISR_Flash( _isr_cookie ) \
296  do { \
297    _CPU_ISR_Enable( _isr_cookie ); \
298    _CPU_ISR_Disable( _isr_cookie ); \
299  } while (0)
300
301RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level )
302{
303  return true;
304}
305
306/*
307 *  Map interrupt level in task mode onto the hardware that the CPU
308 *  actually provides.  Currently, interrupt levels which do not
309 *  map onto the CPU in a generic fashion are undefined.  Someday,
310 *  it would be nice if these were "mapped" by the application
311 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
312 *  8 - 255 would be available for bsp/application specific meaning.
313 *  This could be used to manage a programmable interrupt controller
314 *  via the rtems_task_mode directive.
315 *
316 *  MOXIE Specific Information:
317 *
318 *  TODO: As of 7 October 2014, this method is not implemented.
319 */
320#define _CPU_ISR_Set_level( _new_level )        \
321  {                                                     \
322    if (_new_level)   asm volatile ( "nop\n" );         \
323    else              asm volatile ( "nop\n" );         \
324  }
325
326uint32_t   _CPU_ISR_Get_level( void );
327
328/* end of ISR handler macros */
329
330/* Context handler macros */
331
332/*
333 *  Initialize the context to a state suitable for starting a
334 *  task after a context restore operation.  Generally, this
335 *  involves:
336 *
337 *     - setting a starting address
338 *     - preparing the stack
339 *     - preparing the stack and frame pointers
340 *     - setting the proper interrupt level in the context
341 *     - initializing the floating point context
342 *
343 *  This routine generally does not set any unnecessary register
344 *  in the context.  The state of the "general data" registers is
345 *  undefined at task start time.
346 *
347 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
348 *        point thread.  This is typically only used on CPUs where the
349 *        FPU may be easily disabled by software such as on the SPARC
350 *        where the PSR contains an enable FPU bit.
351 *
352 *  MOXIE Specific Information:
353 *
354 *  TODO: As of 7 October 2014, this method does not ensure that the context
355 *  is set up with interrupts disabled/enabled as requested.
356 */
357#define CPU_CCR_INTERRUPTS_ON  0x80
358#define CPU_CCR_INTERRUPTS_OFF 0x00
359
360#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
361                                 _isr, _entry_point, _is_fp, _tls_area ) \
362  /* Locate Me */                                                  \
363  do {                                                             \
364    uintptr_t   _stack;                                            \
365                                                                   \
366    (void) _is_fp; /* avoid warning for being unused */            \
367    (void) _isr;   /* avoid warning for being unused */            \
368    _stack = ((uintptr_t)(_stack_base)) + (_size) - 8;             \
369    *((void (**)(void))(_stack)) = (_entry_point);                 \
370    _stack -= 4;                                                   \
371    (_the_context)->fp = (void *)_stack;                           \
372    (_the_context)->sp = (void *)_stack;                           \
373  } while (0)
374
375
376/*
377 *  This routine is responsible for somehow restarting the currently
378 *  executing task.  If you are lucky, then all that is necessary
379 *  is restoring the context.  Otherwise, there will need to be
380 *  a special assembly routine which does something special in this
381 *  case.  Context_Restore should work most of the time.  It will
382 *  not work if restarting self conflicts with the stack frame
383 *  assumptions of restoring a context.
384 *
385 *  MOXIE Specific Information:
386 *
387 *  XXX
388 */
389#define _CPU_Context_Restart_self( _the_context ) \
390   _CPU_Context_restore( (_the_context) );
391
392/* end of Context handler macros */
393
394/* Fatal Error manager macros */
395
396/*
397 *  This routine copies _error into a known place -- typically a stack
398 *  location or a register, optionally disables interrupts, and
399 *  halts/stops the CPU.
400 *
401 *  MOXIE Specific Information:
402 *
403 *  XXX
404 */
405#define _CPU_Fatal_halt( _source, _error ) \
406        printk("Fatal Error %d.%lu Halted\n",_source,_error); \
407        for(;;)
408
409/* end of Fatal Error manager macros */
410
411#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
412
413#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
414
415/* functions */
416
417/*
418 *  _CPU_Initialize
419 *
420 *  This routine performs CPU dependent initialization.
421 *
422 *  MOXIE Specific Information:
423 *
424 *  XXX
425 */
426void _CPU_Initialize(void);
427
428typedef void ( *CPU_ISR_handler )( uint32_t );
429
430void _CPU_ISR_install_vector(
431  uint32_t         vector,
432  CPU_ISR_handler  new_handler,
433  CPU_ISR_handler *old_handler
434);
435
436void *_CPU_Thread_Idle_body( uintptr_t );
437
438/*
439 *  _CPU_Context_switch
440 *
441 *  This routine switches from the run context to the heir context.
442 *
443 *  MOXIE Specific Information:
444 *
445 *  XXX
446 */
447void _CPU_Context_switch(
448  Context_Control  *run,
449  Context_Control  *heir
450);
451
452/*
453 *  _CPU_Context_restore
454 *
455 *  This routine is generallu used only to restart self in an
456 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
457 *
458 *  NOTE: May be unnecessary to reload some registers.
459 *
460 *  MOXIE Specific Information:
461 *
462 *  XXX
463 */
464RTEMS_NO_RETURN void _CPU_Context_restore( Context_Control *new_context );
465
466/**
467 * @brief The set of registers that specifies the complete processor state.
468 *
469 * The CPU exception frame may be available in fatal error conditions like for
470 * example illegal opcodes, instruction fetch errors, or data access errors.
471 *
472 * @see rtems_fatal(), RTEMS_FATAL_SOURCE_EXCEPTION, and
473 * rtems_exception_frame_print().
474 */
475typedef struct {
476  uint32_t integer_registers [16];
477} CPU_Exception_frame;
478
479/**
480 * @brief Prints the exception frame via printk().
481 *
482 * @see rtems_fatal() and RTEMS_FATAL_SOURCE_EXCEPTION.
483 */
484void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
485
486/*  The following routine swaps the endian format of an unsigned int.
487 *  It must be static because it is referenced indirectly.
488 *
489 *  This version will work on any processor, but if there is a better
490 *  way for your CPU PLEASE use it.  The most common way to do this is to:
491 *
492 *     swap least significant two bytes with 16-bit rotate
493 *     swap upper and lower 16-bits
494 *     swap most significant two bytes with 16-bit rotate
495 *
496 *  Some CPUs have special instructions which swap a 32-bit quantity in
497 *  a single instruction (e.g. i486).  It is probably best to avoid
498 *  an "endian swapping control bit" in the CPU.  One good reason is
499 *  that interrupts would probably have to be disabled to ensure that
500 *  an interrupt does not try to access the same "chunk" with the wrong
501 *  endian.  Another good reason is that on some CPUs, the endian bit
502 *  endianness for ALL fetches -- both code and data -- so the code
503 *  will be fetched incorrectly.
504 *
505 *  MOXIE Specific Information:
506 *
507 *  This is the generic implementation.
508 */
509static inline uint32_t   CPU_swap_u32(
510  uint32_t   value
511)
512{
513  uint32_t   byte1, byte2, byte3, byte4, swapped;
514
515  byte4 = (value >> 24) & 0xff;
516  byte3 = (value >> 16) & 0xff;
517  byte2 = (value >> 8)  & 0xff;
518  byte1 =  value        & 0xff;
519
520  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
521  return( swapped );
522}
523
524#define CPU_swap_u16( value ) \
525  (((value&0xff) << 8) | ((value >> 8)&0xff))
526
527typedef uint32_t CPU_Counter_ticks;
528
529uint32_t _CPU_Counter_frequency( void );
530
531CPU_Counter_ticks _CPU_Counter_read( void );
532
533static inline CPU_Counter_ticks _CPU_Counter_difference(
534  CPU_Counter_ticks second,
535  CPU_Counter_ticks first
536)
537{
538  return second - first;
539}
540
541/** Type that can store a 32-bit integer or a pointer. */
542typedef uintptr_t CPU_Uint32ptr;
543
544#ifdef __cplusplus
545}
546#endif
547
548#endif
Note: See TracBrowser for help on using the repository browser.