summaryrefslogtreecommitdiff
path: root/src/cmd/9l
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/9l')
-rw-r--r--src/cmd/9l/9.out.h516
-rw-r--r--src/cmd/9l/Makefile5
-rw-r--r--src/cmd/9l/asm.c342
-rw-r--r--src/cmd/9l/doc.go16
-rw-r--r--src/cmd/9l/l.h100
-rw-r--r--src/cmd/9l/list.c40
-rw-r--r--src/cmd/9l/obj.c108
7 files changed, 1127 insertions, 0 deletions
diff --git a/src/cmd/9l/9.out.h b/src/cmd/9l/9.out.h
new file mode 100644
index 000000000..87917f88a
--- /dev/null
+++ b/src/cmd/9l/9.out.h
@@ -0,0 +1,516 @@
+// cmd/9c/9.out.h from Vita Nuova.
+//
+// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+// Portions Copyright © 1997-1999 Vita Nuova Limited
+// Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com)
+// Portions Copyright © 2004,2006 Bruce Ellis
+// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+// Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others
+// Portions Copyright © 2009 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+/*
+ * powerpc 64
+ */
+#define NSNAME 8
+#define NSYM 50
+#define NREG 32 /* number of general registers */
+#define NFREG 32 /* number of floating point registers */
+
+#include "../ld/textflag.h"
+
+enum
+{
+ REGZERO = 0, /* set to zero */
+ REGSP = 1,
+ REGSB = 2,
+ REGRET = 3,
+ REGARG = -1, /* -1 disables passing the first argument in register */
+ REGRT1 = 3, /* reserved for runtime, duffzero and duffcopy */
+ REGRT2 = 4, /* reserved for runtime, duffcopy */
+ REGMIN = 7, /* register variables allocated from here to REGMAX */
+ REGENV = 11, /* environment for closures */
+ REGMAX = 27,
+ REGEXT = 30, /* external registers allocated from here down */
+ REGG = 30, /* G */
+ REGTMP = 31, /* used by the linker */
+
+ FREGRET = 0,
+ FREGMIN = 17, /* first register variable */
+ FREGMAX = 26, /* last register variable for 9g only */
+ FREGEXT = 26, /* first external register */
+ FREGCVI = 27, /* floating conversion constant */
+ FREGZERO = 28, /* both float and double */
+ FREGHALF = 29, /* double */
+ FREGONE = 30, /* double */
+ FREGTWO = 31 /* double */
+/*
+ * GENERAL:
+ *
+ * compiler allocates R3 up as temps
+ * compiler allocates register variables R7-R27
+ * compiler allocates external registers R30 down
+ *
+ * compiler allocates register variables F17-F26
+ * compiler allocates external registers F26 down
+ */
+};
+
+enum {
+ BIG = 32768-8,
+};
+
+enum {
+/* mark flags */
+ LABEL = 1<<0,
+ LEAF = 1<<1,
+ FLOAT = 1<<2,
+ BRANCH = 1<<3,
+ LOAD = 1<<4,
+ FCMP = 1<<5,
+ SYNC = 1<<6,
+ LIST = 1<<7,
+ FOLL = 1<<8,
+ NOSCHED = 1<<9,
+};
+
+enum
+{
+ C_NONE,
+ C_REG,
+ C_FREG,
+ C_CREG,
+ C_SPR, /* special processor register */
+ C_ZCON,
+ C_SCON, /* 16 bit signed */
+ C_UCON, /* low 16 bits 0 */
+ C_ADDCON, /* -0x8000 <= v < 0 */
+ C_ANDCON, /* 0 < v <= 0xFFFF */
+ C_LCON, /* other 32 */
+ C_DCON, /* other 64 (could subdivide further) */
+ C_SACON,
+ C_SECON,
+ C_LACON,
+ C_LECON,
+ C_SBRA,
+ C_LBRA,
+ C_SAUTO,
+ C_LAUTO,
+ C_SEXT,
+ C_LEXT,
+ C_ZOREG,
+ C_SOREG,
+ C_LOREG,
+ C_FPSCR,
+ C_MSR,
+ C_XER,
+ C_LR,
+ C_CTR,
+ C_ANY,
+ C_GOK,
+ C_ADDR,
+
+ C_NCLASS, /* must be the last */
+};
+
+enum
+{
+ AXXX,
+ AADD,
+ AADDCC,
+ AADDV,
+ AADDVCC,
+ AADDC,
+ AADDCCC,
+ AADDCV,
+ AADDCVCC,
+ AADDME,
+ AADDMECC,
+ AADDMEVCC,
+ AADDMEV,
+ AADDE,
+ AADDECC,
+ AADDEVCC,
+ AADDEV,
+ AADDZE,
+ AADDZECC,
+ AADDZEVCC,
+ AADDZEV,
+ AAND,
+ AANDCC,
+ AANDN,
+ AANDNCC,
+ ABC,
+ ABCL,
+ ABEQ,
+ ABGE,
+ ABGT,
+ ABL,
+ ABLE,
+ ABLT,
+ ABNE,
+ ABR,
+ ABVC,
+ ABVS,
+ ACMP,
+ ACMPU,
+ ACNTLZW,
+ ACNTLZWCC,
+ ACRAND,
+ ACRANDN,
+ ACREQV,
+ ACRNAND,
+ ACRNOR,
+ ACROR,
+ ACRORN,
+ ACRXOR,
+ ADIVW,
+ ADIVWCC,
+ ADIVWVCC,
+ ADIVWV,
+ ADIVWU,
+ ADIVWUCC,
+ ADIVWUVCC,
+ ADIVWUV,
+ AEQV,
+ AEQVCC,
+ AEXTSB,
+ AEXTSBCC,
+ AEXTSH,
+ AEXTSHCC,
+ AFABS,
+ AFABSCC,
+ AFADD,
+ AFADDCC,
+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+ AMOVDU,
+ AMOVWZ,
+ AMOVWZU,
+ AMULHD,
+ AMULHDCC,
+ AMULHDU,
+ AMULHDUCC,
+ AMULLD,
+ AMULLDCC,
+ AMULLDVCC,
+ AMULLDV,
+ ARFID,
+ ARLDMI,
+ ARLDMICC,
+ ARLDC,
+ ARLDCCC,
+ ARLDCR,
+ ARLDCRCC,
+ ARLDCL,
+ ARLDCLCC,
+ ASLBIA,
+ ASLBIE,
+ ASLBMFEE,
+ ASLBMFEV,
+ ASLBMTE,
+ ASLD,
+ ASLDCC,
+ ASRD,
+ ASRAD,
+ ASRADCC,
+ ASRDCC,
+ ASTDCCC,
+ ATD,
+
+ /* 64-bit pseudo operation */
+ ADWORD,
+ AREMD,
+ AREMDCC,
+ AREMDV,
+ AREMDVCC,
+ AREMDU,
+ AREMDUCC,
+ AREMDUV,
+ AREMDUVCC,
+
+ /* more 64-bit operations */
+ AHRFID,
+
+ AUNDEF,
+ AUSEFIELD,
+ ATYPE,
+ AFUNCDATA,
+ APCDATA,
+ ACHECKNIL,
+ AVARDEF,
+ AVARKILL,
+ ADUFFCOPY,
+ ADUFFZERO,
+
+ ALAST
+};
+
+/* type/name */
+enum
+{
+ D_GOK = 0,
+ D_NONE,
+
+/* name */
+ D_EXTERN,
+ D_STATIC,
+ D_AUTO,
+ D_PARAM,
+
+/* type */
+ D_BRANCH,
+ D_OREG,
+ D_CONST,
+ D_FCONST,
+ D_SCONST,
+ D_REG,
+ D_FPSCR,
+ D_MSR,
+ D_FREG,
+ D_CREG,
+ D_SPR,
+ D_OPT, /* branch/trap option */
+ D_FILE,
+ D_FILE1,
+ D_DCR, /* device control register */
+ D_DCONST,
+ D_ADDR, // not used, use D_CONST with non-empty sym.
+
+ D_LAST,
+
+/* reg names for 9g OREGISTER */
+ D_R0 = 0, // type is D_REG
+ D_F0 = D_R0+NREG, // type is D_FREG
+
+/* reg names in offset field iff type is D_SPR */
+ D_XER = 1,
+ D_LR = 8,
+ D_CTR = 9
+ /* and many supervisor level registers */
+};
+
+/*
+ * this is the ranlib header
+ */
+#define SYMDEF "__.GOSYMDEF"
diff --git a/src/cmd/9l/Makefile b/src/cmd/9l/Makefile
new file mode 100644
index 000000000..3f528d751
--- /dev/null
+++ b/src/cmd/9l/Makefile
@@ -0,0 +1,5 @@
+# Copyright 2012 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+include ../../Make.dist
diff --git a/src/cmd/9l/asm.c b/src/cmd/9l/asm.c
new file mode 100644
index 000000000..65a36285d
--- /dev/null
+++ b/src/cmd/9l/asm.c
@@ -0,0 +1,342 @@
+// Inferno utils/5l/asm.c
+// http://code.google.com/p/inferno-os/source/browse/utils/5l/asm.c
+//
+// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+// Portions Copyright © 1997-1999 Vita Nuova Limited
+// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
+// Portions Copyright © 2004,2006 Bruce Ellis
+// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
+// Portions Copyright © 2009 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// Writing object files.
+
+#include "l.h"
+#include "../ld/lib.h"
+#include "../ld/elf.h"
+#include "../ld/dwarf.h"
+
+
+char linuxdynld[] = "/lib64/ld64.so.1";
+char freebsddynld[] = "XXX";
+char openbsddynld[] = "XXX";
+char netbsddynld[] = "XXX";
+char dragonflydynld[] = "XXX";
+char solarisdynld[] = "XXX";
+
+static int
+needlib(char *name)
+{
+ char *p;
+ LSym *s;
+
+ if(*name == '\0')
+ return 0;
+
+ /* reuse hash code in symbol table */
+ p = smprint(".dynlib.%s", name);
+ s = linklookup(ctxt, p, 0);
+ free(p);
+ if(s->type == 0) {
+ s->type = 100; // avoid SDATA, etc.
+ return 1;
+ }
+ return 0;
+}
+
+int nelfsym = 1;
+
+void
+adddynrela(LSym *rel, LSym *s, Reloc *r)
+{
+ // TODO(minux)
+ USED(rel); USED(s); USED(r);
+}
+
+void
+adddynrel(LSym *s, Reloc *r)
+{
+ LSym *targ;
+
+ // TODO(minux)
+
+ targ = r->sym;
+ ctxt->cursym = s;
+ diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ->name, r->type, targ->type);
+}
+
+int
+elfreloc1(Reloc *r, vlong sectoff)
+{
+ USED(r); USED(sectoff);
+ // TODO(minux)
+ return -1;
+}
+
+void
+elfsetupplt(void)
+{
+ // TODO(minux)
+ return;
+}
+
+int
+machoreloc1(Reloc *r, vlong sectoff)
+{
+ USED(r);
+ USED(sectoff);
+
+ return -1;
+}
+
+
+int
+archreloc(Reloc *r, LSym *s, vlong *val)
+{
+ uint32 o1, o2;
+ int32 t;
+
+ if(linkmode == LinkExternal) {
+ // TODO(minux): translate R_ADDRPOWER and R_CALLPOWER into standard ELF relocations.
+ // R_ADDRPOWER corresponds to R_PPC_ADDR16_HA and R_PPC_ADDR16_LO.
+ // R_CALLPOWER corresponds to R_PPC_REL24.
+ return -1;
+ }
+ switch(r->type) {
+ case R_CONST:
+ *val = r->add;
+ return 0;
+ case R_GOTOFF:
+ *val = symaddr(r->sym) + r->add - symaddr(linklookup(ctxt, ".got", 0));
+ return 0;
+ case R_ADDRPOWER:
+ // r->add is two power64 instructions holding an immediate 32-bit constant.
+ // We want to add r->sym's address to that constant.
+ // The encoding of the immediate x<<16 + y,
+ // where x is the low 16 bits of the first instruction and y is the low 16
+ // bits of the second. Both x and y are signed (int16, not uint16).
+ o1 = r->add >> 32;
+ o2 = r->add;
+ t = symaddr(r->sym);
+ if(t < 0) {
+ ctxt->diag("relocation for %s is too big (>=2G): %lld", s->name, symaddr(r->sym));
+ }
+ t += ((o1 & 0xffff) << 16) + ((int32)o2 << 16 >> 16);
+ if(t & 0x8000)
+ t += 0x10000;
+ o1 = (o1 & 0xffff0000) | ((t >> 16) & 0xffff);
+ o2 = (o2 & 0xffff0000) | (t & 0xffff);
+ // when laid out, the instruction order must always be o1, o2.
+ if(ctxt->arch->endian == BigEndian)
+ *val = ((vlong)o1 << 32) | o2;
+ else
+ *val = ((vlong)o2 << 32) | o1;
+ return 0;
+ case R_CALLPOWER:
+ // Bits 6 through 29 = (S + A - P) >> 2
+ if(ctxt->arch->endian == BigEndian)
+ o1 = be32(s->p + r->off);
+ else
+ o1 = le32(s->p + r->off);
+
+ t = symaddr(r->sym) + r->add - (s->value + r->off);
+ if(t & 3)
+ ctxt->diag("relocation for %s is not aligned: %lld", s->name, t);
+ if(t << 6 >> 6 != t)
+ ctxt->diag("relocation for %s is too big: %lld", s->name, t);
+
+ *val = (o1 & 0xfc000003U) | (t & ~0xfc000003U);
+ return 0;
+ }
+ return -1;
+}
+
+void
+adddynsym(Link *ctxt, LSym *s)
+{
+ USED(ctxt); USED(s);
+ // TODO(minux)
+ return;
+}
+
+void
+adddynlib(char *lib)
+{
+ LSym *s;
+
+ if(!needlib(lib))
+ return;
+
+ if(iself) {
+ s = linklookup(ctxt, ".dynstr", 0);
+ if(s->size == 0)
+ addstring(s, "");
+ elfwritedynent(linklookup(ctxt, ".dynamic", 0), DT_NEEDED, addstring(s, lib));
+ } else {
+ diag("adddynlib: unsupported binary format");
+ }
+}
+
+void
+asmb(void)
+{
+ uint32 symo;
+ Section *sect;
+ LSym *sym;
+ int i;
+
+ if(debug['v'])
+ Bprint(&bso, "%5.2f asmb\n", cputime());
+ Bflush(&bso);
+
+ if(iself)
+ asmbelfsetup();
+
+ sect = segtext.sect;
+ cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
+ codeblk(sect->vaddr, sect->len);
+ for(sect = sect->next; sect != nil; sect = sect->next) {
+ cseek(sect->vaddr - segtext.vaddr + segtext.fileoff);
+ datblk(sect->vaddr, sect->len);
+ }
+
+ if(segrodata.filelen > 0) {
+ if(debug['v'])
+ Bprint(&bso, "%5.2f rodatblk\n", cputime());
+ Bflush(&bso);
+
+ cseek(segrodata.fileoff);
+ datblk(segrodata.vaddr, segrodata.filelen);
+ }
+
+ if(debug['v'])
+ Bprint(&bso, "%5.2f datblk\n", cputime());
+ Bflush(&bso);
+
+ cseek(segdata.fileoff);
+ datblk(segdata.vaddr, segdata.filelen);
+
+ /* output symbol table */
+ symsize = 0;
+ lcsize = 0;
+ symo = 0;
+ if(!debug['s']) {
+ // TODO: rationalize
+ if(debug['v'])
+ Bprint(&bso, "%5.2f sym\n", cputime());
+ Bflush(&bso);
+ switch(HEADTYPE) {
+ default:
+ if(iself)
+ goto ElfSym;
+ case Hplan9:
+ symo = segdata.fileoff+segdata.filelen;
+ break;
+ ElfSym:
+ symo = segdata.fileoff+segdata.filelen;
+ symo = rnd(symo, INITRND);
+ break;
+ }
+ cseek(symo);
+ switch(HEADTYPE) {
+ default:
+ if(iself) {
+ if(debug['v'])
+ Bprint(&bso, "%5.2f elfsym\n", cputime());
+ asmelfsym();
+ cflush();
+ cwrite(elfstrdat, elfstrsize);
+
+ if(debug['v'])
+ Bprint(&bso, "%5.2f dwarf\n", cputime());
+ dwarfemitdebugsections();
+
+ if(linkmode == LinkExternal)
+ elfemitreloc();
+ }
+ break;
+ case Hplan9:
+ asmplan9sym();
+ cflush();
+
+ sym = linklookup(ctxt, "pclntab", 0);
+ if(sym != nil) {
+ lcsize = sym->np;
+ for(i=0; i < lcsize; i++)
+ cput(sym->p[i]);
+
+ cflush();
+ }
+ break;
+ }
+ }
+
+ ctxt->cursym = nil;
+ if(debug['v'])
+ Bprint(&bso, "%5.2f header\n", cputime());
+ Bflush(&bso);
+ cseek(0L);
+ switch(HEADTYPE) {
+ default:
+ case Hplan9: /* plan 9 */
+ LPUT(0x647); /* magic */
+ LPUT(segtext.filelen); /* sizes */
+ LPUT(segdata.filelen);
+ LPUT(segdata.len - segdata.filelen);
+ LPUT(symsize); /* nsyms */
+ LPUT(entryvalue()); /* va of entry */
+ LPUT(0L);
+ LPUT(lcsize);
+ break;
+ case Hlinux:
+ case Hfreebsd:
+ case Hnetbsd:
+ case Hopenbsd:
+ case Hnacl:
+ asmbelf(symo);
+ break;
+ }
+ cflush();
+ if(debug['c']){
+ print("textsize=%ulld\n", segtext.filelen);
+ print("datsize=%ulld\n", segdata.filelen);
+ print("bsssize=%ulld\n", segdata.len - segdata.filelen);
+ print("symsize=%d\n", symsize);
+ print("lcsize=%d\n", lcsize);
+ print("total=%lld\n", segtext.filelen+segdata.len+symsize+lcsize);
+ }
+}
+
+vlong
+rnd(vlong v, int32 r)
+{
+ vlong c;
+
+ if(r <= 0)
+ return v;
+ v += r - 1;
+ c = v % r;
+ if(c < 0)
+ c += r;
+ v -= c;
+ return v;
+}
diff --git a/src/cmd/9l/doc.go b/src/cmd/9l/doc.go
new file mode 100644
index 000000000..9df5dc614
--- /dev/null
+++ b/src/cmd/9l/doc.go
@@ -0,0 +1,16 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ignore
+
+/*
+
+9l is the linker for the Power64.
+The $GOARCH for these tools is power64 (big endian) or
+power64le (little endian).
+
+The flags are documented in ../ld/doc.go.
+
+*/
+package main
diff --git a/src/cmd/9l/l.h b/src/cmd/9l/l.h
new file mode 100644
index 000000000..dda741c56
--- /dev/null
+++ b/src/cmd/9l/l.h
@@ -0,0 +1,100 @@
+// cmd/9l/l.h from Vita Nuova.
+//
+// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+// Portions Copyright © 1997-1999 Vita Nuova Limited
+// Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com)
+// Portions Copyright © 2004,2006 Bruce Ellis
+// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+// Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others
+// Portions Copyright © 2009 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include <link.h>
+#include "9.out.h"
+
+#ifndef EXTERN
+#define EXTERN extern
+#endif
+
+enum
+{
+ thechar = '9',
+ PtrSize = 8,
+ IntSize = 8,
+ RegSize = 8,
+ MaxAlign = 32, // max data alignment
+ FuncAlign = 8
+};
+
+#define P ((Prog*)0)
+#define S ((LSym*)0)
+
+enum
+{
+ FPCHIP = 1,
+ STRINGSZ = 200,
+ MAXHIST = 20, /* limit of path elements for history symbols */
+ DATBLK = 1024,
+ NHASH = 10007,
+ NHUNK = 100000,
+ MINSIZ = 64,
+ NENT = 100,
+ NSCHED = 20,
+ MINLC = 4,
+
+ Roffset = 22, /* no. bits for offset in relocation address */
+ Rindex = 10 /* no. bits for index in relocation address */
+};
+
+EXTERN int32 autosize;
+EXTERN LSym* datap;
+EXTERN int debug[128];
+EXTERN int32 lcsize;
+EXTERN char literal[32];
+EXTERN int nerrors;
+EXTERN vlong instoffset;
+EXTERN char* rpath;
+EXTERN vlong pc;
+EXTERN int32 symsize;
+EXTERN int32 staticgen;
+EXTERN Prog* lastp;
+EXTERN vlong textsize;
+
+void asmb(void);
+void adddynlib(char *lib);
+void adddynrel(LSym *s, Reloc *r);
+void adddynsym(Link *ctxt, LSym *s);
+int archreloc(Reloc *r, LSym *s, vlong *val);
+void listinit(void);
+vlong rnd(vlong, int32);
+
+#define LPUT(a) (ctxt->arch->endian == BigEndian ? lputb(a):lputl(a))
+#define WPUT(a) (ctxt->arch->endian == BigEndian ? wputb(a):wputl(a))
+#define VPUT(a) (ctxt->arch->endian == BigEndian ? vputb(a):vputl(a))
+
+/* Used by ../ld/dwarf.c */
+enum
+{
+ DWARFREGSP = 1
+};
diff --git a/src/cmd/9l/list.c b/src/cmd/9l/list.c
new file mode 100644
index 000000000..af8dc1588
--- /dev/null
+++ b/src/cmd/9l/list.c
@@ -0,0 +1,40 @@
+// Inferno utils/5l/list.h
+// http://code.google.com/p/inferno-os/source/browse/utils/5l/list.c
+//
+// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+// Portions Copyright © 1997-1999 Vita Nuova Limited
+// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
+// Portions Copyright © 2004,2006 Bruce Ellis
+// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
+// Portions Copyright © 2009 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// Printing.
+
+#include "l.h"
+#include "../ld/lib.h"
+
+void
+listinit(void)
+{
+ listinit9();
+}
diff --git a/src/cmd/9l/obj.c b/src/cmd/9l/obj.c
new file mode 100644
index 000000000..badb72a1a
--- /dev/null
+++ b/src/cmd/9l/obj.c
@@ -0,0 +1,108 @@
+// Inferno utils/5l/obj.c
+// http://code.google.com/p/inferno-os/source/browse/utils/5l/obj.c
+//
+// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+// Portions Copyright © 1997-1999 Vita Nuova Limited
+// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
+// Portions Copyright © 2004,2006 Bruce Ellis
+// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
+// Portions Copyright © 2009 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+// Reading object files.
+
+#include "l.h"
+#include "../ld/lib.h"
+#include "../ld/elf.h"
+#include "../ld/dwarf.h"
+#include <ar.h>
+
+char *thestring = "power64";
+LinkArch *thelinkarch;
+
+void
+linkarchinit(void)
+{
+ thestring = getgoarch();
+ if(strcmp(thestring, "power64le") == 0)
+ thelinkarch = &linkpower64le;
+ else
+ thelinkarch = &linkpower64;
+}
+
+void
+archinit(void)
+{
+ // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when
+ // Go was built; see ../../make.bash.
+ if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0)
+ linkmode = LinkInternal;
+
+ switch(HEADTYPE) {
+ default:
+ if(linkmode == LinkAuto)
+ linkmode = LinkInternal;
+ if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0)
+ sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE));
+ break;
+ }
+
+ switch(HEADTYPE) {
+ default:
+ diag("unknown -H option");
+ errorexit();
+ case Hplan9: /* plan 9 */
+ HEADR = 32L;
+ if(INITTEXT == -1)
+ INITTEXT = 4128;
+ if(INITDAT == -1)
+ INITDAT = 0;
+ if(INITRND == -1)
+ INITRND = 4096;
+ break;
+ case Hlinux: /* power64 elf */
+ debug['d'] = 1; // TODO(minux): dynamic linking is not supported yet.
+ elfinit();
+ HEADR = ELFRESERVE;
+ if(INITTEXT == -1)
+ INITTEXT = 0x10000 + HEADR;
+ if(INITDAT == -1)
+ INITDAT = 0;
+ if(INITRND == -1)
+ INITRND = 0x10000;
+ break;
+ case Hnacl:
+ elfinit();
+ HEADR = 0x10000;
+ funcalign = 16;
+ if(INITTEXT == -1)
+ INITTEXT = 0x20000;
+ if(INITDAT == -1)
+ INITDAT = 0;
+ if(INITRND == -1)
+ INITRND = 0x10000;
+ break;
+ }
+ if(INITDAT != 0 && INITRND != 0)
+ print("warning: -D0x%ux is ignored because of -R0x%ux\n",
+ INITDAT, INITRND);
+}