Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrupt nesting #10057

Merged
merged 9 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
arch/armv6-m: By default, add REG_EXC_RETURN to xcptcontext.
Signed-off-by: wangming9 <[email protected]>
  • Loading branch information
wangming9 committed Aug 3, 2023
commit 5731e08ac4c8cc843c8f734108a038f43e922694
13 changes: 2 additions & 11 deletions arch/arm/include/armv6-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,8 @@
#define REG_R9 (7) /* R9 */
#define REG_R10 (8) /* R10 */
#define REG_R11 (9) /* R11 */

/* In the kernel build, we may return to either privileged or unprivileged
* modes.
*/

#ifdef CONFIG_BUILD_PROTECTED
# define REG_EXC_RETURN (10) /* EXC_RETURN */
# define SW_XCPT_REGS (11)
#else
# define SW_XCPT_REGS (10)
#endif
#define REG_EXC_RETURN (10) /* EXC_RETURN */
#define SW_XCPT_REGS (11)

/* The total number of registers saved by software */

Expand Down
22 changes: 0 additions & 22 deletions arch/arm/src/armv6-m/arm_exception.S
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ exception_common:
* the context is on the MSP or PSP.
*/

#ifdef CONFIG_BUILD_PROTECTED
mov r0, r14 /* Copy high register to low register */
lsls r0, #(31 - EXC_RETURN_PROCESS_BITNO) /* Move to bit 31 */
bmi 1f /* Test bit 31 */
Expand All @@ -123,9 +122,6 @@ exception_common:

1:
mrs r1, psp /* R1=The process stack pointer */
#else
mrs r1, msp /* R1=The main stack pointer */
#endif

/* R1 is the current stack pointer. HW_XCPT_REGS were pushed onto the stack
* when the interrupt was taken so (R1)+HW_XCPT_SIZE is the value of the
Expand All @@ -151,12 +147,8 @@ exception_common:
mov r3, r9
mov r4, r10
mov r5, r11
#ifdef CONFIG_BUILD_PROTECTED
mov r6, r14
stmia r0!, {r2-r6} /* Save the high registers r8-r11 and r14 */
#else
stmia r0!, {r2-r5} /* Save the high registers r8-r11 */
#endif

/* Get the exception number in R0=IRQ, R1=register save area on stack */

Expand Down Expand Up @@ -196,20 +188,12 @@ exception_common:

movs r2, #(4*REG_R8) /* R2=Offset to R8 storage */
adds r1, r0, r2 /* R1=Address of R8 storage */
#ifdef CONFIG_BUILD_PROTECTED
ldmia r1!, {r2-r6} /* Recover R8-R11 and R14 (5 registers)*/
mov r8, r2 /* Move to position in high registers */
mov r9, r3
mov r10, r4
mov r11, r5
mov r14, r6 /* EXEC_RETURN */
#else
ldmia r1!, {r2-r5} /* Recover R8-R11 (4 registers)*/
mov r8, r2 /* Move to position in high registers */
mov r9, r3
mov r10, r4
mov r11, r5
#endif

/* Recover SP (R2), PRIMASK (R3), and R4-R7. Determine the value of
* the stack pointer as it was on entry to the exception handler.
Expand All @@ -223,7 +207,6 @@ exception_common:
* context is on the MSP or PSP.
*/

#ifdef CONFIG_BUILD_PROTECTED
mov r0, r14 /* Copy high register to low register */
lsls r0, #(31 - EXC_RETURN_PROCESS_BITNO) /* Move to bit 31 */
bmi 3f /* Test bit 31 */
Expand All @@ -234,11 +217,6 @@ exception_common:
msr psp, r1 /* R1=The process stack pointer */

4:
#else
msr msp, r1 /* R1=The main stack pointer */
ldr r0, =EXC_RETURN_PRIVTHR /* R0=EXC_RETURN to privileged mode */
mov r14, r0 /* R14=EXC_RETURN to privileged mode */
#endif

/* Restore the interrupt state */

Expand Down
2 changes: 0 additions & 2 deletions arch/arm/src/armv6-m/arm_initialstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ void up_initial_state(struct tcb_s *tcb)
#endif
#endif /* CONFIG_PIC */

#ifdef CONFIG_BUILD_PROTECTED
/* All tasks start via a stub function in kernel space. So all
* tasks must start in privileged thread mode. If CONFIG_BUILD_PROTECTED
* is defined, then that stub function will switch to unprivileged
* mode before transferring control to the user task.
*/

xcp->regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
#endif

/* Enable or disable interrupts, based on user configuration */

Expand Down
8 changes: 3 additions & 5 deletions arch/arm/src/armv6-m/arm_saveusercontext.S
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,12 @@ up_saveusercontext:
/* Save r11 and EXC_RETURN */

mov r1, r11
#ifdef CONFIG_BUILD_PROTECTED

/* Save EXC_RETURN to 0xffffffff */

movs r2, #-1
movs r2, #0
subs r2, #1
stmia r0!, {r1-r2}
#else
stmia r0!, {r1}
#endif

movs r0, #0
bx lr
Expand Down
10 changes: 0 additions & 10 deletions arch/arm/src/armv6-m/arm_svcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,8 @@ int arm_svcall(int irq, void *context, void *arg)
svcinfo(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
# ifdef CONFIG_BUILD_PROTECTED
svcinfo(" PSR: %08x PRIMASK: %08x EXC_RETURN: %08x\n",
regs[REG_XPSR], regs[REG_PRIMASK], regs[REG_EXC_RETURN]);
# else
svcinfo(" PSR: %08x PRIMASK: %08x\n",
regs[REG_XPSR], regs[REG_PRIMASK]);
# endif
}
#endif

Expand Down Expand Up @@ -446,14 +441,9 @@ int arm_svcall(int irq, void *context, void *arg)
CURRENT_REGS[REG_R10], CURRENT_REGS[REG_R11],
CURRENT_REGS[REG_R12], CURRENT_REGS[REG_R13],
CURRENT_REGS[REG_R14], CURRENT_REGS[REG_R15]);
# ifdef CONFIG_BUILD_PROTECTED
svcinfo(" PSR: %08x PRIMASK: %08x EXC_RETURN: %08x\n",
CURRENT_REGS[REG_XPSR], CURRENT_REGS[REG_PRIMASK],
CURRENT_REGS[REG_EXC_RETURN]);
# else
svcinfo(" PSR: %08x PRIMASK: %08x\n",
CURRENT_REGS[REG_XPSR], CURRENT_REGS[REG_PRIMASK]);
# endif
}
# ifdef CONFIG_DEBUG_SVCALL
else
Expand Down