diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index a58013f8b3b..c803ee8982b 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -66,6 +66,10 @@ CSRCS += sim_exit.c sim_schedulesigaction.c sim_switchcontext.c sim_heap.c CSRCS += sim_uart.c sim_copyfullstate.c sim_sigdeliver.c CSRCS += sim_registerdump.c sim_saveusercontext.c sim_textheap.c +ifeq ($(CONFIG_DEBUG_TCBINFO),y) +CSRCS += sim_tcbinfo.c +endif + ifeq ($(CONFIG_SCHED_BACKTRACE),y) CSRCS += sim_backtrace.c endif diff --git a/arch/sim/src/sim/sim_tcbinfo.c b/arch/sim/src/sim/sim_tcbinfo.c new file mode 100644 index 00000000000..fb3689ad325 --- /dev/null +++ b/arch/sim/src/sim/sim_tcbinfo.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * arch/sim/src/sim/sim_tcbinfo.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_DEBUG_TCBINFO + +#include +#include + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#if defined(CONFIG_HOST_X86_64) && !defined(CONFIG_SIM_M32) +static const uint16_t g_reg_offs[] = +{ + UINT16_MAX, /* RAX */ + TCB_REG_OFF(JB_RBX), /* RBX */ + UINT16_MAX, /* RCX */ + UINT16_MAX, /* RDX */ + UINT16_MAX, /* RSI */ + UINT16_MAX, /* RDI */ + TCB_REG_OFF(JB_RBP), /* RBP */ + TCB_REG_OFF(JB_RSP), /* RSP */ + UINT16_MAX, /* R8 */ + UINT16_MAX, /* R9 */ + UINT16_MAX, /* R10 */ + UINT16_MAX, /* R11 */ + TCB_REG_OFF(JB_R12), /* R12 */ + TCB_REG_OFF(JB_R13), /* R13 */ + TCB_REG_OFF(JB_R15), /* R14 */ + TCB_REG_OFF(JB_R15), /* R15 */ + TCB_REG_OFF(JB_RIP), /* RIP */ + UINT16_MAX, /* EFLAGS */ + UINT16_MAX, /* CS */ + UINT16_MAX, /* SS */ + UINT16_MAX, /* DS */ + UINT16_MAX, /* ES */ + UINT16_MAX, /* FS */ +}; +#elif defined(CONFIG_HOST_X86) || defined(CONFIG_SIM_M32) +static const uint16_t g_reg_offs[] = +{ + UINT16_MAX, /* RAX */ + UINT16_MAX, /* RCX */ + UINT16_MAX, /* RDX */ + TCB_REG_OFF(JB_EBX), /* RBX */ + TCB_REG_OFF(JB_ESP), /* ESP */ + UINT16_MAX, /* EBP */ + TCB_REG_OFF(JB_ESI), /* ESI */ + TCB_REG_OFF(JB_EDI), /* EDI */ + TCB_REG_OFF(JB_EIP), /* EIP */ + UINT16_MAX, /* EFLAGS */ + UINT16_MAX, /* CS */ + UINT16_MAX, /* SS */ + UINT16_MAX, /* DS */ + UINT16_MAX, /* ES */ + UINT16_MAX, /* FS */ +}; +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +const struct tcbinfo_s g_tcbinfo = +{ + .pid_off = TCB_PID_OFF, + .state_off = TCB_STATE_OFF, + .pri_off = TCB_PRI_OFF, + .name_off = TCB_NAME_OFF, + .stack_off = TCB_STACK_OFF, + .stack_size_off = TCB_STACK_SIZE_OFF, + .regs_off = TCB_REGS_OFF, + .basic_num = sizeof(g_reg_offs) / sizeof(g_reg_offs[0]), + .total_num = sizeof(g_reg_offs) / sizeof(g_reg_offs[0]), + { + .p = g_reg_offs, + }, +}; + +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/