From ef1ce38a00f21419084f4427d3cd531e365e6819 Mon Sep 17 00:00:00 2001 From: liuxi1234 Date: Fri, 1 Aug 2025 14:59:04 +0800 Subject: [PATCH] gdb:multi core adapte multi core gdb adapte ipi call Signed-off-by: liuxi --- demos/hi3095/CMakeLists.txt | 6 +++ .../gdbstub/gdbauxiliary/CMakeLists.txt | 2 + .../gdbstub/gdbauxiliary/cpu_online.c | 36 ++++++++++++++++++ .../gdbstub/gdbauxiliary/cpu_online.h | 26 +++++++++++++ src/component/gdbstub/gdbauxiliary/ipi_call.c | 37 +++++++++++++++++++ src/component/gdbstub/gdbauxiliary/ipi_call.h | 23 ++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 src/component/gdbstub/gdbauxiliary/CMakeLists.txt create mode 100644 src/component/gdbstub/gdbauxiliary/cpu_online.c create mode 100644 src/component/gdbstub/gdbauxiliary/cpu_online.h create mode 100644 src/component/gdbstub/gdbauxiliary/ipi_call.c create mode 100644 src/component/gdbstub/gdbauxiliary/ipi_call.h diff --git a/demos/hi3095/CMakeLists.txt b/demos/hi3095/CMakeLists.txt index 0db94089..221cdc2f 100644 --- a/demos/hi3095/CMakeLists.txt +++ b/demos/hi3095/CMakeLists.txt @@ -54,6 +54,7 @@ include_directories( ${HOME_PATH}/src/shell/adapter/include ${HOME_PATH}/src/shell/full/include ${HOME_PATH}/src/component/mica + ${HOME_PATH}/src/component/gdbstub/gdbauxiliary ${CMAKE_CURRENT_SOURCE_DIR}/drivers/include ) @@ -99,6 +100,11 @@ if (${CONFIG_OS_OPTION_OPENAMP}) list(APPEND OBJS $) endif() +if (${CONFIG_OS_GDB_STUB}) +add_subdirectory(${HOME_PATH}/src/component/gdbstub/gdbauxiliary gdbauxiliary) +list(APPEND OBJS $) +endif() + if(${CONFIG_OS_SUPPORT_OPC_UA}) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/component/open62541-1.4.4/include diff --git a/src/component/gdbstub/gdbauxiliary/CMakeLists.txt b/src/component/gdbstub/gdbauxiliary/CMakeLists.txt new file mode 100644 index 00000000..d8d2ff02 --- /dev/null +++ b/src/component/gdbstub/gdbauxiliary/CMakeLists.txt @@ -0,0 +1,2 @@ +set(SRC ipi_call.c cpu_online.c) +add_library(gdbauxiliary OBJECT ${SRC}) \ No newline at end of file diff --git a/src/component/gdbstub/gdbauxiliary/cpu_online.c b/src/component/gdbstub/gdbauxiliary/cpu_online.c new file mode 100644 index 00000000..1d3d39f7 --- /dev/null +++ b/src/component/gdbstub/gdbauxiliary/cpu_online.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025-2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * UniProton is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Create: 2025-08-01 + * Description: 多核gdb辅助接口 + */ + +#include +#include "cpu_online.h" +#include "prt_typedef.h" +#include "prt_cpu_external.h" + +OS_SEC_BSS volatile uintptr_t gdebugIntLock; +volatile U8 g_cpu_online_bitmap = 0; + +/* 设置指定核掩码 */ +void OsCpuOnlineSetMask(U8 cpu_id) +{ + uintptr_t intSave = OsDebugIntLock(); + g_cpu_online_bitmap |= (1U << cpu_id); + OsDebugIntUnlock(intSave); +} + +/* 检查指定核的掩码 */ +bool OsCpuOnlineCheckMask(U8 cpu_id) +{ + return (g_cpu_online_bitmap & (1U << cpu_id)) != 0; +} diff --git a/src/component/gdbstub/gdbauxiliary/cpu_online.h b/src/component/gdbstub/gdbauxiliary/cpu_online.h new file mode 100644 index 00000000..856a81d4 --- /dev/null +++ b/src/component/gdbstub/gdbauxiliary/cpu_online.h @@ -0,0 +1,26 @@ +#ifndef _CPU_ONLINE_H_ +#define _CPU_ONLINE_H_ + +#include +#include "prt_cpu_external.h" + +extern volatile U8 g_cpu_online_bitmap; /* 全局变量,记录核的启动状态 */ +extern volatile uintptr_t gdebugIntLock; +OS_SEC_ALW_INLINE INLINE uintptr_t OsDebugIntLock(void) +{ + uintptr_t intSave = OsIntLock(); + OsSplLock(&gdebugIntLock); + return intSave; +} + +OS_SEC_ALW_INLINE INLINE void OsDebugIntUnlock(uintptr_t intSave) +{ + OsSplUnlock(&gdebugIntLock); + OsIntRestore(intSave); +} + +/* 函数声明 */ +void OsCpuOnlineSetMask(U8 cpu_id); +bool OsCpuOnlineCheckMask(U8 cpu_id); + +#endif /* _CPU_ONLINE_H_ */ diff --git a/src/component/gdbstub/gdbauxiliary/ipi_call.c b/src/component/gdbstub/gdbauxiliary/ipi_call.c new file mode 100644 index 00000000..d5498f35 --- /dev/null +++ b/src/component/gdbstub/gdbauxiliary/ipi_call.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025-2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * UniProton is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Create: 2025-08-01 + * Description: 多核gdb辅助接口 + */ + +#include "ipi_call.h" +#include "prt_buildef.h" +#include "prt_typedef.h" +#include "prt_hwi.h" + +struct ipi_slot ipi_slots[OS_MAX_CORE_NUM]; + +void OsIpiCall(U32 core_mask, void (*callback)(void *), void *param) +{ + /* 1. 为每个目标核设置回调和参数 */ + for (int i = 0; i < OS_MAX_CORE_NUM; ++i) + { + if (core_mask & (0x1U << i)) + { + ipi_slots[i].callback = callback; + ipi_slots[i].param = param; + ipi_slots[i].valid = 1; + } + } + + OsHwiMcTrigger(OS_TYPE_TRIGGER_BY_MASK, core_mask, OS_HWI_IPI_NO_06); +} diff --git a/src/component/gdbstub/gdbauxiliary/ipi_call.h b/src/component/gdbstub/gdbauxiliary/ipi_call.h new file mode 100644 index 00000000..5e75c8be --- /dev/null +++ b/src/component/gdbstub/gdbauxiliary/ipi_call.h @@ -0,0 +1,23 @@ +#ifndef _IPI_CALL_H_ +#define _IPI_CALL_H_ + +#include +#include +#include +#include +#include "securec.h" +#include "prt_hwi.h" +#include "prt_task.h" + +/* 每个核的 IPI 描述符 */ +struct ipi_slot { + void (*callback)(void *); /* 回调函数 */ + void *param; /* 参数 */ + uint8_t valid; /* 是否有有效的回调 */ +}; + +extern struct ipi_slot ipi_slots[OS_MAX_CORE_NUM]; /* 全局数组 */ + +void OsIpiCall(U32 core_mask, void (*callback)(void *), void *param); + +#endif /* _IPI_CALL_H_ */ -- Gitee