2017-08-15 12:20:42 +08:00
|
|
|
/*
|
2019-03-05 10:29:16 +08:00
|
|
|
* Copyright (c) 2019 Synopsys.
|
2017-08-15 12:20:42 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <device.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <soc.h>
|
|
|
|
#include <arch/arc/v2/aux_regs.h>
|
|
|
|
#include <arch/arc/v2/mpu/arc_mpu.h>
|
|
|
|
#include <arch/arc/v2/mpu/arc_core_mpu.h>
|
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
|
|
|
#include <linker/linker-defs.h>
|
2017-08-15 12:20:42 +08:00
|
|
|
|
2018-09-17 22:56:20 +08:00
|
|
|
#define LOG_LEVEL CONFIG_MPU_LOG_LEVEL
|
|
|
|
#include <logging/log.h>
|
2019-03-05 10:29:16 +08:00
|
|
|
LOG_MODULE_REGISTER(mpu);
|
2017-11-29 17:42:00 +08:00
|
|
|
|
2017-08-15 12:20:42 +08:00
|
|
|
/**
|
2017-12-20 16:48:45 +08:00
|
|
|
* @brief Get the number of supported MPU regions
|
2017-08-15 12:20:42 +08:00
|
|
|
*
|
|
|
|
*/
|
2019-03-14 23:20:46 +08:00
|
|
|
static inline u8_t get_num_regions(void)
|
2017-08-15 12:20:42 +08:00
|
|
|
{
|
2019-03-09 05:19:05 +08:00
|
|
|
u32_t num = z_arc_v2_aux_reg_read(_ARC_V2_MPU_BUILD);
|
2017-08-15 12:20:42 +08:00
|
|
|
|
2019-02-27 02:03:24 +08:00
|
|
|
num = (num & 0xFF00U) >> 8U;
|
2017-08-15 12:20:42 +08:00
|
|
|
|
|
|
|
return (u8_t)num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This internal function is utilized by the MPU driver to parse the intent
|
|
|
|
* type (i.e. THREAD_STACK_REGION) and return the correct parameter set.
|
|
|
|
*/
|
2019-03-14 23:20:46 +08:00
|
|
|
static inline u32_t get_region_attr_by_type(u32_t type)
|
2017-08-15 12:20:42 +08:00
|
|
|
{
|
|
|
|
switch (type) {
|
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
|
|
|
case THREAD_STACK_USER_REGION:
|
|
|
|
return REGION_RAM_ATTR;
|
2017-08-15 12:20:42 +08:00
|
|
|
case THREAD_STACK_REGION:
|
2019-03-05 10:29:16 +08:00
|
|
|
return AUX_MPU_ATTR_KW | AUX_MPU_ATTR_KR;
|
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
|
|
|
case THREAD_APP_DATA_REGION:
|
|
|
|
return REGION_RAM_ATTR;
|
2017-08-15 12:20:42 +08:00
|
|
|
case THREAD_STACK_GUARD_REGION:
|
2019-02-07 02:17:40 +08:00
|
|
|
/* no Write and Execute to guard region */
|
2019-03-05 10:29:16 +08:00
|
|
|
return AUX_MPU_ATTR_UR | AUX_MPU_ATTR_KR;
|
2017-12-20 16:48:45 +08:00
|
|
|
default:
|
2019-03-05 10:29:16 +08:00
|
|
|
/* unknown type */
|
2017-12-20 16:48:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 17:42:00 +08:00
|
|
|
#if CONFIG_ARC_MPU_VER == 2
|
2019-03-05 10:29:16 +08:00
|
|
|
#include "arc_mpu_v2_internal.h"
|
2017-11-29 17:42:00 +08:00
|
|
|
#elif CONFIG_ARC_MPU_VER == 3
|
2019-03-05 10:29:16 +08:00
|
|
|
#include "arc_mpu_v3_internal.h"
|
2017-11-29 17:42:00 +08:00
|
|
|
#endif
|