Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
arch.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_
15#define ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_
16
17#include <system.h>
18
22#include <zephyr/devicetree.h>
25#include <zephyr/sys/sys_io.h>
27
28#define ARCH_STACK_PTR_ALIGN 4
29
30#ifndef _ASMLANGUAGE
31#include <zephyr/types.h>
32#include <zephyr/irq.h>
33#include <zephyr/sw_isr_table.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* There is no notion of priority with the Nios II internal interrupt
40 * controller and no flags are currently supported.
41 */
42#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
43{ \
44 Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
45}
46
47static ALWAYS_INLINE unsigned int arch_irq_lock(void)
48{
49 unsigned int key, tmp;
50
51 __asm__ volatile (
52 "rdctl %[key], status\n\t"
53 "movi %[tmp], -2\n\t"
54 "and %[tmp], %[key], %[tmp]\n\t"
55 "wrctl status, %[tmp]\n\t"
56 : [key] "=r" (key), [tmp] "=r" (tmp)
57 : : "memory");
58
59 return key;
60}
61
62static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
63{
64 /* If the CPU is built without certain features, then
65 * the only writable bit in the status register is PIE
66 * in which case we can just write the value stored in key,
67 * all the other writable bits will be the same.
68 *
69 * If not, other stuff could have changed and we need to
70 * specifically flip just that bit.
71 */
72
73#if (ALT_CPU_NUM_OF_SHADOW_REG_SETS > 0) || \
74 (defined ALT_CPU_EIC_PRESENT) || \
75 (defined ALT_CPU_MMU_PRESENT) || \
76 (defined ALT_CPU_MPU_PRESENT)
77 __asm__ volatile (
78 "andi %[key], %[key], 1\n\t"
79 "beq %[key], zero, 1f\n\t"
80 "rdctl %[key], status\n\t"
81 "ori %[key], %[key], 1\n\t"
82 "wrctl status, %[key]\n\t"
83 "1:\n\t"
84 : [key] "+r" (key)
85 : : "memory");
86#else
87 __asm__ volatile (
88 "wrctl status, %[key]"
89 : : [key] "r" (key)
90 : "memory");
91#endif
92}
93
94static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
95{
96 return key & 1;
97}
98
99void arch_irq_enable(unsigned int irq);
100void arch_irq_disable(unsigned int irq);
101
102struct __esf {
103 uint32_t ra; /* return address r31 */
104 uint32_t r1; /* at */
105 uint32_t r2; /* return value */
106 uint32_t r3; /* return value */
107 uint32_t r4; /* register args */
108 uint32_t r5; /* register args */
109 uint32_t r6; /* register args */
110 uint32_t r7; /* register args */
111 uint32_t r8; /* Caller-saved general purpose */
112 uint32_t r9; /* Caller-saved general purpose */
113 uint32_t r10; /* Caller-saved general purpose */
114 uint32_t r11; /* Caller-saved general purpose */
115 uint32_t r12; /* Caller-saved general purpose */
116 uint32_t r13; /* Caller-saved general purpose */
117 uint32_t r14; /* Caller-saved general purpose */
118 uint32_t r15; /* Caller-saved general purpose */
119 uint32_t estatus;
120 uint32_t instr; /* Instruction being executed when exc occurred */
121};
122
123typedef struct __esf z_arch_esf_t;
124
125FUNC_NORETURN void z_SysFatalErrorHandler(unsigned int reason,
126 const z_arch_esf_t *esf);
127
128FUNC_NORETURN void z_NanoFatalErrorHandler(unsigned int reason,
129 const z_arch_esf_t *esf);
130
157
158/* Bitfield indicating which exception cause codes report a valid
159 * badaddr register. NIOS2_EXCEPTION_TLB_MISS and NIOS2_EXCEPTION_ECC_TLB_ERR
160 * are deliberately not included here, you need to check if TLBMISC.D=1
161 */
162#define NIOS2_BADADDR_CAUSE_MASK \
163 (BIT(NIOS2_EXCEPTION_SUPERVISOR_ONLY_DATA_ADDR) | \
164 BIT(NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR) | \
165 BIT(NIOS2_EXCEPTION_MISALIGNED_TARGET_PC) | \
166 BIT(NIOS2_EXCEPTION_TLB_READ_PERM_VIOLATION) | \
167 BIT(NIOS2_EXCEPTION_TLB_WRITE_PERM_VIOLATION) | \
168 BIT(NIOS2_EXCEPTION_MPU_DATA_REGION_VIOLATION) | \
169 BIT(NIOS2_EXCEPTION_ECC_DATA_ERR))
170
171
173
174static inline uint32_t arch_k_cycle_get_32(void)
175{
176 return sys_clock_cycle_get_32();
177}
178
180
181static inline uint64_t arch_k_cycle_get_64(void)
182{
183 return sys_clock_cycle_get_64();
184}
185
186static ALWAYS_INLINE void arch_nop(void)
187{
188 __asm__ volatile("nop");
189}
190
191#ifdef __cplusplus
192}
193#endif
194
195#endif /* _ASMLANGUAGE */
196
197#endif /* ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_ */
static ALWAYS_INLINE void arch_nop(void)
Definition: arch.h:348
Per-arch thread definition.
#define arch_irq_disable(irq)
Definition: irq.h:107
#define arch_irq_enable(irq)
Definition: irq.h:106
#define ALWAYS_INLINE
Definition: common.h:129
Devicetree main header.
Public interface for configuring interrupts.
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Definition: arch.h:63
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
Definition: arch.h:74
uint64_t sys_clock_cycle_get_64(void)
uint32_t sys_clock_cycle_get_32(void)
static uint32_t arch_k_cycle_get_32(void)
Definition: arch.h:99
static uint64_t arch_k_cycle_get_64(void)
Definition: arch.h:106
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
Definition: arch.h:87
nios2_exception_cause
Definition: arch.h:131
@ NIOS2_EXCEPTION_ECC_DATA_CACHE_WRITEBACK_ERR
Definition: arch.h:155
@ NIOS2_EXCEPTION_UNKNOWN
Definition: arch.h:132
@ NIOS2_EXCEPTION_TLB_WRITE_PERM_VIOLATION
Definition: arch.h:148
@ NIOS2_EXCEPTION_ECC_TLB_ERR
Definition: arch.h:151
@ NIOS2_EXCEPTION_MPU_INST_REGION_VIOLATION
Definition: arch.h:149
@ NIOS2_EXCEPTION_SUPERVISOR_ONLY_DATA_ADDR
Definition: arch.h:144
@ NIOS2_EXCEPTION_CPU_ONLY_RESET_REQUEST
Definition: arch.h:134
@ NIOS2_EXCEPTION_TLB_MISS
Definition: arch.h:145
@ NIOS2_EXCEPTION_ILLEGAL_INST
Definition: arch.h:138
@ NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST_ADDR
Definition: arch.h:142
@ NIOS2_EXCEPTION_UNIMPLEMENTED_INST
Definition: arch.h:137
@ NIOS2_EXCEPTION_MPU_DATA_REGION_VIOLATION
Definition: arch.h:150
@ NIOS2_EXCEPTION_ECC_FETCH_ERR
Definition: arch.h:152
@ NIOS2_EXCEPTION_MISALIGNED_TARGET_PC
Definition: arch.h:140
@ NIOS2_EXCEPTION_TLB_READ_PERM_VIOLATION
Definition: arch.h:147
@ NIOS2_EXCEPTION_DIVISION_ERROR
Definition: arch.h:141
@ NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR
Definition: arch.h:139
@ NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST
Definition: arch.h:143
@ NIOS2_EXCEPTION_TLB_EXECUTE_PERM_VIOLATION
Definition: arch.h:146
@ NIOS2_EXCEPTION_TRAP_INST
Definition: arch.h:136
@ NIOS2_EXCEPTION_ECC_REGISTER_FILE_ERR
Definition: arch.h:153
@ NIOS2_EXCEPTION_INTERRUPT
Definition: arch.h:135
@ NIOS2_EXCEPTION_ECC_DATA_ERR
Definition: arch.h:154
@ NIOS2_EXCEPTION_RESET
Definition: arch.h:133
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
Software-managed ISR table.