blob: f4b54040dbc39f5b4461498f65b21f8c49c4af1e [file] [log] [blame]
Paul Mundtaf3c7df2007-11-09 17:08:54 +09001/*
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_32_H
9#define __ASM_SH_PROCESSOR_32_H
10#ifdef __KERNEL__
11
12#include <linux/compiler.h>
Paul Mundtfa439722008-09-04 18:53:58 +090013#include <linux/linkage.h>
Paul Mundtaf3c7df2007-11-09 17:08:54 +090014#include <asm/page.h>
15#include <asm/types.h>
Paul Mundtaf3c7df2007-11-09 17:08:54 +090016#include <asm/ptrace.h>
Paul Mundt09a07292009-11-09 16:27:40 +090017#include <asm/ubc.h>
Paul Mundtaf3c7df2007-11-09 17:08:54 +090018
19/*
20 * Default implementation of macro that returns current
21 * instruction pointer ("program counter").
22 */
Paul Mundt103340c2008-07-28 22:32:03 +090023#define current_text_addr() ({ void *pc; __asm__("mova 1f, %0\n.align 2\n1:":"=z" (pc)); pc; })
Paul Mundtaf3c7df2007-11-09 17:08:54 +090024
25/* Core Processor Version Register */
26#define CCN_PVR 0xff000030
27#define CCN_CVR 0xff000040
28#define CCN_PRR 0xff000044
29
Paul Mundtfa439722008-09-04 18:53:58 +090030asmlinkage void __init sh_cpu_init(void);
31
Paul Mundtaf3c7df2007-11-09 17:08:54 +090032/*
33 * User space process size: 2GB.
34 *
35 * Since SH7709 and SH7750 have "area 7", we can't use 0x7c000000--0x7fffffff
36 */
37#define TASK_SIZE 0x7c000000UL
38
David Howells922a70d2008-02-08 04:19:26 -080039#define STACK_TOP TASK_SIZE
40#define STACK_TOP_MAX STACK_TOP
41
Paul Mundtaf3c7df2007-11-09 17:08:54 +090042/* This decides where the kernel will search for a free chunk of vm
43 * space during mmap's.
44 */
45#define TASK_UNMAPPED_BASE (TASK_SIZE / 3)
46
47/*
48 * Bit of SR register
49 *
50 * FD-bit:
51 * When it's set, it means the processor doesn't have right to use FPU,
52 * and it results exception when the floating operation is executed.
53 *
54 * IMASK-bit:
55 * Interrupt level mask
56 */
Paul Mundtaf3c7df2007-11-09 17:08:54 +090057#define SR_DSP 0x00001000
58#define SR_IMASK 0x000000f0
Paul Mundt9bbafce2008-03-26 19:02:47 +090059#define SR_FD 0x00008000
Paul Mundtaf3c7df2007-11-09 17:08:54 +090060
61/*
Michael Trimarchi01ab1032009-04-03 17:32:33 +000062 * DSP structure and data
63 */
64struct sh_dsp_struct {
65 unsigned long dsp_regs[14];
66 long status;
67};
68
69/*
Paul Mundtaf3c7df2007-11-09 17:08:54 +090070 * FPU structure and data
71 */
72
73struct sh_fpu_hard_struct {
74 unsigned long fp_regs[16];
75 unsigned long xfp_regs[16];
76 unsigned long fpscr;
77 unsigned long fpul;
78
79 long status; /* software status information */
80};
81
82/* Dummy fpu emulator */
83struct sh_fpu_soft_struct {
84 unsigned long fp_regs[16];
85 unsigned long xfp_regs[16];
86 unsigned long fpscr;
87 unsigned long fpul;
88
89 unsigned char lookahead;
90 unsigned long entry_pc;
91};
92
93union sh_fpu_union {
94 struct sh_fpu_hard_struct hard;
95 struct sh_fpu_soft_struct soft;
96};
97
98struct thread_struct {
99 /* Saved registers when thread is descheduled */
100 unsigned long sp;
101 unsigned long pc;
102
Paul Mundt09a07292009-11-09 16:27:40 +0900103 /* Save middle states of ptrace breakpoints */
104 struct perf_event *ptrace_bps[NR_UBC_CHANNELS];
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900105
106 /* floating point info */
107 union sh_fpu_union fpu;
Michael Trimarchi01ab1032009-04-03 17:32:33 +0000108
109#ifdef CONFIG_SH_DSP
110 /* Dsp status information */
111 struct sh_dsp_struct dsp_status;
112#endif
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900113};
114
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900115#define INIT_THREAD { \
116 .sp = sizeof(init_stack) + (long) &init_stack, \
117}
118
119/*
120 * Do necessary setup to start up a newly executed thread.
121 */
Roel Kluindc66ff62009-01-22 15:16:14 +0000122#define start_thread(_regs, new_pc, new_sp) \
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900123 set_fs(USER_DS); \
Roel Kluindc66ff62009-01-22 15:16:14 +0000124 _regs->pr = 0; \
125 _regs->sr = SR_FD; /* User mode. */ \
126 _regs->pc = new_pc; \
127 _regs->regs[15] = new_sp
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900128
129/* Forward declaration, a strange C thing */
130struct task_struct;
131struct mm_struct;
132
133/* Free all resources held by a thread. */
134extern void release_thread(struct task_struct *);
135
136/* Prepare to copy thread state - unlazy all lazy status */
137#define prepare_to_copy(tsk) do { } while (0)
138
139/*
140 * create a kernel thread without removing it from tasklists
141 */
142extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
143
144/* Copy and release all segment info associated with a VM */
145#define copy_segments(p, mm) do { } while(0)
146#define release_segments(mm) do { } while(0)
147
148/*
149 * FPU lazy state save handling.
150 */
151
152static __inline__ void disable_fpu(void)
153{
154 unsigned long __dummy;
155
156 /* Set FD flag in SR */
157 __asm__ __volatile__("stc sr, %0\n\t"
158 "or %1, %0\n\t"
159 "ldc %0, sr"
160 : "=&r" (__dummy)
161 : "r" (SR_FD));
162}
163
164static __inline__ void enable_fpu(void)
165{
166 unsigned long __dummy;
167
168 /* Clear out FD flag in SR */
169 __asm__ __volatile__("stc sr, %0\n\t"
170 "and %1, %0\n\t"
171 "ldc %0, sr"
172 : "=&r" (__dummy)
173 : "r" (~SR_FD));
174}
175
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900176/* Double presision, NANS as NANS, rounding to nearest, no exceptions */
177#define FPSCR_INIT 0x00080000
178
179#define FPSCR_CAUSE_MASK 0x0001f000 /* Cause bits */
180#define FPSCR_FLAG_MASK 0x0000007c /* Flag bits */
181
182/*
183 * Return saved PC of a blocked thread.
184 */
185#define thread_saved_pc(tsk) (tsk->thread.pc)
186
187void show_trace(struct task_struct *tsk, unsigned long *sp,
188 struct pt_regs *regs);
Paul Mundt5d2685d2008-12-17 15:56:06 +0900189
190#ifdef CONFIG_DUMP_CODE
Paul Mundt9cfc9a92008-11-26 14:31:03 +0900191void show_code(struct pt_regs *regs);
Paul Mundt5d2685d2008-12-17 15:56:06 +0900192#else
193static inline void show_code(struct pt_regs *regs)
194{
195}
196#endif
197
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900198extern unsigned long get_wchan(struct task_struct *p);
199
200#define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
201#define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[15])
202
Roel Kluindc66ff62009-01-22 15:16:14 +0000203#define user_stack_pointer(_regs) ((_regs)->regs[15])
Paul Mundt9996b422008-09-12 22:11:36 +0900204
Paul Mundta73090ff2009-02-27 16:42:05 +0900205#if defined(CONFIG_CPU_SH2A) || defined(CONFIG_CPU_SH4)
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900206#define PREFETCH_STRIDE L1_CACHE_BYTES
207#define ARCH_HAS_PREFETCH
208#define ARCH_HAS_PREFETCHW
209static inline void prefetch(void *x)
210{
211 __asm__ __volatile__ ("pref @%0\n\t" : : "r" (x) : "memory");
212}
213
214#define prefetchw(x) prefetch(x)
215#endif
216
Paul Mundtaf3c7df2007-11-09 17:08:54 +0900217#endif /* __KERNEL__ */
218#endif /* __ASM_SH_PROCESSOR_32_H */