summaryrefslogtreecommitdiff
path: root/include/asm-sh64/system.h
blob: b1598c26fcb088fe06d809540f7f90c3adde171d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef __ASM_SH64_SYSTEM_H
#define __ASM_SH64_SYSTEM_H

/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * include/asm-sh64/system.h
 *
 * Copyright (C) 2000, 2001  Paolo Alberelli
 * Copyright (C) 2003  Paul Mundt
 * Copyright (C) 2004  Richard Curnow
 *
 */

#include <asm/registers.h>
#include <asm/processor.h>

/*
 *	switch_to() should switch tasks to task nr n, first
 */

typedef struct {
	unsigned long seg;
} mm_segment_t;

extern struct task_struct *sh64_switch_to(struct task_struct *prev,
					  struct thread_struct *prev_thread,
					  struct task_struct *next,
					  struct thread_struct *next_thread);

#define switch_to(prev,next,last) \
	do {\
		if (last_task_used_math != next) {\
			struct pt_regs *regs = next->thread.uregs;\
			if (regs) regs->sr |= SR_FD;\
		}\
		last = sh64_switch_to(prev, &prev->thread, next, &next->thread);\
	} while(0)

#define nop() __asm__ __volatile__ ("nop")

#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))

#define tas(ptr) (xchg((ptr), 1))

extern void __xchg_called_with_bad_pointer(void);

#define mb()	__asm__ __volatile__ ("synco": : :"memory")
#define rmb()	mb()
#define wmb()	__asm__ __volatile__ ("synco": : :"memory")
#define read_barrier_depends()	do { } while (0)

#ifdef CONFIG_SMP
#define smp_mb()	mb()
#define smp_rmb()	rmb()
#define smp_wmb()	wmb()
#define smp_read_barrier_depends()	read_barrier_depends()
#else
#define smp_mb()	barrier()
#define smp_rmb()	barrier()
#define smp_wmb()	barrier()
#define smp_read_barrier_depends()	do { } while (0)
#endif /* CONFIG_SMP */

#define set_rmb(var, value) do { (void)xchg(&var, value); } while (0)
#define set_mb(var, value) set_rmb(var, value)

/* Interrupt Control */
#ifndef HARD_CLI
#define SR_MASK_L 0x000000f0L
#define SR_MASK_LL 0x00000000000000f0LL
#else
#define SR_MASK_L 0x10000000L
#define SR_MASK_LL 0x0000000010000000LL
#endif

static __inline__ void local_irq_enable(void)
{
	/* cli/sti based on SR.BL */
	unsigned long long __dummy0, __dummy1=~SR_MASK_LL;

	__asm__ __volatile__("getcon	" __SR ", %0\n\t"
			     "and	%0, %1, %0\n\t"
			     "putcon	%0, " __SR "\n\t"
			     : "=&r" (__dummy0)
			     : "r" (__dummy1));
}

static __inline__ void local_irq_disable(void)
{
	/* cli/sti based on SR.BL */
	unsigned long long __dummy0, __dummy1=SR_MASK_LL;
	__asm__ __volatile__("getcon	" __SR ", %0\n\t"
			     "or	%0, %1, %0\n\t"
			     "putcon	%0, " __SR "\n\t"
			     : "=&r" (__dummy0)
			     : "r" (__dummy1));
}

#define local_save_flags(x) 						\
(__extension__ ({	unsigned long long __dummy=SR_MASK_LL;		\
	__asm__ __volatile__(						\
		"getcon	" __SR ", %0\n\t"				\
		"and	%0, %1, %0"					\
		: "=&r" (x)						\
		: "r" (__dummy));}))

#define local_irq_save(x)						\
(__extension__ ({	unsigned long long __d2=SR_MASK_LL, __d1;	\
	__asm__ __volatile__(          	         			\
		"getcon	" __SR ", %1\n\t" 				\
		"or	%1, r63, %0\n\t"				\
		"or	%1, %2, %1\n\t"					\
		"putcon	%1, " __SR "\n\t"    				\
		"and	%0, %2, %0"    					\
		: "=&r" (x), "=&r" (__d1)				\
		: "r" (__d2));}));

#define local_irq_restore(x) do { 					\
	if ( ((x) & SR_MASK_L) == 0 )		/* dropping to 0 ? */	\
		local_irq_enable();		/* yes...re-enable */	\
} while (0)

#define irqs_disabled()			\
({					\
	unsigned long flags;		\
	local_save_flags(flags);	\
	(flags != 0);			\
})

static inline unsigned long xchg_u32(volatile int * m, unsigned long val)
{
	unsigned long flags, retval;

	local_irq_save(flags);
	retval = *m;
	*m = val;
	local_irq_restore(flags);
	return retval;
}

static inline unsigned long xchg_u8(volatile unsigned char * m, unsigned long val)
{
	unsigned long flags, retval;

	local_irq_save(flags);
	retval = *m;
	*m = val & 0xff;
	local_irq_restore(flags);
	return retval;
}

static __inline__ unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
{
	switch (size) {
	case 4:
		return xchg_u32(ptr, x);
		break;
	case 1:
		return xchg_u8(ptr, x);
		break;
	}
	__xchg_called_with_bad_pointer();
	return x;
}

/* XXX
 * disable hlt during certain critical i/o operations
 */
#define HAVE_DISABLE_HLT
void disable_hlt(void);
void enable_hlt(void);


#define smp_mb()        barrier()
#define smp_rmb()       barrier()
#define smp_wmb()       barrier()

#ifdef CONFIG_SH_ALPHANUMERIC
/* This is only used for debugging. */
extern void print_seg(char *file,int line);
#define PLS() print_seg(__FILE__,__LINE__)
#else	/* CONFIG_SH_ALPHANUMERIC */
#define PLS()
#endif	/* CONFIG_SH_ALPHANUMERIC */

#define PL() printk("@ <%s,%s:%d>\n",__FILE__,__FUNCTION__,__LINE__)

#define arch_align_stack(x) (x)

#endif /* __ASM_SH64_SYSTEM_H */