2020#include <stddef.h>
2121#include <stdarg.h>
2222#include <sifdma.h>
23+ #include <mipscopaccess.h>
2324
2425#define DI DIntr
2526#define EI EIntr
2627
2728// Workaround for EE kernel bug: call this immediately before returning from any interrupt handler.
28- #define ExitHandler () asm volatile ("sync\nei\n")
29+ #define ExitHandler () __asm__ __volatile__ ("sync\nei\n")
2930
3031// note: 'sync' is the same as 'sync.l'
31- #define EE_SYNC () __asm__ volatile ("sync")
32- #define EE_SYNCL () __asm__ volatile ("sync.l")
33- #define EE_SYNCP () __asm__ volatile ("sync.p")
32+ #define EE_SYNC () __asm__ __volatile__ ("sync")
33+ #define EE_SYNCL () __asm__ __volatile__ ("sync.l")
34+ #define EE_SYNCP () __asm__ __volatile__ ("sync.p")
3435
3536#define UNCACHED_SEG (x ) \
3637 ((void *)(((u32)(x)) | 0x20000000))
@@ -143,58 +144,37 @@ static inline void nopdelay(void)
143144 int i = 0xfffff ;
144145
145146 do {
146- __asm__("nop\nnop\nnop\nnop\nnop\n" );
147+ __asm__ __volatile__ ("nop\nnop\nnop\nnop\nnop\n" );
147148 } while (i -- != -1 );
148149}
149150
150151static inline int ee_get_opmode (void )
151152{
152153 u32 status ;
153154
154- __asm__ volatile (
155- ".set\tpush\n\t"
156- ".set\tnoreorder\n\t"
157- "mfc0\t%0, $12\n\t"
158- ".set\tpop\n\t"
159- : "=r" (status ));
155+ status = get_mips_cop_reg (0 , COP0_REG_Status );
160156
161157 return ((status >> 3 ) & 3 );
162158}
163159
164160static inline int ee_set_opmode (u32 opmode )
165161{
166- u32 status , mask ;
167-
168- __asm__ volatile (
169- ".set\tpush\n\t"
170- ".set\tnoreorder\n\t"
171- "mfc0\t%0, $12\n\t"
172- "li\t%1, 0xffffffe7\n\t"
173- "and\t%0, %1\n\t"
174- "or\t%0, %2\n\t"
175- "mtc0\t%0, $12\n\t"
176- "sync.p\n\t"
177- ".set\tpop\n\t"
178- : "=r" (status ), "=r" (mask )
179- : "r" (opmode ));
162+ u32 status ;
163+
164+ status = (get_mips_cop_reg (0 , COP0_REG_Status ) & ~0x18 ) | opmode ;
165+ set_mips_cop_reg (0 , COP0_REG_Status , status );
166+ EE_SYNCP ();
180167
181168 return ((status >> 3 ) & 3 );
182169}
183170
184171static inline int ee_kmode_enter ()
185172{
186- u32 status , mask ;
187-
188- __asm__ volatile (
189- ".set\tpush\n\t"
190- ".set\tnoreorder\n\t"
191- "mfc0\t%0, $12\n\t"
192- "li\t%1, 0xffffffe7\n\t"
193- "and\t%0, %1\n\t"
194- "mtc0\t%0, $12\n\t"
195- "sync.p\n\t"
196- ".set\tpop\n\t"
197- : "=r" (status ), "=r" (mask ));
173+ u32 status ;
174+
175+ status = (get_mips_cop_reg (0 , COP0_REG_Status ) & ~0x18 );
176+ set_mips_cop_reg (0 , COP0_REG_Status , status );
177+ EE_SYNCP ();
198178
199179 return status ;
200180}
@@ -203,15 +183,9 @@ static inline int ee_kmode_exit()
203183{
204184 int status ;
205185
206- __asm__ volatile (
207- ".set\tpush\n\t"
208- ".set\tnoreorder\n\t"
209- "mfc0\t%0, $12\n\t"
210- "ori\t%0, 0x10\n\t"
211- "mtc0\t%0, $12\n\t"
212- "sync.p\n\t"
213- ".set\tpop\n\t"
214- : "=r" (status ));
186+ status = get_mips_cop_reg (0 , COP0_REG_Status ) | 0x10 ;
187+ set_mips_cop_reg (0 , COP0_REG_Status , status );
188+ EE_SYNCP ();
215189
216190 return status ;
217191}
0 commit comments