Skip to content

Commit d891238

Browse files
refactor: separate necessary nvic interfaces which also used for cortex-m cpu interrupt
Signed-off-by: chaojixx <[email protected]>
1 parent f01c20b commit d891238

File tree

3 files changed

+100
-20
lines changed

3 files changed

+100
-20
lines changed

hw/intc/armv7m_nvic.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ static inline int nvic_exec_prio(NVICState *s)
363363
if (env->v7m.faultmask[M_REG_S]) {
364364
running = (env->v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) ? -3 : -1;
365365
}
366-
367366
/* consider priority of active handler */
368367
return MIN(running, s->exception_prio);
369368
}
@@ -400,8 +399,9 @@ bool armv7m_nvic_neg_prio_requested(void *opaque, bool secure)
400399
bool armv7m_nvic_can_take_pending_exception(void *opaque)
401400
{
402401
NVICState *s = opaque;
403-
404-
return nvic_exec_prio(s) > nvic_pending_prio(s);
402+
const int running = nvic_exec_prio(s);
403+
const int vectpending_prio = s->vectpending_prio;
404+
return running > vectpending_prio;
405405
}
406406

407407
int armv7m_nvic_raw_execution_priority(void *opaque)
@@ -657,7 +657,7 @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure)
657657
void armv7m_nvic_acknowledge_irq(void *opaque)
658658
{
659659
NVICState *s = (NVICState *)opaque;
660-
CPUARMState *env = &s->cpu->env;
660+
/* CPUARMState *env = &s->cpu->env; */
661661
const int pending = s->vectpending;
662662
const int running = nvic_exec_prio(s);
663663
VecInfo *vec;
@@ -672,15 +672,18 @@ void armv7m_nvic_acknowledge_irq(void *opaque)
672672

673673
assert(vec->enabled);
674674
assert(vec->pending);
675-
675+
// printf("check vectpending_prio=0x%x\n",s->vectpending_prio);
676+
// printf("check running=0x%x\n",running);
676677
assert(s->vectpending_prio < running);
677678

678679
trace_nvic_acknowledge_irq(pending, s->vectpending_prio);
679680

680681
vec->active = 1;
681682
vec->pending = 0;
682683

683-
write_v7m_exception(env, s->vectpending);
684+
/*IoT s2e move to do_interrupt_v7m comment this function*/
685+
/* write_v7m_exception(env, s->vectpending); */
686+
684687

685688
nvic_irq_update(s);
686689
}

include/nvic/nvic_interfaces.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <stdbool.h>
2+
/* Interface between CPU and Interrupt controller. */
3+
/**
4+
* armv7m_nvic_set_pending: mark the specified exception as pending
5+
* @opaque: the NVIC
6+
* @irq: the exception number to mark pending
7+
* @secure: false for non-banked exceptions or for the nonsecure
8+
* version of a banked exception, true for the secure version of a banked
9+
* exception.
10+
*
11+
* Marks the specified exception as pending. Note that we will assert()
12+
* if @secure is true and @irq does not specify one of the fixed set
13+
* of architecturally banked exceptions.
14+
*/
15+
void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
16+
/**
17+
* armv7m_nvic_set_pending_derived: mark this derived exception as pending
18+
* @opaque: the NVIC
19+
* @irq: the exception number to mark pending
20+
* @secure: false for non-banked exceptions or for the nonsecure
21+
* version of a banked exception, true for the secure version of a banked
22+
* exception.
23+
*
24+
* Similar to armv7m_nvic_set_pending(), but specifically for derived
25+
* exceptions (exceptions generated in the course of trying to take
26+
* a different exception).
27+
*/
28+
void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure);
29+
/**
30+
* armv7m_nvic_get_pending_irq_info: return highest priority pending
31+
* exception, and whether it targets Secure state
32+
* @opaque: the NVIC
33+
* @pirq: set to pending exception number
34+
* @ptargets_secure: set to whether pending exception targets Secure
35+
*
36+
* This function writes the number of the highest priority pending
37+
* exception (the one which would be made active by
38+
* armv7m_nvic_acknowledge_irq()) to @pirq, and sets @ptargets_secure
39+
* to true if the current highest priority pending exception should
40+
* be taken to Secure state, false for NS.
41+
*/
42+
void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq,
43+
bool *ptargets_secure);
44+
/**
45+
* armv7m_nvic_acknowledge_irq: make highest priority pending exception active
46+
* @opaque: the NVIC
47+
*
48+
* Move the current highest priority pending exception from the pending
49+
* state to the active state, and update v7m.exception to indicate that
50+
* it is the exception currently being handled.
51+
*/
52+
void armv7m_nvic_acknowledge_irq(void *opaque);
53+
/**
54+
* armv7m_nvic_complete_irq: complete specified interrupt or exception
55+
* @opaque: the NVIC
56+
* @irq: the exception number to complete
57+
* @secure: true if this exception was secure
58+
*
59+
* Returns: -1 if the irq was not active
60+
* 1 if completing this irq brought us back to base (no active irqs)
61+
* 0 if there is still an irq active after this one was completed
62+
* (Ignoring -1, this is the same as the RETTOBASE value before completion.)
63+
*/
64+
int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure);
65+
66+
/* Interface between CPU and Interrupt controller. */
67+
#ifndef CONFIG_USER_ONLY
68+
bool armv7m_nvic_can_take_pending_exception(void *opaque);
69+
#else
70+
static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
71+
{
72+
return true;
73+
}
74+
#endif

target/arm/cpu.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "kvm-consts.h"
2424
#include "hw/registerfields.h"
25+
#include "nvic/nvic_interfaces.h"
2526

2627
#if defined(TARGET_AARCH64)
2728
/* AArch64 definitions */
@@ -1628,15 +1629,17 @@ void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf);
16281629
uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx,
16291630
uint32_t cur_el, bool secure);
16301631

1632+
// The following 6 interfaces move to nvic/nvic_interfaces,
1633+
// since S2E ARM CPU and qemu client both will invokes these functions.
16311634
/* Interface between CPU and Interrupt controller. */
1632-
#ifndef CONFIG_USER_ONLY
1633-
bool armv7m_nvic_can_take_pending_exception(void *opaque);
1634-
#else
1635-
static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
1636-
{
1637-
return true;
1638-
}
1639-
#endif
1635+
/* #ifndef CONFIG_USER_ONLY */
1636+
// bool armv7m_nvic_can_take_pending_exception(void *opaque);
1637+
// #else
1638+
// static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
1639+
// {
1640+
// return true;
1641+
// }
1642+
/* #endif */
16401643
/**
16411644
* armv7m_nvic_set_pending: mark the specified exception as pending
16421645
* @opaque: the NVIC
@@ -1649,7 +1652,7 @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
16491652
* if @secure is true and @irq does not specify one of the fixed set
16501653
* of architecturally banked exceptions.
16511654
*/
1652-
void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
1655+
//void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
16531656
/**
16541657
* armv7m_nvic_set_pending_derived: mark this derived exception as pending
16551658
* @opaque: the NVIC
@@ -1662,7 +1665,7 @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
16621665
* exceptions (exceptions generated in the course of trying to take
16631666
* a different exception).
16641667
*/
1665-
void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure);
1668+
//void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure);
16661669
/**
16671670
* armv7m_nvic_get_pending_irq_info: return highest priority pending
16681671
* exception, and whether it targets Secure state
@@ -1676,8 +1679,8 @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure);
16761679
* to true if the current highest priority pending exception should
16771680
* be taken to Secure state, false for NS.
16781681
*/
1679-
void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq,
1680-
bool *ptargets_secure);
1682+
//void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq,
1683+
// bool *ptargets_secure);
16811684
/**
16821685
* armv7m_nvic_acknowledge_irq: make highest priority pending exception active
16831686
* @opaque: the NVIC
@@ -1686,7 +1689,7 @@ void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq,
16861689
* state to the active state, and update v7m.exception to indicate that
16871690
* it is the exception currently being handled.
16881691
*/
1689-
void armv7m_nvic_acknowledge_irq(void *opaque);
1692+
//void armv7m_nvic_acknowledge_irq(void *opaque);
16901693
/**
16911694
* armv7m_nvic_complete_irq: complete specified interrupt or exception
16921695
* @opaque: the NVIC
@@ -1698,7 +1701,7 @@ void armv7m_nvic_acknowledge_irq(void *opaque);
16981701
* 0 if there is still an irq active after this one was completed
16991702
* (Ignoring -1, this is the same as the RETTOBASE value before completion.)
17001703
*/
1701-
int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure);
1704+
//int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure);
17021705
/**
17031706
* armv7m_nvic_raw_execution_priority: return the raw execution priority
17041707
* @opaque: the NVIC

0 commit comments

Comments
 (0)