- David Miller: sparc and net updates. Fix merge_segments.
[davej-history.git] / include / asm-sparc / processor.h
blob41b96727ad85a016b27556ad5709131492684f17
1 /* $Id: processor.h,v 1.78 2000/11/30 08:37:31 anton Exp $
2 * include/asm-sparc/processor.h
4 * Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu)
5 */
7 #ifndef __ASM_SPARC_PROCESSOR_H
8 #define __ASM_SPARC_PROCESSOR_H
11 * Sparc32 implementation of macro that returns current
12 * instruction pointer ("program counter").
14 #define current_text_addr() ({ void *pc; __asm__("sethi %%hi(1f), %0; or %0, %%lo(1f), %0;\n1:" : "=r" (pc)); pc; })
16 #include <linux/a.out.h>
18 #include <asm/psr.h>
19 #include <asm/ptrace.h>
20 #include <asm/head.h>
21 #include <asm/signal.h>
22 #include <asm/segment.h>
23 #include <asm/btfixup.h>
24 #include <asm/page.h>
25 #include <asm/atomic.h>
28 * Bus types
30 #define EISA_bus 0
31 #define EISA_bus__is_a_macro /* for versions in ksyms.c */
32 #define MCA_bus 0
33 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
36 * The sparc has no problems with write protection
38 #define wp_works_ok 1
39 #define wp_works_ok__is_a_macro /* for versions in ksyms.c */
41 /* Whee, this is STACK_TOP + PAGE_SIZE and the lowest kernel address too...
42 * That one page is used to protect kernel from intruders, so that
43 * we can make our access_ok test faster
45 #define TASK_SIZE PAGE_OFFSET
47 struct fpq {
48 unsigned long *insn_addr;
49 unsigned long insn;
52 typedef struct {
53 int seg;
54 } mm_segment_t;
56 /* The Sparc processor specific thread struct. */
57 struct thread_struct {
58 unsigned long uwinmask __attribute__ ((aligned (8)));
59 struct pt_regs *kregs;
61 /* Context switch saved kernel state. */
62 unsigned long ksp __attribute__ ((aligned (8)));
63 unsigned long kpc;
64 unsigned long kpsr;
65 unsigned long kwim;
67 /* Special child fork kpsr/kwim values. */
68 unsigned long fork_kpsr __attribute__ ((aligned (8)));
69 unsigned long fork_kwim;
71 /* A place to store user windows and stack pointers
72 * when the stack needs inspection.
74 #define NSWINS 8
75 struct reg_window reg_window[NSWINS] __attribute__ ((aligned (8)));
76 unsigned long rwbuf_stkptrs[NSWINS] __attribute__ ((aligned (8)));
77 unsigned long w_saved;
79 /* Floating point regs */
80 unsigned long float_regs[32] __attribute__ ((aligned (8)));
81 unsigned long fsr;
82 unsigned long fpqdepth;
83 struct fpq fpqueue[16];
84 unsigned long flags;
85 mm_segment_t current_ds;
86 struct exec core_exec; /* just what it says. */
87 int new_signal;
88 atomic_t refcount; /* used for sun4c only */
91 #define SPARC_FLAG_KTHREAD 0x1 /* task is a kernel thread */
92 #define SPARC_FLAG_UNALIGNED 0x2 /* is allowed to do unaligned accesses */
93 #define SPARC_FLAG_MMAPSHARED 0x4 /* task wants a shared mmap */
95 #define INIT_MMAP { &init_mm, (0), (0), \
96 NULL, __pgprot(0x0) , VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
98 #define INIT_THREAD { \
99 /* uwinmask, kregs, ksp, kpc, kpsr, kwim */ \
100 0, 0, 0, 0, 0, 0, \
101 /* fork_kpsr, fork_kwim */ \
102 0, 0, \
103 /* reg_window */ \
104 { { { 0, }, { 0, } }, }, \
105 /* rwbuf_stkptrs */ \
106 { 0, 0, 0, 0, 0, 0, 0, 0, }, \
107 /* w_saved */ \
108 0, \
109 /* FPU regs */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
111 /* FPU status, FPU qdepth, FPU queue */ \
112 0, 0, { { 0, 0, }, }, \
113 /* flags, current_ds, */ \
114 SPARC_FLAG_KTHREAD, KERNEL_DS, \
115 /* core_exec */ \
116 { 0, }, \
117 /* new_signal */ \
118 0, \
121 /* Return saved PC of a blocked thread. */
122 extern __inline__ unsigned long thread_saved_pc(struct thread_struct *t)
124 return t->kpc;
127 /* Do necessary setup to start up a newly executed thread. */
128 extern __inline__ void start_thread(struct pt_regs * regs, unsigned long pc,
129 unsigned long sp)
131 register unsigned long zero asm("g1");
133 regs->psr = (regs->psr & (PSR_CWP)) | PSR_S;
134 regs->pc = ((pc & (~3)) - 4);
135 regs->npc = regs->pc + 4;
136 regs->y = 0;
137 zero = 0;
138 __asm__ __volatile__("std\t%%g0, [%0 + %3 + 0x00]\n\t"
139 "std\t%%g0, [%0 + %3 + 0x08]\n\t"
140 "std\t%%g0, [%0 + %3 + 0x10]\n\t"
141 "std\t%%g0, [%0 + %3 + 0x18]\n\t"
142 "std\t%%g0, [%0 + %3 + 0x20]\n\t"
143 "std\t%%g0, [%0 + %3 + 0x28]\n\t"
144 "std\t%%g0, [%0 + %3 + 0x30]\n\t"
145 "st\t%1, [%0 + %3 + 0x38]\n\t"
146 "st\t%%g0, [%0 + %3 + 0x3c]"
147 : : "r" (regs), "r" (sp - REGWIN_SZ), "r" (zero),
148 "i" ((const unsigned long)(&((struct pt_regs *)0)->u_regs[0])));
151 /* Free all resources held by a thread. */
152 #define release_thread(tsk) do { } while(0)
153 extern pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
156 #define copy_segments(__tsk, __mm) \
157 if((__tsk) == current && \
158 (__mm) != NULL) \
159 flush_user_windows()
160 #define release_segments(mm) do { } while (0)
161 #define forget_segments() do { } while (0)
163 #define get_wchan(__TSK) \
164 ({ extern void scheduling_functions_start_here(void); \
165 extern void scheduling_functions_end_here(void); \
166 unsigned long pc, fp, bias = 0; \
167 unsigned long task_base = (unsigned long) (__TSK); \
168 unsigned long __ret = 0; \
169 struct reg_window *rw; \
170 int count = 0; \
171 if (!(__TSK) || (__TSK) == current || \
172 (__TSK)->state == TASK_RUNNING) \
173 goto __out; \
174 fp = (__TSK)->thread.ksp + bias; \
175 do { \
176 /* Bogus frame pointer? */ \
177 if (fp < (task_base + sizeof(struct task_struct)) || \
178 fp >= (task_base + (2 * PAGE_SIZE))) \
179 break; \
180 rw = (struct reg_window *) fp; \
181 pc = rw->ins[7]; \
182 if (pc < ((unsigned long) scheduling_functions_start_here) || \
183 pc >= ((unsigned long) scheduling_functions_end_here)) { \
184 __ret = pc; \
185 goto __out; \
187 fp = rw->ins[6] + bias; \
188 } while (++count < 16); \
189 __out: __ret; \
192 #define KSTK_EIP(tsk) ((tsk)->thread.kregs->pc)
193 #define KSTK_ESP(tsk) ((tsk)->thread.kregs->u_regs[UREG_FP])
195 #ifdef __KERNEL__
196 #define THREAD_SIZE (2*PAGE_SIZE)
198 extern struct task_struct *last_task_used_math;
200 /* Allocation and freeing of basic task resources. */
201 BTFIXUPDEF_CALL(struct task_struct *, alloc_task_struct, void)
202 BTFIXUPDEF_CALL(void, free_task_struct, struct task_struct *)
203 BTFIXUPDEF_CALL(void, get_task_struct, struct task_struct *)
205 #define alloc_task_struct() BTFIXUP_CALL(alloc_task_struct)()
206 #define free_task_struct(tsk) BTFIXUP_CALL(free_task_struct)(tsk)
207 #define get_task_struct(tsk) BTFIXUP_CALL(get_task_struct)(tsk)
209 #define init_task (init_task_union.task)
210 #define init_stack (init_task_union.stack)
212 #endif
214 #endif /* __ASM_SPARC_PROCESSOR_H */