From efe4523132169a4f28b84b1820a1a71d35118965 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 30 Aug 2018 20:27:45 +0800 Subject: [Kernel] move module tolibc/libdl. --- include/rtdef.h | 53 ----------------------------------------------------- include/rtthread.h | 38 -------------------------------------- 2 files changed, 91 deletions(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index f8d90ceadb..d18ced3a6f 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -1021,59 +1021,6 @@ struct rt_device_graphic_ops /*@}*/ #endif -#ifdef RT_USING_MODULE -/** - * @addtogroup Module - */ - -/*@{*/ - -/* - * module system - */ - -#define RT_MODULE_FLAG_WITHENTRY 0x00 /**< with entry point */ -#define RT_MODULE_FLAG_WITHOUTENTRY 0x01 /**< without entry point */ - -/** - * Application Module structure - */ -struct rt_module -{ - struct rt_object parent; /**< inherit from object */ - - rt_uint32_t vstart_addr; /**< VMA base address for the - first LOAD segment. */ - rt_uint8_t *module_space; /**< module memory space */ - - void *module_entry; /**< the entry address of module */ - rt_thread_t module_thread; /**< the main thread of module */ - - rt_uint8_t *module_cmd_line; /**< module command line */ - rt_uint32_t module_cmd_size; /**< the size of module command line */ - -#ifdef RT_USING_SLAB - /* module memory allocator */ - void *mem_list; /**< module's free memory list */ - void *page_array; /**< module's using pages */ - rt_uint32_t page_cnt; /**< module's using pages count */ -#endif - - rt_uint16_t nref; /**< reference count */ - - rt_uint16_t nsym; /**< number of symbol in the module */ - struct rt_module_symtab *symtab; /**< module symbol table */ - - rt_uint32_t user_data; /**< arch data in the module */ - - void (*module_init)(void); - void (*module_cleanup)(void); -}; -typedef struct rt_module *rt_module_t; - -/*@}*/ -#endif - /* definitions for libc */ #include "rtlibc.h" diff --git a/include/rtthread.h b/include/rtthread.h index 86a1664f83..4114866f6f 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -442,44 +442,6 @@ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg); /**@}*/ #endif -#ifdef RT_USING_MODULE -/** - * @addtogroup Module - */ - -/**@{*/ - -/* - * module interface - */ -rt_module_t rt_module_load(const char *name, void *module_ptr); -rt_err_t rt_module_unload(rt_module_t module); -#ifdef RT_USING_DFS -rt_module_t rt_module_open(const char *filename); -rt_module_t rt_module_exec_cmd(const char *path, const char *cmd_line, int size); -#endif -void *rt_module_malloc(rt_size_t size); -void *rt_module_realloc(void *ptr, rt_size_t size); -void rt_module_free(rt_module_t module, void *addr); -rt_module_t rt_module_self(void); -rt_module_t rt_module_find(const char *name); - -#ifdef RT_USING_HOOK -void rt_module_load_sethook(void (*hook)(rt_module_t module)); -void rt_module_unload_sethook(void (*hook)(rt_module_t module)); -#endif - -void rt_module_init_object_container(struct rt_module *module); -rt_err_t rt_module_destroy(rt_module_t module); - -/* - * application module system initialization - */ -int rt_system_module_init(void); - -/**@}*/ -#endif - /* * interrupt service */ -- cgit v1.3.1 From 0aa03dd7314d84a0547300b55259294cae1edfd2 Mon Sep 17 00:00:00 2001 From: liang yongxiang Date: Fri, 31 Aug 2018 14:41:13 +0800 Subject: [kernel] add RT_USED to INIT_EXPORT, so that the initialization function is not deleted when it is linked. --- include/rtdef.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index f8d90ceadb..735d535c7e 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -189,13 +189,13 @@ typedef int (*init_fn_t)(void); const char* fn_name; const init_fn_t fn; }; - #define INIT_EXPORT(fn, level) \ - const char __rti_##fn##_name[] = #fn; \ - const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn."level) = \ + #define INIT_EXPORT(fn, level) \ + const char __rti_##fn##_name[] = #fn; \ + RT_USED const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn."level) = \ { __rti_##fn##_name, fn}; #else - #define INIT_EXPORT(fn, level) \ - const init_fn_t __rt_init_##fn SECTION(".rti_fn."level) = fn + #define INIT_EXPORT(fn, level) \ + RT_USED const init_fn_t __rt_init_##fn SECTION(".rti_fn."level) = fn #endif #endif #else -- cgit v1.3.1 From ab1a220eae0cac577d6d7e0cb63d892620e1cd49 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 1 Sep 2018 12:03:32 +0800 Subject: [components] Remove lwP from v3.1.0 --- components/Kconfig | 2 - components/lwp/Kconfig | 7 - components/lwp/SConscript | 20 - components/lwp/arch/arm/cortex-m3/lwp_gcc.S | 176 -------- components/lwp/arch/arm/cortex-m3/lwp_iar.S | 176 -------- components/lwp/arch/arm/cortex-m3/lwp_rvds.S | 184 --------- components/lwp/arch/arm/cortex-m4/lwp_gcc.S | 210 ---------- components/lwp/arch/arm/cortex-m4/lwp_iar.S | 215 ---------- components/lwp/arch/arm/cortex-m4/lwp_rvds.S | 219 ---------- components/lwp/arch/arm/cortex-m7/lwp_gcc.S | 210 ---------- components/lwp/arch/arm/cortex-m7/lwp_iar.S | 215 ---------- components/lwp/arch/arm/cortex-m7/lwp_rvds.S | 218 ---------- components/lwp/lwp.c | 398 ------------------ components/lwp/lwp.h | 84 ---- components/lwp/lwp_mem.c | 236 ----------- components/lwp/lwp_mem.h | 34 -- components/lwp/lwp_memheap.c | 590 --------------------------- components/lwp/lwp_memheap.h | 74 ---- components/lwp/lwp_syscall.c | 283 ------------- components/lwp/lwp_syscall.h | 78 ---- include/rtdef.h | 11 +- 21 files changed, 4 insertions(+), 3636 deletions(-) delete mode 100644 components/lwp/Kconfig delete mode 100644 components/lwp/SConscript delete mode 100644 components/lwp/arch/arm/cortex-m3/lwp_gcc.S delete mode 100644 components/lwp/arch/arm/cortex-m3/lwp_iar.S delete mode 100644 components/lwp/arch/arm/cortex-m3/lwp_rvds.S delete mode 100644 components/lwp/arch/arm/cortex-m4/lwp_gcc.S delete mode 100644 components/lwp/arch/arm/cortex-m4/lwp_iar.S delete mode 100644 components/lwp/arch/arm/cortex-m4/lwp_rvds.S delete mode 100644 components/lwp/arch/arm/cortex-m7/lwp_gcc.S delete mode 100644 components/lwp/arch/arm/cortex-m7/lwp_iar.S delete mode 100644 components/lwp/arch/arm/cortex-m7/lwp_rvds.S delete mode 100644 components/lwp/lwp.c delete mode 100644 components/lwp/lwp.h delete mode 100644 components/lwp/lwp_mem.c delete mode 100644 components/lwp/lwp_mem.h delete mode 100644 components/lwp/lwp_memheap.c delete mode 100644 components/lwp/lwp_memheap.h delete mode 100644 components/lwp/lwp_syscall.c delete mode 100644 components/lwp/lwp_syscall.h (limited to 'include') diff --git a/components/Kconfig b/components/Kconfig index c221f12df3..327489910b 100644 --- a/components/Kconfig +++ b/components/Kconfig @@ -31,8 +31,6 @@ source "$RTT_DIR/components/drivers/Kconfig" source "$RTT_DIR/components/libc/Kconfig" -source "$RTT_DIR/components/lwp/Kconfig" - source "$RTT_DIR/components/net/Kconfig" source "$RTT_DIR/components/vbus/Kconfig" diff --git a/components/lwp/Kconfig b/components/lwp/Kconfig deleted file mode 100644 index e3f13a3b6d..0000000000 --- a/components/lwp/Kconfig +++ /dev/null @@ -1,7 +0,0 @@ -config RT_USING_LWP - bool "Using light-weight process" - select RT_USING_DFS - depends on ARCH_ARM_CORTEX_M - default n - help - The lwP is a light weight process running in user mode. diff --git a/components/lwp/SConscript b/components/lwp/SConscript deleted file mode 100644 index f54d9422e1..0000000000 --- a/components/lwp/SConscript +++ /dev/null @@ -1,20 +0,0 @@ -Import('rtconfig') -from building import * - -cwd = GetCurrentDir() -src = [] -CPPPATH = [] - -support_arch = {"arm": ["cortex-m3", "cortex-m4", "cortex-m7"]} -platform_file = {'armcc': 'rvds.S', 'gcc': 'gcc.S', 'iar': 'iar.S'} - -if rtconfig.PLATFORM in platform_file.keys(): # support platforms - if rtconfig.ARCH in support_arch.keys() and rtconfig.CPU in support_arch[rtconfig.ARCH]: - # arch/arm/cortex-m7/lwp_gcc.S - asm_path = 'arch/' + rtconfig.ARCH + '/' + rtconfig.CPU + '/*_' + platform_file[rtconfig.PLATFORM] - src = Glob('*.c') + Glob(asm_path) - CPPPATH = [cwd] - -group = DefineGroup('lwP', src, depend = ['RT_USING_LWP'], CPPPATH = CPPPATH) - -Return('group') diff --git a/components/lwp/arch/arm/cortex-m3/lwp_gcc.S b/components/lwp/arch/arm/cortex-m3/lwp_gcc.S deleted file mode 100644 index 8c866f9990..0000000000 --- a/components/lwp/arch/arm/cortex-m3/lwp_gcc.S +++ /dev/null @@ -1,176 +0,0 @@ -/* - * File : lwp_gcc.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -.cpu cortex-m3 -.syntax unified -.thumb -.text - -/* - * void* lwp_get_sys_api(rt_uint32_t number); - */ -.global lwp_get_sys_api -.global lwp_get_kernel_sp -.global lwp_set_kernel_sp - - -/* - * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr); - */ -.global lwp_user_entry -.type lwp_user_entry, % function -lwp_user_entry: - PUSH {R0 - R1} /* push text&data addr. */ - - MOV R0, SP /* v1 = SP */ - BL lwp_set_kernel_sp /* lwp_set_kernel_sp(v1) */ - - POP {R0 - R1} /* pop app address to R1. */ - - /* set CPU to user-thread mode. */ - MRS R2, CONTROL - ORR R2, R2, #0x03 /* use PSP, user-thread mode. */ - MSR CONTROL, R2 - - /* set data address. */ - MOV R9, R1 - - /* run app, only Thumb-mode. */ - ORR R0, R0, #0x01 - BX R0 - -/* - * void SVC_Handler(void); - */ -.global SVC_Handler -.type SVC_Handler, % function -SVC_Handler: - - PUSH {LR} - - /* get user SP. */ - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} /* push app SP. */ - MOV R2, R1 - - STMFD R2!, {R4 - R11} /* push app R4-R11 to app stack , and R1 not change. */ - - /* get SVC number. */ - LDR R0, [R1, #24] /* get the app LR. */ - LDRB R0, [R0, #-2] /* get the SVC No. from instruction. */ - - /* get kernel system API */ - BL lwp_get_sys_api - - /* if(api == NULL) return; */ - CMP R0, #0 - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - /* push api */ - PUSH {R0} - - /* get kernel SP to R0. */ - BL lwp_get_kernel_sp - - POP {R2} /* pop api to R2. */ - POP {R1} /* pop app SP to R1. */ - - /* copy R1(app SP) to R0(server SP). */ - LDMFD R1, {R4 - R11} /* pop exception_stack_frame to r4 - r11 register */ - STMFD R0!, {R4 - R11} /* push exception_stack_frame to server SP. */ - - POP {LR} - PUSH {LR} - - /* save app SP. */ - PUSH {R0 - R3} - SUB R0, R1, #0x20 /* keep {R4 - R11} */ - BL lwp_set_kernel_sp - POP {R0 - R3} - - /* set to thread-privilege mode. */ - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - /* call api. */ - LDR R3, = svc_exit - STR R3, [R0, #20] /* update LR */ - STR R2, [R0, #24] /* update api to PC */ - MSR PSP, R0 /* update stack pointer */ - POP {LR} /* 0xFFFFFFED */ - - ORR LR, LR, #0x10 - - BX LR - -/* -* void svc_exit(void); -*/ -.global svc_exit -.type svc_exit, % function -svc_exit: - - /* get user SP. */ - PUSH {R0} /* push result to SP. */ - BL lwp_get_kernel_sp - - LDMFD R0!, {R4 - R11} /* pop app {R4 - R11} */ - - ADD R0, R0, #16 /* skip R0-R3 */ - LDMFD R0!, {R12, LR} - LDMFD R0!, {R1} /* pop PC to R1 */ - LDMFD R0!, {R2} /* pop PSR to R2 */ - - /* align to 2 words */ - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} /* push user-SP to SP */ - - /* save server SP. */ - ADD R0, SP, #0x08 /* [user-SP, result] */ - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} /* pop user-SP to R3 */ - POP {R0} /* restore API result. */ - - MSR APSR, R2 /* restore PSR */ - MSR PSP, R3 /* restore app stack pointer */ - - /* restore to PSP & thread-unprivilege mode. */ - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - /* return to lwp. */ - ORR R1, R1, #0x01 /* only Thumb-mode. */ - BX R1 /* return to user app. */ diff --git a/components/lwp/arch/arm/cortex-m3/lwp_iar.S b/components/lwp/arch/arm/cortex-m3/lwp_iar.S deleted file mode 100644 index e00424cbec..0000000000 --- a/components/lwp/arch/arm/cortex-m3/lwp_iar.S +++ /dev/null @@ -1,176 +0,0 @@ -;/* -; * File : lwp_iar.S -; * This file is part of RT-Thread RTOS -; * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -; * -; * This program is free software; you can redistribute it and/or modify -; * it under the terms of the GNU General Public License as published by -; * the Free Software Foundation; either version 2 of the License, or -; * (at your option) any later version. -; * -; * This program is distributed in the hope that it will be useful, -; * but WITHOUT ANY WARRANTY; without even the implied warranty of -; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; * GNU General Public License for more details. -; * -; * You should have received a copy of the GNU General Public License along -; * with this program; if not, write to the Free Software Foundation, Inc., -; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -; * -; * Change Logs: -; * Date Author Notes -; */ - - SECTION .text:CODE(2) - THUMB - REQUIRE8 - PRESERVE8 - -;/* -; * void* lwp_get_sys_api(rt_uint32_t number); -; */ - IMPORT lwp_get_sys_api - IMPORT lwp_get_kernel_sp - IMPORT lwp_set_kernel_sp - -;/* -; * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr); -; */ - EXPORT lwp_user_entry -lwp_user_entry: - - PUSH {R0-R1} ; push text&data addr. - - MOV R0, SP ; v1 = SP - BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1) - - POP {R0-R1} ; pop app address to R1. - - ; set CPU to user-thread mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 ; use PSP, user-thread mode. - MSR CONTROL, R2 - - ; set data address. - MOV R9, R1 - - ; run app, only Thumb-mode. - ORR R0, R0, #0x01 - BX R0 - -;/* -; * void SVC_Handler(void); -; */ - EXPORT SVC_Handler -SVC_Handler: - - PUSH {LR} - - ; get user SP. - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} ; push app SP. - MOV R2, R1 - - STMFD R2!, {R4 - R11} ; push app R4-R11 to app stack , and R1 not change. - - ; get SVC number. - LDR R0, [R1, #24] ; get the app LR. - LDRB R0, [R0, #-2] ; get the SVC No. from instruction. - - ; get kernel system API - BL lwp_get_sys_api - - ; if(api == NULL) return; - CMP R0, #0 - ITTT EQ - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - ; push api - PUSH {R0} - - ; get kernel SP to R0. - BL lwp_get_kernel_sp - - POP {R2} ; pop api to R2. - POP {R1} ; pop app SP to R1. - - ; copy R1(app SP) to R0(server SP). - LDMFD R1, {R4 - R11} ; pop exception_stack_frame to r4 - r11 register - STMFD R0!, {R4 - R11} ; push exception_stack_frame to server SP. - - POP {LR} - PUSH {LR} - - ; save app SP. - PUSH {R0 - R3} - SUB R0, R1, #0x20 ; keep {R4 - R11} - BL lwp_set_kernel_sp - POP {R0 - R3} - - ; set to thread-privilege mode. - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - ; call api. - LDR R3, =svc_exit - STR R3, [R0, #20] ; update LR - STR R2, [R0, #24] ; update api to PC - MSR PSP, R0 ; update stack pointer - POP {LR} ; 0xFFFFFFED - - ORR LR, LR, #0x10 - - BX LR - -;/* -; * void svc_exit(void); -; */ - EXPORT svc_exit -svc_exit: - - ; get user SP. - PUSH {R0} ; push result to SP. - BL lwp_get_kernel_sp - - LDMFD R0!, {R4 - R11} ; pop app {R4 - R11} - - ADD R0, R0, #16 ; skip R0-R3 - LDMFD R0!, {R12, LR} ; - LDMFD R0!, {R1} ; pop PC to R1 - LDMFD R0!, {R2} ; pop PSR to R2 - - ; align to 2 words - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} ; push user-SP to SP - - ; save server SP. - ADD R0, SP, #0x08 ; [user-SP, result] - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} ; pop user-SP to R3 - POP {R0} ; restore API result. - - MSR APSR, R2 ; restore PSR - MSR PSP, R3 ; restore app stack pointer - - ; restore to PSP & thread-unprivilege mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - ; return to lwp. - ORR R1, R1, #0x01 ; only Thumb-mode. - BX R1 ; return to user app. - - END diff --git a/components/lwp/arch/arm/cortex-m3/lwp_rvds.S b/components/lwp/arch/arm/cortex-m3/lwp_rvds.S deleted file mode 100644 index 49470ea03a..0000000000 --- a/components/lwp/arch/arm/cortex-m3/lwp_rvds.S +++ /dev/null @@ -1,184 +0,0 @@ -;/* -; * File : lwp_rvds.S -; * This file is part of RT-Thread RTOS -; * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -; * -; * This program is free software; you can redistribute it and/or modify -; * it under the terms of the GNU General Public License as published by -; * the Free Software Foundation; either version 2 of the License, or -; * (at your option) any later version. -; * -; * This program is distributed in the hope that it will be useful, -; * but WITHOUT ANY WARRANTY; without even the implied warranty of -; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; * GNU General Public License for more details. -; * -; * You should have received a copy of the GNU General Public License along -; * with this program; if not, write to the Free Software Foundation, Inc., -; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -; * -; * Change Logs: -; * Date Author Notes -; */ - - AREA |.text|, CODE, READONLY, ALIGN=2 - THUMB - REQUIRE8 - PRESERVE8 - -;/* -; * void* lwp_get_sys_api(rt_uint32_t number); -; */ - IMPORT lwp_get_sys_api - IMPORT lwp_get_kernel_sp - IMPORT lwp_set_kernel_sp - -;/* -; * void lwp_user_entry(args, text, data); -; */ -lwp_user_entry PROC - EXPORT lwp_user_entry - - PUSH {R0-R3} ; push text&data addr. - - MOV R0, SP ; v1 = SP - BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1) - - ; set CPU to user-thread mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 ; use PSP, user-thread mode. - MSR CONTROL, R2 - - POP {R0-R3} ; pop app address to R1. - ; set data address. - MOV R9, R2 - - ; run app, only Thumb-mode. - ORR R1, R1, #0x01 - BX R1 - - ; never reach here! - ENDP - - -;/* -; * void SVC_Handler(void); -; */ -SVC_Handler PROC - EXPORT SVC_Handler - - PUSH {LR} - - ; get user SP. - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} ; push app SP. - MOV R2, R1 - - STMFD R2!, {R4 - R11} ; push app R4-R11 to app stack , and R1 not change. - - ; get SVC number. - LDR R0, [R1, #24] ; get the app LR. - LDRB R0, [R0, #-2] ; get the SVC No. from instruction. - - ; get kernel system API - BL lwp_get_sys_api - - ; if(api == NULL) return; - CMP R0, #0 - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - ; push api - PUSH {R0} - - ; get kernel SP to R0. - BL lwp_get_kernel_sp - - POP {R2} ; pop api to R2. - POP {R1} ; pop app SP to R1. - - ; copy R1(app SP) to R0(server SP). - LDMFD R1, {R4 - R11} ; pop exception_stack_frame to r4 - r11 register - STMFD R0!, {R4 - R11} ; push exception_stack_frame to server SP. - - POP {LR} - PUSH {LR} - - ; save app SP. - PUSH {R0 - R3} - SUB R0, R1, #0x20 ; keep {R4 - R11} - BL lwp_set_kernel_sp - POP {R0 - R3} - - ; set to thread-privilege mode. - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - ; call api. - LDR R3, =svc_exit - STR R3, [R0, #20] ; update LR - STR R2, [R0, #24] ; update api to PC - MSR PSP, R0 ; update stack pointer - POP {LR} ; 0xFFFFFFED - - ORR LR, LR, #0x10 - - BX LR - - ENDP - -;/* -; * void svc_exit(void); -; */ -svc_exit PROC - EXPORT svc_exit - - ; get user SP. - PUSH {R0} ; push result to SP. - BL lwp_get_kernel_sp - - LDMFD R0!, {R4 - R11} ; pop app {R4 - R11} - - ADD R0, R0, #16 ; skip R0-R3 - LDMFD R0!, {R12, LR} ; - LDMFD R0!, {R1} ; pop PC to R1 - LDMFD R0!, {R2} ; pop PSR to R2 - - ; align to 2 words - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} ; push user-SP to SP - - ; save server SP. - ADD R0, SP, #0x08 ; [user-SP, result] - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} ; pop user-SP to R3 - POP {R0} ; restore API result. - - MSR APSR, R2 ; restore PSR - MSR PSP, R3 ; restore app stack pointer - - ; restore to PSP & thread-unprivilege mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - ; return to lwp. - ORR R1, R1, #0x01 ; only Thumb-mode. - BX R1 ; return to user app. - - ENDP - - ALIGN - - END diff --git a/components/lwp/arch/arm/cortex-m4/lwp_gcc.S b/components/lwp/arch/arm/cortex-m4/lwp_gcc.S deleted file mode 100644 index fd46d6142d..0000000000 --- a/components/lwp/arch/arm/cortex-m4/lwp_gcc.S +++ /dev/null @@ -1,210 +0,0 @@ -/* - * File : lwp_gcc.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -.cpu cortex-m4 -.syntax unified -.thumb -.text - -/* - * void* lwp_get_sys_api(rt_uint32_t number); - */ -.global lwp_get_sys_api -.global lwp_get_kernel_sp -.global lwp_set_kernel_sp - - -/* - * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr); - */ -.global lwp_user_entry -.type lwp_user_entry, % function -lwp_user_entry: - PUSH {R0 - R1} /* push text&data addr. */ - - MOV R0, SP /* v1 = SP */ - BL lwp_set_kernel_sp /* lwp_set_kernel_sp(v1) */ - - POP {R0 - R1} /* pop app address to R1. */ - - /* set CPU to user-thread mode. */ - MRS R2, CONTROL - ORR R2, R2, #0x03 /* use PSP, user-thread mode. */ - MSR CONTROL, R2 - - /* set data address. */ - MOV R9, R1 - - /* run app, only Thumb-mode. */ - ORR R0, R0, #0x01 - BX R0 - -/* - * void SVC_Handler(void); - */ -.global SVC_Handler -.type SVC_Handler, % function -SVC_Handler: - - PUSH {LR} - - /* get user SP. */ - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} /* push app SP. */ - MOV R2, R1 - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - TST LR, #0x10 - VSTMDBEQ R2!, {D8 - D15} -#endif - - STMFD R2!, {R4 - R11} /* push app R4-R11 to app stack , and R1 not change. */ - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - MOV R4, #0x00 /* flag = 0 */ - TST LR, #0x10 /* if(!EXC_RETURN[4]) */ - MOVEQ R4, #0x01 /* flag = 1 */ - STMFD R2!, {R4} /* push flag */ -#endif - - /* get SVC number. */ - LDR R0, [R1, #24] /* get the app LR. */ - LDRB R0, [R0, #-2] /* get the SVC No. from instruction. */ - - /* get kernel system API */ - BL lwp_get_sys_api - - /* if(api == NULL) return; */ - CMP R0, #0 - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - /* push api */ - PUSH {R0} - - /* get kernel SP to R0. */ - BL lwp_get_kernel_sp - - POP {R2} /* pop api to R2. */ - POP {R1} /* pop app SP to R1. */ - - /* copy R1(app SP) to R0(server SP). */ - LDMFD R1, {R4 - R11} /* pop exception_stack_frame to r4 - r11 register */ - STMFD R0!, {R4 - R11} /* push exception_stack_frame to server SP. */ - - POP {LR} - PUSH {LR} - - /* save app SP. */ - PUSH {R0 - R3} -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - TST LR, #0x10 - SUBEQ R0, R1, #0x64 /* keep {R4 - R11}, {D8-D15}, FLAG */ - SUBNE R0, R1, #0x24 /* keep {R4 - R11}, FLAG */ -#else - SUB R0, R1, #0x20 /* keep {R4 - R11} */ -#endif - BL lwp_set_kernel_sp - POP {R0 - R3} - - /* set to thread-privilege mode. */ - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - /* call api. */ - LDR R3, = svc_exit - STR R3, [R0, #20] /* update LR */ - STR R2, [R0, #24] /* update api to PC */ - MSR PSP, R0 /* update stack pointer */ - POP {LR} /* 0xFFFFFFED */ - - ORR LR, LR, #0x10 - - BX LR - -/* -* void svc_exit(void); -*/ -.global svc_exit -.type svc_exit, % function -svc_exit: - - /* get user SP. */ - PUSH {R0} /* push result to SP. */ - BL lwp_get_kernel_sp - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - LDMFD R0!, {R3} /* pop flag */ -#endif - - LDMFD R0!, {R4 - R11} /* pop app {R4 - R11} */ - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - CMP R3, #0 /* if(flag_r3 != 0) */ - VLDMIANE R0!, {D8 - D15} /* pop FPU register s16~s31 */ -#endif - - ADD R0, R0, #16 /* skip R0-R3 */ - LDMFD R0!, {R12, LR} - LDMFD R0!, {R1} /* pop PC to R1 */ - LDMFD R0!, {R2} /* pop PSR to R2 */ - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - CMP R3, #0 /* if(flag_r3 != 0) */ - VLDMIANE R0!, {D0 - D7} /* pop FPU register s16~s31 */ - LDMIANE R0!, {R3} - VMSRNE FPSCR, R3 -#endif - - /* align to 2 words */ - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} /* push user-SP to SP */ - - /* save server SP. */ - ADD R0, SP, #0x08 /* [user-SP, result] */ - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} /* pop user-SP to R3 */ - POP {R0} /* restore API result. */ - - MSR APSR, R2 /* restore PSR */ - MSR PSP, R3 /* restore app stack pointer */ - - /* restore to PSP & thread-unprivilege mode. */ - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - /* return to lwp. */ - ORR R1, R1, #0x01 /* only Thumb-mode. */ - BX R1 /* return to user app. */ diff --git a/components/lwp/arch/arm/cortex-m4/lwp_iar.S b/components/lwp/arch/arm/cortex-m4/lwp_iar.S deleted file mode 100644 index 27ca8778e0..0000000000 --- a/components/lwp/arch/arm/cortex-m4/lwp_iar.S +++ /dev/null @@ -1,215 +0,0 @@ -;/* -; * File : lwp_iar.S -; * This file is part of RT-Thread RTOS -; * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -; * -; * This program is free software; you can redistribute it and/or modify -; * it under the terms of the GNU General Public License as published by -; * the Free Software Foundation; either version 2 of the License, or -; * (at your option) any later version. -; * -; * This program is distributed in the hope that it will be useful, -; * but WITHOUT ANY WARRANTY; without even the implied warranty of -; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; * GNU General Public License for more details. -; * -; * You should have received a copy of the GNU General Public License along -; * with this program; if not, write to the Free Software Foundation, Inc., -; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -; * -; * Change Logs: -; * Date Author Notes -; */ - - SECTION .text:CODE(2) - THUMB - REQUIRE8 - PRESERVE8 - -;/* -; * void* lwp_get_sys_api(rt_uint32_t number); -; */ - IMPORT lwp_get_sys_api - IMPORT lwp_get_kernel_sp - IMPORT lwp_set_kernel_sp - -;/* -; * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr); -; */ - EXPORT lwp_user_entry -lwp_user_entry: - - PUSH {R0-R1} ; push text&data addr. - - MOV R0, SP ; v1 = SP - BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1) - - POP {R0-R1} ; pop app address to R1. - - ; set CPU to user-thread mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 ; use PSP, user-thread mode. - MSR CONTROL, R2 - - ; set data address. - MOV R9, R1 - - ; run app, only Thumb-mode. - ORR R0, R0, #0x01 - BX R0 - -;/* -; * void SVC_Handler(void); -; */ - EXPORT SVC_Handler -SVC_Handler: - - PUSH {LR} - - ; get user SP. - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} ; push app SP. - MOV R2, R1 - -#if defined ( __ARMVFP__ ) - TST LR, #0x10 - IT EQ - VSTMDBEQ R2!, {D8 - D15} -#endif - - STMFD R2!, {R4 - R11} ; push app R4-R11 to app stack , and R1 not change. - -#if defined ( __ARMVFP__ ) - MOV R4, #0x00 ; flag = 0 - TST LR, #0x10 ; if(!EXC_RETURN[4]) - IT EQ - MOVEQ R4, #0x01 ; flag = 1 - STMFD R2!, {R4} ; push flag -#endif - - ; get SVC number. - LDR R0, [R1, #24] ; get the app LR. - LDRB R0, [R0, #-2] ; get the SVC No. from instruction. - - ; get kernel system API - BL lwp_get_sys_api - - ; if(api == NULL) return; - CMP R0, #0 - ITTT EQ - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - ; push api - PUSH {R0} - - ; get kernel SP to R0. - BL lwp_get_kernel_sp - - POP {R2} ; pop api to R2. - POP {R1} ; pop app SP to R1. - - ; copy R1(app SP) to R0(server SP). - LDMFD R1, {R4 - R11} ; pop exception_stack_frame to r4 - r11 register - STMFD R0!, {R4 - R11} ; push exception_stack_frame to server SP. - - POP {LR} - PUSH {LR} - - ; save app SP. - PUSH {R0 - R3} -#if defined ( __ARMVFP__ ) - TST LR, #0x10 - ITE EQ - SUBEQ R0, R1, #0x64 ; keep {R4 - R11}, {D8-D15}, FLAG - SUBNE R0, R1, #0x24 ; keep {R4 - R11}, FLAG -#else - SUB R0, R1, #0x20 ; keep {R4 - R11} -#endif - BL lwp_set_kernel_sp - POP {R0 - R3} - - ; set to thread-privilege mode. - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - ; call api. - LDR R3, =svc_exit - STR R3, [R0, #20] ; update LR - STR R2, [R0, #24] ; update api to PC - MSR PSP, R0 ; update stack pointer - POP {LR} ; 0xFFFFFFED - - ORR LR, LR, #0x10 - - BX LR - -;/* -; * void svc_exit(void); -; */ - EXPORT svc_exit -svc_exit: - - ; get user SP. - PUSH {R0} ; push result to SP. - BL lwp_get_kernel_sp - -#if defined ( __ARMVFP__ ) - LDMFD R0!, {R3} ; pop flag -#endif - - LDMFD R0!, {R4 - R11} ; pop app {R4 - R11} - -#if defined ( __ARMVFP__ ) - CMP R3, #0 ; if(flag_r3 != 0) - IT NE - VLDMIANE R0!, {D8 - D15} ; pop FPU register s16~s31 -#endif - - ADD R0, R0, #16 ; skip R0-R3 - LDMFD R0!, {R12, LR} ; - LDMFD R0!, {R1} ; pop PC to R1 - LDMFD R0!, {R2} ; pop PSR to R2 - -#if defined ( __ARMVFP__ ) - CMP R3, #0 ; if(flag_r3 != 0) - ITTT NE - VLDMIANE R0!, {D0 - D7} ; pop FPU register s16~s31 - LDMIANE R0!, {R3} - VMSRNE FPSCR, R3 -#endif - - ; align to 2 words - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} ; push user-SP to SP - - ; save server SP. - ADD R0, SP, #0x08 ; [user-SP, result] - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} ; pop user-SP to R3 - POP {R0} ; restore API result. - - MSR APSR, R2 ; restore PSR - MSR PSP, R3 ; restore app stack pointer - - ; restore to PSP & thread-unprivilege mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - ; return to lwp. - ORR R1, R1, #0x01 ; only Thumb-mode. - BX R1 ; return to user app. - - END diff --git a/components/lwp/arch/arm/cortex-m4/lwp_rvds.S b/components/lwp/arch/arm/cortex-m4/lwp_rvds.S deleted file mode 100644 index 42fad954ce..0000000000 --- a/components/lwp/arch/arm/cortex-m4/lwp_rvds.S +++ /dev/null @@ -1,219 +0,0 @@ -;/* -; * File : lwp_rvds.S -; * This file is part of RT-Thread RTOS -; * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -; * -; * This program is free software; you can redistribute it and/or modify -; * it under the terms of the GNU General Public License as published by -; * the Free Software Foundation; either version 2 of the License, or -; * (at your option) any later version. -; * -; * This program is distributed in the hope that it will be useful, -; * but WITHOUT ANY WARRANTY; without even the implied warranty of -; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; * GNU General Public License for more details. -; * -; * You should have received a copy of the GNU General Public License along -; * with this program; if not, write to the Free Software Foundation, Inc., -; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -; * -; * Change Logs: -; * Date Author Notes -; */ - - AREA |.text|, CODE, READONLY, ALIGN=2 - THUMB - REQUIRE8 - PRESERVE8 - -;/* -; * void* lwp_get_sys_api(rt_uint32_t number); -; */ - IMPORT lwp_get_sys_api - IMPORT lwp_get_kernel_sp - IMPORT lwp_set_kernel_sp - -;/* -; * void lwp_user_entry(args, text, data); -; */ -lwp_user_entry PROC - EXPORT lwp_user_entry - - PUSH {R0-R3} ; push text&data addr. - - MOV R0, SP ; v1 = SP - BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1) - - ; set CPU to user-thread mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 ; use PSP, user-thread mode. - MSR CONTROL, R2 - - POP {R0-R3} ; pop app address to R1. - ; set data address. - MOV R9, R2 - - ; run app, only Thumb-mode. - ORR R1, R1, #0x01 - BX R1 - - ; never reach here! - ENDP - - -;/* -; * void SVC_Handler(void); -; */ -SVC_Handler PROC - EXPORT SVC_Handler - - PUSH {LR} - - ; get user SP. - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} ; push app SP. - MOV R2, R1 - - IF {FPU} != "SoftVFP" - TST LR, #0x10 - VSTMFDEQ R2!, {D8 - D15} - ENDIF - - STMFD R2!, {R4 - R11} ; push app R4-R11 to app stack , and R1 not change. - - IF {FPU} != "SoftVFP" - MOV R4, #0x00 ; flag = 0 - TST LR, #0x10 ; if(!EXC_RETURN[4]) - MOVEQ R4, #0x01 ; flag = 1 - STMFD R2!, {R4} ; push flag - ENDIF - - ; get SVC number. - LDR R0, [R1, #24] ; get the app LR. - LDRB R0, [R0, #-2] ; get the SVC No. from instruction. - - ; get kernel system API - BL lwp_get_sys_api - - ; if(api == NULL) return; - CMP R0, #0 - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - ; push api - PUSH {R0} - - ; get kernel SP to R0. - BL lwp_get_kernel_sp - - POP {R2} ; pop api to R2. - POP {R1} ; pop app SP to R1. - - ; copy R1(app SP) to R0(server SP). - LDMFD R1, {R4 - R11} ; pop exception_stack_frame to r4 - r11 register - STMFD R0!, {R4 - R11} ; push exception_stack_frame to server SP. - - POP {LR} - PUSH {LR} - - ; save app SP. - PUSH {R0 - R3} - IF {FPU} != "SoftVFP" - TST LR, #0x10 - SUBEQ R0, R1, #0x64 ; keep {R4 - R11}, {D8-D15}, FLAG - SUBNE R0, R1, #0x24 ; keep {R4 - R11}, FLAG - ELSE - SUB R0, R1, #0x20 ; keep {R4 - R11} - ENDIF - BL lwp_set_kernel_sp - POP {R0 - R3} - - ; set to thread-privilege mode. - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - ; call api. - LDR R3, =svc_exit - STR R3, [R0, #20] ; update LR - STR R2, [R0, #24] ; update api to PC - MSR PSP, R0 ; update stack pointer - POP {LR} ; 0xFFFFFFED - - ORR LR, LR, #0x10 - - BX LR - - ENDP - -;/* -; * void svc_exit(void); -; */ -svc_exit PROC - EXPORT svc_exit - - ; get user SP. - PUSH {R0} ; push result to SP. - BL lwp_get_kernel_sp - - IF {FPU} != "SoftVFP" - LDMFD R0!, {R3} ; pop flag - ENDIF - - LDMFD R0!, {R4 - R11} ; pop app {R4 - R11} - - IF {FPU} != "SoftVFP" - CMP R3, #0 ; if(flag_r3 != 0) - VLDMFDNE R0!, {D8 - D15} ; pop FPU register s16~s31 - ENDIF - - ADD R0, R0, #16 ; skip R0-R3 - LDMFD R0!, {R12, LR} ; - LDMFD R0!, {R1} ; pop PC to R1 - LDMFD R0!, {R2} ; pop PSR to R2 - - IF {FPU} != "SoftVFP" - CMP R3, #0 ; if(flag_r3 != 0) - VLDMFDNE R0!, {D0 - D7} ; pop FPU register s16~s31 - LDMFDNE R0!, {R3} - VMSRNE FPSCR, R3 - - ENDIF - - ; align to 2 words - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} ; push user-SP to SP - - ; save server SP. - ADD R0, SP, #0x08 ; [user-SP, result] - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} ; pop user-SP to R3 - POP {R0} ; restore API result. - - MSR APSR, R2 ; restore PSR - MSR PSP, R3 ; restore app stack pointer - - ; restore to PSP & thread-unprivilege mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - ; return to lwp. - ORR R1, R1, #0x01 ; only Thumb-mode. - BX R1 ; return to user app. - - ENDP - - ALIGN - - END diff --git a/components/lwp/arch/arm/cortex-m7/lwp_gcc.S b/components/lwp/arch/arm/cortex-m7/lwp_gcc.S deleted file mode 100644 index fd46d6142d..0000000000 --- a/components/lwp/arch/arm/cortex-m7/lwp_gcc.S +++ /dev/null @@ -1,210 +0,0 @@ -/* - * File : lwp_gcc.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -.cpu cortex-m4 -.syntax unified -.thumb -.text - -/* - * void* lwp_get_sys_api(rt_uint32_t number); - */ -.global lwp_get_sys_api -.global lwp_get_kernel_sp -.global lwp_set_kernel_sp - - -/* - * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr); - */ -.global lwp_user_entry -.type lwp_user_entry, % function -lwp_user_entry: - PUSH {R0 - R1} /* push text&data addr. */ - - MOV R0, SP /* v1 = SP */ - BL lwp_set_kernel_sp /* lwp_set_kernel_sp(v1) */ - - POP {R0 - R1} /* pop app address to R1. */ - - /* set CPU to user-thread mode. */ - MRS R2, CONTROL - ORR R2, R2, #0x03 /* use PSP, user-thread mode. */ - MSR CONTROL, R2 - - /* set data address. */ - MOV R9, R1 - - /* run app, only Thumb-mode. */ - ORR R0, R0, #0x01 - BX R0 - -/* - * void SVC_Handler(void); - */ -.global SVC_Handler -.type SVC_Handler, % function -SVC_Handler: - - PUSH {LR} - - /* get user SP. */ - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} /* push app SP. */ - MOV R2, R1 - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - TST LR, #0x10 - VSTMDBEQ R2!, {D8 - D15} -#endif - - STMFD R2!, {R4 - R11} /* push app R4-R11 to app stack , and R1 not change. */ - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - MOV R4, #0x00 /* flag = 0 */ - TST LR, #0x10 /* if(!EXC_RETURN[4]) */ - MOVEQ R4, #0x01 /* flag = 1 */ - STMFD R2!, {R4} /* push flag */ -#endif - - /* get SVC number. */ - LDR R0, [R1, #24] /* get the app LR. */ - LDRB R0, [R0, #-2] /* get the SVC No. from instruction. */ - - /* get kernel system API */ - BL lwp_get_sys_api - - /* if(api == NULL) return; */ - CMP R0, #0 - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - /* push api */ - PUSH {R0} - - /* get kernel SP to R0. */ - BL lwp_get_kernel_sp - - POP {R2} /* pop api to R2. */ - POP {R1} /* pop app SP to R1. */ - - /* copy R1(app SP) to R0(server SP). */ - LDMFD R1, {R4 - R11} /* pop exception_stack_frame to r4 - r11 register */ - STMFD R0!, {R4 - R11} /* push exception_stack_frame to server SP. */ - - POP {LR} - PUSH {LR} - - /* save app SP. */ - PUSH {R0 - R3} -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - TST LR, #0x10 - SUBEQ R0, R1, #0x64 /* keep {R4 - R11}, {D8-D15}, FLAG */ - SUBNE R0, R1, #0x24 /* keep {R4 - R11}, FLAG */ -#else - SUB R0, R1, #0x20 /* keep {R4 - R11} */ -#endif - BL lwp_set_kernel_sp - POP {R0 - R3} - - /* set to thread-privilege mode. */ - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - /* call api. */ - LDR R3, = svc_exit - STR R3, [R0, #20] /* update LR */ - STR R2, [R0, #24] /* update api to PC */ - MSR PSP, R0 /* update stack pointer */ - POP {LR} /* 0xFFFFFFED */ - - ORR LR, LR, #0x10 - - BX LR - -/* -* void svc_exit(void); -*/ -.global svc_exit -.type svc_exit, % function -svc_exit: - - /* get user SP. */ - PUSH {R0} /* push result to SP. */ - BL lwp_get_kernel_sp - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - LDMFD R0!, {R3} /* pop flag */ -#endif - - LDMFD R0!, {R4 - R11} /* pop app {R4 - R11} */ - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - CMP R3, #0 /* if(flag_r3 != 0) */ - VLDMIANE R0!, {D8 - D15} /* pop FPU register s16~s31 */ -#endif - - ADD R0, R0, #16 /* skip R0-R3 */ - LDMFD R0!, {R12, LR} - LDMFD R0!, {R1} /* pop PC to R1 */ - LDMFD R0!, {R2} /* pop PSR to R2 */ - -#if defined (__VFP_FP__) && !defined(__SOFTFP__) - CMP R3, #0 /* if(flag_r3 != 0) */ - VLDMIANE R0!, {D0 - D7} /* pop FPU register s16~s31 */ - LDMIANE R0!, {R3} - VMSRNE FPSCR, R3 -#endif - - /* align to 2 words */ - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} /* push user-SP to SP */ - - /* save server SP. */ - ADD R0, SP, #0x08 /* [user-SP, result] */ - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} /* pop user-SP to R3 */ - POP {R0} /* restore API result. */ - - MSR APSR, R2 /* restore PSR */ - MSR PSP, R3 /* restore app stack pointer */ - - /* restore to PSP & thread-unprivilege mode. */ - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - /* return to lwp. */ - ORR R1, R1, #0x01 /* only Thumb-mode. */ - BX R1 /* return to user app. */ diff --git a/components/lwp/arch/arm/cortex-m7/lwp_iar.S b/components/lwp/arch/arm/cortex-m7/lwp_iar.S deleted file mode 100644 index 27ca8778e0..0000000000 --- a/components/lwp/arch/arm/cortex-m7/lwp_iar.S +++ /dev/null @@ -1,215 +0,0 @@ -;/* -; * File : lwp_iar.S -; * This file is part of RT-Thread RTOS -; * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -; * -; * This program is free software; you can redistribute it and/or modify -; * it under the terms of the GNU General Public License as published by -; * the Free Software Foundation; either version 2 of the License, or -; * (at your option) any later version. -; * -; * This program is distributed in the hope that it will be useful, -; * but WITHOUT ANY WARRANTY; without even the implied warranty of -; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; * GNU General Public License for more details. -; * -; * You should have received a copy of the GNU General Public License along -; * with this program; if not, write to the Free Software Foundation, Inc., -; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -; * -; * Change Logs: -; * Date Author Notes -; */ - - SECTION .text:CODE(2) - THUMB - REQUIRE8 - PRESERVE8 - -;/* -; * void* lwp_get_sys_api(rt_uint32_t number); -; */ - IMPORT lwp_get_sys_api - IMPORT lwp_get_kernel_sp - IMPORT lwp_set_kernel_sp - -;/* -; * void lwp_user_entry(u32 R0_text_addr, u32 R1_data_addr); -; */ - EXPORT lwp_user_entry -lwp_user_entry: - - PUSH {R0-R1} ; push text&data addr. - - MOV R0, SP ; v1 = SP - BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1) - - POP {R0-R1} ; pop app address to R1. - - ; set CPU to user-thread mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 ; use PSP, user-thread mode. - MSR CONTROL, R2 - - ; set data address. - MOV R9, R1 - - ; run app, only Thumb-mode. - ORR R0, R0, #0x01 - BX R0 - -;/* -; * void SVC_Handler(void); -; */ - EXPORT SVC_Handler -SVC_Handler: - - PUSH {LR} - - ; get user SP. - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} ; push app SP. - MOV R2, R1 - -#if defined ( __ARMVFP__ ) - TST LR, #0x10 - IT EQ - VSTMDBEQ R2!, {D8 - D15} -#endif - - STMFD R2!, {R4 - R11} ; push app R4-R11 to app stack , and R1 not change. - -#if defined ( __ARMVFP__ ) - MOV R4, #0x00 ; flag = 0 - TST LR, #0x10 ; if(!EXC_RETURN[4]) - IT EQ - MOVEQ R4, #0x01 ; flag = 1 - STMFD R2!, {R4} ; push flag -#endif - - ; get SVC number. - LDR R0, [R1, #24] ; get the app LR. - LDRB R0, [R0, #-2] ; get the SVC No. from instruction. - - ; get kernel system API - BL lwp_get_sys_api - - ; if(api == NULL) return; - CMP R0, #0 - ITTT EQ - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - ; push api - PUSH {R0} - - ; get kernel SP to R0. - BL lwp_get_kernel_sp - - POP {R2} ; pop api to R2. - POP {R1} ; pop app SP to R1. - - ; copy R1(app SP) to R0(server SP). - LDMFD R1, {R4 - R11} ; pop exception_stack_frame to r4 - r11 register - STMFD R0!, {R4 - R11} ; push exception_stack_frame to server SP. - - POP {LR} - PUSH {LR} - - ; save app SP. - PUSH {R0 - R3} -#if defined ( __ARMVFP__ ) - TST LR, #0x10 - ITE EQ - SUBEQ R0, R1, #0x64 ; keep {R4 - R11}, {D8-D15}, FLAG - SUBNE R0, R1, #0x24 ; keep {R4 - R11}, FLAG -#else - SUB R0, R1, #0x20 ; keep {R4 - R11} -#endif - BL lwp_set_kernel_sp - POP {R0 - R3} - - ; set to thread-privilege mode. - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - ; call api. - LDR R3, =svc_exit - STR R3, [R0, #20] ; update LR - STR R2, [R0, #24] ; update api to PC - MSR PSP, R0 ; update stack pointer - POP {LR} ; 0xFFFFFFED - - ORR LR, LR, #0x10 - - BX LR - -;/* -; * void svc_exit(void); -; */ - EXPORT svc_exit -svc_exit: - - ; get user SP. - PUSH {R0} ; push result to SP. - BL lwp_get_kernel_sp - -#if defined ( __ARMVFP__ ) - LDMFD R0!, {R3} ; pop flag -#endif - - LDMFD R0!, {R4 - R11} ; pop app {R4 - R11} - -#if defined ( __ARMVFP__ ) - CMP R3, #0 ; if(flag_r3 != 0) - IT NE - VLDMIANE R0!, {D8 - D15} ; pop FPU register s16~s31 -#endif - - ADD R0, R0, #16 ; skip R0-R3 - LDMFD R0!, {R12, LR} ; - LDMFD R0!, {R1} ; pop PC to R1 - LDMFD R0!, {R2} ; pop PSR to R2 - -#if defined ( __ARMVFP__ ) - CMP R3, #0 ; if(flag_r3 != 0) - ITTT NE - VLDMIANE R0!, {D0 - D7} ; pop FPU register s16~s31 - LDMIANE R0!, {R3} - VMSRNE FPSCR, R3 -#endif - - ; align to 2 words - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} ; push user-SP to SP - - ; save server SP. - ADD R0, SP, #0x08 ; [user-SP, result] - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} ; pop user-SP to R3 - POP {R0} ; restore API result. - - MSR APSR, R2 ; restore PSR - MSR PSP, R3 ; restore app stack pointer - - ; restore to PSP & thread-unprivilege mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - ; return to lwp. - ORR R1, R1, #0x01 ; only Thumb-mode. - BX R1 ; return to user app. - - END diff --git a/components/lwp/arch/arm/cortex-m7/lwp_rvds.S b/components/lwp/arch/arm/cortex-m7/lwp_rvds.S deleted file mode 100644 index 6c310a3632..0000000000 --- a/components/lwp/arch/arm/cortex-m7/lwp_rvds.S +++ /dev/null @@ -1,218 +0,0 @@ -;/* -; * File : lwp_rvds.S -; * This file is part of RT-Thread RTOS -; * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -; * -; * This program is free software; you can redistribute it and/or modify -; * it under the terms of the GNU General Public License as published by -; * the Free Software Foundation; either version 2 of the License, or -; * (at your option) any later version. -; * -; * This program is distributed in the hope that it will be useful, -; * but WITHOUT ANY WARRANTY; without even the implied warranty of -; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; * GNU General Public License for more details. -; * -; * You should have received a copy of the GNU General Public License along -; * with this program; if not, write to the Free Software Foundation, Inc., -; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -; * -; * Change Logs: -; * Date Author Notes -; */ - - AREA |.text|, CODE, READONLY, ALIGN=2 - THUMB - REQUIRE8 - PRESERVE8 - -;/* -; * void* lwp_get_sys_api(rt_uint32_t number); -; */ - IMPORT lwp_get_sys_api - IMPORT lwp_get_kernel_sp - IMPORT lwp_set_kernel_sp - -;/* -; * void lwp_user_entry(args, text, data); -; */ -lwp_user_entry PROC - EXPORT lwp_user_entry - - PUSH {R0-R3} ; push text&data addr. - - MOV R0, SP ; v1 = SP - BL lwp_set_kernel_sp ; lwp_set_kernel_sp(v1) - - ; set CPU to user-thread mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 ; use PSP, user-thread mode. - MSR CONTROL, R2 - - POP {R0-R3} ; pop app address to R1. - ; set data address. - MOV R9, R2 - - ; run app, only Thumb-mode. - ORR R1, R1, #0x01 - BX R1 - - ; never reach here! - ENDP - -;/* -; * void SVC_Handler(void); -; */ -SVC_Handler PROC - EXPORT SVC_Handler - - PUSH {LR} - - ; get user SP. - TST LR, #0x4 - ITE EQ - MRSEQ R1, MSP - MRSNE R1, PSP - - PUSH {R1} ; push app SP. - MOV R2, R1 - - IF {FPU} != "SoftVFP" - TST LR, #0x10 - VSTMFDEQ R2!, {D8 - D15} - ENDIF - - STMFD R2!, {R4 - R11} ; push app R4-R11 to app stack , and R1 not change. - - IF {FPU} != "SoftVFP" - MOV R4, #0x00 ; flag = 0 - TST LR, #0x10 ; if(!EXC_RETURN[4]) - MOVEQ R4, #0x01 ; flag = 1 - STMFD R2!, {R4} ; push flag - ENDIF - - ; get SVC number. - LDR R0, [R1, #24] ; get the app LR. - LDRB R0, [R0, #-2] ; get the SVC No. from instruction. - - ; get kernel system API - BL lwp_get_sys_api - - ; if(api == NULL) return; - CMP R0, #0 - POPEQ {R1} - POPEQ {LR} - BXEQ LR - - ; push api - PUSH {R0} - - ; get kernel SP to R0. - BL lwp_get_kernel_sp - - POP {R2} ; pop api to R2. - POP {R1} ; pop app SP to R1. - - ; copy R1(app SP) to R0(server SP). - LDMFD R1, {R4 - R11} ; pop exception_stack_frame to r4 - r11 register - STMFD R0!, {R4 - R11} ; push exception_stack_frame to server SP. - - POP {LR} - PUSH {LR} - - ; save app SP. - PUSH {R0 - R3} - IF {FPU} != "SoftVFP" - TST LR, #0x10 - SUBEQ R0, R1, #0x64 ; keep {R4 - R11}, {D8-D15}, FLAG - SUBNE R0, R1, #0x24 ; keep {R4 - R11}, FLAG - ELSE - SUB R0, R1, #0x20 ; keep {R4 - R11} - ENDIF - BL lwp_set_kernel_sp - POP {R0 - R3} - - ; set to thread-privilege mode. - MRS R3, CONTROL - BIC R3, R3, #0x01 - ORR R3, R3, #0x02 - MSR CONTROL, R3 - - ; call api. - LDR R3, =svc_exit - STR R3, [R0, #20] ; update LR - STR R2, [R0, #24] ; update api to PC - MSR PSP, R0 ; update stack pointer - POP {LR} ; 0xFFFFFFED - - ORR LR, LR, #0x10 - - BX LR - - ENDP - -;/* -; * void svc_exit(void); -; */ -svc_exit PROC - EXPORT svc_exit - - ; get user SP. - PUSH {R0} ; push result to SP. - BL lwp_get_kernel_sp - - IF {FPU} != "SoftVFP" - LDMFD R0!, {R3} ; pop flag - ENDIF - - LDMFD R0!, {R4 - R11} ; pop app {R4 - R11} - - IF {FPU} != "SoftVFP" - CMP R3, #0 ; if(flag_r3 != 0) - VLDMFDNE R0!, {D8 - D15} ; pop FPU register s16~s31 - ENDIF - - ADD R0, R0, #16 ; skip R0-R3 - LDMFD R0!, {R12, LR} ; - LDMFD R0!, {R1} ; pop PC to R1 - LDMFD R0!, {R2} ; pop PSR to R2 - - IF {FPU} != "SoftVFP" - CMP R3, #0 ; if(flag_r3 != 0) - VLDMFDNE R0!, {D0 - D7} ; pop FPU register s16~s31 - LDMFDNE R0!, {R3} - VMSRNE FPSCR, R3 - - ENDIF - - ; align to 2 words - ADD R0, R0, #0x07 - BIC R0, R0, #0x07 - PUSH {R0} ; push user-SP to SP - - ; save server SP. - ADD R0, SP, #0x08 ; [user-SP, result] - PUSH {R1 - R2, LR} - BL lwp_set_kernel_sp - POP {R1 - R2, LR} - - POP {R3} ; pop user-SP to R3 - POP {R0} ; restore API result. - - MSR APSR, R2 ; restore PSR - MSR PSP, R3 ; restore app stack pointer - - ; restore to PSP & thread-unprivilege mode. - MRS R2, CONTROL - ORR R2, R2, #0x03 - MSR CONTROL, R2 - - ; return to lwp. - ORR R1, R1, #0x01 ; only Thumb-mode. - BX R1 ; return to user app. - - ENDP - - ALIGN - - END diff --git a/components/lwp/lwp.c b/components/lwp/lwp.c deleted file mode 100644 index 0bfeb4b103..0000000000 --- a/components/lwp/lwp.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - * File : clock.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -#include -#include -#include - -#ifndef RT_USING_DFS - #error "lwp need file system(RT_USING_DFS)" -#endif - -#include "lwp.h" - -#define DBG_ENABLE -#define DBG_SECTION_NAME "LWP" -#define DBG_COLOR -#define DBG_LEVEL DBG_WARNING -#include - -extern rt_thread_t rt_current_thread; -extern void lwp_user_entry(void *args, const void *text, void *data); - -/** - * RT-Thread light-weight process - */ -void lwp_set_kernel_sp(uint32_t *sp) -{ - struct rt_lwp *user_data; - user_data = (struct rt_lwp *)rt_current_thread->lwp; - user_data->kernel_sp = sp; -} - -uint32_t *lwp_get_kernel_sp(void) -{ - struct rt_lwp *user_data; - user_data = (struct rt_lwp *)rt_current_thread->lwp; - - return user_data->kernel_sp; -} - -static int lwp_argscopy(struct rt_lwp *lwp, int argc, char **argv) -{ - int size = sizeof(int)*3; /* store argc, argv, NULL */ - int *args; - char *str; - char **new_argv; - int i; - int len; - - for (i = 0; i < argc; i ++) - { - size += (rt_strlen(argv[i]) + 1); - } - size += (sizeof(int) * argc); - - args = (int*)rt_malloc(size); - if (args == RT_NULL) - return -1; - - str = (char*)((int)args + (argc + 3) * sizeof(int)); - new_argv = (char**)&args[2]; - args[0] = argc; - args[1] = (int)new_argv; - - for (i = 0; i < argc; i ++) - { - len = rt_strlen(argv[i]) + 1; - new_argv[i] = str; - rt_memcpy(str, argv[i], len); - str += len; - } - new_argv[i] = 0; - lwp->args = args; - - return 0; -} - -static int lwp_load(const char *filename, struct rt_lwp *lwp, uint8_t *load_addr, size_t addr_size) -{ - int fd; - uint8_t *ptr; - int result = RT_EOK; - int nbytes; - struct lwp_header header; - struct lwp_chunk chunk; - - /* check file name */ - RT_ASSERT(filename != RT_NULL); - /* check lwp control block */ - RT_ASSERT(lwp != RT_NULL); - - if (load_addr != RT_NULL) - { - lwp->lwp_type = LWP_TYPE_FIX_ADDR; - ptr = load_addr; - } - else - { - lwp->lwp_type = LWP_TYPE_DYN_ADDR; - ptr = RT_NULL; - } - - /* open lwp */ - fd = open(filename, 0, O_RDONLY); - if (fd < 0) - { - dbg_log(DBG_ERROR, "open file:%s failed!\n", filename); - result = -RT_ENOSYS; - goto _exit; - } - - /* read lwp header */ - nbytes = read(fd, &header, sizeof(struct lwp_header)); - if (nbytes != sizeof(struct lwp_header)) - { - dbg_log(DBG_ERROR, "read lwp header return error size: %d!\n", nbytes); - result = -RT_EIO; - goto _exit; - } - - /* check file header */ - if (header.magic != LWP_MAGIC) - { - dbg_log(DBG_ERROR, "erro header magic number: 0x%02X\n", header.magic); - result = -RT_EINVAL; - goto _exit; - } - - /* read text chunk info */ - nbytes = read(fd, &chunk, sizeof(struct lwp_chunk)); - if (nbytes != sizeof(struct lwp_chunk)) - { - dbg_log(DBG_ERROR, "read text chunk info failed!\n"); - result = -RT_EIO; - goto _exit; - } - - dbg_log(DBG_LOG, "chunk name: %s, total len %d, data %d, need space %d!\n", - "text", /*chunk.name*/ chunk.total_len, chunk.data_len, chunk.data_len_space); - - /* load text */ - { - lwp->text_size = RT_ALIGN(chunk.data_len_space, 4); - if (load_addr) - lwp->text_entry = ptr; - else - { -#ifdef RT_USING_CACHE - lwp->text_entry = (rt_uint8_t *)rt_malloc_align(lwp->text_size, RT_CPU_CACHE_LINE_SZ); -#else - lwp->text_entry = (rt_uint8_t *)rt_malloc(lwp->text_size); -#endif - - if (lwp->text_entry == RT_NULL) - { - dbg_log(DBG_ERROR, "alloc text memory faild!\n"); - result = -RT_ENOMEM; - goto _exit; - } - else - { - dbg_log(DBG_LOG, "lwp text malloc : %p, size: %d!\n", lwp->text_entry, lwp->text_size); - } - } - dbg_log(DBG_INFO, "load text %d => (0x%08x, 0x%08x)\n", lwp->text_size, (uint32_t)lwp->text_entry, (uint32_t)lwp->text_entry + lwp->text_size); - - nbytes = read(fd, lwp->text_entry, chunk.data_len); - if (nbytes != chunk.data_len) - { - dbg_log(DBG_ERROR, "read text region from file failed!\n"); - result = -RT_EIO; - goto _exit; - } -#ifdef RT_USING_CACHE - else - { - rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, lwp->text_entry, lwp->text_size); - rt_hw_cpu_icache_ops(RT_HW_CACHE_INVALIDATE, lwp->text_entry, lwp->text_size); - } -#endif - - if (ptr != RT_NULL) ptr += nbytes; - - /* skip text hole */ - if ((chunk.total_len - sizeof(struct lwp_chunk) - chunk.data_len)) - { - dbg_log(DBG_LOG, "skip text hole %d!\n", (chunk.total_len - sizeof(struct lwp_chunk) - chunk.data_len)); - lseek(fd, (chunk.total_len - sizeof(struct lwp_chunk) - chunk.data_len), SEEK_CUR); - } - } - - /* load data */ - nbytes = read(fd, &chunk, sizeof(struct lwp_chunk)); - if (nbytes != sizeof(struct lwp_chunk)) - { - dbg_log(DBG_ERROR, "read data chunk info failed!\n"); - result = -RT_EIO; - goto _exit; - } - - dbg_log(DBG_LOG, "chunk name: %s, total len %d, data %d, need space %d!\n", - chunk.name, chunk.total_len, chunk.data_len, chunk.data_len_space); - - { - lwp->data_size = RT_ALIGN(chunk.data_len_space, 4); - if (load_addr) - lwp->data = ptr; - else - { - lwp->data = rt_malloc(lwp->data_size); - if (lwp->data == RT_NULL) - { - dbg_log(DBG_ERROR, "alloc data memory faild!\n"); - result = -RT_ENOMEM; - goto _exit; - } - else - { - dbg_log(DBG_LOG, "lwp data malloc : %p, size: %d!\n", lwp->data, lwp->data_size); - rt_memset(lwp->data, 0, lwp->data_size); - } - } - - dbg_log(DBG_INFO, "load data %d => (0x%08x, 0x%08x)\n", lwp->data_size, (uint32_t)lwp->data, (uint32_t)lwp->data + lwp->data_size); - nbytes = read(fd, lwp->data, chunk.data_len); - if (nbytes != chunk.data_len) - { - dbg_log(DBG_ERROR, "read data region from file failed!\n"); - result = -RT_ERROR; - goto _exit; - } - } - -_exit: - if (fd >= 0) - close(fd); - - if (result != RT_EOK) - { - if (lwp->lwp_type == LWP_TYPE_DYN_ADDR) - { - dbg_log(DBG_ERROR, "lwp dynamic load faild, %d\n", result); - if (lwp->text_entry) - { - dbg_log(DBG_LOG, "lwp text free: %p\n", lwp->text_entry); -#ifdef RT_USING_CACHE - rt_free_align(lwp->text_entry); -#else - rt_free(lwp->text_entry); -#endif - } - if (lwp->data) - { - dbg_log(DBG_LOG, "lwp data free: %p\n", lwp->data); - rt_free(lwp->data); - } - } - } - - return result; -} - -static void lwp_cleanup(struct rt_thread *tid) -{ - struct rt_lwp *lwp; - - dbg_log(DBG_INFO, "thread: %s, stack_addr: %08X\n", tid->name, tid->stack_addr); - - lwp = (struct rt_lwp *)tid->lwp; - - if (lwp->lwp_type == LWP_TYPE_DYN_ADDR) - { - dbg_log(DBG_INFO, "dynamic lwp\n"); - if (lwp->text_entry) - { - dbg_log(DBG_LOG, "lwp text free: %p\n", lwp->text_entry); -#ifdef RT_USING_CACHE - rt_free_align(lwp->text_entry); -#else - rt_free(lwp->text_entry); -#endif - } - if (lwp->data) - { - dbg_log(DBG_LOG, "lwp data free: %p\n", lwp->data); - rt_free(lwp->data); - } - } - - dbg_log(DBG_LOG, "lwp free memory pages\n"); - rt_lwp_mem_deinit(lwp); - - /* cleanup fd table */ - while (lwp->fdt.maxfd > 0) - { - lwp->fdt.maxfd --; - close(lwp->fdt.maxfd); - } - rt_free(lwp->fdt.fds); - rt_free(lwp->args); - - dbg_log(DBG_LOG, "lwp free: %p\n", lwp); - rt_free(lwp); - - /* TODO: cleanup fd table */ -} - -static void lwp_thread(void *parameter) -{ - rt_thread_t tid; - struct rt_lwp *lwp; - - lwp = (struct rt_lwp *)parameter; - rt_lwp_mem_init(lwp); - tid = rt_thread_self(); - tid->lwp = lwp; - tid->cleanup = lwp_cleanup; - - lwp_user_entry(lwp->args, lwp->text_entry, lwp->data); -} - -struct rt_lwp *rt_lwp_self(void) -{ - return (struct rt_lwp *)rt_thread_self()->lwp; -} - -int exec(char *filename, int argc, char **argv) -{ - struct rt_lwp *lwp; - int result; - - if (filename == RT_NULL) - return -RT_ERROR; - - lwp = (struct rt_lwp *)rt_malloc(sizeof(struct rt_lwp)); - if (lwp == RT_NULL) - { - dbg_log(DBG_ERROR, "lwp struct out of memory!\n"); - return -RT_ENOMEM; - } - dbg_log(DBG_INFO, "lwp malloc : %p, size: %d!\n", lwp, sizeof(struct rt_lwp)); - - rt_memset(lwp, 0, sizeof(*lwp)); - if (lwp_argscopy(lwp, argc, argv) != 0) - { - rt_free(lwp); - return -ENOMEM; - } - - result = lwp_load(filename, lwp, RT_NULL, 0); - if (result == RT_EOK) - { - rt_thread_t tid; - - tid = rt_thread_create("user", lwp_thread, (void *)lwp, - 1024 * 4, 2, 200); - if (tid != RT_NULL) - { - dbg_log(DBG_LOG, "lwp kernel => (0x%08x, 0x%08x)\n", (rt_uint32_t)tid->stack_addr, (rt_uint32_t)tid->stack_addr + tid->stack_size); - rt_thread_startup(tid); - return RT_EOK; - } - else - { -#ifdef RT_USING_CACHE - rt_free_align(lwp->text_entry); -#else - rt_free(lwp->text_entry); -#endif - rt_free(lwp->data); - } - } - - rt_free(lwp->args); - rt_free(lwp); - - return -RT_ERROR; -} diff --git a/components/lwp/lwp.h b/components/lwp/lwp.h deleted file mode 100644 index 0b25cf6917..0000000000 --- a/components/lwp/lwp.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * File : lwp.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -#ifndef __LWP_H__ -#define __LWP_H__ - -#define LWP_MAGIC 0x5A - -#define LWP_TYPE_FIX_ADDR 0x01 -#define LWP_TYPE_DYN_ADDR 0x02 - -#define LWP_ARG_MAX 8 - -#include -#include -#include -#include - -struct rt_lwp -{ - uint8_t lwp_type; - uint8_t heap_cnt; - uint8_t reserv[2]; - - rt_list_t hlist; /**< headp list */ - - uint8_t *text_entry; - uint32_t text_size; - - uint8_t *data; - uint32_t data_size; - - uint32_t *kernel_sp; /**< kernel stack point */ - struct dfs_fdtable fdt; - void *args; -}; - -struct lwp_header -{ - uint8_t magic; - uint8_t compress_encrypt_algo; - uint16_t reserved; - - uint32_t crc32; -}; - -struct lwp_chunk -{ - uint32_t total_len; - - char name[4]; - uint32_t data_len; - uint32_t data_len_space; -}; - -extern struct rt_lwp *rt_lwp_self(void); - -extern void rt_lwp_mem_init(struct rt_lwp *lwp); -extern void rt_lwp_mem_deinit(struct rt_lwp *lwp); -extern void *rt_lwp_mem_malloc(rt_uint32_t size); -extern void rt_lwp_mem_free(void *addr); -extern void *rt_lwp_mem_realloc(void *rmem, rt_size_t newsize); - -#endif diff --git a/components/lwp/lwp_mem.c b/components/lwp/lwp_mem.c deleted file mode 100644 index 9b3dcf45a6..0000000000 --- a/components/lwp/lwp_mem.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * File : lwp_mem.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2018-03-24 Tanek the first version - */ - -#include -#include - -#define DBG_ENABLE -#define DBG_SECTION_NAME "LWPMEM" -#define DBG_COLOR -#define DBG_LEVEL DBG_WARNING -#include - -// todo: remove repleat code -#define RT_MEMHEAP_SIZE RT_ALIGN(sizeof(struct rt_lwp_memheap_item), RT_ALIGN_SIZE) -#define MEMITEM_SIZE(item) ((rt_uint32_t)item->next - (rt_uint32_t)item - RT_MEMHEAP_SIZE) - -#ifndef LWP_MEM_PAGE_SIZE - #define LWP_MEM_PAGE_SIZE (4 * 1024) -#endif - -#ifndef LWP_MEM_MAX_PAGE_COUNT - #define LWP_MEM_MAX_PAGE_COUNT (256 * 4) -#endif - -static void *rt_lwp_malloc_page(struct rt_lwp *lwp, rt_size_t npages) -{ - void *chunk; - char name[6]; - struct rt_lwp_memheap *lwp_heap; - rt_size_t page_cnt; - - RT_ASSERT(lwp != RT_NULL); - - page_cnt = lwp->heap_cnt + npages; - if (page_cnt > LWP_MEM_MAX_PAGE_COUNT) - { - dbg_log(DBG_ERROR, "alloc new page failed, lwp memory size out of limited: %d\n", page_cnt); - return RT_NULL; - } - - lwp_heap = rt_malloc(sizeof(struct rt_lwp_memheap)); - if (lwp_heap == RT_NULL) - { - dbg_log(DBG_ERROR, "alloc new page head failed, out of memory : %d\n", page_cnt); - return RT_NULL; - } - - chunk = rt_malloc(npages * LWP_MEM_PAGE_SIZE); - if (chunk == RT_NULL) - { - dbg_log(DBG_ERROR, "alloc new page buffer failed, out of memory : %d\n", page_cnt); - rt_free(lwp_heap); - return RT_NULL; - } - - dbg_log(DBG_LOG, "lwp alloc page: %d\n", npages); - - rt_sprintf(name, "lwp%02x", lwp->heap_cnt); - rt_lwp_memheap_init(lwp_heap, name, chunk, npages * LWP_MEM_PAGE_SIZE); - - rt_list_insert_before(&lwp->hlist, &lwp_heap->mlist); - - lwp->heap_cnt += npages; - - return chunk; -} - -static void rt_lwp_free_page(struct rt_lwp *lwp, struct rt_lwp_memheap *lwp_heap) -{ - rt_size_t npages; - - RT_ASSERT(lwp != RT_NULL); - RT_ASSERT(lwp_heap != RT_NULL); - RT_ASSERT(lwp_heap->start_addr != RT_NULL); - - npages = lwp_heap->pool_size / LWP_MEM_PAGE_SIZE; - lwp->heap_cnt -= npages; - - dbg_log(DBG_LOG, "lwp free page: %d\n", npages); - - rt_list_remove(&lwp_heap->mlist); - - rt_free(lwp_heap->start_addr); - rt_free(lwp_heap); -} - -void rt_lwp_mem_init(struct rt_lwp *lwp) -{ - RT_ASSERT(lwp != RT_NULL); - rt_list_init(&lwp->hlist); -} - -void rt_lwp_mem_deinit(struct rt_lwp *lwp) -{ - struct rt_list_node *node; - - RT_ASSERT(lwp != RT_NULL); - - node = lwp->hlist.next; - - while (node != &(lwp->hlist)) - { - struct rt_lwp_memheap *lwp_heap; - - lwp_heap = rt_list_entry(node, struct rt_lwp_memheap, mlist); - RT_ASSERT(lwp_heap != RT_NULL); - - /* update note before free page*/ - node = node->next; - - rt_lwp_free_page(lwp, lwp_heap); - } -} - -void *rt_lwp_mem_malloc(rt_uint32_t size) -{ - struct rt_lwp *lwp; - struct rt_list_node *node; - void *addr = RT_NULL; - rt_uint32_t npages; - - if (size == 0) - return RT_NULL; - - lwp = rt_lwp_self(); - RT_ASSERT(lwp != RT_NULL); - - for (node = lwp->hlist.next; node != &(lwp->hlist); node = node->next) - { - struct rt_lwp_memheap *lwp_heap; - lwp_heap = rt_list_entry(node, struct rt_lwp_memheap, mlist); - - addr = rt_lwp_memheap_alloc(lwp_heap, size); - if (addr != RT_NULL) - { - dbg_log(DBG_LOG, "lwp alloc 0x%x/%d\n", addr, size); - return addr; - } - } - - npages = (size + rt_lwp_memheap_unavailable_size_get() + LWP_MEM_PAGE_SIZE) / LWP_MEM_PAGE_SIZE; - if (RT_NULL != rt_lwp_malloc_page(lwp, npages)) - return rt_lwp_mem_malloc(size); - else - return RT_NULL; -} - -void rt_lwp_mem_free(void *addr) -{ - struct rt_lwp_memheap_item *header_ptr; - struct rt_lwp_memheap *lwp_heap; - - if (addr == RT_NULL) - return ; - - /* get memory item */ - header_ptr = (struct rt_lwp_memheap_item *)((rt_uint8_t *)addr - RT_MEMHEAP_SIZE); - RT_ASSERT(header_ptr); - - lwp_heap = header_ptr->pool_ptr; - RT_ASSERT(lwp_heap); - - dbg_log(DBG_LOG, "lwp free 0x%x\n", addr); - rt_lwp_memheap_free((void *)addr); - - if (rt_lwp_memheap_is_empty(lwp_heap)) - { - rt_lwp_free_page(rt_lwp_self(), lwp_heap); - } -} - -void *rt_lwp_mem_realloc(void *rmem, rt_size_t newsize) -{ - void *new_ptr; - struct rt_lwp_memheap_item *header_ptr; - - if (rmem == RT_NULL) - return rt_lwp_mem_malloc(newsize); - - if (newsize == 0) - { - rt_lwp_mem_free(rmem); - return RT_NULL; - } - - /* get old memory item */ - header_ptr = (struct rt_lwp_memheap_item *) - ((rt_uint8_t *)rmem - RT_MEMHEAP_SIZE); - - new_ptr = rt_lwp_memheap_realloc(header_ptr->pool_ptr, rmem, newsize); - if (new_ptr == RT_NULL) - { - /* allocate memory block from other memheap */ - new_ptr = rt_lwp_mem_malloc(newsize); - if (new_ptr != RT_NULL && rmem != RT_NULL) - { - rt_size_t oldsize; - - /* get the size of old memory block */ - oldsize = MEMITEM_SIZE(header_ptr); - if (newsize > oldsize) - rt_memcpy(new_ptr, rmem, oldsize); - else - rt_memcpy(new_ptr, rmem, newsize); - - dbg_log(DBG_LOG, "lwp realloc with memcpy 0x%x -> 0x%x/%d\n", rmem, new_ptr, newsize); - rt_lwp_mem_free(rmem); - - } - } - - dbg_log(DBG_LOG, "lwp realloc in same address 0x%x/%d\n", rmem, newsize); - - return new_ptr; -} diff --git a/components/lwp/lwp_mem.h b/components/lwp/lwp_mem.h deleted file mode 100644 index 117a18f677..0000000000 --- a/components/lwp/lwp_mem.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * File : lwp_mem.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -#ifndef __LWP_MEM_H__ -#define __LWP_MEM_H__ - -extern void rt_lwp_mem_init(struct rt_lwp *lwp); -extern void rt_lwp_mem_deinit(struct rt_lwp *lwp); - -extern void *rt_lwp_mem_malloc(rt_uint32_t size); -extern void rt_lwp_mem_free(void *addr); -extern void *rt_lwp_mem_realloc(void *rmem, rt_size_t newsize); - -#endif diff --git a/components/lwp/lwp_memheap.c b/components/lwp/lwp_memheap.c deleted file mode 100644 index 46ba667695..0000000000 --- a/components/lwp/lwp_memheap.c +++ /dev/null @@ -1,590 +0,0 @@ -/* - * File : lwp_memheap.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2012-04-10 Bernard first implementation - * 2012-10-16 Bernard add the mutex lock for heap object. - * 2012-12-29 Bernard memheap can be used as system heap. - * change mutex lock to semaphore lock. - * 2013-04-10 Bernard add rt_lwp_memheap_realloc function. - * 2013-05-24 Bernard fix the rt_lwp_memheap_realloc issue. - * 2013-07-11 Grissiom fix the memory block splitting issue. - * 2013-07-15 Grissiom optimize rt_lwp_memheap_realloc - */ - -#include -#include -#include - -/* dynamic pool magic and mask */ -#define RT_MEMHEAP_MAGIC 0x1ea01ea0 -#define RT_MEMHEAP_MASK 0xfffffffe -#define RT_MEMHEAP_USED 0x01 -#define RT_MEMHEAP_FREED 0x00 - -#define RT_MEMHEAP_IS_USED(i) ((i)->magic & RT_MEMHEAP_USED) -#define RT_MEMHEAP_MINIALLOC 12 - -#define RT_MEMHEAP_SIZE RT_ALIGN(sizeof(struct rt_lwp_memheap_item), RT_ALIGN_SIZE) -#define MEMITEM_SIZE(item) ((rt_uint32_t)item->next - (rt_uint32_t)item - RT_MEMHEAP_SIZE) - -/* - * The initialized memory pool will be: - * +-----------------------------------+--------------------------+ - * | whole freed memory block | Used Memory Block Tailer | - * +-----------------------------------+--------------------------+ - * - * block_list --> whole freed memory block - * - * The length of Used Memory Block Tailer is 0, - * which is prevents block merging across list - */ -rt_err_t rt_lwp_memheap_init(struct rt_lwp_memheap *memheap, - const char *name, - void *start_addr, - rt_uint32_t size) -{ - struct rt_lwp_memheap_item *item; - - RT_ASSERT(memheap != RT_NULL); - - /* initialize pool object */ - memheap->start_addr = start_addr; - memheap->pool_size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE); - memheap->available_size = memheap->pool_size - (2 * RT_MEMHEAP_SIZE); - memheap->max_used_size = memheap->pool_size - memheap->available_size; - - /* initialize the free list header */ - item = &(memheap->free_header); - item->magic = RT_MEMHEAP_MAGIC; - item->pool_ptr = memheap; - item->next = RT_NULL; - item->prev = RT_NULL; - item->next_free = item; - item->prev_free = item; - - /* set the free list to free list header */ - memheap->free_list = item; - - /* initialize the first big memory block */ - item = (struct rt_lwp_memheap_item *)start_addr; - item->magic = RT_MEMHEAP_MAGIC; - item->pool_ptr = memheap; - item->next = RT_NULL; - item->prev = RT_NULL; - item->next_free = item; - item->prev_free = item; - - item->next = (struct rt_lwp_memheap_item *) - ((rt_uint8_t *)item + memheap->available_size + RT_MEMHEAP_SIZE); - item->prev = item->next; - - /* block list header */ - memheap->block_list = item; - - /* place the big memory block to free list */ - item->next_free = memheap->free_list->next_free; - item->prev_free = memheap->free_list; - memheap->free_list->next_free->prev_free = item; - memheap->free_list->next_free = item; - - /* move to the end of memory pool to build a small tailer block, - * which prevents block merging - */ - item = item->next; - /* it's a used memory block */ - item->magic = RT_MEMHEAP_MAGIC | RT_MEMHEAP_USED; - item->pool_ptr = memheap; - item->next = (struct rt_lwp_memheap_item *)start_addr; - item->prev = (struct rt_lwp_memheap_item *)start_addr; - /* not in free list */ - item->next_free = item->prev_free = RT_NULL; - - /* initialize semaphore lock */ - rt_sem_init(&(memheap->lock), name, 1, RT_IPC_FLAG_FIFO); - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("memory heap: start addr 0x%08x, size %d, free list header 0x%08x\n", - start_addr, size, &(memheap->free_header))); - - return RT_EOK; -} - -void *rt_lwp_memheap_alloc(struct rt_lwp_memheap *heap, rt_uint32_t size) -{ - rt_err_t result; - rt_uint32_t free_size; - struct rt_lwp_memheap_item *header_ptr; - - RT_ASSERT(heap != RT_NULL); - - /* align allocated size */ - size = RT_ALIGN(size, RT_ALIGN_SIZE); - if (size < RT_MEMHEAP_MINIALLOC) - size = RT_MEMHEAP_MINIALLOC; - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("allocate %d on heap:%8.*s", - size, RT_NAME_MAX, heap->parent.name)); - - if (size < heap->available_size) - { - /* search on free list */ - free_size = 0; - - /* lock memheap */ - result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); - if (result != RT_EOK) - { - rt_set_errno(result); - - return RT_NULL; - } - - /* get the first free memory block */ - header_ptr = heap->free_list->next_free; - while (header_ptr != heap->free_list && free_size < size) - { - /* get current freed memory block size */ - free_size = MEMITEM_SIZE(header_ptr); - if (free_size < size) - { - /* move to next free memory block */ - header_ptr = header_ptr->next_free; - } - } - - /* determine if the memory is available. */ - if (free_size >= size) - { - /* a block that satisfies the request has been found. */ - - /* determine if the block needs to be split. */ - if (free_size >= (size + RT_MEMHEAP_SIZE + RT_MEMHEAP_MINIALLOC)) - { - struct rt_lwp_memheap_item *new_ptr; - - /* split the block. */ - new_ptr = (struct rt_lwp_memheap_item *) - (((rt_uint8_t *)header_ptr) + size + RT_MEMHEAP_SIZE); - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("split: block[0x%08x] nextm[0x%08x] prevm[0x%08x] to new[0x%08x]\n", - header_ptr, - header_ptr->next, - header_ptr->prev, - new_ptr)); - - /* mark the new block as a memory block and freed. */ - new_ptr->magic = RT_MEMHEAP_MAGIC; - - /* put the pool pointer into the new block. */ - new_ptr->pool_ptr = heap; - - /* break down the block list */ - new_ptr->prev = header_ptr; - new_ptr->next = header_ptr->next; - header_ptr->next->prev = new_ptr; - header_ptr->next = new_ptr; - - /* remove header ptr from free list */ - header_ptr->next_free->prev_free = header_ptr->prev_free; - header_ptr->prev_free->next_free = header_ptr->next_free; - header_ptr->next_free = RT_NULL; - header_ptr->prev_free = RT_NULL; - - /* insert new_ptr to free list */ - new_ptr->next_free = heap->free_list->next_free; - new_ptr->prev_free = heap->free_list; - heap->free_list->next_free->prev_free = new_ptr; - heap->free_list->next_free = new_ptr; - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("new ptr: next_free 0x%08x, prev_free 0x%08x\n", - new_ptr->next_free, - new_ptr->prev_free)); - - /* decrement the available byte count. */ - heap->available_size = heap->available_size - - size - - RT_MEMHEAP_SIZE; - if (heap->pool_size - heap->available_size > heap->max_used_size) - heap->max_used_size = heap->pool_size - heap->available_size; - } - else - { - /* decrement the entire free size from the available bytes count. */ - heap->available_size = heap->available_size - free_size; - if (heap->pool_size - heap->available_size > heap->max_used_size) - heap->max_used_size = heap->pool_size - heap->available_size; - - /* remove header_ptr from free list */ - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("one block: block[0x%08x], next_free 0x%08x, prev_free 0x%08x\n", - header_ptr, - header_ptr->next_free, - header_ptr->prev_free)); - - header_ptr->next_free->prev_free = header_ptr->prev_free; - header_ptr->prev_free->next_free = header_ptr->next_free; - header_ptr->next_free = RT_NULL; - header_ptr->prev_free = RT_NULL; - } - - /* Mark the allocated block as not available. */ - header_ptr->magic |= RT_MEMHEAP_USED; - - /* release lock */ - rt_sem_release(&(heap->lock)); - - /* Return a memory address to the caller. */ - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("alloc mem: memory[0x%08x], heap[0x%08x], size: %d\n", - (void *)((rt_uint8_t *)header_ptr + RT_MEMHEAP_SIZE), - header_ptr, - size)); - - return (void *)((rt_uint8_t *)header_ptr + RT_MEMHEAP_SIZE); - } - - /* release lock */ - rt_sem_release(&(heap->lock)); - } - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("allocate memory: failed\n")); - - /* Return the completion status. */ - return RT_NULL; -} - -void *rt_lwp_memheap_realloc(struct rt_lwp_memheap *heap, void *ptr, rt_size_t newsize) -{ - rt_err_t result; - rt_size_t oldsize; - struct rt_lwp_memheap_item *header_ptr; - struct rt_lwp_memheap_item *new_ptr; - - if (newsize == 0) - { - rt_lwp_memheap_free(ptr); - - return RT_NULL; - } - /* align allocated size */ - newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE); - if (newsize < RT_MEMHEAP_MINIALLOC) - newsize = RT_MEMHEAP_MINIALLOC; - - if (ptr == RT_NULL) - { - return rt_lwp_memheap_alloc(heap, newsize); - } - - /* get memory block header and get the size of memory block */ - header_ptr = (struct rt_lwp_memheap_item *) - ((rt_uint8_t *)ptr - RT_MEMHEAP_SIZE); - oldsize = MEMITEM_SIZE(header_ptr); - /* re-allocate memory */ - if (newsize > oldsize) - { - void *new_ptr; - struct rt_lwp_memheap_item *next_ptr; - - /* lock memheap */ - result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); - if (result != RT_EOK) - { - rt_set_errno(result); - return RT_NULL; - } - - next_ptr = header_ptr->next; - - /* header_ptr should not be the tail */ - RT_ASSERT(next_ptr > header_ptr); - - /* check whether the following free space is enough to expand */ - if (!RT_MEMHEAP_IS_USED(next_ptr)) - { - rt_int32_t nextsize; - - nextsize = MEMITEM_SIZE(next_ptr); - RT_ASSERT(next_ptr > 0); - - /* Here is the ASCII art of the situation that we can make use of - * the next free node without alloc/memcpy, |*| is the control - * block: - * - * oldsize free node - * |*|-----------|*|----------------------|*| - * newsize >= minialloc - * |*|----------------|*|-----------------|*| - */ - if (nextsize + oldsize > newsize + RT_MEMHEAP_MINIALLOC) - { - /* decrement the entire free size from the available bytes count. */ - heap->available_size = heap->available_size - (newsize - oldsize); - if (heap->pool_size - heap->available_size > heap->max_used_size) - heap->max_used_size = heap->pool_size - heap->available_size; - - /* remove next_ptr from free list */ - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("remove block: block[0x%08x], next_free 0x%08x, prev_free 0x%08x", - next_ptr, - next_ptr->next_free, - next_ptr->prev_free)); - - next_ptr->next_free->prev_free = next_ptr->prev_free; - next_ptr->prev_free->next_free = next_ptr->next_free; - next_ptr->next->prev = next_ptr->prev; - next_ptr->prev->next = next_ptr->next; - - /* build a new one on the right place */ - next_ptr = (struct rt_lwp_memheap_item *)((char *)ptr + newsize); - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("new free block: block[0x%08x] nextm[0x%08x] prevm[0x%08x]", - next_ptr, - next_ptr->next, - next_ptr->prev)); - - /* mark the new block as a memory block and freed. */ - next_ptr->magic = RT_MEMHEAP_MAGIC; - - /* put the pool pointer into the new block. */ - next_ptr->pool_ptr = heap; - - next_ptr->prev = header_ptr; - next_ptr->next = header_ptr->next; - header_ptr->next->prev = next_ptr; - header_ptr->next = next_ptr; - - /* insert next_ptr to free list */ - next_ptr->next_free = heap->free_list->next_free; - next_ptr->prev_free = heap->free_list; - heap->free_list->next_free->prev_free = next_ptr; - heap->free_list->next_free = next_ptr; - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("new ptr: next_free 0x%08x, prev_free 0x%08x", - next_ptr->next_free, - next_ptr->prev_free)); - - /* release lock */ - rt_sem_release(&(heap->lock)); - - return ptr; - } - } - - /* release lock */ - rt_sem_release(&(heap->lock)); - - /* re-allocate a memory block */ - new_ptr = (void *)rt_lwp_memheap_alloc(heap, newsize); - if (new_ptr != RT_NULL) - { - rt_memcpy(new_ptr, ptr, oldsize < newsize ? oldsize : newsize); - rt_lwp_memheap_free(ptr); - } - - return new_ptr; - } - - /* don't split when there is less than one node space left */ - if (newsize + RT_MEMHEAP_SIZE + RT_MEMHEAP_MINIALLOC >= oldsize) - return ptr; - - /* lock memheap */ - result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); - if (result != RT_EOK) - { - rt_set_errno(result); - - return RT_NULL; - } - - /* split the block. */ - new_ptr = (struct rt_lwp_memheap_item *) - (((rt_uint8_t *)header_ptr) + newsize + RT_MEMHEAP_SIZE); - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("split: block[0x%08x] nextm[0x%08x] prevm[0x%08x] to new[0x%08x]\n", - header_ptr, - header_ptr->next, - header_ptr->prev, - new_ptr)); - - /* mark the new block as a memory block and freed. */ - new_ptr->magic = RT_MEMHEAP_MAGIC; - /* put the pool pointer into the new block. */ - new_ptr->pool_ptr = heap; - - /* break down the block list */ - new_ptr->prev = header_ptr; - new_ptr->next = header_ptr->next; - header_ptr->next->prev = new_ptr; - header_ptr->next = new_ptr; - - /* determine if the block can be merged with the next neighbor. */ - if (!RT_MEMHEAP_IS_USED(new_ptr->next)) - { - struct rt_lwp_memheap_item *free_ptr; - - /* merge block with next neighbor. */ - free_ptr = new_ptr->next; - heap->available_size = heap->available_size - MEMITEM_SIZE(free_ptr); - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("merge: right node 0x%08x, next_free 0x%08x, prev_free 0x%08x\n", - header_ptr, header_ptr->next_free, header_ptr->prev_free)); - - free_ptr->next->prev = new_ptr; - new_ptr->next = free_ptr->next; - - /* remove free ptr from free list */ - free_ptr->next_free->prev_free = free_ptr->prev_free; - free_ptr->prev_free->next_free = free_ptr->next_free; - } - - /* insert the split block to free list */ - new_ptr->next_free = heap->free_list->next_free; - new_ptr->prev_free = heap->free_list; - heap->free_list->next_free->prev_free = new_ptr; - heap->free_list->next_free = new_ptr; - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("new free ptr: next_free 0x%08x, prev_free 0x%08x\n", - new_ptr->next_free, - new_ptr->prev_free)); - - /* increment the available byte count. */ - heap->available_size = heap->available_size + MEMITEM_SIZE(new_ptr); - - /* release lock */ - rt_sem_release(&(heap->lock)); - - /* return the old memory block */ - return ptr; -} - -void rt_lwp_memheap_free(void *ptr) -{ - rt_err_t result; - struct rt_lwp_memheap *heap; - struct rt_lwp_memheap_item *header_ptr, *new_ptr; - rt_uint32_t insert_header; - - /* NULL check */ - if (ptr == RT_NULL) return; - - /* set initial status as OK */ - insert_header = 1; - new_ptr = RT_NULL; - header_ptr = (struct rt_lwp_memheap_item *) - ((rt_uint8_t *)ptr - RT_MEMHEAP_SIZE); - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("free memory: memory[0x%08x], block[0x%08x]\n", - ptr, header_ptr)); - - /* check magic */ - RT_ASSERT((header_ptr->magic & RT_MEMHEAP_MASK) == RT_MEMHEAP_MAGIC); - RT_ASSERT(header_ptr->magic & RT_MEMHEAP_USED); - /* check whether this block of memory has been over-written. */ - RT_ASSERT((header_ptr->next->magic & RT_MEMHEAP_MASK) == RT_MEMHEAP_MAGIC); - - /* get pool ptr */ - heap = header_ptr->pool_ptr; - - /* lock memheap */ - result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); - if (result != RT_EOK) - { - rt_set_errno(result); - - return ; - } - - /* Mark the memory as available. */ - header_ptr->magic &= ~RT_MEMHEAP_USED; - /* Adjust the available number of bytes. */ - heap->available_size = heap->available_size + MEMITEM_SIZE(header_ptr); - - /* Determine if the block can be merged with the previous neighbor. */ - if (!RT_MEMHEAP_IS_USED(header_ptr->prev)) - { - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("merge: left node 0x%08x\n", - header_ptr->prev)); - - /* adjust the available number of bytes. */ - heap->available_size = heap->available_size + RT_MEMHEAP_SIZE; - - /* yes, merge block with previous neighbor. */ - (header_ptr->prev)->next = header_ptr->next; - (header_ptr->next)->prev = header_ptr->prev; - - /* move header pointer to previous. */ - header_ptr = header_ptr->prev; - /* don't insert header to free list */ - insert_header = 0; - } - - /* determine if the block can be merged with the next neighbor. */ - if (!RT_MEMHEAP_IS_USED(header_ptr->next)) - { - /* adjust the available number of bytes. */ - heap->available_size = heap->available_size + RT_MEMHEAP_SIZE; - - /* merge block with next neighbor. */ - new_ptr = header_ptr->next; - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("merge: right node 0x%08x, next_free 0x%08x, prev_free 0x%08x\n", - new_ptr, new_ptr->next_free, new_ptr->prev_free)); - - new_ptr->next->prev = header_ptr; - header_ptr->next = new_ptr->next; - - /* remove new ptr from free list */ - new_ptr->next_free->prev_free = new_ptr->prev_free; - new_ptr->prev_free->next_free = new_ptr->next_free; - } - - if (insert_header) - { - /* no left merge, insert to free list */ - header_ptr->next_free = heap->free_list->next_free; - header_ptr->prev_free = heap->free_list; - heap->free_list->next_free->prev_free = header_ptr; - heap->free_list->next_free = header_ptr; - - RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, - ("insert to free list: next_free 0x%08x, prev_free 0x%08x\n", - header_ptr->next_free, header_ptr->prev_free)); - } - - /* release lock */ - rt_sem_release(&(heap->lock)); -} - -rt_bool_t rt_lwp_memheap_is_empty(struct rt_lwp_memheap *memheap) -{ - RT_ASSERT(memheap != RT_NULL); - - return (memheap->available_size + 2 * sizeof(struct rt_lwp_memheap_item)) == memheap->pool_size; -} - -rt_bool_t rt_lwp_memheap_unavailable_size_get(void) -{ - return 2 * RT_MEMHEAP_SIZE + 3; -} diff --git a/components/lwp/lwp_memheap.h b/components/lwp/lwp_memheap.h deleted file mode 100644 index 064238585c..0000000000 --- a/components/lwp/lwp_memheap.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * File : lwp_memheap.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -#ifndef __LWP_MEMHEAP_H__ -#define __LWP_MEMHEAP_H__ - -#include -#include - -/** - * memory item on the heap - */ -struct rt_lwp_memheap_item -{ - rt_uint32_t magic; /**< magic number for memheap */ - struct rt_lwp_memheap *pool_ptr; /**< point of pool */ - - struct rt_lwp_memheap_item *next; /**< next memheap item */ - struct rt_lwp_memheap_item *prev; /**< prev memheap item */ - - struct rt_lwp_memheap_item *next_free; /**< next free memheap item */ - struct rt_lwp_memheap_item *prev_free; /**< prev free memheap item */ -}; - -/** - * Base structure of memory heap object - */ -struct rt_lwp_memheap -{ - struct rt_object parent; /**< inherit from rt_object */ - - void *start_addr; /**< pool start address and size */ - - rt_uint32_t pool_size; /**< pool size */ - rt_uint32_t available_size; /**< available size */ - rt_uint32_t max_used_size; /**< maximum allocated size */ - - struct rt_lwp_memheap_item *block_list; /**< used block list */ - struct rt_lwp_memheap_item *free_list; /**< free block list */ - struct rt_lwp_memheap_item free_header; /**< free block list header */ - - struct rt_semaphore lock; /**< semaphore lock */ - - rt_list_t mlist; -}; - -extern rt_err_t rt_lwp_memheap_init(struct rt_lwp_memheap *memheap, const char *name, void *start_addr, rt_uint32_t size); -extern void *rt_lwp_memheap_alloc(struct rt_lwp_memheap *heap, rt_uint32_t size); -extern void rt_lwp_memheap_free(void *ptr); -extern void *rt_lwp_memheap_realloc(struct rt_lwp_memheap *heap, void *ptr, rt_size_t newsize); -extern rt_bool_t rt_lwp_memheap_is_empty(struct rt_lwp_memheap *memheap); -extern rt_bool_t rt_lwp_memheap_unavailable_size_get(void); - -#endif diff --git a/components/lwp/lwp_syscall.c b/components/lwp/lwp_syscall.c deleted file mode 100644 index 0150e50b62..0000000000 --- a/components/lwp/lwp_syscall.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * File : lwp_syscall.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - */ - -/* RT-Thread System call */ -#include -#include -#include - -#include -#include - -#if (defined(RT_USING_SAL) && defined(SAL_USING_POSIX)) -#include - -#define SYSCALL_NET(f) (f) -#else -#define SYSCALL_NET(f) (sys_notimpl) -#endif - -#define DBG_ENABLE -#define DBG_SECTION_NAME "LWP_CALL" -#define DBG_COLOR -#define DBG_LEVEL DBG_WARNING -#include - -/* thread/process */ -void sys_exit(int value) -{ - /* TODO: handle the return_value */ - - dbg_log(DBG_LOG, "enter sys_exit\n"); - - rt_thread_delete(rt_thread_self()); - - rt_schedule(); - - return; -} - -/* syscall: "read" ret: "ssize_t" args: "int" "void *" "size_t" */ -ssize_t sys_read(int fd, void *buf, size_t nbyte) -{ - return read(fd, buf, nbyte); -} - -/* syscall: "write" ret: "ssize_t" args: "int" "const void *" "size_t" */ -ssize_t sys_write(int fd, const void *buf, size_t nbyte) -{ - return write(fd, buf, nbyte); -} - -/* syscall: "lseek" ret: "off_t" args: "int" "off_t" "int" */ -off_t sys_lseek(int fd, off_t offset, int whence) -{ - return lseek(fd, offset, whence); -} - -/* syscall: "open" ret: "int" args: "const char *" "int" "..." */ -int sys_open(const char *name, int mode, ...) -{ - return open(name, mode, 0); -} - -/* syscall: "close" ret: "int" args: "int" */ -int sys_close(int fd) -{ - return close(fd); -} - -/* syscall: "ioctl" ret: "int" args: "int" "u_long" "..." */ -int sys_ioctl(int fd, unsigned long cmd, void* data) -{ - return ioctl(fd, cmd, data); -} - -/* syscall: "nanosleep" ret: "int" args: "const struct timespec *" "struct timespec *" */ -int sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp) -{ - rt_tick_t tick; - - dbg_log(DBG_LOG, "sys_nanosleep\n"); - - tick = rqtp->tv_sec * RT_TICK_PER_SECOND + (rqtp->tv_nsec * RT_TICK_PER_SECOND)/ 1000000000; - rt_thread_delay(tick); - - if (rmtp) - { - tick = rt_tick_get() - tick; - /* get the passed time */ - rmtp->tv_sec = tick/RT_TICK_PER_SECOND; - rmtp->tv_nsec = (tick%RT_TICK_PER_SECOND) * (1000000000/RT_TICK_PER_SECOND); - } - - return 0; -} - -/* syscall: "getpriority" ret: "int" args: "int" "id_t" */ -int sys_getpriority(int which, id_t who) -{ - if (which == PRIO_PROCESS) - { - rt_thread_t tid; - - tid = rt_thread_self(); - if (who == (id_t)tid || who == 0xff) - { - return tid->current_priority; - } - } - - return 0xff; -} - -/* syscall: "setpriority" ret: "int" args: "int" "id_t" "int" */ -int sys_setpriority(int which, id_t who, int prio) -{ - if (which == PRIO_PROCESS) - { - rt_thread_t tid; - - tid = rt_thread_self(); - if ((who == (id_t)tid || who == 0xff) && (prio >= 0 && prio < RT_THREAD_PRIORITY_MAX)) - { - rt_thread_control(tid, RT_THREAD_CTRL_CHANGE_PRIORITY, &prio); - return 0; - } - } - - return -1; -} - -/* syscall: "gettimeofday" ret: "int" args: "struct timeval *" "struct timezone *" */ -int sys_gettimeofday(struct timeval *tp, struct timezone *tzp) -{ - if (tp) - { - tp->tv_sec = rt_tick_get() / RT_TICK_PER_SECOND; - tp->tv_usec = (rt_tick_get() % RT_TICK_PER_SECOND) * (1000000 / RT_TICK_PER_SECOND); - } - - return 0; -} - -/* syscall: "settimeofday" ret: "int" args: "const struct timeval *" "const struct timezone *" */ -int sys_settimeofday(const struct timeval *tv, const struct timezone *tzp) -{ - return 0; -} - -/* syscall: "msgget" ret: "int" args: "key_t" "int" */ -int sys_msgget(key_t key, int msgflg) -{ - return -1; -} - -/* syscall: "msgsnd" ret: "int" args: "int" "const void *" "size_t" "int" */ -int sys_msgsend(int msqid, const void *msgp, size_t msgsz, int msgflg) -{ - return -1; -} - -/* syscall: "msgrcv" ret: "int" args: "int" "void *" "size_t" "long" "int" */ -int sys_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) -{ - return -1; -} - -/* syscall: "sys_log" ret: "int" args: "const char*" "size" */ -int sys_log(const char* log, int size) -{ - rt_device_t console = rt_console_get_device(); - - if (console) rt_device_write(console, -1, log, size); - - return 0; -} - -void *sys_malloc(size_t size) -{ - return rt_lwp_mem_malloc(size); -} - -void sys_free(void *addr) -{ - rt_lwp_mem_free(addr); -} - -void *sys_realloc(void *rmem, size_t newsize) -{ - return rt_lwp_mem_realloc(rmem, newsize); -} - -int sys_fstat(int file, struct stat *buf) -{ - return fstat(file, buf); -} - -int sys_notimpl(void) -{ - return -ENOSYS; -} - -const static void* func_table[] = -{ - (void *)sys_exit, // 0x01 - (void *)sys_read, // 0x02 - (void *)sys_write, // 0x03 - (void *)sys_lseek, // 0x04 - (void *)sys_open, // 0x05 - (void *)sys_close, // 0x06 - (void *)sys_ioctl, // 0x07 - - (void *)sys_nanosleep, // 0x08 - - (void *)sys_getpriority, // 0x09 - (void *)sys_setpriority, // 0x0a - - (void *)sys_gettimeofday, // 0x0b - (void *)sys_settimeofday, // 0x0c - - (void *)sys_malloc, // 0x0d - (void *)sys_free, // 0x0e - (void *)sys_realloc, //0x0f - (void *)sys_fstat, // 0x10 - poll, // 0x11 - - SYSCALL_NET(accept), // 0x12 - SYSCALL_NET(bind), // 0x13 - SYSCALL_NET(shutdown), // 0x14 - SYSCALL_NET(getpeername),// 0x15 - SYSCALL_NET(getsockname),// 0x16 - SYSCALL_NET(getsockopt), // 0x17 - SYSCALL_NET(setsockopt), // 0x18 - SYSCALL_NET(connect), // 0x19 - SYSCALL_NET(listen), // 0x1a - SYSCALL_NET(recv), // 0x1b - SYSCALL_NET(recvfrom), // 0x1c - SYSCALL_NET(send), // 0x1d - SYSCALL_NET(sendto), // 0x1e - SYSCALL_NET(socket), // 0x1f - - select, // 0x20 -}; - -const void *lwp_get_sys_api(rt_uint32_t number) -{ - const void *func = sys_notimpl; - - if (number == 0xff) - { - func = (void *)sys_log; - } - else - { - number -= 1; - if (number < sizeof(func_table)/sizeof(func_table[0])) - { - func = func_table[number]; - } - } - - return func; -} diff --git a/components/lwp/lwp_syscall.h b/components/lwp/lwp_syscall.h deleted file mode 100644 index eba25c40e3..0000000000 --- a/components/lwp/lwp_syscall.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * File : lwp_syscall.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2006-03-18 Bernard the first version - * 2006-04-25 Bernard add rt_hw_context_switch_interrupt declaration - * 2006-09-24 Bernard add rt_hw_context_switch_to declaration - * 2012-12-29 Bernard add rt_hw_exception_install declaration - * 2017-10-17 Hichard add some micros - */ - -#ifndef __LWP_SYSCALL_H__ -#define __LWP_SYSCALL_H__ - -#include -#include -#include -#include -#include - -typedef long suseconds_t; /* microseconds (signed) */ -typedef long key_t; /* IPC key (for Sys V IPC) */ -typedef uint32_t id_t; /* may contain pid, uid or gid */ - -/* - * Process priority specifications to get/setpriority. - */ -#define PRIO_MIN (-20) -#define PRIO_MAX 20 - -#define PRIO_PROCESS 0 /* only support lwp process */ -#define PRIO_PGRP 1 -#define PRIO_USER 2 - -#define TIMEVAL_TO_TIMESPEC(tv, ts) { \ - (ts)->tv_sec = (tv)->tv_sec; \ - (ts)->tv_nsec = (tv)->tv_usec * 1000; \ -} -#define TIMESPEC_TO_TIMEVAL(tv, ts) { \ - (tv)->tv_sec = (ts)->tv_sec; \ - (tv)->tv_usec = (ts)->tv_nsec / 1000; \ -} - -void sys_exit(int value); -ssize_t sys_read(int fd, void *buf, size_t nbyte); -ssize_t sys_write(int fd, const void *buf, size_t nbyte); -off_t sys_lseek(int fd, off_t offset, int whence); -int sys_open(const char *name, int mode, ...); -int sys_close(int fd); -int sys_nanosleep(const struct timespec *rqtp, struct timespec *rmtp); -int sys_getpriority(int which, id_t who); -int sys_setpriority(int which, id_t who, int prio); -int sys_gettimeofday(struct timeval *tp, struct timezone *tzp); -int sys_settimeofday(const struct timeval *tv, const struct timezone *tzp); -int sys_msgget(key_t key, int msgflg); -int sys_msgsend(int msqid, const void *msgp, size_t msgsz, int msgflg); -int sys_msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg); - -int sys_log(const char* log, int size); - -#endif diff --git a/include/rtdef.h b/include/rtdef.h index c37f90be2d..7889412ab3 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -496,10 +496,6 @@ typedef siginfo_t rt_siginfo_t; #define RT_THREAD_CTRL_CHANGE_PRIORITY 0x02 /**< Change thread priority. */ #define RT_THREAD_CTRL_INFO 0x03 /**< Get thread information. */ -#ifdef RT_USING_LWP -struct rt_lwp; -#endif - /** * Thread structure */ @@ -560,11 +556,12 @@ struct rt_thread void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */ - rt_uint32_t user_data; /**< private user data beyond this thread */ - + /* light weight process if present */ #ifdef RT_USING_LWP - struct rt_lwp *lwp; /**< if NULL it's a kernel thread */ + void *lwp; #endif + + rt_uint32_t user_data; /**< private user data beyond this thread */ }; typedef struct rt_thread *rt_thread_t; -- cgit v1.3.1 From 95c36f32e20b9799907890cbb6d366ad783501b1 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 4 Sep 2018 07:01:39 +0800 Subject: Update rtdef.h --- include/rtdef.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/rtdef.h b/include/rtdef.h index 7889412ab3..03871d1fcc 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -36,6 +36,7 @@ * 2018-02-24 Bernard change version number to v3.0.3 * 2018-04-25 Bernard change version number to v3.0.4 * 2018-05-31 Bernard change version number to v3.1.0 + * 2018-09-04 Bernard change version number to v3.1.1 */ #ifndef __RT_DEF_H__ @@ -57,7 +58,7 @@ extern "C" { /* RT-Thread version information */ #define RT_VERSION 3L /**< major version number */ #define RT_SUBVERSION 1L /**< minor version number */ -#define RT_REVISION 0L /**< revise version number */ +#define RT_REVISION 1L /**< revise version number */ /* RT-Thread version */ #define RTTHREAD_VERSION ((RT_VERSION * 10000) + \ -- cgit v1.3.1 From 3dea90eaf9212e5387c68b6cd731ab3e8d2d3605 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 6 Sep 2018 09:50:18 +0800 Subject: [rtdbg] Optimize footprint for rtdbg log. --- include/rtdbg.h | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/rtdbg.h b/include/rtdbg.h index f53aba8de9..13e057bfc4 100644 --- a/include/rtdbg.h +++ b/include/rtdbg.h @@ -84,10 +84,14 @@ #define _DBG_COLOR(n) rt_kprintf("\033["#n"m") #define _DBG_LOG_HDR(lvl_name, color_n) \ rt_kprintf("\033["#color_n"m["lvl_name"/"DBG_SECTION_NAME"] ") +#define _DBG_LOG_X_END \ + rt_kprintf("\033[0m\n") #else #define _DBG_COLOR(n) #define _DBG_LOG_HDR(lvl_name, color_n) \ rt_kprintf("["lvl_name"/"DBG_SECTION_NAME"] ") +#define _DBG_LOG_X_END \ + rt_kprintf("\n") #endif /* DBG_COLOR */ /* @@ -130,11 +134,15 @@ _DBG_COLOR(0); \ } -#define dbg_log_line(level, ...) \ - dbg_log(level, __VA_ARGS__); \ - if ((level) >= DBG_LEVEL) { \ - rt_kprintf("\n"); \ - } + +#define dbg_log_line(lvl, color_n, fmt, ...) \ + do \ + { \ + _DBG_LOG_HDR(lvl, color_n); \ + rt_kprintf(fmt, ##__VA_ARGS__); \ + _DBG_LOG_X_END; \ + } \ + while (0) #define dbg_raw(...) rt_kprintf(__VA_ARGS__); @@ -143,14 +151,34 @@ #define dbg_here #define dbg_enter #define dbg_exit -#define dbg_log_line(level, ...) +#define dbg_log_line(lvl, color_n, fmt, ...) #define dbg_raw(...) +#endif /* DBG_ENABLE */ + +#if (DBG_LEVEL <= DBG_LOG) +#define LOG_D(fmt, ...) dbg_log_line("D", 0, fmt, ##__VA_ARGS__) +#else +#define LOG_D(...) +#endif + +#if (DBG_LEVEL <= DBG_INFO) +#define LOG_I(fmt, ...) dbg_log_line("I", 32, fmt, ##__VA_ARGS__) +#else +#define LOG_I(...) +#endif + +#if (DBG_LEVEL <= DBG_WARNING) +#define LOG_W(fmt, ...) dbg_log_line("W", 33, fmt, ##__VA_ARGS__) +#else +#define LOG_W(...) +#endif + +#if (DBG_LEVEL <= DBG_ERROR) +#define LOG_E(fmt, ...) dbg_log_line("E", 31, fmt, ##__VA_ARGS__) +#else +#define LOG_E(...) #endif -#define LOG_D(...) dbg_log_line(DBG_LOG , __VA_ARGS__) -#define LOG_I(...) dbg_log_line(DBG_INFO , __VA_ARGS__) -#define LOG_W(...) dbg_log_line(DBG_WARNING, __VA_ARGS__) -#define LOG_E(...) dbg_log_line(DBG_ERROR , __VA_ARGS__) #define LOG_RAW(...) dbg_raw(__VA_ARGS__) #endif /* RT_DBG_H__ */ -- cgit v1.3.1 From aa8ff55bbbe751a85fe5e541cb2e297ae1cca6ca Mon Sep 17 00:00:00 2001 From: armink Date: Tue, 11 Sep 2018 18:26:28 +0800 Subject: [rtdbg] Change all level sequence. The most urgent log level (error) using 0. --- include/rtdbg.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/rtdbg.h b/include/rtdbg.h index 13e057bfc4..911a0d8fc9 100644 --- a/include/rtdbg.h +++ b/include/rtdbg.h @@ -54,10 +54,10 @@ #include /* DEBUG level */ -#define DBG_LOG 0 -#define DBG_INFO 1 -#define DBG_WARNING 2 -#define DBG_ERROR 3 +#define DBG_ERROR 0 +#define DBG_WARNING 1 +#define DBG_INFO 2 +#define DBG_LOG 3 #ifndef DBG_SECTION_NAME #define DBG_SECTION_NAME "DBG" @@ -98,7 +98,7 @@ * static debug routine */ #define dbg_log(level, fmt, ...) \ - if ((level) >= DBG_LEVEL) \ + if ((level) <= DBG_LEVEL) \ { \ switch(level) \ { \ @@ -113,13 +113,13 @@ } #define dbg_here \ - if ((DBG_LEVEL) >= DBG_LOG){ \ + if ((DBG_LEVEL) <= DBG_LOG){ \ rt_kprintf(DBG_SECTION_NAME " Here %s:%d\n", \ __FUNCTION__, __LINE__); \ } #define dbg_enter \ - if ((DBG_LEVEL) >= DBG_LOG){ \ + if ((DBG_LEVEL) <= DBG_LOG){ \ _DBG_COLOR(32); \ rt_kprintf(DBG_SECTION_NAME " Enter %s\n", \ __FUNCTION__); \ @@ -127,7 +127,7 @@ } #define dbg_exit \ - if ((DBG_LEVEL) >= DBG_LOG){ \ + if ((DBG_LEVEL) <= DBG_LOG){ \ _DBG_COLOR(32); \ rt_kprintf(DBG_SECTION_NAME " Exit %s:%d\n", \ __FUNCTION__); \ @@ -155,25 +155,25 @@ #define dbg_raw(...) #endif /* DBG_ENABLE */ -#if (DBG_LEVEL <= DBG_LOG) +#if (DBG_LEVEL >= DBG_LOG) #define LOG_D(fmt, ...) dbg_log_line("D", 0, fmt, ##__VA_ARGS__) #else #define LOG_D(...) #endif -#if (DBG_LEVEL <= DBG_INFO) +#if (DBG_LEVEL >= DBG_INFO) #define LOG_I(fmt, ...) dbg_log_line("I", 32, fmt, ##__VA_ARGS__) #else #define LOG_I(...) #endif -#if (DBG_LEVEL <= DBG_WARNING) +#if (DBG_LEVEL >= DBG_WARNING) #define LOG_W(fmt, ...) dbg_log_line("W", 33, fmt, ##__VA_ARGS__) #else #define LOG_W(...) #endif -#if (DBG_LEVEL <= DBG_ERROR) +#if (DBG_LEVEL >= DBG_ERROR) #define LOG_E(fmt, ...) dbg_log_line("E", 31, fmt, ##__VA_ARGS__) #else #define LOG_E(...) -- cgit v1.3.1 From a969b7096fc8e8f2519851ab5023da3854191287 Mon Sep 17 00:00:00 2001 From: armink Date: Tue, 11 Sep 2018 20:05:08 +0800 Subject: [slist] Add rt_slist_tail and rt_slist_tail_entry for slist. --- include/rtservice.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include') diff --git a/include/rtservice.h b/include/rtservice.h index 0bfa424338..77a21d1f97 100644 --- a/include/rtservice.h +++ b/include/rtservice.h @@ -253,6 +253,13 @@ rt_inline rt_slist_t *rt_slist_first(rt_slist_t *l) return l->next; } +rt_inline rt_slist_t *rt_slist_tail(rt_slist_t *l) +{ + while (l->next) l = l->next; + + return l; +} + rt_inline rt_slist_t *rt_slist_next(rt_slist_t *n) { return n->next; @@ -302,6 +309,17 @@ rt_inline int rt_slist_isempty(rt_slist_t *l) #define rt_slist_first_entry(ptr, type, member) \ rt_slist_entry((ptr)->next, type, member) +/** + * rt_slist_tail_entry - get the tail element from a slist + * @ptr: the slist head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the slist_struct within the struct. + * + * Note, that slist is expected to be not empty. + */ +#define rt_slist_tail_entry(ptr, type, member) \ + rt_slist_entry(rt_slist_tail(ptr), type, member) + /*@}*/ #ifdef __cplusplus -- cgit v1.3.1 From 41f7f2c28411472cf99cdedf0abaaab823ba185f Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 14 Sep 2018 22:37:43 +0800 Subject: [Kernel] Update to Apache License v2.0 Update license for RT-Thread kernel. --- include/libc/libc_dirent.h | 6 ++++++ include/libc/libc_errno.h | 22 ++++++---------------- include/libc/libc_fcntl.h | 22 ++++++---------------- include/libc/libc_fdset.h | 22 ++++++---------------- include/libc/libc_ioctl.h | 22 ++++++---------------- include/libc/libc_signal.h | 22 ++++++---------------- include/libc/libc_stat.h | 6 ++++++ include/rtdbg.h | 22 ++++++---------------- include/rtdebug.h | 22 ++++++---------------- include/rtdef.h | 23 +++++++---------------- include/rthw.h | 22 ++++++---------------- include/rtlibc.h | 22 ++++++---------------- include/rtm.h | 22 ++++++---------------- include/rtservice.h | 22 ++++++---------------- include/rtthread.h | 22 ++++++---------------- src/clock.c | 21 ++++++--------------- src/components.c | 22 ++++++---------------- src/device.c | 22 ++++++---------------- src/idle.c | 22 ++++++---------------- src/ipc.c | 22 ++++++---------------- src/irq.c | 22 ++++++---------------- src/kservice.c | 22 ++++++---------------- src/mem.c | 22 ++++++---------------- src/memheap.c | 22 ++++++---------------- src/mempool.c | 22 ++++++---------------- src/object.c | 22 ++++++---------------- src/scheduler.c | 22 ++++++---------------- src/signal.c | 22 ++++++---------------- src/slab.c | 22 ++++++---------------- src/thread.c | 22 ++++++---------------- src/timer.c | 22 ++++++---------------- 31 files changed, 187 insertions(+), 463 deletions(-) (limited to 'include') diff --git a/include/libc/libc_dirent.h b/include/libc/libc_dirent.h index 5bcbc32478..c3a19878ec 100644 --- a/include/libc/libc_dirent.h +++ b/include/libc/libc_dirent.h @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + #ifndef LIBC_DIRENT_H__ #define LIBC_DIRENT_H__ diff --git a/include/libc/libc_errno.h b/include/libc/libc_errno.h index b4f4410595..82ae8cf943 100644 --- a/include/libc/libc_errno.h +++ b/include/libc/libc_errno.h @@ -1,21 +1,11 @@ /* - * File : libc_errno.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2017, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : libc_errno.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_fcntl.h b/include/libc/libc_fcntl.h index 7c5a075a97..1b7c69b1f4 100644 --- a/include/libc/libc_fcntl.h +++ b/include/libc/libc_fcntl.h @@ -1,21 +1,11 @@ /* - * File : libc_fcntl.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2017 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : libc_fcntl.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_fdset.h b/include/libc/libc_fdset.h index 74c4ba1cb2..ecd965cd22 100644 --- a/include/libc/libc_fdset.h +++ b/include/libc/libc_fdset.h @@ -1,21 +1,11 @@ /* - * File : libc_errno.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2017, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : libc_errno.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_ioctl.h b/include/libc/libc_ioctl.h index b61866a524..ef5a5257a8 100644 --- a/include/libc/libc_ioctl.h +++ b/include/libc/libc_ioctl.h @@ -1,21 +1,11 @@ /* - * File : libc_ioctl.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2017, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : libc_ioctl.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h index d3050bfb54..5db43eb35e 100644 --- a/include/libc/libc_signal.h +++ b/include/libc/libc_signal.h @@ -1,21 +1,11 @@ /* - * File : libc_signal.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2017, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : libc_signal.h * * Change Logs: * Date Author Notes diff --git a/include/libc/libc_stat.h b/include/libc/libc_stat.h index 26752393db..9079d1ef15 100644 --- a/include/libc/libc_stat.h +++ b/include/libc/libc_stat.h @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + #ifndef LIBC_STAT_H__ #define LIBC_STAT_H__ diff --git a/include/rtdbg.h b/include/rtdbg.h index 911a0d8fc9..da4eb48303 100644 --- a/include/rtdbg.h +++ b/include/rtdbg.h @@ -1,21 +1,11 @@ /* - * File : rtdbg.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2016, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rtdbg.h * * Change Logs: * Date Author Notes diff --git a/include/rtdebug.h b/include/rtdebug.h index e403d51e06..48f8d2392a 100644 --- a/include/rtdebug.h +++ b/include/rtdebug.h @@ -1,21 +1,11 @@ /* - * File : rtdebug.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rtdebug.h */ #ifndef __RTDEBUG_H__ diff --git a/include/rtdef.h b/include/rtdef.h index 03871d1fcc..9379a7db44 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -1,21 +1,11 @@ /* - * File : rtdef.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rtdef.h * * Change Logs: * Date Author Notes @@ -37,6 +27,7 @@ * 2018-04-25 Bernard change version number to v3.0.4 * 2018-05-31 Bernard change version number to v3.1.0 * 2018-09-04 Bernard change version number to v3.1.1 + * 2018-09-14 Bernard apply Apache License v2.0 to RT-Thread Kernel */ #ifndef __RT_DEF_H__ diff --git a/include/rthw.h b/include/rthw.h index d517228083..8473854538 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -1,21 +1,11 @@ /* - * File : rthw.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rthw.h * * Change Logs: * Date Author Notes diff --git a/include/rtlibc.h b/include/rtlibc.h index db5236edb1..385d57500e 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -1,21 +1,11 @@ /* - * File : rtlibc.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2017, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rtlibc.h * * Change Logs: * Date Author Notes diff --git a/include/rtm.h b/include/rtm.h index 05419e4420..08ad721baf 100644 --- a/include/rtm.h +++ b/include/rtm.h @@ -1,21 +1,11 @@ /* - * File : rtm.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rtm.h */ #ifndef __RTM_H__ diff --git a/include/rtservice.h b/include/rtservice.h index 77a21d1f97..145a225ace 100644 --- a/include/rtservice.h +++ b/include/rtservice.h @@ -1,21 +1,11 @@ /* - * File : rtservice.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rtservice.h * * Change Logs: * Date Author Notes diff --git a/include/rtthread.h b/include/rtthread.h index 4114866f6f..82d975d648 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -1,21 +1,11 @@ /* - * File : rtthread.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : rtthread.h * * Change Logs: * Date Author Notes diff --git a/src/clock.c b/src/clock.c index 734c0d5014..9834f0f95c 100644 --- a/src/clock.c +++ b/src/clock.c @@ -1,21 +1,12 @@ /* - * File : clock.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * SPDX-License-Identifier: Apache-2.0 * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * File : clock.c * * Change Logs: * Date Author Notes diff --git a/src/components.c b/src/components.c index 818e570b3c..410b20be93 100644 --- a/src/components.c +++ b/src/components.c @@ -1,21 +1,11 @@ /* - * File : init.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2012 - 2015, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : init.c * * Change Logs: * Date Author Notes diff --git a/src/device.c b/src/device.c index 0b662ae620..94f550d682 100644 --- a/src/device.c +++ b/src/device.c @@ -1,21 +1,11 @@ /* - * File : device.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : device.c * * Change Logs: * Date Author Notes diff --git a/src/idle.c b/src/idle.c index 1aca33d3e4..8a4734ab49 100644 --- a/src/idle.c +++ b/src/idle.c @@ -1,21 +1,11 @@ /* - * File : idle.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : idle.c * * Change Logs: * Date Author Notes diff --git a/src/ipc.c b/src/ipc.c index b1a5dbe402..d2a3ba766c 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1,21 +1,11 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* * File : ipc.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Change Logs: * Date Author Notes diff --git a/src/irq.c b/src/irq.c index 9b933e3960..98a6fd3a04 100644 --- a/src/irq.c +++ b/src/irq.c @@ -1,21 +1,11 @@ /* - * File : irq.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : irq.c * * Change Logs: * Date Author Notes diff --git a/src/kservice.c b/src/kservice.c index 35444aa248..a31e5a6f93 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1,21 +1,11 @@ /* - * File : kservice.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : kservice.c * * Change Logs: * Date Author Notes diff --git a/src/mem.c b/src/mem.c index 324a5f8f64..03e6f34eb4 100644 --- a/src/mem.c +++ b/src/mem.c @@ -1,21 +1,11 @@ /* - * File : mem.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : mem.c * * Change Logs: * Date Author Notes diff --git a/src/memheap.c b/src/memheap.c index de637f2685..946f163b64 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -1,21 +1,11 @@ /* - * File : memheap.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : memheap.c * * Change Logs: * Date Author Notes diff --git a/src/mempool.c b/src/mempool.c index cd98e8c14e..e1af7d9e42 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -1,21 +1,11 @@ /* - * File : mempool.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : mempool.c * * Change Logs: * Date Author Notes diff --git a/src/object.c b/src/object.c index e9a2b99246..8dcfb2e57e 100644 --- a/src/object.c +++ b/src/object.c @@ -1,21 +1,11 @@ /* - * File : object.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : object.c * * Change Logs: * Date Author Notes diff --git a/src/scheduler.c b/src/scheduler.c index 1be1816bc2..8b5ffc9f4c 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1,21 +1,11 @@ /* - * File : scheduler.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : scheduler.c * * Change Logs: * Date Author Notes diff --git a/src/signal.c b/src/signal.c index b2193957bc..6499d05a97 100644 --- a/src/signal.c +++ b/src/signal.c @@ -1,21 +1,11 @@ /* - * File : signal.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : signal.c * * Change Logs: * Date Author Notes diff --git a/src/slab.c b/src/slab.c index 16c68a2408..bf26c84cca 100644 --- a/src/slab.c +++ b/src/slab.c @@ -1,21 +1,11 @@ /* - * File : slab.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : slab.c * * Change Logs: * Date Author Notes diff --git a/src/thread.c b/src/thread.c index 7febf32082..249219b8aa 100644 --- a/src/thread.c +++ b/src/thread.c @@ -1,21 +1,11 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* * File : thread.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Change Logs: * Date Author Notes diff --git a/src/timer.c b/src/timer.c index 042826f41b..01e6211e04 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,21 +1,11 @@ /* - * File : timer.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Copyright (c) 2006-2018, RT-Thread Development Team * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * File : timer.c * * Change Logs: * Date Author Notes -- cgit v1.3.1 From b98a0ba804f388f531106ff9602eb22ee66fe751 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 23 Sep 2018 12:08:44 +0800 Subject: [Kernel] Add ARMCC 6.x support. --- components/finsh/shell.c | 8 +++----- components/libc/compilers/armlibc/mem_std.c | 3 +++ components/libc/compilers/armlibc/stubs.c | 4 ++++ components/net/lwip-2.0.2/src/arch/include/arch/cc.h | 2 +- include/libc/libc_signal.h | 2 +- include/rtdef.h | 9 +++++++-- include/rtlibc.h | 2 +- include/rtthread.h | 2 +- libcpu/arm/cortex-m4/cpuport.c | 11 ++++++++--- libcpu/arm/cortex-m7/cpuport.c | 11 ++++++++--- src/components.c | 4 ++-- src/kservice.c | 2 +- 12 files changed, 40 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/components/finsh/shell.c b/components/finsh/shell.c index ccd5b97306..441f6c3241 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -55,7 +55,9 @@ static struct rt_thread finsh_thread; ALIGN(RT_ALIGN_SIZE) static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE]; +struct finsh_shell _shell; #endif + struct finsh_shell *shell; static char *finsh_prompt_custom = RT_NULL; @@ -473,9 +475,6 @@ static void shell_push_history(struct finsh_shell *shell) } #endif -#ifndef RT_USING_HEAP -struct finsh_shell _shell; -#endif void finsh_thread_entry(void *parameter) { char ch; @@ -792,7 +791,7 @@ int finsh_system_init(void) rt_thread_t tid; #ifdef FINSH_USING_SYMTAB -#ifdef __CC_ARM /* ARM C Compiler */ +#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM C Compiler */ extern const int FSymTab$$Base; extern const int FSymTab$$Limit; extern const int VSymTab$$Base; @@ -867,4 +866,3 @@ int finsh_system_init(void) return 0; } INIT_APP_EXPORT(finsh_system_init); - diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c index 138ebe9773..4393b5f2af 100644 --- a/components/libc/compilers/armlibc/mem_std.c +++ b/components/libc/compilers/armlibc/mem_std.c @@ -16,8 +16,11 @@ #include "rtthread.h" #ifdef RT_USING_HEAP + +#ifdef __CC_ARM /* avoid the heap and heap-using library functions supplied by arm */ #pragma import(__use_no_heap) +#endif void *malloc(size_t n) { diff --git a/components/libc/compilers/armlibc/stubs.c b/components/libc/compilers/armlibc/stubs.c index b292cd7629..c826c8a0ec 100644 --- a/components/libc/compilers/armlibc/stubs.c +++ b/components/libc/compilers/armlibc/stubs.c @@ -37,7 +37,11 @@ #include "dfs_posix.h" #endif +#ifdef __CLANG_ARM +__asm(".global __use_no_semihosting\n\t"); +#else #pragma import(__use_no_semihosting_swi) +#endif /* Standard IO device handles. */ #define STDIN 0 diff --git a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h index 1875d9ab00..77a589276a 100644 --- a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h +++ b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h @@ -46,7 +46,7 @@ #define X32_F "lx" #ifdef RT_USING_LIBC -#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) +#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) #include #else #include diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h index 5db43eb35e..b592b8227e 100644 --- a/include/libc/libc_signal.h +++ b/include/libc/libc_signal.h @@ -71,7 +71,7 @@ typedef struct siginfo siginfo_t; #include #endif -#ifdef __CC_ARM +#if defined(__CC_ARM) || defined(__CLANG_ARM) #include typedef unsigned long sigset_t; diff --git a/include/rtdef.h b/include/rtdef.h index 9379a7db44..92b997151d 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -88,14 +88,19 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_UINT32_MAX 0xffffffff /**< Maxium number of UINT32 */ #define RT_TICK_MAX RT_UINT32_MAX /**< Maxium number of tick */ +#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) +#define __CLANG_ARM +#endif + /* Compiler Related Definitions */ -#ifdef __CC_ARM /* ARM Compiler */ +#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */ #include #define SECTION(x) __attribute__((section(x))) #define RT_UNUSED __attribute__((unused)) #define RT_USED __attribute__((used)) #define ALIGN(n) __attribute__((aligned(n))) - #define RT_WEAK __weak + + #define RT_WEAK __attribute__((weak)) #define rt_inline static __inline /* module compiling */ #ifdef RT_USING_MODULE diff --git a/include/rtlibc.h b/include/rtlibc.h index 385d57500e..020c34764e 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -25,7 +25,7 @@ #include "libc/libc_signal.h" #include "libc/libc_fdset.h" -#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) +#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__IAR_SYSTEMS_ICC__) typedef signed long off_t; typedef int mode_t; #endif diff --git a/include/rtthread.h b/include/rtthread.h index 82d975d648..f8da2d46bf 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -501,7 +501,7 @@ rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count); rt_int32_t rt_strcmp(const char *cs, const char *ct); rt_size_t rt_strlen(const char *src); char *rt_strdup(const char *s); -#ifdef __CC_ARM +#if defined(__CC_ARM) || defined(__CLANG_ARM) /* leak strdup interface */ char* strdup(const char* str); #endif diff --git a/libcpu/arm/cortex-m4/cpuport.c b/libcpu/arm/cortex-m4/cpuport.c index ed7102f844..1d2184c2d7 100644 --- a/libcpu/arm/cortex-m4/cpuport.c +++ b/libcpu/arm/cortex-m4/cpuport.c @@ -22,9 +22,14 @@ #include -#define USE_FPU /* ARMCC */ ( (defined ( __CC_ARM ) && defined ( __TARGET_FPU_VFP )) \ - /* IAR */ || (defined ( __ICCARM__ ) && defined ( __ARMVFP__ )) \ +#if /* ARMCC */ ( (defined ( __CC_ARM ) && defined ( __TARGET_FPU_VFP )) \ + /* Clang */ || (defined ( __CLANG_ARM ) && defined ( __TARGET_FPU_VFP )) \ + /* IAR */ || (defined ( __ICCARM__ ) && defined ( __ARMVFP__ )) \ /* GNU */ || (defined ( __GNUC__ ) && defined ( __VFP_FP__ ) && !defined(__SOFTFP__)) ) +#define USE_FPU 1 +#else +#define USE_FPU 0 +#endif /* exception and interrupt handler table */ rt_uint32_t rt_interrupt_from_thread; @@ -452,7 +457,7 @@ RT_WEAK void rt_hw_cpu_reset(void) * @return return the index of the first bit set. If value is 0, then this function * shall return 0. */ -#if defined(__CC_ARM) +#if defined(__CC_ARM) || defined(__CLANG_ARM) __asm int __rt_ffs(int value) { CMP r0, #0x00 diff --git a/libcpu/arm/cortex-m7/cpuport.c b/libcpu/arm/cortex-m7/cpuport.c index ed7102f844..1d2184c2d7 100644 --- a/libcpu/arm/cortex-m7/cpuport.c +++ b/libcpu/arm/cortex-m7/cpuport.c @@ -22,9 +22,14 @@ #include -#define USE_FPU /* ARMCC */ ( (defined ( __CC_ARM ) && defined ( __TARGET_FPU_VFP )) \ - /* IAR */ || (defined ( __ICCARM__ ) && defined ( __ARMVFP__ )) \ +#if /* ARMCC */ ( (defined ( __CC_ARM ) && defined ( __TARGET_FPU_VFP )) \ + /* Clang */ || (defined ( __CLANG_ARM ) && defined ( __TARGET_FPU_VFP )) \ + /* IAR */ || (defined ( __ICCARM__ ) && defined ( __ARMVFP__ )) \ /* GNU */ || (defined ( __GNUC__ ) && defined ( __VFP_FP__ ) && !defined(__SOFTFP__)) ) +#define USE_FPU 1 +#else +#define USE_FPU 0 +#endif /* exception and interrupt handler table */ rt_uint32_t rt_interrupt_from_thread; @@ -452,7 +457,7 @@ RT_WEAK void rt_hw_cpu_reset(void) * @return return the index of the first bit set. If value is 0, then this function * shall return 0. */ -#if defined(__CC_ARM) +#if defined(__CC_ARM) || defined(__CLANG_ARM) __asm int __rt_ffs(int value) { CMP r0, #0x00 diff --git a/src/components.c b/src/components.c index 410b20be93..09f0680b55 100644 --- a/src/components.c +++ b/src/components.c @@ -136,7 +136,7 @@ void rt_application_init(void); void rt_hw_board_init(void); int rtthread_startup(void); -#if defined (__CC_ARM) +#if defined(__CC_ARM) || defined(__CLANG_ARM) extern int $Super$$main(void); /* re-define main function */ int $Sub$$main(void) @@ -185,7 +185,7 @@ void main_thread_entry(void *parameter) rt_components_init(); /* invoke system main function */ -#if defined (__CC_ARM) +#if defined(__CC_ARM) || defined(__CLANG_ARM) $Super$$main(); /* for ARMCC. */ #elif defined(__ICCARM__) || defined(__GNUC__) main(); diff --git a/src/kservice.c b/src/kservice.c index a31e5a6f93..e10c093c70 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -525,7 +525,7 @@ char *rt_strdup(const char *s) return tmp; } RTM_EXPORT(rt_strdup); -#ifdef __CC_ARM +#if defined(__CC_ARM) || defined(__CLANG_ARM) char *strdup(const char *s) __attribute__((alias("rt_strdup"))); #endif #endif -- cgit v1.3.1 From 20bc91d25fd97b3136d26aa6339c6648db0e9e1c Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 14 Oct 2018 19:38:52 +0800 Subject: [license] Change license to Apache. --- include/rtdbg.h | 4 ---- include/rtdebug.h | 4 ---- include/rtdef.h | 4 ---- include/rthw.h | 4 ---- include/rtlibc.h | 4 ---- include/rtm.h | 4 ---- include/rtservice.h | 4 ---- include/rtthread.h | 4 ---- 8 files changed, 32 deletions(-) (limited to 'include') diff --git a/include/rtdbg.h b/include/rtdbg.h index da4eb48303..d19a191227 100644 --- a/include/rtdbg.h +++ b/include/rtdbg.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : rtdbg.h * * Change Logs: * Date Author Notes diff --git a/include/rtdebug.h b/include/rtdebug.h index 48f8d2392a..b66cd6fc69 100644 --- a/include/rtdebug.h +++ b/include/rtdebug.h @@ -4,10 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -/* - * File : rtdebug.h - */ - #ifndef __RTDEBUG_H__ #define __RTDEBUG_H__ diff --git a/include/rtdef.h b/include/rtdef.h index 92b997151d..deb3295e27 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : rtdef.h * * Change Logs: * Date Author Notes diff --git a/include/rthw.h b/include/rthw.h index 8473854538..c6af392e62 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : rthw.h * * Change Logs: * Date Author Notes diff --git a/include/rtlibc.h b/include/rtlibc.h index 020c34764e..b3a548beb1 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : rtlibc.h * * Change Logs: * Date Author Notes diff --git a/include/rtm.h b/include/rtm.h index 08ad721baf..7e07a2239c 100644 --- a/include/rtm.h +++ b/include/rtm.h @@ -4,10 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -/* - * File : rtm.h - */ - #ifndef __RTM_H__ #define __RTM_H__ diff --git a/include/rtservice.h b/include/rtservice.h index 145a225ace..3b6fc94c92 100644 --- a/include/rtservice.h +++ b/include/rtservice.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : rtservice.h * * Change Logs: * Date Author Notes diff --git a/include/rtthread.h b/include/rtthread.h index f8da2d46bf..fc5029a220 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -2,10 +2,6 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * File : rtthread.h * * Change Logs: * Date Author Notes -- cgit v1.3.1 From 29dd96ec351919a3eca34729335c4d1ded637c43 Mon Sep 17 00:00:00 2001 From: armink Date: Wed, 31 Oct 2018 10:57:52 +0800 Subject: [rtdbg] Add ulog compatible with rtdbg. --- include/rtdbg.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/rtdbg.h b/include/rtdbg.h index d19a191227..9036a0cd66 100644 --- a/include/rtdbg.h +++ b/include/rtdbg.h @@ -23,10 +23,7 @@ * #define DBG_LEVEL DBG_INFO * #include // must after of DEBUG_ENABLE or some other options * - * Then in your C/C++ file, you can use dbg_log macro to print out logs: - * dbg_log(DBG_INFO, "this is a log!\n"); - * - * Or if you want to using the simple API, you can + * Then in your C/C++ file, you can use LOG_X macro to print out logs: * LOG_D("this is a debug log!"); * LOG_E("this is a error log!"); * @@ -39,6 +36,11 @@ #include +#if defined(RT_USING_ULOG) && defined(DBG_ENABLE) +/* using ulog compatible with rtdbg */ +#include +#else + /* DEBUG level */ #define DBG_ERROR 0 #define DBG_WARNING 1 @@ -82,6 +84,8 @@ /* * static debug routine + * NOTE: This is a NOT RECOMMENDED API. Please using LOG_X API. + * It will be DISCARDED later. Because it will take up more resources. */ #define dbg_log(level, fmt, ...) \ if ((level) <= DBG_LEVEL) \ @@ -167,4 +171,6 @@ #define LOG_RAW(...) dbg_raw(__VA_ARGS__) +#endif /* defined(RT_USING_ULOG) && define(DBG_ENABLE) */ + #endif /* RT_DBG_H__ */ -- cgit v1.3.1 From e108dfe4a521355c454cf4d61b4297840264080b Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 10 Nov 2018 16:58:07 +0800 Subject: [libc] Fix the _EXFUN issue in newlib --- components/dfs/include/dfs_posix.h | 4 +++- components/dfs/src/dfs_posix.c | 4 ++-- include/libc/libc_signal.h | 18 +++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index 79607fc8b4..bc8ff1c698 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -41,13 +41,15 @@ int closedir(DIR* d); /* file api*/ int open(const char *file, int flags, ...); int close(int d); -#ifdef RT_USING_NEWLIB + +#if defined(RT_USING_NEWLIB) && defined(_EXFUN) _READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte)); _READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte)); #else int read(int fd, void *buf, size_t len); int write(int fd, const void *buf, size_t len); #endif + off_t lseek(int fd, off_t offset, int whence); int rename(const char *from, const char *to); int unlink(const char *pathname); diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 59acde1f8c..97531ad59c 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -110,7 +110,7 @@ RTM_EXPORT(close); * @return the actual read data buffer length. If the returned value is 0, it * may be reach the end of file, please check errno. */ -#ifdef RT_USING_NEWLIB +#if defined(RT_USING_NEWLIB) && defined(_EXFUN) _READ_WRITE_RETURN_TYPE _EXFUN(read, (int fd, void *buf, size_t len)) #else int read(int fd, void *buf, size_t len) @@ -154,7 +154,7 @@ RTM_EXPORT(read); * * @return the actual written data buffer length. */ -#ifdef RT_USING_NEWLIB +#if defined(RT_USING_NEWLIB) && defined(_EXFUN) _READ_WRITE_RETURN_TYPE _EXFUN(write, (int fd, const void *buf, size_t len)) #else int write(int fd, const void *buf, size_t len) diff --git a/include/libc/libc_signal.h b/include/libc/libc_signal.h index b592b8227e..61a7e445e9 100644 --- a/include/libc/libc_signal.h +++ b/include/libc/libc_signal.h @@ -76,20 +76,20 @@ typedef struct siginfo siginfo_t; typedef unsigned long sigset_t; #define SIGHUP 1 -// #define SIGINT 2 +/* #define SIGINT 2 */ #define SIGQUIT 3 -// #define SIGILL 4 +/* #define SIGILL 4 */ #define SIGTRAP 5 -// #define SIGABRT 6 +/* #define SIGABRT 6 */ #define SIGEMT 7 -// #define SIGFPE 8 +/* #define SIGFPE 8 */ #define SIGKILL 9 #define SIGBUS 10 -// #define SIGSEGV 11 +/* #define SIGSEGV 11 */ #define SIGSYS 12 #define SIGPIPE 13 #define SIGALRM 14 -// #define SIGTERM 15 +/* #define SIGTERM 15 */ #define SIGURG 16 #define SIGSTOP 17 #define SIGTSTP 18 @@ -99,8 +99,8 @@ typedef unsigned long sigset_t; #define SIGTTOU 22 #define SIGPOLL 23 #define SIGWINCH 24 -// #define SIGUSR1 25 -// #define SIGUSR2 26 +/* #define SIGUSR1 25 */ +/* #define SIGUSR2 26 */ #define SIGRTMIN 27 #define SIGRTMAX 31 #define NSIG 32 @@ -136,7 +136,7 @@ typedef unsigned long sigset_t; #define SIGQUIT 3 #define SIGILL 4 #define SIGTRAP 5 -// #define SIGABRT 6 +/* #define SIGABRT 6 */ #define SIGEMT 7 #define SIGFPE 8 #define SIGKILL 9 -- cgit v1.3.1 From d343c6578a0c12c4bdc98e7634907fb9779ba0d7 Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Tue, 13 Nov 2018 11:32:01 +0800 Subject: [kernel]Change 'rt_timer_timeout_hook' function to 'rt_timer_enter_hook' and add 'rt_timer_exit_hook' hook function. --- include/rtthread.h | 3 ++- src/timer.c | 28 +++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/rtthread.h b/include/rtthread.h index fc5029a220..96ebe1940a 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -100,7 +100,8 @@ rt_tick_t rt_timer_next_timeout_tick(void); void rt_timer_check(void); #ifdef RT_USING_HOOK -void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer)); +void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)); +void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)); #endif /**@}*/ diff --git a/src/timer.c b/src/timer.c index dc489a2d0d..fd938065db 100644 --- a/src/timer.c +++ b/src/timer.c @@ -43,7 +43,8 @@ static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE]; #ifdef RT_USING_HOOK extern void (*rt_object_take_hook)(struct rt_object *object); extern void (*rt_object_put_hook)(struct rt_object *object); -static void (*rt_timer_timeout_hook)(struct rt_timer *timer); +static void (*rt_timer_enter_hook)(struct rt_timer *timer); +static void (*rt_timer_exit_hook)(struct rt_timer *timer); /** * @addtogroup Hook @@ -52,14 +53,25 @@ static void (*rt_timer_timeout_hook)(struct rt_timer *timer); /**@{*/ /** - * This function will set a hook function, which will be invoked when timer - * is timeout. + * This function will set a hook function, which will be invoked when enter + * timer timeout callback function. * * @param hook the hook function */ -void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer)) +void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer)) { - rt_timer_timeout_hook = hook; + rt_timer_enter_hook = hook; +} + +/** + * This function will set a hook function, which will be invoked when exit + * timer timeout callback function. + * + * @param hook the hook function + */ +void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer)) +{ + rt_timer_exit_hook = hook; } /**@}*/ @@ -503,7 +515,7 @@ void rt_timer_check(void) */ if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2) { - RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t)); + RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* remove timer from timer list firstly */ _rt_timer_remove(t); @@ -514,6 +526,7 @@ void rt_timer_check(void) /* re-get tick */ current_tick = rt_tick_get(); + RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) && @@ -578,7 +591,7 @@ void rt_soft_timer_check(void) */ if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2) { - RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t)); + RT_OBJECT_HOOK_CALL(rt_timer_enter_hook, (t)); /* move node to the next */ n = n->next; @@ -594,6 +607,7 @@ void rt_soft_timer_check(void) /* re-get tick */ current_tick = rt_tick_get(); + RT_OBJECT_HOOK_CALL(rt_timer_exit_hook, (t)); RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick)); /* lock scheduler */ -- cgit v1.3.1