processor.h 6.1 KB

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