From 2ab425acf95ef2186508802a3802f526f648b895 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 23 Dec 2012 10:07:22 +0000 Subject: [PATCH] Backported kernel debuggers info record from 2.5.1. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_2.4.x@4954 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/chregistry.h | 28 +++++++++++++++++++++ os/kernel/src/chregistry.c | 45 ++++++++++++++++++++++++++++++++++ os/kernel/src/chsys.c | 8 ++++-- readme.txt | 2 ++ 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/os/kernel/include/chregistry.h b/os/kernel/include/chregistry.h index 2400d2637..182624a5c 100644 --- a/os/kernel/include/chregistry.h +++ b/os/kernel/include/chregistry.h @@ -37,6 +37,33 @@ #define _CHREGISTRY_H_ #if CH_USE_REGISTRY || defined(__DOXYGEN__) + +/** + * @brief ChibiOS/RT memory signature record. + */ +typedef struct { + char ch_identifier[4]; /**< @brief Always set to "main". */ + uint8_t ch_zero; /**< @brief Must be zero. */ + uint8_t ch_size; /**< @brief Size of this structure. */ + uint16_t ch_version; /**< @brief Encoded ChibiOS/RT version. */ + uint8_t ch_ptrsize; /**< @brief Size of a pointer. */ + uint8_t ch_timesize; /**< @brief Size of a @p systime_t. */ + uint8_t ch_threadsize; /**< @brief Size of a @p Thread struct. */ + uint8_t cf_off_prio; /**< @brief Offset of @p p_prio field. */ + uint8_t cf_off_ctx; /**< @brief Offset of @p p_ctx field. */ + uint8_t cf_off_newer; /**< @brief Offset of @p p_newer field. */ + uint8_t cf_off_older; /**< @brief Offset of @p p_older field. */ + uint8_t cf_off_name; /**< @brief Offset of @p p_name field. */ + uint8_t cf_off_stklimit; /**< @brief Offset of @p p_stklimit + field. */ + uint8_t cf_off_state; /**< @brief Offset of @p p_state field. */ + uint8_t cf_off_flags; /**< @brief Offset of @p p_flags field. */ + uint8_t cf_off_refs; /**< @brief Offset of @p p_refs field. */ + uint8_t cf_off_preempt; /**< @brief Offset of @p p_preempt + field. */ + uint8_t cf_off_time; /**< @brief Offset of @p p_time field. */ +} chdebug_t; + /** * @name Macro Functions * @{ @@ -96,6 +123,7 @@ #ifdef __cplusplus extern "C" { #endif + extern ROMCONST chdebug_t ch_debug; Thread *chRegFirstThread(void); Thread *chRegNextThread(Thread *tp); #ifdef __cplusplus diff --git a/os/kernel/src/chregistry.c b/os/kernel/src/chregistry.c index 48153c3a9..30c96eb88 100644 --- a/os/kernel/src/chregistry.c +++ b/os/kernel/src/chregistry.c @@ -57,6 +57,51 @@ #if CH_USE_REGISTRY || defined(__DOXYGEN__) +#define _offsetof(st, m) \ + ((size_t)((char *)&((st *)0)->m - (char *)0)) + +/* + * OS signature in ROM plus debug-related information. + */ +ROMCONST chdebug_t ch_debug = { + "main", + (uint8_t)0, + (uint8_t)sizeof (chdebug_t), + (uint16_t)((CH_KERNEL_MAJOR << 11) | + (CH_KERNEL_MINOR << 6) | + (CH_KERNEL_PATCH) << 0), + (uint8_t)sizeof (void *), + (uint8_t)sizeof (systime_t), + (uint8_t)sizeof (Thread), + (uint8_t)_offsetof(Thread, p_prio), + (uint8_t)_offsetof(Thread, p_ctx), + (uint8_t)_offsetof(Thread, p_newer), + (uint8_t)_offsetof(Thread, p_older), + (uint8_t)_offsetof(Thread, p_name), +#if CH_DBG_ENABLE_STACK_CHECK + (uint8_t)_offsetof(Thread, p_stklimit), +#else + (uint8_t)0, +#endif + (uint8_t)_offsetof(Thread, p_state), + (uint8_t)_offsetof(Thread, p_flags), +#if CH_USE_DYNAMIC + (uint8_t)_offsetof(Thread, p_refs), +#else + (uint8_t)0, +#endif +#if CH_TIME_QUANTUM > 0 + (uint8_t)_offsetof(Thread, p_preempt), +#else + (uint8_t)0, +#endif +#if CH_DBG_THREADS_PROFILING + (uint8_t)_offsetof(Thread, p_time) +#else + (uint8_t)0 +#endif +}; + /** * @brief Returns the first thread in the system. * @details Returns the most ancient thread in the system, usually this is diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c index a461a2bbd..2314d78ec 100644 --- a/os/kernel/src/chsys.c +++ b/os/kernel/src/chsys.c @@ -43,7 +43,9 @@ #include "ch.h" #if !CH_NO_IDLE_THREAD || defined(__DOXYGEN__) -/* Idle thread working area.*/ +/** + * @brief Idle thread working area. + */ WORKING_AREA(_idle_thread_wa, PORT_IDLE_THREAD_STACK_SIZE); /** @@ -108,7 +110,9 @@ void chSysInit(void) { #endif chSysEnable(); - chRegSetThreadName("main"); + /* Note, &ch_debug points to the string "main" if the registry is + active, else the parameter is ignored.*/ + chRegSetThreadName((const char *)&ch_debug); #if !CH_NO_IDLE_THREAD /* This thread has the lowest priority in the system, its role is just to diff --git a/readme.txt b/readme.txt index 88cf8f506..f8c85726f 100644 --- a/readme.txt +++ b/readme.txt @@ -79,6 +79,8 @@ ***************************************************************************** *** 2.4.3 *** +- NEW: Added memory signature record to the registry in order to simplify + the implementation of ad-hoc debuggers. - FIX: Fixed warning in STM32 ICU driver using IAR compiler (bug 3598177). - FIX: Fixed typo in chOQGetEmptyI() macro (bug 3595910). - FIX: Fixed possible false detect of loaded prescaler in RTCv1 driver (bug