From d7576df91679bb81b29cfa51c07997b79dea7b09 Mon Sep 17 00:00:00 2001 From: peshkovivan Date: Mon, 2 Oct 2023 13:00:07 +0300 Subject: [PATCH] Replace GCC with LLVM for LiteOS-m Signed-off-by: peshkovivan --- arch/arm/cortex-m4/gcc/los_dispatch.S | 76 +++++++++---------- components/cpup/los_cpup.c | 72 +++++++++--------- .../sample/kernel/swtmr/It_los_swtmr_035.c | 39 +++++----- .../unittest/posix/src/math/math_func_test.c | 10 +++ .../posix/src/mqueue/mqueue_func_test.c | 4 +- 5 files changed, 105 insertions(+), 96 deletions(-) diff --git a/arch/arm/cortex-m4/gcc/los_dispatch.S b/arch/arm/cortex-m4/gcc/los_dispatch.S index 64c41a24..5fadfcec 100644 --- a/arch/arm/cortex-m4/gcc/los_dispatch.S +++ b/arch/arm/cortex-m4/gcc/los_dispatch.S @@ -43,25 +43,25 @@ .equ OS_CONTROL_FPCA_ENABLE, 0x4 .equ OS_CONTROL_KERNEL_MODE, 0x2 #if (LOSCFG_SECURE == 1) -.equ OS_CONTROL_USER_MODE, 0x3 -.equ OS_TASK_FLAG_USER_TASK, 0x0200 -#endif - - .section .text - .thumb - -.macro SIGNAL_CONTEXT_RESTORE - push {r12, lr} - blx OsSignalTaskContextRestore - pop {r12, lr} - cmp r0, #0 - mov r1, r0 - bne SignalContextRestore -.endm - - .type HalStartToRun, %function - .global HalStartToRun -HalStartToRun: +.equ OS_CONTROL_USER_MODE, 0x3 +.equ OS_TASK_FLAG_USER_TASK, 0x0200 +#endif + + .section .text + .thumb + +.macro SIGNAL_CONTEXT_RESTORE + push {r12, lr} + bl OsSignalTaskContextRestore + pop {r12, lr} + cmp r0, #0 + mov r1, r0 + bne SignalContextRestore +.endm + + .type HalStartToRun, %function + .global HalStartToRun +HalStartToRun: .fnstart .cantunwind @@ -153,25 +153,25 @@ ArchTaskSchedule: .global HalPendSV HalPendSV: .fnstart - .cantunwind - - mrs r12, PRIMASK - cpsid I - -HalTaskSwitch: - SIGNAL_CONTEXT_RESTORE - - push {r12, lr} - blx OsSchedTaskSwitch - pop {r12, lr} - cmp r0, #0 - mov r0, lr - bne TaskContextSwitch - msr PRIMASK, r12 - bx lr - -TaskContextSwitch: - mov lr, r0 + .cantunwind + + mrs r12, PRIMASK + cpsid I + +HalTaskSwitch: + SIGNAL_CONTEXT_RESTORE + + push {r12, lr} + bl OsSchedTaskSwitch + pop {r12, lr} + cmp r0, #0 + mov r0, lr + bne TaskContextSwitch + msr PRIMASK, r12 + bx lr + +TaskContextSwitch: + mov lr, r0 mrs r0, psp stmfd r0!, {r4-r12} diff --git a/components/cpup/los_cpup.c b/components/cpup/los_cpup.c index 0c3e2cf7..54927ca5 100644 --- a/components/cpup/los_cpup.c +++ b/components/cpup/los_cpup.c @@ -118,42 +118,42 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpupGuardCreator(VOID) (VOID)LOS_SwtmrStart(cpupSwtmrID); return LOS_OK; -} -#endif - -/***************************************************************************** -Function : OsCpupDaemonInit -Description: initialization of CPUP Daemon -Input : None -Return : LOS_OK or Error Information -*****************************************************************************/ -LITE_OS_SEC_TEXT_INIT UINT32 OsCpupDaemonInit() -{ -#if (LOSCFG_BASE_CORE_SWTMR == 1) - (VOID)OsCpupGuardCreator(); - g_irqCpupInitFlg = 1; -#endif - - return LOS_OK; -} -#endif - -/***************************************************************************** -Function : OsCpupInit -Description: initialization of CPUP -Input : None -Return : LOS_OK or Error Information -*****************************************************************************/ -LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit() -{ - UINT32 size; - CHAR *cpupMem = NULL; - - size = g_taskMaxNum * sizeof(OsCpupCB); -#if (LOSCFG_CPUP_INCLUDE_IRQ == 1) - size += LOSCFG_PLATFORM_HWI_LIMIT * sizeof(OsIrqCpupCB); -#endif - +} +#endif + +/***************************************************************************** +Function : OsCpupDaemonInit +Description: initialization of CPUP Daemon +Input : None +Return : LOS_OK or Error Information +*****************************************************************************/ +LITE_OS_SEC_TEXT_INIT UINT32 OsCpupDaemonInit(void) +{ +#if (LOSCFG_BASE_CORE_SWTMR == 1) + (VOID)OsCpupGuardCreator(); + g_irqCpupInitFlg = 1; +#endif + + return LOS_OK; +} +#endif + +/***************************************************************************** +Function : OsCpupInit +Description: initialization of CPUP +Input : None +Return : LOS_OK or Error Information +*****************************************************************************/ +LITE_OS_SEC_TEXT_INIT UINT32 OsCpupInit(void) +{ + UINT32 size; + CHAR *cpupMem = NULL; + + size = g_taskMaxNum * sizeof(OsCpupCB); +#if (LOSCFG_CPUP_INCLUDE_IRQ == 1) + size += LOSCFG_PLATFORM_HWI_LIMIT * sizeof(OsIrqCpupCB); +#endif + cpupMem = LOS_MemAlloc(m_aucSysMem0, size); if (cpupMem == NULL) { return LOS_ERRNO_CPUP_NO_MEMORY; diff --git a/testsuites/sample/kernel/swtmr/It_los_swtmr_035.c b/testsuites/sample/kernel/swtmr/It_los_swtmr_035.c index 20cb37b2..f716bea1 100644 --- a/testsuites/sample/kernel/swtmr/It_los_swtmr_035.c +++ b/testsuites/sample/kernel/swtmr/It_los_swtmr_035.c @@ -199,26 +199,25 @@ static UINT32 Testcase(VOID) } } - ret = LOS_EventDestroy(&g_eventCB1); - ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - - ret = LOS_EventDestroy(&g_eventCB2); - ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - - ret = LOS_EventDestroy(&g_eventCB3); - ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); - - return LOS_OK; - -EXIT: - LOS_SwtmrDelete(g_swtmrId3); - LOS_SwtmrDelete(g_swtmrId2); - LOS_SwtmrDelete(g_swtmrId1); - LOS_TaskDelete(g_testTaskID02); - LOS_TaskDelete(g_testTaskID03); - - return LOS_OK; -} + ret = LOS_EventDestroy(&g_eventCB1); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); + + ret = LOS_EventDestroy(&g_eventCB2); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); + + ret = LOS_EventDestroy(&g_eventCB3); + ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT); + + // cleanup resources after tests +EXIT: + LOS_SwtmrDelete(g_swtmrId3); + LOS_SwtmrDelete(g_swtmrId2); + LOS_SwtmrDelete(g_swtmrId1); + LOS_TaskDelete(g_testTaskID02); + LOS_TaskDelete(g_testTaskID03); + + return LOS_OK; +} VOID ItLosSwtmr035(VOID) // IT_Layer_ModuleORFeature_No { diff --git a/testsuites/unittest/posix/src/math/math_func_test.c b/testsuites/unittest/posix/src/math/math_func_test.c index d57420d4..9a5159c6 100644 --- a/testsuites/unittest/posix/src/math/math_func_test.c +++ b/testsuites/unittest/posix/src/math/math_func_test.c @@ -119,9 +119,19 @@ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs001, Function | MediumTest | L */ LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs002, Function | MediumTest | Level1) { + // the first case ( abs(-2147483648) ) is UB + // quote from "man abs": "Trying to take the absolute value of the most negative integer is not defined." + // so this case is disabled for non-GCC toolchains +#ifdef LOSCFG_COMPILER_GCC const int testCount = 3; int testValues[] = {-2147483648, -2147483647, 2147483647}; int expected[] = {-2147483648, 2147483647, 2147483647}; +#else + const int testCount = 2; + int testValues[] = {-2147483647, 2147483647}; + int expected[] = {2147483647, 2147483647}; +#endif + int ret; for (int i = 0; i < testCount; ++i) { ret = abs(testValues[i]); diff --git a/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c b/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c index 2c4c3220..242db5a4 100644 --- a/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c +++ b/testsuites/unittest/posix/src/mqueue/mqueue_func_test.c @@ -355,7 +355,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, TestMqOpenENOSPC, Function | MediumTest | Le */ LITE_TEST_CASE(MqueueFuncTestSuite, TestMqCloseEBADF, Function | MediumTest | Level2) { - ICUNIT_TRACK_EQUAL(mq_close(NULL), -1, -1); + ICUNIT_TRACK_EQUAL(mq_close((mqd_t)NULL), -1, -1); ICUNIT_TRACK_EQUAL(errno, EBADF, errno); return 0; } @@ -411,7 +411,7 @@ LITE_TEST_CASE(MqueueFuncTestSuite, TestMqSendEBADFEMSGSIZE, Function | MediumTe queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); - ret = mq_send(NULL, MQ_MSG, 1, MQ_MSG_PRIO); + ret = mq_send((mqd_t)NULL, MQ_MSG, 1, MQ_MSG_PRIO); ICUNIT_TRACK_EQUAL(ret, -1, ret); ICUNIT_TRACK_EQUAL(errno, EBADF, errno);