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