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); /* 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 */
342 lput((0x160L<<16)|3L); /* magic and sections */
343 lput(time(0)); /* time and date */
344 lput(rnd(HEADR+textsize, 4096)+datsize);
345 lput(symsize); /* nsyms */
346 lput((0x38L<<16)|7L); /* size of optional hdr and flags */
348 lput((0413<<16)|01012L); /* magic and version */
349 lput(textsize); /* sizes */
352 lput(entryvalue()); /* va of entry */
353 lput(INITTEXT); /* va of base of text */
354 lput(INITDAT); /* va of base of data */
355 lput(INITDAT+datsize); /* va of base of bss */
356 lput(~0L); /* gp reg mask */
361 lput(~0L); /* gp value ?? */
363 strnput(".text", 8); /* text segment */
364 lput(INITTEXT); /* address */
369 lput(HEADR+textsize+datsize+symsize);
370 lput(lcsize); /* line number size */
371 lput(0x20L); /* flags */
373 strnput(".data", 8); /* data segment */
374 lput(INITDAT); /* address */
377 lput(rnd(HEADR+textsize, 4096)); /* sizes */
381 lput(0x40L); /* flags */
383 strnput(".bss", 8); /* bss segment */
384 lput(INITDAT+datsize); /* address */
385 lput(INITDAT+datsize);
391 lput(0x80L); /* flags */
394 /* first part of ELF is byte-wide parts, thus no byte-order issues */
395 strnput("\177ELF", 4); /* e_ident */
396 CPUT(1); /* class = 32 bit */
397 CPUT(little? 1: 2); /* data: 1 = LSB, 2 = MSB */
398 CPUT(1); /* version = 1 */
399 strnput("", 9); /* reserved for expansion */
400 /* entire remainder of ELF file is in target byte order */
402 /* file header part of ELF header */
403 objhput(2); /* type = EXEC */
404 objhput(8); /* machine = MIPS */
405 objput(1L); /* version = CURRENT */
406 objput(entryvalue()); /* entry vaddr */
407 objput(52L); /* offset to first phdr */
408 objput(0L); /* offset to first shdr */
409 objput(0L); /* flags (no MIPS flags defined) */
410 objhput(52); /* Ehdr size */
411 objhput(32); /* Phdr size */
412 objhput(3); /* # of Phdrs */
413 objhput(0); /* Shdr size */
414 objhput(0); /* # of Shdrs */
415 objhput(0); /* Shdr string size */
417 /* "Program headers" - one per chunk of file to load */
420 * include ELF headers in text -- 8l doesn't,
421 * but in theory it aids demand loading.
423 objput(1L); /* text: type = PT_LOAD */
424 objput(0L); /* file offset */
425 objput(INITTEXT-HEADR); /* vaddr */
426 objput(INITTEXT-HEADR); /* paddr */
427 objput(HEADR+textsize); /* file size */
428 objput(HEADR+textsize); /* memory size */
429 objput(0x05L); /* protections = RX */
430 objput(0x1000L); /* page-align text off's & vaddrs */
432 objput(1L); /* data: type = PT_LOAD */
433 objput(HEADR+textsize); /* file offset */
434 objput(INITDAT); /* vaddr */
435 objput(INITDAT); /* paddr */
436 objput(datsize); /* file size */
437 objput(datsize+bsssize); /* memory size */
438 objput(0x06L); /* protections = RW */
439 if(INITDAT % 4096 == 0 && (HEADR + textsize) % 4096 == 0)
440 objput(0x1000L); /* page-align data off's & vaddrs */
442 objput(0L); /* do not claim alignment */
444 objput(0L); /* P9 symbols: type = PT_NULL */
445 objput(HEADR+textsize+datsize); /* file offset */
448 objput(symsize); /* symbol table size */
449 objput(lcsize); /* line number size */
450 objput(0x04L); /* protections = R */
451 objput(0L); /* do not claim alignment */
460 strnput(char *s, int n)
475 n = sizeof(buf.cbuf) - cbc;
477 write(cout, buf.cbuf, n);
479 cbc = sizeof(buf.cbuf);
483 nopstat(char *f, Count *c)
486 Bprint(&bso, "%s delay %ld/%ld (%.2f)\n", f,
487 c->outof - c->count, c->outof,
488 (double)(c->outof - c->count)/c->outof);
499 s = lookup("etext", 0);
501 putsymb(s->name, 'T', s->value, s->version);
503 for(h=0; h<NHASH; h++)
504 for(s=hash[h]; s!=S; s=s->link)
507 putsymb(s->name, 'D', s->value, s->version);
511 putsymb(s->name, 'T', s->value, s->version);
515 putsymb(s->name, 'D', s->value+INITDAT, s->version);
519 putsymb(s->name, 'B', s->value+INITDAT, s->version);
523 putsymb(s->name, 'f', s->value, s->version);
527 for(p=textp; p!=P; p=p->cond) {
529 if(s->type != STEXT && s->type != SLEAF)
532 /* filenames first */
533 for(a=p->to.autom; a; a=a->link)
534 if(a->type == D_FILE)
535 putsymb(a->asym->name, 'z', a->aoffset, 0);
537 if(a->type == D_FILE1)
538 putsymb(a->asym->name, 'Z', a->aoffset, 0);
541 putsymb(s->name, 'T', s->value, s->version);
543 putsymb(s->name, 'L', s->value, s->version);
545 /* frame, auto and param after */
546 putsymb(".frame", 'm', p->to.offset+4, 0);
547 for(a=p->to.autom; a; a=a->link)
548 if(a->type == D_AUTO)
549 putsymb(a->asym->name, 'a', -a->aoffset, 0);
551 if(a->type == D_PARAM)
552 putsymb(a->asym->name, 'p', a->aoffset, 0);
554 if(debug['v'] || debug['n'])
555 Bprint(&bso, "symsize = %lud\n", symsize);
560 putsymb(char *s, int t, long v, int ver)
569 CPUT(t+0x80); /* 0x80 is variable length */
571 if(t == 'Z' || t == 'z') {
573 for(i=1; s[i] != 0 || s[i+1] != 0; i += 2) {
586 symsize += 4 + 1 + i + 1;
589 if(t == 'z' || t == 'Z') {
590 Bprint(&bso, "%c %.8lux ", t, v);
591 for(i=1; s[i] != 0 || s[i+1] != 0; i+=2) {
592 f = ((s[i]&0xff) << 8) | (s[i+1]&0xff);
593 Bprint(&bso, "/%x", f);
599 Bprint(&bso, "%c %.8lux %s<%d>\n", t, v, s, ver);
601 Bprint(&bso, "%c %.8lux %s\n", t, v, s);
615 for(p = firstp; p != P; p = p->link) {
616 if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
620 Bprint(&bso, "%6lux %P\n",
625 Bprint(&bso, "\t\t%6ld", lcsize);
626 v = (p->pc - oldpc) / MINLC;
631 CPUT(s+128); /* 129-255 +pc */
633 Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128);
639 oldpc = p->pc + MINLC;
640 if(s > 64 || s < -64) {
641 CPUT(0); /* 0 vv +lc */
648 Bprint(&bso, " lc+%ld(%d,%ld)\n",
651 Bprint(&bso, " lc%ld(%d,%ld)\n",
653 Bprint(&bso, "%6lux %P\n",
660 CPUT(0+s); /* 1-64 +lc */
662 Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s);
663 Bprint(&bso, "%6lux %P\n",
667 CPUT(64-s); /* 65-128 -lc */
669 Bprint(&bso, " lc%ld(%ld)\n", s, 64-s);
670 Bprint(&bso, "%6lux %P\n",
681 if(debug['v'] || debug['L'])
682 Bprint(&bso, "lcsize = %ld\n", lcsize);
687 datblk(long s, long n, int str)
694 memset(buf.dbuf, 0, n+100);
695 for(p = datap; p != P; p = p->link) {
697 if(str != (p->from.sym->type == SSTRING))
699 l = p->from.sym->value + p->from.offset - s;
712 if(p->as != AINIT && p->as != ADYNT) {
713 for(j=l+(c-i)-1; j>=l; j--)
716 diag("multiple initialization");
722 diag("unknown mode in initialization\n%P", p);
729 fl = ieeedtof(p->to.ieee);
732 buf.dbuf[l] = cast[fnuxi8[i+4]];
737 cast = (char*)p->to.ieee;
739 buf.dbuf[l] = cast[fnuxi8[i]];
748 buf.dbuf[l] = p->to.sval[i];
756 switch(p->to.sym->type) {
760 d += p->to.sym->value;
764 d += p->to.sym->value + INITDAT;
771 diag("bad nuxi %d %d\n%P", c, i, curp);
775 buf.dbuf[l] = cast[inuxi1[i]];
781 buf.dbuf[l] = cast[inuxi2[i]];
787 buf.dbuf[l] = cast[inuxi4[i]];
795 write(cout, buf.dbuf, n);
798 #define OP_RRR(op,r1,r2,r3)\
799 (op|(((r1)&31L)<<16)|(((r2)&31L)<<21)|(((r3)&31L)<<11))
800 #define OP_IRR(op,i,r2,r3)\
801 (op|((i)&0xffffL)|(((r2)&31L)<<21)|(((r3)&31L)<<16))
802 #define OP_SRR(op,s,r2,r3)\
803 (op|(((s)&31L)<<6)|(((r2)&31L)<<16)|(((r3)&31L)<<11))
804 #define OP_FRRR(op,r1,r2,r3)\
805 (op|(((r1)&31L)<<16)|(((r2)&31L)<<11)|(((r3)&31L)<<6))
806 #define OP_JMP(op,i)\
807 ((op)|((i)&0x3ffffffL))
812 (((x)<<29)|((y)<<26))
814 (((x)<<19)|((y)<<16))
816 (SP(2,0)|(16<<21)|((x)<<3)|((y)<<0))
818 (SP(2,1)|(16<<21)|((x)<<3)|((y)<<0))
820 (SP(2,1)|(17<<21)|((x)<<3)|((y)<<0))
822 (SP(2,1)|(20<<21)|((x)<<3)|((y)<<0))
827 asmout(Prog *p, Optab *o, int aflag)
829 long o1, o2, o3, o4, o5, o6, o7, v;
842 diag("unknown type %d", o->type);
847 case 0: /* pseudo ops */
854 autosize = p->to.offset + 4;
855 o1 = asmout(p->link, oplook(p->link), aflag);
859 o1 = asmout(p->link, oplook(p->link), aflag);
865 case 1: /* mov[v] r1,r2 ==> OR r1,r0,r2 */
866 o1 = OP_RRR(oprrr(AOR), p->from.reg, REGZERO, p->to.reg);
869 case 2: /* add/sub r1,[r2],r3 */
873 o1 = OP_RRR(oprrr(p->as), p->from.reg, r, p->to.reg);
876 case 3: /* mov $soreg, r ==> or/add $i,o,r */
877 v = regoff(&p->from);
882 if(o->a1 == C_ANDCON)
884 o1 = OP_IRR(opirr(a), v, r, p->to.reg);
887 case 4: /* add $scon,[r1],r2 */
888 v = regoff(&p->from);
892 o1 = OP_IRR(opirr(p->as), v, r, p->to.reg);
895 case 5: /* syscall */
901 case 6: /* beq r1,[r2],sbra */
907 v = (p->cond->pc - pc-4) >> 2;
908 if(((v << 16) >> 16) != v)
909 diag("short branch too far: %ld\n%P", v, p);
910 o1 = OP_IRR(opirr(p->as), v, p->from.reg, p->reg);
913 case 7: /* mov r, soreg ==> sw o(r) */
918 o1 = OP_IRR(opirr(p->as), v, r, p->from.reg);
921 case 8: /* mov soreg, r ==> lw o(r) */
925 v = regoff(&p->from);
926 o1 = OP_IRR(opirr(p->as+ALAST), v, r, p->to.reg);
929 case 9: /* asl r1,[r2],r3 */
933 o1 = OP_RRR(oprrr(p->as), r, p->from.reg, p->to.reg);
936 case 10: /* add $con,[r1],r2 ==> mov $con,t; add t,[r1],r2 */
937 v = regoff(&p->from);
941 o1 = OP_IRR(opirr(r), v, 0, REGTMP);
945 o2 = OP_RRR(oprrr(p->as), REGTMP, r, p->to.reg);
948 case 11: /* jmp lbra */
954 v = p->cond->pc >> 2;
955 o1 = OP_JMP(opirr(p->as), v);
956 if(!debug['Y'] && p->link && p->cond && isnop(p->link)) {
960 o2 = asmout(p->cond, oplook(p->cond), 1);
964 Bprint(&bso, " %.8lux: %.8lux %.8lux%P\n",
973 case 12: /* movbs r,r */
977 o1 = OP_SRR(opirr(ASLL), v, p->from.reg, p->to.reg);
978 o2 = OP_SRR(opirr(ASRA), v, p->to.reg, p->to.reg);
981 case 13: /* movbu r,r */
983 o1 = OP_IRR(opirr(AAND), 0xffL, p->from.reg, p->to.reg);
985 o1 = OP_IRR(opirr(AAND), 0xffffL, p->from.reg, p->to.reg);
988 case 16: /* sll $c,[r1],r2 */
989 v = regoff(&p->from);
994 /* OP_SRR will use only the low 5 bits of the shift value */
995 if(v >= 32 && vshift(p->as))
996 o1 = OP_SRR(opirr(p->as+ALAST), v-32, r, p->to.reg);
998 o1 = OP_SRR(opirr(p->as), v, r, p->to.reg);
1001 case 18: /* jmp [r1],0(r2) */
1007 o1 = OP_RRR(oprrr(p->as), 0, p->to.reg, r);
1010 case 19: /* mov $lcon,r ==> lu+or */
1011 v = regoff(&p->from);
1012 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, p->to.reg);
1013 o2 = OP_IRR(opirr(AOR), v, p->to.reg, p->to.reg);
1016 case 20: /* mov lohi,r */
1017 r = OP(2,0); /* mfhi */
1018 if(p->from.type == D_LO)
1019 r = OP(2,2); /* mflo */
1020 o1 = OP_RRR(r, REGZERO, REGZERO, p->to.reg);
1023 case 21: /* mov r,lohi */
1024 r = OP(2,1); /* mthi */
1025 if(p->to.type == D_LO)
1026 r = OP(2,3); /* mtlo */
1027 o1 = OP_RRR(r, REGZERO, p->from.reg, REGZERO);
1030 case 22: /* mul r1,r2 */
1031 o1 = OP_RRR(oprrr(p->as), p->from.reg, p->reg, REGZERO);
1034 case 23: /* add $lcon,r1,r2 ==> lu+or+add */
1035 v = regoff(&p->from);
1036 if(p->to.reg == REGTMP || p->reg == REGTMP)
1037 diag("cant synthesize large constant\n%P", p);
1038 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1039 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1043 o3 = OP_RRR(oprrr(p->as), REGTMP, r, p->to.reg);
1046 case 24: /* mov $ucon,,r ==> lu r */
1047 v = regoff(&p->from);
1048 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, p->to.reg);
1051 case 25: /* add/and $ucon,[r1],r2 ==> lu $con,t; add t,[r1],r2 */
1052 v = regoff(&p->from);
1053 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1057 o2 = OP_RRR(oprrr(p->as), REGTMP, r, p->to.reg);
1060 case 26: /* mov $lsext/auto/oreg,,r2 ==> lu+or+add */
1061 v = regoff(&p->from);
1062 if(p->to.reg == REGTMP)
1063 diag("cant synthesize large constant\n%P", p);
1064 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1065 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1069 o3 = OP_RRR(oprrr(AADDU), REGTMP, r, p->to.reg);
1072 case 27: /* mov [sl]ext/auto/oreg,fr ==> lwc1 o(r) */
1076 v = regoff(&p->from);
1079 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1080 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1081 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1082 o4 = OP_IRR(opirr(AMOVF+ALAST), 0, REGTMP, p->to.reg+1);
1083 o5 = OP_IRR(opirr(AMOVF+ALAST), 4, REGTMP, p->to.reg);
1086 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1087 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1088 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1089 o4 = OP_IRR(opirr(AMOVF+ALAST), 0, REGTMP, p->to.reg);
1092 o1 = OP_IRR(opirr(AMOVF+ALAST), v, r, p->to.reg+1);
1093 o2 = OP_IRR(opirr(AMOVF+ALAST), v+4, r, p->to.reg);
1096 o1 = OP_IRR(opirr(AMOVF+ALAST), v, r, p->to.reg);
1101 case 28: /* mov fr,[sl]ext/auto/oreg ==> swc1 o(r) */
1109 diag("cant synthesize large constant\n%P", p);
1110 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1111 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1112 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1113 o4 = OP_IRR(opirr(AMOVF), 0, REGTMP, p->from.reg+1);
1114 o5 = OP_IRR(opirr(AMOVF), 4, REGTMP, p->from.reg);
1118 diag("cant synthesize large constant\n%P", p);
1119 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1120 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1121 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1122 o4 = OP_IRR(opirr(AMOVF), 0, REGTMP, p->from.reg);
1125 o1 = OP_IRR(opirr(AMOVF), v, r, p->from.reg+1);
1126 o2 = OP_IRR(opirr(AMOVF), v+4, r, p->from.reg);
1129 o1 = OP_IRR(opirr(AMOVF), v, r, p->from.reg);
1134 case 30: /* movw r,fr */
1135 r = SP(2,1)|(4<<21); /* mtc1 */
1136 o1 = OP_RRR(r, p->from.reg, 0, p->to.reg);
1139 case 31: /* movw fr,r */
1140 r = SP(2,1)|(0<<21); /* mfc1 */
1141 o1 = OP_RRR(r, p->to.reg, 0, p->from.reg);
1144 case 32: /* fadd fr1,[fr2],fr3 */
1147 o1 = OP_FRRR(oprrr(p->as), p->from.reg, p->to.reg, p->to.reg);
1149 o1 = OP_FRRR(oprrr(p->as), p->from.reg, r, p->to.reg);
1152 case 33: /* fabs fr1,fr3 */
1153 o1 = OP_FRRR(oprrr(p->as), 0, p->from.reg, p->to.reg);
1156 case 34: /* mov $con,fr ==> or/add $i,r,r2 */
1157 v = regoff(&p->from);
1159 if(o->a1 == C_ANDCON)
1161 o1 = OP_IRR(opirr(r), v, 0, REGTMP);
1162 o2 = OP_RRR(SP(2,1)|(4<<21), REGTMP, 0, p->to.reg); /* mtc1 */
1165 case 35: /* mov r,lext/luto/oreg ==> sw o(r) */
1167 * the lowbits of the constant cannot
1168 * be moved into the offset of the load
1169 * because the mips 4000 in 64-bit mode
1170 * does a 64-bit add and it will screw up.
1177 diag("cant synthesize large constant\n%P", p);
1178 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1179 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1180 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1181 o4 = OP_IRR(opirr(p->as), 0, REGTMP, p->from.reg);
1184 case 36: /* mov lext/lauto/lreg,r ==> lw o(r30) */
1185 v = regoff(&p->from);
1190 diag("cant synthesize large constant\n%P", p);
1191 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1192 o2 = OP_IRR(opirr(AOR), v, REGTMP, REGTMP);
1193 o3 = OP_RRR(oprrr(AADDU), r, REGTMP, REGTMP);
1194 o4 = OP_IRR(opirr(p->as+ALAST), 0, REGTMP, p->to.reg);
1197 case 37: /* movw r,mr */
1198 r = SP(2,0)|(4<<21); /* mtc0 */
1200 r = SP(2,0)|(5<<21); /* dmtc0 */
1201 o1 = OP_RRR(r, p->from.reg, 0, p->to.reg);
1204 case 38: /* movw mr,r */
1205 r = SP(2,0)|(0<<21); /* mfc0 */
1207 r = SP(2,0)|(1<<21); /* dmfc0 */
1208 o1 = OP_RRR(r, p->to.reg, 0, p->from.reg);
1211 case 39: /* rfe ==> jmp+rfe */
1214 o1 = OP_RRR(oprrr(AJMP), 0, p->to.reg, REGZERO);
1221 o1 = regoff(&p->to);
1224 case 41: /* movw r,fcr */
1225 o1 = OP_RRR(SP(2,1)|(2<<21), REGZERO, 0, p->to.reg); /* mfcc1 */
1226 o2 = OP_RRR(SP(2,1)|(6<<21), p->from.reg, 0, p->to.reg);/* mtcc1 */
1229 case 42: /* movw fcr,r */
1230 o1 = OP_RRR(SP(2,1)|(2<<21), p->to.reg, 0, p->from.reg);/* mfcc1 */
1233 case 45: /* case r */
1239 o1 = OP_IRR(opirr(ALAST), (v>>16)+1, REGZERO, REGTMP);
1241 o1 = OP_IRR(opirr(ALAST), v>>16, REGZERO, REGTMP);
1242 o2 = OP_SRR(opirr(ASLL), 2, p->from.reg, p->from.reg);
1243 o3 = OP_RRR(oprrr(AADD), p->from.reg, REGTMP, REGTMP);
1244 o4 = OP_IRR(opirr(AMOVW+ALAST), v, REGTMP, REGTMP);
1245 o5 = OP_RRR(oprrr(ANOR), REGZERO, REGZERO, REGZERO);
1246 o6 = OP_RRR(oprrr(AJMP), 0, REGTMP, REGZERO);
1247 o7 = OP_RRR(oprrr(ANOR), REGZERO, REGZERO, REGZERO);
1250 case 46: /* bcase $con,lbra */
1264 Bprint(&bso, " %.8lux:\t\t%P\n", v, p);
1268 Bprint(&bso, " %.8lux: %.8lux\t%P\n", v, o1, p);
1273 Bprint(&bso, " %.8lux: %.8lux %.8lux%P\n", v, o1, o2, p);
1279 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux%P\n", v, o1, o2, o3, p);
1286 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux%P\n",
1287 v, o1, o2, o3, o4, p);
1295 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux%P\n",
1296 v, o1, o2, o3, o4, o5, p);
1306 Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux %.8lux %.8lux%P\n",
1307 v, o1, o2, o3, o4, o5, o6, o7, p);
1325 if(p->reg != REGZERO && p->reg != NREG)
1327 if(p->from.type != D_REG || p->from.reg != REGZERO)
1329 if(p->to.type != D_REG || p->to.reg != REGZERO)
1338 case AADD: return OP(4,0);
1339 case AADDU: return OP(4,1);
1340 case ASGT: return OP(5,2);
1341 case ASGTU: return OP(5,3);
1342 case AAND: return OP(4,4);
1343 case AOR: return OP(4,5);
1344 case AXOR: return OP(4,6);
1345 case ASUB: return OP(4,2);
1346 case ASUBU: return OP(4,3);
1347 case ANOR: return OP(4,7);
1348 case ASLL: return OP(0,4);
1349 case ASRL: return OP(0,6);
1350 case ASRA: return OP(0,7);
1353 case ADIV: return OP(3,2);
1355 case ADIVU: return OP(3,3);
1356 case AMUL: return OP(3,0);
1357 case AMULU: return OP(3,1);
1359 case AJMP: return OP(1,0);
1360 case AJAL: return OP(1,1);
1362 case ABREAK: return OP(1,5);
1363 case ASYSCALL: return OP(1,4);
1364 case ATLBP: return MMU(1,0);
1365 case ATLBR: return MMU(0,1);
1366 case ATLBWI: return MMU(0,2);
1367 case ATLBWR: return MMU(0,6);
1368 case ARFE: return MMU(2,0);
1370 case ADIVF: return FPF(0,3);
1371 case ADIVD: return FPD(0,3);
1372 case AMULF: return FPF(0,2);
1373 case AMULD: return FPD(0,2);
1374 case ASUBF: return FPF(0,1);
1375 case ASUBD: return FPD(0,1);
1376 case AADDF: return FPF(0,0);
1377 case AADDD: return FPD(0,0);
1379 case AMOVFW: return FPF(4,4);
1380 case AMOVDW: return FPD(4,4);
1381 case AMOVWF: return FPW(4,0);
1382 case AMOVDF: return FPD(4,0);
1383 case AMOVWD: return FPW(4,1);
1384 case AMOVFD: return FPF(4,1);
1385 case AABSF: return FPF(0,5);
1386 case AABSD: return FPD(0,5);
1387 case AMOVF: return FPF(0,6);
1388 case AMOVD: return FPD(0,6);
1389 case ANEGF: return FPF(0,7);
1390 case ANEGD: return FPD(0,7);
1392 case ACMPEQF: return FPF(6,2);
1393 case ACMPEQD: return FPD(6,2);
1394 case ACMPGTF: return FPF(7,4);
1395 case ACMPGTD: return FPD(7,4);
1396 case ACMPGEF: return FPF(7,6);
1397 case ACMPGED: return FPD(7,6);
1399 case ADIVV: return OP(3,6);
1400 case ADIVVU: return OP(3,7);
1401 case AADDV: return OP(5,4);
1402 case AADDVU: return OP(5,5);
1404 diag("bad rrr %d", a);
1412 case AADD: return SP(1,0);
1413 case AADDU: return SP(1,1);
1414 case ASGT: return SP(1,2);
1415 case ASGTU: return SP(1,3);
1416 case AAND: return SP(1,4);
1417 case AOR: return SP(1,5);
1418 case AXOR: return SP(1,6);
1419 case ALAST: return SP(1,7);
1420 case ASLL: return OP(0,0);
1421 case ASRL: return OP(0,2);
1422 case ASRA: return OP(0,3);
1424 case AJMP: return SP(0,2);
1425 case AJAL: return SP(0,3);
1426 case ABEQ: return SP(0,4);
1427 case ABNE: return SP(0,5);
1429 case ABGEZ: return SP(0,1)|BCOND(0,1);
1430 case ABGEZAL: return SP(0,1)|BCOND(2,1);
1431 case ABGTZ: return SP(0,7);
1432 case ABLEZ: return SP(0,6);
1433 case ABLTZ: return SP(0,1)|BCOND(0,0);
1434 case ABLTZAL: return SP(0,1)|BCOND(2,0);
1436 case ABFPT: return SP(2,1)|(257<<16);
1437 case ABFPF: return SP(2,1)|(256<<16);
1440 case AMOVBU: return SP(5,0);
1442 case AMOVHU: return SP(5,1);
1443 case AMOVW: return SP(5,3);
1444 case AMOVV: return SP(7,7);
1445 case AMOVF: return SP(7,1);
1446 case AMOVWL: return SP(5,2);
1447 case AMOVWR: return SP(5,6);
1448 case AMOVVL: return SP(5,4);
1449 case AMOVVR: return SP(5,5);
1451 case ABREAK: return SP(5,7);
1453 case AMOVWL+ALAST: return SP(4,2);
1454 case AMOVWR+ALAST: return SP(4,6);
1455 case AMOVVL+ALAST: return SP(3,2);
1456 case AMOVVR+ALAST: return SP(3,3);
1457 case AMOVB+ALAST: return SP(4,0);
1458 case AMOVBU+ALAST: return SP(4,4);
1459 case AMOVH+ALAST: return SP(4,1);
1460 case AMOVHU+ALAST: return SP(4,5);
1461 case AMOVW+ALAST: return SP(4,3);
1462 case AMOVV+ALAST: return SP(6,7);
1463 case AMOVF+ALAST: return SP(6,1);
1465 case ASLLV: return OP(7,0);
1466 case ASRLV: return OP(7,2);
1467 case ASRAV: return OP(7,3);
1468 case ASLLV+ALAST: return OP(7,4);
1469 case ASRLV+ALAST: return OP(7,6);
1470 case ASRAV+ALAST: return OP(7,7);
1472 case AADDV: return SP(3,0);
1473 case AADDVU: return SP(3,1);
1475 diag("bad irr %d", a);
1484 case ASLLV: return 1;
1485 case ASRLV: return 1;
1486 case ASRAV: return 1;