33#ifndef _RTEMS_SCORE_NIOS2_UTILITY_H
34#define _RTEMS_SCORE_NIOS2_UTILITY_H
36#define NIOS2_CTLREG_INDEX_STATUS 0
37#define NIOS2_CTLREG_INDEX_ESTATUS 1
38#define NIOS2_CTLREG_INDEX_BSTATUS 2
39#define NIOS2_CTLREG_INDEX_IENABLE 3
40#define NIOS2_CTLREG_INDEX_IPENDING 4
41#define NIOS2_CTLREG_INDEX_CPUID 5
42#define NIOS2_CTLREG_INDEX_EXCEPTION 7
43#define NIOS2_CTLREG_INDEX_PTEADDR 8
44#define NIOS2_CTLREG_INDEX_TLBACC 9
45#define NIOS2_CTLREG_INDEX_TLBMISC 10
46#define NIOS2_CTLREG_INDEX_BADADDR 12
47#define NIOS2_CTLREG_INDEX_CONFIG 13
48#define NIOS2_CTLREG_INDEX_MPUBASE 14
49#define NIOS2_CTLREG_INDEX_MPUACC 15
51#define NIOS2_CONTEXT_OFFSET_R16 0
52#define NIOS2_CONTEXT_OFFSET_R17 4
53#define NIOS2_CONTEXT_OFFSET_R18 8
54#define NIOS2_CONTEXT_OFFSET_R19 12
55#define NIOS2_CONTEXT_OFFSET_R20 16
56#define NIOS2_CONTEXT_OFFSET_R21 20
57#define NIOS2_CONTEXT_OFFSET_R22 24
58#define NIOS2_CONTEXT_OFFSET_R23 28
59#define NIOS2_CONTEXT_OFFSET_FP 32
60#define NIOS2_CONTEXT_OFFSET_STATUS 36
61#define NIOS2_CONTEXT_OFFSET_SP 40
62#define NIOS2_CONTEXT_OFFSET_RA 44
63#define NIOS2_CONTEXT_OFFSET_ISR_DISPATCH_DISABLE 48
64#define NIOS2_CONTEXT_OFFSET_STACK_MPUBASE 52
65#define NIOS2_CONTEXT_OFFSET_STACK_MPUACC 56
67#define NIOS2_ISR_STATUS_MASK_IIC 0xfffffffe
68#define NIOS2_ISR_STATUS_BITS_IIC 0x00000000
70#define NIOS2_ISR_STATUS_MASK_EIC_IL 0xfffffc0f
71#define NIOS2_ISR_STATUS_BITS_EIC_IL 0x000003f0
73#define NIOS2_ISR_STATUS_MASK_EIC_RSIE 0xf7ffffff
74#define NIOS2_ISR_STATUS_BITS_EIC_RSIE 0x00000000
76#define NIOS2_STATUS_RSIE (1 << 23)
77#define NIOS2_STATUS_NMI (1 << 22)
78#define NIOS2_STATUS_PRS_OFFSET 16
79#define NIOS2_STATUS_PRS_MASK (0x3f << NIOS2_STATUS_PRS_OFFSET)
80#define NIOS2_STATUS_CRS_OFFSET 10
81#define NIOS2_STATUS_CRS_MASK (0x3f << NIOS2_STATUS_CRS_OFFSET)
82#define NIOS2_STATUS_IL_OFFSET 4
83#define NIOS2_STATUS_IL_MASK (0x3f << NIOS2_STATUS_IL_OFFSET)
84#define NIOS2_STATUS_IH (1 << 3)
85#define NIOS2_STATUS_EH (1 << 2)
86#define NIOS2_STATUS_U (1 << 1)
87#define NIOS2_STATUS_PIE (1 << 0)
89#define NIOS2_EXCEPTION_CAUSE_OFFSET 2
90#define NIOS2_EXCEPTION_CAUSE_MASK (0x1f << NIOS2_EXCEPTION_CAUSE_OFFSET)
92#define NIOS2_PTEADDR_PTBASE_OFFSET 22
93#define NIOS2_PTEADDR_PTBASE_MASK (0x3ff << NIOS2_PTEADDR_PTBASE_OFFSET)
94#define NIOS2_PTEADDR_VPN_OFFSET 2
95#define NIOS2_PTEADDR_VPN_MASK (0xfffff << NIOS2_PTEADDR_VPN_OFFSET)
97#define NIOS2_TLBACC_IG_OFFSET 25
98#define NIOS2_TLBACC_IG_MASK (0x3ff << NIOS2_TLBACC_IG_OFFSET)
99#define NIOS2_TLBACC_C (1 << 24)
100#define NIOS2_TLBACC_R (1 << 23)
101#define NIOS2_TLBACC_W (1 << 22)
102#define NIOS2_TLBACC_X (1 << 21)
103#define NIOS2_TLBACC_G (1 << 20)
104#define NIOS2_TLBACC_PFN_OFFSET 2
105#define NIOS2_TLBACC_PFN_MASK (0xfffff << NIOS2_TLBACC_PFN_OFFSET)
107#define NIOS2_TLBMISC_WAY_OFFSET 20
108#define NIOS2_TLBMISC_WAY_MASK (0xf << NIOS2_TLBMISC_WAY_OFFSET)
109#define NIOS2_TLBMISC_RD (1 << 19)
110#define NIOS2_TLBMISC_WE (1 << 18)
111#define NIOS2_TLBMISC_PID_OFFSET 5
112#define NIOS2_TLBMISC_PID_MASK (0x3fff << NIOS2_TLBMISC_PID_OFFSET)
113#define NIOS2_TLBMISC_DBL (1 << 3)
114#define NIOS2_TLBMISC_BAD (1 << 2)
115#define NIOS2_TLBMISC_PERM (1 << 1)
116#define NIOS2_TLBMISC_D (1 << 0)
118#define NIOS2_CONFIG_ANI (1 << 1)
119#define NIOS2_CONFIG_PE (1 << 0)
121#define NIOS2_MPUBASE_BASE_OFFSET 6
122#define NIOS2_MPUBASE_BASE_MASK (0x1ffffff << NIOS2_MPUBASE_BASE_OFFSET)
123#define NIOS2_MPUBASE_INDEX_OFFSET 1
126#define NIOS2_MPUBASE_INDEX_MASK (0x0000003e)
128#define NIOS2_MPUBASE_D (1 << 0)
130#define NIOS2_MPUACC_MASK_OFFSET 6
133#define NIOS2_MPUACC_MASK_MASK (0x7fffffc0)
135#define NIOS2_MPUACC_LIMIT_OFFSET 6
138#define NIOS2_MPUACC_LIMIT_MASK (0xffffffc0)
140#define NIOS2_MPUACC_C (1 << 5)
141#define NIOS2_MPUACC_PERM_OFFSET 2
144#define NIOS2_MPUACC_PERM_MASK (0x0000001c)
146#define NIOS2_MPUACC_RD (1 << 1)
147#define NIOS2_MPUACC_WR (1 << 0)
177static inline void _Nios2_Flush_pipeline(
void )
182static inline uint32_t _Nios2_Get_ctlreg_status(
void )
184 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_STATUS );
187static inline void _Nios2_Set_ctlreg_status( uint32_t value )
189 __builtin_wrctl( NIOS2_CTLREG_INDEX_STATUS, (
int) value );
192static inline uint32_t _Nios2_Get_ctlreg_estatus(
void )
194 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_ESTATUS );
197static inline void _Nios2_Set_ctlreg_estatus( uint32_t value )
199 __builtin_wrctl( NIOS2_CTLREG_INDEX_ESTATUS, (
int) value );
202static inline uint32_t _Nios2_Get_ctlreg_bstatus(
void )
204 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_BSTATUS );
207static inline void _Nios2_Set_ctlreg_bstatus( uint32_t value )
209 __builtin_wrctl( NIOS2_CTLREG_INDEX_BSTATUS, (
int) value );
212static inline uint32_t _Nios2_Get_ctlreg_ienable(
void )
214 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_IENABLE );
217static inline void _Nios2_Set_ctlreg_ienable( uint32_t value )
219 __builtin_wrctl( NIOS2_CTLREG_INDEX_IENABLE, (
int) value );
222static inline uint32_t _Nios2_Get_ctlreg_ipending(
void )
224 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_IPENDING );
227static inline uint32_t _Nios2_Get_ctlreg_cpuid(
void )
229 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_CPUID );
232static inline uint32_t _Nios2_Get_ctlreg_exception(
void )
234 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_EXCEPTION );
237static inline uint32_t _Nios2_Get_ctlreg_pteaddr(
void )
239 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_PTEADDR );
242static inline void _Nios2_Set_ctlreg_pteaddr( uint32_t value )
244 __builtin_wrctl( NIOS2_CTLREG_INDEX_PTEADDR, (
int) value );
247static inline uint32_t _Nios2_Get_ctlreg_tlbacc(
void )
249 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_TLBACC );
252static inline void _Nios2_Set_ctlreg_tlbacc( uint32_t value )
254 __builtin_wrctl( NIOS2_CTLREG_INDEX_TLBACC, (
int) value );
257static inline uint32_t _Nios2_Get_ctlreg_tlbmisc(
void )
259 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_TLBMISC );
262static inline void _Nios2_Set_ctlreg_tlbmisc( uint32_t value )
264 __builtin_wrctl( NIOS2_CTLREG_INDEX_TLBMISC, (
int) value );
267static inline uint32_t _Nios2_Get_ctlreg_badaddr(
void )
269 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_BADADDR );
272static inline uint32_t _Nios2_Get_ctlreg_config(
void )
274 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_CONFIG );
277static inline void _Nios2_Set_ctlreg_config( uint32_t value )
279 __builtin_wrctl( NIOS2_CTLREG_INDEX_CONFIG, (
int) value );
282static inline uint32_t _Nios2_Get_ctlreg_mpubase(
void )
284 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_MPUBASE );
287static inline void _Nios2_Set_ctlreg_mpubase( uint32_t value )
289 __builtin_wrctl( NIOS2_CTLREG_INDEX_MPUBASE, (
int) value );
292static inline uint32_t _Nios2_Get_ctlreg_mpuacc(
void )
294 return (uint32_t) __builtin_rdctl( NIOS2_CTLREG_INDEX_MPUACC );
297static inline void _Nios2_Set_ctlreg_mpuacc( uint32_t value )
299 __builtin_wrctl( NIOS2_CTLREG_INDEX_MPUACC, (
int) value );
302static inline uint32_t _Nios2_ISR_Get_status_mask(
void )
307static inline uint32_t _Nios2_ISR_Get_status_bits(
void )
312static inline bool _Nios2_Has_internal_interrupt_controller(
void )
314 return _Nios2_ISR_Get_status_mask() == NIOS2_ISR_STATUS_MASK_IIC;
317uint32_t _Nios2_ISR_Set_level( uint32_t new_level, uint32_t status );
320 int data_address_width;
321 int instruction_address_width;
322 int data_region_size_log2;
323 int instruction_region_size_log2;
324 int data_region_count;
325 int instruction_region_count;
326 int data_index_for_stack_protection;
327 bool region_uses_limit;
328 bool enable_data_cache_for_stack;
336 NIOS2_MPU_INST_PERM_SVR_NONE_USER_NONE = 0,
337 NIOS2_MPU_INST_PERM_SVR_EXECUTE_USER_NONE,
338 NIOS2_MPU_INST_PERM_SVR_EXECUTE_USER_EXECUTE,
339 NIOS2_MPU_DATA_PERM_SVR_NONE_USER_NONE = 0,
340 NIOS2_MPU_DATA_PERM_SVR_READONLY_USER_NONE,
341 NIOS2_MPU_DATA_PERM_SVR_READONLY_USER_READONLY,
342 NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE = 4,
343 NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_READONLY,
344 NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_READWRITE
345} Nios2_MPU_Region_permissions;
351 Nios2_MPU_Region_permissions perm;
358#define NIOS2_MPU_REGION_DESC_INST( index, base, end ) \
360 (index), (base), (end), NIOS2_MPU_INST_PERM_SVR_EXECUTE_USER_NONE, \
361 false, false, false, true \
364#define NIOS2_MPU_REGION_DESC_DATA_RO( index, base, end ) \
366 (index), (base), (end), NIOS2_MPU_DATA_PERM_SVR_READONLY_USER_NONE, \
367 true, true, false, true \
370#define NIOS2_MPU_REGION_DESC_DATA_RW( index, base, end ) \
372 (index), (base), (end), NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE, \
373 true, true, false, true \
376#define NIOS2_MPU_REGION_DESC_DATA_IO( index, base, end ) \
378 (index), (base), (end), NIOS2_MPU_DATA_PERM_SVR_READWRITE_USER_NONE, \
379 true, false, false, true \
382static inline int _Nios2_MPU_Get_region_count(
389 :
config->instruction_region_count;
392static inline bool _Nios2_MPU_Is_valid_index(
399 && index < _Nios2_MPU_Get_region_count(
config, data );
402bool _Nios2_MPU_Setup_region_registers(
409bool _Nios2_MPU_Get_region_descriptor(
448static inline void _Nios2_MPU_Get_region_registers(
455 uint32_t base = (uint32_t)
456 (((index << NIOS2_MPUBASE_INDEX_OFFSET) & NIOS2_MPUBASE_INDEX_MASK)
457 | (data ? NIOS2_MPUBASE_D : 0));
459 _Nios2_Set_ctlreg_mpubase( base );
460 _Nios2_Set_ctlreg_mpuacc( NIOS2_MPUACC_RD );
461 _Nios2_Flush_pipeline();
462 *mpubase = _Nios2_Get_ctlreg_mpubase() | base;
463 *mpuacc = _Nios2_Get_ctlreg_mpuacc();
466static inline void _Nios2_MPU_Set_region_registers(
471 _Nios2_Set_ctlreg_mpubase( mpubase );
472 _Nios2_Set_ctlreg_mpuacc( mpuacc );
473 _Nios2_Flush_pipeline();
476static inline void _Nios2_MPU_Enable(
void )
478 uint32_t
config = _Nios2_Get_ctlreg_config();
480 _Nios2_Set_ctlreg_config(
config | NIOS2_CONFIG_PE );
483static inline uint32_t _Nios2_MPU_Disable(
void )
485 uint32_t
config = _Nios2_Get_ctlreg_config();
486 uint32_t config_pe = NIOS2_CONFIG_PE;
488 _Nios2_Set_ctlreg_config(
config & ~config_pe );
493static inline void _Nios2_MPU_Restore( uint32_t
config )
495 _Nios2_Set_ctlreg_config(
config );
498uint32_t _Nios2_MPU_Disable_protected(
void );
508 .macro NIOS2_ASM_DISABLE_INTERRUPTS new_status, current_status
511 and \new_status, \current_status, \new_status
513 wrctl status, \new_status
register struct Per_CPU_Control *_SPARC_Per_CPU_current __asm__("g6")
The pointer to the current per-CPU control is available via register g6.
ssize_t read(int fd, void *buffer, size_t count)
Definition: read.c:46
ssize_t write(int fd, const void *buffer, size_t count)
Definition: write.c:49
bool _Nios2_MPU_Add_region(const Nios2_MPU_Configuration *config, const Nios2_MPU_Region_descriptor *desc, bool force)
Adds a region according to region descriptor desc.
Definition: nios2-mpu-add-region.c:84
char _Nios2_ISR_Status_bits[]
This symbol specifies the status register bits used to disable interrupts.
char _Nios2_ISR_Status_mask[]
This global symbol specifies the status register mask used to disable interrupts.
int _Nios2_MPU_Get_disabled_region_index(const Nios2_MPU_Configuration *config, bool data, int begin, int end)
Searches the region table part for a disabled region.
Definition: nios2-mpu-add-region.c:52
Definition: nios2-utility.h:319
Definition: nios2-utility.h:347
Definition: deflate.c:114