import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / include / asm-cris / system.h
1 #ifndef __ASM_CRIS_SYSTEM_H
2 #define __ASM_CRIS_SYSTEM_H
3
4 #include <linux/config.h>
5
6 #include <asm/segment.h>
7
8 /* the switch_to macro calls resume, an asm function in entry.S which does the actual
9  * task switching.
10  */
11
12 extern struct task_struct *resume(struct task_struct *prev, struct task_struct *next, int);
13 #define prepare_to_switch()     do { } while(0)
14 #define switch_to(prev,next,last) last = resume(prev,next, \
15                                          (int)&((struct task_struct *)0)->thread)
16
17 /* read the CPU version register */
18
19 extern inline unsigned long rdvr(void) { 
20         unsigned char vr;
21         __asm__ volatile ("move $vr,%0" : "=rm" (vr));
22         return vr;
23 }
24
25 /* read/write the user-mode stackpointer */
26
27 extern inline unsigned long rdusp(void) {
28         unsigned long usp;
29         __asm__ __volatile__("move $usp,%0" : "=rm" (usp));
30         return usp;
31 }
32
33 #define wrusp(usp) \
34         __asm__ __volatile__("move %0,$usp" : /* no outputs */ : "rm" (usp))
35
36 /* read the current stackpointer */
37
38 extern inline unsigned long rdsp(void) {
39         unsigned long sp;
40         __asm__ __volatile__("move.d $sp,%0" : "=rm" (sp));
41         return sp;
42 }
43
44 extern inline unsigned long _get_base(char * addr)
45 {
46   return 0;
47 }
48
49 #define nop() __asm__ __volatile__ ("nop");
50
51 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
52 #define tas(ptr) (xchg((ptr),1))
53
54 struct __xchg_dummy { unsigned long a[100]; };
55 #define __xg(x) ((struct __xchg_dummy *)(x))
56
57 #if 0
58 /* use these and an oscilloscope to see the fraction of time we're running with IRQ's disabled */
59 /* it assumes the LED's are on port 0x90000000 of course. */
60 #define sti() __asm__ __volatile__ ( "ei\n\tpush $r0\n\tmoveq 0,$r0\n\tmove.d $r0,[0x90000000]\n\tpop $r0" );
61 #define cli() __asm__ __volatile__ ( "di\n\tpush $r0\n\tmove.d 0x40000,$r0\n\tmove.d $r0,[0x90000000]\n\tpop $r0");
62 #define save_flags(x) __asm__ __volatile__ ("move $ccr,%0" : "=rm" (x) : : "memory");
63 #define restore_flags(x) __asm__ __volatile__ ("move %0,$ccr\n\tbtstq 5,%0\n\tbpl 1f\n\tnop\n\tpush $r0\n\tmoveq 0,$r0\n\tmove.d $r0,[0x90000000]\n\tpop $r0\n1:\n" : : "r" (x) : "memory");
64 #else
65 #define __cli() __asm__ __volatile__ ( "di" : : :"memory");
66 #define __sti() __asm__ __volatile__ ( "ei" : : :"memory");
67 #define __save_flags(x) __asm__ __volatile__ ("move $ccr,%0" : "=rm" (x) : : "memory");
68 #define __restore_flags(x) __asm__ __volatile__ ("move %0,$ccr" : : "rm" (x) : "memory");
69
70 /* For spinlocks etc */
71 #define local_irq_save(x) __asm__ __volatile__ ("move $ccr,%0\n\tdi" : "=rm" (x) : : "memory"); 
72 #define local_irq_set(x) __asm__ __volatile__ ("move $ccr,%0\n\tei" : "=rm" (x) : : "memory");
73 #define local_irq_restore(x) restore_flags(x)
74
75 #define local_irq_disable()  cli()
76 #define local_irq_enable()   sti()
77
78 #endif
79
80 #define cli() __cli()
81 #define sti() __sti()
82 #define save_flags(x) __save_flags(x)
83 #define restore_flags(x) __restore_flags(x)
84 #define save_and_cli(x) do { save_flags(x); cli(); } while(0)
85 #define save_and_sti(x) do { save_flags(x); sti(); } while(0)
86
87 extern inline unsigned long __xchg(unsigned long x, void * ptr, int size)
88 {
89   /* since Etrax doesn't have any atomic xchg instructions, we need to disable
90      irq's (if enabled) and do it with move.d's */
91 #if 0
92   unsigned int flags;
93   save_flags(flags); /* save flags, including irq enable bit */
94   cli();             /* shut off irq's */
95   switch (size) {
96   case 1:
97     __asm__ __volatile__ (
98        "move.b %0,r0\n\t"
99        "move.b %1,%0\n\t"
100        "move.b r0,%1\n\t"
101        : "=r" (x)
102        : "m" (*__xg(ptr)), "r" (x)
103        : "memory","r0");    
104     break;
105   case 2:
106     __asm__ __volatile__ (
107        "move.w %0,r0\n\t"
108        "move.w %1,%0\n\t"
109        "move.w r0,%1\n\t"
110        : "=r" (x)
111        : "m" (*__xg(ptr)), "r" (x)
112        : "memory","r0");
113     break;
114   case 4:
115     __asm__ __volatile__ (
116        "move.d %0,r0\n\t"
117        "move.d %1,%0\n\t"
118        "move.d r0,%1\n\t"
119        : "=r" (x)
120        : "m" (*__xg(ptr)), "r" (x)
121        : "memory","r0");
122     break;
123   }
124   restore_flags(flags); /* restore irq enable bit */
125   return x;
126 #else
127   unsigned long flags,temp;
128   save_flags(flags); /* save flags, including irq enable bit */
129   cli();             /* shut off irq's */
130   switch (size) {
131   case 1:
132     *((unsigned char *)&temp) = x;
133     x = *(unsigned char *)ptr;
134     *(unsigned char *)ptr = *((unsigned char *)&temp);
135     break;
136   case 2:
137     *((unsigned short *)&temp) = x;
138     x = *(unsigned short *)ptr;
139     *(unsigned short *)ptr = *((unsigned short *)&temp);
140     break;
141   case 4:
142     temp = x;
143     x = *(unsigned long *)ptr;
144     *(unsigned long *)ptr = temp;
145     break;
146   }
147   restore_flags(flags); /* restore irq enable bit */
148   return x;
149 #endif
150 }
151
152 #define mb() __asm__ __volatile__ ("" : : : "memory")
153 #define rmb() mb()
154 #define wmb() mb()
155
156 #ifdef CONFIG_SMP
157 #define smp_mb()        mb()
158 #define smp_rmb()       rmb()
159 #define smp_wmb()       wmb()
160 #else
161 #define smp_mb()        barrier()
162 #define smp_rmb()       barrier()
163 #define smp_wmb()       barrier()
164 #endif
165
166 #define iret()
167
168 /*
169  * disable hlt during certain critical i/o operations
170  */
171 #define HAVE_DISABLE_HLT
172 void disable_hlt(void);
173 void enable_hlt(void);
174
175 #endif