2 // RMAC - Renamed 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-2021 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 v = (uint32_t)aNexval;
13 WORD w = (WORD)(aNexattr & DEFINED);
14 WORD tdb = (WORD)(aNexattr & TDB);
15 uint32_t vbd = (uint32_t)aNbdexval;
16 WORD wbd = (WORD)(aNbdexattr & DEFINED);
17 WORD tdbbd = (WORD)(aNbdexattr & TDB);
22 // "Do nothing" - they're in the opword
32 // This is a performance hit, though
41 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
43 if ((v == 0) && CHECK_OPTS(OPT_OUTER_DISP) && !movep)
45 // If expr is 0, size optimise the opcode. Generally the lower
46 // 6 bits of the opcode for expr(ax) are 101rrr where rrr=the
47 // number of the register, then followed by a word containing
48 // 'expr'. We need to change that to 010rrr.
49 if ((siz & 0x8000) == 0)
51 chptr_opcode[0] &= ((0xFFC7 >> 8) & 255); // mask off bits
52 chptr_opcode[1] &= 0xFFC7 & 255; // mask off bits
53 chptr_opcode[0] |= ((0x0010 >> 8) & 255); // slap in 010 bits
54 chptr_opcode[1] |= 0x0010 & 255; // slap in 010 bits
58 // Special case for move ea,ea: there are two ea fields
59 // there and we get a signal if it's the second ea field
60 // from m_ea - siz's 16th bit is set
61 chptr_opcode[0] &= ((0xFE3F >> 8) & 255); // mask off bits
62 chptr_opcode[1] &= 0xFE3F & 255; // mask off bits
63 chptr_opcode[0] |= ((0x0080 >> 8) & 255); // slap in 010 bits
64 chptr_opcode[1] |= 0x0080 & 255; // slap in 010 bits
68 warn("0(An) converted to (An)");
73 if ((v + 0x8000) >= 0x18000)
74 return error(range_error);
80 // Arrange for fixup later on
81 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
91 if ((aNexattr & TDB) == cursect)
93 else if ((aNexattr & TDB) != ABS)
96 if (v + 0x8000 >= 0x10000)
97 return error(range_error);
103 // Arrange for fixup later on
104 AddFixup(FU_WORD | FU_SEXT | FU_PCREL, sloc, aNexpr);
111 // Compute ixreg and size+scale
112 w = (WORD)((aNixreg << 12) | aNixsiz);
114 if (aNexattr & DEFINED)
119 return error(abs_error);
121 if (v + 0x80 >= 0x180)
122 return error(range_error);
129 // Fixup the byte later
130 AddFixup(FU_BYTE | FU_SEXT, sloc + 1, aNexpr);
137 // Compute ixreg and size+scale
138 w = (WORD)((aNixreg << 12) | aNixsiz);
140 if (aNexattr & DEFINED)
143 if ((aNexattr & TDB) == cursect)
145 else if ((aNexattr & TDB) != ABS)
148 if (v + 0x80 >= 0x100)
149 return error(range_error);
156 // Fixup the byte later
157 AddFixup(FU_WBYTE | FU_SEXT | FU_PCREL, sloc, aNexpr);
170 return error("illegal byte-sized relative reference");
172 if (v + 0x100 >= 0x200)
173 return error(range_error);
179 AddFixup(FU_BYTE | FU_SEXT, sloc + 1, aNexpr);
189 if (v + 0x10000 >= 0x20000)
190 return error(range_error);
193 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
199 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
209 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
215 AddFixup(FU_LONG, sloc, aNexpr);
222 // 68881/68882/68040 only
225 //Would a floating point value *ever* need to be fixed up as if it were an address? :-P
227 // MarkRelocatable(cursect, sloc, tdb, MSINGLE, NULL);
229 // The value passed back from expr() is an internal C double;
230 // so we have to access it as such then convert it to an
231 // IEEE-754 float so we can store it as such in the instruction
235 float f = (float)*p.dp;
236 uint32_t ieee754 = FloatToIEEE754(f);
241 AddFixup(FU_FLOATSING, sloc, aNexpr);
242 D_long(0); // IEEE-754 zero is all zeroes
248 // 68881/68882/68040 only
251 //Would a floating point value *ever* need to be fixed up as if it were an address? :-P
253 // MarkRelocatable(cursect, sloc, tdb, MDOUBLE, NULL);
258 uint64_t ieee754 = DoubleToIEEE754(d);
263 AddFixup(FU_FLOATDOUB, sloc, aNexpr);
264 D_quad(0LL); // IEEE-754 zero is all zeroes
270 // 68881/68882/68040 only
273 //Would a floating point value *ever* need to be fixed up as if it were an address? :-P
275 // MarkRelocatable(cursect, sloc, tdb, MEXTEND, NULL);
279 DoubleToExtended(*p.dp, extDbl);
284 // Why would this be anything other than a floating point
285 // expression??? Even if there were an undefined symbol in
286 // the expression, how would that be relevant? I can't see
287 // any use case where this would make sense.
288 AddFixup(FU_FLOATDOUB, sloc, aNexpr);
289 memset(extDbl, 0, 12);
296 // IMMED size problem
303 // 68881/68882/68040 only
304 return error("Sorry, .p constant format is not implemented yet!");
311 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
313 if (v + 0x8000 >= 0x10000)
314 return error(range_error);
320 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
329 if (CHECK_OPTS(OPT_PC_RELATIVE))
331 if ((aNexattr & (DEFINED | REFERENCED | EQUATED)) == (DEFINED | REFERENCED))
332 return error("relocation not allowed when o10 is enabled");
336 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
342 AddFixup(FU_LONG, sloc, aNexpr);
349 D_word((0x190 | (aNixreg << 12)));
353 D_word((0x990 | (aNixreg << 12)));
364 // Deposit bd (if not suppressed)
365 if ((aNexten & 0x0030) == EXT_BDSIZE0)
367 // Don't deposit anything (suppressed)
369 else if ((aNexten & 0x0030) == EXT_BDSIZEW)
376 MarkRelocatable(cursect, sloc, tdbbd, MWORD, NULL);
378 if (vbd + 0x8000 >= 0x10000)
379 return error(range_error);
385 // Arrange for fixup later on
386 AddFixup(FU_WORD | FU_SEXT | FU_PCRELX, sloc, aNbexpr);
397 MarkRelocatable(cursect, sloc, tdbbd, MLONG, NULL);
403 // Arrange for fixup later on
404 AddFixup(FU_LONG, sloc, aNbexpr);
409 // Deposit od (if not suppressed)
410 if ((aNexten & 7) == EXT_IISPRE0 || (aNexten & 7) == EXT_IISPREN
411 || (aNexten & 7) == EXT_IISNOIN || (aNexten & 7) == EXT_IISPOSN)
413 // Don't deposit anything (suppressed)
415 else if ((aNexten & 7) == EXT_IISPREW
416 || (aNexten & 7) == EXT_IISPOSW || (aNexten & 7) == EXT_IISNOIW)
423 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
425 if (v + 0x8000 >= 0x10000)
426 return error(range_error);
432 // Arrange for fixup later on
433 AddFixup(FU_WORD | FU_SEXT, sloc, aNexpr);
444 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
450 // Arrange for fixup later on
451 AddFixup(FU_LONG | FU_SEXT, sloc, aNexpr);
457 //return error("unsupported 68020 addressing mode");
460 // Bad addressing mode in ea gen
467 // Undefine dirty macros