blob: 48e74965c6e57c08649435b25881b4999dfaf4df [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: processor.h,v 1.83 2002/02/10 06:04:33 davem Exp $
2 * include/asm-sparc64/processor.h
3 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
6
7#ifndef __ASM_SPARC64_PROCESSOR_H
8#define __ASM_SPARC64_PROCESSOR_H
9
10/*
11 * Sparc64 implementation of macro that returns current
12 * instruction pointer ("program counter").
13 */
14#define current_text_addr() ({ void *pc; __asm__("rd %%pc, %0" : "=r" (pc)); pc; })
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/asi.h>
17#include <asm/a.out.h>
18#include <asm/pstate.h>
19#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/page.h>
21
22/* The sparc has no problems with write protection */
23#define wp_works_ok 1
24#define wp_works_ok__is_a_macro /* for versions in ksyms.c */
25
26/*
27 * User lives in his very own context, and cannot reference us. Note
28 * that TASK_SIZE is a misnomer, it really gives maximum user virtual
29 * address that the kernel will allocate out.
David S. Miller74bf4312006-01-31 18:29:18 -080030 *
31 * XXX No longer using virtual page tables, kill this upper limit...
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 */
33#define VA_BITS 44
34#ifndef __ASSEMBLY__
35#define VPTE_SIZE (1UL << (VA_BITS - PAGE_SHIFT + 3))
36#else
37#define VPTE_SIZE (1 << (VA_BITS - PAGE_SHIFT + 3))
38#endif
David Howells922a70d2008-02-08 04:19:26 -080039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define TASK_SIZE ((unsigned long)-VPTE_SIZE)
David Howells922a70d2008-02-08 04:19:26 -080041#ifdef __KERNEL__
42
43#define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE)
44#define STACK_TOP64 (0x0000080000000000UL - (1UL << 32UL))
45
46#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
47 STACK_TOP32 : STACK_TOP64)
48
49#define STACK_TOP_MAX STACK_TOP64
50
51#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#ifndef __ASSEMBLY__
54
55typedef struct {
56 unsigned char seg;
57} mm_segment_t;
58
59/* The Sparc processor specific thread struct. */
60/* XXX This should die, everything can go into thread_info now. */
61struct thread_struct {
62#ifdef CONFIG_DEBUG_SPINLOCK
63 /* How many spinlocks held by this thread.
64 * Used with spin lock debugging to catch tasks
65 * sleeping illegally with locks held.
66 */
67 int smp_lock_count;
68 unsigned int smp_lock_pc;
69#else
70 int dummy; /* f'in gcc bug... */
71#endif
72};
73
74#endif /* !(__ASSEMBLY__) */
75
76#ifndef CONFIG_DEBUG_SPINLOCK
77#define INIT_THREAD { \
78 0, \
79}
80#else /* CONFIG_DEBUG_SPINLOCK */
81#define INIT_THREAD { \
82/* smp_lock_count, smp_lock_pc, */ \
83 0, 0, \
84}
85#endif /* !(CONFIG_DEBUG_SPINLOCK) */
86
87#ifndef __ASSEMBLY__
88
89#include <linux/types.h>
90
91/* Return saved PC of a blocked thread. */
92struct task_struct;
93extern unsigned long thread_saved_pc(struct task_struct *);
94
95/* On Uniprocessor, even in RMO processes see TSO semantics */
96#ifdef CONFIG_SMP
97#define TSTATE_INITIAL_MM TSTATE_TSO
98#else
99#define TSTATE_INITIAL_MM TSTATE_RMO
100#endif
101
102/* Do necessary setup to start up a newly executed thread. */
103#define start_thread(regs, pc, sp) \
104do { \
David S. Miller0f05da62006-02-22 16:20:11 -0800105 unsigned long __asi = ASI_PNF; \
106 regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (__asi << 24UL); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 regs->tpc = ((pc & (~3)) - 4); \
108 regs->tnpc = regs->tpc + 4; \
109 regs->y = 0; \
110 set_thread_wstate(1 << 3); \
111 if (current_thread_info()->utraps) { \
112 if (*(current_thread_info()->utraps) < 2) \
113 kfree(current_thread_info()->utraps); \
114 else \
115 (*(current_thread_info()->utraps))--; \
116 current_thread_info()->utraps = NULL; \
117 } \
118 __asm__ __volatile__( \
119 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
120 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
121 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
122 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
123 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
124 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
125 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
126 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
127 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
128 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
129 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
130 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
131 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
132 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
133 "stx %1, [%0 + %2 + 0x70]\n\t" \
134 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
135 "wrpr %%g0, (1 << 3), %%wstate\n\t" \
136 : \
137 : "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
138 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
139} while (0)
140
141#define start_thread32(regs, pc, sp) \
142do { \
David S. Miller0f05da62006-02-22 16:20:11 -0800143 unsigned long __asi = ASI_PNF; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 pc &= 0x00000000ffffffffUL; \
145 sp &= 0x00000000ffffffffUL; \
David S. Miller0f05da62006-02-22 16:20:11 -0800146 regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM) | (__asi << 24UL); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 regs->tpc = ((pc & (~3)) - 4); \
148 regs->tnpc = regs->tpc + 4; \
149 regs->y = 0; \
150 set_thread_wstate(2 << 3); \
151 if (current_thread_info()->utraps) { \
152 if (*(current_thread_info()->utraps) < 2) \
153 kfree(current_thread_info()->utraps); \
154 else \
155 (*(current_thread_info()->utraps))--; \
156 current_thread_info()->utraps = NULL; \
157 } \
158 __asm__ __volatile__( \
159 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
160 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
161 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
162 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
163 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
164 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
165 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
166 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
167 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
168 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
169 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
170 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
171 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
172 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
173 "stx %1, [%0 + %2 + 0x70]\n\t" \
174 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
175 "wrpr %%g0, (2 << 3), %%wstate\n\t" \
176 : \
177 : "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
178 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
179} while (0)
180
181/* Free all resources held by a thread. */
182#define release_thread(tsk) do { } while (0)
183
184/* Prepare to copy thread state - unlazy all lazy status */
185#define prepare_to_copy(tsk) do { } while (0)
186
187extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
188
189extern unsigned long get_wchan(struct task_struct *task);
190
Al Viro26ecbde2006-01-12 01:05:43 -0800191#define task_pt_regs(tsk) (task_thread_info(tsk)->kregs)
192#define KSTK_EIP(tsk) (task_pt_regs(tsk)->tpc)
193#define KSTK_ESP(tsk) (task_pt_regs(tsk)->u_regs[UREG_FP])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195#define cpu_relax() barrier()
196
David S. Miller7049e682005-06-21 16:20:28 -0700197/* Prefetch support. This is tuned for UltraSPARC-III and later.
198 * UltraSPARC-I will treat these as nops, and UltraSPARC-II has
199 * a shallower prefetch queue than later chips.
200 */
201#define ARCH_HAS_PREFETCH
202#define ARCH_HAS_PREFETCHW
203#define ARCH_HAS_SPINLOCK_PREFETCH
204
205static inline void prefetch(const void *x)
206{
207 /* We do not use the read prefetch mnemonic because that
208 * prefetches into the prefetch-cache which only is accessible
209 * by floating point operations in UltraSPARC-III and later.
210 * By contrast, "#one_write" prefetches into the L2 cache
211 * in shared state.
212 */
213 __asm__ __volatile__("prefetch [%0], #one_write"
214 : /* no outputs */
215 : "r" (x));
216}
217
218static inline void prefetchw(const void *x)
219{
220 /* The most optimal prefetch to use for writes is
221 * "#n_writes". This brings the cacheline into the
222 * L2 cache in "owned" state.
223 */
224 __asm__ __volatile__("prefetch [%0], #n_writes"
225 : /* no outputs */
226 : "r" (x));
227}
228
229#define spin_lock_prefetch(x) prefetchw(x)
230
David S. Millera91690d2006-03-17 14:41:03 -0800231#define HAVE_ARCH_PICK_MMAP_LAYOUT
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#endif /* !(__ASSEMBLY__) */
234
235#endif /* !(__ASM_SPARC64_PROCESSOR_H) */