processor.h 7.0 KB

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