portmacro.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*
  2. * FreeRTOS Kernel <DEVELOPMENT BRANCH>
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. * Copyright 2025-2026 Arm Limited and/or its affiliates
  5. * <open-source-office@arm.com>
  6. *
  7. * SPDX-License-Identifier: MIT
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  10. * this software and associated documentation files (the "Software"), to deal in
  11. * the Software without restriction, including without limitation the rights to
  12. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  13. * the Software, and to permit persons to whom the Software is furnished to do so,
  14. * subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in all
  17. * copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  21. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  22. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  23. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * https://www.FreeRTOS.org
  27. * https://github.com/FreeRTOS
  28. *
  29. */
  30. #ifndef PORTMACRO_H
  31. #define PORTMACRO_H
  32. /* *INDENT-OFF* */
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* *INDENT-ON* */
  37. /*-----------------------------------------------------------
  38. * Port specific definitions.
  39. *
  40. * The settings in this file configure FreeRTOS correctly for the given hardware
  41. * and compiler.
  42. *
  43. * These settings should not be altered.
  44. *-----------------------------------------------------------
  45. */
  46. /* Type definitions. */
  47. #define portCHAR char
  48. #define portFLOAT float
  49. #define portDOUBLE double
  50. #define portLONG long
  51. #define portSHORT short
  52. #define portSTACK_TYPE size_t
  53. #define portBASE_TYPE long
  54. #if !defined(__ASSEMBLER__)
  55. typedef portSTACK_TYPE StackType_t;
  56. typedef portBASE_TYPE BaseType_t;
  57. typedef uint64_t UBaseType_t;
  58. typedef uint64_t TickType_t;
  59. #define portMAX_DELAY ( ( TickType_t ) 0xffffffffffffffff )
  60. #endif /* if !defined(__ASSEMBLER__) */
  61. /* 64-bit tick type on a 64-bit architecture, so reads of the tick count do
  62. * not need to be guarded with a critical section. */
  63. #define portTICK_TYPE_IS_ATOMIC 1
  64. /*-----------------------------------------------------------*/
  65. /* Hardware specifics. */
  66. #define portSTACK_GROWTH ( -1 )
  67. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  68. #define portBYTE_ALIGNMENT 16
  69. #define portPOINTER_SIZE_TYPE uint64_t
  70. /*-----------------------------------------------------------*/
  71. /* Task utilities. */
  72. #if !defined(__ASSEMBLER__)
  73. /* Called at the end of an ISR that can cause a context switch. */
  74. #if ( configNUMBER_OF_CORES == 1 )
  75. #define portEND_SWITCHING_ISR( xSwitchRequired ) \
  76. { \
  77. extern uint64_t ullPortYieldRequired; \
  78. \
  79. if( xSwitchRequired != pdFALSE ) \
  80. { \
  81. ullPortYieldRequired = pdTRUE; \
  82. } \
  83. }
  84. #else
  85. #define portEND_SWITCHING_ISR( xSwitchRequired ) \
  86. { \
  87. extern uint64_t ullPortYieldRequired[ configNUMBER_OF_CORES ]; \
  88. \
  89. if( xSwitchRequired != pdFALSE ) \
  90. { \
  91. ullPortYieldRequired[ portGET_CORE_ID() ] = pdTRUE; \
  92. } \
  93. }
  94. #endif /* if ( configNUMBER_OF_CORES == 1 ) */
  95. #endif /* if !defined(__ASSEMBLER__) */
  96. /**
  97. * @brief SVC numbers.
  98. */
  99. #define portSVC_SYSTEM_CALL_EXIT 104
  100. #define portSVC_YIELD 105
  101. #define portSVC_START_FIRST_TASK 106
  102. #define portSVC_DISABLE_INTERRUPTS 107
  103. #define portSVC_ENABLE_INTERRUPTS 108
  104. #define portSVC_GET_CORE_ID 109
  105. #define portSVC_MASK_ALL_INTERRUPTS 110
  106. #define portSVC_UNMASK_ALL_INTERRUPTS 111
  107. #define portSVC_UNMASK_INTERRUPTS 112
  108. #define portSVC_CHECK_PRIVILEGE 113
  109. #define portSVC_SAVE_TASK_CONTEXT 114
  110. #define portSVC_RESTORE_CONTEXT 115
  111. #define portSVC_DELETE_CURRENT_TASK 116
  112. #define portSVC_INTERRUPT_CORE 117
  113. #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
  114. #define portYIELD() __asm volatile ( "SVC %0" : : "i" ( portSVC_YIELD ) : "memory" )
  115. /*-----------------------------------------------------------
  116. * Critical section control
  117. *----------------------------------------------------------*/
  118. #if !defined(__ASSEMBLER__)
  119. extern UBaseType_t vTaskEnterCriticalFromISR( void );
  120. extern void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus );
  121. extern UBaseType_t uxPortSetInterruptMask( void );
  122. extern UBaseType_t uxPortSetInterruptMaskFromISR( void );
  123. extern void vPortClearInterruptMask( UBaseType_t uxNewMaskValue );
  124. extern void vPortClearInterruptMaskFromISR( UBaseType_t uxNewMaskValue );
  125. extern void vInterruptCore( uint32_t ulInterruptID, uint8_t ucCoreID );
  126. #endif /* if !defined(__ASSEMBLER__) */
  127. /* Use SVC so this is safe from EL0. EL1 sites in the port use direct MSR. */
  128. #define portDISABLE_INTERRUPTS() __asm volatile ( "SVC %0" : : "i" ( portSVC_DISABLE_INTERRUPTS ) : "memory" )
  129. #define portENABLE_INTERRUPTS() __asm volatile ( "SVC %0" : : "i" ( portSVC_ENABLE_INTERRUPTS ) : "memory" )
  130. /* In all GICs 255 can be written to the priority mask register to unmask all
  131. * (but the lowest) interrupt priority. */
  132. #define portUNMASK_VALUE ( 0xFFUL )
  133. #if !defined(__ASSEMBLER__)
  134. /* These macros do not globally disable/enable interrupts. They do mask off
  135. * interrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */
  136. #if ( configNUMBER_OF_CORES == 1 )
  137. extern void vPortEnterCritical( void );
  138. extern void vPortExitCritical( void );
  139. #define portENTER_CRITICAL() vPortEnterCritical()
  140. #define portEXIT_CRITICAL() vPortExitCritical()
  141. #else
  142. #define portENTER_CRITICAL() vTaskEnterCritical()
  143. #define portEXIT_CRITICAL() vTaskExitCritical()
  144. #endif
  145. #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()
  146. #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortClearInterruptMaskFromISR( x )
  147. #define portENTER_CRITICAL_FROM_ISR() vTaskEnterCriticalFromISR()
  148. #define portEXIT_CRITICAL_FROM_ISR( x ) vTaskExitCriticalFromISR( x )
  149. #endif /* if !defined(__ASSEMBLER__) */
  150. /*-----------------------------------------------------------*/
  151. /* Task function macros as described on the FreeRTOS.org WEB site. These are
  152. * not required for this port but included in case common demo code that uses these
  153. * macros is used. */
  154. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
  155. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
  156. #if !defined(__ASSEMBLER__)
  157. /* Prototype of the FreeRTOS tick handler. This must be installed as the
  158. * handler for whichever peripheral is used to generate the RTOS tick. */
  159. void FreeRTOS_Tick_Handler( void );
  160. #endif /* if !defined(__ASSEMBLER__) */
  161. #define portTASK_NO_FPU_CONTEXT_BY_DEFAULT ( 1U )
  162. #define portTASK_HAVE_FPU_CONTEXT_BY_DEFAULT ( 2U )
  163. /* If configUSE_TASK_FPU_SUPPORT is set to portTASK_NO_FPU_CONTEXT_BY_DEFAULT (1U)
  164. * (or left undefined) then tasks are created without an FPU context and
  165. * must call vPortTaskUsesFPU() to give themselves an FPU context before
  166. * using any FPU instructions. If configUSE_TASK_FPU_SUPPORT is set to
  167. * portTASK_HAVE_FPU_CONTEXT_BY_DEFAULT (2U) then all tasks will have an FPU context
  168. * by default. */
  169. #if ( configUSE_TASK_FPU_SUPPORT == portTASK_NO_FPU_CONTEXT_BY_DEFAULT )
  170. void vPortTaskUsesFPU( void );
  171. #else
  172. /* Each task has an FPU context already, so define this function away to
  173. * nothing to prevent it from being called accidentally. */
  174. #define vPortTaskUsesFPU()
  175. #endif
  176. #define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()
  177. #define portLOWEST_INTERRUPT_PRIORITY ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )
  178. #define portLOWEST_USABLE_INTERRUPT_PRIORITY ( portLOWEST_INTERRUPT_PRIORITY - 1UL )
  179. /* Architecture specific optimisations. */
  180. #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
  181. #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
  182. #endif
  183. #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
  184. /* Store/clear the ready priorities in a bit map. */
  185. #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
  186. #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
  187. #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __builtin_clz( uxReadyPriorities ) )
  188. #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
  189. #if ( configASSERT_DEFINED == 1 )
  190. void vPortValidateInterruptPriority( void );
  191. #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
  192. #endif /* configASSERT */
  193. #define portNOP() __asm volatile ( "NOP" )
  194. #define portINLINE __inline
  195. /* The number of bits to shift for an interrupt priority is dependent on the
  196. * number of bits implemented by the interrupt controller. */
  197. #if configUNIQUE_INTERRUPT_PRIORITIES == 16
  198. #define portPRIORITY_SHIFT 4
  199. #define portMAX_BINARY_POINT_VALUE 3
  200. #elif configUNIQUE_INTERRUPT_PRIORITIES == 32
  201. #define portPRIORITY_SHIFT 3
  202. #define portMAX_BINARY_POINT_VALUE 2
  203. #elif configUNIQUE_INTERRUPT_PRIORITIES == 64
  204. #define portPRIORITY_SHIFT 2
  205. #define portMAX_BINARY_POINT_VALUE 1
  206. #elif configUNIQUE_INTERRUPT_PRIORITIES == 128
  207. #define portPRIORITY_SHIFT 1
  208. #define portMAX_BINARY_POINT_VALUE 0
  209. #elif configUNIQUE_INTERRUPT_PRIORITIES == 256
  210. #define portPRIORITY_SHIFT 0
  211. #define portMAX_BINARY_POINT_VALUE 0
  212. #else /* if configUNIQUE_INTERRUPT_PRIORITIES == 16 */
  213. #error Invalid configUNIQUE_INTERRUPT_PRIORITIES setting. configUNIQUE_INTERRUPT_PRIORITIES must be set to the number of unique priorities implemented by the target hardware
  214. #endif /* if configUNIQUE_INTERRUPT_PRIORITIES == 16 */
  215. #define portINTERRUPT_PRIORITY_REGISTER_OFFSET ( 0x400U )
  216. #define portYIELD_CORE_INT_ID ( 0x0U )
  217. #define portMAX_API_PRIORITY_MASK ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT )
  218. #if ( configNUMBER_OF_CORES > 1 )
  219. #if !defined(__ASSEMBLER__)
  220. typedef enum
  221. {
  222. eIsrLock = 0,
  223. eTaskLock,
  224. eLockCount
  225. } ePortRTOSLock;
  226. extern volatile uint64_t ullCriticalNestings[ configNUMBER_OF_CORES ];
  227. extern void vPortRecursiveLock( uint8_t ucCoreID,
  228. ePortRTOSLock eLockNum,
  229. BaseType_t uxAcquire );
  230. extern uint8_t ucPortGetCoreID( void );
  231. extern uint8_t ucPortGetCoreIDFromIsr( void );
  232. #endif /* if !defined(__ASSEMBLER__) */
  233. #define portSET_INTERRUPT_MASK() uxPortSetInterruptMask()
  234. #define portCLEAR_INTERRUPT_MASK( x ) vPortClearInterruptMask( x )
  235. #define portMAX_CORE_COUNT configNUMBER_OF_CORES
  236. #define portGET_CORE_ID() ucPortGetCoreID()
  237. #define portGET_CORE_ID_FROM_ISR() ucPortGetCoreIDFromIsr()
  238. /* Use SGI 0 as the yield core interrupt. */
  239. #define portYIELD_CORE( xCoreID ) vInterruptCore( portYIELD_CORE_INT_ID, ( uint8_t ) xCoreID )
  240. #define portRELEASE_ISR_LOCK( xCoreID ) vPortRecursiveLock( ( uint8_t ) xCoreID, eIsrLock, pdFALSE )
  241. #define portGET_ISR_LOCK( xCoreID ) vPortRecursiveLock( ( uint8_t ) xCoreID, eIsrLock, pdTRUE )
  242. #define portRELEASE_TASK_LOCK( xCoreID ) vPortRecursiveLock( ( uint8_t ) xCoreID, eTaskLock, pdFALSE )
  243. #define portGET_TASK_LOCK( xCoreID ) vPortRecursiveLock( ( uint8_t ) xCoreID, eTaskLock, pdTRUE )
  244. #define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( ullCriticalNestings[ ( uint8_t ) xCoreID ] )
  245. #define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( ullCriticalNestings[ ( uint8_t ) xCoreID ] = ( x ) )
  246. #define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( ullCriticalNestings[ ( uint8_t ) xCoreID ]++ )
  247. #define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( ullCriticalNestings[ ( uint8_t ) xCoreID ]-- )
  248. #endif /* configNUMBER_OF_CORES > 1 */
  249. #define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
  250. /**
  251. * @brief MPU specific constants.
  252. */
  253. #if ( configENABLE_MPU == 1 )
  254. #if !defined(__ASSEMBLER__)
  255. extern BaseType_t xPortIsTaskPrivileged( void );
  256. #endif /* if !defined(__ASSEMBLER__) */
  257. /* Device memory attributes used in MAIR_EL1 registers.
  258. *
  259. * 8-bit values encoded as follows:
  260. * Bit[7:4] - 0000 - Device Memory
  261. * Bit[3:2] - 00 --> Device-nGnRnE
  262. * 01 --> Device-nGnRE
  263. * 10 --> Device-nGRE
  264. * 11 --> Device-GRE
  265. * Bit[1:0] - 00.
  266. */
  267. #define portMPU_DEVICE_MEMORY_nGnRnE ( 0x00 )
  268. #define portMPU_DEVICE_MEMORY_nGnRE ( 0x04 )
  269. #define portMPU_DEVICE_MEMORY_nGRE ( 0x08 )
  270. #define portMPU_DEVICE_MEMORY_GRE ( 0x0C )
  271. /* MPU settings that can be overridden in FreeRTOSConfig.h. */
  272. #ifndef configTOTAL_MPU_REGIONS
  273. #define configTOTAL_MPU_REGIONS ( 16UL )
  274. #endif
  275. #define portPRIVILEGED_FLASH_REGION ( 0ULL ) /* Privileged flash region number. */
  276. #define portUNPRIVILEGED_FLASH_REGION ( 1ULL ) /* Unprivileged flash region number. */
  277. #define portUNPRIVILEGED_SYSCALLS_REGION ( 2ULL ) /* Unprivileged syscalls region number. */
  278. #define portPRIVILEGED_RAM_REGION ( 3ULL ) /* Privileged RAM region number. */
  279. #define portSTACK_REGION ( 4ULL ) /* Stack region number. */
  280. #define portSTACK_REGION_INDEX ( 0ULL ) /* Stack region index in the xRegionSettings array. */
  281. #define portFIRST_CONFIGURABLE_REGION ( 5ULL ) /* First user configurable region number. */
  282. #define portLAST_CONFIGURABLE_REGION ( configTOTAL_MPU_REGIONS - 1UL )
  283. #define portNUM_CONFIGURABLE_REGIONS ( ( portLAST_CONFIGURABLE_REGION - portFIRST_CONFIGURABLE_REGION ) + 1 )
  284. #define portTOTAL_NUM_REGIONS ( portNUM_CONFIGURABLE_REGIONS + 1 ) /* Plus one to make space for the stack region. */
  285. #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
  286. #define portACL_ENTRY_SIZE_BITS ( 32UL )
  287. #endif /* configENABLE_ACCESS_CONTROL_LIST == 1 */
  288. #if !defined(__ASSEMBLER__)
  289. /**
  290. * @brief Settings to define an MPU region.
  291. */
  292. typedef struct MPURegionSettings
  293. {
  294. uint64_t ullPrbarEl1; /**< PRBAR_EL1 for the region. */
  295. uint64_t ullPrlarEl1; /**< PRLAR_EL1 for the region. */
  296. } MPURegionSettings_t;
  297. #ifndef configSYSTEM_CALL_STACK_SIZE
  298. #define configSYSTEM_CALL_STACK_SIZE 128 /* must be defined to the desired size of the system call stack in words for using MPU wrappers v2. */
  299. #endif
  300. /**
  301. * @brief System call info.
  302. */
  303. typedef struct SYSTEM_CALL_INFO
  304. {
  305. /* Used to save both the user-mode stack pointer (SP_EL0) and link register (X30)
  306. * at system call entry so they can be restored or referenced safely even if the task
  307. * switches out while executing the system call.
  308. */
  309. uint64_t ullLinkRegisterAtSystemCallEntry;
  310. uint64_t ullUserSPAtSystemCallEntry;
  311. } xSYSTEM_CALL_INFO;
  312. #endif /* if !defined(__ASSEMBLER__) */
  313. /**
  314. * @brief Task context as stored in the TCB.
  315. */
  316. #if ( configENABLE_FPU == 1 )
  317. /*
  318. * +-----------+------------+--------------------------------+-------------+------------------+
  319. * | Q0-Q31 | FPSR, FPCR | CRITICAL_NESTING, FPU_CONTEXT | X0-X30, XZR | INIT_PSTATE, PC |
  320. * +-----------+------------+--------------------------------+-------------+------------------+
  321. *
  322. * <-----------><-----------><-------------------------------><------------><----------------->
  323. * 64 2 2 32 2
  324. */
  325. #define MAX_CONTEXT_SIZE 102
  326. #else /* #if ( configENABLE_FPU == 1 ) */
  327. /*
  328. * +--------------------------------+-------------+------------------+
  329. * | CRITICAL_NESTING, FPU_CONTEXT | X0-X30, XZR | INIT_PSTATE, PC |
  330. * +--------------------------------+-------------+------------------+
  331. * <-------------------------------><------------><------------------>
  332. * 2 32 2
  333. */
  334. #define MAX_CONTEXT_SIZE 36
  335. #endif /* #if ( configENABLE_FPU == 1 ) */
  336. #if !defined(__ASSEMBLER__)
  337. typedef struct MPU_SETTINGS
  338. {
  339. uint64_t ullTaskUnprivilegedSP; /* Task's unprivileged user stack pointer. */
  340. uint64_t ullMairEl1; /* MAIR_EL1 for the task containing attributes. */
  341. MPURegionSettings_t xRegionsSettings[ portTOTAL_NUM_REGIONS ]; /* Settings for tasks' regions. */
  342. uint64_t ullContext[ MAX_CONTEXT_SIZE + configSYSTEM_CALL_STACK_SIZE ]; /* Task's saved context. */
  343. uint64_t ullTaskFlags;
  344. xSYSTEM_CALL_INFO xSystemCallInfo;
  345. #if ( configENABLE_ACCESS_CONTROL_LIST == 1 )
  346. uint32_t ulAccessControlList[ ( configPROTECTED_KERNEL_OBJECT_POOL_SIZE / portACL_ENTRY_SIZE_BITS ) + 1 ];
  347. #endif /* configENABLE_ACCESS_CONTROL_LIST */
  348. } xMPU_SETTINGS;
  349. #endif /* if !defined(__ASSEMBLER__) */
  350. #define portUSING_MPU_WRAPPERS ( 1 )
  351. #define portPRIVILEGE_BIT ( 0x80000000UL )
  352. /* Normal memory attributes used in MAIR_EL1 registers. */
  353. #define portMPU_NORMAL_MEMORY_NON_CACHEABLE ( 0x44 ) /* Non-cacheable. */
  354. #define portMPU_NORMAL_MEMORY_BUFFERABLE_CACHEABLE ( 0xFF ) /* Non-Transient, Write-back, Read-Allocate and Write-Allocate. */
  355. #define portMPU_MAIR_EL1_ATTR0_POS ( 0UL )
  356. #define portMPU_MAIR_EL1_ATTR0_MASK ( 0x00000000000000ffULL )
  357. #define portMPU_MAIR_EL1_ATTR1_POS ( 8UL )
  358. #define portMPU_MAIR_EL1_ATTR1_MASK ( 0x000000000000ff00ULL )
  359. #define portMPU_MAIR_EL1_ATTR2_POS ( 16UL )
  360. #define portMPU_MAIR_EL1_ATTR2_MASK ( 0x0000000000ff0000ULL )
  361. #define portMPU_MAIR_EL1_ATTR3_POS ( 24UL )
  362. #define portMPU_MAIR_EL1_ATTR3_MASK ( 0x00000000ff000000ULL )
  363. #define portMPU_MAIR_EL1_ATTR4_POS ( 32UL )
  364. #define portMPU_MAIR_EL1_ATTR4_MASK ( 0x000000ff00000000ULL )
  365. #define portMPU_MAIR_EL1_ATTR5_POS ( 40UL )
  366. #define portMPU_MAIR_EL1_ATTR5_MASK ( 0x0000ff0000000000ULL )
  367. #define portMPU_MAIR_EL1_ATTR6_POS ( 48UL )
  368. #define portMPU_MAIR_EL1_ATTR6_MASK ( 0x00ff000000000000ULL )
  369. #define portMPU_MAIR_EL1_ATTR7_POS ( 56UL )
  370. #define portMPU_MAIR_EL1_ATTR7_MASK ( 0xff00000000000000ULL )
  371. #define portMPU_PRBAR_EL1_ADDRESS_MASK ( 0x0000FFFFFFFFFFC0ULL )
  372. #define portMPU_PRLAR_EL1_ADDRESS_MASK ( 0x0000FFFFFFFFFFC0ULL )
  373. #define portMPU_PRBAR_EL1_ACCESS_PERMISSIONS_MASK ( 3ULL<< 2ULL )
  374. #define portMPU_REGION_NON_SHAREABLE ( 0ULL << 4ULL )
  375. #define portMPU_REGION_OUTER_SHAREABLE ( 2ULL << 4ULL )
  376. #define portMPU_REGION_INNER_SHAREABLE ( 3ULL << 4ULL )
  377. #define portMPU_REGION_PRIVILEGED_READ_WRITE ( 0ULL << 2ULL )
  378. #define portMPU_REGION_READ_WRITE ( 1ULL << 2ULL )
  379. #define portMPU_REGION_PRIVILEGED_READ_ONLY ( 2ULL << 2ULL )
  380. #define portMPU_REGION_READ_ONLY ( 3ULL << 2ULL )
  381. #define portMPU_REGION_EXECUTE_NEVER ( 1ULL << 1ULL )
  382. #define portMPU_PRLAR_EL1_ATTR_INDEX0 ( 0ULL << 1ULL )
  383. #define portMPU_PRLAR_EL1_ATTR_INDEX1 ( 1ULL << 1ULL )
  384. #define portMPU_PRLAR_EL1_ATTR_INDEX2 ( 2ULL << 1ULL )
  385. #define portMPU_PRLAR_EL1_ATTR_INDEX3 ( 3ULL << 1ULL )
  386. #define portMPU_PRLAR_EL1_ATTR_INDEX4 ( 4ULL << 1ULL )
  387. #define portMPU_PRLAR_EL1_ATTR_INDEX5 ( 5ULL << 1ULL )
  388. #define portMPU_PRLAR_EL1_ATTR_INDEX6 ( 6ULL << 1ULL )
  389. #define portMPU_PRLAR_EL1_ATTR_INDEX7 ( 7ULL << 1ULL )
  390. #define portMPU_PRLAR_EL1_REGION_ENABLE ( 1ULL )
  391. #define portMPU_ENABLE_BIT ( 1ULL << 0ULL )
  392. #define portMPU_PRIV_BACKGROUND_ENABLE_BIT ( 1ULL << 17ULL )
  393. /* Max value that fits in a uint64_t type. */
  394. #define portUINT64_MAX ( ~( ( uint64_t ) 0 ) )
  395. #define portADD_UINT64_WILL_OVERFLOW( a, b ) ( ( a ) > ( portUINT64_MAX - ( b ) ) )
  396. /* Extract first address of the MPU region as encoded in the
  397. * PRBAR_EL1 register value. */
  398. #define portEXTRACT_FIRST_ADDRESS_FROM_PRBAR_EL1( prbar_el1 ) \
  399. ( ( prbar_el1 ) & portMPU_PRBAR_EL1_ADDRESS_MASK )
  400. /* Extract last address of the MPU region as encoded in the
  401. * PRLAR_EL1 register value. */
  402. #define portEXTRACT_LAST_ADDRESS_FROM_PRLAR_EL1( prlar_el1 ) \
  403. ( ( ( prlar_el1 ) & portMPU_PRLAR_EL1_ADDRESS_MASK ) | ~portMPU_PRLAR_EL1_ADDRESS_MASK )
  404. /* Does addr lies within [start, end] address range? */
  405. #define portIS_ADDRESS_WITHIN_RANGE( addr, start, end ) \
  406. ( ( ( addr ) >= ( start ) ) && ( ( addr ) <= ( end ) ) )
  407. /* Is the access request satisfied by the available permissions? */
  408. #define portIS_AUTHORIZED( accessRequest, permissions ) \
  409. ( ( ( permissions ) & ( accessRequest ) ) == accessRequest )
  410. /**
  411. * @brief Offsets in the task's stack (context).
  412. */
  413. #if ( configUSE_TASK_FPU_SUPPORT == portTASK_HAVE_FPU_CONTEXT_BY_DEFAULT )
  414. #define portOFFSET_TO_PC ( 68 )
  415. #define portOFFSET_TO_LR ( 70 )
  416. #define portOFFSET_TO_X0 ( 100 )
  417. #define portOFFSET_TO_X1 ( 101 )
  418. #define portOFFSET_TO_X2 ( 98 )
  419. #define portOFFSET_TO_X3 ( 99 )
  420. #else
  421. #define portOFFSET_TO_PC ( 2 )
  422. #define portOFFSET_TO_LR ( 4 )
  423. #define portOFFSET_TO_X0 ( 34 )
  424. #define portOFFSET_TO_X1 ( 35 )
  425. #define portOFFSET_TO_X2 ( 32 )
  426. #define portOFFSET_TO_X3 ( 33 )
  427. #endif
  428. /**
  429. * @brief Flag used to mark that a Task is privileged.
  430. *
  431. * @ingroup Port Privilege
  432. */
  433. #define portTASK_IS_PRIVILEGED_FLAG ( 1UL << 1UL )
  434. /**
  435. * @brief Checks whether or not the calling task is privileged.
  436. *
  437. * @return pdTRUE if the calling task is privileged, pdFALSE otherwise.
  438. */
  439. #define portIS_TASK_PRIVILEGED() xPortIsTaskPrivileged()
  440. #else
  441. #define portPRIVILEGE_BIT ( 0x0UL )
  442. #endif /* #if ( configENABLE_MPU == 1 ) */
  443. #define portPSTATE_I_BIT ( 0x7 )
  444. /* *INDENT-OFF* */
  445. #ifdef __cplusplus
  446. }
  447. #endif
  448. /* *INDENT-ON* */
  449. #endif /* PORTMACRO_H */