2017-02-20 18:35:56 +03:00
|
|
|
/*
|
|
|
|
* ARMv7M NVIC object
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Linaro Ltd
|
|
|
|
* Written by Peter Maydell <peter.maydell@linaro.org>
|
|
|
|
*
|
|
|
|
* This code is licensed under the GPL version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_ARM_ARMV7M_NVIC_H
|
|
|
|
#define HW_ARM_ARMV7M_NVIC_H
|
|
|
|
|
|
|
|
#include "target/arm/cpu.h"
|
|
|
|
#include "hw/sysbus.h"
|
2017-02-20 18:36:03 +03:00
|
|
|
#include "hw/timer/armv7m_systick.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2017-02-20 18:35:56 +03:00
|
|
|
|
|
|
|
#define TYPE_NVIC "armv7m_nvic"
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
typedef struct NVICState NVICState;
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_INSTANCE_CHECKER(NVICState, NVIC,
|
|
|
|
TYPE_NVIC)
|
2017-02-20 18:35:56 +03:00
|
|
|
|
|
|
|
/* Highest permitted number of exceptions (architectural limit) */
|
|
|
|
#define NVIC_MAX_VECTORS 512
|
2017-09-21 18:28:59 +03:00
|
|
|
/* Number of internal exceptions */
|
|
|
|
#define NVIC_INTERNAL_VECTORS 16
|
2017-02-20 18:35:56 +03:00
|
|
|
|
|
|
|
typedef struct VecInfo {
|
|
|
|
/* Exception priorities can range from -3 to 255; only the unmodifiable
|
|
|
|
* priority values for RESET, NMI and HardFault can be negative.
|
|
|
|
*/
|
|
|
|
int16_t prio;
|
|
|
|
uint8_t enabled;
|
|
|
|
uint8_t pending;
|
|
|
|
uint8_t active;
|
|
|
|
uint8_t level; /* exceptions <=15 never set level */
|
|
|
|
} VecInfo;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct NVICState {
|
2017-02-20 18:35:56 +03:00
|
|
|
/*< private >*/
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
|
|
|
ARMCPU *cpu;
|
|
|
|
|
|
|
|
VecInfo vectors[NVIC_MAX_VECTORS];
|
2017-09-21 18:28:59 +03:00
|
|
|
/* If the v8M security extension is implemented, some of the internal
|
|
|
|
* exceptions are banked between security states (ie there exists both
|
|
|
|
* a Secure and a NonSecure version of the exception and its state):
|
|
|
|
* HardFault, MemManage, UsageFault, SVCall, PendSV, SysTick (R_PJHV)
|
|
|
|
* The rest (including all the external exceptions) are not banked, though
|
|
|
|
* they may be configurable to target either Secure or NonSecure state.
|
|
|
|
* We store the secure exception state in sec_vectors[] for the banked
|
|
|
|
* exceptions, and otherwise use only vectors[] (including for exceptions
|
|
|
|
* like SecureFault that unconditionally target Secure state).
|
|
|
|
* Entries in sec_vectors[] for non-banked exception numbers are unused.
|
|
|
|
*/
|
|
|
|
VecInfo sec_vectors[NVIC_INTERNAL_VECTORS];
|
2017-09-12 21:13:52 +03:00
|
|
|
/* The PRIGROUP field in AIRCR is banked */
|
|
|
|
uint32_t prigroup[M_REG_NUM_BANKS];
|
2018-08-14 19:17:19 +03:00
|
|
|
uint8_t num_prio_bits;
|
2017-02-20 18:35:56 +03:00
|
|
|
|
2017-09-12 21:13:54 +03:00
|
|
|
/* v8M NVIC_ITNS state (stored as a bool per bit) */
|
|
|
|
bool itns[NVIC_MAX_VECTORS];
|
|
|
|
|
2017-09-12 21:13:50 +03:00
|
|
|
/* The following fields are all cached state that can be recalculated
|
|
|
|
* from the vectors[] and sec_vectors[] arrays and the prigroup field:
|
|
|
|
* - vectpending
|
|
|
|
* - vectpending_is_secure
|
|
|
|
* - exception_prio
|
2017-09-12 21:13:51 +03:00
|
|
|
* - vectpending_prio
|
2017-02-20 18:35:56 +03:00
|
|
|
*/
|
|
|
|
unsigned int vectpending; /* highest prio pending enabled exception */
|
2017-09-12 21:13:50 +03:00
|
|
|
/* true if vectpending is a banked secure exception, ie it is in
|
|
|
|
* sec_vectors[] rather than vectors[]
|
|
|
|
*/
|
|
|
|
bool vectpending_is_s_banked;
|
2017-02-20 18:35:56 +03:00
|
|
|
int exception_prio; /* group prio of the highest prio active exception */
|
2017-09-12 21:13:51 +03:00
|
|
|
int vectpending_prio; /* group prio of the exeception in vectpending */
|
2017-02-20 18:35:56 +03:00
|
|
|
|
|
|
|
MemoryRegion sysregmem;
|
2017-09-07 15:54:53 +03:00
|
|
|
MemoryRegion sysreg_ns_mem;
|
2017-12-13 20:59:26 +03:00
|
|
|
MemoryRegion systickmem;
|
|
|
|
MemoryRegion systick_ns_mem;
|
2017-02-20 18:35:56 +03:00
|
|
|
MemoryRegion container;
|
|
|
|
|
|
|
|
uint32_t num_irq;
|
|
|
|
qemu_irq excpout;
|
|
|
|
qemu_irq sysresetreq;
|
2017-02-20 18:36:03 +03:00
|
|
|
|
2017-12-13 20:59:26 +03:00
|
|
|
SysTickState systick[M_REG_NUM_BANKS];
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2017-02-20 18:35:56 +03:00
|
|
|
|
|
|
|
#endif
|