|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * MC68000 emulation - machine dependent bits
5: *
6: * Copyright 1996 Bernd Schmidt
7: */
8:
1.1.1.3 ! root 9: #if 0
1.1 root 10: struct flag_struct {
11: unsigned int c:1; /* first byte */
12: int :5;
13: unsigned int z:1;
14: unsigned int n:1;
15: int :3; /* second, third & fourth byte */
16: unsigned int v:1;
17: int :20;
18: unsigned int x:1; /* fifth */
19: int :31;
20: };
21:
22: #define ZFLG (regflags.z)
23: #define NFLG (regflags.n)
24: #define CFLG (regflags.c)
25: #define VFLG (regflags.v)
26: #define XFLG (regflags.x)
27:
1.1.1.3 ! root 28: #else
! 29:
! 30: struct flag_struct {
! 31: unsigned int cznv;
! 32: unsigned int x;
! 33: };
! 34:
! 35: #define SET_ZFLG(y) (regflags.cznv = (regflags.cznv & ~0x40) | (((y) & 1) << 6))
! 36: #define SET_CFLG(y) (regflags.cznv = (regflags.cznv & ~1) | ((y) & 1))
! 37: #define SET_VFLG(y) (regflags.cznv = (regflags.cznv & ~0x800) | (((y) & 1) << 11))
! 38: #define SET_NFLG(y) (regflags.cznv = (regflags.cznv & ~0x80) | (((y) & 1) << 7))
! 39: #define SET_XFLG(y) (regflags.x = (y))
! 40:
! 41: #define GET_ZFLG ((regflags.cznv >> 6) & 1)
! 42: #define GET_CFLG (regflags.cznv & 1)
! 43: #define GET_VFLG ((regflags.cznv >> 11) & 1)
! 44: #define GET_NFLG ((regflags.cznv >> 7) & 1)
! 45: #define GET_XFLG (regflags.x & 1)
! 46:
! 47: #define CLEAR_CZNV (regflags.cznv = 0)
! 48: #define COPY_CARRY (regflags.x = regflags.cznv)
! 49:
! 50: #endif
! 51:
! 52: extern struct flag_struct regflags __asm__ ("regflags");
! 53:
! 54: static __inline__ int cctrue(int cc)
1.1 root 55: {
1.1.1.3 ! root 56: uae_u32 cznv = regflags.cznv;
1.1 root 57: switch(cc){
58: case 0: return 1; /* T */
59: case 1: return 0; /* F */
1.1.1.3 ! root 60: case 2: return (cznv & 0x41) == 0; /* !GET_CFLG && !GET_ZFLG; HI */
! 61: case 3: return (cznv & 0x41) != 0; /* GET_CFLG || GET_ZFLG; LS */
! 62: case 4: return (cznv & 1) == 0; /* !GET_CFLG; CC */
! 63: case 5: return (cznv & 1) != 0; /* GET_CFLG; CS */
! 64: case 6: return (cznv & 0x40) == 0; /* !GET_ZFLG; NE */
! 65: case 7: return (cznv & 0x40) != 0; /* GET_ZFLG; EQ */
! 66: case 8: return (cznv & 0x800) == 0;/* !GET_VFLG; VC */
! 67: case 9: return (cznv & 0x800) != 0;/* GET_VFLG; VS */
! 68: case 10:return (cznv & 0x80) == 0; /* !GET_NFLG; PL */
! 69: case 11:return (cznv & 0x80) != 0; /* GET_NFLG; MI */
! 70: case 12:return (((cznv << 4) ^ cznv) & 0x800) == 0; /* GET_NFLG == GET_VFLG; GE */
! 71: case 13:return (((cznv << 4) ^ cznv) & 0x800) != 0;/* GET_NFLG != GET_VFLG; LT */
! 72: case 14:
! 73: cznv &= 0x8c0;
! 74: return (((cznv << 4) ^ cznv) & 0x840) == 0; /* !GET_ZFLG && (GET_NFLG == GET_VFLG); GT */
! 75: case 15:
! 76: cznv &= 0x8c0;
! 77: return (((cznv << 4) ^ cznv) & 0x840) != 0; /* GET_ZFLG || (GET_NFLG != GET_VFLG); LE */
1.1 root 78: }
79: abort();
80: return 0;
81: }
82:
1.1.1.2 root 83: #define x86_flag_testl(v) \
84: __asm__ __volatile__ ("testl %1,%1\n\t" \
85: "pushfl\n\t" \
86: "popl %0\n\t" \
1.1.1.3 ! root 87: : "=r" (regflags.cznv) : "r" (v) : "cc")
1.1.1.2 root 88:
89: #define x86_flag_testw(v) \
90: __asm__ __volatile__ ("testw %w1,%w1\n\t" \
91: "pushfl\n\t" \
92: "popl %0\n\t" \
1.1.1.3 ! root 93: : "=r" (regflags.cznv) : "r" (v) : "cc")
1.1.1.2 root 94:
95: #define x86_flag_testb(v) \
96: __asm__ __volatile__ ("testb %b1,%b1\n\t" \
97: "pushfl\n\t" \
98: "popl %0\n\t" \
1.1.1.3 ! root 99: : "=r" (regflags.cznv) : "q" (v) : "cc")
1.1.1.2 root 100:
1.1.1.3 ! root 101: #define x86_flag_addl(v, s, d) do { \
1.1.1.2 root 102: __asm__ __volatile__ ("addl %k2,%k1\n\t" \
103: "pushfl\n\t" \
104: "popl %0\n\t" \
1.1.1.3 ! root 105: : "=r" (regflags.cznv), "=r" (v) : "rmi" (s), "1" (d) : "cc"); \
! 106: COPY_CARRY; \
! 107: } while (0)
! 108: #define x86_flag_addw(v, s, d) do { \
1.1.1.2 root 109: __asm__ __volatile__ ("addw %w2,%w1\n\t" \
110: "pushfl\n\t" \
111: "popl %0\n\t" \
1.1.1.3 ! root 112: : "=r" (regflags.cznv), "=r" (v) : "rmi" (s), "1" (d) : "cc"); \
! 113: COPY_CARRY; \
! 114: } while (0)
1.1.1.2 root 115:
1.1.1.3 ! root 116: #define x86_flag_addb(v, s, d) do { \
1.1.1.2 root 117: __asm__ __volatile__ ("addb %b2,%b1\n\t" \
118: "pushfl\n\t" \
119: "popl %0\n\t" \
1.1.1.3 ! root 120: : "=r" (regflags.cznv), "=q" (v) : "qmi" (s), "1" (d) : "cc"); \
! 121: COPY_CARRY; \
! 122: } while (0)
1.1.1.2 root 123:
1.1.1.3 ! root 124: #define x86_flag_subl(v, s, d) do { \
1.1.1.2 root 125: __asm__ __volatile__ ("subl %k2,%k1\n\t" \
126: "pushfl\n\t" \
127: "popl %0\n\t" \
1.1.1.3 ! root 128: : "=r" (regflags.cznv), "=r" (v) : "rmi" (s), "1" (d) : "cc"); \
! 129: COPY_CARRY; \
! 130: } while (0)
1.1.1.2 root 131:
1.1.1.3 ! root 132: #define x86_flag_subw(v, s, d) do { \
1.1.1.2 root 133: __asm__ __volatile__ ("subw %w2,%w1\n\t" \
134: "pushfl\n\t" \
135: "popl %0\n\t" \
1.1.1.3 ! root 136: : "=r" (regflags.cznv), "=r" (v) : "rmi" (s), "1" (d) : "cc"); \
! 137: COPY_CARRY; \
! 138: } while (0)
1.1.1.2 root 139:
1.1.1.3 ! root 140: #define x86_flag_subb(v, s, d) do { \
1.1.1.2 root 141: __asm__ __volatile__ ("subb %b2,%b1\n\t" \
142: "pushfl\n\t" \
143: "popl %0\n\t" \
1.1.1.3 ! root 144: : "=r" (regflags.cznv), "=q" (v) : "qmi" (s), "1" (d) : "cc"); \
! 145: COPY_CARRY; \
! 146: } while (0)
1.1.1.2 root 147:
148: #define x86_flag_cmpl(s, d) \
149: __asm__ __volatile__ ("cmpl %k1,%k2\n\t" \
150: "pushfl\n\t" \
151: "popl %0\n\t" \
1.1.1.3 ! root 152: : "=r" (regflags.cznv) : "rmi" (s), "r" (d) : "cc")
1.1.1.2 root 153:
154: #define x86_flag_cmpw(s, d) \
155: __asm__ __volatile__ ("cmpw %w1,%w2\n\t" \
156: "pushfl\n\t" \
157: "popl %0\n\t" \
1.1.1.3 ! root 158: : "=r" (regflags.cznv) : "rmi" (s), "r" (d) : "cc")
1.1.1.2 root 159:
160: #define x86_flag_cmpb(s, d) \
161: __asm__ __volatile__ ("cmpb %b1,%b2\n\t" \
162: "pushfl\n\t" \
163: "popl %0\n\t" \
1.1.1.3 ! root 164: : "=r" (regflags.cznv) : "qmi" (s), "q" (d) : "cc")
1.1.1.2 root 165:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.