processor.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 Waldorf GMBH
  7. * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001 Ralf Baechle
  8. * Copyright (C) 1996 Paul M. Antoine
  9. * Copyright (C) 1999 Silicon Graphics, Inc.
  10. */
  11. #ifndef _ASM_PROCESSOR_H
  12. #define _ASM_PROCESSOR_H
  13. #include <linux/config.h>
  14. #include <asm/isadep.h>
  15. /*
  16. * Default implementation of macro that returns current
  17. * instruction pointer ("program counter").
  18. */
  19. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  20. #if !defined (_LANGUAGE_ASSEMBLY)
  21. #if 0
  22. #include <linux/threads.h>
  23. #endif
  24. #include <asm/cachectl.h>
  25. #include <asm/mipsregs.h>
  26. #include <asm/reg.h>
  27. #include <asm/system.h>
  28. struct mips_cpuinfo {
  29. unsigned long udelay_val;
  30. unsigned long *pgd_quick;
  31. unsigned long *pte_quick;
  32. unsigned long pgtable_cache_sz;
  33. };
  34. /*
  35. * System setup and hardware flags..
  36. * XXX: Should go into mips_cpuinfo.
  37. */
  38. extern void (*cpu_wait)(void); /* only available on R4[26]00 and R3081 */
  39. extern void r3081_wait(void);
  40. extern void r4k_wait(void);
  41. extern char cyclecounter_available; /* only available from R4000 upwards. */
  42. extern struct mips_cpuinfo boot_cpu_data;
  43. extern unsigned int vced_count, vcei_count;
  44. #ifdef CONFIG_SMP
  45. extern struct mips_cpuinfo cpu_data[];
  46. #define current_cpu_data cpu_data[smp_processor_id()]
  47. #else
  48. #define cpu_data &boot_cpu_data
  49. #define current_cpu_data boot_cpu_data
  50. #endif
  51. /*
  52. * Bus types (default is ISA, but people can check others with these..)
  53. * MCA_bus hardcoded to 0 for now.
  54. *
  55. * This needs to be extended since MIPS systems are being delivered with
  56. * numerous different types of bus systems.
  57. */
  58. extern int EISA_bus;
  59. #define MCA_bus 0
  60. #define MCA_bus__is_a_macro /* for versions in ksyms.c */
  61. /*
  62. * MIPS has no problems with write protection
  63. */
  64. #define wp_works_ok 1
  65. #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
  66. /* Lazy FPU handling on uni-processor */
  67. extern struct task_struct *last_task_used_math;
  68. /*
  69. * User space process size: 2GB. This is hardcoded into a few places,
  70. * so don't change it unless you know what you are doing. TASK_SIZE
  71. * for a 64 bit kernel expandable to 8192EB, of which the current MIPS
  72. * implementations will "only" be able to use 1TB ...
  73. */
  74. #define TASK_SIZE (0x7fff8000UL)
  75. /* This decides where the kernel will search for a free chunk of vm
  76. * space during mmap's.
  77. */
  78. #define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
  79. /*
  80. * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
  81. */
  82. #define IO_BITMAP_SIZE 32
  83. #define NUM_FPU_REGS 32
  84. struct mips_fpu_hard_struct {
  85. double fp_regs[NUM_FPU_REGS];
  86. unsigned int control;
  87. };
  88. /*
  89. * It would be nice to add some more fields for emulator statistics, but there
  90. * are a number of fixed offsets in offset.h and elsewhere that would have to
  91. * be recalculated by hand. So the additional information will be private to
  92. * the FPU emulator for now. See asm-mips/fpu_emulator.h.
  93. */
  94. typedef u64 fpureg_t;
  95. struct mips_fpu_soft_struct {
  96. fpureg_t regs[NUM_FPU_REGS];
  97. unsigned int sr;
  98. };
  99. union mips_fpu_union {
  100. struct mips_fpu_hard_struct hard;
  101. struct mips_fpu_soft_struct soft;
  102. };
  103. #define INIT_FPU { \
  104. {{0,},} \
  105. }
  106. typedef struct {
  107. unsigned long seg;
  108. } mm_segment_t;
  109. /*
  110. * If you change thread_struct remember to change the #defines below too!
  111. */
  112. struct thread_struct {
  113. /* Saved main processor registers. */
  114. unsigned long reg16;
  115. unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
  116. unsigned long reg29, reg30, reg31;
  117. /* Saved cp0 stuff. */
  118. unsigned long cp0_status;
  119. /* Saved fpu/fpu emulator stuff. */
  120. union mips_fpu_union fpu;
  121. /* Other stuff associated with the thread. */
  122. unsigned long cp0_badvaddr; /* Last user fault */
  123. unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
  124. unsigned long error_code;
  125. unsigned long trap_no;
  126. #define MF_FIXADE 1 /* Fix address errors in software */
  127. #define MF_LOGADE 2 /* Log address errors to syslog */
  128. unsigned long mflags;
  129. mm_segment_t current_ds;
  130. unsigned long irix_trampoline; /* Wheee... */
  131. unsigned long irix_oldctx;
  132. /*
  133. * These are really only needed if the full FPU emulator is configured.
  134. * Would be made conditional on MIPS_FPU_EMULATOR if it weren't for the
  135. * fact that having offset.h rebuilt differently for different config
  136. * options would be asking for trouble.
  137. *
  138. * Saved EPC during delay-slot emulation (see math-emu/cp1emu.c)
  139. */
  140. unsigned long dsemul_epc;
  141. /*
  142. * Pointer to instruction used to induce address error
  143. */
  144. unsigned long dsemul_aerpc;
  145. };
  146. #endif /* !defined (_LANGUAGE_ASSEMBLY) */
  147. #define INIT_THREAD { \
  148. /* \
  149. * saved main processor registers \
  150. */ \
  151. 0, 0, 0, 0, 0, 0, 0, 0, \
  152. 0, 0, 0, \
  153. /* \
  154. * saved cp0 stuff \
  155. */ \
  156. 0, \
  157. /* \
  158. * saved fpu/fpu emulator stuff \
  159. */ \
  160. INIT_FPU, \
  161. /* \
  162. * Other stuff associated with the process \
  163. */ \
  164. 0, 0, 0, 0, \
  165. /* \
  166. * For now the default is to fix address errors \
  167. */ \
  168. MF_FIXADE, { 0 }, 0, 0, \
  169. /* \
  170. * dsemul_epc and dsemul_aerpc should never be used uninitialized, \
  171. * but... \
  172. */ \
  173. 0 ,0 \
  174. }
  175. #ifdef __KERNEL__
  176. #define KERNEL_STACK_SIZE 8192
  177. #if !defined (_LANGUAGE_ASSEMBLY)
  178. /* Free all resources held by a thread. */
  179. #define release_thread(thread) do { } while(0)
  180. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  181. /* Copy and release all segment info associated with a VM */
  182. #define copy_segments(p, mm) do { } while(0)
  183. #define release_segments(mm) do { } while(0)
  184. /*
  185. * Return saved PC of a blocked thread.
  186. */
  187. extern inline unsigned long thread_saved_pc(struct thread_struct *t)
  188. {
  189. extern void ret_from_fork(void);
  190. /* New born processes are a special case */
  191. if (t->reg31 == (unsigned long) ret_from_fork)
  192. return t->reg31;
  193. return ((unsigned long *)t->reg29)[10];
  194. }
  195. /*
  196. * Do necessary setup to start up a newly executed thread.
  197. */
  198. #define start_thread(regs, new_pc, new_sp) do { \
  199. /* New thread looses kernel privileges. */ \
  200. regs->cp0_status = (regs->cp0_status & ~(ST0_CU0|ST0_KSU)) | KU_USER;\
  201. regs->cp0_epc = new_pc; \
  202. regs->regs[29] = new_sp; \
  203. current->thread.current_ds = USER_DS; \
  204. } while (0)
  205. unsigned long get_wchan(struct task_struct *p);
  206. #define __PT_REG(reg) ((long)&((struct pt_regs *)0)->reg - sizeof(struct pt_regs))
  207. #define __KSTK_TOS(tsk) ((unsigned long)(tsk) + KERNEL_STACK_SIZE - 32)
  208. #define KSTK_EIP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_epc)))
  209. #define KSTK_ESP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(regs[29])))
  210. /* Allocation and freeing of basic task resources. */
  211. /*
  212. * NOTE! The task struct and the stack go together
  213. */
  214. #define THREAD_SIZE (2*PAGE_SIZE)
  215. #define alloc_task_struct() \
  216. ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
  217. #define free_task_struct(p) free_pages((unsigned long)(p),1)
  218. #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
  219. #define init_task (init_task_union.task)
  220. #define init_stack (init_task_union.stack)
  221. #define cpu_relax() do { } while (0)
  222. #endif /* !defined (_LANGUAGE_ASSEMBLY) */
  223. #endif /* __KERNEL__ */
  224. /*
  225. * Return_address is a replacement for __builtin_return_address(count)
  226. * which on certain architectures cannot reasonably be implemented in GCC
  227. * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
  228. * Note that __builtin_return_address(x>=1) is forbidden because GCC
  229. * aborts compilation on some CPUs. It's simply not possible to unwind
  230. * some CPU's stackframes.
  231. *
  232. * __builtin_return_address works only for non-leaf functions. We avoid the
  233. * overhead of a function call by forcing the compiler to save the return
  234. * address register on the stack.
  235. */
  236. #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
  237. #endif /* _ASM_PROCESSOR_H */