1 /* $Id: processor.h,v 1.83 2002/02/10 06:04:33 davem Exp $
2 * include/asm-sparc64/processor.h
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 #ifndef __ASM_SPARC64_PROCESSOR_H
8 #define __ASM_SPARC64_PROCESSOR_H
11 * Sparc64 implementation of macro that returns current
12 * instruction pointer ("program counter").
14 #define current_text_addr() ({ void *pc; __asm__("rd %%pc, %0" : "=r" (pc)); pc; })
17 #include <asm/pstate.h>
18 #include <asm/ptrace.h>
21 /* The sparc has no problems with write protection */
23 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
26 * User lives in his very own context, and cannot reference us. Note
27 * that TASK_SIZE is a misnomer, it really gives maximum user virtual
28 * address that the kernel will allocate out.
30 * XXX No longer using virtual page tables, kill this upper limit...
34 #define VPTE_SIZE (1UL << (VA_BITS - PAGE_SHIFT + 3))
36 #define VPTE_SIZE (1 << (VA_BITS - PAGE_SHIFT + 3))
39 #define TASK_SIZE ((unsigned long)-VPTE_SIZE)
42 #define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE)
43 #define STACK_TOP64 (0x0000080000000000UL - (1UL << 32UL))
45 #define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
46 STACK_TOP32 : STACK_TOP64)
48 #define STACK_TOP_MAX STACK_TOP64
58 /* The Sparc processor specific thread struct. */
59 /* XXX This should die, everything can go into thread_info now. */
60 struct thread_struct
{
61 #ifdef CONFIG_DEBUG_SPINLOCK
62 /* How many spinlocks held by this thread.
63 * Used with spin lock debugging to catch tasks
64 * sleeping illegally with locks held.
67 unsigned int smp_lock_pc
;
69 int dummy
; /* f'in gcc bug... */
73 #endif /* !(__ASSEMBLY__) */
75 #ifndef CONFIG_DEBUG_SPINLOCK
76 #define INIT_THREAD { \
79 #else /* CONFIG_DEBUG_SPINLOCK */
80 #define INIT_THREAD { \
81 /* smp_lock_count, smp_lock_pc, */ \
84 #endif /* !(CONFIG_DEBUG_SPINLOCK) */
88 #include <linux/types.h>
90 /* Return saved PC of a blocked thread. */
92 extern unsigned long thread_saved_pc(struct task_struct
*);
94 /* On Uniprocessor, even in RMO processes see TSO semantics */
96 #define TSTATE_INITIAL_MM TSTATE_TSO
98 #define TSTATE_INITIAL_MM TSTATE_RMO
101 /* Do necessary setup to start up a newly executed thread. */
102 #define start_thread(regs, pc, sp) \
104 unsigned long __asi = ASI_PNF; \
105 regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
106 regs->tpc = ((pc & (~3)) - 4); \
107 regs->tnpc = regs->tpc + 4; \
109 set_thread_wstate(1 << 3); \
110 if (current_thread_info()->utraps) { \
111 if (*(current_thread_info()->utraps) < 2) \
112 kfree(current_thread_info()->utraps); \
114 (*(current_thread_info()->utraps))--; \
115 current_thread_info()->utraps = NULL; \
117 __asm__ __volatile__( \
118 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
119 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
120 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
121 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
122 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
123 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
124 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
125 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
126 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
127 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
128 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
129 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
130 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
131 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
132 "stx %1, [%0 + %2 + 0x70]\n\t" \
133 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
134 "wrpr %%g0, (1 << 3), %%wstate\n\t" \
136 : "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
137 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
140 #define start_thread32(regs, pc, sp) \
142 unsigned long __asi = ASI_PNF; \
143 pc &= 0x00000000ffffffffUL; \
144 sp &= 0x00000000ffffffffUL; \
145 regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
146 regs->tpc = ((pc & (~3)) - 4); \
147 regs->tnpc = regs->tpc + 4; \
149 set_thread_wstate(2 << 3); \
150 if (current_thread_info()->utraps) { \
151 if (*(current_thread_info()->utraps) < 2) \
152 kfree(current_thread_info()->utraps); \
154 (*(current_thread_info()->utraps))--; \
155 current_thread_info()->utraps = NULL; \
157 __asm__ __volatile__( \
158 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
159 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
160 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
161 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
162 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
163 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
164 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
165 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
166 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
167 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
168 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
169 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
170 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
171 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
172 "stx %1, [%0 + %2 + 0x70]\n\t" \
173 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
174 "wrpr %%g0, (2 << 3), %%wstate\n\t" \
176 : "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
177 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
180 /* Free all resources held by a thread. */
181 #define release_thread(tsk) do { } while (0)
183 /* Prepare to copy thread state - unlazy all lazy status */
184 #define prepare_to_copy(tsk) do { } while (0)
186 extern pid_t
kernel_thread(int (*fn
)(void *), void * arg
, unsigned long flags
);
188 extern unsigned long get_wchan(struct task_struct
*task
);
190 #define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
191 #define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc)
192 #define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP])
194 #define cpu_relax() barrier()
196 /* Prefetch support. This is tuned for UltraSPARC-III and later.
197 * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
198 * a shallower prefetch queue than later chips.
200 #define ARCH_HAS_PREFETCH
201 #define ARCH_HAS_PREFETCHW
202 #define ARCH_HAS_SPINLOCK_PREFETCH
204 static inline void prefetch(const void *x
)
206 /* We do not use the read prefetch mnemonic because that
207 * prefetches into the prefetch-cache which only is accessible
208 * by floating point operations in UltraSPARC-III and later.
209 * By contrast, "#one_write" prefetches into the L2 cache
212 __asm__
__volatile__("prefetch [%0], #one_write"
217 static inline void prefetchw(const void *x
)
219 /* The most optimal prefetch to use for writes is
220 * "#n_writes". This brings the cacheline into the
221 * L2 cache in "owned" state.
223 __asm__
__volatile__("prefetch [%0], #n_writes"
228 #define spin_lock_prefetch(x) prefetchw(x)
230 #define HAVE_ARCH_PICK_MMAP_LAYOUT
232 #endif /* !(__ASSEMBLY__) */
234 #endif /* !(__ASM_SPARC64_PROCESSOR_H) */