1 
2 #ifndef MMU_COMMON_H
3 #define MMU_COMMON_H
4 
5 #define MMUDEBUG 0
6 #define MMUINSDEBUG 0
7 
8 #define unlikely(x) x
9 #define likely(x) x
10 
11 #ifdef __cplusplus
12 struct m68k_exception {
13 	int prb;
m68k_exceptionm68k_exception14 	m68k_exception (int exc) : prb (exc) {}
15 	operator int() { return prb; }
16 };
17 #define SAVE_EXCEPTION
18 #define RESTORE_EXCEPTION
19 #define TRY(var) try
20 #define CATCH(var) catch(m68k_exception var)
21 #define THROW(n) throw m68k_exception(n)
22 #define THROW_AGAIN(var) throw
23 #define ENDTRY
24 #else
25 /* we are in plain C, just use a stack of long jumps */
26 #include <setjmp.h>
27 extern jmp_buf __exbuf;
28 extern int     __exvalue;
29 /*
30 #define TRY(DUMMY)       __exvalue=setjmp(__exbuf);       \
31                   if (__exvalue==0) { __pushtry(&__exbuf);
32 #define CATCH(x)  __poptry(); } else { fprintf(stderr,"Gotcha! %d %s in %d\n",__exvalue,__FILE__,__LINE__);
33 #define ENDTRY    __poptry();}
34 #define THROW(x) if (__is_catched()) {fprintf(stderr,"Longjumping %s in %d\n",__FILE__,__LINE__);longjmp(__exbuf,x);}
35 #define THROW_AGAIN(var) if (__is_catched()) longjmp(*__poptry(),__exvalue)
36 */
37 #define TRY(DUMMY)
38 #define CATCH(x)
39 #define ENDTRY
40 #define THROW(x) { fprintf(stderr,"Longjumping %s in %d\n",__FILE__,__LINE__);abort(); }
41 #define THROW_AGAIN(var)
42 #define SAVE_EXCEPTION
43 #define RESTORE_EXCEPTION
44 jmp_buf* __poptry(void);
45 void __pushtry(jmp_buf *j);
46 int __is_catched(void);
47 
48 typedef  int m68k_exception;
49 
50 #endif
51 
52 /* special status word (access error stack frame) */
53 /* 68060 */
54 #define MMU_FSLW_MA		0x08000000
55 #define MMU_FSLW_LK		0x02000000
56 #define MMU_FSLW_R		0x01000000
57 #define MMU_FSLW_W		0x00800000
58 #define MMU_FSLW_SIZE_L		0x00000000 /* Note: wrong in mc68060 manual! */
59 #define MMU_FSLW_SIZE_B		0x00200000
60 #define MMU_FSLW_SIZE_W		0x00400000
61 #define MMU_FSLW_SIZE_D		0x00600000
62 #define MMU_FSLW_TT		0x00180000
63 #define MMU_FSLW_TT_N		0x00000000 /* Normal access */
64 #define MMU_FSLW_TT_16		0x00080000 /* MOVE16 */
65 #define MMU_FSLW_TM		0x00070000 /* = function code */
66 #define MMU_FSLW_IO		0x00008000
67 #define MMU_FSLW_PBE		0x00004000
68 #define MMU_FSLW_SBE		0x00002000
69 #define MMU_FSLW_PTA		0x00001000
70 #define MMU_FSLW_PTB		0x00000800
71 #define MMU_FSLW_IL		0x00000400
72 #define MMU_FSLW_PF		0x00000200
73 #define MMU_FSLW_SP		0x00000100
74 #define MMU_FSLW_WP		0x00000080
75 #define MMU_FSLW_TWE		0x00000040
76 #define MMU_FSLW_RE		0x00000020
77 #define MMU_FSLW_WE		0x00000010
78 #define MMU_FSLW_TTR		0x00000008
79 #define MMU_FSLW_BPE		0x00000004
80 #define MMU_FSLW_SEE		0x00000001
81 /* 68040 */
82 #define MMU_SSW_TM		0x0007
83 #define MMU_SSW_TT		0x0018
84 #define MMU_SSW_TT1		0x0010
85 #define MMU_SSW_TT0		0x0008
86 #define MMU_SSW_SIZE		0x0060
87 #define MMU_SSW_SIZE_B		0x0020
88 #define MMU_SSW_SIZE_W		0x0040
89 #define MMU_SSW_SIZE_L		0x0000
90 #define MMU_SSW_RW		0x0100
91 #define MMU_SSW_LK		0x0200
92 #define MMU_SSW_ATC		0x0400
93 #define MMU_SSW_MA		0x0800
94 #define MMU_SSW_CM		0x1000
95 #define MMU_SSW_CT		0x2000
96 #define MMU_SSW_CU		0x4000
97 #define MMU_SSW_CP		0x8000
98 /* 68030 */
99 #define MMU030_SSW_FC		0x8000
100 #define MMU030_SSW_FB		0x4000
101 #define MMU030_SSW_RC		0x2000
102 #define MMU030_SSW_RB		0x1000
103 #define MMU030_SSW_DF		0x0100
104 #define MMU030_SSW_RM		0x0080
105 #define MMU030_SSW_RW		0x0040
106 #define MMU030_SSW_SIZE_MASK	0x0030
107 #define MMU030_SSW_SIZE_B	0x0010
108 #define MMU030_SSW_SIZE_W	0x0020
109 #define MMU030_SSW_SIZE_L	0x0000
110 #define MMU030_SSW_FC_MASK	0x0007
111 
112 
113 #define ALWAYS_INLINE __inline
114 
115 // take care of 2 kinds of alignement, bus size and page
is_unaligned(uaecptr addr,int size)116 static inline bool is_unaligned(uaecptr addr, int size)
117 {
118     return unlikely((addr & (size - 1)) && (addr ^ (addr + size - 1)) & regs.mmu_page_size);
119 }
120 
phys_put_long(uaecptr addr,uae_u32 l)121 static ALWAYS_INLINE void phys_put_long(uaecptr addr, uae_u32 l)
122 {
123     longput(addr, l);
124 }
phys_put_word(uaecptr addr,uae_u32 w)125 static ALWAYS_INLINE void phys_put_word(uaecptr addr, uae_u32 w)
126 {
127     wordput(addr, w);
128 }
phys_put_byte(uaecptr addr,uae_u32 b)129 static ALWAYS_INLINE void phys_put_byte(uaecptr addr, uae_u32 b)
130 {
131     byteput(addr, b);
132 }
phys_get_long(uaecptr addr)133 static ALWAYS_INLINE uae_u32 phys_get_long(uaecptr addr)
134 {
135     return longget (addr);
136 }
phys_get_word(uaecptr addr)137 static ALWAYS_INLINE uae_u32 phys_get_word(uaecptr addr)
138 {
139     return wordget (addr);
140 }
phys_get_byte(uaecptr addr)141 static ALWAYS_INLINE uae_u32 phys_get_byte(uaecptr addr)
142 {
143     return byteget (addr);
144 }
145 
146 #endif
147