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)
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>
26 #define EISA_bus__is_a_macro /* for versions in ksyms.c */
28 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
30 /* The sparc has no problems with write protection */
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. */
36 #define TASK_SIZE ((unsigned long)-PGDIR_SIZE)
38 #define TASK_SIZE 0xfffffffc00000000
49 /* The Sparc processor specific thread struct. */
50 struct thread_struct
{
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];
61 struct pt_regs
*kregs
;
62 unsigned long *utraps
;
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
;
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, */ \
97 /* fault_address, fpsaved, __pad2, kregs, */ \
99 /* utraps, gsr, __pad3, xfsr, */ \
100 0, { 0 }, 0, { 0 }, \
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 */ \
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
;
118 sp
= (unsigned long *)(t
->ksp
+ STACK_BIAS
);
119 if (((unsigned long)sp
& (sizeof(long) - 1)) == 0UL &&
122 fp
= (unsigned long *)(sp
[14] + STACK_BIAS
);
123 if (((unsigned long)fp
& (sizeof(long) - 1)) == 0UL)
130 /* On Uniprocessor, even in RMO processes see TSO semantics */
132 #define TSTATE_INITIAL_MM TSTATE_TSO
134 #define TSTATE_INITIAL_MM TSTATE_RMO
137 /* Do necessary setup to start up a newly executed thread. */
138 #define start_thread(regs, pc, sp) \
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; \
144 current->thread.wstate = (1 << 3); \
145 if (current->thread.utraps) { \
146 if (*(current->thread.utraps) < 2) \
147 kfree (current->thread.utraps); \
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]))); \
175 #define start_thread32(regs, pc, sp) \
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; \
184 current->thread.wstate = (2 << 3); \
185 if (current->thread.utraps) { \
186 if (*(current->thread.utraps) < 2) \
187 kfree (current->thread.utraps); \
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]))); \
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; \
232 if (!(__TSK) || (__TSK) == current || \
233 (__TSK)->state == TASK_RUNNING) \
236 fp = (__TSK)->thread.ksp + bias; \
238 /* Bogus frame pointer? */ \
239 if (fp < (task_base + sizeof(struct task_struct)) || \
240 fp >= (task_base + (2 * PAGE_SIZE))) \
242 rw = (struct reg_window *) fp; \
244 if (pc < ((unsigned long) scheduling_functions_start_here) || \
245 pc >= ((unsigned long) scheduling_functions_end_here)) { \
249 fp = rw->ins[6] + bias; \
250 } while (++count < 16); \
254 #define KSTK_EIP(tsk) ((tsk)->thread.kregs->tpc)
255 #define KSTK_ESP(tsk) ((tsk)->thread.kregs->u_regs[UREG_FP])
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) */