From 75063a1b5e519d27485dac77590d46f626354ea2 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 25 Nov 2021 15:31:43 +0800 Subject: [timer] update the RT_TIMER_CTRL_GET_STATE code in rt_timer_control --- src/timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 25ba175306..846c33263b 100644 --- a/src/timer.c +++ b/src/timer.c @@ -560,12 +560,12 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg) if(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) { /*timer is start and run*/ - *(rt_tick_t *)arg = RT_TIMER_FLAG_ACTIVATED; + *(rt_uint32_t *)arg = RT_TIMER_FLAG_ACTIVATED; } else { /*timer is stop*/ - *(rt_tick_t *)arg = RT_TIMER_FLAG_DEACTIVATED; + *(rt_uint32_t *)arg = RT_TIMER_FLAG_DEACTIVATED; } break; -- cgit v1.3.1 From 6a863ef65cbdd3bb12404e9871b391a3bcdc0984 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 27 Nov 2021 18:25:33 -0500 Subject: [kservice] 优化RT_PRINTF_LONGLONG,减少重复代码 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Kconfig | 10 +++++----- src/kservice.c | 29 +++++++++++------------------ 2 files changed, 16 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/Kconfig b/src/Kconfig index 427a65eb74..a11cb856cf 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -144,7 +144,11 @@ config RT_USING_ASM_MEMSET default n config RT_USING_TINY_FFS - bool "Enable kservice to use tiny ffs" + bool "Enable kservice to use tiny finding first bit set method" + default n + +config RT_PRINTF_LONGLONG + bool "Enable rt_xprintf functions to support long long format" default n endmenu @@ -375,10 +379,6 @@ menu "Kernel Device Object" config RT_CONSOLE_DEVICE_NAME string "the device name for console" default "uart" - - config RT_PRINTF_LONGLONG - bool "rt_kprintf support long long" - default n endif endmenu diff --git a/src/kservice.c b/src/kservice.c index aa5b39075c..5e877e5d2a 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -593,7 +593,6 @@ RTM_EXPORT(rt_show_version); /* private function */ #define _ISDIGIT(c) ((unsigned)((c) - '0') < 10) -#ifdef RT_PRINTF_LONGLONG /** * This function will duplicate a string. * @@ -603,44 +602,38 @@ RTM_EXPORT(rt_show_version); * * @return the duplicated string pointer. */ +#ifdef RT_PRINTF_LONGLONG rt_inline int divide(long long *n, int base) +#else +rt_inline int divide(long *n, int base) +#endif /* RT_PRINTF_LONGLONG */ { int res; /* optimized for processor which does not support divide instructions. */ if (base == 10) { +#ifdef RT_PRINTF_LONGLONG res = (int)(((unsigned long long)*n) % 10U); *n = (long long)(((unsigned long long)*n) / 10U); - } - else - { - res = (int)(((unsigned long long)*n) % 16U); - *n = (long long)(((unsigned long long)*n) / 16U); - } - - return res; -} #else -rt_inline int divide(long *n, int base) -{ - int res; - - /* optimized for processor which does not support divide instructions. */ - if (base == 10) - { res = (int)(((unsigned long)*n) % 10U); *n = (long)(((unsigned long)*n) / 10U); +#endif } else { +#ifdef RT_PRINTF_LONGLONG + res = (int)(((unsigned long long)*n) % 16U); + *n = (long long)(((unsigned long long)*n) / 16U); +#else res = (int)(((unsigned long)*n) % 16U); *n = (long)(((unsigned long)*n) / 16U); +#endif } return res; } -#endif /* RT_PRINTF_LONGLONG */ rt_inline int skip_atoi(const char **s) { -- cgit v1.3.1 From e13230ba7297eda36891bf8cc2f8436a09db46d8 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 27 Nov 2021 18:34:44 -0500 Subject: [kernel] 整理Kconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Kconfig | 220 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 110 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/Kconfig b/src/Kconfig index a11cb856cf..1a52f33b53 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -115,41 +115,40 @@ config RT_USING_TIMER_SOFT thread. if RT_USING_TIMER_SOFT -config RT_TIMER_THREAD_PRIO - int "The priority level value of timer thread" - default 4 - -config RT_TIMER_THREAD_STACK_SIZE - int "The stack size of timer thread" - default 512 + config RT_TIMER_THREAD_PRIO + int "The priority level value of timer thread" + default 4 + config RT_TIMER_THREAD_STACK_SIZE + int "The stack size of timer thread" + default 512 endif menu "kservice optimization" -config RT_KSERVICE_USING_STDLIB - bool "Enable kservice to use standard C library" - default n + config RT_KSERVICE_USING_STDLIB + bool "Enable kservice to use standard C library" + default n -config RT_KSERVICE_USING_TINY_SIZE - bool "Enable kservice to use tiny size" - default n + config RT_KSERVICE_USING_TINY_SIZE + bool "Enable kservice to use tiny size" + default n -config RT_USING_ASM_MEMCPY - bool - default n + config RT_USING_ASM_MEMCPY + bool + default n -config RT_USING_ASM_MEMSET - bool - default n + config RT_USING_ASM_MEMSET + bool + default n -config RT_USING_TINY_FFS - bool "Enable kservice to use tiny finding first bit set method" - default n + config RT_USING_TINY_FFS + bool "Enable kservice to use tiny finding first bit set method" + default n -config RT_PRINTF_LONGLONG - bool "Enable rt_xprintf functions to support long long format" - default n + config RT_PRINTF_LONGLONG + bool "Enable rt_xprintf functions to support long long format" + default n endmenu @@ -159,121 +158,122 @@ menuconfig RT_DEBUG if RT_DEBUG -config RT_DEBUG_COLOR - bool "Enable color debugging log" - default n + config RT_DEBUG_COLOR + bool "Enable color debugging log" + default n -config RT_DEBUG_INIT_CONFIG - bool "Enable debugging of components initialization" - default n + config RT_DEBUG_INIT_CONFIG + bool "Enable debugging of components initialization" + default n -config RT_DEBUG_INIT - int - default 1 if RT_DEBUG_INIT_CONFIG + config RT_DEBUG_INIT + int + default 1 if RT_DEBUG_INIT_CONFIG -config RT_DEBUG_THREAD_CONFIG - bool "Enable debugging of Thread State Changes" - default n + config RT_DEBUG_THREAD_CONFIG + bool "Enable debugging of Thread State Changes" + default n -config RT_DEBUG_THREAD - int - default 1 if RT_DEBUG_THREAD_CONFIG + config RT_DEBUG_THREAD + int + default 1 if RT_DEBUG_THREAD_CONFIG -config RT_DEBUG_SCHEDULER_CONFIG - bool "Enable debugging of Scheduler" - default n + config RT_DEBUG_SCHEDULER_CONFIG + bool "Enable debugging of Scheduler" + default n -config RT_DEBUG_SCHEDULER - int - default 1 if RT_DEBUG_SCHEDULER_CONFIG + config RT_DEBUG_SCHEDULER + int + default 1 if RT_DEBUG_SCHEDULER_CONFIG -config RT_DEBUG_IPC_CONFIG - bool "Enable debugging of IPC" - default n + config RT_DEBUG_IPC_CONFIG + bool "Enable debugging of IPC" + default n -config RT_DEBUG_IPC - int - default 1 if RT_DEBUG_IPC_CONFIG + config RT_DEBUG_IPC + int + default 1 if RT_DEBUG_IPC_CONFIG -config RT_DEBUG_TIMER_CONFIG - bool "Enable debugging of Timer" - default n + config RT_DEBUG_TIMER_CONFIG + bool "Enable debugging of Timer" + default n -config RT_DEBUG_TIMER - int - default 1 if RT_DEBUG_TIMER_CONFIG + config RT_DEBUG_TIMER + int + default 1 if RT_DEBUG_TIMER_CONFIG -config RT_DEBUG_IRQ_CONFIG - bool "Enable debugging of IRQ(Interrupt Request)" - default n + config RT_DEBUG_IRQ_CONFIG + bool "Enable debugging of IRQ(Interrupt Request)" + default n -config RT_DEBUG_IRQ - int - default 1 if RT_DEBUG_IRQ_CONFIG + config RT_DEBUG_IRQ + int + default 1 if RT_DEBUG_IRQ_CONFIG -config RT_DEBUG_MEM_CONFIG - bool "Enable debugging of Small Memory Algorithm" - default n + config RT_DEBUG_MEM_CONFIG + bool "Enable debugging of Small Memory Algorithm" + default n -config RT_DEBUG_MEM - int - default 1 if RT_DEBUG_MEM_CONFIG + config RT_DEBUG_MEM + int + default 1 if RT_DEBUG_MEM_CONFIG -config RT_DEBUG_SLAB_CONFIG - bool "Enable debugging of SLAB Memory Algorithm" - default n + config RT_DEBUG_SLAB_CONFIG + bool "Enable debugging of SLAB Memory Algorithm" + default n -config RT_DEBUG_SLAB - int - default 1 if RT_DEBUG_SLAB_CONFIG + config RT_DEBUG_SLAB + int + default 1 if RT_DEBUG_SLAB_CONFIG -config RT_DEBUG_MEMHEAP_CONFIG - bool "Enable debugging of Memory Heap Algorithm" - default n + config RT_DEBUG_MEMHEAP_CONFIG + bool "Enable debugging of Memory Heap Algorithm" + default n -config RT_DEBUG_MEMHEAP - int - default 1 if RT_DEBUG_MEMHEAP_CONFIG + config RT_DEBUG_MEMHEAP + int + default 1 if RT_DEBUG_MEMHEAP_CONFIG -config RT_DEBUG_MODULE_CONFIG - bool "Enable debugging of Application Module" - default n + config RT_DEBUG_MODULE_CONFIG + bool "Enable debugging of Application Module" + default n -config RT_DEBUG_MODULE - int - default 1 if RT_DEBUG_MODULE_CONFIG + config RT_DEBUG_MODULE + int + default 1 if RT_DEBUG_MODULE_CONFIG endif menu "Inter-Thread communication" -config RT_USING_SEMAPHORE - bool "Enable semaphore" - default y + config RT_USING_SEMAPHORE + bool "Enable semaphore" + default y -config RT_USING_MUTEX - bool "Enable mutex" - default y + config RT_USING_MUTEX + bool "Enable mutex" + default y -config RT_USING_EVENT - bool "Enable event flag" - default y + config RT_USING_EVENT + bool "Enable event flag" + default y -config RT_USING_MAILBOX - bool "Enable mailbox" - default y + config RT_USING_MAILBOX + bool "Enable mailbox" + default y -config RT_USING_MESSAGEQUEUE - bool "Enable message queue" - default y + config RT_USING_MESSAGEQUEUE + bool "Enable message queue" + default y + + config RT_USING_SIGNALS + bool "Enable signals" + select RT_USING_MEMPOOL + default n + help + A signal is an asynchronous notification sent to a specific thread + in order to notify it of an event that occurred. -config RT_USING_SIGNALS - bool "Enable signals" - select RT_USING_MEMPOOL - default n - help - A signal is an asynchronous notification sent to a specific thread - in order to notify it of an event that occurred. endmenu menu "Memory Management" -- cgit v1.3.1 From 2d505d8ffd482dfe7b5416a593ceff6ab341f989 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 27 Nov 2021 19:40:52 -0500 Subject: [kservice] 精简RT_PRINTF_PRECISION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Kconfig | 2 +- src/kservice.c | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Kconfig b/src/Kconfig index 1a52f33b53..8647d35698 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -147,7 +147,7 @@ menu "kservice optimization" default n config RT_PRINTF_LONGLONG - bool "Enable rt_xprintf functions to support long long format" + bool "Enable rt_printf-family functions to support long long format" default n endmenu diff --git a/src/kservice.c b/src/kservice.c index 5e877e5d2a..8b959cbd68 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -652,7 +652,6 @@ rt_inline int skip_atoi(const char **s) #define SPECIAL (1 << 5) /* 0x */ #define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */ -#ifdef RT_PRINTF_PRECISION static char *print_number(char *buf, char *end, #ifdef RT_PRINTF_LONGLONG @@ -662,20 +661,10 @@ static char *print_number(char *buf, #endif /* RT_PRINTF_LONGLONG */ int base, int s, +#ifdef RT_PRINTF_PRECISION int precision, - int type) -#else -static char *print_number(char *buf, - char *end, -#ifdef RT_PRINTF_LONGLONG - long long num, -#else - long num, -#endif /* RT_PRINTF_LONGLONG */ - int base, - int s, - int type) #endif /* RT_PRINTF_PRECISION */ + int type) { char c, sign; #ifdef RT_PRINTF_LONGLONG -- cgit v1.3.1 From efbdbc2636abf25d0836d58a666b91d61b99bf80 Mon Sep 17 00:00:00 2001 From: GuEe-GUI <2991707448@qq.com> Date: Tue, 30 Nov 2021 10:32:23 +0800 Subject: fixup .bss size define in link.lds and set spsel=1 in aarch64 --- bsp/qemu-virt64-aarch64/link.lds | 2 +- bsp/raspberry-pi/raspi3-64/link.lds | 2 +- bsp/raspberry-pi/raspi4-64/link.lds | 2 +- libcpu/aarch64/common/context_gcc.S | 39 +++++++++++++---------------------- libcpu/aarch64/common/stack.c | 7 ++++--- libcpu/aarch64/common/vector_gcc.S | 2 +- libcpu/aarch64/cortex-a/entry_point.S | 19 +++++++++-------- src/thread.c | 1 + 8 files changed, 33 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/bsp/qemu-virt64-aarch64/link.lds b/bsp/qemu-virt64-aarch64/link.lds index 2344d96e3b..9d1ece0010 100644 --- a/bsp/qemu-virt64-aarch64/link.lds +++ b/bsp/qemu-virt64-aarch64/link.lds @@ -148,4 +148,4 @@ SECTIONS .debug_varnames 0 : { *(.debug_varnames) } } -__bss_size = (__bss_end - __bss_start)>>3; +__bss_size = SIZEOF(.bss); diff --git a/bsp/raspberry-pi/raspi3-64/link.lds b/bsp/raspberry-pi/raspi3-64/link.lds index a624a973b4..c17d66dbdf 100644 --- a/bsp/raspberry-pi/raspi3-64/link.lds +++ b/bsp/raspberry-pi/raspi3-64/link.lds @@ -137,4 +137,4 @@ SECTIONS .debug_varnames 0 : { *(.debug_varnames) } } -__bss_size = (__bss_end - __bss_start)>>3; +__bss_size = SIZEOF(.bss); diff --git a/bsp/raspberry-pi/raspi4-64/link.lds b/bsp/raspberry-pi/raspi4-64/link.lds index a624a973b4..c17d66dbdf 100644 --- a/bsp/raspberry-pi/raspi4-64/link.lds +++ b/bsp/raspberry-pi/raspi4-64/link.lds @@ -137,4 +137,4 @@ SECTIONS .debug_varnames 0 : { *(.debug_varnames) } } -__bss_size = (__bss_end - __bss_start)>>3; +__bss_size = SIZEOF(.bss); diff --git a/libcpu/aarch64/common/context_gcc.S b/libcpu/aarch64/common/context_gcc.S index 934db7ed84..b1a8313916 100644 --- a/libcpu/aarch64/common/context_gcc.S +++ b/libcpu/aarch64/common/context_gcc.S @@ -5,10 +5,11 @@ * * Change Logs: * Date Author Notes - * 2018-10-06 ZhaoXiaowei the first version + * 2018-10-06 ZhaoXiaowei the first version + * 2021-11-04 GuEe-GUI set sp with SP_ELx */ - /* +/* *enable gtimer */ .globl rt_hw_gtimer_enable @@ -17,6 +18,14 @@ rt_hw_gtimer_enable: MSR CNTP_CTL_EL0,X0 RET +/* + *disable gtimer + */ +.globl rt_hw_gtimer_disable +rt_hw_gtimer_disable: + MSR CNTP_CTL_EL0,XZR + RET + /* *set gtimer CNTP_TVAL_EL0 value */ @@ -48,10 +57,6 @@ rt_hw_get_gtimer_frq: RET .macro SAVE_CONTEXT - - /* Switch to use the EL0 stack pointer. */ - MSR SPSEL, #0 - /* Save the entire context. */ STP X0, X1, [SP, #-0x10]! STP X2, X3, [SP, #-0x10]! @@ -98,16 +103,9 @@ rt_hw_get_gtimer_frq: MOV X0, SP /* Move SP into X0 for saving. */ - /* Switch to use the ELx stack pointer. */ - MSR SPSEL, #1 - .endm .macro SAVE_CONTEXT_T - - /* Switch to use the EL0 stack pointer. */ - MSR SPSEL, #0 - /* Save the entire context. */ STP X0, X1, [SP, #-0x10]! STP X2, X3, [SP, #-0x10]! @@ -135,15 +133,15 @@ rt_hw_get_gtimer_frq: B.EQ 1f B . 3: - MRS X3, SPSR_EL3 + MOV X3, 0x0d MOV X2, X30 B 0f 2: - MRS X3, SPSR_EL2 + MOV X3, 0x09 MOV X2, X30 B 0f 1: - MRS X3, SPSR_EL1 + MOV X3, 0x05 MOV X2, X30 B 0f 0: @@ -152,16 +150,10 @@ rt_hw_get_gtimer_frq: MOV X0, SP /* Move SP into X0 for saving. */ - /* Switch to use the ELx stack pointer. */ - MSR SPSEL, #1 - .endm .macro RESTORE_CONTEXT - /* Switch to use the EL0 stack pointer. */ - MSR SPSEL, #0 - /* Set the SP to point to the stack of the task being restored. */ MOV SP, X0 @@ -206,9 +198,6 @@ rt_hw_get_gtimer_frq: LDP X2, X3, [SP], #0x10 LDP X0, X1, [SP], #0x10 - /* Switch to use the ELx stack pointer. _RB_ Might not be required. */ - MSR SPSEL, #1 - ERET .endm diff --git a/libcpu/aarch64/common/stack.c b/libcpu/aarch64/common/stack.c index 0fe00d8674..d93706fcb9 100644 --- a/libcpu/aarch64/common/stack.c +++ b/libcpu/aarch64/common/stack.c @@ -7,15 +7,16 @@ * Date Author Notes * 2011-09-23 Bernard the first version * 2011-10-05 Bernard add thumb mode + * 2021-11-04 GuEe-GUI set sp with SP_ELx */ #include #include #include -#define INITIAL_SPSR_EL3 (PSTATE_EL3 | SP_EL0) -#define INITIAL_SPSR_EL2 (PSTATE_EL2 | SP_EL0) -#define INITIAL_SPSR_EL1 (PSTATE_EL1 | SP_EL0) +#define INITIAL_SPSR_EL3 (PSTATE_EL3 | SP_ELx) +#define INITIAL_SPSR_EL2 (PSTATE_EL2 | SP_ELx) +#define INITIAL_SPSR_EL1 (PSTATE_EL1 | SP_ELx) /** * This function will initialize thread stack diff --git a/libcpu/aarch64/common/vector_gcc.S b/libcpu/aarch64/common/vector_gcc.S index fc88cce7f8..50ff41a8e3 100644 --- a/libcpu/aarch64/common/vector_gcc.S +++ b/libcpu/aarch64/common/vector_gcc.S @@ -18,7 +18,7 @@ system_vectors: .align 11 .set VBAR, system_vectors .org VBAR - // Exception from CurrentEL (EL1) with SP_EL0 (SPSEL=1) + // Exception from CurrentEL (EL1) with SP_EL0 (SPSEL=0) .org (VBAR + 0x00 + 0) B vector_error // Synchronous .org (VBAR + 0x80 + 0) diff --git a/libcpu/aarch64/cortex-a/entry_point.S b/libcpu/aarch64/cortex-a/entry_point.S index ac7b793811..0385dd4cf8 100644 --- a/libcpu/aarch64/cortex-a/entry_point.S +++ b/libcpu/aarch64/cortex-a/entry_point.S @@ -6,6 +6,7 @@ * Date Author Notes * 2020-01-15 bigmagic the first version * 2020-08-10 SummerGift support clang compiler + * 2021-11-04 GuEe-GUI set sp with SP_ELx */ .section ".text.entrypoint","ax" @@ -32,14 +33,15 @@ cpu_setup: bne cpu_not_in_el3 /* Should never be executed, just for completeness. (EL3) */ - mov x0, #(1 << 0) /* EL0 and EL1 are in Non-Secure state */ - orr x0, x0, #(1 << 4) /* RES1 */ - orr x0, x0, #(1 << 5) /* RES1 */ - orr x0, x0, #(1 << 7) /* SMC instructions are undefined at EL1 and above */ - orr x0, x0, #(1 << 8) /* HVC instructions are enabled at EL1 and above */ - orr x0, x0, #(1 << 10) /* The next lower level is AArch64 */ + mov x2, #(1 << 0) /* EL0 and EL1 are in Non-Secure state */ + orr x2, x2, #(1 << 4) /* RES1 */ + orr x2, x2, #(1 << 5) /* RES1 */ + orr x2, x2, #(1 << 7) /* SMC instructions are undefined at EL1 and above */ + orr x2, x2, #(1 << 8) /* HVC instructions are enabled at EL1 and above */ + orr x2, x2, #(1 << 10) /* The next lower level is AArch64 */ msr scr_el3, x2 + /* Change execution level to EL2 */ mov x2, #0x3c9 msr spsr_el3, x2 /* 0b1111001001 */ adr x2, cpu_not_in_el3 @@ -51,8 +53,6 @@ cpu_not_in_el3: /* Running at EL2 or EL1 */ beq cpu_in_el1 /* Halt this core if running in El1 */ cpu_in_el2: - msr sp_el1, x1 - /* Enable CNTP for EL1 */ mrs x0, cnthctl_el2 /* Counter-timer Hypervisor Control register */ orr x0, x0, #3 @@ -71,6 +71,7 @@ cpu_in_el2: eret cpu_in_el1: + msr spsel, #1 mov sp, x1 /* Set sp in el1 */ /* Avoid trap from SIMD or float point instruction */ @@ -89,7 +90,7 @@ cpu_in_el1: clean_bss_loop: cbz w2, jump_to_entry str xzr, [x1], #8 - sub w2, w2, #1 + sub w2, w2, #8 cbnz w2, clean_bss_loop jump_to_entry: diff --git a/src/thread.c b/src/thread.c index 0c7ae4beaa..3d47cdbd76 100644 --- a/src/thread.c +++ b/src/thread.c @@ -31,6 +31,7 @@ #include #include +#include #ifdef RT_USING_HOOK static void (*rt_thread_suspend_hook)(rt_thread_t thread); -- cgit v1.3.1