2015-04-10 16:44:37 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-10 16:44:37 -07:00
|
|
|
*/
|
|
|
|
|
2015-12-04 10:09:39 -05:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief New thread creation for ARCv2
|
|
|
|
*
|
2016-12-18 09:42:55 -05:00
|
|
|
* Core thread related primitives for the ARCv2 processor architecture.
|
2015-04-10 16:44:37 -07:00
|
|
|
*/
|
|
|
|
|
2016-12-23 08:35:34 -05:00
|
|
|
#include <kernel.h>
|
2019-10-25 00:08:21 +09:00
|
|
|
#include <ksched.h>
|
2016-11-08 10:36:50 -05:00
|
|
|
#include <offsets_short.h>
|
2015-06-14 14:19:10 -04:00
|
|
|
#include <wait_q.h>
|
2018-02-12 19:42:37 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
#include <arch/arc/v2/mpu/arc_core_mpu.h>
|
|
|
|
#endif
|
|
|
|
|
2015-04-10 16:44:37 -07:00
|
|
|
/* initial stack frame */
|
|
|
|
struct init_stack_frame {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t pc;
|
2018-02-01 16:34:47 +08:00
|
|
|
#ifdef CONFIG_ARC_HAS_SECURE
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t sec_stat;
|
2018-02-01 16:34:47 +08:00
|
|
|
#endif
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t status32;
|
|
|
|
uint32_t r3;
|
|
|
|
uint32_t r2;
|
|
|
|
uint32_t r1;
|
|
|
|
uint32_t r0;
|
2015-04-10 16:44:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2015-08-20 11:04:01 -04:00
|
|
|
* @brief Initialize a new thread from its stack space
|
2015-04-10 16:44:37 -07:00
|
|
|
*
|
2016-11-08 10:36:50 -05:00
|
|
|
* The thread control structure is put at the lower address of the stack. An
|
2015-04-10 16:44:37 -07:00
|
|
|
* initial context, to be "restored" by __return_from_coop(), is put at
|
|
|
|
* the other end of the stack, and thus reusable by the stack when not
|
|
|
|
* needed anymore.
|
|
|
|
*
|
|
|
|
* The initial context is a basic stack frame that contains arguments for
|
2019-03-08 14:19:05 -07:00
|
|
|
* z_thread_entry() return address, that points at z_thread_entry()
|
2015-04-10 16:44:37 -07:00
|
|
|
* and status register.
|
|
|
|
*
|
|
|
|
* <options> is currently unused.
|
|
|
|
*
|
2015-10-20 09:42:33 -07:00
|
|
|
* @param pStackmem the pointer to aligned stack memory
|
|
|
|
* @param stackSize the stack size in bytes
|
|
|
|
* @param pEntry thread entry point routine
|
|
|
|
* @param parameter1 first param to entry point
|
|
|
|
* @param parameter2 second param to entry point
|
|
|
|
* @param parameter3 third param to entry point
|
2016-09-30 11:02:37 -04:00
|
|
|
* @param priority thread priority
|
2016-11-02 15:55:20 -05:00
|
|
|
* @param options thread options: K_ESSENTIAL
|
2015-10-20 09:42:33 -07:00
|
|
|
*
|
2015-07-01 17:29:04 -04:00
|
|
|
* @return N/A
|
2015-04-10 16:44:37 -07:00
|
|
|
*/
|
2019-11-07 12:43:29 -08:00
|
|
|
void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|
|
|
size_t stackSize, k_thread_entry_t pEntry,
|
|
|
|
void *parameter1, void *parameter2, void *parameter3,
|
|
|
|
int priority, unsigned int options)
|
2015-04-10 16:44:37 -07:00
|
|
|
{
|
2019-04-04 12:05:28 -07:00
|
|
|
char *pStackMem = Z_THREAD_STACK_BUFFER(stack);
|
2016-11-08 15:44:05 -05:00
|
|
|
|
2018-02-12 19:42:37 +08:00
|
|
|
char *stackEnd;
|
2020-04-02 22:53:06 +08:00
|
|
|
char *priv_stack_end;
|
2015-04-10 16:44:37 -07:00
|
|
|
struct init_stack_frame *pInitCtx;
|
2018-02-12 19:42:37 +08:00
|
|
|
|
2019-05-17 10:20:01 -04:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2019-02-19 16:34:43 +08:00
|
|
|
|
|
|
|
size_t stackAdjSize;
|
|
|
|
size_t offset = 0;
|
|
|
|
|
2020-04-02 22:53:06 +08:00
|
|
|
|
|
|
|
stackAdjSize = Z_ARC_MPU_SIZE_ALIGN(stackSize);
|
|
|
|
|
2019-02-19 16:34:43 +08:00
|
|
|
stackEnd = pStackMem + stackAdjSize;
|
|
|
|
|
2019-05-17 14:57:48 -04:00
|
|
|
#ifdef CONFIG_STACK_POINTER_RANDOM
|
2019-02-19 16:34:43 +08:00
|
|
|
offset = stackAdjSize - stackSize;
|
2018-02-12 19:42:37 +08:00
|
|
|
#endif
|
|
|
|
|
2018-08-07 12:46:52 +08:00
|
|
|
if (options & K_USER) {
|
2020-04-03 12:25:29 +08:00
|
|
|
#ifdef CONFIG_GEN_PRIV_STACKS
|
2018-08-07 12:46:52 +08:00
|
|
|
thread->arch.priv_stack_start =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)z_priv_stack_find(thread->stack_obj);
|
2020-04-03 12:25:29 +08:00
|
|
|
#else
|
|
|
|
thread->arch.priv_stack_start =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)(stackEnd + STACK_GUARD_SIZE);
|
2020-04-03 12:25:29 +08:00
|
|
|
#endif
|
2018-08-20 22:39:39 +08:00
|
|
|
|
2020-04-02 22:53:06 +08:00
|
|
|
priv_stack_end = (char *)Z_STACK_PTR_ALIGN(
|
|
|
|
thread->arch.priv_stack_start +
|
|
|
|
CONFIG_PRIVILEGED_STACK_SIZE);
|
2018-08-20 22:39:39 +08:00
|
|
|
|
|
|
|
/* reserve 4 bytes for the start of user sp */
|
2020-04-02 22:53:06 +08:00
|
|
|
priv_stack_end -= 4;
|
2020-05-27 11:26:57 -05:00
|
|
|
(*(uint32_t *)priv_stack_end) = Z_STACK_PTR_ALIGN(
|
|
|
|
(uint32_t)stackEnd - offset);
|
2018-08-20 22:39:39 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
|
|
|
|
/* reserve stack space for the userspace local data struct */
|
|
|
|
thread->userspace_local_data =
|
|
|
|
(struct _thread_userspace_local_data *)
|
2020-04-19 15:06:31 -07:00
|
|
|
Z_STACK_PTR_ALIGN(stackEnd -
|
2019-02-19 16:34:43 +08:00
|
|
|
sizeof(*thread->userspace_local_data) - offset);
|
2018-08-20 22:39:39 +08:00
|
|
|
/* update the start of user sp */
|
2020-05-27 11:26:57 -05:00
|
|
|
(*(uint32_t *)priv_stack_end) =
|
|
|
|
(uint32_t) thread->userspace_local_data;
|
2018-08-20 22:39:39 +08:00
|
|
|
#endif
|
|
|
|
|
2018-08-07 12:46:52 +08:00
|
|
|
} else {
|
2020-04-03 12:25:29 +08:00
|
|
|
pStackMem += STACK_GUARD_SIZE;
|
|
|
|
stackEnd += STACK_GUARD_SIZE;
|
2018-08-07 12:46:52 +08:00
|
|
|
|
|
|
|
thread->arch.priv_stack_start = 0;
|
2018-08-20 22:39:39 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
|
|
|
|
/* reserve stack space for the userspace local data struct */
|
2020-04-02 22:53:06 +08:00
|
|
|
priv_stack_end = (char *)Z_STACK_PTR_ALIGN(stackEnd
|
2019-02-19 16:34:43 +08:00
|
|
|
- sizeof(*thread->userspace_local_data) - offset);
|
2018-08-20 22:39:39 +08:00
|
|
|
thread->userspace_local_data =
|
2020-04-02 22:53:06 +08:00
|
|
|
(struct _thread_userspace_local_data *)priv_stack_end;
|
2018-11-06 01:29:39 +08:00
|
|
|
#else
|
2020-04-02 22:53:06 +08:00
|
|
|
priv_stack_end = (char *)Z_STACK_PTR_ALIGN(stackEnd - offset);
|
2018-08-20 22:39:39 +08:00
|
|
|
#endif
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
}
|
2018-08-07 12:46:52 +08:00
|
|
|
|
2020-04-19 14:28:15 -07:00
|
|
|
z_new_thread_init(thread, pStackMem, stackAdjSize);
|
2018-08-16 15:42:28 -07:00
|
|
|
|
2018-08-07 12:46:52 +08:00
|
|
|
/* carve the thread entry struct from the "base" of
|
2018-08-20 22:39:39 +08:00
|
|
|
the privileged stack */
|
2018-08-07 12:46:52 +08:00
|
|
|
pInitCtx = (struct init_stack_frame *)(
|
2020-04-02 22:53:06 +08:00
|
|
|
priv_stack_end - sizeof(struct init_stack_frame));
|
2018-08-16 15:42:28 -07:00
|
|
|
|
2018-08-07 12:46:52 +08:00
|
|
|
/* fill init context */
|
2018-11-29 11:09:09 -08:00
|
|
|
pInitCtx->status32 = 0U;
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
if (options & K_USER) {
|
2020-05-27 11:26:57 -05:00
|
|
|
pInitCtx->pc = ((uint32_t)z_user_thread_entry_wrapper);
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
} else {
|
2020-05-27 11:26:57 -05:00
|
|
|
pInitCtx->pc = ((uint32_t)z_thread_entry_wrapper);
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
}
|
2018-08-07 12:46:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* enable US bit, US is read as zero in user mode. This will allow use
|
|
|
|
* mode sleep instructions, and it enables a form of denial-of-service
|
|
|
|
* attack by putting the processor in sleep mode, but since interrupt
|
|
|
|
* level/mask can't be set from user space that's not worse than
|
|
|
|
* executing a loop without yielding.
|
|
|
|
*/
|
|
|
|
pInitCtx->status32 |= _ARC_V2_STATUS32_US;
|
|
|
|
#else /* For no USERSPACE feature */
|
2020-04-03 12:25:29 +08:00
|
|
|
pStackMem += STACK_GUARD_SIZE;
|
2018-08-07 12:46:52 +08:00
|
|
|
stackEnd = pStackMem + stackSize;
|
|
|
|
|
2020-04-19 14:28:15 -07:00
|
|
|
z_new_thread_init(thread, pStackMem, stackSize);
|
2018-08-07 12:46:52 +08:00
|
|
|
|
2020-04-02 22:53:06 +08:00
|
|
|
priv_stack_end = stackEnd;
|
2018-08-07 12:46:52 +08:00
|
|
|
|
|
|
|
pInitCtx = (struct init_stack_frame *)(
|
2020-04-02 22:53:06 +08:00
|
|
|
Z_STACK_PTR_ALIGN(priv_stack_end) -
|
2018-08-07 12:46:52 +08:00
|
|
|
sizeof(struct init_stack_frame));
|
|
|
|
|
2018-11-29 11:09:09 -08:00
|
|
|
pInitCtx->status32 = 0U;
|
2020-05-27 11:26:57 -05:00
|
|
|
pInitCtx->pc = ((uint32_t)z_thread_entry_wrapper);
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
#endif
|
2018-02-01 16:34:47 +08:00
|
|
|
|
2019-08-01 12:39:35 +08:00
|
|
|
#ifdef CONFIG_ARC_SECURE_FIRMWARE
|
2019-03-08 14:19:05 -07:00
|
|
|
pInitCtx->sec_stat = z_arc_v2_aux_reg_read(_ARC_V2_SEC_STAT);
|
2018-02-01 16:34:47 +08:00
|
|
|
#endif
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
pInitCtx->r0 = (uint32_t)pEntry;
|
|
|
|
pInitCtx->r1 = (uint32_t)parameter1;
|
|
|
|
pInitCtx->r2 = (uint32_t)parameter2;
|
|
|
|
pInitCtx->r3 = (uint32_t)parameter3;
|
2018-08-07 12:46:52 +08:00
|
|
|
|
|
|
|
/* stack check configuration */
|
2016-03-11 18:29:14 +01:00
|
|
|
#ifdef CONFIG_ARC_STACK_CHECKING
|
2019-08-01 12:39:35 +08:00
|
|
|
#ifdef CONFIG_ARC_SECURE_FIRMWARE
|
2018-07-19 16:59:21 +08:00
|
|
|
pInitCtx->sec_stat |= _ARC_V2_SEC_STAT_SSC;
|
|
|
|
#else
|
2018-08-07 12:46:52 +08:00
|
|
|
pInitCtx->status32 |= _ARC_V2_STATUS32_SC;
|
2018-07-19 16:59:21 +08:00
|
|
|
#endif
|
2018-06-01 14:00:22 +08:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
if (options & K_USER) {
|
2020-05-27 11:26:57 -05:00
|
|
|
thread->arch.u_stack_top = (uint32_t)pStackMem;
|
|
|
|
thread->arch.u_stack_base = (uint32_t)stackEnd;
|
2018-06-01 14:00:22 +08:00
|
|
|
thread->arch.k_stack_top =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)(thread->arch.priv_stack_start);
|
|
|
|
thread->arch.k_stack_base = (uint32_t)
|
2020-04-02 22:53:06 +08:00
|
|
|
(thread->arch.priv_stack_start + CONFIG_PRIVILEGED_STACK_SIZE);
|
2018-06-01 14:00:22 +08:00
|
|
|
} else {
|
2020-05-27 11:26:57 -05:00
|
|
|
thread->arch.k_stack_top = (uint32_t)pStackMem;
|
|
|
|
thread->arch.k_stack_base = (uint32_t)stackEnd;
|
2018-06-01 14:00:22 +08:00
|
|
|
thread->arch.u_stack_top = 0;
|
|
|
|
thread->arch.u_stack_base = 0;
|
|
|
|
}
|
|
|
|
#else
|
2020-05-27 11:26:57 -05:00
|
|
|
thread->arch.k_stack_top = (uint32_t) pStackMem;
|
|
|
|
thread->arch.k_stack_base = (uint32_t) stackEnd;
|
2018-06-01 14:00:22 +08:00
|
|
|
#endif
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
#endif
|
2019-06-13 17:21:52 +08:00
|
|
|
|
2019-07-17 01:10:39 +03:00
|
|
|
#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
|
|
|
|
pInitCtx->status32 |= _ARC_V2_STATUS32_AD;
|
|
|
|
#endif
|
|
|
|
|
2019-06-13 17:21:52 +08:00
|
|
|
thread->switch_handle = thread;
|
2016-11-08 10:36:50 -05:00
|
|
|
thread->arch.relinquish_cause = _CAUSE_COOP;
|
|
|
|
thread->callee_saved.sp =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)pInitCtx - ___callee_saved_stack_t_SIZEOF;
|
2015-04-10 16:44:37 -07:00
|
|
|
|
2016-11-08 10:36:50 -05:00
|
|
|
/* initial values in all other regs/k_thread entries are irrelevant */
|
2015-04-10 16:44:37 -07:00
|
|
|
}
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
|
2020-02-03 21:07:19 +08:00
|
|
|
void *z_arch_get_next_switch_handle(struct k_thread **old_thread)
|
|
|
|
{
|
|
|
|
*old_thread = _current;
|
|
|
|
|
|
|
|
return z_get_next_switch_handle(*old_thread);
|
|
|
|
}
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
|
|
|
|
void *p1, void *p2, void *p3)
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
{
|
2018-02-12 19:42:37 +08:00
|
|
|
|
2020-04-02 22:53:06 +08:00
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
_current->stack_info.start = (uint32_t)_current->stack_obj;
|
2020-04-03 12:25:29 +08:00
|
|
|
#ifdef CONFIG_GEN_PRIV_STACKS
|
2018-02-12 19:42:37 +08:00
|
|
|
_current->arch.priv_stack_start =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)z_priv_stack_find(_current->stack_obj);
|
2020-04-03 12:25:29 +08:00
|
|
|
#else
|
|
|
|
_current->arch.priv_stack_start =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)(_current->stack_info.start +
|
2020-04-03 12:25:29 +08:00
|
|
|
_current->stack_info.size + STACK_GUARD_SIZE);
|
|
|
|
#endif
|
2020-04-02 22:53:06 +08:00
|
|
|
|
2018-02-12 19:42:37 +08:00
|
|
|
|
2018-06-01 14:00:22 +08:00
|
|
|
#ifdef CONFIG_ARC_STACK_CHECKING
|
|
|
|
_current->arch.k_stack_top = _current->arch.priv_stack_start;
|
|
|
|
_current->arch.k_stack_base = _current->arch.priv_stack_start +
|
2018-12-11 14:27:28 +01:00
|
|
|
CONFIG_PRIVILEGED_STACK_SIZE;
|
2018-06-01 14:00:22 +08:00
|
|
|
_current->arch.u_stack_top = _current->stack_info.start;
|
|
|
|
_current->arch.u_stack_base = _current->stack_info.start +
|
|
|
|
_current->stack_info.size;
|
|
|
|
#endif
|
|
|
|
|
2018-02-12 19:42:37 +08:00
|
|
|
/* possible optimizaiton: no need to load mem domain anymore */
|
|
|
|
/* need to lock cpu here ? */
|
|
|
|
configure_mpu_thread(_current);
|
|
|
|
|
2019-03-14 09:20:46 -06:00
|
|
|
z_arc_userspace_enter(user_entry, p1, p2, p3,
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)_current->stack_obj,
|
2020-03-02 13:45:34 +08:00
|
|
|
_current->stack_info.size, _current);
|
arch: arc: add user space support for arc
* add the implementation of syscall
* based on 'trap_s' intruction, id = 3
* add the privilege stack
* the privilege stack is allocted with thread stack
* for the kernel thread, the privilege stack is also a
part of thread stack, the start of stack can be configured
as stack guard
* for the user thread, no stack guard, when the user stack is
overflow, it will fall into kernel memory area which requires
kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
specific
* the above codes have been tested through tests/kernel/mem_protect/
userspace for MPU version 2
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-23 17:13:09 +08:00
|
|
|
CODE_UNREACHABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2019-06-17 18:53:06 +08:00
|
|
|
|
2020-05-03 18:03:19 +09:00
|
|
|
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
|
2019-11-07 12:43:29 -08:00
|
|
|
int arch_float_disable(struct k_thread *thread)
|
2019-06-17 18:53:06 +08:00
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
|
|
|
/* Ensure a preemptive context switch does not occur */
|
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
|
|
|
/* Disable all floating point capabilities for the thread */
|
|
|
|
thread->base.user_options &= ~K_FP_REGS;
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-06-20 09:29:12 +08:00
|
|
|
|
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
int arch_float_enable(struct k_thread *thread)
|
2019-06-20 09:29:12 +08:00
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
|
|
|
/* Ensure a preemptive context switch does not occur */
|
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
|
|
|
/* Enable all floating point capabilities for the thread */
|
|
|
|
thread->base.user_options |= K_FP_REGS;
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-03 18:03:19 +09:00
|
|
|
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
|