37#ifndef _RTEMS_SCORE_CPU_H
38#define _RTEMS_SCORE_CPU_H
41#if defined(RTEMS_PARAVIRT)
42#include <rtems/score/paravirt.h>
45#include <libcpu/vectors.h>
63#define AARCH64_PSTATE_N (1LL << 31)
64#define AARCH64_PSTATE_Z (1LL << 30)
65#define AARCH64_PSTATE_C (1LL << 29)
66#define AARCH64_PSTATE_V (1LL << 28)
67#define AARCH64_PSTATE_D (1LL << 9)
68#define AARCH64_PSTATE_A (1LL << 8)
69#define AARCH64_PSTATE_I (1LL << 7)
70#define AARCH64_PSTATE_F (1LL << 6)
77#define CPU_SIMPLE_VECTORED_INTERRUPTS FALSE
79#define CPU_ISR_PASSES_FRAME_POINTER FALSE
81#define CPU_HARDWARE_FP FALSE
83#define CPU_SOFTWARE_FP FALSE
85#define CPU_ALL_TASKS_ARE_FP FALSE
87#define CPU_IDLE_TASK_IS_FP FALSE
89#define CPU_USE_DEFERRED_FP_SWITCH FALSE
91#define CPU_ENABLE_ROBUST_THREAD_DISPATCH TRUE
93#define CPU_STACK_GROWS_UP FALSE
95#if defined(AARCH64_MULTILIB_CACHE_LINE_MAX_64)
96 #define CPU_CACHE_LINE_BYTES 64
98 #define CPU_CACHE_LINE_BYTES 32
101#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
103#define CPU_MODES_INTERRUPT_MASK 0x1
105#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
107#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
109#define CPU_STACK_MINIMUM_SIZE (1024 * 8)
114#define CPU_SIZEOF_POINTER __SIZEOF_POINTER__
117#define CPU_ALIGNMENT 16
119#define CPU_HEAP_ALIGNMENT CPU_ALIGNMENT
122#define CPU_STACK_ALIGNMENT 16
124#define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
126#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
128#define CPU_USE_LIBC_INIT_FINI_ARRAY TRUE
130#define CPU_MAXIMUM_PROCESSORS 32
132#define AARCH64_CONTEXT_CONTROL_THREAD_ID_OFFSET 0x70
134#ifdef AARCH64_MULTILIB_VFP
135 #define AARCH64_CONTEXT_CONTROL_D8_OFFSET 0x78
138#define AARCH64_CONTEXT_CONTROL_ISR_DISPATCH_DISABLE 0x68
141 #if defined(AARCH64_MULTILIB_VFP)
142 #define AARCH64_CONTEXT_CONTROL_IS_EXECUTING_OFFSET 0xb8
144 #define AARCH64_CONTEXT_CONTROL_IS_EXECUTING_OFFSET 0x78
148#define AARCH64_EXCEPTION_FRAME_SIZE 0x350
150#define AARCH64_EXCEPTION_FRAME_REGISTER_SP_OFFSET 0xF8
151#define AARCH64_EXCEPTION_FRAME_REGISTER_LR_OFFSET 0xF0
152#define AARCH64_EXCEPTION_FRAME_REGISTER_DAIF_OFFSET 0x108
153#define AARCH64_EXCEPTION_FRAME_REGISTER_SYNDROME_OFFSET 0x118
154#define AARCH64_EXCEPTION_FRAME_REGISTER_VECTOR_OFFSET 0x128
155#define AARCH64_EXCEPTION_FRAME_REGISTER_FPSR_OFFSET 0x138
156#define AARCH64_EXCEPTION_FRAME_REGISTER_Q0_OFFSET 0x150
168#pragma GCC diagnostic push
169#pragma GCC diagnostic ignored "-Wpedantic"
170typedef unsigned __int128 uint128_t;
171#pragma GCC diagnostic pop
174 uint64_t register_x19;
175 uint64_t register_x20;
176 uint64_t register_x21;
177 uint64_t register_x22;
178 uint64_t register_x23;
179 uint64_t register_x24;
180 uint64_t register_x25;
181 uint64_t register_x26;
182 uint64_t register_x27;
183 uint64_t register_x28;
184 uint64_t register_fp;
185 uint64_t register_lr;
186 uint64_t register_sp;
189#ifdef AARCH64_MULTILIB_VFP
190 uint64_t register_d8;
191 uint64_t register_d9;
192 uint64_t register_d10;
193 uint64_t register_d11;
194 uint64_t register_d12;
195 uint64_t register_d13;
196 uint64_t register_d14;
197 uint64_t register_d15;
200 volatile bool is_executing;
204static inline void _AARCH64_Data_memory_barrier(
void )
206 __asm__
volatile (
"dmb SY" : : :
"memory" );
209static inline void _AARCH64_Data_synchronization_barrier(
void )
211 __asm__
volatile (
"dsb SY" : : :
"memory" );
214static inline void _AARCH64_Instruction_synchronization_barrier(
void )
216 __asm__
volatile (
"isb" : : :
"memory" );
219void _CPU_ISR_Set_level( uint32_t level );
223#if defined(AARCH64_DISABLE_INLINE_ISR_DISABLE_ENABLE)
224uint64_t AArch64_interrupt_disable(
void );
225void AArch64_interrupt_enable( uint64_t isr_cookie );
226void AArch64_interrupt_flash( uint64_t isr_cookie );
228static inline uint64_t AArch64_interrupt_disable(
void )
233 "mrs %[isr_cookie], DAIF\n"
234 "msr DAIFSet, #0x2\n"
235 : [isr_cookie]
"=&r" (isr_cookie)
241static inline void AArch64_interrupt_enable( uint64_t isr_cookie )
244 "msr DAIF, %[isr_cookie]\n"
245 : : [isr_cookie]
"r" (isr_cookie)
249static inline void AArch64_interrupt_flash( uint64_t isr_cookie )
251 AArch64_interrupt_enable(isr_cookie);
252 AArch64_interrupt_disable();
256#define _CPU_ISR_Disable( _isr_cookie ) \
258 _isr_cookie = AArch64_interrupt_disable(); \
261#define _CPU_ISR_Enable( _isr_cookie ) \
262 AArch64_interrupt_enable( _isr_cookie )
264#define _CPU_ISR_Flash( _isr_cookie ) \
265 AArch64_interrupt_flash( _isr_cookie )
267static inline bool _CPU_ISR_Is_enabled( uint64_t isr_cookie )
269 return ( isr_cookie & AARCH64_PSTATE_I ) == 0;
272void _CPU_Context_Initialize(
274 void *stack_area_begin,
275 size_t stack_area_size,
277 void (*entry_point)(
void ),
282#define _CPU_Context_Get_SP( _context ) \
283 (uintptr_t)(_context)->register_sp
286 static inline bool _CPU_Context_Get_is_executing(
290 return context->is_executing;
293 static inline void _CPU_Context_Set_is_executing(
298 context->is_executing = is_executing;
303 #define _CPU_Start_multitasking( _heir ) _AArch64_Start_multitasking( _heir )
306#define _CPU_Context_Restart_self( _the_context ) \
307 _CPU_Context_restore( (_the_context) );
309#define _CPU_Context_Initialize_fp( _destination ) \
311 *(*(_destination)) = _CPU_Null_fp_context; \
319typedef void ( *CPU_ISR_handler )( void );
334 uint32_t _CPU_SMP_Initialize(
void );
336 bool _CPU_SMP_Start_processor( uint32_t cpu_index );
338 void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
340 void _CPU_SMP_Prepare_start_multitasking(
void );
348 uint32_t _CPU_SMP_Get_current_processor(
void );
350 void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
352 static inline void _AARCH64_Send_event(
void )
354 __asm__
volatile (
"sev" : : :
"memory" );
357 static inline void _AARCH64_Wait_for_event(
void )
359 __asm__
volatile (
"wfe" : : :
"memory" );
364static inline uint32_t CPU_swap_u32( uint32_t value )
366 uint32_t tmp = value;
367 __asm__
volatile (
"EOR %1, %0, %0, ROR #16\n"
368 "BIC %1, %1, #0xff0000\n"
369 "MOV %0, %0, ROR #8\n"
370 "EOR %0, %0, %1, LSR #8\n"
371 :
"=r" (value),
"=r" (tmp)
372 :
"0" (value),
"1" (tmp));
376static inline uint16_t CPU_swap_u16( uint16_t value )
378 return (uint16_t) (((value & 0xffU) << 8) | ((value >> 8) & 0xffU));
381typedef uint32_t CPU_Counter_ticks;
390 AARCH64_EXCEPTION_SP0_SYNCHRONOUS = 0,
391 AARCH64_EXCEPTION_SP0_IRQ = 1,
392 AARCH64_EXCEPTION_SP0_FIQ = 2,
393 AARCH64_EXCEPTION_SP0_SERROR = 3,
394 AARCH64_EXCEPTION_SPx_SYNCHRONOUS = 4,
395 AARCH64_EXCEPTION_SPx_IRQ = 5,
396 AARCH64_EXCEPTION_SPx_FIQ = 6,
397 AARCH64_EXCEPTION_SPx_SERROR = 7,
398 AARCH64_EXCEPTION_LEL64_SYNCHRONOUS = 8,
399 AARCH64_EXCEPTION_LEL64_IRQ = 9,
400 AARCH64_EXCEPTION_LEL64_FIQ = 10,
401 AARCH64_EXCEPTION_LEL64_SERROR = 11,
402 AARCH64_EXCEPTION_LEL32_SYNCHRONOUS = 12,
403 AARCH64_EXCEPTION_LEL32_IRQ = 13,
404 AARCH64_EXCEPTION_LEL32_FIQ = 14,
405 AARCH64_EXCEPTION_LEL32_SERROR = 15,
407 AARCH64_EXCEPTION_MAKE_ENUM_64_BIT = INT_MAX
408} AArch64_symbolic_exception_name;
410typedef void(*AArch64_Exception_Handler)(void);
411extern AArch64_Exception_Handler aarch64_exception_sp0_synchronous;
412extern AArch64_Exception_Handler aarch64_exception_sp0_irq;
413extern AArch64_Exception_Handler aarch64_exception_sp0_fiq;
414extern AArch64_Exception_Handler aarch64_exception_sp0_serror;
415extern AArch64_Exception_Handler aarch64_exception_spx_synchronous;
416extern AArch64_Exception_Handler aarch64_exception_spx_irq;
417extern AArch64_Exception_Handler aarch64_exception_spx_fiq;
418extern AArch64_Exception_Handler aarch64_exception_spx_serror;
419extern AArch64_Exception_Handler aarch64_exception_lel64_synchronous;
420extern AArch64_Exception_Handler aarch64_exception_lel64_irq;
421extern AArch64_Exception_Handler aarch64_exception_lel64_fiq;
422extern AArch64_Exception_Handler aarch64_exception_lel64_serror;
423extern AArch64_Exception_Handler aarch64_exception_lel32_synchronous;
424extern AArch64_Exception_Handler aarch64_exception_lel32_irq;
425extern AArch64_Exception_Handler aarch64_exception_lel32_fiq;
426extern AArch64_Exception_Handler aarch64_exception_lel32_serror;
428#define VECTOR_POINTER_OFFSET 0x78
429#define VECTOR_ENTRY_SIZE 0x80
430void _AArch64_Exception_interrupt_no_nest(
void );
431void _AArch64_Exception_interrupt_nest(
void );
432static inline AArch64_Exception_Handler AArch64_set_exception_handler(
433 AArch64_symbolic_exception_name exception,
434 AArch64_Exception_Handler handler
437 AArch64_Exception_Handler *target_address;
439 case AARCH64_EXCEPTION_SP0_SYNCHRONOUS:
440 target_address = &aarch64_exception_sp0_synchronous;
442 case AARCH64_EXCEPTION_SP0_IRQ:
443 target_address = &aarch64_exception_sp0_irq;
445 case AARCH64_EXCEPTION_SP0_FIQ:
446 target_address = &aarch64_exception_sp0_fiq;
448 case AARCH64_EXCEPTION_SP0_SERROR:
449 target_address = &aarch64_exception_sp0_serror;
451 case AARCH64_EXCEPTION_SPx_SYNCHRONOUS:
452 target_address = &aarch64_exception_spx_synchronous;
454 case AARCH64_EXCEPTION_SPx_IRQ:
455 target_address = &aarch64_exception_spx_irq;
457 case AARCH64_EXCEPTION_SPx_FIQ:
458 target_address = &aarch64_exception_spx_fiq;
460 case AARCH64_EXCEPTION_SPx_SERROR:
461 target_address = &aarch64_exception_spx_serror;
463 case AARCH64_EXCEPTION_LEL64_SYNCHRONOUS:
464 target_address = &aarch64_exception_lel64_synchronous;
466 case AARCH64_EXCEPTION_LEL64_IRQ:
467 target_address = &aarch64_exception_lel64_irq;
469 case AARCH64_EXCEPTION_LEL64_FIQ:
470 target_address = &aarch64_exception_lel64_fiq;
472 case AARCH64_EXCEPTION_LEL64_SERROR:
473 target_address = &aarch64_exception_lel64_serror;
475 case AARCH64_EXCEPTION_LEL32_SYNCHRONOUS:
476 target_address = &aarch64_exception_lel32_synchronous;
478 case AARCH64_EXCEPTION_LEL32_IRQ:
479 target_address = &aarch64_exception_lel32_irq;
481 case AARCH64_EXCEPTION_LEL32_FIQ:
482 target_address = &aarch64_exception_lel32_fiq;
484 case AARCH64_EXCEPTION_LEL32_SERROR:
485 target_address = &aarch64_exception_lel32_serror;
491 AArch64_Exception_Handler current_vector_pointer = *target_address;
494 *target_address = handler;
497 return current_vector_pointer;
501 uint64_t register_x0;
502 uint64_t register_x1;
503 uint64_t register_x2;
504 uint64_t register_x3;
505 uint64_t register_x4;
506 uint64_t register_x5;
507 uint64_t register_x6;
508 uint64_t register_x7;
509 uint64_t register_x8;
510 uint64_t register_x9;
511 uint64_t register_x10;
512 uint64_t register_x11;
513 uint64_t register_x12;
514 uint64_t register_x13;
515 uint64_t register_x14;
516 uint64_t register_x15;
517 uint64_t register_x16;
518 uint64_t register_x17;
519 uint64_t register_x18;
520 uint64_t register_x19;
521 uint64_t register_x20;
522 uint64_t register_x21;
523 uint64_t register_x22;
524 uint64_t register_x23;
525 uint64_t register_x24;
526 uint64_t register_x25;
527 uint64_t register_x26;
528 uint64_t register_x27;
529 uint64_t register_x28;
530 uint64_t register_fp;
532#ifdef AARCH64_MULTILIB_ARCH_V8_ILP32
533 uint32_t _register_lr_top;
535 uintptr_t register_sp;
536#ifdef AARCH64_MULTILIB_ARCH_V8_ILP32
537 uint32_t _register_sp_top;
540#ifdef AARCH64_MULTILIB_ARCH_V8_ILP32
541 uint32_t _register_pc_top;
543 uint64_t register_daif;
544 uint64_t register_cpsr;
545 uint64_t register_syndrome;
546 uint64_t register_fault_address;
547 AArch64_symbolic_exception_name vector;
548 uint64_t reserved_for_stack_alignment;
549 uint64_t register_fpsr;
550 uint64_t register_fpcr;
551 uint128_t register_q0;
552 uint128_t register_q1;
553 uint128_t register_q2;
554 uint128_t register_q3;
555 uint128_t register_q4;
556 uint128_t register_q5;
557 uint128_t register_q6;
558 uint128_t register_q7;
559 uint128_t register_q8;
560 uint128_t register_q9;
561 uint128_t register_q10;
562 uint128_t register_q11;
563 uint128_t register_q12;
564 uint128_t register_q13;
565 uint128_t register_q14;
566 uint128_t register_q15;
567 uint128_t register_q16;
568 uint128_t register_q17;
569 uint128_t register_q18;
570 uint128_t register_q19;
571 uint128_t register_q20;
572 uint128_t register_q21;
573 uint128_t register_q22;
574 uint128_t register_q23;
575 uint128_t register_q24;
576 uint128_t register_q25;
577 uint128_t register_q26;
578 uint128_t register_q27;
579 uint128_t register_q28;
580 uint128_t register_q29;
581 uint128_t register_q30;
582 uint128_t register_q31;
592void _CPU_Exception_disable_thread_dispatch(
void );
599void _CPU_Exception_frame_make_resume_next_instruction(
603void _AArch64_Exception_frame_copy(
ARM AArch64 Assembler Support API.
This header file provides basic definitions used by the API and the implementation.
#define RTEMS_NO_RETURN
Tells the compiler in a function declaration that this function does not return.
Definition: basedefs.h:386
uint32_t _CPU_ISR_Get_level(void)
Returns the interrupt level of the executing thread.
Definition: cpu.c:167
void * _CPU_Thread_Idle_body(uintptr_t ignored)
Definition: m68kidle.c:39
void _CPU_Initialize(void)
CPU initialization.
Definition: cpu.c:47
uintptr_t CPU_Uint32ptr
Definition: cpu.h:611
void _CPU_Exception_frame_print(const CPU_Exception_frame *frame)
Prints the exception frame via printk().
Definition: vectorexceptions.c:64
uint32_t _CPU_Counter_frequency(void)
Gets the current CPU counter frequency in Hz.
Definition: system-clocks.c:125
void _CPU_Context_switch(Context_Control *run, Context_Control *heir)
CPU switch context.
Definition: cpu_asm.c:110
CPU_Counter_ticks _CPU_Counter_read(void)
Gets the current CPU counter value.
Definition: system-clocks.c:130
The set of registers that specifies the complete processor state.
Definition: cpu.h:500
Thread register context.
Definition: cpu.h:173
uint64_t isr_dispatch_disable
This member is used for the external interrupt controller (EIC) support.
Definition: cpu.h:187