OLD | NEW |
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 void | 190 void |
191 xdefine(char *p, int t, vlong v) | 191 xdefine(char *p, int t, vlong v) |
192 { | 192 { |
193 Sym *s; | 193 Sym *s; |
194 | 194 |
195 s = lookup(p, 0); | 195 s = lookup(p, 0); |
196 s->type = t; | 196 s->type = t; |
197 s->value = v; | 197 s->value = v; |
198 s->reachable = 1; | 198 s->reachable = 1; |
| 199 s->special = 1; |
199 } | 200 } |
200 | 201 |
201 void | 202 void |
202 instinit(void) | 203 instinit(void) |
203 { | 204 { |
204 int c, i; | 205 int c, i; |
205 | 206 |
206 for(i=1; optab[i].as; i++) { | 207 for(i=1; optab[i].as; i++) { |
207 c = optab[i].as; | 208 c = optab[i].as; |
208 if(opindex[c] != nil) { | 209 if(opindex[c] != nil) { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 r->off = p->pc + andptr - and; | 665 r->off = p->pc + andptr - and; |
665 } | 666 } |
666 put8(v); | 667 put8(v); |
667 } | 668 } |
668 */ | 669 */ |
669 | 670 |
670 vlong | 671 vlong |
671 symaddr(Sym *s) | 672 symaddr(Sym *s) |
672 { | 673 { |
673 switch(s->type) { | 674 switch(s->type) { |
674 case SFIXED: | |
675 return s->value; | |
676 ········ | |
677 case SMACHO: | 675 case SMACHO: |
678 return segdata.vaddr + segdata.filelen - dynptrsize + s->value; | 676 return segdata.vaddr + segdata.filelen - dynptrsize + s->value; |
679 | 677 |
680 default: | 678 default: |
681 if(!s->reachable) | 679 if(!s->reachable) |
682 diag("unreachable symbol in symaddr - %s", s->name); | 680 diag("unreachable symbol in symaddr - %s", s->name); |
683 return s->value; | 681 return s->value; |
684 } | 682 } |
685 } | 683 } |
686 | 684 |
687 static vlong | 685 static vlong |
688 vaddr(Adr *a, Reloc *r) | 686 vaddr(Adr *a, Reloc *r) |
689 { | 687 { |
690 int t; | 688 int t; |
691 vlong v; | 689 vlong v; |
692 Sym *s; | 690 Sym *s; |
693 ········ | 691 ········ |
694 if(r != nil) | 692 if(r != nil) |
695 memset(r, 0, sizeof *r); | 693 memset(r, 0, sizeof *r); |
696 | 694 |
697 t = a->type; | 695 t = a->type; |
698 v = a->offset; | 696 v = a->offset; |
699 if(t == D_ADDR) | 697 if(t == D_ADDR) |
700 t = a->index; | 698 t = a->index; |
701 switch(t) { | 699 switch(t) { |
702 case D_STATIC: | 700 case D_STATIC: |
703 case D_EXTERN: | 701 case D_EXTERN: |
704 s = a->sym; | 702 s = a->sym; |
705 » » switch(s->type) { | 703 » » if(!s->reachable) |
706 » » case SFIXED: | 704 » » » diag("unreachable symbol in vaddr - %s", s->name); |
707 » » » v += s->value; | 705 » » if(r == nil) { |
708 » » » break; | 706 » » » diag("need reloc for %D", a); |
709 » » default: | 707 » » » errorexit(); |
710 » » » if(!s->reachable) | |
711 » » » » diag("unreachable symbol in vaddr - %s", s->name
); | |
712 » » » if(r == nil) { | |
713 » » » » diag("need reloc for %D", a); | |
714 » » » » errorexit(); | |
715 » » » } | |
716 » » » r->type = D_ADDR; | |
717 » » » r->siz = 4;» // TODO: 8 for external symbols | |
718 » » » r->off = -1;» // caller must fill in | |
719 » » » r->sym = s; | |
720 » » » r->add = v; | |
721 » » » v = 0; | |
722 » » » break; | |
723 } | 708 } |
| 709 r->type = D_ADDR; |
| 710 r->siz = 4; // TODO: 8 for external symbols |
| 711 r->off = -1; // caller must fill in |
| 712 r->sym = s; |
| 713 r->add = v; |
| 714 v = 0; |
724 } | 715 } |
725 return v; | 716 return v; |
726 } | 717 } |
727 | 718 |
728 static void | 719 static void |
729 asmandsz(Adr *a, int r, int rex, int m64) | 720 asmandsz(Adr *a, int r, int rex, int m64) |
730 { | 721 { |
731 int32 v; | 722 int32 v; |
732 int t, scale; | 723 int t, scale; |
733 Reloc rel; | 724 Reloc rel; |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 for(r=cursym->r+cursym->nr; r-- > cursym->r; ) { | 1749 for(r=cursym->r+cursym->nr; r-- > cursym->r; ) { |
1759 if(r->off < p->pc) | 1750 if(r->off < p->pc) |
1760 break; | 1751 break; |
1761 r->off++; | 1752 r->off++; |
1762 } | 1753 } |
1763 memmove(and+np+1, and+np, n-np); | 1754 memmove(and+np+1, and+np, n-np); |
1764 and[np] = 0x40 | rexflag; | 1755 and[np] = 0x40 | rexflag; |
1765 andptr++; | 1756 andptr++; |
1766 } | 1757 } |
1767 } | 1758 } |
OLD | NEW |