processor.h 6.5 KB

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