processor.h 5.7 KB

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