processor.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #ifndef __ASM_SH64_PROCESSOR_H
  2. #define __ASM_SH64_PROCESSOR_H
  3. /*
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * include/asm-sh64/processor.h
  9. *
  10. * Copyright (C) 2000, 2001 Paolo Alberelli
  11. * Copyright (C) 2003 Paul Mundt
  12. * Copyright (C) 2004 Richard Curnow
  13. *
  14. */
  15. #include <asm/page.h>
  16. #ifndef __ASSEMBLY__
  17. #include <asm/types.h>
  18. #include <asm/cache.h>
  19. #include <asm/registers.h>
  20. #include <linux/threads.h>
  21. #include <linux/compiler.h>
  22. /*
  23. * Default implementation of macro that returns current
  24. * instruction pointer ("program counter").
  25. */
  26. #define current_text_addr() ({ \
  27. void *pc; \
  28. unsigned long long __dummy = 0; \
  29. __asm__("gettr tr0, %1\n\t" \
  30. "pta 4, tr0\n\t" \
  31. "gettr tr0, %0\n\t" \
  32. "ptabs %1, tr0\n\t" \
  33. :"=r" (pc), "=r" (__dummy) \
  34. : "1" (__dummy)); \
  35. pc; })
  36. /*
  37. * CPU type and hardware bug flags. Kept separately for each CPU.
  38. */
  39. enum cpu_type {
  40. CPU_SH5_101,
  41. CPU_SH5_103,
  42. CPU_SH_NONE
  43. };
  44. /*
  45. * TLB information structure
  46. *
  47. * Defined for both I and D tlb, per-processor.
  48. */
  49. struct tlb_info {
  50. unsigned long long next;
  51. unsigned long long first;
  52. unsigned long long last;
  53. unsigned int entries;
  54. unsigned int step;
  55. unsigned long flags;
  56. };
  57. struct sh_cpuinfo {
  58. enum cpu_type type;
  59. unsigned long loops_per_jiffy;
  60. char hard_math;
  61. unsigned long *pgd_quick;
  62. unsigned long *pmd_quick;
  63. unsigned long *pte_quick;
  64. unsigned long pgtable_cache_sz;
  65. unsigned int cpu_clock, master_clock, bus_clock, module_clock;
  66. /* Cache info */
  67. struct cache_info icache;
  68. struct cache_info dcache;
  69. /* TLB info */
  70. struct tlb_info itlb;
  71. struct tlb_info dtlb;
  72. };
  73. extern struct sh_cpuinfo boot_cpu_data;
  74. #define cpu_data (&boot_cpu_data)
  75. #define current_cpu_data boot_cpu_data
  76. #endif
  77. /*
  78. * User space process size: 2GB - 4k.
  79. */
  80. #define TASK_SIZE 0x7ffff000UL
  81. /* This decides where the kernel will search for a free chunk of vm
  82. * space during mmap's.
  83. */
  84. #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
  85. /*
  86. * Bit of SR register
  87. *
  88. * FD-bit:
  89. * When it's set, it means the processor doesn't have right to use FPU,
  90. * and it results exception when the floating operation is executed.
  91. *
  92. * IMASK-bit:
  93. * Interrupt level mask
  94. *
  95. * STEP-bit:
  96. * Single step bit
  97. *
  98. */
  99. #define SR_FD 0x00008000
  100. #if defined(CONFIG_SH64_SR_WATCH)
  101. #define SR_MMU 0x84000000
  102. #else
  103. #define SR_MMU 0x80000000
  104. #endif
  105. #define SR_IMASK 0x000000f0
  106. #define SR_SSTEP 0x08000000
  107. #ifndef __ASSEMBLY__
  108. /*
  109. * FPU structure and data : require 8-byte alignment as we need to access it
  110. with fld.p, fst.p
  111. */
  112. struct sh_fpu_hard_struct {
  113. unsigned long fp_regs[64];
  114. unsigned int fpscr;
  115. /* long status; * software status information */
  116. };
  117. #if 0
  118. /* Dummy fpu emulator */
  119. struct sh_fpu_soft_struct {
  120. unsigned long long fp_regs[32];
  121. unsigned int fpscr;
  122. unsigned char lookahead;
  123. unsigned long entry_pc;
  124. };
  125. #endif
  126. union sh_fpu_union {
  127. struct sh_fpu_hard_struct hard;
  128. /* 'hard' itself only produces 32 bit alignment, yet we need
  129. to access it using 64 bit load/store as well. */
  130. unsigned long long alignment_dummy;
  131. };
  132. struct thread_struct {
  133. unsigned long sp;
  134. unsigned long pc;
  135. /* This stores the address of the pt_regs built during a context
  136. switch, or of the register save area built for a kernel mode
  137. exception. It is used for backtracing the stack of a sleeping task
  138. or one that traps in kernel mode. */
  139. struct pt_regs *kregs;
  140. /* This stores the address of the pt_regs constructed on entry from
  141. user mode. It is a fixed value over the lifetime of a process, or
  142. NULL for a kernel thread. */
  143. struct pt_regs *uregs;
  144. unsigned long trap_no, error_code;
  145. unsigned long address;
  146. /* Hardware debugging registers may come here */
  147. /* floating point info */
  148. union sh_fpu_union fpu;
  149. };
  150. #define INIT_MMAP \
  151. { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
  152. extern struct pt_regs fake_swapper_regs;
  153. #define INIT_THREAD { \
  154. .sp = sizeof(init_stack) + \
  155. (long) &init_stack, \
  156. .pc = 0, \
  157. .kregs = &fake_swapper_regs, \
  158. .uregs = NULL, \
  159. .trap_no = 0, \
  160. .error_code = 0, \
  161. .address = 0, \
  162. .fpu = { { { 0, } }, } \
  163. }
  164. /*
  165. * Do necessary setup to start up a newly executed thread.
  166. */
  167. #define SR_USER (SR_MMU | SR_FD)
  168. #define start_thread(regs, new_pc, new_sp) \
  169. set_fs(USER_DS); \
  170. regs->sr = SR_USER; /* User mode. */ \
  171. regs->pc = new_pc - 4; /* Compensate syscall exit */ \
  172. regs->pc |= 1; /* Set SHmedia ! */ \
  173. regs->regs[18] = 0; \
  174. regs->regs[15] = new_sp
  175. /* Forward declaration, a strange C thing */
  176. struct task_struct;
  177. struct mm_struct;
  178. /* Free all resources held by a thread. */
  179. extern void release_thread(struct task_struct *);
  180. /*
  181. * create a kernel thread without removing it from tasklists
  182. */
  183. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  184. /* Copy and release all segment info associated with a VM */
  185. #define copy_segments(p, mm) do { } while (0)
  186. #define release_segments(mm) do { } while (0)
  187. #define forget_segments() do { } while (0)
  188. #define prepare_to_copy(tsk) do { } while (0)
  189. /*
  190. * FPU lazy state save handling.
  191. */
  192. static inline void release_fpu(void)
  193. {
  194. unsigned long long __dummy;
  195. /* Set FD flag in SR */
  196. __asm__ __volatile__("getcon " __SR ", %0\n\t"
  197. "or %0, %1, %0\n\t"
  198. "putcon %0, " __SR "\n\t"
  199. : "=&r" (__dummy)
  200. : "r" (SR_FD));
  201. }
  202. static inline void grab_fpu(void)
  203. {
  204. unsigned long long __dummy;
  205. /* Clear out FD flag in SR */
  206. __asm__ __volatile__("getcon " __SR ", %0\n\t"
  207. "and %0, %1, %0\n\t"
  208. "putcon %0, " __SR "\n\t"
  209. : "=&r" (__dummy)
  210. : "r" (~SR_FD));
  211. }
  212. /* Round to nearest, no exceptions on inexact, overflow, underflow,
  213. zero-divide, invalid. Configure option for whether to flush denorms to
  214. zero, or except if a denorm is encountered. */
  215. #if defined(CONFIG_SH64_FPU_DENORM_FLUSH)
  216. #define FPSCR_INIT 0x00040000
  217. #else
  218. #define FPSCR_INIT 0x00000000
  219. #endif
  220. /* Save the current FP regs */
  221. void fpsave(struct sh_fpu_hard_struct *fpregs);
  222. /* Initialise the FP state of a task */
  223. void fpinit(struct sh_fpu_hard_struct *fpregs);
  224. extern struct task_struct *last_task_used_math;
  225. /*
  226. * Return saved PC of a blocked thread.
  227. */
  228. #define thread_saved_pc(tsk) (tsk->thread.pc)
  229. extern unsigned long get_wchan(struct task_struct *p);
  230. #define KSTK_EIP(tsk) ((tsk)->thread.pc)
  231. #define KSTK_ESP(tsk) ((tsk)->thread.sp)
  232. #define cpu_relax() barrier()
  233. #endif /* __ASSEMBLY__ */
  234. #endif /* __ASM_SH64_PROCESSOR_H */