cleanup
[linux-2.4.git] / include / asm-sh64 / processor.h
1 #ifndef __ASM_SH64_PROCESSOR_H
2 #define __ASM_SH64_PROCESSOR_H
3
4 /*
5  * This file is subject to the terms and conditions of the GNU General Public
6  * License.  See the file "COPYING" in the main directory of this archive
7  * for more details.
8  *
9  * include/asm-sh64/processor.h
10  *
11  * Copyright (C) 2000, 2001  Paolo Alberelli
12  * Copyright (C) 2003  Paul Mundt
13  *
14  */
15
16 #include <asm/page.h>
17
18 #ifndef __ASSEMBLY__
19
20 #include <asm/types.h>
21 #include <asm/cache.h>
22 #include <asm/tlb.h>
23 #include <asm/registers.h>
24 #include <linux/threads.h>
25
26 /*
27  * Default implementation of macro that returns current
28  * instruction pointer ("program counter").
29  */
30 #define current_text_addr() ({ \
31 void *pc; \
32 unsigned long long __dummy; \
33 __asm__("gettr  " __t0 ", %1\n\t" \
34         "pta    4, " __t0 "\n\t" \
35         "gettr  " __t0 ", %0\n\t" \
36         "ptabs  %1, " __t0 "\n\t"       \
37         :"=r" (pc), "=r" (__dummy) \
38         : "1" (__dummy)); \
39 pc; })
40
41 /*
42  *  CPU type and hardware bug flags. Kept separately for each CPU.
43  */
44 enum cpu_type {
45         CPU_SH5_101,
46         CPU_SH5_103,
47         CPU_SH_NONE
48 };
49
50 struct sh_cpuinfo {
51         enum cpu_type type;
52         unsigned long loops_per_jiffy;
53
54         char    hard_math;
55
56         unsigned long *pgd_quick;
57         unsigned long *pmd_quick;
58         unsigned long *pte_quick;
59         unsigned long pgtable_cache_sz;
60         unsigned int cpu_clock, master_clock, bus_clock, module_clock;
61
62         /* Cache info */
63         struct cache_info icache;
64         struct cache_info dcache;
65
66         /* TLB info */
67         struct tlb_info itlb;
68         struct tlb_info dtlb;
69 };
70
71 extern struct sh_cpuinfo boot_cpu_data;
72
73 #define cpu_data (&boot_cpu_data)
74 #define current_cpu_data boot_cpu_data
75
76 #endif
77
78 /*
79  * User space process size: 2GB - 4k.
80  */
81 #define TASK_SIZE       0x7ffff000UL
82
83 /* This decides where the kernel will search for a free chunk of vm
84  * space during mmap's.
85  */
86 #define TASK_UNMAPPED_BASE      (TASK_SIZE / 3)
87
88 /*
89  * Bit of SR register
90  *
91  * FD-bit:
92  *     When it's set, it means the processor doesn't have right to use FPU,
93  *     and it results exception when the floating operation is executed.
94  *
95  * IMASK-bit:
96  *     Interrupt level mask
97  *
98  * STEP-bit:
99  *     Single step bit
100  *
101  */
102 #define SR_FD    0x00008000
103
104 #if defined(CONFIG_SH64_SR_WATCH)
105 #define SR_MMU   0x84000000
106 #else
107 #define SR_MMU   0x80000000
108 #endif
109
110 #define SR_IMASK 0x000000f0
111 #define SR_SSTEP 0x08000000
112
113 #ifndef __ASSEMBLY__
114
115 /*
116  * FPU structure and data : require 8-byte alignment as we need to access it
117    with fld.p, fst.p
118  */
119
120 struct sh_fpu_hard_struct {
121         unsigned long fp_regs[64];
122         unsigned int fpscr;
123         /* long status; * software status information */
124 };
125
126 #if 0
127 /* Dummy fpu emulator  */
128 struct sh_fpu_soft_struct {
129         unsigned long long fp_regs[32];
130         unsigned int fpscr;
131         unsigned char lookahead;
132         unsigned long entry_pc;
133 };
134 #endif
135
136 union sh_fpu_union {
137         struct sh_fpu_hard_struct hard;
138         // struct sh_fpu_soft_struct soft;
139         /* 'hard' itself only produces 32 bit alignment, yet we need
140            to access it using 64 bit load/store as well. */
141         unsigned long long alignment_dummy;
142 };
143
144 struct thread_struct {
145         unsigned long sp;
146         unsigned long pc;
147
148         unsigned long trap_no, error_code;
149         unsigned long address;
150         /* Hardware debugging registers may come here */
151
152         struct pt_regs *kregs;
153         /* floating point info */
154         union sh_fpu_union fpu;
155 };
156
157 #define INIT_MMAP \
158 { &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, NULL, NULL }
159
160 extern  struct pt_regs fake_swapper_regs;
161
162 #define INIT_THREAD  {                                          \
163         sizeof(init_stack) + (long) &init_stack, /* sp */       \
164         0,                                       /* pc */       \
165         0, 0,                                                   \
166         0,                                                      \
167         &fake_swapper_regs,                     /*kregs*/       \
168         {{{0,}},}                               /* fpu state */ \
169 }
170
171 /*
172  * Do necessary setup to start up a newly executed thread.
173  */
174 #define SR_USER (SR_MMU | SR_FD)
175
176 #define start_thread(regs, new_pc, new_sp)                      \
177         set_fs(USER_DS);                                        \
178         regs->sr = SR_USER;     /* User mode. */                \
179         regs->pc = new_pc - 4;  /* Compensate syscall exit */   \
180         regs->pc |= 1;          /* Set SHmedia ! */             \
181         regs->regs[18] = 0;                                     \
182         regs->regs[15] = new_sp
183
184 /* Forward declaration, a strange C thing */
185 struct task_struct;
186 struct mm_struct;
187
188 /* Free all resources held by a thread. */
189 extern void release_thread(struct task_struct *);
190 /*
191  * create a kernel thread without removing it from tasklists
192  */
193 extern int arch_kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
194
195 /*
196  * Bus types
197  */
198 #define EISA_bus 0
199 #define EISA_bus__is_a_macro /* for versions in ksyms.c */
200 #define MCA_bus 0
201 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
202
203
204 /* Copy and release all segment info associated with a VM */
205 #define copy_segments(p, mm)    do { } while(0)
206 #define release_segments(mm)    do { } while(0)
207 #define forget_segments()       do { } while (0)
208
209 /*
210  * FPU lazy state save handling.
211  */
212
213 extern __inline__ void release_fpu(void)
214 {
215         unsigned long long __dummy;
216
217         /* Set FD flag in SR */
218         __asm__ __volatile__("getcon    " __c0 ", %0\n\t"
219                              "or        %0, %1, %0\n\t"
220                              "putcon    %0, " __c0 "\n\t"
221                              : "=&r" (__dummy)
222                              : "r" (SR_FD));
223 }
224
225 extern __inline__ void grab_fpu(void)
226 {
227         unsigned long long __dummy;
228
229         /* Clear out FD flag in SR */
230         __asm__ __volatile__("getcon    " __c0 ", %0\n\t"
231                              "and       %0, %1, %0\n\t"
232                              "putcon    %0, " __c0 "\n\t"
233                              : "=&r" (__dummy)
234                              : "r" (~SR_FD));
235 }
236
237 /* Round to nearest, no exceptions on inexact, overflow, underflow,
238    zero-divide, invalid.  Configure option for whether to flush denorms to
239    zero, or except if a denorm is encountered.  */
240 #if defined(CONFIG_SH64_FPU_DENORM_FLUSH)
241 #define FPSCR_INIT  0x00040000
242 #else
243 #define FPSCR_INIT  0x00000000
244 #endif
245
246 /* Save the current FP regs */
247 void fpsave(struct sh_fpu_hard_struct *fpregs);
248
249 /* Initialise the FP state of a task */
250 void fpinit(struct sh_fpu_hard_struct *fpregs);
251
252 /*
253  * Return saved PC of a blocked thread.
254  */
255 extern __inline__ unsigned long thread_saved_pc(struct thread_struct *t)
256 {
257         return t->pc;
258 }
259
260 extern unsigned long get_wchan(struct task_struct *p);
261
262 #define KSTK_EIP(tsk)  ((tsk)->thread.pc)
263 #define KSTK_ESP(tsk)  ((tsk)->thread.sp)
264
265 #endif  /* __ASSEMBLY__ */
266
267 #define TASK_STKPAGES   2               /* Must be power of 2. 2 minimum */
268 #define THREAD_SIZE     (TASK_STKPAGES * PAGE_SIZE)
269 #define INIT_TASK_SIZE  THREAD_SIZE
270
271
272 #ifndef __ASSEMBLY__
273 extern struct task_struct *last_task_used_math;
274
275 extern struct task_struct * alloc_task_struct(void);
276 extern void free_task_struct(struct task_struct *);
277 #define get_task_struct(tsk)      atomic_inc(&mem_map[MAP_NR(tsk)].count)
278
279 #define init_task       (init_task_union.task)
280 #define init_stack      (init_task_union.stack)
281
282 #endif  /* __ASSEMBLY__ */
283 #endif /* __ASM_SH64_PROCESSOR_H */