thread.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2017 Intel Corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Per-arch thread definition
  9. *
  10. * This file contains definitions for
  11. *
  12. * struct _thread_arch
  13. * struct _callee_saved
  14. *
  15. * necessary to instantiate instances of struct k_thread.
  16. */
  17. #ifndef ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_THREAD_H_
  18. #define ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_THREAD_H_
  19. #ifndef _ASMLANGUAGE
  20. #include <zephyr/types.h>
  21. struct _callee_saved {
  22. uint32_t v1; /* r4 */
  23. uint32_t v2; /* r5 */
  24. uint32_t v3; /* r6 */
  25. uint32_t v4; /* r7 */
  26. uint32_t v5; /* r8 */
  27. uint32_t v6; /* r9 */
  28. uint32_t v7; /* r10 */
  29. uint32_t v8; /* r11 */
  30. uint32_t psp; /* r13 */
  31. };
  32. typedef struct _callee_saved _callee_saved_t;
  33. #if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
  34. struct _preempt_float {
  35. float s16;
  36. float s17;
  37. float s18;
  38. float s19;
  39. float s20;
  40. float s21;
  41. float s22;
  42. float s23;
  43. float s24;
  44. float s25;
  45. float s26;
  46. float s27;
  47. float s28;
  48. float s29;
  49. float s30;
  50. float s31;
  51. };
  52. #endif
  53. struct _thread_arch {
  54. /* interrupt locking key */
  55. uint32_t basepri;
  56. /* r0 in stack frame cannot be written to reliably */
  57. uint32_t swap_return_value;
  58. #if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
  59. /*
  60. * No cooperative floating point register set structure exists for
  61. * the Cortex-M as it automatically saves the necessary registers
  62. * in its exception stack frame.
  63. */
  64. struct _preempt_float preempt_float;
  65. #endif
  66. #if defined(CONFIG_ARM_STORE_EXC_RETURN) || defined(CONFIG_USERSPACE)
  67. /*
  68. * Status variable holding several thread status flags
  69. * as follows:
  70. *
  71. * byte 0
  72. * +-bits 4-7-----bit-3----------bit-2--------bit-1---+----bit-0------+
  73. * : | | | | |
  74. * : reserved |<Guard FLOAT>| reserved | reserved | <priv mode> |
  75. * : bits | | | | CONTROL.nPRIV |
  76. * +------------------------------------------------------------------+
  77. *
  78. * byte 1
  79. * +----------------------------bits 8-15-----------------------------+
  80. * : Least significant byte of EXC_RETURN |
  81. * : bit 15| bit 14| bit 13 | bit 12| bit 11 | bit 10 | bit 9 | bit 8 |
  82. * : Res | S | DCRS | FType | Mode | SPSel | Res | ES |
  83. * +------------------------------------------------------------------+
  84. *
  85. * Bit 0: thread's current privileged mode (Supervisor or User mode)
  86. * Mirrors CONTROL.nPRIV flag.
  87. * Bit 2: Deprecated in favor of FType. Note: FType = !CONTROL.FPCA.
  88. * indicating whether the thread has an active FP context.
  89. * Mirrors CONTROL.FPCA flag.
  90. * Bit 3: indicating whether the thread is applying the long (FLOAT)
  91. * or the default MPU stack guard size.
  92. *
  93. * Bits 8-15: Least significant octet of the EXC_RETURN value when a
  94. * thread is switched-out. The value is copied from LR when
  95. * entering the PendSV handler. When the thread is
  96. * switched in again, the value is restored to LR before
  97. * exiting the PendSV handler.
  98. */
  99. union {
  100. uint32_t mode;
  101. #if defined(CONFIG_ARM_STORE_EXC_RETURN)
  102. struct {
  103. uint8_t mode_bits;
  104. uint8_t mode_exc_return;
  105. uint16_t mode_reserved2;
  106. };
  107. #endif
  108. };
  109. #if defined(CONFIG_USERSPACE)
  110. uint32_t priv_stack_start;
  111. #if defined(CONFIG_CPU_CORTEX_R)
  112. uint32_t priv_stack_end;
  113. uint32_t sp_usr;
  114. #endif
  115. #endif
  116. #endif
  117. };
  118. #if defined(CONFIG_FPU_SHARING) && defined(CONFIG_MPU_STACK_GUARD)
  119. #define Z_ARM_MODE_MPU_GUARD_FLOAT_Msk (1 << 3)
  120. #endif
  121. typedef struct _thread_arch _thread_arch_t;
  122. #endif /* _ASMLANGUAGE */
  123. #endif /* ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_THREAD_H_ */