2016-04-22 05:47:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-04-22 05:47:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2016-12-23 20:32:56 +08:00
|
|
|
* @brief Nios II specific kernel interface header
|
|
|
|
* This header contains the Nios II specific kernel interface. It is
|
|
|
|
* included by the generic kernel interface header (include/arch/cpu.h)
|
2016-04-22 05:47:09 +08:00
|
|
|
*/
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_
|
|
|
|
#define ZEPHYR_INCLUDE_ARCH_NIOS2_ARCH_H_
|
2016-04-22 05:47:09 +08:00
|
|
|
|
2016-05-05 04:52:25 +08:00
|
|
|
#include <system.h>
|
2016-06-21 04:39:21 +08:00
|
|
|
#include <arch/nios2/asm_inline.h>
|
2018-04-21 00:18:10 +08:00
|
|
|
#include <generated_dts_board.h>
|
2016-05-05 05:28:07 +08:00
|
|
|
#include "nios2.h"
|
2016-05-05 04:52:25 +08:00
|
|
|
|
2016-04-22 05:47:09 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STACK_ALIGN 4
|
|
|
|
|
2016-06-22 03:15:33 +08:00
|
|
|
#define _NANO_ERR_CPU_EXCEPTION (0) /* Any unhandled exception */
|
2016-04-22 05:47:09 +08:00
|
|
|
#define _NANO_ERR_STACK_CHK_FAIL (2) /* Stack corruption detected */
|
|
|
|
#define _NANO_ERR_ALLOCATION_FAIL (3) /* Kernel Allocation Failure */
|
2016-06-22 03:15:33 +08:00
|
|
|
#define _NANO_ERR_SPURIOUS_INT (4) /* Spurious interrupt */
|
2017-04-19 06:22:05 +08:00
|
|
|
#define _NANO_ERR_KERNEL_OOPS (5) /* Kernel oops (fatal to thread) */
|
|
|
|
#define _NANO_ERR_KERNEL_PANIC (6) /* Kernel panic (fatal to system) */
|
2016-04-22 05:47:09 +08:00
|
|
|
|
|
|
|
#ifndef _ASMLANGUAGE
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-04-22 05:47:09 +08:00
|
|
|
#include <irq.h>
|
2016-06-22 03:18:50 +08:00
|
|
|
#include <sw_isr_table.h>
|
2016-04-22 05:47:09 +08:00
|
|
|
|
2017-04-09 23:50:18 +08:00
|
|
|
/* physical/virtual address types required by the kernel */
|
2016-06-30 06:26:14 +08:00
|
|
|
typedef unsigned int paddr_t;
|
|
|
|
typedef unsigned int vaddr_t;
|
|
|
|
|
2016-06-22 03:18:50 +08:00
|
|
|
/**
|
|
|
|
* Configure a static interrupt.
|
|
|
|
*
|
2016-09-23 02:20:26 +08:00
|
|
|
* All arguments must be computable by the compiler at build time.
|
2016-06-22 03:18:50 +08:00
|
|
|
*
|
|
|
|
* Internally this function does a few things:
|
|
|
|
*
|
|
|
|
* 1. The enum statement has no effect but forces the compiler to only
|
|
|
|
* accept constant values for the irq_p parameter, very important as the
|
|
|
|
* numerical IRQ line is used to create a named section.
|
|
|
|
*
|
2017-01-26 06:32:53 +08:00
|
|
|
* 2. An instance of struct _isr_table_entry is created containing the ISR and
|
|
|
|
* its parameter. If you look at how _sw_isr_table is created, each entry in
|
|
|
|
* the array is in its own section named by the IRQ line number. What we are
|
|
|
|
* doing here is to override one of the default entries (which points to the
|
2016-06-22 03:18:50 +08:00
|
|
|
* spurious IRQ handler) with what was supplied here.
|
|
|
|
*
|
|
|
|
* There is no notion of priority with the Nios II internal interrupt
|
|
|
|
* controller and no flags are currently supported.
|
|
|
|
*
|
|
|
|
* @param irq_p IRQ line number
|
|
|
|
* @param priority_p Interrupt priority (ignored)
|
|
|
|
* @param isr_p Interrupt service routine
|
|
|
|
* @param isr_param_p ISR parameter
|
|
|
|
* @param flags_p IRQ triggering options (currently unused)
|
|
|
|
*
|
|
|
|
* @return The vector assigned to this interrupt
|
|
|
|
*/
|
2019-03-09 05:19:05 +08:00
|
|
|
#define Z_ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
|
2016-06-22 03:18:50 +08:00
|
|
|
({ \
|
2019-03-09 05:19:05 +08:00
|
|
|
Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
|
2016-06-22 03:18:50 +08:00
|
|
|
irq_p; \
|
|
|
|
})
|
2016-04-22 05:47:09 +08:00
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
extern void z_irq_spurious(void *unused);
|
2017-02-10 06:37:32 +08:00
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
static ALWAYS_INLINE unsigned int z_arch_irq_lock(void)
|
2016-04-22 05:47:09 +08:00
|
|
|
{
|
2016-12-03 06:04:47 +08:00
|
|
|
unsigned int key, tmp;
|
2016-04-22 05:47:09 +08:00
|
|
|
|
2016-12-03 06:04:47 +08:00
|
|
|
__asm__ volatile (
|
|
|
|
"rdctl %[key], status\n\t"
|
|
|
|
"movi %[tmp], -2\n\t"
|
|
|
|
"and %[tmp], %[key], %[tmp]\n\t"
|
|
|
|
"wrctl status, %[tmp]\n\t"
|
|
|
|
: [key] "=r" (key), [tmp] "=r" (tmp)
|
|
|
|
: : "memory");
|
2016-05-07 06:14:05 +08:00
|
|
|
|
|
|
|
return key;
|
2016-04-22 05:47:09 +08:00
|
|
|
}
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
static ALWAYS_INLINE void z_arch_irq_unlock(unsigned int key)
|
2016-04-22 05:47:09 +08:00
|
|
|
{
|
2016-05-07 06:14:05 +08:00
|
|
|
/* If the CPU is built without certain features, then
|
|
|
|
* the only writable bit in the status register is PIE
|
|
|
|
* in which case we can just write the value stored in key,
|
|
|
|
* all the other writable bits will be the same.
|
|
|
|
*
|
|
|
|
* If not, other stuff could have changed and we need to
|
|
|
|
* specifically flip just that bit.
|
|
|
|
*/
|
|
|
|
|
2016-07-12 03:42:02 +08:00
|
|
|
#if (ALT_CPU_NUM_OF_SHADOW_REG_SETS > 0) || \
|
|
|
|
(defined ALT_CPU_EIC_PRESENT) || \
|
|
|
|
(defined ALT_CPU_MMU_PRESENT) || \
|
|
|
|
(defined ALT_CPU_MPU_PRESENT)
|
2016-12-03 06:04:47 +08:00
|
|
|
__asm__ volatile (
|
|
|
|
"andi %[key], %[key], 1\n\t"
|
|
|
|
"beq %[key], zero, 1f\n\t"
|
|
|
|
"rdctl %[key], status\n\t"
|
|
|
|
"ori %[key], %[key], 1\n\t"
|
|
|
|
"wrctl status, %[key]\n\t"
|
|
|
|
"1:\n\t"
|
|
|
|
: [key] "+r" (key)
|
|
|
|
: : "memory");
|
2016-05-07 06:14:05 +08:00
|
|
|
#else
|
2016-12-03 06:04:47 +08:00
|
|
|
__asm__ volatile (
|
|
|
|
"wrctl status, %[key]"
|
|
|
|
: : [key] "r" (key)
|
|
|
|
: "memory");
|
2016-05-07 06:14:05 +08:00
|
|
|
#endif
|
2016-04-22 05:47:09 +08:00
|
|
|
}
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
void z_arch_irq_enable(unsigned int irq);
|
|
|
|
void z_arch_irq_disable(unsigned int irq);
|
2016-04-22 05:47:09 +08:00
|
|
|
|
|
|
|
struct __esf {
|
2017-04-21 23:55:34 +08:00
|
|
|
u32_t ra; /* return address r31 */
|
|
|
|
u32_t r1; /* at */
|
|
|
|
u32_t r2; /* return value */
|
|
|
|
u32_t r3; /* return value */
|
|
|
|
u32_t r4; /* register args */
|
|
|
|
u32_t r5; /* register args */
|
|
|
|
u32_t r6; /* register args */
|
|
|
|
u32_t r7; /* register args */
|
|
|
|
u32_t r8; /* Caller-saved general purpose */
|
|
|
|
u32_t r9; /* Caller-saved general purpose */
|
|
|
|
u32_t r10; /* Caller-saved general purpose */
|
|
|
|
u32_t r11; /* Caller-saved general purpose */
|
|
|
|
u32_t r12; /* Caller-saved general purpose */
|
|
|
|
u32_t r13; /* Caller-saved general purpose */
|
|
|
|
u32_t r14; /* Caller-saved general purpose */
|
|
|
|
u32_t r15; /* Caller-saved general purpose */
|
|
|
|
u32_t estatus;
|
|
|
|
u32_t instr; /* Instruction being executed when exc occurred */
|
2016-04-22 05:47:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct __esf NANO_ESF;
|
|
|
|
extern const NANO_ESF _default_esf;
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
FUNC_NORETURN void z_SysFatalErrorHandler(unsigned int reason,
|
2016-05-04 02:49:50 +08:00
|
|
|
const NANO_ESF *esf);
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
FUNC_NORETURN void z_NanoFatalErrorHandler(unsigned int reason,
|
2017-07-18 07:07:01 +08:00
|
|
|
const NANO_ESF *esf);
|
2016-06-22 03:15:33 +08:00
|
|
|
|
|
|
|
enum nios2_exception_cause {
|
|
|
|
NIOS2_EXCEPTION_UNKNOWN = -1,
|
|
|
|
NIOS2_EXCEPTION_RESET = 0,
|
|
|
|
NIOS2_EXCEPTION_CPU_ONLY_RESET_REQUEST = 1,
|
|
|
|
NIOS2_EXCEPTION_INTERRUPT = 2,
|
|
|
|
NIOS2_EXCEPTION_TRAP_INST = 3,
|
|
|
|
NIOS2_EXCEPTION_UNIMPLEMENTED_INST = 4,
|
|
|
|
NIOS2_EXCEPTION_ILLEGAL_INST = 5,
|
|
|
|
NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR = 6,
|
|
|
|
NIOS2_EXCEPTION_MISALIGNED_TARGET_PC = 7,
|
|
|
|
NIOS2_EXCEPTION_DIVISION_ERROR = 8,
|
|
|
|
NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST_ADDR = 9,
|
|
|
|
NIOS2_EXCEPTION_SUPERVISOR_ONLY_INST = 10,
|
|
|
|
NIOS2_EXCEPTION_SUPERVISOR_ONLY_DATA_ADDR = 11,
|
|
|
|
NIOS2_EXCEPTION_TLB_MISS = 12,
|
|
|
|
NIOS2_EXCEPTION_TLB_EXECUTE_PERM_VIOLATION = 13,
|
|
|
|
NIOS2_EXCEPTION_TLB_READ_PERM_VIOLATION = 14,
|
|
|
|
NIOS2_EXCEPTION_TLB_WRITE_PERM_VIOLATION = 15,
|
|
|
|
NIOS2_EXCEPTION_MPU_INST_REGION_VIOLATION = 16,
|
|
|
|
NIOS2_EXCEPTION_MPU_DATA_REGION_VIOLATION = 17,
|
|
|
|
NIOS2_EXCEPTION_ECC_TLB_ERR = 18,
|
|
|
|
NIOS2_EXCEPTION_ECC_FETCH_ERR = 19,
|
|
|
|
NIOS2_EXCEPTION_ECC_REGISTER_FILE_ERR = 20,
|
|
|
|
NIOS2_EXCEPTION_ECC_DATA_ERR = 21,
|
|
|
|
NIOS2_EXCEPTION_ECC_DATA_CACHE_WRITEBACK_ERR = 22
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Bitfield indicating which exception cause codes report a valid
|
|
|
|
* badaddr register. NIOS2_EXCEPTION_TLB_MISS and NIOS2_EXCEPTION_ECC_TLB_ERR
|
|
|
|
* are deliberately not included here, you need to check if TLBMISC.D=1
|
|
|
|
*/
|
|
|
|
#define NIOS2_BADADDR_CAUSE_MASK \
|
|
|
|
(BIT(NIOS2_EXCEPTION_SUPERVISOR_ONLY_DATA_ADDR) | \
|
|
|
|
BIT(NIOS2_EXCEPTION_MISALIGNED_DATA_ADDR) | \
|
|
|
|
BIT(NIOS2_EXCEPTION_MISALIGNED_TARGET_PC) | \
|
|
|
|
BIT(NIOS2_EXCEPTION_TLB_READ_PERM_VIOLATION) | \
|
|
|
|
BIT(NIOS2_EXCEPTION_TLB_WRITE_PERM_VIOLATION) | \
|
|
|
|
BIT(NIOS2_EXCEPTION_MPU_DATA_REGION_VIOLATION) | \
|
|
|
|
BIT(NIOS2_EXCEPTION_ECC_DATA_ERR))
|
|
|
|
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
extern u32_t z_timer_cycle_get_32(void);
|
|
|
|
#define z_arch_k_cycle_get_32() z_timer_cycle_get_32()
|
2017-02-16 05:40:17 +08:00
|
|
|
|
2018-12-05 09:15:27 +08:00
|
|
|
/**
|
|
|
|
* @brief Explicitly nop operation.
|
|
|
|
*/
|
|
|
|
static ALWAYS_INLINE void arch_nop(void)
|
|
|
|
{
|
|
|
|
__asm__ volatile("nop");
|
|
|
|
}
|
|
|
|
|
2016-04-22 05:47:09 +08:00
|
|
|
#endif /* _ASMLANGUAGE */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|