Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 52 additions & 29 deletions arch/risc-v/src/qemu-rv/chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,45 @@

#ifdef __ASSEMBLY__

#if CONFIG_ARCH_INTERRUPTSTACK > 15

/****************************************************************************
* Name: setintstack_bounds
*
* Description:
* Set sp to high if sp is outside [low, high], the bounds of the
* interrupt stack for the current CPU.
*
****************************************************************************/

.macro setintstack_bounds high, low

/* Check if sp is below the low address of the interrupt stack
* (outside the interrupt stack).
*/

blt sp, \low, 1f

/* Check if sp is above the high address of the interrupt stack
* (outside the interrupt stack)
*/

bgt sp, \high, 1f

/* If sp is within the interrupt stack boundaries, no action is required */

j 2f

1:
/* Set sp to the high address of the interrupt stack (start of the
* interrupt stack)
*/

mv sp, \high

2:
.endm

/****************************************************************************
* Name: setintstack
*
Expand All @@ -56,7 +95,7 @@
*
****************************************************************************/

#if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 15
#if defined(CONFIG_SMP)
.macro setintstack tmp0, tmp1
up_cpu_index \tmp0
li \tmp1, STACKFRAME_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK)
Expand All @@ -76,40 +115,24 @@

sub \tmp1, \tmp0, \tmp1

/* Check if sp is below the low address of the interrupt stack
* (outside the interrupt stack).
*/

blt sp, \tmp1, 1f

/* Check if sp is above the high address of the interrupt stack
* (outside the interrupt stack)
*/

bgt sp, \tmp0, 1f

/* If sp is within the interrupt stack boundaries, no action is required */
setintstack_bounds \tmp0, \tmp1
.endm
#elif defined(CONFIG_ARCH_USE_S_MODE)
.macro setintstack tmp0, tmp1
csrr \tmp0, CSR_SCRATCH
REGLOAD \tmp0, RISCV_PERCPU_IRQSTACK(\tmp0)

j 2f
/* tmp0 = high address (top) of the interrupt stack for this hart */

1:
/* Set sp to the high address of the interrupt stack (start of the
* interrupt stack)
*/
li \tmp1, STACKFRAME_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK)
sub \tmp1, \tmp0, \tmp1

mv sp, \tmp0
/* tmp1 = low address of the interrupt stack */

2:
setintstack_bounds \tmp0, \tmp1
.endm
#endif /* CONFIG_SMP && CONFIG_ARCH_INTERRUPTSTACK > 15 */
#endif /* defined(CONFIG_SMP) */

#if CONFIG_ARCH_INTERRUPTSTACK > 15
#if !defined(CONFIG_SMP) && defined(CONFIG_ARCH_USE_S_MODE)
.macro setintstack tmp0, tmp1
csrr \tmp0, CSR_SCRATCH
REGLOAD sp, RISCV_PERCPU_IRQSTACK(\tmp0)
.endm
#endif /* !defined(CONFIG_SMP) && defined(CONFIG_ARCH_USE_S_MODE) */
#endif /* CONFIG_ARCH_INTERRUPTSTACK > 15 */

#endif /* __ASSEMBLY__ */
Expand Down
Loading