processor.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <asm/variant/core.h>
  13. #include <asm/coprocessor.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. /*
  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. #define TASK_SIZE __XTENSA_UL_CONST(0x40000000)
  30. /*
  31. * General exception cause assigned to debug exceptions. Debug exceptions go
  32. * to their own vector, rather than the general exception vectors (user,
  33. * kernel, double); and their specific causes are reported via DEBUGCAUSE
  34. * rather than EXCCAUSE. However it is sometimes convenient to redirect debug
  35. * exceptions to the general exception mechanism. To do this, an otherwise
  36. * unused EXCCAUSE value was assigned to debug exceptions for this purpose.
  37. */
  38. #define EXCCAUSE_MAPPED_DEBUG 63
  39. /*
  40. * We use DEPC also as a flag to distinguish between double and regular
  41. * exceptions. For performance reasons, DEPC might contain the value of
  42. * EXCCAUSE for regular exceptions, so we use this definition to mark a
  43. * valid double exception address.
  44. * (Note: We use it in bgeui, so it should be 64, 128, or 256)
  45. */
  46. #define VALID_DOUBLE_EXCEPTION_ADDRESS 64
  47. /* LOCKLEVEL defines the interrupt level that masks all
  48. * general-purpose interrupts.
  49. */
  50. #define LOCKLEVEL 1
  51. /* WSBITS and WBBITS are the width of the WINDOWSTART and WINDOWBASE
  52. * registers
  53. */
  54. #define WSBITS (XCHAL_NUM_AREGS / 4) /* width of WINDOWSTART in bits */
  55. #define WBBITS (XCHAL_NUM_AREGS_LOG2 - 2) /* width of WINDOWBASE in bits */
  56. #ifndef __ASSEMBLY__
  57. /* Build a valid return address for the specified call winsize.
  58. * winsize must be 1 (call4), 2 (call8), or 3 (call12)
  59. */
  60. #define MAKE_RA_FOR_CALL(ra,ws) (((ra) & 0x3fffffff) | (ws) << 30)
  61. /* Convert return address to a valid pc
  62. * Note: We assume that the stack pointer is in the same 1GB ranges as the ra
  63. */
  64. #define MAKE_PC_FROM_RA(ra,sp) (((ra) & 0x3fffffff) | ((sp) & 0xc0000000))
  65. typedef struct {
  66. unsigned long seg;
  67. } mm_segment_t;
  68. struct thread_struct {
  69. /* kernel's return address and stack pointer for context switching */
  70. unsigned long ra; /* kernel's a0: return address and window call size */
  71. unsigned long sp; /* kernel's a1: stack pointer */
  72. mm_segment_t current_ds; /* see uaccess.h for example uses */
  73. /* struct xtensa_cpuinfo info; */
  74. unsigned long bad_vaddr; /* last user fault */
  75. unsigned long bad_uaddr; /* last kernel fault accessing user space */
  76. unsigned long error_code;
  77. unsigned long ibreak[XCHAL_NUM_IBREAK];
  78. unsigned long dbreaka[XCHAL_NUM_DBREAK];
  79. unsigned long dbreakc[XCHAL_NUM_DBREAK];
  80. /* Allocate storage for extra state and coprocessor state. */
  81. unsigned char cp_save[XTENSA_CP_EXTRA_SIZE]
  82. __attribute__ ((aligned(XTENSA_CP_EXTRA_ALIGN)));
  83. /* Make structure 16 bytes aligned. */
  84. int align[0] __attribute__ ((aligned(16)));
  85. };
  86. /*
  87. * Default implementation of macro that returns current
  88. * instruction pointer ("program counter").
  89. */
  90. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  91. /* This decides where the kernel will search for a free chunk of vm
  92. * space during mmap's.
  93. */
  94. #define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
  95. #define INIT_THREAD \
  96. { \
  97. ra: 0, \
  98. sp: sizeof(init_stack) + (long) &init_stack, \
  99. current_ds: {0}, \
  100. /*info: {0}, */ \
  101. bad_vaddr: 0, \
  102. bad_uaddr: 0, \
  103. error_code: 0, \
  104. }
  105. /*
  106. * Do necessary setup to start up a newly executed thread.
  107. * Note: We set-up ps as if we did a call4 to the new pc.
  108. * set_thread_state in signal.c depends on it.
  109. */
  110. #define USER_PS_VALUE ((1 << PS_WOE_BIT) | \
  111. (1 << PS_CALLINC_SHIFT) | \
  112. (USER_RING << PS_RING_SHIFT) | \
  113. (1 << PS_UM_BIT) | \
  114. (1 << PS_EXCM_BIT))
  115. /* Clearing a0 terminates the backtrace. */
  116. #define start_thread(regs, new_pc, new_sp) \
  117. regs->pc = new_pc; \
  118. regs->ps = USER_PS_VALUE; \
  119. regs->areg[1] = new_sp; \
  120. regs->areg[0] = 0; \
  121. regs->wmask = 1; \
  122. regs->depc = 0; \
  123. regs->windowbase = 0; \
  124. regs->windowstart = 1;
  125. /* Forward declaration */
  126. struct task_struct;
  127. struct mm_struct;
  128. // FIXME: do we need release_thread for CP??
  129. /* Free all resources held by a thread. */
  130. #define release_thread(thread) do { } while(0)
  131. // FIXME: do we need prepare_to_copy (lazy status) for CP??
  132. /* Prepare to copy thread state - unlazy all lazy status */
  133. #define prepare_to_copy(tsk) do { } while (0)
  134. /*
  135. * create a kernel thread without removing it from tasklists
  136. */
  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 */