summaryrefslogtreecommitdiff
path: root/include/asm-v850/system.h
blob: 7091af4b786677ca176f08d01127cc6f69361185 (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
/*
 * include/asm-v850/system.h -- Low-level interrupt/thread ops
 *
 *  Copyright (C) 2001,02,03  NEC Electronics Corporation
 *  Copyright (C) 2001,02,03  Miles Bader <miles@gnu.org>
 *
 * 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.
 *
 * Written by Miles Bader <miles@gnu.org>
 */

#ifndef __V850_SYSTEM_H__
#define __V850_SYSTEM_H__

#include <linux/linkage.h>
#include <asm/ptrace.h>


/*
 * switch_to(n) should switch tasks to task ptr, first checking that
 * ptr isn't the current task, in which case it does nothing.
 */
struct thread_struct;
extern void *switch_thread (struct thread_struct *last,
			    struct thread_struct *next);
#define switch_to(prev,next,last)					      \
  do {									      \
        if (prev != next) {						      \
 		(last) = switch_thread (&prev->thread, &next->thread);	      \
	}								      \
  } while (0)


/* Enable/disable interrupts.  */
#define local_irq_enable()	__asm__ __volatile__ ("ei")
#define local_irq_disable()	__asm__ __volatile__ ("di")

#define local_save_flags(flags) \
  __asm__ __volatile__ ("stsr %1, %0" : "=r" (flags) : "i" (SR_PSW))
#define local_restore_flags(flags) \
  __asm__ __volatile__ ("ldsr %0, %1" :: "r" (flags), "i" (SR_PSW))

/* For spinlocks etc */
#define	local_irq_save(flags) \
  do { local_save_flags (flags); local_irq_disable (); } while (0) 
#define local_irq_restore(flags) \
  local_restore_flags (flags);


static inline int irqs_disabled (void)
{
	unsigned flags;
	local_save_flags (flags);
	return !!(flags & 0x20);
}


/*
 * Force strict CPU ordering.
 * Not really required on v850...
 */
#define nop()			__asm__ __volatile__ ("nop")
#define mb()			__asm__ __volatile__ ("" ::: "memory")
#define rmb()			mb ()
#define wmb()			mb ()
#define read_barrier_depends()	((void)0)
#define set_rmb(var, value)	do { xchg (&var, value); } while (0)
#define set_mb(var, value)	set_rmb (var, value)
#define set_wmb(var, value)	do { var = value; wmb (); } while (0)

#define smp_mb()	mb ()
#define smp_rmb()	rmb ()
#define smp_wmb()	wmb ()
#define smp_read_barrier_depends()	read_barrier_depends()

#define xchg(ptr, with) \
  ((__typeof__ (*(ptr)))__xchg ((unsigned long)(with), (ptr), sizeof (*(ptr))))
#define tas(ptr) (xchg ((ptr), 1))

static inline unsigned long __xchg (unsigned long with,
				    __volatile__ void *ptr, int size)
{
	unsigned long tmp, flags;

	local_irq_save (flags);

	switch (size) {
	case 1:
		tmp = *(unsigned char *)ptr;
		*(unsigned char *)ptr = with;
		break;
	case 2:
		tmp = *(unsigned short *)ptr;
		*(unsigned short *)ptr = with;
		break;
	case 4:
		tmp = *(unsigned long *)ptr;
		*(unsigned long *)ptr = with;
		break;
	}

	local_irq_restore (flags);

	return tmp;
}

#define arch_align_stack(x) (x)

#endif /* __V850_SYSTEM_H__ */