processor.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #ifdef __ASSEMBLY__
  13. #define _ASMLANGUAGE
  14. #endif
  15. #include <xtensa/config/core.h>
  16. #include <xtensa/config/specreg.h>
  17. #include <xtensa/config/tie.h>
  18. #include <xtensa/config/system.h>
  19. #include <linux/compiler.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/types.h>
  22. #include <asm/coprocessor.h>
  23. /* Assertions. */
  24. #if (XCHAL_HAVE_WINDOWED != 1)
  25. #error Linux requires the Xtensa Windowed Registers Option.
  26. #endif
  27. /*
  28. * User space process size: 1 GB.
  29. * Windowed call ABI requires caller and callee to be located within the same
  30. * 1 GB region. The C compiler places trampoline code on the stack for sources
  31. * that take the address of a nested C function (a feature used by glibc), so
  32. * the 1 GB requirement applies to the stack as well.
  33. */
  34. #define TASK_SIZE 0x40000000
  35. /*
  36. * General exception cause assigned to debug exceptions. Debug exceptions go
  37. * to their own vector, rather than the general exception vectors (user,
  38. * kernel, double); and their specific causes are reported via DEBUGCAUSE
  39. * rather than EXCCAUSE. However it is sometimes convenient to redirect debug
  40. * exceptions to the general exception mechanism. To do this, an otherwise
  41. * unused EXCCAUSE value was assigned to debug exceptions for this purpose.
  42. */
  43. #define EXCCAUSE_MAPPED_DEBUG 63
  44. /*
  45. * We use DEPC also as a flag to distinguish between double and regular
  46. * exceptions. For performance reasons, DEPC might contain the value of
  47. * EXCCAUSE for regular exceptions, so we use this definition to mark a
  48. * valid double exception address.
  49. * (Note: We use it in bgeui, so it should be 64, 128, or 256)
  50. */
  51. #define VALID_DOUBLE_EXCEPTION_ADDRESS 64
  52. /* LOCKLEVEL defines the interrupt level that masks all
  53. * general-purpose interrupts.
  54. */
  55. #define LOCKLEVEL 1
  56. /* WSBITS and WBBITS are the width of the WINDOWSTART and WINDOWBASE
  57. * registers
  58. */
  59. #define WSBITS (XCHAL_NUM_AREGS / 4) /* width of WINDOWSTART in bits */
  60. #define WBBITS (XCHAL_NUM_AREGS_LOG2 - 2) /* width of WINDOWBASE in bits */
  61. #ifndef __ASSEMBLY__
  62. /* Build a valid return address for the specified call winsize.
  63. * winsize must be 1 (call4), 2 (call8), or 3 (call12)
  64. */
  65. #define MAKE_RA_FOR_CALL(ra,ws) (((ra) & 0x3fffffff) | (ws) << 30)
  66. /* Convert return address to a valid pc
  67. * Note: We assume that the stack pointer is in the same 1GB ranges as the ra
  68. */
  69. #define MAKE_PC_FROM_RA(ra,sp) (((ra) & 0x3fffffff) | ((sp) & 0xc0000000))
  70. typedef struct {
  71. unsigned long seg;
  72. } mm_segment_t;
  73. struct thread_struct {
  74. /* kernel's return address and stack pointer for context switching */
  75. unsigned long ra; /* kernel's a0: return address and window call size */
  76. unsigned long sp; /* kernel's a1: stack pointer */
  77. mm_segment_t current_ds; /* see uaccess.h for example uses */
  78. /* struct xtensa_cpuinfo info; */
  79. unsigned long bad_vaddr; /* last user fault */
  80. unsigned long bad_uaddr; /* last kernel fault accessing user space */
  81. unsigned long error_code;
  82. unsigned long ibreak[XCHAL_NUM_IBREAK];
  83. unsigned long dbreaka[XCHAL_NUM_DBREAK];
  84. unsigned long dbreakc[XCHAL_NUM_DBREAK];
  85. /* Allocate storage for extra state and coprocessor state. */
  86. unsigned char cp_save[XTENSA_CP_EXTRA_SIZE]
  87. __attribute__ ((aligned(XTENSA_CP_EXTRA_ALIGN)));
  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 << XCHAL_PS_WOE_SHIFT) + \
  116. (1 << XCHAL_PS_CALLINC_SHIFT) + \
  117. (USER_RING << XCHAL_PS_RING_SHIFT) + \
  118. (1 << XCHAL_PS_PROGSTACK_SHIFT) + \
  119. (1 << XCHAL_PS_EXCM_SHIFT) )
  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. // FIXME: do we need release_thread for CP??
  134. /* Free all resources held by a thread. */
  135. #define release_thread(thread) do { } while(0)
  136. // FIXME: do we need prepare_to_copy (lazy status) for CP??
  137. /* Prepare to copy thread state - unlazy all lazy status */
  138. #define prepare_to_copy(tsk) do { } while (0)
  139. /*
  140. * create a kernel thread without removing it from tasklists
  141. */
  142. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  143. /* Copy and release all segment info associated with a VM */
  144. #define copy_segments(p, mm) do { } while(0)
  145. #define release_segments(mm) do { } while(0)
  146. #define forget_segments() do { } while (0)
  147. #define thread_saved_pc(tsk) (task_pt_regs(tsk)->pc)
  148. extern unsigned long get_wchan(struct task_struct *p);
  149. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
  150. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->areg[1])
  151. #define cpu_relax() barrier()
  152. /* Special register access. */
  153. #define WSR(v,sr) __asm__ __volatile__ ("wsr %0,"__stringify(sr) :: "a"(v));
  154. #define RSR(v,sr) __asm__ __volatile__ ("rsr %0,"__stringify(sr) : "=a"(v));
  155. #define set_sr(x,sr) ({unsigned int v=(unsigned int)x; WSR(v,sr);})
  156. #define get_sr(sr) ({unsigned int v; RSR(v,sr); v; })
  157. #endif /* __ASSEMBLY__ */
  158. #endif /* _XTENSA_PROCESSOR_H */