7 if(OFFSET <= BADOFFSET && OFFSET+4 > BADOFFSET)\
11 if(OFFSET == BADOFFSET)\
87 objput(long l) /* emit long in byte order appropriate to object machine */
99 lput(long l) /* emit long in big-endian byte order */
111 if(*a >= '0' && *a <= '9')
116 if(s->type != STEXT && s->type != SLEAF)
117 diag("entry not text: %s", s->name);
129 Bprint(&bso, "%5.2f asm\n", cputime());
132 seek(cout, OFFSET, 0);
134 for(p = firstp; p != P; p = p->link) {
137 autosize = p->to.offset + 4;
140 diag("phase error %lux sb %lux",
147 o = oplook(p); /* could probably avoid this call */
148 if(asmout(p, o, 0)) {
159 etext = INITTEXT + textsize;
160 for(t = pc; t < etext; t += sizeof(buf)-100) {
161 if(etext-t > sizeof(buf)-100)
162 datblk(t, sizeof(buf)-100, 1);
164 datblk(t, etext-t, 1);
174 OFFSET = rnd(HEADR+textsize, 4096);
175 seek(cout, OFFSET, 0);
182 OFFSET = HEADR+textsize;
183 seek(cout, OFFSET, 0);
186 for(t = 0; t < datsize; t += sizeof(buf)-100) {
187 if(datsize-t > sizeof(buf)-100)
188 datblk(t, sizeof(buf)-100, 0);
190 datblk(t, datsize-t, 0);
197 Bprint(&bso, "%5.2f sym\n", cputime());
202 OFFSET = rnd(HEADR+textsize, 4096)+datsize;
203 seek(cout, OFFSET, 0);
210 OFFSET = HEADR+textsize+datsize;
211 seek(cout, OFFSET, 0);
217 Bprint(&bso, "%5.2f pc\n", cputime());
225 Bprint(&bso, "%5.2f header\n", cputime());
228 seek(cout, OFFSET, 0);
231 lput(0x160L<<16); /* magic and sections */
232 lput(0L); /* time and date */
233 lput(rnd(HEADR+textsize, 4096)+datsize);
234 lput(symsize); /* nsyms */
235 lput((0x38L<<16)|7L); /* size of optional hdr and flags */
236 lput((0413<<16)|0437L); /* magic and version */
237 lput(rnd(HEADR+textsize, 4096)); /* sizes */
240 lput(entryvalue()); /* va of entry */
241 lput(INITTEXT-HEADR); /* va of base of text */
242 lput(INITDAT); /* va of base of data */
243 lput(INITDAT+datsize); /* va of base of bss */
244 lput(~0L); /* gp reg mask */
249 lput(~0L); /* gp value ?? */
252 lput(0x160L<<16); /* magic and sections */
253 lput(0L); /* time and date */
254 lput(HEADR+textsize+datsize);
255 lput(symsize); /* nsyms */
256 lput((0x38L<<16)|7L); /* size of optional hdr and flags */
258 lput((0407<<16)|0437L); /* magic and version */
259 lput(textsize); /* sizes */
262 lput(entryvalue()); /* va of entry */
263 lput(INITTEXT); /* va of base of text */
264 lput(INITDAT); /* va of base of data */
265 lput(INITDAT+datsize); /* va of base of bss */
266 lput(~0L); /* gp reg mask */
271 lput(~0L); /* gp value ?? */
272 lput(0L); /* complete mystery */
279 lput(((((4*t)+0)*t)+7)); /* magic */
280 lput(textsize); /* sizes */
283 lput(symsize); /* nsyms */
284 lput(entryvalue()); /* va of entry */
289 lput((0x160L<<16)|3L); /* magic and sections */
290 lput(time(0)); /* time and date */
291 lput(HEADR+textsize+datsize);
292 lput(symsize); /* nsyms */
293 lput((0x38L<<16)|7L); /* size of optional hdr and flags */
295 lput((0407<<16)|0437L); /* magic and version */
296 lput(textsize); /* sizes */
299 lput(entryvalue()); /* va of entry */
300 lput(INITTEXT); /* va of base of text */
301 lput(INITDAT); /* va of base of data */
302 lput(INITDAT+datsize); /* va of base of bss */
303 lput(~0L); /* gp reg mask */
308 lput(~0L); /* gp value ?? */
310 strnput(".text", 8); /* text segment */
311 lput(INITTEXT); /* address */
316 lput(HEADR+textsize+datsize+symsize);
317 lput(lcsize & 0xffff); /* line number size */
318 lput(0x20L); /* flags */
320 strnput(".data", 8); /* data segment */
321 lput(INITDAT); /* address */
324 lput(HEADR+textsize);
328 lput(0x40L); /* flags */
330 strnput(".bss", 8); /* bss segment */
331 lput(INITDAT+datsize); /* address */
332 lput(INITDAT+datsize);
338 lput(0x80L); /* flags */
341 lput((0x160L<<16)|3L); /* magic and sections */
342 lput(time(0)); /* time and date */
343 lput(rnd(HEADR+textsize, 4096)+datsize);
344 lput(symsize); /* nsyms */
345 lput((0x38L<<16)|7L); /* size of optional hdr and flags */
347 lput((0413<<16)|01012L); /* magic and version */
348 lput(textsize); /* sizes */
351 lput(entryvalue()); /* va of entry */
352 lput(INITTEXT); /* va of base of text */
353 lput(INITDAT); /* va of base of data */
354 lput(INITDAT+datsize); /* va of base of bss */
355 lput(~0L); /* gp reg mask */
360 lput(~0L); /* gp value ?? */
362 strnput(".text", 8); /* text segment */
363 lput(INITTEXT); /* address */
368 lput(HEADR+textsize+datsize+symsize);
369 lput(lcsize & 0xffff); /* line number size */
370 lput(0x20L); /* flags */
372 strnput(".data", 8); /* data segment */
373 lput(INITDAT); /* address */
376 lput(rnd(HEADR+textsize, 4096)); /* sizes */
380 lput(0x40L); /* flags */
382 strnput(".bss", 8); /* bss segment */
383 lput(INITDAT+datsize); /* address */
384 lput(INITDAT+datsize);
390 lput(0x80L); /* flags */
393 /* first part of ELF is byte-wide parts, thus no byte-order issues */
394 strnput("\177ELF", 4); /* e_ident */
395 CPUT(1); /* class = 32 bit */
396 CPUT(little? 1: 2); /* data: 1 = LSB, 2 = MSB */
397 CPUT(1); /* version = 1 */
398 strnput("", 9); /* reserved for expansion */
399 /* entire remainder of ELF file is in target byte order */
401 /* file header part of ELF header */
402 objhput(2); /* type = EXEC */
403 objhput(8); /* machine = MIPS */
404 objput(1L); /* version = CURRENT */
405 objput(entryvalue()); /* entry vaddr */
406 objput(52L); /* offset to first phdr */
407 objput(0L); /* offset to first shdr */
408 objput(0L); /* flags (no MIPS flags defined) */
409 objhput(52); /* Ehdr size */
410 objhput(32); /* Phdr size */
411 objhput(3); /* # of Phdrs */
412 objhput(0); /* Shdr size */
413 objhput(0); /* # of Shdrs */
414 objhput(0); /* Shdr string size */
416 /* "Program headers" - one per chunk of file to load */
419 * include ELF headers in text -- 8l doesn't,
420 * but in theory it aids demand loading.
422 objput(1L); /* text: type = PT_LOAD */
423 objput(0L); /* file offset */
424 objput(INITTEXT-HEADR); /* vaddr */
425 objput(INITTEXT-HEADR); /* paddr */
426 objput(HEADR+textsize); /* file size */
427 objput(HEADR+textsize); /* memory size */
428 objput(0x05L); /* protections = RX */
429 objput(0x1000L); /* page-align text off's & vaddrs */
431 objput(1L); /* data: type = PT_LOAD */
432 objput(HEADR+textsize); /* file offset */
433 objput(INITDAT); /* vaddr */
434 objput(INITDAT); /* paddr */
435 objput(datsize); /* file size */
436 objput(datsize+bsssize); /* memory size */
437 objput(0x06L); /* protections = RW */
438 if(INITDAT % 4096 == 0 && (HEADR + textsize) % 4096 == 0)
439 objput(0x1000L); /* page-align data off's & vaddrs */
441 objput(0L); /* do not claim alignment */
443 objput(0L); /* P9 symbols: type = PT_NULL */
444 objput(HEADR+textsize+datsize); /* file offset */
447 objput(symsize); /* symbol table size */
448 objput(lcsize); /* line number size */
449 objput(0x04L); /* protections = R */
450 objput(0L); /* do not claim alignment */
459 strnput(char *s, int n)
474 n = sizeof(buf.cbuf) - cbc;
476 write(cout, buf.cbuf, n);
478 cbc = sizeof(buf.cbuf);
482 nopstat(char *f, Count *c)
485 Bprint(&bso, "%s delay %ld/%ld (%.2f)\n", f,
486 c->outof - c->count, c->outof,
487 (double)(c->outof - c->count)/c->outof);
498 s = lookup("etext", 0);
500 putsymb(s->name, 'T', s->value, s->version);
502 for(h=0; h<NHASH; h++)
503 for(s=hash[h]; s!=S; s=s->link)
506 putsymb(s->name, 'D', s->value, s->version);
510 putsymb(s->name, 'T', s->value, s->version);
514 putsymb(s->name, 'D', s->value+INITDAT, s->version);
518 putsymb(s->name, 'B', s->value+INITDAT, s->version);
522 putsymb(s->name, 'f', s->value, s->version);
526 for(p=textp; p!=P; p=p->cond) {
528 if(s->type != STEXT && s->type != SLEAF)
531 /* filenames first */
532 for(a=p->to.autom; a; a=a->link)
533 if(a->type == D_FILE)
534 putsymb(a->asym->name, 'z', a->aoffset, 0);
536 if(a->type == D_FILE1)
537 putsymb(a->asym->name, 'Z', a->aoffset, 0);
540 putsymb(s->name, 'T', s->value, s->version);
542 putsymb(s->name, 'L', s->value, s->version);
544 /* frame, auto and param after */
545 putsymb(".frame", 'm', p->to.offset+4, 0);
546 for(a=p->to.autom; a; a=a->link)
547 if(a->type == D_AUTO)
548 putsymb(a->asym->name, 'a', -a->aoffset, 0);
550 if(a->type == D_PARAM)
551 putsymb(a->asym->name, 'p', a->aoffset, 0);
553 if(debug['v'] || debug['n'])
554 Bprint(&bso, "symsize = %lud\n", symsize);
559 putsymb(char *s, int t, long v, int ver)
568 CPUT(t+0x80); /* 0x80 is variable length */
570 if(t == 'Z' || t == 'z') {
572 for(i=1; s[i] != 0 || s[i+1] != 0; i += 2) {
585 symsize += 4 + 1 + i + 1;
588 if(t == 'z' || t == 'Z') {
589 Bprint(&bso, "%c %.8lux ", t, v);
590 for(i=1; s[i] != 0 || s[i+1] != 0; i+=2) {
591 f = ((s[i]&0xff) << 8) | (s[i+1]&0xff);
592 Bprint(&bso, "/%x", f);
598 Bprint(&bso, "%c %.8lux %s<%d>\n", t, v, s, ver);
600 Bprint(&bso, "%c %.8lux %s\n", t, v, s);
614 for(p = firstp; p != P; p = p->link) {
615 if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
619 Bprint(&bso, "%6lux %P\n",
624 Bprint(&bso, "\t\t%6ld", lcsize);
625 v = (p->pc - oldpc) / MINLC;
630 CPUT(s+128); /* 129-255 +pc */
632 Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128);
638 oldpc = p->pc + MINLC;
639 if(s > 64 || s < -64) {
640 CPUT(0); /* 0 vv +lc */
647 Bprint(&bso, " lc+%ld(%d,%ld)\n",
650 Bprint(&bso, " lc%ld(%d,%ld)\n",
652 Bprint(&bso, "%6lux %P\n",
659 CPUT(0+s); /* 1-64 +lc */
661 Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s);
662 Bprint(&bso, "%6lux %P\n",
666 CPUT(64-s); /* 65-128 -lc */
668 Bprint(&bso, " lc%ld(%ld)\n", s, 64-s);
669 Bprint(&bso, "%6lux %P\n",
680 if(debug['v'] || debug['L'])
681 Bprint(&bso, "lcsize = %ld\n", lcsize);
686 datblk(long s, long n, int str)
693 memset(buf.dbuf, 0, n+100);
694 for(p = datap; p != P; p = p->link) {
696 if(str != (p->from.sym->type == SSTRING))
698 l = p->from.sym->value + p->from.offset - s;
711 if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
712 for(j=l+(c-i)-1; j>=l; j--)
715 diag("multiple initialization");
721 diag("unknown mode in initialization\n%P", p);
728 fl = ieeedtof(p->to.ieee);
731 buf.dbuf[l] = cast[fnuxi8[i+4]];
736 cast = (char*)p->to.ieee;
738 buf.dbuf[l] = cast[fnuxi8[i]];
747 buf.dbuf[l] = p->to.sval[i];
755 switch(p->to.sym->type) {
759 d += p->to.sym->value;
763 d += p->to.sym->value + INITDAT;
770 diag("bad nuxi %d %d\n%P", c, i, curp);
774 buf.dbuf[l] = cast[inuxi1[i]];
780 buf.dbuf[l] = cast[inuxi2[i]];
786 buf.dbuf[l] = cast[inuxi4[i]];
794 write(cout, buf.dbuf, n);
797 #define OP_RRR(op,r1,r2,r3)\
798 (op|(((r1)&31L)<<16)|(((r2)&31L)<<21)|(((r3)&31L)<<11))
799 #define OP_IRR(op,i,r2,r3)\
800 (op|((i)&0xffffL)|(((r2)&31L)<<21)|(((r3)&31L)<<16))
801 #define OP_SRR(op,s,r2,r3)\
802 (op|(((s)&31L)<<6)|(((r2)&31L)<<16)|(((r3)&31L)<<11))
803 #define OP_FRRR(op,r1,r2,r3)\
804 (op|(((r1)&31L)<<16)|(((r2)&31L)<<11)|(((r3)&31L)<<6))
805 #define OP_JMP(op,i)\
806 ((op)|((i)&0x3ffffffL))
811 (((x)<<29)|((y)<<26))
813 (((x)<<19)|((y)<<16))
815 (SP(2,0)|(16<<21)|((x)<<3)|((y)<<0))
817 (SP(2,1)|(16<<21)|((x)<<3)|((y)<<0))
819 (SP(2,1)|(17<<21)|((x)<<3)|((y)<<0))
821 (SP(2,1)|(20<<21)|((x)<<3)|((y)<<0))
826 asmout(Prog *p, Optab *o, int aflag)
828 long o1, o2, o3, o4, o5, o6, o7, v;
841 diag("unknown type %d", o->type);
846 case 0: /* pseudo ops */
853 autosize = p->to.offset + 4;
854 o1 = asmout(p->link, oplook(p->link), aflag);
858 o1 = asmout(p->link, oplook(p->link), aflag);
864 case 1: /* mov[v] r1,r2 ==> OR r1,r0,r2 */
865 o1 = OP_RRR(oprrr(AOR), p->from.reg, REGZERO, p->to.reg);
868 case 2: /* add/sub r1,[r2],r3 */
872 o1 = OP_RRR(oprrr(p->as), p->from.reg, r, p->to.reg);
875 case 3: /* mov $soreg, r ==> or/add $i,o,r */
876 v = regoff(&p->from);
881 if(o->a1 == C_ANDCON)
883 o1 = OP_IRR(opirr(a), v, r, p->to.reg);
886 case 4: /* add $scon,[r1],r2 */
887 v = regoff(&p->from);
891 o1 = OP_IRR(opirr(p->as), v, r, p->to.reg);
894 case 5: /* syscall */
900 case 6: /* beq r1,[r2],sbra */
906 v = (p->cond->pc - pc-4) >> 2;
907 if(((v << 16) >> 16) != v)
908 diag("short branch too far: %ld\n%P", v, p);
909 o1 = OP_IRR(opirr(p->as), v, p->from.reg, p->reg);
912 case 7: /* mov r, soreg ==> sw o(r) */
917 o1 = OP_IRR(opirr(p->as), v, r, p->from.reg);
920 case 8: /* mov soreg, r ==> lw o(r) */
924 v = regoff(&p->from);
925 o1 = OP_IRR(opirr(p->as+ALAST), v, r, p->to.reg);
928 case 9: /* asl r1,[r2],r3 */
932 o1 = OP_RRR(oprrr(p->as), r, p->from.reg, p->to.reg);
935 case 10: /* add $con,[r1],r2 ==> mov $con,t; add t,[r1],r2 */
936 v = regoff(&p->from);
940 o1 = OP_IRR(opirr(r), v, 0, REGTMP);
944 o2 = OP_RRR(oprrr(p->as), REGTMP, r, p->to.reg);
947 case 11: /* jmp lbra */
953 v = p->cond->pc >> 2;
954 o1 = OP_JMP(opirr(p->as), v);
955 if(!debug['Y'] && p->link && p->cond && isnop(p->link)) {
959 o2 = asmout(p->cond, oplook(p->cond), 1);
963 Bprint(&bso, " %.8lux: %.8lux %.8lux%P\n",
972 case 12: /* movbs r,r */
976 o1 = OP_SRR(opirr(ASLL), v, p->from.reg, p->to.reg);
977 o2 = OP_SRR(opirr(ASRA), v, p->to.reg, p->to.reg);
980 case 13: /* movbu r,r */
982 o1 = OP_IRR(opirr(AAND), 0xffL, p->from.reg, p->to.reg);
984 o1 = OP_IRR(opirr(AAND), 0xffffL, p->from.reg, p->to.reg);
987 case 16: /* sll $c,[r1],r2 */
988 v = regoff(&p->from);
993 /* OP_SRR will use only the low 5 bits of the shift value */
994 if(v >= 32 && vshift(p->as))
995 o1 = OP_SRR(opirr(p->as+ALAST), v-32, r, p->to.reg);
997 o1 = OP_SRR(opirr(p->as), v, r, p->to.reg);
1000 case 18: /* jmp [r1],0(r2) */
1006 o1 = OP_RRR(oprrr(p->as), 0, p->to.reg, r);
1009 case 19: /* mov $lcon,r ==> lu+or */
1010 v = regoff(&p->from);
1011 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, p->to.reg);
1012 o2 = OP_IRR(opirr(AOR), v, p->to.reg, p->to.reg);
1015 case 20: /* mov lohi,r */
1016 r = OP(2,0); /* mfhi */
1017 if(p->from.type == D_LO)
1018 r = OP(2,2); /* mflo */
1019 o1 = OP_RRR(r, REGZERO, REGZERO, p->to.reg);
1022 case 21: /* mov r,lohi */
1023 r = OP(2,1); /* mthi */
1024 if(p->to.type == D_LO)
1025 r = OP(2,3); /* mtlo */
1026 o1 = OP_RRR(r, REGZERO, p->from.reg, REGZERO);
1029 case 22: /* mul r1,r2 */
1030 o1 = OP_RRR(oprrr(p->as), p->from.reg, p->reg, REGZERO);
1033 case 23: /* add $lcon,r1,r2 ==> lu+or+add */
1034 v = regoff(&p->from);
1035 if(p->to.reg == REGTMP || p->reg == REGTMP)
1036 diag("cant synthesize large constant\n%P", p);
1037 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1038 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1042 o3 = OP_RRR(oprrr(p->as), REGTMP, r, p->to.reg);
1045 case 24: /* mov $ucon,,r ==> lu r */
1046 v = regoff(&p->from);
1047 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, p->to.reg);
1050 case 25: /* add/and $ucon,[r1],r2 ==> lu $con,t; add t,[r1],r2 */
1051 v = regoff(&p->from);
1052 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1056 o2 = OP_RRR(oprrr(p->as), REGTMP, r, p->to.reg);
1059 case 26: /* mov $lsext/auto/oreg,,r2 ==> lu+or+add */
1060 v = regoff(&p->from);
1061 if(p->to.reg == REGTMP)
1062 diag("cant synthesize large constant\n%P", p);
1063 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1064 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1068 o3 = OP_RRR(oprrr(AADDU), REGTMP, r, p->to.reg);
1071 case 27: /* mov [sl]ext/auto/oreg,fr ==> lwc1 o(r) */
1075 v = regoff(&p->from);
1078 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1079 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1080 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1081 o4 = OP_IRR(opirr(AMOVF+ALAST), 0, REGTMP, p->to.reg+1);
1082 o5 = OP_IRR(opirr(AMOVF+ALAST), 4, REGTMP, p->to.reg);
1085 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1086 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1087 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1088 o4 = OP_IRR(opirr(AMOVF+ALAST), 0, REGTMP, p->to.reg);
1091 o1 = OP_IRR(opirr(AMOVF+ALAST), v, r, p->to.reg+1);
1092 o2 = OP_IRR(opirr(AMOVF+ALAST), v+4, r, p->to.reg);
1095 o1 = OP_IRR(opirr(AMOVF+ALAST), v, r, p->to.reg);
1100 case 28: /* mov fr,[sl]ext/auto/oreg ==> swc1 o(r) */
1108 diag("cant synthesize large constant\n%P", p);
1109 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1110 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1111 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1112 o4 = OP_IRR(opirr(AMOVF), 0, REGTMP, p->from.reg+1);
1113 o5 = OP_IRR(opirr(AMOVF), 4, REGTMP, p->from.reg);
1117 diag("cant synthesize large constant\n%P", p);
1118 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1119 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1120 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1121 o4 = OP_IRR(opirr(AMOVF), 0, REGTMP, p->from.reg);
1124 o1 = OP_IRR(opirr(AMOVF), v, r, p->from.reg+1);
1125 o2 = OP_IRR(opirr(AMOVF), v+4, r, p->from.reg);
1128 o1 = OP_IRR(opirr(AMOVF), v, r, p->from.reg);
1133 case 30: /* movw r,fr */
1134 r = SP(2,1)|(4<<21); /* mtc1 */
1135 o1 = OP_RRR(r, p->from.reg, 0, p->to.reg);
1138 case 31: /* movw fr,r */
1139 r = SP(2,1)|(0<<21); /* mfc1 */
1140 o1 = OP_RRR(r, p->to.reg, 0, p->from.reg);
1143 case 32: /* fadd fr1,[fr2],fr3 */
1146 o1 = OP_FRRR(oprrr(p->as), p->from.reg, p->to.reg, p->to.reg);
1148 o1 = OP_FRRR(oprrr(p->as), p->from.reg, r, p->to.reg);
1151 case 33: /* fabs fr1,fr3 */
1152 o1 = OP_FRRR(oprrr(p->as), 0, p->from.reg, p->to.reg);
1155 case 34: /* mov $con,fr ==> or/add $i,r,r2 */
1156 v = regoff(&p->from);
1158 if(o->a1 == C_ANDCON)
1160 o1 = OP_IRR(opirr(r), v, 0, REGTMP);
1161 o2 = OP_RRR(SP(2,1)|(4<<21), REGTMP, 0, p->to.reg); /* mtc1 */
1164 case 35: /* mov r,lext/luto/oreg ==> sw o(r) */
1166 * the lowbits of the constant cannot
1167 * be moved into the offset of the load
1168 * because the mips 4000 in 64-bit mode
1169 * does a 64-bit add and it will screw up.
1176 diag("cant synthesize large constant\n%P", p);
1177 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1178 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1179 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1180 o4 = OP_IRR(opirr(p->as), 0, REGTMP, p->from.reg);
1183 case 36: /* mov lext/lauto/lreg,r ==> lw o(r30) */
1184 v = regoff(&p->from);
1189 diag("cant synthesize large constant\n%P", p);
1190 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1191 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1192 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1193 o4 = OP_IRR(opirr(p->as+ALAST), 0, REGTMP, p->to.reg);
1196 case 37: /* movw r,mr */
1197 r = SP(2,0)|(4<<21); /* mtc0 */
1199 r = SP(2,0)|(5<<21); /* dmtc0 */
1200 o1 = OP_RRR(r, p->from.reg, 0, p->to.reg);
1203 case 38: /* movw mr,r */
1204 r = SP(2,0)|(0<<21); /* mfc0 */
1206 r = SP(2,0)|(1<<21); /* dmfc0 */
1207 o1 = OP_RRR(r, p->to.reg, 0, p->from.reg);
1210 case 39: /* rfe ==> jmp+rfe */
1213 o1 = OP_RRR(oprrr(AJMP), 0, p->to.reg, REGZERO);
1220 o1 = regoff(&p->to);
1223 case 41: /* movw r,fcr */
1224 o1 = OP_RRR(SP(2,1)|(2<<21), REGZERO, 0, p->to.reg); /* mfcc1 */
1225 o2 = OP_RRR(SP(2,1)|(6<<21), p->from.reg, 0, p->to.reg);/* mtcc1 */
1228 case 42: /* movw fcr,r */
1229 o1 = OP_RRR(SP(2,1)|(2<<21), p->to.reg, 0, p->from.reg);/* mfcc1 */
1232 case 45: /* case r */
1238 o1 = OP_IRR(opirr(ALAST), (v>>16)+1, REGZERO, REGTMP);
1240 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1241 o2 = OP_SRR(opirr(ASLL), 2, p->from.reg, p->from.reg);
1242 o3 = OP_RRR(oprrr(AADD), p->from.reg, REGTMP, REGTMP);
1243 o4 = OP_IRR(opirr(AMOVW+ALAST), v, REGTMP, REGTMP);
1244 o5 = OP_RRR(oprrr(ANOR), REGZERO, REGZERO, REGZERO);
1245 o6 = OP_RRR(oprrr(AJMP), 0, REGTMP, REGZERO);
1246 o7 = OP_RRR(oprrr(ANOR), REGZERO, REGZERO, REGZERO);
1249 case 46: /* bcase $con,lbra */
1263 Bprint(&bso, " %.8lux:\t\t%P\n", v, p);
1267 Bprint(&bso, " %.8lux: %.8lux\t%P\n", v, o1, p);
1272 Bprint(&bso, " %.8lux: %.8lux %.8lux%P\n", v, o1, o2, p);
1278 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux%P\n", v, o1, o2, o3, p);
1285 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux%P\n",
1286 v, o1, o2, o3, o4, p);
1294 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux%P\n",
1295 v, o1, o2, o3, o4, o5, p);
1305 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux %.8lux %.8lux%P\n",
1306 v, o1, o2, o3, o4, o5, o6, o7, p);
1324 if(p->reg != REGZERO && p->reg != NREG)
1326 if(p->from.type != D_REG || p->from.reg != REGZERO)
1328 if(p->to.type != D_REG || p->to.reg != REGZERO)
1337 case AADD: return OP(4,0);
1338 case AADDU: return OP(4,1);
1339 case ASGT: return OP(5,2);
1340 case ASGTU: return OP(5,3);
1341 case AAND: return OP(4,4);
1342 case AOR: return OP(4,5);
1343 case AXOR: return OP(4,6);
1344 case ASUB: return OP(4,2);
1345 case ASUBU: return OP(4,3);
1346 case ANOR: return OP(4,7);
1347 case ASLL: return OP(0,4);
1348 case ASRL: return OP(0,6);
1349 case ASRA: return OP(0,7);
1352 case ADIV: return OP(3,2);
1354 case ADIVU: return OP(3,3);
1355 case AMUL: return OP(3,0);
1356 case AMULU: return OP(3,1);
1358 case AJMP: return OP(1,0);
1359 case AJAL: return OP(1,1);
1361 case ABREAK: return OP(1,5);
1362 case ASYSCALL: return OP(1,4);
1363 case ATLBP: return MMU(1,0);
1364 case ATLBR: return MMU(0,1);
1365 case ATLBWI: return MMU(0,2);
1366 case ATLBWR: return MMU(0,6);
1367 case ARFE: return MMU(2,0);
1369 case ADIVF: return FPF(0,3);
1370 case ADIVD: return FPD(0,3);
1371 case AMULF: return FPF(0,2);
1372 case AMULD: return FPD(0,2);
1373 case ASUBF: return FPF(0,1);
1374 case ASUBD: return FPD(0,1);
1375 case AADDF: return FPF(0,0);
1376 case AADDD: return FPD(0,0);
1378 case AMOVFW: return FPF(4,4);
1379 case AMOVDW: return FPD(4,4);
1380 case AMOVWF: return FPW(4,0);
1381 case AMOVDF: return FPD(4,0);
1382 case AMOVWD: return FPW(4,1);
1383 case AMOVFD: return FPF(4,1);
1384 case AABSF: return FPF(0,5);
1385 case AABSD: return FPD(0,5);
1386 case AMOVF: return FPF(0,6);
1387 case AMOVD: return FPD(0,6);
1388 case ANEGF: return FPF(0,7);
1389 case ANEGD: return FPD(0,7);
1391 case ACMPEQF: return FPF(6,2);
1392 case ACMPEQD: return FPD(6,2);
1393 case ACMPGTF: return FPF(7,4);
1394 case ACMPGTD: return FPD(7,4);
1395 case ACMPGEF: return FPF(7,6);
1396 case ACMPGED: return FPD(7,6);
1398 case ADIVV: return OP(3,6);
1399 case ADIVVU: return OP(3,7);
1400 case AADDV: return OP(5,4);
1401 case AADDVU: return OP(5,5);
1403 diag("bad rrr %d", a);
1411 case AADD: return SP(1,0);
1412 case AADDU: return SP(1,1);
1413 case ASGT: return SP(1,2);
1414 case ASGTU: return SP(1,3);
1415 case AAND: return SP(1,4);
1416 case AOR: return SP(1,5);
1417 case AXOR: return SP(1,6);
1418 case ALAST: return SP(1,7);
1419 case ASLL: return OP(0,0);
1420 case ASRL: return OP(0,2);
1421 case ASRA: return OP(0,3);
1423 case AJMP: return SP(0,2);
1424 case AJAL: return SP(0,3);
1425 case ABEQ: return SP(0,4);
1426 case ABNE: return SP(0,5);
1428 case ABGEZ: return SP(0,1)|BCOND(0,1);
1429 case ABGEZAL: return SP(0,1)|BCOND(2,1);
1430 case ABGTZ: return SP(0,7);
1431 case ABLEZ: return SP(0,6);
1432 case ABLTZ: return SP(0,1)|BCOND(0,0);
1433 case ABLTZAL: return SP(0,1)|BCOND(2,0);
1435 case ABFPT: return SP(2,1)|(257<<16);
1436 case ABFPF: return SP(2,1)|(256<<16);
1439 case AMOVBU: return SP(5,0);
1441 case AMOVHU: return SP(5,1);
1442 case AMOVW: return SP(5,3);
1443 case AMOVV: return SP(7,7);
1444 case AMOVF: return SP(7,1);
1445 case AMOVWL: return SP(5,2);
1446 case AMOVWR: return SP(5,6);
1447 case AMOVVL: return SP(5,4);
1448 case AMOVVR: return SP(5,5);
1450 case ABREAK: return SP(5,7);
1452 case AMOVWL+ALAST: return SP(4,2);
1453 case AMOVWR+ALAST: return SP(4,6);
1454 case AMOVVL+ALAST: return SP(3,2);
1455 case AMOVVR+ALAST: return SP(3,3);
1456 case AMOVB+ALAST: return SP(4,0);
1457 case AMOVBU+ALAST: return SP(4,4);
1458 case AMOVH+ALAST: return SP(4,1);
1459 case AMOVHU+ALAST: return SP(4,5);
1460 case AMOVW+ALAST: return SP(4,3);
1461 case AMOVV+ALAST: return SP(6,7);
1462 case AMOVF+ALAST: return SP(6,1);
1464 case ASLLV: return OP(7,0);
1465 case ASRLV: return OP(7,2);
1466 case ASRAV: return OP(7,3);
1467 case ASLLV+ALAST: return OP(7,4);
1468 case ASRLV+ALAST: return OP(7,6);
1469 case ASRAV+ALAST: return OP(7,7);
1471 case AADDV: return SP(3,0);
1472 case AADDVU: return SP(3,1);
1474 diag("bad irr %d", a);
1483 case ASLLV: return 1;
1484 case ASRLV: return 1;
1485 case ASRAV: return 1;