1 #ifndef UAE_MMU_COMMON_H
2 #define UAE_MMU_COMMON_H
3
4 #include "uae/types.h"
5 #include "uae/likely.h"
6
7 #define MMUDEBUG 0
8 #define MMUINSDEBUG 0
9 #define MMUDEBUGMISC 0
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 #define STOPTRY
25 #else
26 /* we are in plain C, just use a stack of long jumps */
27 #include <setjmp.h>
28 extern jmp_buf __exbuf;
29 extern int __exvalue;
30 #define TRY(DUMMY) __exvalue=setjmp(__exbuf); \
31 if (__exvalue==0) { __pushtry(&__exbuf);
32 #define CATCH(x) __poptry(); } else {m68k_exception x=__exvalue; x=x;
33 #define ENDTRY __poptry();}
34 #define STOPTRY __poptry()
35 #define THROW(x) if (__is_catched()) {longjmp(__exbuf,x);}
36 #define THROW_AGAIN(var) if (__is_catched()) longjmp(*__poptry(),__exvalue)
37 #define SAVE_EXCEPTION
38 #define RESTORE_EXCEPTION
39 jmp_buf* __poptry(void);
40 void __pushtry(jmp_buf *j);
41 int __is_catched(void);
42
43 typedef int m68k_exception;
44
45 #endif
46
47 /* special status word (access error stack frame) */
48 /* 68060 */
49 #define MMU_FSLW_MA 0x08000000
50 #define MMU_FSLW_LK 0x02000000
51 #define MMU_FSLW_R 0x01000000
52 #define MMU_FSLW_W 0x00800000
53 #define MMU_FSLW_SIZE_L 0x00000000 /* Note: wrong in mc68060 manual! */
54 #define MMU_FSLW_SIZE_B 0x00200000
55 #define MMU_FSLW_SIZE_W 0x00400000
56 #define MMU_FSLW_SIZE_D 0x00600000
57 #define MMU_FSLW_TT 0x00180000
58 #define MMU_FSLW_TT_N 0x00000000 /* Normal access */
59 #define MMU_FSLW_TT_16 0x00080000 /* MOVE16 */
60 #define MMU_FSLW_TM 0x00070000 /* = function code */
61 #define MMU_FSLW_IO 0x00008000
62 #define MMU_FSLW_PBE 0x00004000
63 #define MMU_FSLW_SBE 0x00002000
64 #define MMU_FSLW_PTA 0x00001000
65 #define MMU_FSLW_PTB 0x00000800
66 #define MMU_FSLW_IL 0x00000400
67 #define MMU_FSLW_PF 0x00000200
68 #define MMU_FSLW_SP 0x00000100
69 #define MMU_FSLW_WP 0x00000080
70 #define MMU_FSLW_TWE 0x00000040
71 #define MMU_FSLW_RE 0x00000020
72 #define MMU_FSLW_WE 0x00000010
73 #define MMU_FSLW_TTR 0x00000008
74 #define MMU_FSLW_BPE 0x00000004
75 #define MMU_FSLW_SEE 0x00000001
76 /* 68040 */
77 #define MMU_SSW_TM 0x0007
78 #define MMU_SSW_TT 0x0018
79 #define MMU_SSW_TT1 0x0010
80 #define MMU_SSW_TT0 0x0008
81 #define MMU_SSW_SIZE 0x0060
82 #define MMU_SSW_SIZE_B 0x0020
83 #define MMU_SSW_SIZE_W 0x0040
84 #define MMU_SSW_SIZE_L 0x0000
85 #define MMU_SSW_SIZE_CL 0x0060
86 #define MMU_SSW_RW 0x0100
87 #define MMU_SSW_LK 0x0200
88 #define MMU_SSW_ATC 0x0400
89 #define MMU_SSW_MA 0x0800
90 #define MMU_SSW_CM 0x1000
91 #define MMU_SSW_CT 0x2000
92 #define MMU_SSW_CU 0x4000
93 #define MMU_SSW_CP 0x8000
94 /* 68030 */
95 #define MMU030_SSW_FC 0x8000
96 #define MMU030_SSW_FB 0x4000
97 #define MMU030_SSW_RC 0x2000
98 #define MMU030_SSW_RB 0x1000
99 #define MMU030_SSW_DF 0x0100
100 #define MMU030_SSW_RM 0x0080
101 #define MMU030_SSW_RW 0x0040
102 #define MMU030_SSW_SIZE_MASK 0x0030
103 #define MMU030_SSW_SIZE_B 0x0010
104 #define MMU030_SSW_SIZE_W 0x0020
105 #define MMU030_SSW_SIZE_L 0x0000
106 #define MMU030_SSW_FC_MASK 0x0007
107
108
109 #define ALWAYS_INLINE __inline
110
111 // take care of 2 kinds of alignment, bus size and page
is_unaligned_page(uaecptr addr,int size)112 static ALWAYS_INLINE bool is_unaligned_page(uaecptr addr, int size)
113 {
114 return unlikely((addr & (size - 1)) && (addr ^ (addr + size - 1)) & regs.mmu_page_size);
115 }
is_unaligned_bus(uaecptr addr,int size)116 static ALWAYS_INLINE bool is_unaligned_bus(uaecptr addr, int size)
117 {
118 return (addr & (size - 1));
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 extern uae_u32(*x_phys_get_iword)(uaecptr);
147 extern uae_u32(*x_phys_get_ilong)(uaecptr);
148 extern uae_u32(*x_phys_get_byte)(uaecptr);
149 extern uae_u32(*x_phys_get_word)(uaecptr);
150 extern uae_u32(*x_phys_get_long)(uaecptr);
151 extern void(*x_phys_put_byte)(uaecptr, uae_u32);
152 extern void(*x_phys_put_word)(uaecptr, uae_u32);
153 extern void(*x_phys_put_long)(uaecptr, uae_u32);
154
155 #endif /* UAE_MMU_COMMON_H */
156