OLD | NEW |
1 // Inferno utils/8l/span.c | 1 // Inferno utils/8l/span.c |
2 // http://code.google.com/p/inferno-os/source/browse/utils/8l/span.c | 2 // http://code.google.com/p/inferno-os/source/browse/utils/8l/span.c |
3 // | 3 // |
4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. | 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. |
5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) | 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) |
6 // Portions Copyright © 1997-1999 Vita Nuova Limited | 6 // Portions Copyright © 1997-1999 Vita Nuova Limited |
7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov
a.com) | 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov
a.com) |
8 // Portions Copyright © 2004,2006 Bruce Ellis | 8 // Portions Copyright © 2004,2006 Bruce Ellis |
9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) | 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) |
10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others | 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 ycover[Yrx*Ymax + Ymb] = 1; | 228 ycover[Yrx*Ymax + Ymb] = 1; |
229 ycover[Yrb*Ymax + Ymb] = 1; | 229 ycover[Yrb*Ymax + Ymb] = 1; |
230 ycover[Ym*Ymax + Ymb] = 1; | 230 ycover[Ym*Ymax + Ymb] = 1; |
231 | 231 |
232 ycover[Yax*Ymax + Yml] = 1; | 232 ycover[Yax*Ymax + Yml] = 1; |
233 ycover[Ycx*Ymax + Yml] = 1; | 233 ycover[Ycx*Ymax + Yml] = 1; |
234 ycover[Yrx*Ymax + Yml] = 1; | 234 ycover[Yrx*Ymax + Yml] = 1; |
235 ycover[Yrl*Ymax + Yml] = 1; | 235 ycover[Yrl*Ymax + Yml] = 1; |
236 ycover[Ym*Ymax + Yml] = 1; | 236 ycover[Ym*Ymax + Yml] = 1; |
237 | 237 |
| 238 ycover[Yax*Ymax + Ymm] = 1; |
| 239 ycover[Ycx*Ymax + Ymm] = 1; |
| 240 ycover[Yrx*Ymax + Ymm] = 1; |
| 241 ycover[Yrl*Ymax + Ymm] = 1; |
| 242 ycover[Ym*Ymax + Ymm] = 1; |
| 243 ycover[Ymr*Ymax + Ymm] = 1; |
| 244 |
| 245 ycover[Yax*Ymax + Yxm] = 1; |
| 246 ycover[Ycx*Ymax + Yxm] = 1; |
| 247 ycover[Yrx*Ymax + Yxm] = 1; |
| 248 ycover[Yrl*Ymax + Yxm] = 1; |
| 249 ycover[Ym*Ymax + Yxm] = 1; |
| 250 ycover[Yxr*Ymax + Yxm] = 1; |
| 251 |
238 for(i=0; i<D_NONE; i++) { | 252 for(i=0; i<D_NONE; i++) { |
239 reg[i] = -1; | 253 reg[i] = -1; |
240 if(i >= D_AL && i <= D_BH) | 254 if(i >= D_AL && i <= D_BH) |
241 reg[i] = (i-D_AL) & 7; | 255 reg[i] = (i-D_AL) & 7; |
242 if(i >= D_AX && i <= D_DI) | 256 if(i >= D_AX && i <= D_DI) |
243 reg[i] = (i-D_AX) & 7; | 257 reg[i] = (i-D_AX) & 7; |
244 if(i >= D_F0 && i <= D_F0+7) | 258 if(i >= D_F0 && i <= D_F0+7) |
245 reg[i] = (i-D_F0) & 7; | 259 reg[i] = (i-D_F0) & 7; |
| 260 if(i >= D_M0 && i <= D_M0+7) |
| 261 reg[i] = (i-D_M0) & 7; |
| 262 if(i >= D_X0 && i <= D_X0+7) |
| 263 reg[i] = (i-D_X0) & 7; |
246 } | 264 } |
247 } | 265 } |
248 | 266 |
249 int | 267 int |
250 prefixof(Adr *a) | 268 prefixof(Adr *a) |
251 { | 269 { |
252 switch(a->type) { | 270 switch(a->type) { |
253 case D_INDIR+D_CS: | 271 case D_INDIR+D_CS: |
254 return 0x2e; | 272 return 0x2e; |
255 case D_INDIR+D_DS: | 273 case D_INDIR+D_DS: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 339 |
322 case D_F0+1: | 340 case D_F0+1: |
323 case D_F0+2: | 341 case D_F0+2: |
324 case D_F0+3: | 342 case D_F0+3: |
325 case D_F0+4: | 343 case D_F0+4: |
326 case D_F0+5: | 344 case D_F0+5: |
327 case D_F0+6: | 345 case D_F0+6: |
328 case D_F0+7: | 346 case D_F0+7: |
329 return Yrf; | 347 return Yrf; |
330 | 348 |
| 349 case D_M0+0: |
| 350 case D_M0+1: |
| 351 case D_M0+2: |
| 352 case D_M0+3: |
| 353 case D_M0+4: |
| 354 case D_M0+5: |
| 355 case D_M0+6: |
| 356 case D_M0+7: |
| 357 return Ymr; |
| 358 |
| 359 case D_X0+0: |
| 360 case D_X0+1: |
| 361 case D_X0+2: |
| 362 case D_X0+3: |
| 363 case D_X0+4: |
| 364 case D_X0+5: |
| 365 case D_X0+6: |
| 366 case D_X0+7: |
| 367 return Yxr; |
| 368 |
331 case D_NONE: | 369 case D_NONE: |
332 return Ynone; | 370 return Ynone; |
333 | 371 |
334 case D_CS: return Ycs; | 372 case D_CS: return Ycs; |
335 case D_SS: return Yss; | 373 case D_SS: return Yss; |
336 case D_DS: return Yds; | 374 case D_DS: return Yds; |
337 case D_ES: return Yes; | 375 case D_ES: return Yes; |
338 case D_FS: return Yfs; | 376 case D_FS: return Yfs; |
339 case D_GS: return Ygs; | 377 case D_GS: return Ygs; |
340 | 378 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 if(v >= -128 && v < 128 && rel.siz == 0) { | 611 if(v >= -128 && v < 128 && rel.siz == 0) { |
574 *andptr++ = (1 << 6) | (4 << 0) | (r << 3); | 612 *andptr++ = (1 << 6) | (4 << 0) | (r << 3); |
575 asmidx(a->scale, a->index, t); | 613 asmidx(a->scale, a->index, t); |
576 *andptr++ = v; | 614 *andptr++ = v; |
577 return; | 615 return; |
578 } | 616 } |
579 *andptr++ = (2 << 6) | (4 << 0) | (r << 3); | 617 *andptr++ = (2 << 6) | (4 << 0) | (r << 3); |
580 asmidx(a->scale, a->index, t); | 618 asmidx(a->scale, a->index, t); |
581 goto putrelv; | 619 goto putrelv; |
582 } | 620 } |
583 » if(t >= D_AL && t <= D_F0+7) { | 621 » if(t >= D_AL && t <= D_X0+7) { |
584 if(v) | 622 if(v) |
585 goto bad; | 623 goto bad; |
586 *andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3); | 624 *andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3); |
587 return; | 625 return; |
588 } | 626 } |
589 ········ | 627 ········ |
590 scale = a->scale; | 628 scale = a->scale; |
591 if(t < D_INDIR || t >= 2*D_INDIR) { | 629 if(t < D_INDIR || t >= 2*D_INDIR) { |
592 switch(a->type) { | 630 switch(a->type) { |
593 default: | 631 default: |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 } | 853 } |
816 if(p->to.type == from) { | 854 if(p->to.type == from) { |
817 p->to.type = to+D_INDIR; | 855 p->to.type = to+D_INDIR; |
818 p->tt = 0; | 856 p->tt = 0; |
819 } | 857 } |
820 | 858 |
821 if(debug['Q']) | 859 if(debug['Q']) |
822 print("%P\n", p); | 860 print("%P\n", p); |
823 } | 861 } |
824 | 862 |
| 863 static int |
| 864 mediaop(Optab *o, int op, int osize, int z) |
| 865 { |
| 866 switch(op){ |
| 867 case Pm: |
| 868 case Pe: |
| 869 case Pf2: |
| 870 // case Pf3: |
| 871 if(osize != 1){ |
| 872 if(op != Pm) |
| 873 *andptr++ = op; |
| 874 *andptr++ = Pm; |
| 875 op = o->op[++z]; |
| 876 break; |
| 877 } |
| 878 default: |
| 879 if(andptr == and || andptr[-1] != Pm) |
| 880 *andptr++ = Pm; |
| 881 break; |
| 882 } |
| 883 *andptr++ = op; |
| 884 return z; |
| 885 } |
| 886 |
825 void | 887 void |
826 doasm(Prog *p) | 888 doasm(Prog *p) |
827 { | 889 { |
828 Optab *o; | 890 Optab *o; |
829 Prog *q, pp; | 891 Prog *q, pp; |
830 uchar *t; | 892 uchar *t; |
831 int z, op, ft, tt; | 893 int z, op, ft, tt; |
832 int32 v, pre; | 894 int32 v, pre; |
833 Reloc rel, *r; | 895 Reloc rel, *r; |
834 Adr *a; | 896 Adr *a; |
(...skipping 26 matching lines...) Expand all Loading... |
861 goto found; | 923 goto found; |
862 goto domov; | 924 goto domov; |
863 | 925 |
864 found: | 926 found: |
865 switch(o->prefix) { | 927 switch(o->prefix) { |
866 case Pq: /* 16 bit escape and opcode escape */ | 928 case Pq: /* 16 bit escape and opcode escape */ |
867 *andptr++ = Pe; | 929 *andptr++ = Pe; |
868 *andptr++ = Pm; | 930 *andptr++ = Pm; |
869 break; | 931 break; |
870 | 932 |
| 933 case Pf2: /* xmm opcode escape */ |
| 934 // case Pf3: |
| 935 *andptr++ = o->prefix; |
| 936 *andptr++ = Pm; |
| 937 break; |
| 938 |
871 case Pm: /* opcode escape */ | 939 case Pm: /* opcode escape */ |
872 *andptr++ = Pm; | 940 *andptr++ = Pm; |
873 break; | 941 break; |
874 | 942 |
875 case Pe: /* 16 bit escape */ | 943 case Pe: /* 16 bit escape */ |
876 *andptr++ = Pe; | 944 *andptr++ = Pe; |
877 break; | 945 break; |
878 | 946 |
879 case Pb: /* botch */ | 947 case Pb: /* botch */ |
880 break; | 948 break; |
(...skipping 11 matching lines...) Expand all Loading... |
892 case Zlit: | 960 case Zlit: |
893 for(; op = o->op[z]; z++) | 961 for(; op = o->op[z]; z++) |
894 *andptr++ = op; | 962 *andptr++ = op; |
895 break; | 963 break; |
896 | 964 |
897 case Zm_r: | 965 case Zm_r: |
898 *andptr++ = op; | 966 *andptr++ = op; |
899 asmand(&p->from, reg[p->to.type]); | 967 asmand(&p->from, reg[p->to.type]); |
900 break; | 968 break; |
901 | 969 |
| 970 case Zm_r_xm: |
| 971 mediaop(o, op, t[3], z); |
| 972 asmand(&p->from, reg[p->to.type]); |
| 973 break; |
| 974 |
902 case Zaut_r: | 975 case Zaut_r: |
903 *andptr++ = 0x8d; /* leal */ | 976 *andptr++ = 0x8d; /* leal */ |
904 if(p->from.type != D_ADDR) | 977 if(p->from.type != D_ADDR) |
905 diag("asmins: Zaut sb type ADDR"); | 978 diag("asmins: Zaut sb type ADDR"); |
906 p->from.type = p->from.index; | 979 p->from.type = p->from.index; |
907 p->from.index = D_NONE; | 980 p->from.index = D_NONE; |
908 p->ft = 0; | 981 p->ft = 0; |
909 asmand(&p->from, reg[p->to.type]); | 982 asmand(&p->from, reg[p->to.type]); |
910 p->from.index = p->from.type; | 983 p->from.index = p->from.type; |
911 p->from.type = D_ADDR; | 984 p->from.type = D_ADDR; |
912 p->ft = 0; | 985 p->ft = 0; |
913 break; | 986 break; |
914 | 987 |
915 case Zm_o: | 988 case Zm_o: |
916 *andptr++ = op; | 989 *andptr++ = op; |
917 asmand(&p->from, o->op[z+1]); | 990 asmand(&p->from, o->op[z+1]); |
918 break; | 991 break; |
919 | 992 |
920 case Zr_m: | 993 case Zr_m: |
921 *andptr++ = op; | 994 *andptr++ = op; |
922 asmand(&p->to, reg[p->from.type]); | 995 asmand(&p->to, reg[p->from.type]); |
923 break; | 996 break; |
924 | 997 |
| 998 case Zr_m_xm: |
| 999 mediaop(o, op, t[3], z); |
| 1000 asmand(&p->to, reg[p->from.type]); |
| 1001 break; |
| 1002 |
925 case Zo_m: | 1003 case Zo_m: |
926 *andptr++ = op; | 1004 *andptr++ = op; |
927 asmand(&p->to, o->op[z+1]); | 1005 asmand(&p->to, o->op[z+1]); |
928 break; | 1006 break; |
929 | 1007 |
930 case Zm_ibo: | 1008 case Zm_ibo: |
931 *andptr++ = op; | 1009 *andptr++ = op; |
932 asmand(&p->from, o->op[z+1]); | 1010 asmand(&p->from, o->op[z+1]); |
933 *andptr++ = vaddr(&p->to, nil); | 1011 *andptr++ = vaddr(&p->to, nil); |
934 break; | 1012 break; |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 void | 1394 void |
1317 asmins(Prog *p) | 1395 asmins(Prog *p) |
1318 { | 1396 { |
1319 andptr = and; | 1397 andptr = and; |
1320 doasm(p); | 1398 doasm(p); |
1321 if(andptr > and+sizeof and) { | 1399 if(andptr > and+sizeof and) { |
1322 print("and[] is too short - %d byte instruction\n", andptr - and
); | 1400 print("and[] is too short - %d byte instruction\n", andptr - and
); |
1323 errorexit(); | 1401 errorexit(); |
1324 } | 1402 } |
1325 } | 1403 } |
OLD | NEW |