processor.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  4. */
  5. #ifndef _ASM_PROCESSOR_H
  6. #define _ASM_PROCESSOR_H
  7. #include <linux/atomic.h>
  8. #include <linux/cpumask.h>
  9. #include <linux/sizes.h>
  10. #include <asm/cpu.h>
  11. #include <asm/cpu-info.h>
  12. #include <asm/hw_breakpoint.h>
  13. #include <asm/loongarch.h>
  14. #include <asm/vdso/processor.h>
  15. #include <uapi/asm/ptrace.h>
  16. #include <uapi/asm/sigcontext.h>
  17. #ifdef CONFIG_32BIT
  18. #define TASK_SIZE 0x80000000UL
  19. #define TASK_SIZE_MIN TASK_SIZE
  20. #define STACK_TOP_MAX TASK_SIZE
  21. #define TASK_IS_32BIT_ADDR 1
  22. #endif
  23. #ifdef CONFIG_64BIT
  24. #define TASK_SIZE32 0x100000000UL
  25. #define TASK_SIZE64 (0x1UL << ((cpu_vabits > VA_BITS) ? VA_BITS : cpu_vabits))
  26. #define TASK_SIZE (test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE64)
  27. #define TASK_SIZE_MIN TASK_SIZE32
  28. #define STACK_TOP_MAX TASK_SIZE64
  29. #define TASK_SIZE_OF(tsk) \
  30. (test_tsk_thread_flag(tsk, TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE64)
  31. #define TASK_IS_32BIT_ADDR test_thread_flag(TIF_32BIT_ADDR)
  32. #endif
  33. #define VDSO_RANDOMIZE_SIZE (TASK_IS_32BIT_ADDR ? SZ_1M : SZ_64M)
  34. unsigned long stack_top(void);
  35. #define STACK_TOP stack_top()
  36. /*
  37. * This decides where the kernel will search for a free chunk of vm
  38. * space during mmap's.
  39. */
  40. #define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3)
  41. #define FPU_REG_WIDTH 256
  42. #define FPU_ALIGN __attribute__((aligned(32)))
  43. union fpureg {
  44. __u32 val32[FPU_REG_WIDTH / 32];
  45. __u64 val64[FPU_REG_WIDTH / 64];
  46. };
  47. #define FPR_IDX(width, idx) (idx)
  48. #define BUILD_FPR_ACCESS(width) \
  49. static inline u##width get_fpr##width(union fpureg *fpr, unsigned idx) \
  50. { \
  51. return fpr->val##width[FPR_IDX(width, idx)]; \
  52. } \
  53. \
  54. static inline void set_fpr##width(union fpureg *fpr, unsigned int idx, \
  55. u##width val) \
  56. { \
  57. fpr->val##width[FPR_IDX(width, idx)] = val; \
  58. }
  59. BUILD_FPR_ACCESS(32)
  60. BUILD_FPR_ACCESS(64)
  61. struct loongarch_fpu {
  62. uint64_t fcc; /* 8x8 */
  63. uint32_t fcsr;
  64. uint32_t ftop;
  65. union fpureg fpr[NUM_FPU_REGS];
  66. };
  67. struct loongarch_lbt {
  68. /* Scratch registers */
  69. unsigned long scr0;
  70. unsigned long scr1;
  71. unsigned long scr2;
  72. unsigned long scr3;
  73. /* Eflags register */
  74. unsigned long eflags;
  75. };
  76. #define INIT_CPUMASK { \
  77. {0,} \
  78. }
  79. #define ARCH_MIN_TASKALIGN 32
  80. struct loongarch_vdso_info;
  81. /*
  82. * If you change thread_struct remember to change the #defines below too!
  83. */
  84. struct thread_struct {
  85. /* Main processor registers. */
  86. unsigned long reg01, reg03, reg22; /* ra sp fp */
  87. unsigned long reg23, reg24, reg25, reg26; /* s0-s3 */
  88. unsigned long reg27, reg28, reg29, reg30, reg31; /* s4-s8 */
  89. /* __schedule() return address / call frame address */
  90. unsigned long sched_ra;
  91. unsigned long sched_cfa;
  92. /* CSR registers */
  93. unsigned long csr_prmd;
  94. unsigned long csr_crmd;
  95. unsigned long csr_euen;
  96. unsigned long csr_ecfg;
  97. unsigned long csr_badvaddr; /* Last user fault */
  98. /* Other stuff associated with the thread. */
  99. unsigned long trap_nr;
  100. unsigned long error_code;
  101. unsigned long single_step; /* Used by PTRACE_SINGLESTEP */
  102. struct loongarch_vdso_info *vdso;
  103. /*
  104. * FPU & vector registers, must be at the last of inherited
  105. * context because they are conditionally copied at fork().
  106. */
  107. struct loongarch_fpu fpu FPU_ALIGN;
  108. struct loongarch_lbt lbt; /* Also conditionally copied */
  109. /* Hardware breakpoints pinned to this task. */
  110. struct perf_event *hbp_break[LOONGARCH_MAX_BRP];
  111. struct perf_event *hbp_watch[LOONGARCH_MAX_WRP];
  112. };
  113. #define thread_saved_ra(tsk) (tsk->thread.sched_ra)
  114. #define thread_saved_fp(tsk) (tsk->thread.sched_cfa)
  115. #define INIT_THREAD { \
  116. /* \
  117. * Main processor registers \
  118. */ \
  119. .reg01 = 0, \
  120. .reg03 = 0, \
  121. .reg22 = 0, \
  122. .reg23 = 0, \
  123. .reg24 = 0, \
  124. .reg25 = 0, \
  125. .reg26 = 0, \
  126. .reg27 = 0, \
  127. .reg28 = 0, \
  128. .reg29 = 0, \
  129. .reg30 = 0, \
  130. .reg31 = 0, \
  131. .sched_ra = 0, \
  132. .sched_cfa = 0, \
  133. .csr_crmd = 0, \
  134. .csr_prmd = 0, \
  135. .csr_euen = 0, \
  136. .csr_ecfg = 0, \
  137. .csr_badvaddr = 0, \
  138. /* \
  139. * Other stuff associated with the process \
  140. */ \
  141. .trap_nr = 0, \
  142. .error_code = 0, \
  143. /* \
  144. * FPU & vector registers \
  145. */ \
  146. .fpu = { \
  147. .fcc = 0, \
  148. .fcsr = 0, \
  149. .ftop = 0, \
  150. .fpr = {{{0,},},}, \
  151. }, \
  152. .hbp_break = {0}, \
  153. .hbp_watch = {0}, \
  154. }
  155. struct task_struct;
  156. enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_HALT, IDLE_NOMWAIT, IDLE_POLL};
  157. extern unsigned long boot_option_idle_override;
  158. /*
  159. * Do necessary setup to start up a newly executed thread.
  160. */
  161. extern void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp);
  162. unsigned long __get_wchan(struct task_struct *p);
  163. #define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + \
  164. THREAD_SIZE - sizeof(struct pt_regs))
  165. #define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk))
  166. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->csr_era)
  167. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[3])
  168. #define KSTK_EUEN(tsk) (task_pt_regs(tsk)->csr_euen)
  169. #define KSTK_ECFG(tsk) (task_pt_regs(tsk)->csr_ecfg)
  170. #define return_address() ({__asm__ __volatile__("":::"$1"); __builtin_return_address(0);})
  171. #ifdef CONFIG_CPU_HAS_PREFETCH
  172. #define ARCH_HAS_PREFETCH
  173. #define prefetch(x) __builtin_prefetch((x), 0, 1)
  174. #define ARCH_HAS_PREFETCHW
  175. #define prefetchw(x) __builtin_prefetch((x), 1, 1)
  176. #endif
  177. #endif /* _ASM_PROCESSOR_H */