@@ -88,6 +88,23 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
88
88
(u32_t )(stackEnd + STACK_GUARD_SIZE );
89
89
thread -> arch .priv_stack_size =
90
90
(u32_t )(CONFIG_PRIVILEGED_STACK_SIZE );
91
+
92
+ stackAdjEnd = (char * )STACK_ROUND_DOWN (stackEnd + STACK_GUARD_SIZE +
93
+ CONFIG_PRIVILEGED_STACK_SIZE );
94
+
95
+ /* reserve 4 bytes for the start of user sp */
96
+ stackAdjEnd -= 4 ;
97
+ (* (u32_t * )stackAdjEnd ) = (u32_t )stackEnd ;
98
+
99
+ #ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
100
+ /* reserve stack space for the userspace local data struct */
101
+ thread -> userspace_local_data =
102
+ (struct _thread_userspace_local_data * )
103
+ STACK_ROUND_DOWN (stackEnd - sizeof (* thread -> userspace_local_data ));
104
+ /* update the start of user sp */
105
+ (* (u32_t * )stackAdjEnd ) = (u32_t ) thread -> userspace_local_data ;
106
+ #endif
107
+
91
108
} else {
92
109
/* for kernel thread, the privilege stack is merged into thread stack */
93
110
/* if MPU_STACK_GUARD is enabled, reserve the the stack area
@@ -105,32 +122,31 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack,
105
122
106
123
thread -> arch .priv_stack_start = 0 ;
107
124
thread -> arch .priv_stack_size = 0 ;
125
+
126
+ stackAdjEnd = (char * )STACK_ROUND_DOWN (stackEnd );
127
+
128
+ #ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
129
+ /* reserve stack space for the userspace local data struct */
130
+ stackAdjEnd = (char * )STACK_ROUND_DOWN (stackEnd
131
+ - sizeof (* thread -> userspace_local_data ));
132
+ thread -> userspace_local_data =
133
+ (struct _thread_userspace_local_data * )stackAdjEnd ;
134
+ #endif
108
135
}
109
136
110
137
_new_thread_init (thread , pStackMem , stackSize , priority , options );
111
138
112
- stackAdjEnd = stackEnd ;
113
139
114
- #ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
115
- /* reserve stack space for the userspace local data struct */
116
- stackAdjEnd = (char * )STACK_ROUND_DOWN (stackEnd
117
- - sizeof (* thread -> userspace_local_data ));
118
- thread -> userspace_local_data =
119
- (struct _thread_userspace_local_data * )stackAdjEnd ;
120
- #endif
121
140
/* carve the thread entry struct from the "base" of
122
- the user stack */
141
+ the privileged stack */
123
142
pInitCtx = (struct init_stack_frame * )(
124
- STACK_ROUND_DOWN (stackAdjEnd ) -
125
- sizeof (struct init_stack_frame ));
143
+ stackAdjEnd - sizeof (struct init_stack_frame ));
126
144
127
145
/* fill init context */
146
+ pInitCtx -> status32 = 0 ;
128
147
if (options & K_USER ) {
129
- /* through exception return to user mode */
130
- pInitCtx -> status32 = _ARC_V2_STATUS32_AE ;
131
148
pInitCtx -> pc = ((u32_t )_user_thread_entry_wrapper );
132
149
} else {
133
- pInitCtx -> status32 = 0 ;
134
150
pInitCtx -> pc = ((u32_t )_thread_entry_wrapper );
135
151
}
136
152
0 commit comments