LEFT | RIGHT |
1 // Inferno utils/6l/span.c | 1 // Inferno utils/6l/span.c |
2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/span.c | 2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 { | 365 { |
366 vlong v; | 366 vlong v; |
367 int32 l; | 367 int32 l; |
368 | 368 |
369 if(a->type >= D_INDIR || a->index != D_NONE) { | 369 if(a->type >= D_INDIR || a->index != D_NONE) { |
370 if(a->index != D_NONE && a->scale == 0) { | 370 if(a->index != D_NONE && a->scale == 0) { |
371 if(a->type == D_ADDR) { | 371 if(a->type == D_ADDR) { |
372 switch(a->index) { | 372 switch(a->index) { |
373 case D_EXTERN: | 373 case D_EXTERN: |
374 case D_STATIC: | 374 case D_STATIC: |
375 » » » » » if (!debug['U']) | 375 » » » » » if(flag_shared) |
| 376 » » » » » » return Yiauto; |
| 377 » » » » » else |
376 return Yi32; /* TO DO: Yi64 *
/ | 378 return Yi32; /* TO DO: Yi64 *
/ |
377 /* else fallthrough */ | |
378 case D_AUTO: | 379 case D_AUTO: |
379 case D_PARAM: | 380 case D_PARAM: |
380 return Yiauto; | 381 return Yiauto; |
381 } | 382 } |
382 return Yxxx; | 383 return Yxxx; |
383 } | 384 } |
384 return Ycol; | 385 return Ycol; |
385 } | 386 } |
386 return Ym; | 387 return Ym; |
387 } | 388 } |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 switch(t) { | 727 switch(t) { |
727 case D_STATIC: | 728 case D_STATIC: |
728 case D_EXTERN: | 729 case D_EXTERN: |
729 s = a->sym; | 730 s = a->sym; |
730 if(!s->reachable) | 731 if(!s->reachable) |
731 diag("unreachable symbol in vaddr - %s", s->name); | 732 diag("unreachable symbol in vaddr - %s", s->name); |
732 if(r == nil) { | 733 if(r == nil) { |
733 diag("need reloc for %D", a); | 734 diag("need reloc for %D", a); |
734 errorexit(); | 735 errorexit(); |
735 } | 736 } |
736 » » if (!debug['U']) | 737 » » if(flag_shared) |
| 738 » » » r->type = D_PCREL; |
| 739 » » else |
737 r->type = D_ADDR; | 740 r->type = D_ADDR; |
738 else | |
739 r->type = D_PCREL; | |
740 r->siz = 4; // TODO: 8 for external symbols | 741 r->siz = 4; // TODO: 8 for external symbols |
741 r->off = -1; // caller must fill in | 742 r->off = -1; // caller must fill in |
742 r->sym = s; | 743 r->sym = s; |
743 r->add = v; | 744 r->add = v; |
744 v = 0; | 745 v = 0; |
745 } | 746 } |
746 return v; | 747 return v; |
747 } | 748 } |
748 | 749 |
749 static void | 750 static void |
750 asmandsz(Adr *a, int r, int rex, int m64) | 751 asmandsz(Adr *a, int r, int rex, int m64) |
751 { | 752 { |
752 int32 v; | 753 int32 v; |
753 int t, scale; | 754 int t, scale; |
754 Reloc rel; | 755 Reloc rel; |
755 | 756 |
756 USED(m64); | 757 USED(m64); |
757 rex &= (0x40 | Rxr); | 758 rex &= (0x40 | Rxr); |
758 v = a->offset; | 759 v = a->offset; |
759 t = a->type; | 760 t = a->type; |
760 rel.siz = 0; | 761 rel.siz = 0; |
761 if(a->index != D_NONE) { | 762 if(a->index != D_NONE) { |
762 if(t < D_INDIR) {· | 763 if(t < D_INDIR) {· |
763 switch(t) { | 764 switch(t) { |
| 765 default: |
| 766 goto bad; |
764 case D_STATIC: | 767 case D_STATIC: |
765 case D_EXTERN: | 768 case D_EXTERN: |
766 » » » » if (!debug['U']) { | 769 » » » » if(flag_shared) |
767 » » » » » t = D_NONE; | 770 » » » » » goto bad; |
768 » » » » » v = vaddr(a, &rel); | 771 » » » » t = D_NONE; |
769 » » » » » break; | 772 » » » » v = vaddr(a, &rel); |
770 » » » » } /* else, fallthrough */ | 773 » » » » break; |
771 » » » default: | |
772 » » » » goto bad; | |
773 case D_AUTO: | 774 case D_AUTO: |
774 case D_PARAM: | 775 case D_PARAM: |
775 t = D_SP; | 776 t = D_SP; |
776 break; | 777 break; |
777 } | 778 } |
778 } else | 779 } else |
779 t -= D_INDIR; | 780 t -= D_INDIR; |
780 rexflag |= (regrex[(int)a->index] & Rxx) | (regrex[t] & Rxb) | r
ex; | 781 rexflag |= (regrex[(int)a->index] & Rxx) | (regrex[t] & Rxb) | r
ex; |
781 if(t == D_NONE) { | 782 if(t == D_NONE) { |
782 *andptr++ = (0 << 6) | (4 << 0) | (r << 3); | 783 *andptr++ = (0 << 6) | (4 << 0) | (r << 3); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 case D_PARAM: | 821 case D_PARAM: |
821 t = D_SP; | 822 t = D_SP; |
822 break; | 823 break; |
823 } | 824 } |
824 scale = 1; | 825 scale = 1; |
825 } else | 826 } else |
826 t -= D_INDIR; | 827 t -= D_INDIR; |
827 | 828 |
828 rexflag |= (regrex[t] & Rxb) | rex; | 829 rexflag |= (regrex[t] & Rxb) | rex; |
829 if(t == D_NONE || (D_CS <= t && t <= D_GS)) { | 830 if(t == D_NONE || (D_CS <= t && t <= D_GS)) { |
830 » » if(debug['U'] && t == D_NONE && (a->type == D_STATIC || a->type
== D_EXTERN) || asmode != 64){ | 831 » » if(flag_shared && t == D_NONE && (a->type == D_STATIC || a->type
== D_EXTERN) || asmode != 64) { |
831 *andptr++ = (0 << 6) | (5 << 0) | (r << 3); | 832 *andptr++ = (0 << 6) | (5 << 0) | (r << 3); |
832 goto putrelv; | 833 goto putrelv; |
833 } | 834 } |
834 /* temporary */ | 835 /* temporary */ |
835 *andptr++ = (0 << 6) | (4 << 0) | (r << 3); /* sib present *
/ | 836 *andptr++ = (0 << 6) | (4 << 0) | (r << 3); /* sib present *
/ |
836 *andptr++ = (0 << 6) | (4 << 3) | (5 << 0); /* DS:d32 */ | 837 *andptr++ = (0 << 6) | (4 << 3) | (5 << 0); /* DS:d32 */ |
837 goto putrelv; | 838 goto putrelv; |
838 } | 839 } |
839 if(t == D_SP || t == D_R12) { | 840 if(t == D_SP || t == D_R12) { |
840 if(v == 0) { | 841 if(v == 0) { |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 break; | 1785 break; |
1785 } | 1786 } |
1786 memmove(and+np+1, and+np, n-np); | 1787 memmove(and+np+1, and+np, n-np); |
1787 and[np] = 0x40 | rexflag; | 1788 and[np] = 0x40 | rexflag; |
1788 andptr++; | 1789 andptr++; |
1789 } | 1790 } |
1790 n = andptr - and; | 1791 n = andptr - and; |
1791 for(r=cursym->r+cursym->nr; r-- > cursym->r; ) { | 1792 for(r=cursym->r+cursym->nr; r-- > cursym->r; ) { |
1792 if(r->off < p->pc) | 1793 if(r->off < p->pc) |
1793 break; | 1794 break; |
1794 » » if (rexflag) | 1795 » » if(rexflag) |
1795 r->off++; | 1796 r->off++; |
1796 » » if (r->type == D_PCREL) | 1797 » » if(r->type == D_PCREL) |
1797 r->add -= p->pc + n - (r->off + r->siz); | 1798 r->add -= p->pc + n - (r->off + r->siz); |
1798 } | 1799 } |
1799 } | 1800 } |
LEFT | RIGHT |