|
| 1 | +// Inferno utils/5l/asm.c |
| 2 | +// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/5l/asm.c |
| 3 | +// |
| 4 | +// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. |
| 5 | +// Portions Copyright © 1995-1997 C H Forsyth ([email protected]) |
| 6 | +// Portions Copyright © 1997-1999 Vita Nuova Limited |
| 7 | +// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) |
| 8 | +// Portions Copyright © 2004,2006 Bruce Ellis |
| 9 | +// Portions Copyright © 2005-2007 C H Forsyth ([email protected]) |
| 10 | +// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others |
| 11 | +// Portions Copyright © 2016 The Go Authors. All rights reserved. |
| 12 | +// |
| 13 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 14 | +// of this software and associated documentation files (the "Software"), to deal |
| 15 | +// in the Software without restriction, including without limitation the rights |
| 16 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 17 | +// copies of the Software, and to permit persons to whom the Software is |
| 18 | +// furnished to do so, subject to the following conditions: |
| 19 | +// |
| 20 | +// The above copyright notice and this permission notice shall be included in |
| 21 | +// all copies or substantial portions of the Software. |
| 22 | +// |
| 23 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 24 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 25 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 26 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 27 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 28 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 29 | +// THE SOFTWARE. |
| 30 | + |
| 31 | +package mips |
| 32 | + |
| 33 | +import ( |
| 34 | + "cmd/internal/obj" |
| 35 | + "cmd/link/internal/ld" |
| 36 | + "fmt" |
| 37 | + "log" |
| 38 | +) |
| 39 | + |
| 40 | +func gentext(ctxt *ld.Link) { |
| 41 | + return |
| 42 | +} |
| 43 | + |
| 44 | +func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool { |
| 45 | + log.Fatalf("adddynrel not implemented") |
| 46 | + return false |
| 47 | +} |
| 48 | + |
| 49 | +func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int { |
| 50 | + return -1 |
| 51 | +} |
| 52 | + |
| 53 | +func elfsetupplt(ctxt *ld.Link) { |
| 54 | + return |
| 55 | +} |
| 56 | + |
| 57 | +func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int { |
| 58 | + return -1 |
| 59 | +} |
| 60 | + |
| 61 | +func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int { |
| 62 | + if ld.Linkmode == ld.LinkExternal { |
| 63 | + return -1 |
| 64 | + } |
| 65 | + |
| 66 | + switch r.Type { |
| 67 | + case obj.R_CONST: |
| 68 | + *val = r.Add |
| 69 | + return 0 |
| 70 | + |
| 71 | + case obj.R_GOTOFF: |
| 72 | + *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) |
| 73 | + return 0 |
| 74 | + |
| 75 | + case obj.R_ADDRMIPS, |
| 76 | + obj.R_ADDRMIPSU: |
| 77 | + t := ld.Symaddr(r.Sym) + r.Add |
| 78 | + o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:]) |
| 79 | + if r.Type == obj.R_ADDRMIPS { |
| 80 | + *val = int64(o1&0xffff0000 | uint32(t)&0xffff) |
| 81 | + } else { |
| 82 | + *val = int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff) |
| 83 | + } |
| 84 | + return 0 |
| 85 | + |
| 86 | + case obj.R_CALLMIPS, |
| 87 | + obj.R_JMPMIPS: |
| 88 | + // Low 26 bits = (S + A) >> 2 |
| 89 | + t := ld.Symaddr(r.Sym) + r.Add |
| 90 | + o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:]) |
| 91 | + *val = int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000) |
| 92 | + return 0 |
| 93 | + } |
| 94 | + |
| 95 | + return -1 |
| 96 | +} |
| 97 | + |
| 98 | +func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 { |
| 99 | + return -1 |
| 100 | +} |
| 101 | + |
| 102 | +func asmb(ctxt *ld.Link) { |
| 103 | + if ctxt.Debugvlog != 0 { |
| 104 | + ctxt.Logf("%5.2f asmb\n", obj.Cputime()) |
| 105 | + } |
| 106 | + |
| 107 | + if ld.Iself { |
| 108 | + ld.Asmbelfsetup() |
| 109 | + } |
| 110 | + |
| 111 | + sect := ld.Segtext.Sect |
| 112 | + ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) |
| 113 | + ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) |
| 114 | + for sect = sect.Next; sect != nil; sect = sect.Next { |
| 115 | + ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff)) |
| 116 | + ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length)) |
| 117 | + } |
| 118 | + |
| 119 | + if ld.Segrodata.Filelen > 0 { |
| 120 | + if ctxt.Debugvlog != 0 { |
| 121 | + ctxt.Logf("%5.2f rodatblk\n", obj.Cputime()) |
| 122 | + } |
| 123 | + |
| 124 | + ld.Cseek(int64(ld.Segrodata.Fileoff)) |
| 125 | + ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen)) |
| 126 | + } |
| 127 | + |
| 128 | + if ctxt.Debugvlog != 0 { |
| 129 | + ctxt.Logf("%5.2f datblk\n", obj.Cputime()) |
| 130 | + } |
| 131 | + |
| 132 | + ld.Cseek(int64(ld.Segdata.Fileoff)) |
| 133 | + ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen)) |
| 134 | + |
| 135 | + ld.Cseek(int64(ld.Segdwarf.Fileoff)) |
| 136 | + ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen)) |
| 137 | + |
| 138 | + /* output symbol table */ |
| 139 | + ld.Symsize = 0 |
| 140 | + |
| 141 | + ld.Lcsize = 0 |
| 142 | + symo := uint32(0) |
| 143 | + if !*ld.FlagS { |
| 144 | + if !ld.Iself { |
| 145 | + ld.Errorf(nil, "unsupported executable format") |
| 146 | + } |
| 147 | + if ctxt.Debugvlog != 0 { |
| 148 | + ctxt.Logf("%5.2f sym\n", obj.Cputime()) |
| 149 | + } |
| 150 | + symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen) |
| 151 | + symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound))) |
| 152 | + |
| 153 | + ld.Cseek(int64(symo)) |
| 154 | + if ctxt.Debugvlog != 0 { |
| 155 | + ctxt.Logf("%5.2f elfsym\n", obj.Cputime()) |
| 156 | + } |
| 157 | + ld.Asmelfsym(ctxt) |
| 158 | + ld.Cflush() |
| 159 | + ld.Cwrite(ld.Elfstrdat) |
| 160 | + |
| 161 | + if ctxt.Debugvlog != 0 { |
| 162 | + ctxt.Logf("%5.2f dwarf\n", obj.Cputime()) |
| 163 | + } |
| 164 | + |
| 165 | + if ld.Linkmode == ld.LinkExternal { |
| 166 | + ld.Elfemitreloc(ctxt) |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + if ctxt.Debugvlog != 0 { |
| 171 | + ctxt.Logf("%5.2f header\n", obj.Cputime()) |
| 172 | + } |
| 173 | + |
| 174 | + ld.Cseek(0) |
| 175 | + switch ld.Headtype { |
| 176 | + default: |
| 177 | + ld.Errorf(nil, "unsupported operating system") |
| 178 | + case obj.Hlinux: |
| 179 | + ld.Asmbelf(ctxt, int64(symo)) |
| 180 | + } |
| 181 | + |
| 182 | + ld.Cflush() |
| 183 | + if *ld.FlagC { |
| 184 | + fmt.Printf("textsize=%d\n", ld.Segtext.Filelen) |
| 185 | + fmt.Printf("datsize=%d\n", ld.Segdata.Filelen) |
| 186 | + fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen) |
| 187 | + fmt.Printf("symsize=%d\n", ld.Symsize) |
| 188 | + fmt.Printf("lcsize=%d\n", ld.Lcsize) |
| 189 | + fmt.Printf("total=%d\n", ld.Segtext.Filelen+ld.Segdata.Length+uint64(ld.Symsize)+uint64(ld.Lcsize)) |
| 190 | + } |
| 191 | +} |
0 commit comments