1 
2 #ifndef MMU_COMMON_H
3 #define MMU_COMMON_H
4 
5 #if 0
6 struct m68k_exception {
7 	int prb;
8 	m68k_exception (int exc) : prb (exc) {}
9 	operator int() { return prb; }
10 };
11 #define SAVE_EXCEPTION
12 #define RESTORE_EXCEPTION
13 #define TRY(var) try
14 #define CATCH(var) catch(m68k_exception var)
15 #define THROW(n) throw m68k_exception(n)
16 #define THROW_AGAIN(var) throw
17 
18 #else
19 /* we are in plain C, just use a stack of long jumps */
20 #include <setjmp.h>
21 extern jmp_buf __exbuf;
22 extern int     __exvalue;
23 #define TRY(DUMMY)       __exvalue=setjmp(__exbuf);       \
24                   if (__exvalue==0) { __pushtry(&__exbuf);
25 #define CATCH(x)  __poptry(); } else { /*fprintf(stderr,"CATCHed! %d %s in %d\n",__exvalue,__FILE__,__LINE__);*/
26 #define ENDTRY    __poptry();}
27 #define THROW(x) if (__is_catched()) {/*fprintf(stderr,"THROWing %s in %d\n",__FILE__,__LINE__);*/longjmp(__exbuf,x);}
28 #define THROW_AGAIN(var) if (__is_catched()) longjmp(*__poptry(),__exvalue)
29 #define SAVE_EXCEPTION
30 #define RESTORE_EXCEPTION
31 jmp_buf* __poptry(void);
32 void __pushtry(jmp_buf *j);
33 int __is_catched(void);
34 
35 typedef  int m68k_exception;
36 
37 #endif
38 
39 /* special status word (access error stack frame) */
40 #define MMU_SSW_TM		0x0007
41 #define MMU_SSW_TT		0x0018
42 #define MMU_SSW_SIZE	0x0060
43 #define MMU_SSW_SIZE_B	0x0020
44 #define MMU_SSW_SIZE_W	0x0040
45 #define MMU_SSW_SIZE_L	0x0000
46 #define MMU_SSW_RW		0x0100
47 #define MMU_SSW_LK		0x0200
48 #define MMU_SSW_ATC		0x0400
49 #define MMU_SSW_MA		0x0800
50 #define MMU_SSW_CM	0x1000
51 #define MMU_SSW_CT	0x2000
52 #define MMU_SSW_CU	0x4000
53 #define MMU_SSW_CP	0x8000
54 
55 
56 #define ALWAYS_INLINE __inline
57 
is_unaligned(uaecptr addr,int size)58 static inline bool is_unaligned(uaecptr addr, int size)
59 {
60     return unlikely((addr & (size - 1)) && (addr ^ (addr + size - 1)) & 0x1000);
61 }
62 
phys_put_long(uaecptr addr,uae_u32 l)63 static ALWAYS_INLINE void phys_put_long(uaecptr addr, uae_u32 l)
64 {
65     longput(addr, l);
66 }
phys_put_word(uaecptr addr,uae_u32 w)67 static ALWAYS_INLINE void phys_put_word(uaecptr addr, uae_u32 w)
68 {
69     wordput(addr, w);
70 }
phys_put_byte(uaecptr addr,uae_u32 b)71 static ALWAYS_INLINE void phys_put_byte(uaecptr addr, uae_u32 b)
72 {
73     byteput(addr, b);
74 }
phys_get_long(uaecptr addr)75 static ALWAYS_INLINE uae_u32 phys_get_long(uaecptr addr)
76 {
77     return longget (addr);
78 }
phys_get_word(uaecptr addr)79 static ALWAYS_INLINE uae_u32 phys_get_word(uaecptr addr)
80 {
81     return wordget (addr);
82 }
phys_get_byte(uaecptr addr)83 static ALWAYS_INLINE uae_u32 phys_get_byte(uaecptr addr)
84 {
85     return byteget (addr);
86 }
87 
88 #endif
89