修复-O2时cortex-m惰性压栈错误,以及内存访问错误时task删除hardfault错误
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -112,7 +112,7 @@
|
||||
"boot_info.h": "c"
|
||||
},
|
||||
"cortex-debug.showRTOS": false,
|
||||
"cortex-debug.variableUseNaturalFormat": true,
|
||||
"cortex-debug.variableUseNaturalFormat": false,
|
||||
"C_Cpp.default.systemIncludePath": [""],
|
||||
"C_Cpp.default.forcedInclude": ["${workspaceFolder}/build/autoconf.h"]
|
||||
}
|
||||
@@ -1,21 +1,28 @@
|
||||
message("========use armv7_8.cmake")
|
||||
|
||||
set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -O0 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -mthumb-interwork -D=MKRTOS \
|
||||
set(CMAKE_C_FLAGS "-mcpu=${CONFIG_ARCH} -O0 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -D=MKRTOS \
|
||||
-std=gnu11 -ffunction-sections -fdata-sections -fno-builtin -u=_printf_float \
|
||||
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
|
||||
-fno-stack-protector -Wl,--gc-sections -D__ARM_ARCH_7M__ \
|
||||
-include ${CMAKE_SOURCE_DIR}/build/autoconf.h \
|
||||
" CACHE STRING "" FORCE)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-mcpu=${CONFIG_ARCH} -O0 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -mthumb-interwork -D=MKRTOS -std=c++11 \
|
||||
set(CMAKE_CXX_FLAGS "-mcpu=${CONFIG_ARCH} -O2 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -mthumb-interwork -D=MKRTOS -std=c++11 \
|
||||
-fmessage-length=0 -Xlinker --print-map -Wall -W -fno-stack-protector -g \
|
||||
-u=_printf_float -D__ARM_ARCH_7M__ \
|
||||
-ffunction-sections -fdata-sections -fno-builtin -nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
|
||||
-include ${CMAKE_SOURCE_DIR}/build/autoconf.h \
|
||||
" CACHE STRING "" FORCE)
|
||||
|
||||
set(CMAKE_ASM_FLAGS "-mcpu=${CONFIG_ARCH} -O0 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -mthumb-interwork -D=MKRTOS \
|
||||
set(CMAKE_ASM_FLAGS "-mcpu=${CONFIG_ARCH} -O2 -g3 -mfloat-abi=${CONFIG_FLOAT_TYPE} -mthumb -mthumb-interwork -D=MKRTOS \
|
||||
-u=_printf_float -std=gnu11 -ffunction-sections -fdata-sections -fno-builtin \
|
||||
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker -fno-stack-protector -D__ARM_ARCH_7M__ \
|
||||
-include ${CMAKE_SOURCE_DIR}/build/autoconf.h \
|
||||
" CACHE STRING "" FORCE)
|
||||
" CACHE STRING "" FORCE)
|
||||
|
||||
if (${CONFIG_FLOAT_TYPE} STREQUAL "hard")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMKRTOS_USE_FPU ")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMKRTOS_USE_FPU ")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DMKRTOS_USE_FPU ")
|
||||
endif()
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ static boot_info_t boot_info; //!< 启动信息
|
||||
void arch_to_sche(void)
|
||||
{
|
||||
// 开启pensv中断
|
||||
write_reg(REG1_ADDR, 0x10000000);
|
||||
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk; // 设置PendSV中断标志位
|
||||
_dmb();
|
||||
_dsb();
|
||||
_isb();
|
||||
}
|
||||
void sys_startup(void)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,7 @@ typedef struct sp_info
|
||||
} sp_info_t;
|
||||
#define _dmb(ins) asm volatile("dmb" : : : "memory")
|
||||
#define _dsb(ins) asm volatile("dsb" : : : "memory")
|
||||
#define _isb(ins) asm volatile("isb" : : : "memory")
|
||||
#define PAGE_SHIFT CONFIG_PAGE_SHIFT
|
||||
#define cpu_sleep() asm volatile("wfi" : : : "memory")
|
||||
#define read_reg(addr) (*((volatile umword_t *)(addr)))
|
||||
|
||||
@@ -91,7 +91,7 @@ void MemManage_Handler(void)
|
||||
if (task_vma_page_fault(&(thread_get_current_task()->mm_space.mem_vma),
|
||||
ALIGN_DOWN(fault_addr, PAGE_SIZE), NULL) < 0)
|
||||
{
|
||||
printk("task:0x%x, mem_addr:0x%lx bus_addr:0x%lx semgement fault.\n",
|
||||
printk("[semgement fault] task:0x%x, mem_addr:0x%lx bus_addr:0x%lx .\n",
|
||||
thread_get_current_task(), fault_addr, bus_addr);
|
||||
task_knl_kill(thread_get_current(), is_knl);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ syscall_ret_user:
|
||||
|
||||
//还原msp的值
|
||||
mrs r0, msp
|
||||
#ifdef MKRTOS_USE_FPU
|
||||
// 如果支持浮点,则里则要把惰性浮点得位置留查出来
|
||||
TST lr, #0x10
|
||||
IT eq
|
||||
addeq r0,r0,#0x48
|
||||
#endif
|
||||
add r0, #0x20
|
||||
ldmfd r0!,{r4-r11}
|
||||
msr msp,r0
|
||||
@@ -37,7 +43,7 @@ syscall_ret_user:
|
||||
.global SVC_Handler
|
||||
.type SVC_Handler, %function
|
||||
SVC_Handler:
|
||||
CPSID I
|
||||
CPSID I
|
||||
TST.W LR, #4
|
||||
ITE EQ
|
||||
MRSEQ R1, MSP
|
||||
@@ -77,6 +83,12 @@ SYS_CALL:
|
||||
stmfd sp!,{r4-r11}
|
||||
//压入到用户栈中
|
||||
stmfd r0,{r4-r11}
|
||||
#ifdef MKRTOS_USE_FPU
|
||||
// 如果支持浮点,则里则要把惰性浮点得位置留查出来
|
||||
TST lr, #0x10
|
||||
IT eq
|
||||
subeq sp,sp,#0x48
|
||||
#endif
|
||||
//取出PSR PC LR R12 R3 R2 R1 R0
|
||||
ldmfd r0,{r4-r11}
|
||||
//压入到内核栈中
|
||||
@@ -99,7 +111,7 @@ SYS_CALL:
|
||||
|
||||
dsb
|
||||
isb
|
||||
orr lr, lr, #0x18
|
||||
orr lr, lr, #0x08
|
||||
bic lr, lr, #0x04
|
||||
CPSIE I
|
||||
bx lr
|
||||
|
||||
@@ -61,7 +61,8 @@ static inline umword_t is_power_of_2(umword_t num)
|
||||
}
|
||||
static inline umword_t align_power_of_2(umword_t num)
|
||||
{
|
||||
if (is_power_of_2(num)) {
|
||||
if (is_power_of_2(num))
|
||||
{
|
||||
return num;
|
||||
}
|
||||
return (1 << (ffs(num) + 1));
|
||||
|
||||
@@ -404,9 +404,9 @@ int task_vma_page_fault(task_vma_t *task_vma, vaddr_t addr, void *paddr)
|
||||
container_of(task_vma, mm_space_t, mem_vma),
|
||||
task_t,
|
||||
mm_space);
|
||||
mword_t status = spinlock_lock(&task_vma->lock);
|
||||
|
||||
#if IS_ENABLED(MPU_PAGE_FAULT_SUPPORT) //!< 缺页模拟
|
||||
mword_t status = spinlock_lock(&task_vma->lock);
|
||||
for (int i = 0; i < MPU_PAGE_NUM; i++)
|
||||
{
|
||||
if (task_vma->mem_pages[i] == NULL)
|
||||
|
||||
@@ -53,10 +53,16 @@ signed short userShellWrite(char *data, unsigned short len)
|
||||
*/
|
||||
signed short userShellRead(char *data, unsigned short len)
|
||||
{
|
||||
while (cons_read((uint8_t *)data, len) <= 0)
|
||||
int rlen;
|
||||
|
||||
again:
|
||||
rlen = cons_read((uint8_t *)data, len);
|
||||
if (rlen <= 0)
|
||||
{
|
||||
u_sleep_ms(5);
|
||||
goto again;
|
||||
}
|
||||
return rlen;
|
||||
}
|
||||
/**
|
||||
* @brief 列出文件
|
||||
|
||||
@@ -10,10 +10,121 @@
|
||||
|
||||
RPC_GENERATION_CALL1(cons_t, CONS_PROT, CONS_WRITE, write,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, data)
|
||||
RPC_GENERATION_CALL2(cons_t, CONS_PROT, CONS_READ, read,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_OUT, RPC_TYPE_DATA, data,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||
// RPC_GENERATION_CALL2(cons_t, CONS_PROT, CONS_READ, read,
|
||||
// rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_OUT, RPC_TYPE_DATA, data,
|
||||
// rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, len)
|
||||
msg_tag_t cons_t_read_call(obj_handler_t hd, rpc_ref_array_uint32_t_uint8_t_32_t *var0, rpc_int_t *var1)
|
||||
{
|
||||
void *buf;
|
||||
ipc_msg_t *msg_ipc;
|
||||
int off = 0;
|
||||
int off_buf = 0;
|
||||
int ret = -1;
|
||||
umword_t op_val = ((umword_t)1);
|
||||
|
||||
thread_msg_buf_get(-1, (umword_t *)(&buf), ((void *)0));
|
||||
msg_ipc = (ipc_msg_t *)buf;
|
||||
msg_ipc->msg_buf[0] = op_val;
|
||||
off += rpc_align(sizeof(op_val), __alignof(((umword_t)1)));
|
||||
|
||||
do
|
||||
{
|
||||
if (1 == 1)
|
||||
{
|
||||
if (2 == 1 || 2 == 4)
|
||||
{
|
||||
int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (1 == 2)
|
||||
{
|
||||
if (2 == 1 || 2 == 4)
|
||||
{
|
||||
int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off_buf = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (1 == 1)
|
||||
{
|
||||
if (1 == 1 || 1 == 4)
|
||||
{
|
||||
int ret = rpc_cli_msg_to_buf_rpc_int_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (1 == 2)
|
||||
{
|
||||
if (1 == 1 || 1 == 4)
|
||||
{
|
||||
int ret = rpc_cli_msg_to_buf_rpc_int_t(var1, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off_buf = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
msg_tag_t tag = thread_ipc_call(((msg_tag_t){.flags = (0), .msg_buf_len = ((((off) / ((sizeof(void *)))) + (((off) % ((sizeof(void *)))) ? 1 : 0))), .map_buf_len = ((((off_buf) / ((sizeof(void *)))) + (((off_buf) % ((sizeof(void *)))) ? 1 : 0))), .prot = (0x0006)}), hd, ipc_timeout_create2(0, 0));
|
||||
if (((int)((tag).prot)) < 0)
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
off = 0;
|
||||
do
|
||||
{
|
||||
if (1 == 1)
|
||||
{
|
||||
if (2 == 2 || 2 == 4)
|
||||
{
|
||||
int ret = rpc_cli_buf_to_msg_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *)));
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (1 == 1)
|
||||
{
|
||||
if (1 == 2 || 1 == 4)
|
||||
{
|
||||
int ret = rpc_cli_buf_to_msg_rpc_int_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *)));
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
return tag;
|
||||
}
|
||||
RPC_GENERATION_CALL1(cons_t, CONS_PROT, CONS_ACTIVE, active,
|
||||
rpc_int_t, rpc_int_t, RPC_DIR_IN, RPC_TYPE_DATA, flags)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <u_util.h>
|
||||
#if !IS_ENABLED(CONFIG_MMU)
|
||||
#define HEAP_SIZE 2048
|
||||
#define STACK_SIZE (2048)
|
||||
#define STACK_SIZE (3*1024)
|
||||
|
||||
#if defined(__CC_ARM)
|
||||
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
|
||||
|
||||
Reference in New Issue
Block a user