ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-sparc64 / processor.h
1 /* $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
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/segment.h>
22 #include <asm/page.h>
23
24 /* Bus types */
25 #define MCA_bus 0
26 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
27
28 /* The sparc has no problems with write protection */
29 #define wp_works_ok 1
30 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
31
32 /*
33  * User lives in his very own context, and cannot reference us. Note
34  * that TASK_SIZE is a misnomer, it really gives maximum user virtual 
35  * address that the kernel will allocate out.
36  */
37 #define VA_BITS         44
38 #ifndef __ASSEMBLY__
39 #define VPTE_SIZE       (1UL << (VA_BITS - PAGE_SHIFT + 3))
40 #else
41 #define VPTE_SIZE       (1 << (VA_BITS - PAGE_SHIFT + 3))
42 #endif
43 #define TASK_SIZE       ((unsigned long)-VPTE_SIZE)
44
45 /*
46  * The vpte base must be able to hold the entire vpte, half
47  * of which lives above, and half below, the base. And it
48  * is placed as close to the highest address range as possible.
49  */
50 #define VPTE_BASE_SPITFIRE      (-(VPTE_SIZE/2))
51 #if 1
52 #define VPTE_BASE_CHEETAH       VPTE_BASE_SPITFIRE
53 #else
54 #define VPTE_BASE_CHEETAH       0xffe0000000000000
55 #endif
56
57 #ifndef __ASSEMBLY__
58
59 typedef struct {
60         unsigned char seg;
61 } mm_segment_t;
62
63 /* The Sparc processor specific thread struct. */
64 /* XXX This should die, everything can go into thread_info now. */
65 struct thread_struct {
66 #ifdef CONFIG_DEBUG_SPINLOCK
67         /* How many spinlocks held by this thread.
68          * Used with spin lock debugging to catch tasks
69          * sleeping illegally with locks held.
70          */
71         int smp_lock_count;
72         unsigned int smp_lock_pc;
73 #else
74         int dummy; /* f'in gcc bug... */
75 #endif
76 };
77
78 #endif /* !(__ASSEMBLY__) */
79
80 #ifndef CONFIG_DEBUG_SPINLOCK
81 #define INIT_THREAD  {                  \
82         0,                              \
83 }
84 #else /* CONFIG_DEBUG_SPINLOCK */
85 #define INIT_THREAD  {                                  \
86 /* smp_lock_count, smp_lock_pc, */                      \
87    0,              0,                                   \
88 }
89 #endif /* !(CONFIG_DEBUG_SPINLOCK) */
90
91 #ifndef __ASSEMBLY__
92
93 #include <linux/types.h>
94
95 /* Return saved PC of a blocked thread. */
96 struct task_struct;
97 extern unsigned long thread_saved_pc(struct task_struct *);
98
99 /* On Uniprocessor, even in RMO processes see TSO semantics */
100 #ifdef CONFIG_SMP
101 #define TSTATE_INITIAL_MM       TSTATE_TSO
102 #else
103 #define TSTATE_INITIAL_MM       TSTATE_RMO
104 #endif
105
106 /* Do necessary setup to start up a newly executed thread. */
107 #define start_thread(regs, pc, sp) \
108 do { \
109         regs->tstate = (regs->tstate & (TSTATE_CWP)) | (TSTATE_INITIAL_MM|TSTATE_IE) | (ASI_PNF << 24); \
110         regs->tpc = ((pc & (~3)) - 4); \
111         regs->tnpc = regs->tpc + 4; \
112         regs->y = 0; \
113         set_thread_wstate(1 << 3); \
114         if (current_thread_info()->utraps) { \
115                 if (*(current_thread_info()->utraps) < 2) \
116                         kfree(current_thread_info()->utraps); \
117                 else \
118                         (*(current_thread_info()->utraps))--; \
119                 current_thread_info()->utraps = NULL; \
120         } \
121         __asm__ __volatile__( \
122         "stx            %%g0, [%0 + %2 + 0x00]\n\t" \
123         "stx            %%g0, [%0 + %2 + 0x08]\n\t" \
124         "stx            %%g0, [%0 + %2 + 0x10]\n\t" \
125         "stx            %%g0, [%0 + %2 + 0x18]\n\t" \
126         "stx            %%g0, [%0 + %2 + 0x20]\n\t" \
127         "stx            %%g0, [%0 + %2 + 0x28]\n\t" \
128         "stx            %%g0, [%0 + %2 + 0x30]\n\t" \
129         "stx            %%g0, [%0 + %2 + 0x38]\n\t" \
130         "stx            %%g0, [%0 + %2 + 0x40]\n\t" \
131         "stx            %%g0, [%0 + %2 + 0x48]\n\t" \
132         "stx            %%g0, [%0 + %2 + 0x50]\n\t" \
133         "stx            %%g0, [%0 + %2 + 0x58]\n\t" \
134         "stx            %%g0, [%0 + %2 + 0x60]\n\t" \
135         "stx            %%g0, [%0 + %2 + 0x68]\n\t" \
136         "stx            %1,   [%0 + %2 + 0x70]\n\t" \
137         "stx            %%g0, [%0 + %2 + 0x78]\n\t" \
138         "wrpr           %%g0, (1 << 3), %%wstate\n\t" \
139         : \
140         : "r" (regs), "r" (sp - sizeof(struct reg_window) - STACK_BIAS), \
141           "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
142 } while (0)
143
144 #define start_thread32(regs, pc, sp) \
145 do { \
146         pc &= 0x00000000ffffffffUL; \
147         sp &= 0x00000000ffffffffUL; \
148 \
149         regs->tstate = (regs->tstate & (TSTATE_CWP))|(TSTATE_INITIAL_MM|TSTATE_IE|TSTATE_AM); \
150         regs->tpc = ((pc & (~3)) - 4); \
151         regs->tnpc = regs->tpc + 4; \
152         regs->y = 0; \
153         set_thread_wstate(2 << 3); \
154         if (current_thread_info()->utraps) { \
155                 if (*(current_thread_info()->utraps) < 2) \
156                         kfree(current_thread_info()->utraps); \
157                 else \
158                         (*(current_thread_info()->utraps))--; \
159                 current_thread_info()->utraps = NULL; \
160         } \
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, (2 << 3), %%wstate\n\t" \
179         : \
180         : "r" (regs), "r" (sp - sizeof(struct reg_window32)), \
181           "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0]))); \
182 } while (0)
183
184 /* Free all resources held by a thread. */
185 #define release_thread(tsk)             do { } while (0)
186
187 /* Prepare to copy thread state - unlazy all lazy status */
188 #define prepare_to_copy(tsk)    do { } while (0)
189
190 extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
191
192 extern unsigned long get_wchan(struct task_struct *task);
193
194 #define KSTK_EIP(tsk)  ((tsk)->thread_info->kregs->tpc)
195 #define KSTK_ESP(tsk)  ((tsk)->thread_info->kregs->u_regs[UREG_FP])
196
197 #define cpu_relax()     barrier()
198
199 #endif /* !(__ASSEMBLY__) */
200
201 #endif /* !(__ASM_SPARC64_PROCESSOR_H) */