2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // EAGEN0.C - Effective Address Code Generation
4 // Generated Code for eaN (Included twice by "eagen.c")
5 // Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends
6 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
7 // Source utilised with the kind permission of Landon Dyer
12 uint32_t vbd, v = (uint32_t)aNexval;
13 WORD wbd, w = (WORD)(aNexattr & DEFINED);
14 WORD tdbbd, tdb = (WORD)(aNexattr & TDB);
15 vbd = (uint32_t)aNbdexval;
16 wbd = (WORD)(aNbdexattr & DEFINED);
17 tdbbd = (WORD)(aNbdexattr & TDB);
21 // "Do nothing" - they're in the opword
31 // This is a performance hit, though
39 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
41 if ((v == 0) && CHECK_OPTS(OPT_INDIRECT_DISP) && !movep)
43 // If expr is 0, size optimise the opcode. Generally the lower
44 // 6 bits of the opcode for expr(ax) are 101rrr where rrr=the
45 // number of the register, then followed by a word containing
46 // 'expr'. We need to change that to 010rrr.
47 if ((siz & 0x8000) == 0)
49 chptr_opcode[0] &= ((0xFFC7 >> 8) & 255); // mask off bits
50 chptr_opcode[1] &= 0xFFC7 & 255; // mask off bits
51 chptr_opcode[0] |= ((0x0010 >> 8) & 255); // slap in 010 bits
52 chptr_opcode[1] |= 0x0010 & 255; // slap in 010 bits
56 // Special case for move ea,ea: there are two ea fields
57 // there and we get a signal if it's the second ea field
58 // from m_ea - siz's 16th bit is set
59 chptr_opcode[0] &= ((0xFE3F >> 8) & 255); // mask off bits
60 chptr_opcode[1] &= 0xFE3F & 255; // mask off bits
61 chptr_opcode[0] |= ((0x0080 >> 8) & 255); // slap in 010 bits
62 chptr_opcode[1] |= 0x0080 & 255; // slap in 010 bits
66 warn("0(An) converted to (An)");
71 if ((v + 0x8000) >= 0x18000)
72 return error(range_error);
78 // Arrange for fixup later on
79 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
88 if ((aNexattr & TDB) == cursect)
90 else if ((aNexattr & TDB) != ABS)
93 if (v + 0x8000 >= 0x10000)
94 return error(range_error);
100 // Arrange for fixup later on
101 AddFixup(FU_WORD | FU_SEXT | FU_PCREL, sloc, aNexpr);
107 // Compute ixreg and size+scale
108 w = (WORD)((aNixreg << 12) | aNixsiz);
110 if (aNexattr & DEFINED)
115 return error(abs_error);
117 if (v + 0x80 >= 0x180)
118 return error(range_error);
125 // Fixup the byte later
126 AddFixup(FU_BYTE | FU_SEXT, sloc + 1, aNexpr);
132 // Compute ixreg and size+scale
133 w = (WORD)((aNixreg << 12) | aNixsiz);
135 if (aNexattr & DEFINED)
138 if ((aNexattr & TDB) == cursect)
140 else if ((aNexattr & TDB) != ABS)
143 if (v + 0x80 >= 0x100)
144 return error(range_error);
151 // Fixup the byte later
152 AddFixup(FU_WBYTE | FU_SEXT | FU_PCREL, sloc, aNexpr);
164 return error("illegal byte-sized relative reference");
166 if (v + 0x100 >= 0x200)
167 return error(range_error);
173 AddFixup(FU_BYTE | FU_SEXT, sloc + 1, aNexpr);
182 if (v + 0x10000 >= 0x20000)
183 return error(range_error);
186 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
192 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
201 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
207 AddFixup(FU_LONG, sloc, aNexpr);
213 // 68881/68882/68040 only
218 MarkRelocatable(cursect, sloc, tdb, MSINGLE, NULL);
227 AddFixup(FU_FLOATSING, sloc, aNexpr);
234 // 68881/68882/68040 only
238 unsigned long long vvv;
240 MarkRelocatable(cursect, sloc, tdb, MDOUBLE, NULL);
242 // We want to store the IEE754 float into ram from a generic
243 // 32-bit int. First, convert it to double float, then cast
244 // that to 64-bit, then convert to big endian (if needed)
245 // and then store it (phew!)
246 vv = *(float *)&aNexval;
247 vvv = BYTESWAP64(*(unsigned long long *)&vv);
253 unsigned long long vvv = 0;
254 AddFixup(FU_FLOATDOUB, sloc, aNexpr);
261 // 68881/68882/68040 only
266 MarkRelocatable(cursect, sloc, tdb, MEXTEND, NULL);
268 // We want to store the IEE754 float into ram from a generic
269 // 32-bit int. First, convert it to double float, then cast
270 // that to 96-bit, then convert to big endian (if needed)
271 // and then store it (phew!)
272 vv = (double)aNexval;
274 //*chptr++ = (char)((*(unsigned long long *)&vv) >> 32) | 0x80 /* assume that the number is normalised */;
280 AddFixup(FU_FLOATDOUB, sloc, aNexpr);
287 // IMMED size problem
293 // 68881/68882/68040 only
294 return error("Sorry, .p constant format is not implemented yet!");
300 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
302 if (v + 0x8000 >= 0x10000)
303 return error(range_error);
309 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
318 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
324 AddFixup(FU_LONG, sloc, aNexpr);
330 D_word((0x190 | (aNixreg << 12)));
333 D_word((0x990 | (aNixreg << 12)));
342 // Deposit bd (if not suppressed)
343 if ((aNexten & 0x0030) == EXT_BDSIZE0)
345 // Don't deposit anything (suppressed)
347 else if ((aNexten & 0x0030) == EXT_BDSIZEW)
354 MarkRelocatable(cursect, sloc, tdbbd, MWORD, NULL);
356 if (vbd + 0x8000 >= 0x10000)
357 return error(range_error);
363 // Arrange for fixup later on
364 AddFixup(FU_WORD|FU_SEXT, sloc, aNbexpr);
375 MarkRelocatable(cursect, sloc, tdbbd, MLONG, NULL);
381 // Arrange for fixup later on
382 AddFixup(FU_LONG, sloc, aNbexpr);
386 // Deposit od (if not suppressed)
387 if ((aNexten&7)==EXT_IISPRE0 || (aNexten&7)==EXT_IISPREN
388 || (aNexten&7)==EXT_IISNOIN || (aNexten&7)==EXT_IISPOSN)
390 // Don't deposit anything (suppressed)
392 else if ((aNexten&7)==EXT_IISPREW
393 || (aNexten&7)==EXT_IISPOSW || (aNexten&7)==EXT_IISNOIW)
400 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
402 if (v + 0x8000 >= 0x10000)
403 return error(range_error);
409 // Arrange for fixup later on
410 AddFixup(FU_WORD|FU_SEXT, sloc, aNexpr);
421 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
427 // Arrange for fixup later on
428 AddFixup(FU_LONG|FU_SEXT, sloc, aNexpr);
434 //return error("unsupported 68020 addressing mode");
436 // Bad addressing mode in ea gen
443 // Undefine dirty macros