1 /* $Id: processor.h,v 1.75 2001/09/20 00:35:34 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; })
16 #include <linux/config.h>
18 #include <asm/a.out.h>
19 #include <asm/pstate.h>
20 #include <asm/ptrace.h>
21 #include <asm/signal.h>
22 #include <asm/segment.h>
27 #define EISA_bus__is_a_macro /* for versions in ksyms.c */
29 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
31 /* The sparc has no problems with write protection */
33 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
36 * User lives in his very own context, and cannot reference us. Note
37 * that TASK_SIZE is a misnomer, it really gives maximum user virtual
38 * address that the kernel will allocate out.
41 #define VPTE_SIZE (1UL << (VA_BITS - PAGE_SHIFT + 3))
42 #define TASK_SIZE ((unsigned long)-VPTE_SIZE)
52 /* The Sparc processor specific thread struct. */
53 struct thread_struct {
55 unsigned long ksp __attribute__ ((aligned(16)));
56 unsigned char wstate, cwp, flags;
57 mm_segment_t current_ds;
58 unsigned char w_saved, fpdepth, fault_code, use_blkcommit;
59 unsigned long fault_address;
60 unsigned char fpsaved[7];
64 struct pt_regs *kregs;
65 unsigned long *utraps;
67 unsigned long xfsr[7];
69 struct reg_window reg_window[NSWINS];
70 unsigned long rwbuf_stkptrs[NSWINS];
72 /* Performance counter state */
73 u64 *user_cntd0, *user_cntd1;
74 u64 kernel_cntd0, kernel_cntd1;
78 #endif /* !(__ASSEMBLY__) */
80 #define SPARC_FLAG_UNALIGNED 0x01 /* is allowed to do unaligned accesses */
81 #define SPARC_FLAG_NEWSIGNALS 0x02 /* task wants new-style signals */
82 #define SPARC_FLAG_32BIT 0x04 /* task is older 32-bit binary */
83 #define SPARC_FLAG_NEWCHILD 0x08 /* task is just-spawned child process */
84 #define SPARC_FLAG_PERFCTR 0x10 /* task has performance counters active */
86 #define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
87 #define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
88 #define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
89 #define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
91 #define INIT_THREAD { \
92 /* ksp, wstate, cwp, flags, current_ds, */ \
93 0, 0, 0, 0, KERNEL_DS, \
94 /* w_saved, fpdepth, fault_code, use_blkcommit, */ \
96 /* fault_address, fpsaved, __pad2, kregs, */ \
98 /* utraps, gsr, xfsr, */ \
101 { { { 0, }, { 0, } }, }, \
102 /* rwbuf_stkptrs */ \
103 { 0, 0, 0, 0, 0, 0, 0, }, \
104 /* user_cntd0, user_cndd1, kernel_cntd0, kernel_cntd0, pcr_reg */ \
110 #define THREAD_SIZE (2*PAGE_SIZE)
111 #define THREAD_SHIFT (PAGE_SHIFT + 1)
112 #else /* PAGE_SHIFT == 13 */
113 #define THREAD_SIZE PAGE_SIZE
114 #define THREAD_SHIFT PAGE_SHIFT
115 #endif /* PAGE_SHIFT == 13 */
116 #endif /* __KERNEL__ */
120 /* Return saved PC of a blocked thread. */
121 extern __inline__ unsigned long thread_saved_pc(struct thread_struct *t)
123 unsigned long ret = 0xdeadbeefUL;
127 sp = (unsigned long *)(t->ksp + STACK_BIAS);
128 if (((unsigned long)sp & (sizeof(long) - 1)) == 0UL &&
131 fp = (unsigned long *)(sp[14] + STACK_BIAS);
132 if (((unsigned long)fp & (sizeof(long) - 1)) == 0UL)
139 /* On Uniprocessor, even in RMO processes see TSO semantics */
141 #define TSTATE_INITIAL_MM TSTATE_TSO
143 #define TSTATE_INITIAL_MM TSTATE_RMO
146 /* Do necessary setup to start up a newly executed thread. */
147 #define start_thread(regs, pc, sp) \
149 regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (ASI_PNF << 24); \
150 regs->tpc = ((pc & (~3)) - 4); \
151 regs->tnpc = regs->tpc + 4; \
153 current->thread.wstate = (1 << 3); \
154 if (current->thread.utraps) { \
155 if (*(current->thread.utraps) < 2) \
156 kfree (current->thread.utraps); \
158 (*(current->thread.utraps))--; \
159 current->thread.utraps = NULL; \
161 __asm__ __volatile__( \
162 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
163 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
164 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
165 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
166 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
167 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
168 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
169 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
170 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
171 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
172 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
173 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
174 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
175 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
176 "stx %1, [%0 + %2 + 0x70]\n\t" \
177 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
178 "wrpr %%g0, (1 << 3), %%wstate\n\t" \
180 : "r" (regs), "r" (sp - REGWIN_SZ - STACK_BIAS), \
181 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
184 #define start_thread32(regs, pc, sp) \
186 pc &= 0x00000000ffffffffUL; \
187 sp &= 0x00000000ffffffffUL; \
189 regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM); \
190 regs->tpc = ((pc & (~3)) - 4); \
191 regs->tnpc = regs->tpc + 4; \
193 current->thread.wstate = (2 << 3); \
194 if (current->thread.utraps) { \
195 if (*(current->thread.utraps) < 2) \
196 kfree (current->thread.utraps); \
198 (*(current->thread.utraps))--; \
199 current->thread.utraps = NULL; \
201 __asm__ __volatile__( \
202 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
203 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
204 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
205 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
206 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
207 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
208 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
209 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
210 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
211 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
212 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
213 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
214 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
215 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
216 "stx %1, [%0 + %2 + 0x70]\n\t" \
217 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
218 "wrpr %%g0, (2 << 3), %%wstate\n\t" \
220 : "r" (regs), "r" (sp - REGWIN32_SZ), \
221 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
224 /* Free all resources held by a thread. */
225 #define release_thread(tsk) do { } while(0)
227 extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
229 #define copy_segments(tsk, mm) do { } while (0)
230 #define release_segments(mm) do { } while (0)
232 #define get_wchan(__TSK) \
233 ({ extern void scheduling_functions_start_here(void); \
234 extern void scheduling_functions_end_here(void); \
235 unsigned long pc, fp, bias = 0; \
236 unsigned long task_base = (unsigned long) (__TSK); \
237 struct reg_window *rw; \
238 unsigned long __ret = 0; \
240 if (!(__TSK) || (__TSK) == current || \
241 (__TSK)->state == TASK_RUNNING) \
244 fp = (__TSK)->thread.ksp + bias; \
246 /* Bogus frame pointer? */ \
247 if (fp < (task_base + sizeof(struct task_struct)) || \
248 fp >= (task_base + THREAD_SIZE)) \
250 rw = (struct reg_window *) fp; \
252 if (pc < ((unsigned long) scheduling_functions_start_here) || \
253 pc >= ((unsigned long) scheduling_functions_end_here)) { \
257 fp = rw->ins[6] + bias; \
258 } while (++count < 16); \
262 #define KSTK_EIP(tsk) ((tsk)->thread.kregs->tpc)
263 #define KSTK_ESP(tsk) ((tsk)->thread.kregs->u_regs[UREG_FP])
266 /* Allocation and freeing of task_struct and kernel stack. */
268 #define alloc_task_struct() ((struct task_struct *)__get_free_pages(GFP_KERNEL, 1))
269 #define free_task_struct(tsk) free_pages((unsigned long)(tsk),1)
270 #else /* PAGE_SHIFT == 13 */
271 #define alloc_task_struct() ((struct task_struct *)__get_free_pages(GFP_KERNEL, 0))
272 #define free_task_struct(tsk) free_pages((unsigned long)(tsk),0)
273 #endif /* PAGE_SHIFT == 13 */
274 #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
276 #define init_task (init_task_union.task)
277 #define init_stack (init_task_union.stack)
279 #define cpu_relax() do { } while (0)
281 #endif /* __KERNEL__ */
283 #endif /* !(__ASSEMBLY__) */
285 #endif /* !(__ASM_SPARC64_PROCESSOR_H) */