processor_64.h 5.7 KB

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