Skip to content

Commit a1504c3

Browse files
Wayne Rennashif
authored andcommitted
arch: arc: set the right init status for user space
The fake exception return is used to jump to user mode. So the init status of user thread is in exception mode. Signed-off-by: Wayne Ren <[email protected]>
1 parent d68c016 commit a1504c3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

arch/arc/core/thread.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
118118
#if CONFIG_USERSPACE
119119
if (options & K_USER) {
120120
pInitCtx->pc = ((u32_t)_user_thread_entry_wrapper);
121+
/* through exception return to user mode */
122+
pInitCtx->status32 = _ARC_V2_STATUS32_AE;
121123
} else {
124+
pInitCtx->status32 = 0;
122125
pInitCtx->pc = ((u32_t)_thread_entry_wrapper);
123126
}
124127
#else
128+
pInitCtx->status32 = 0;
125129
pInitCtx->pc = ((u32_t)_thread_entry_wrapper);
126130
#endif
127131

@@ -143,9 +147,9 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
143147
#ifdef CONFIG_ARC_STACK_CHECKING
144148
#ifdef CONFIG_ARC_HAS_SECURE
145149
pInitCtx->sec_stat |= _ARC_V2_SEC_STAT_SSC;
146-
pInitCtx->status32 = _ARC_V2_STATUS32_E(_ARC_V2_DEF_IRQ_LEVEL);
150+
pInitCtx->status32 |= _ARC_V2_STATUS32_E(_ARC_V2_DEF_IRQ_LEVEL);
147151
#else
148-
pInitCtx->status32 = _ARC_V2_STATUS32_SC |
152+
pInitCtx->status32 |= _ARC_V2_STATUS32_SC |
149153
_ARC_V2_STATUS32_E(_ARC_V2_DEF_IRQ_LEVEL);
150154
#endif
151155
#ifdef CONFIG_USERSPACE
@@ -196,7 +200,7 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
196200
* dst[31:6] dst[5] dst[4] dst[3:0]
197201
* 26'd0 1 STATUS32.IE STATUS32.E[3:0]
198202
*/
199-
thread->arch.intlock_key = 0x3F;
203+
thread->arch.intlock_key = 0x30 | (_ARC_V2_DEF_IRQ_LEVEL & 0xf);
200204
thread->arch.relinquish_cause = _CAUSE_COOP;
201205
thread->callee_saved.sp =
202206
(u32_t)pInitCtx - ___callee_saved_stack_t_SIZEOF;

arch/arc/core/userspace.S

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ SECTION_FUNC(TEXT, _user_thread_entry_wrapper)
6262
/* start of privilege stack */
6363
add blink, r5, CONFIG_PRIVILEGED_STACK_SIZE+STACK_GUARD_SIZE+16
6464

65-
/* r4<- start of user stack region */
66-
mov r0, _kernel
67-
ld_s r1, [r0, _kernel_offset_to_current]
68-
ld r4, [r1, ___thread_stack_info_t_start_OFFSET]
69-
7065
/*
7166
* when CONFIG_INIT_STACKS is enable, stack will be initialized
7267
* in _new_thread_init.
@@ -145,6 +140,7 @@ _clear_user_stack:
145140
_arc_go_to_user_space:
146141
lr r0, [_ARC_V2_STATUS32]
147142
bset r0, r0, _ARC_V2_STATUS32_U_BIT
143+
bclr r0, r0, _ARC_V2_STATUS32_AE_BIT
148144

149145
mov r1, _thread_entry_wrapper
150146

0 commit comments

Comments
 (0)