thread_info.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2017 Intel Corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <kernel.h>
  7. #define THREAD_INFO_UNIMPLEMENTED 0xffffffff
  8. enum {
  9. THREAD_INFO_OFFSET_VERSION,
  10. THREAD_INFO_OFFSET_K_CURR_THREAD,
  11. THREAD_INFO_OFFSET_K_THREADS,
  12. THREAD_INFO_OFFSET_T_ENTRY,
  13. THREAD_INFO_OFFSET_T_NEXT_THREAD,
  14. THREAD_INFO_OFFSET_T_STATE,
  15. THREAD_INFO_OFFSET_T_USER_OPTIONS,
  16. THREAD_INFO_OFFSET_T_PRIO,
  17. THREAD_INFO_OFFSET_T_STACK_PTR,
  18. THREAD_INFO_OFFSET_T_NAME,
  19. THREAD_INFO_OFFSET_T_ARCH,
  20. THREAD_INFO_OFFSET_T_PREEMPT_FLOAT,
  21. THREAD_INFO_OFFSET_T_COOP_FLOAT,
  22. };
  23. #if CONFIG_MP_NUM_CPUS > 1
  24. #error "This code doesn't work properly with multiple CPUs enabled"
  25. #endif
  26. /* Forward-compatibility notes: 1) Only append items to this table; otherwise
  27. * debugger plugin versions that expect fewer items will read garbage values.
  28. * 2) Avoid incompatible changes that affect the interpretation of existing
  29. * items. But if you have to do them, increment THREAD_INFO_OFFSET_VERSION
  30. * and submit a patch for debugger plugins to deal with both the old and new
  31. * scheme.
  32. * Only version 1 is backward compatible to version 0.
  33. */
  34. __attribute__((used, section(".dbg_thread_info")))
  35. size_t _kernel_thread_info_offsets[] = {
  36. /* Version 0 starts */
  37. [THREAD_INFO_OFFSET_VERSION] = 1,
  38. [THREAD_INFO_OFFSET_K_CURR_THREAD] = offsetof(struct _cpu, current),
  39. [THREAD_INFO_OFFSET_K_THREADS] = offsetof(struct z_kernel, threads),
  40. [THREAD_INFO_OFFSET_T_ENTRY] = offsetof(struct k_thread, entry),
  41. [THREAD_INFO_OFFSET_T_NEXT_THREAD] = offsetof(struct k_thread,
  42. next_thread),
  43. [THREAD_INFO_OFFSET_T_STATE] = offsetof(struct _thread_base,
  44. thread_state),
  45. [THREAD_INFO_OFFSET_T_USER_OPTIONS] = offsetof(struct _thread_base,
  46. user_options),
  47. [THREAD_INFO_OFFSET_T_PRIO] = offsetof(struct _thread_base, prio),
  48. #if defined(CONFIG_ARM64)
  49. /* We are assuming that the SP of interest is SP_EL1 */
  50. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  51. callee_saved.sp_elx),
  52. #elif defined(CONFIG_ARM)
  53. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  54. callee_saved.psp),
  55. #elif defined(CONFIG_ARC)
  56. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  57. callee_saved.sp),
  58. #elif defined(CONFIG_X86)
  59. #if defined(CONFIG_X86_64)
  60. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  61. callee_saved.rsp),
  62. #else
  63. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  64. callee_saved.esp),
  65. #endif
  66. #elif defined(CONFIG_NIOS2)
  67. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  68. callee_saved.sp),
  69. #elif defined(CONFIG_RISCV)
  70. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  71. callee_saved.sp),
  72. #elif defined(CONFIG_SPARC)
  73. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  74. callee_saved.o6),
  75. #elif defined(CONFIG_ARCH_POSIX)
  76. [THREAD_INFO_OFFSET_T_STACK_PTR] = offsetof(struct k_thread,
  77. callee_saved.thread_status),
  78. #elif defined(CONFIG_XTENSA)
  79. /* Xtensa does not store stack pointers inside thread objects.
  80. * The registers are saved in thread stack where there is
  81. * no fixed location for this to work. So mark this as
  82. * unimplemented to avoid the #warning below.
  83. */
  84. [THREAD_INFO_OFFSET_T_STACK_PTR] = THREAD_INFO_UNIMPLEMENTED,
  85. #else
  86. /* Use a special value so that OpenOCD knows that obtaining the stack
  87. * pointer is not possible on this particular architecture.
  88. */
  89. #warning Please define THREAD_INFO_OFFSET_T_STACK_PTR for this architecture
  90. [THREAD_INFO_OFFSET_T_STACK_PTR] = THREAD_INFO_UNIMPLEMENTED,
  91. #endif
  92. /* Version 0 ends */
  93. [THREAD_INFO_OFFSET_T_NAME] = offsetof(struct k_thread, name),
  94. [THREAD_INFO_OFFSET_T_ARCH] = offsetof(struct k_thread, arch),
  95. #if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING) && defined(CONFIG_ARM)
  96. [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch,
  97. preempt_float),
  98. [THREAD_INFO_OFFSET_T_COOP_FLOAT] = THREAD_INFO_UNIMPLEMENTED,
  99. #elif defined(CONFIG_FPU) && defined(CONFIG_X86)
  100. #if defined(CONFIG_X86_64)
  101. [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch,
  102. sse),
  103. #else
  104. [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = offsetof(struct _thread_arch,
  105. preempFloatReg),
  106. #endif
  107. [THREAD_INFO_OFFSET_T_COOP_FLOAT] = THREAD_INFO_UNIMPLEMENTED,
  108. #else
  109. [THREAD_INFO_OFFSET_T_PREEMPT_FLOAT] = THREAD_INFO_UNIMPLEMENTED,
  110. [THREAD_INFO_OFFSET_T_COOP_FLOAT] = THREAD_INFO_UNIMPLEMENTED,
  111. #endif
  112. /* Version is still 1, but existence of following elements must be
  113. * checked with _kernel_thread_info_num_offsets.
  114. */
  115. };
  116. extern size_t __attribute__((alias("_kernel_thread_info_offsets")))
  117. _kernel_openocd_offsets;
  118. __attribute__((used, section(".dbg_thread_info")))
  119. size_t _kernel_thread_info_num_offsets = ARRAY_SIZE(_kernel_thread_info_offsets);
  120. extern size_t __attribute__((alias("_kernel_thread_info_num_offsets")))
  121. _kernel_openocd_num_offsets;
  122. __attribute__((used, section(".dbg_thread_info")))
  123. uint8_t _kernel_thread_info_size_t_size = (uint8_t)sizeof(size_t);
  124. extern uint8_t __attribute__((alias("_kernel_thread_info_size_t_size")))
  125. _kernel_openocd_size_t_size;