|
|
1.1 ! root 1: /* ! 2: ! 3: * translation routines; sometimes we pass data on ! 4: ! 5: * through directly (asm syntax->asm syntax, with ! 6: ! 7: * some macro expansion), and other times we also ! 8: ! 9: * do asm syntax->gas syntax translation ! 10: ! 11: */ ! 12: ! 13: ! 14: ! 15: #include "asmtrans.h" ! 16: ! 17: ! 18: ! 19: int syntax = GAS; ! 20: ! 21: ! 22: ! 23: char * ! 24: ! 25: immediate(op) ! 26: ! 27: char *op; ! 28: ! 29: { ! 30: ! 31: return concat("#", op); ! 32: ! 33: } ! 34: ! 35: ! 36: ! 37: char * ! 38: ! 39: indirect(op) ! 40: ! 41: char *op; ! 42: ! 43: { ! 44: ! 45: if (syntax == GAS) { ! 46: ! 47: return concat(op, "@"); ! 48: ! 49: } else { ! 50: ! 51: return concat3("(", op, ")"); ! 52: ! 53: } ! 54: ! 55: } ! 56: ! 57: ! 58: ! 59: char * ! 60: ! 61: postinc(op) ! 62: ! 63: char *op; ! 64: ! 65: { ! 66: ! 67: if (syntax == GAS) { ! 68: ! 69: return concat(op, "@+"); ! 70: ! 71: } else { ! 72: ! 73: return concat3("(", op, ")+"); ! 74: ! 75: } ! 76: ! 77: } ! 78: ! 79: ! 80: ! 81: char * ! 82: ! 83: predec(op) ! 84: ! 85: char *op; ! 86: ! 87: { ! 88: ! 89: if (syntax == GAS) { ! 90: ! 91: return concat(op, "@-"); ! 92: ! 93: } else { ! 94: ! 95: return concat3("-(", op, ")"); ! 96: ! 97: } ! 98: ! 99: } ! 100: ! 101: ! 102: ! 103: char * ! 104: ! 105: indexed(op1, op2) ! 106: ! 107: char *op1, *op2; ! 108: ! 109: { ! 110: ! 111: if (syntax == GAS) { ! 112: ! 113: return concat4(op2, "@(", op1, ")"); ! 114: ! 115: } else { ! 116: ! 117: return concat4(op1, "(", op2, ")"); ! 118: ! 119: } ! 120: ! 121: } ! 122: ! 123: ! 124: ! 125: char * ! 126: ! 127: sizedop(op, size) ! 128: ! 129: char *op, *size; ! 130: ! 131: { ! 132: ! 133: if (syntax == GAS) { ! 134: ! 135: return changesiz(concat(op, size)); ! 136: ! 137: } else { ! 138: ! 139: return concat4("(", op, ")", size); ! 140: ! 141: } ! 142: ! 143: } ! 144: ! 145: ! 146: ! 147: char * ! 148: ! 149: twoindex(disp, base, index) ! 150: ! 151: char *disp, *base, *index; ! 152: ! 153: { ! 154: ! 155: if (syntax == GAS) { ! 156: ! 157: return concat6(base, "@(", disp, ",", changesiz(index), ")"); ! 158: ! 159: } else { ! 160: ! 161: return concat6(disp, "(", base, ",", index, ")"); ! 162: ! 163: } ! 164: ! 165: } ! 166: ! 167: ! 168: ! 169: char * ! 170: ! 171: bitfield(op1, op2, op3) ! 172: ! 173: char *op1, *op2, *op3; ! 174: ! 175: { ! 176: ! 177: if (syntax == GAS) { ! 178: ! 179: return concat6(op1, "{#", op2, ":#", op3, "}"); ! 180: ! 181: } else { ! 182: ! 183: return concat6(op1, "{", op2, ":", op3, "}"); ! 184: ! 185: } ! 186: ! 187: } ! 188: ! 189: ! 190: ! 191: char * ! 192: ! 193: do_ops(label, opcode, space, operand) ! 194: ! 195: char *label, *opcode, *space, *operand; ! 196: ! 197: { ! 198: ! 199: static char temp[LINSIZ]; ! 200: ! 201: static char optemp[40]; ! 202: ! 203: char *to, *from; ! 204: ! 205: char c; ! 206: ! 207: ! 208: ! 209: if (syntax == GAS) { ! 210: ! 211: if (!strcmp(opcode, "ds.l")) { ! 212: ! 213: strcpy(temp, "\t.even\n\t.comm"); ! 214: ! 215: strcat(temp, space); ! 216: ! 217: strcat(temp, label); ! 218: ! 219: strcat(temp, ","); ! 220: ! 221: strcat(temp, "4*"); ! 222: ! 223: strcat(temp, operand); ! 224: ! 225: return strdup(temp); ! 226: ! 227: } else if (!strcmp(opcode, "ds.w")) { ! 228: ! 229: strcpy(temp, "\t.even\n\t.comm"); ! 230: ! 231: strcat(temp, space); ! 232: ! 233: strcat(temp, label); ! 234: ! 235: strcat(temp, ","); ! 236: ! 237: strcat(temp, "2*"); ! 238: ! 239: strcat(temp, operand); ! 240: ! 241: return strdup(temp); ! 242: ! 243: } else if (!strcmp(opcode, "ds.b")) { ! 244: ! 245: strcpy(temp, "\t.comm"); ! 246: ! 247: strcat(temp, space); ! 248: ! 249: strcat(temp, label); ! 250: ! 251: strcat(temp, ","); ! 252: ! 253: strcat(temp, operand); ! 254: ! 255: return strdup(temp); ! 256: ! 257: } else { ! 258: ! 259: to = optemp; ! 260: ! 261: from = opcode; ! 262: ! 263: for(;;) { ! 264: ! 265: c = *from++; ! 266: ! 267: if (!c) break; ! 268: ! 269: /* change 'foo.b' -> 'foob' */ ! 270: ! 271: /* special case: bra.s -> 'bra', since gas automatically ! 272: ! 273: * selects offset sizes and since some gas's actually ! 274: ! 275: * mess up if an explicit '.s' is given ! 276: ! 277: */ ! 278: ! 279: if (c == '.' && *from && from[1] == 0) { ! 280: ! 281: if (*from == 's') from++; ! 282: ! 283: continue; ! 284: ! 285: } ! 286: ! 287: *to++ = c; ! 288: ! 289: } ! 290: ! 291: *to = 0; ! 292: ! 293: opcode = optemp; ! 294: ! 295: } ! 296: ! 297: } ! 298: ! 299: ! 300: ! 301: to = temp; ! 302: ! 303: ! 304: ! 305: if (*label) { ! 306: ! 307: int colonseen = 0; ! 308: ! 309: char c; ! 310: ! 311: ! 312: ! 313: for (from = label; (c = *from++) != 0;) { ! 314: ! 315: if (c == ':') colonseen = 1; ! 316: ! 317: *to++ = c; ! 318: ! 319: } ! 320: ! 321: /* gas labels must have a ':' after them */ ! 322: ! 323: if (!colonseen && syntax == GAS) ! 324: ! 325: *to++ = ':'; ! 326: ! 327: } ! 328: ! 329: ! 330: ! 331: *to++ = '\t'; ! 332: ! 333: strcpy(to, opcode); ! 334: ! 335: strcat(temp, space); ! 336: ! 337: strcat(temp, operand); ! 338: ! 339: return strdup(temp); ! 340: ! 341: } ! 342: ! 343: ! 344: ! 345: char * ! 346: ! 347: changesiz(op) ! 348: ! 349: char *op; ! 350: ! 351: { ! 352: ! 353: char *r = op; ! 354: ! 355: ! 356: ! 357: if (syntax != GAS) return op; ! 358: ! 359: ! 360: ! 361: while (*op) { ! 362: ! 363: if (*op == '.') *op = ':'; ! 364: ! 365: op++; ! 366: ! 367: } ! 368: ! 369: return r; ! 370: ! 371: } ! 372: ! 373: ! 374: ! 375: char * ! 376: ! 377: hexop(op) ! 378: ! 379: char *op; ! 380: ! 381: { ! 382: ! 383: if (syntax == GAS) ! 384: ! 385: return concat("0x", op); ! 386: ! 387: else ! 388: ! 389: return concat("$", op); ! 390: ! 391: } ! 392:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.