/arch/sh/include/asm/processor_64.h

http://github.com/mirrors/linux · C Header · 212 lines · 102 code · 37 blank · 73 comment · 1 complexity · 12b2661bd526ac534f2fa7a12221bbef MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_PROCESSOR_64_H
  3. #define __ASM_SH_PROCESSOR_64_H
  4. /*
  5. * include/asm-sh/processor_64.h
  6. *
  7. * Copyright (C) 2000, 2001 Paolo Alberelli
  8. * Copyright (C) 2003 Paul Mundt
  9. * Copyright (C) 2004 Richard Curnow
  10. */
  11. #ifndef __ASSEMBLY__
  12. #include <linux/compiler.h>
  13. #include <asm/page.h>
  14. #include <asm/types.h>
  15. #include <cpu/registers.h>
  16. #endif
  17. /*
  18. * User space process size: 2GB - 4k.
  19. */
  20. #define TASK_SIZE 0x7ffff000UL
  21. #define STACK_TOP TASK_SIZE
  22. #define STACK_TOP_MAX STACK_TOP
  23. /* This decides where the kernel will search for a free chunk of vm
  24. * space during mmap's.
  25. */
  26. #define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3)
  27. /*
  28. * Bit of SR register
  29. *
  30. * FD-bit:
  31. * When it's set, it means the processor doesn't have right to use FPU,
  32. * and it results exception when the floating operation is executed.
  33. *
  34. * IMASK-bit:
  35. * Interrupt level mask
  36. *
  37. * STEP-bit:
  38. * Single step bit
  39. *
  40. */
  41. #if defined(CONFIG_SH64_SR_WATCH)
  42. #define SR_MMU 0x84000000
  43. #else
  44. #define SR_MMU 0x80000000
  45. #endif
  46. #define SR_IMASK 0x000000f0
  47. #define SR_FD 0x00008000
  48. #define SR_SSTEP 0x08000000
  49. #ifndef __ASSEMBLY__
  50. /*
  51. * FPU structure and data : require 8-byte alignment as we need to access it
  52. with fld.p, fst.p
  53. */
  54. struct sh_fpu_hard_struct {
  55. unsigned long fp_regs[64];
  56. unsigned int fpscr;
  57. /* long status; * software status information */
  58. };
  59. /* Dummy fpu emulator */
  60. struct sh_fpu_soft_struct {
  61. unsigned long fp_regs[64];
  62. unsigned int fpscr;
  63. unsigned char lookahead;
  64. unsigned long entry_pc;
  65. };
  66. union thread_xstate {
  67. struct sh_fpu_hard_struct hardfpu;
  68. struct sh_fpu_soft_struct softfpu;
  69. /*
  70. * The structure definitions only produce 32 bit alignment, yet we need
  71. * to access them using 64 bit load/store as well.
  72. */
  73. unsigned long long alignment_dummy;
  74. };
  75. struct thread_struct {
  76. unsigned long sp;
  77. unsigned long pc;
  78. /* Various thread flags, see SH_THREAD_xxx */
  79. unsigned long flags;
  80. /* This stores the address of the pt_regs built during a context
  81. switch, or of the register save area built for a kernel mode
  82. exception. It is used for backtracing the stack of a sleeping task
  83. or one that traps in kernel mode. */
  84. struct pt_regs *kregs;
  85. /* This stores the address of the pt_regs constructed on entry from
  86. user mode. It is a fixed value over the lifetime of a process, or
  87. NULL for a kernel thread. */
  88. struct pt_regs *uregs;
  89. unsigned long address;
  90. /* Hardware debugging registers may come here */
  91. /* floating point info */
  92. union thread_xstate *xstate;
  93. /*
  94. * fpu_counter contains the number of consecutive context switches
  95. * that the FPU is used. If this is over a threshold, the lazy fpu
  96. * saving becomes unlazy to save the trap. This is an unsigned char
  97. * so that after 256 times the counter wraps and the behavior turns
  98. * lazy again; this to deal with bursty apps that only use FPU for
  99. * a short time
  100. */
  101. unsigned char fpu_counter;
  102. };
  103. #define INIT_MMAP \
  104. { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
  105. #define INIT_THREAD { \
  106. .sp = sizeof(init_stack) + \
  107. (long) &init_stack, \
  108. .pc = 0, \
  109. .kregs = &fake_swapper_regs, \
  110. .uregs = NULL, \
  111. .address = 0, \
  112. .flags = 0, \
  113. }
  114. /*
  115. * Do necessary setup to start up a newly executed thread.
  116. */
  117. #define SR_USER (SR_MMU | SR_FD)
  118. #define start_thread(_regs, new_pc, new_sp) \
  119. _regs->sr = SR_USER; /* User mode. */ \
  120. _regs->pc = new_pc - 4; /* Compensate syscall exit */ \
  121. _regs->pc |= 1; /* Set SHmedia ! */ \
  122. _regs->regs[18] = 0; \
  123. _regs->regs[15] = new_sp
  124. /* Forward declaration, a strange C thing */
  125. struct task_struct;
  126. struct mm_struct;
  127. /* Free all resources held by a thread. */
  128. extern void release_thread(struct task_struct *);
  129. /*
  130. * FPU lazy state save handling.
  131. */
  132. static inline void disable_fpu(void)
  133. {
  134. unsigned long long __dummy;
  135. /* Set FD flag in SR */
  136. __asm__ __volatile__("getcon " __SR ", %0\n\t"
  137. "or %0, %1, %0\n\t"
  138. "putcon %0, " __SR "\n\t"
  139. : "=&r" (__dummy)
  140. : "r" (SR_FD));
  141. }
  142. static inline void enable_fpu(void)
  143. {
  144. unsigned long long __dummy;
  145. /* Clear out FD flag in SR */
  146. __asm__ __volatile__("getcon " __SR ", %0\n\t"
  147. "and %0, %1, %0\n\t"
  148. "putcon %0, " __SR "\n\t"
  149. : "=&r" (__dummy)
  150. : "r" (~SR_FD));
  151. }
  152. /* Round to nearest, no exceptions on inexact, overflow, underflow,
  153. zero-divide, invalid. Configure option for whether to flush denorms to
  154. zero, or except if a denorm is encountered. */
  155. #if defined(CONFIG_SH64_FPU_DENORM_FLUSH)
  156. #define FPSCR_INIT 0x00040000
  157. #else
  158. #define FPSCR_INIT 0x00000000
  159. #endif
  160. #ifdef CONFIG_SH_FPU
  161. /* Initialise the FP state of a task */
  162. void fpinit(struct sh_fpu_hard_struct *fpregs);
  163. #else
  164. #define fpinit(fpregs) do { } while (0)
  165. #endif
  166. extern struct task_struct *last_task_used_math;
  167. /*
  168. * Return saved PC of a blocked thread.
  169. */
  170. #define thread_saved_pc(tsk) (tsk->thread.pc)
  171. extern unsigned long get_wchan(struct task_struct *p);
  172. #define KSTK_EIP(tsk) ((tsk)->thread.pc)
  173. #define KSTK_ESP(tsk) ((tsk)->thread.sp)
  174. #endif /* __ASSEMBLY__ */
  175. #endif /* __ASM_SH_PROCESSOR_64_H */