Optimize andes_clear_page() and andes_copy_page() with prefetch
[linux-2.6/linux-mips.git] / include / asm-sparc64 / processor.h
blobb7b124a56fdcd54ccdb64e86640abf15a06601ee
1 /* $Id: processor.h,v 1.64 2000/05/09 17:40:15 davem Exp $
2 * include/asm-sparc64/processor.h
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
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>
17 #include <asm/asi.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>
24 /* Bus types */
25 #define EISA_bus 0
26 #define EISA_bus__is_a_macro /* for versions in ksyms.c */
27 #define MCA_bus 0
28 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
30 /* The sparc has no problems with write protection */
31 #define wp_works_ok 1
32 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
34 /* User lives in his very own context, and cannot reference us. */
35 #ifndef __ASSEMBLY__
36 #define TASK_SIZE ((unsigned long)-PGDIR_SIZE)
37 #else
38 #define TASK_SIZE 0xfffffffc00000000
39 #endif
41 #ifndef __ASSEMBLY__
43 #define NSWINS 7
45 typedef struct {
46 unsigned char seg;
47 } mm_segment_t;
49 /* The Sparc processor specific thread struct. */
50 struct thread_struct {
51 /* D$ line 1 */
52 unsigned long ksp __attribute__ ((aligned(16)));
53 unsigned char wstate, cwp, flags;
54 mm_segment_t current_ds;
55 unsigned char w_saved, fpdepth, fault_code, use_blkcommit;
56 unsigned long fault_address;
57 unsigned char fpsaved[7];
58 unsigned char __pad2;
60 /* D$ line 2, 3, 4 */
61 struct pt_regs *kregs;
62 unsigned long *utraps;
63 unsigned char gsr[7];
64 unsigned char __pad3;
65 unsigned long xfsr[7];
67 struct reg_window reg_window[NSWINS];
68 unsigned long rwbuf_stkptrs[NSWINS];
70 /* Performance counter state */
71 u64 *user_cntd0, *user_cntd1;
72 u64 kernel_cntd0, kernel_cntd1;
73 u64 pcr_reg;
76 #endif /* !(__ASSEMBLY__) */
78 #define SPARC_FLAG_UNALIGNED 0x01 /* is allowed to do unaligned accesses */
79 #define SPARC_FLAG_NEWSIGNALS 0x02 /* task wants new-style signals */
80 #define SPARC_FLAG_32BIT 0x04 /* task is older 32-bit binary */
81 #define SPARC_FLAG_NEWCHILD 0x08 /* task is just-spawned child process */
82 #define SPARC_FLAG_PERFCTR 0x10 /* task has performance counters active */
84 #define FAULT_CODE_WRITE 0x01 /* Write access, implies D-TLB */
85 #define FAULT_CODE_DTLB 0x02 /* Miss happened in D-TLB */
86 #define FAULT_CODE_ITLB 0x04 /* Miss happened in I-TLB */
87 #define FAULT_CODE_WINFIXUP 0x08 /* Miss happened during spill/fill */
89 #define INIT_MMAP { &init_mm, 0xfffff80000000000, 0xfffff80001000000, \
90 NULL, PAGE_SHARED , VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
92 #define INIT_THREAD { \
93 /* ksp, wstate, cwp, flags, current_ds, */ \
94 0, 0, 0, 0, KERNEL_DS, \
95 /* w_saved, fpdepth, fault_code, use_blkcommit, */ \
96 0, 0, 0, 0, \
97 /* fault_address, fpsaved, __pad2, kregs, */ \
98 0, { 0 }, 0, 0, \
99 /* utraps, gsr, __pad3, xfsr, */ \
100 0, { 0 }, 0, { 0 }, \
101 /* reg_window */ \
102 { { { 0, }, { 0, } }, }, \
103 /* rwbuf_stkptrs */ \
104 { 0, 0, 0, 0, 0, 0, 0, }, \
105 /* user_cntd0, user_cndd1, kernel_cntd0, kernel_cntd0, pcr_reg */ \
106 0, 0, 0, 0, 0, \
109 #ifndef __ASSEMBLY__
111 /* Return saved PC of a blocked thread. */
112 extern __inline__ unsigned long thread_saved_pc(struct thread_struct *t)
114 unsigned long ret = 0xdeadbeefUL;
116 if (t->ksp) {
117 unsigned long *sp;
118 sp = (unsigned long *)(t->ksp + STACK_BIAS);
119 if (((unsigned long)sp & (sizeof(long) - 1)) == 0UL &&
120 sp[14]) {
121 unsigned long *fp;
122 fp = (unsigned long *)(sp[14] + STACK_BIAS);
123 if (((unsigned long)fp & (sizeof(long) - 1)) == 0UL)
124 ret = fp[15];
127 return ret;
130 /* On Uniprocessor, even in RMO processes see TSO semantics */
131 #ifdef CONFIG_SMP
132 #define TSTATE_INITIAL_MM TSTATE_TSO
133 #else
134 #define TSTATE_INITIAL_MM TSTATE_RMO
135 #endif
137 /* Do necessary setup to start up a newly executed thread. */
138 #define start_thread(regs, pc, sp) \
139 do { \
140 regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (ASI_PNF << 24); \
141 regs->tpc = ((pc & (~3)) - 4); \
142 regs->tnpc = regs->tpc + 4; \
143 regs->y = 0; \
144 current->thread.wstate = (1 << 3); \
145 if (current->thread.utraps) { \
146 if (*(current->thread.utraps) < 2) \
147 kfree (current->thread.utraps); \
148 else \
149 (*(current->thread.utraps))--; \
150 current->thread.utraps = NULL; \
152 __asm__ __volatile__( \
153 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
154 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
155 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
156 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
157 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
158 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
159 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
160 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
161 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
162 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
163 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
164 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
165 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
166 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
167 "stx %1, [%0 + %2 + 0x70]\n\t" \
168 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
169 "wrpr %%g0, (1 << 3), %%wstate\n\t" \
171 : "r" (regs), "r" (sp - REGWIN_SZ - STACK_BIAS), \
172 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
173 } while(0)
175 #define start_thread32(regs, pc, sp) \
176 do { \
177 pc &= 0x00000000ffffffffUL; \
178 sp &= 0x00000000ffffffffUL; \
180 regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM); \
181 regs->tpc = ((pc & (~3)) - 4); \
182 regs->tnpc = regs->tpc + 4; \
183 regs->y = 0; \
184 current->thread.wstate = (2 << 3); \
185 if (current->thread.utraps) { \
186 if (*(current->thread.utraps) < 2) \
187 kfree (current->thread.utraps); \
188 else \
189 (*(current->thread.utraps))--; \
190 current->thread.utraps = NULL; \
192 __asm__ __volatile__( \
193 "stx %%g0, [%0 + %2 + 0x00]\n\t" \
194 "stx %%g0, [%0 + %2 + 0x08]\n\t" \
195 "stx %%g0, [%0 + %2 + 0x10]\n\t" \
196 "stx %%g0, [%0 + %2 + 0x18]\n\t" \
197 "stx %%g0, [%0 + %2 + 0x20]\n\t" \
198 "stx %%g0, [%0 + %2 + 0x28]\n\t" \
199 "stx %%g0, [%0 + %2 + 0x30]\n\t" \
200 "stx %%g0, [%0 + %2 + 0x38]\n\t" \
201 "stx %%g0, [%0 + %2 + 0x40]\n\t" \
202 "stx %%g0, [%0 + %2 + 0x48]\n\t" \
203 "stx %%g0, [%0 + %2 + 0x50]\n\t" \
204 "stx %%g0, [%0 + %2 + 0x58]\n\t" \
205 "stx %%g0, [%0 + %2 + 0x60]\n\t" \
206 "stx %%g0, [%0 + %2 + 0x68]\n\t" \
207 "stx %1, [%0 + %2 + 0x70]\n\t" \
208 "stx %%g0, [%0 + %2 + 0x78]\n\t" \
209 "wrpr %%g0, (2 << 3), %%wstate\n\t" \
211 : "r" (regs), "r" (sp - REGWIN32_SZ), \
212 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
213 } while(0)
215 /* Free all resources held by a thread. */
216 #define release_thread(tsk) do { } while(0)
218 extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
220 #define copy_segments(tsk, mm) do { } while (0)
221 #define release_segments(mm) do { } while (0)
222 #define forget_segments() do { } while (0)
224 #define get_wchan(__TSK) \
225 ({ extern void scheduling_functions_start_here(void); \
226 extern void scheduling_functions_end_here(void); \
227 unsigned long pc, fp, bias = 0; \
228 unsigned long task_base = (unsigned long) (__TSK); \
229 struct reg_window *rw; \
230 unsigned long __ret = 0; \
231 int count = 0; \
232 if (!(__TSK) || (__TSK) == current || \
233 (__TSK)->state == TASK_RUNNING) \
234 goto __out; \
235 bias = STACK_BIAS; \
236 fp = (__TSK)->thread.ksp + bias; \
237 do { \
238 /* Bogus frame pointer? */ \
239 if (fp < (task_base + sizeof(struct task_struct)) || \
240 fp >= (task_base + (2 * PAGE_SIZE))) \
241 break; \
242 rw = (struct reg_window *) fp; \
243 pc = rw->ins[7]; \
244 if (pc < ((unsigned long) scheduling_functions_start_here) || \
245 pc >= ((unsigned long) scheduling_functions_end_here)) { \
246 __ret = pc; \
247 goto __out; \
249 fp = rw->ins[6] + bias; \
250 } while (++count < 16); \
251 __out: __ret; \
254 #define KSTK_EIP(tsk) ((tsk)->thread.kregs->tpc)
255 #define KSTK_ESP(tsk) ((tsk)->thread.kregs->u_regs[UREG_FP])
257 #ifdef __KERNEL__
258 #define THREAD_SIZE (2*PAGE_SIZE)
259 /* Allocation and freeing of task_struct and kernel stack. */
260 #define alloc_task_struct() ((struct task_struct *)__get_free_pages(GFP_KERNEL, 1))
261 #define free_task_struct(tsk) free_pages((unsigned long)(tsk),1)
262 #define get_task_struct(tsk) atomic_inc(&mem_map[MAP_NR(tsk)].count)
264 #define init_task (init_task_union.task)
265 #define init_stack (init_task_union.stack)
267 #endif /* __KERNEL__ */
269 #endif /* !(__ASSEMBLY__) */
271 #endif /* !(__ASM_SPARC64_PROCESSOR_H) */