processor.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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) 2001 - 2008 Tensilica Inc.
  7. * Copyright (C) 2015 Cadence Design Systems Inc.
  8. */
  9. #ifndef _XTENSA_PROCESSOR_H
  10. #define _XTENSA_PROCESSOR_H
  11. #include <variant/core.h>
  12. #include <linux/compiler.h>
  13. #include <asm/ptrace.h>
  14. #include <asm/types.h>
  15. #include <asm/regs.h>
  16. /* Assertions. */
  17. #if (XCHAL_HAVE_WINDOWED != 1)
  18. # error Linux requires the Xtensa Windowed Registers Option.
  19. #endif
  20. /* Xtensa ABI requires stack alignment to be at least 16 */
  21. #define STACK_ALIGN (XCHAL_DATA_WIDTH > 16 ? XCHAL_DATA_WIDTH : 16)
  22. #define ARCH_SLAB_MINALIGN STACK_ALIGN
  23. /*
  24. * User space process size: 1 GB.
  25. * Windowed call ABI requires caller and callee to be located within the same
  26. * 1 GB region. The C compiler places trampoline code on the stack for sources
  27. * that take the address of a nested C function (a feature used by glibc), so
  28. * the 1 GB requirement applies to the stack as well.
  29. */
  30. #ifdef CONFIG_MMU
  31. #define TASK_SIZE __XTENSA_UL_CONST(0x40000000)
  32. #else
  33. #define TASK_SIZE __XTENSA_UL_CONST(0xffffffff)
  34. #endif
  35. #define STACK_TOP TASK_SIZE
  36. #define STACK_TOP_MAX STACK_TOP
  37. /*
  38. * General exception cause assigned to fake NMI. Fake NMI needs to be handled
  39. * differently from other interrupts, but it uses common kernel entry/exit
  40. * code.
  41. */
  42. #define EXCCAUSE_MAPPED_NMI 62
  43. /*
  44. * General exception cause assigned to debug exceptions. Debug exceptions go
  45. * to their own vector, rather than the general exception vectors (user,
  46. * kernel, double); and their specific causes are reported via DEBUGCAUSE
  47. * rather than EXCCAUSE. However it is sometimes convenient to redirect debug
  48. * exceptions to the general exception mechanism. To do this, an otherwise
  49. * unused EXCCAUSE value was assigned to debug exceptions for this purpose.
  50. */
  51. #define EXCCAUSE_MAPPED_DEBUG 63
  52. /*
  53. * We use DEPC also as a flag to distinguish between double and regular
  54. * exceptions. For performance reasons, DEPC might contain the value of
  55. * EXCCAUSE for regular exceptions, so we use this definition to mark a
  56. * valid double exception address.
  57. * (Note: We use it in bgeui, so it should be 64, 128, or 256)
  58. */
  59. #define VALID_DOUBLE_EXCEPTION_ADDRESS 64
  60. #define XTENSA_INT_LEVEL(intno) _XTENSA_INT_LEVEL(intno)
  61. #define _XTENSA_INT_LEVEL(intno) XCHAL_INT##intno##_LEVEL
  62. #define XTENSA_INTLEVEL_MASK(level) _XTENSA_INTLEVEL_MASK(level)
  63. #define _XTENSA_INTLEVEL_MASK(level) (XCHAL_INTLEVEL##level##_MASK)
  64. #define XTENSA_INTLEVEL_ANDBELOW_MASK(l) _XTENSA_INTLEVEL_ANDBELOW_MASK(l)
  65. #define _XTENSA_INTLEVEL_ANDBELOW_MASK(l) (XCHAL_INTLEVEL##l##_ANDBELOW_MASK)
  66. #define PROFILING_INTLEVEL XTENSA_INT_LEVEL(XCHAL_PROFILING_INTERRUPT)
  67. /* LOCKLEVEL defines the interrupt level that masks all
  68. * general-purpose interrupts.
  69. */
  70. #if defined(CONFIG_XTENSA_FAKE_NMI) && defined(XCHAL_PROFILING_INTERRUPT)
  71. #define LOCKLEVEL (PROFILING_INTLEVEL - 1)
  72. #else
  73. #define LOCKLEVEL XCHAL_EXCM_LEVEL
  74. #endif
  75. #define TOPLEVEL XCHAL_EXCM_LEVEL
  76. #define XTENSA_FAKE_NMI (LOCKLEVEL < TOPLEVEL)
  77. /* WSBITS and WBBITS are the width of the WINDOWSTART and WINDOWBASE
  78. * registers
  79. */
  80. #define WSBITS (XCHAL_NUM_AREGS / 4) /* width of WINDOWSTART in bits */
  81. #define WBBITS (XCHAL_NUM_AREGS_LOG2 - 2) /* width of WINDOWBASE in bits */
  82. #ifndef __ASSEMBLY__
  83. /* Build a valid return address for the specified call winsize.
  84. * winsize must be 1 (call4), 2 (call8), or 3 (call12)
  85. */
  86. #define MAKE_RA_FOR_CALL(ra,ws) (((ra) & 0x3fffffff) | (ws) << 30)
  87. /* Convert return address to a valid pc
  88. * Note: We assume that the stack pointer is in the same 1GB ranges as the ra
  89. */
  90. #define MAKE_PC_FROM_RA(ra,sp) (((ra) & 0x3fffffff) | ((sp) & 0xc0000000))
  91. /* Spill slot location for the register reg in the spill area under the stack
  92. * pointer sp. reg must be in the range [0..4).
  93. */
  94. #define SPILL_SLOT(sp, reg) (*(((unsigned long *)(sp)) - 4 + (reg)))
  95. /* Spill slot location for the register reg in the spill area under the stack
  96. * pointer sp for the call8. reg must be in the range [4..8).
  97. */
  98. #define SPILL_SLOT_CALL8(sp, reg) (*(((unsigned long *)(sp)) - 12 + (reg)))
  99. /* Spill slot location for the register reg in the spill area under the stack
  100. * pointer sp for the call12. reg must be in the range [4..12).
  101. */
  102. #define SPILL_SLOT_CALL12(sp, reg) (*(((unsigned long *)(sp)) - 16 + (reg)))
  103. typedef struct {
  104. unsigned long seg;
  105. } mm_segment_t;
  106. struct thread_struct {
  107. /* kernel's return address and stack pointer for context switching */
  108. unsigned long ra; /* kernel's a0: return address and window call size */
  109. unsigned long sp; /* kernel's a1: stack pointer */
  110. mm_segment_t current_ds; /* see uaccess.h for example uses */
  111. /* struct xtensa_cpuinfo info; */
  112. unsigned long bad_vaddr; /* last user fault */
  113. unsigned long bad_uaddr; /* last kernel fault accessing user space */
  114. unsigned long error_code;
  115. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  116. struct perf_event *ptrace_bp[XCHAL_NUM_IBREAK];
  117. struct perf_event *ptrace_wp[XCHAL_NUM_DBREAK];
  118. #endif
  119. /* Make structure 16 bytes aligned. */
  120. int align[0] __attribute__ ((aligned(16)));
  121. };
  122. /*
  123. * Default implementation of macro that returns current
  124. * instruction pointer ("program counter").
  125. */
  126. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  127. /* This decides where the kernel will search for a free chunk of vm
  128. * space during mmap's.
  129. */
  130. #define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
  131. #define INIT_THREAD \
  132. { \
  133. ra: 0, \
  134. sp: sizeof(init_stack) + (long) &init_stack, \
  135. current_ds: {0}, \
  136. /*info: {0}, */ \
  137. bad_vaddr: 0, \
  138. bad_uaddr: 0, \
  139. error_code: 0, \
  140. }
  141. /*
  142. * Do necessary setup to start up a newly executed thread.
  143. * Note: We set-up ps as if we did a call4 to the new pc.
  144. * set_thread_state in signal.c depends on it.
  145. */
  146. #define USER_PS_VALUE ((1 << PS_WOE_BIT) | \
  147. (1 << PS_CALLINC_SHIFT) | \
  148. (USER_RING << PS_RING_SHIFT) | \
  149. (1 << PS_UM_BIT) | \
  150. (1 << PS_EXCM_BIT))
  151. /* Clearing a0 terminates the backtrace. */
  152. #define start_thread(regs, new_pc, new_sp) \
  153. memset(regs, 0, sizeof(*regs)); \
  154. regs->pc = new_pc; \
  155. regs->ps = USER_PS_VALUE; \
  156. regs->areg[1] = new_sp; \
  157. regs->areg[0] = 0; \
  158. regs->wmask = 1; \
  159. regs->depc = 0; \
  160. regs->windowbase = 0; \
  161. regs->windowstart = 1;
  162. /* Forward declaration */
  163. struct task_struct;
  164. struct mm_struct;
  165. /* Free all resources held by a thread. */
  166. #define release_thread(thread) do { } while(0)
  167. extern unsigned long get_wchan(struct task_struct *p);
  168. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
  169. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->areg[1])
  170. #define cpu_relax() barrier()
  171. /* Special register access. */
  172. #define WSR(v,sr) __asm__ __volatile__ ("wsr %0,"__stringify(sr) :: "a"(v));
  173. #define RSR(v,sr) __asm__ __volatile__ ("rsr %0,"__stringify(sr) : "=a"(v));
  174. #define set_sr(x,sr) ({unsigned int v=(unsigned int)x; WSR(v,sr);})
  175. #define get_sr(sr) ({unsigned int v; RSR(v,sr); v; })
  176. #ifndef XCHAL_HAVE_EXTERN_REGS
  177. #define XCHAL_HAVE_EXTERN_REGS 0
  178. #endif
  179. #if XCHAL_HAVE_EXTERN_REGS
  180. static inline void set_er(unsigned long value, unsigned long addr)
  181. {
  182. asm volatile ("wer %0, %1" : : "a" (value), "a" (addr) : "memory");
  183. }
  184. static inline unsigned long get_er(unsigned long addr)
  185. {
  186. register unsigned long value;
  187. asm volatile ("rer %0, %1" : "=a" (value) : "a" (addr) : "memory");
  188. return value;
  189. }
  190. #endif /* XCHAL_HAVE_EXTERN_REGS */
  191. #endif /* __ASSEMBLY__ */
  192. #endif /* _XTENSA_PROCESSOR_H */