sh: Fixup __strnlen_user() behaviour.
[pandora-kernel.git] / include / asm-sh / processor.h
1 /*
2  * include/asm-sh/processor.h
3  *
4  * Copyright (C) 1999, 2000  Niibe Yutaka
5  * Copyright (C) 2002, 2003  Paul Mundt
6  */
7
8 #ifndef __ASM_SH_PROCESSOR_H
9 #define __ASM_SH_PROCESSOR_H
10 #ifdef __KERNEL__
11
12 #include <linux/compiler.h>
13 #include <asm/page.h>
14 #include <asm/types.h>
15 #include <asm/cache.h>
16 #include <asm/ptrace.h>
17
18 /*
19  * Default implementation of macro that returns current
20  * instruction pointer ("program counter").
21  */
22 #define current_text_addr() ({ void *pc; __asm__("mova  1f, %0\n1:":"=z" (pc)); pc; })
23
24 /* Core Processor Version Register */
25 #define CCN_PVR         0xff000030
26 #define CCN_CVR         0xff000040
27 #define CCN_PRR         0xff000044
28
29 /*
30  *  CPU type and hardware bug flags. Kept separately for each CPU.
31  *
32  *  Each one of these also needs a CONFIG_CPU_SUBTYPE_xxx entry
33  *  in arch/sh/mm/Kconfig, as well as an entry in arch/sh/kernel/setup.c
34  *  for parsing the subtype in get_cpu_subtype().
35  */
36 enum cpu_type {
37         /* SH-2 types */
38         CPU_SH7604,
39
40         /* SH-3 types */
41         CPU_SH7705, CPU_SH7707,  CPU_SH7708, CPU_SH7708S, CPU_SH7708R,
42         CPU_SH7709, CPU_SH7709A, CPU_SH7729, CPU_SH7300,
43
44         /* SH-4 types */
45         CPU_SH7750, CPU_SH7750S, CPU_SH7750R, CPU_SH7751, CPU_SH7751R,
46         CPU_SH7760, CPU_ST40RA, CPU_ST40GX1, CPU_SH4_202, CPU_SH4_501,
47         CPU_SH73180, CPU_SH7770, CPU_SH7780, CPU_SH7781,
48
49         /* Unknown subtype */
50         CPU_SH_NONE
51 };
52
53 struct sh_cpuinfo {
54         enum cpu_type type;
55         unsigned long loops_per_jiffy;
56
57         struct cache_info icache;
58         struct cache_info dcache;
59
60         unsigned long flags;
61 };
62
63 extern struct sh_cpuinfo boot_cpu_data;
64
65 #ifdef CONFIG_SMP
66 extern struct sh_cpuinfo cpu_data[];
67 #define current_cpu_data cpu_data[smp_processor_id()]
68 #else
69 #define cpu_data (&boot_cpu_data)
70 #define current_cpu_data boot_cpu_data
71 #endif
72
73 /*
74  * User space process size: 2GB.
75  *
76  * Since SH7709 and SH7750 have "area 7", we can't use 0x7c000000--0x7fffffff
77  */
78 #define TASK_SIZE       0x7c000000UL
79
80 /* This decides where the kernel will search for a free chunk of vm
81  * space during mmap's.
82  */
83 #define TASK_UNMAPPED_BASE      (TASK_SIZE / 3)
84
85 /*
86  * Bit of SR register
87  *
88  * FD-bit:
89  *     When it's set, it means the processor doesn't have right to use FPU,
90  *     and it results exception when the floating operation is executed.
91  *
92  * IMASK-bit:
93  *     Interrupt level mask
94  */
95 #define SR_FD           0x00008000
96 #define SR_DSP          0x00001000
97 #define SR_IMASK        0x000000f0
98
99 /*
100  * FPU structure and data
101  */
102
103 struct sh_fpu_hard_struct {
104         unsigned long fp_regs[16];
105         unsigned long xfp_regs[16];
106         unsigned long fpscr;
107         unsigned long fpul;
108
109         long status; /* software status information */
110 };
111
112 /* Dummy fpu emulator  */
113 struct sh_fpu_soft_struct {
114         unsigned long fp_regs[16];
115         unsigned long xfp_regs[16];
116         unsigned long fpscr;
117         unsigned long fpul;
118
119         unsigned char lookahead;
120         unsigned long entry_pc;
121 };
122
123 union sh_fpu_union {
124         struct sh_fpu_hard_struct hard;
125         struct sh_fpu_soft_struct soft;
126 };
127
128 /*
129  * Processor flags
130  */
131
132 #define CPU_HAS_FPU             0x0001  /* Hardware FPU support */
133 #define CPU_HAS_P2_FLUSH_BUG    0x0002  /* Need to flush the cache in P2 area */
134 #define CPU_HAS_MMU_PAGE_ASSOC  0x0004  /* SH3: TLB way selection bit support */
135 #define CPU_HAS_DSP             0x0008  /* SH-DSP: DSP support */
136 #define CPU_HAS_PERF_COUNTER    0x0010  /* Hardware performance counters */
137 #define CPU_HAS_PTEA            0x0020  /* PTEA register */
138
139 struct thread_struct {
140         unsigned long sp;
141         unsigned long pc;
142
143         unsigned long trap_no, error_code;
144         unsigned long address;
145         /* Hardware debugging registers may come here */
146         unsigned long ubc_pc;
147
148         /* floating point info */
149         union sh_fpu_union fpu;
150 };
151
152 typedef struct {
153         unsigned long seg;
154 } mm_segment_t;
155
156 /* Count of active tasks with UBC settings */
157 extern int ubc_usercnt;
158
159 #define INIT_THREAD  {                                          \
160         sizeof(init_stack) + (long) &init_stack, /* sp */       \
161         0,                                       /* pc */       \
162         0, 0,                                                   \
163         0,                                                      \
164         0,                                                      \
165         {{{0,}},}                               /* fpu state */ \
166 }
167
168 /*
169  * Do necessary setup to start up a newly executed thread.
170  */
171 #define start_thread(regs, new_pc, new_sp)       \
172         set_fs(USER_DS);                         \
173         regs->pr = 0;                            \
174         regs->sr = SR_FD;       /* User mode. */ \
175         regs->pc = new_pc;                       \
176         regs->regs[15] = new_sp
177
178 /* Forward declaration, a strange C thing */
179 struct task_struct;
180 struct mm_struct;
181
182 /* Free all resources held by a thread. */
183 extern void release_thread(struct task_struct *);
184
185 /* Prepare to copy thread state - unlazy all lazy status */
186 #define prepare_to_copy(tsk)    do { } while (0)
187
188 /*
189  * create a kernel thread without removing it from tasklists
190  */
191 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
192
193 /* Copy and release all segment info associated with a VM */
194 #define copy_segments(p, mm)    do { } while(0)
195 #define release_segments(mm)    do { } while(0)
196
197 /*
198  * FPU lazy state save handling.
199  */
200
201 static __inline__ void disable_fpu(void)
202 {
203         unsigned long __dummy;
204
205         /* Set FD flag in SR */
206         __asm__ __volatile__("stc       sr, %0\n\t"
207                              "or        %1, %0\n\t"
208                              "ldc       %0, sr"
209                              : "=&r" (__dummy)
210                              : "r" (SR_FD));
211 }
212
213 static __inline__ void enable_fpu(void)
214 {
215         unsigned long __dummy;
216
217         /* Clear out FD flag in SR */
218         __asm__ __volatile__("stc       sr, %0\n\t"
219                              "and       %1, %0\n\t"
220                              "ldc       %0, sr"
221                              : "=&r" (__dummy)
222                              : "r" (~SR_FD));
223 }
224
225 static __inline__ void release_fpu(struct pt_regs *regs)
226 {
227         regs->sr |= SR_FD;
228 }
229
230 static __inline__ void grab_fpu(struct pt_regs *regs)
231 {
232         regs->sr &= ~SR_FD;
233 }
234
235 #ifdef CONFIG_CPU_SH4
236 extern void save_fpu(struct task_struct *__tsk, struct pt_regs *regs);
237 #else
238 #define save_fpu(tsk)   do { } while (0)
239 #endif
240
241 #define unlazy_fpu(tsk, regs) do {                      \
242         if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) {   \
243                 save_fpu(tsk, regs);                    \
244         }                                               \
245 } while (0)
246
247 #define clear_fpu(tsk, regs) do {                               \
248         if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) {           \
249                 clear_tsk_thread_flag(tsk, TIF_USEDFPU);        \
250                 release_fpu(regs);                              \
251         }                                                       \
252 } while (0)
253
254 /* Double presision, NANS as NANS, rounding to nearest, no exceptions */
255 #define FPSCR_INIT  0x00080000
256
257 #define FPSCR_CAUSE_MASK        0x0001f000      /* Cause bits */
258 #define FPSCR_FLAG_MASK         0x0000007c      /* Flag bits */
259
260 /*
261  * Return saved PC of a blocked thread.
262  */
263 #define thread_saved_pc(tsk)    (tsk->thread.pc)
264
265 extern unsigned long get_wchan(struct task_struct *p);
266
267 #define KSTK_EIP(tsk)  ((tsk)->thread.pc)
268 #define KSTK_ESP(tsk)  ((tsk)->thread.sp)
269
270 #define cpu_sleep()     __asm__ __volatile__ ("sleep" : : : "memory")
271 #define cpu_relax()     barrier()
272
273 #if defined(CONFIG_CPU_SH2A) || defined(CONFIG_CPU_SH3) || \
274     defined(CONFIG_CPU_SH4)
275 #define PREFETCH_STRIDE         L1_CACHE_BYTES
276 #define ARCH_HAS_PREFETCH
277 #define ARCH_HAS_PREFETCHW
278 static inline void prefetch(void *x)
279 {
280         __asm__ __volatile__ ("pref @%0\n\t" : : "r" (x) : "memory");
281 }
282
283 #define prefetchw(x)    prefetch(x)
284 #endif
285
286 #endif /* __KERNEL__ */
287 #endif /* __ASM_SH_PROCESSOR_H */