processor.h 7.1 KB

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