processor.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * include/asm-xtensa/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. * Copyright (C) 2001 - 2005 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_PROCESSOR_H
  11. #define _XTENSA_PROCESSOR_H
  12. #include <variant/core.h>
  13. #include <platform/hardware.h>
  14. #include <linux/compiler.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/types.h>
  17. #include <asm/regs.h>
  18. /* Assertions. */
  19. #if (XCHAL_HAVE_WINDOWED != 1)
  20. # error Linux requires the Xtensa Windowed Registers Option.
  21. #endif
  22. #define ARCH_SLAB_MINALIGN XCHAL_DATA_WIDTH
  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 (PLATFORM_DEFAULT_MEM_START + PLATFORM_DEFAULT_MEM_SIZE)
  34. #endif
  35. #define STACK_TOP TASK_SIZE
  36. #define STACK_TOP_MAX STACK_TOP
  37. /*
  38. * General exception cause assigned to debug exceptions. Debug exceptions go
  39. * to their own vector, rather than the general exception vectors (user,
  40. * kernel, double); and their specific causes are reported via DEBUGCAUSE
  41. * rather than EXCCAUSE. However it is sometimes convenient to redirect debug
  42. * exceptions to the general exception mechanism. To do this, an otherwise
  43. * unused EXCCAUSE value was assigned to debug exceptions for this purpose.
  44. */
  45. #define EXCCAUSE_MAPPED_DEBUG 63
  46. /*
  47. * We use DEPC also as a flag to distinguish between double and regular
  48. * exceptions. For performance reasons, DEPC might contain the value of
  49. * EXCCAUSE for regular exceptions, so we use this definition to mark a
  50. * valid double exception address.
  51. * (Note: We use it in bgeui, so it should be 64, 128, or 256)
  52. */
  53. #define VALID_DOUBLE_EXCEPTION_ADDRESS 64
  54. /* LOCKLEVEL defines the interrupt level that masks all
  55. * general-purpose interrupts.
  56. */
  57. #define LOCKLEVEL 1
  58. /* WSBITS and WBBITS are the width of the WINDOWSTART and WINDOWBASE
  59. * registers
  60. */
  61. #define WSBITS (XCHAL_NUM_AREGS / 4) /* width of WINDOWSTART in bits */
  62. #define WBBITS (XCHAL_NUM_AREGS_LOG2 - 2) /* width of WINDOWBASE in bits */
  63. #ifndef __ASSEMBLY__
  64. /* Build a valid return address for the specified call winsize.
  65. * winsize must be 1 (call4), 2 (call8), or 3 (call12)
  66. */
  67. #define MAKE_RA_FOR_CALL(ra,ws) (((ra) & 0x3fffffff) | (ws) << 30)
  68. /* Convert return address to a valid pc
  69. * Note: We assume that the stack pointer is in the same 1GB ranges as the ra
  70. */
  71. #define MAKE_PC_FROM_RA(ra,sp) (((ra) & 0x3fffffff) | ((sp) & 0xc0000000))
  72. typedef struct {
  73. unsigned long seg;
  74. } mm_segment_t;
  75. struct thread_struct {
  76. /* kernel's return address and stack pointer for context switching */
  77. unsigned long ra; /* kernel's a0: return address and window call size */
  78. unsigned long sp; /* kernel's a1: stack pointer */
  79. mm_segment_t current_ds; /* see uaccess.h for example uses */
  80. /* struct xtensa_cpuinfo info; */
  81. unsigned long bad_vaddr; /* last user fault */
  82. unsigned long bad_uaddr; /* last kernel fault accessing user space */
  83. unsigned long error_code;
  84. unsigned long ibreak[XCHAL_NUM_IBREAK];
  85. unsigned long dbreaka[XCHAL_NUM_DBREAK];
  86. unsigned long dbreakc[XCHAL_NUM_DBREAK];
  87. /* Make structure 16 bytes aligned. */
  88. int align[0] __attribute__ ((aligned(16)));
  89. };
  90. /*
  91. * Default implementation of macro that returns current
  92. * instruction pointer ("program counter").
  93. */
  94. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  95. /* This decides where the kernel will search for a free chunk of vm
  96. * space during mmap's.
  97. */
  98. #define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
  99. #define INIT_THREAD \
  100. { \
  101. ra: 0, \
  102. sp: sizeof(init_stack) + (long) &init_stack, \
  103. current_ds: {0}, \
  104. /*info: {0}, */ \
  105. bad_vaddr: 0, \
  106. bad_uaddr: 0, \
  107. error_code: 0, \
  108. }
  109. /*
  110. * Do necessary setup to start up a newly executed thread.
  111. * Note: We set-up ps as if we did a call4 to the new pc.
  112. * set_thread_state in signal.c depends on it.
  113. */
  114. #define USER_PS_VALUE ((1 << PS_WOE_BIT) | \
  115. (1 << PS_CALLINC_SHIFT) | \
  116. (USER_RING << PS_RING_SHIFT) | \
  117. (1 << PS_UM_BIT) | \
  118. (1 << PS_EXCM_BIT))
  119. /* Clearing a0 terminates the backtrace. */
  120. #define start_thread(regs, new_pc, new_sp) \
  121. regs->pc = new_pc; \
  122. regs->ps = USER_PS_VALUE; \
  123. regs->areg[1] = new_sp; \
  124. regs->areg[0] = 0; \
  125. regs->wmask = 1; \
  126. regs->depc = 0; \
  127. regs->windowbase = 0; \
  128. regs->windowstart = 1;
  129. /* Forward declaration */
  130. struct task_struct;
  131. struct mm_struct;
  132. /* Free all resources held by a thread. */
  133. #define release_thread(thread) do { } while(0)
  134. /* Prepare to copy thread state - unlazy all lazy status */
  135. extern void prepare_to_copy(struct task_struct*);
  136. /* Create a kernel thread without removing it from tasklists */
  137. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  138. /* Copy and release all segment info associated with a VM */
  139. #define copy_segments(p, mm) do { } while(0)
  140. #define release_segments(mm) do { } while(0)
  141. #define forget_segments() do { } while (0)
  142. #define thread_saved_pc(tsk) (task_pt_regs(tsk)->pc)
  143. extern unsigned long get_wchan(struct task_struct *p);
  144. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
  145. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->areg[1])
  146. #define cpu_relax() barrier()
  147. /* Special register access. */
  148. #define WSR(v,sr) __asm__ __volatile__ ("wsr %0,"__stringify(sr) :: "a"(v));
  149. #define RSR(v,sr) __asm__ __volatile__ ("rsr %0,"__stringify(sr) : "=a"(v));
  150. #define set_sr(x,sr) ({unsigned int v=(unsigned int)x; WSR(v,sr);})
  151. #define get_sr(sr) ({unsigned int v; RSR(v,sr); v; })
  152. #endif /* __ASSEMBLY__ */
  153. #endif /* _XTENSA_PROCESSOR_H */