2015-09-10 11:32:49 -04:00
|
|
|
// Inferno utils/5l/asm.c
|
2020-06-03 13:17:17 +02:00
|
|
|
// https://bitbucket.org/inferno-os/inferno-os/src/master/utils/5l/asm.c
|
2015-09-10 11:32:49 -04:00
|
|
|
//
|
|
|
|
|
// 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
|
2016-04-10 14:32:26 -07:00
|
|
|
// Portions Copyright © 2009 The Go Authors. All rights reserved.
|
2015-09-10 11:32:49 -04:00
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
package mips64
|
|
|
|
|
|
|
|
|
|
import (
|
2017-04-18 12:53:25 -07:00
|
|
|
"cmd/internal/objabi"
|
2016-04-06 12:01:40 -07:00
|
|
|
"cmd/internal/sys"
|
2015-09-10 11:32:49 -04:00
|
|
|
"cmd/link/internal/ld"
|
2020-03-11 12:12:41 -04:00
|
|
|
"cmd/link/internal/loader"
|
2017-10-04 17:54:04 -04:00
|
|
|
"cmd/link/internal/sym"
|
2017-10-06 16:01:02 -04:00
|
|
|
"debug/elf"
|
2015-09-10 11:32:49 -04:00
|
|
|
)
|
|
|
|
|
|
2020-05-15 18:35:05 -04:00
|
|
|
func gentext(ctxt *ld.Link, ldr *loader.Loader) {}
|
2015-09-10 11:32:49 -04:00
|
|
|
|
2020-06-26 19:17:33 -04:00
|
|
|
func elfreloc1(ctxt *ld.Link, out *ld.OutBuf, ldr *loader.Loader, s loader.Sym, r loader.ExtRelocView, sectoff int64) bool {
|
2020-05-11 16:00:13 -04:00
|
|
|
|
2016-04-27 22:18:09 -04:00
|
|
|
// mips64 ELF relocation (endian neutral)
|
|
|
|
|
// offset uint64
|
|
|
|
|
// sym uint32
|
|
|
|
|
// ssym uint8
|
|
|
|
|
// type3 uint8
|
|
|
|
|
// type2 uint8
|
|
|
|
|
// type uint8
|
|
|
|
|
// addend int64
|
|
|
|
|
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write64(uint64(sectoff))
|
2016-04-27 22:18:09 -04:00
|
|
|
|
2020-05-15 18:35:05 -04:00
|
|
|
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write32(uint32(elfsym))
|
|
|
|
|
out.Write8(0)
|
|
|
|
|
out.Write8(0)
|
|
|
|
|
out.Write8(0)
|
2020-05-11 16:00:13 -04:00
|
|
|
switch r.Type() {
|
2016-04-27 22:18:09 -04:00
|
|
|
default:
|
2017-08-27 22:00:00 +09:00
|
|
|
return false
|
2020-04-29 22:00:28 -04:00
|
|
|
case objabi.R_ADDR, objabi.R_DWARFSECREF:
|
2020-05-11 16:00:13 -04:00
|
|
|
switch r.Siz() {
|
2016-04-27 22:18:09 -04:00
|
|
|
case 4:
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write8(uint8(elf.R_MIPS_32))
|
2016-04-27 22:18:09 -04:00
|
|
|
case 8:
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write8(uint8(elf.R_MIPS_64))
|
2016-04-27 22:18:09 -04:00
|
|
|
default:
|
2017-08-27 22:00:00 +09:00
|
|
|
return false
|
2016-04-27 22:18:09 -04:00
|
|
|
}
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_ADDRMIPS:
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write8(uint8(elf.R_MIPS_LO16))
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_ADDRMIPSU:
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write8(uint8(elf.R_MIPS_HI16))
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_ADDRMIPSTLS:
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write8(uint8(elf.R_MIPS_TLS_TPREL_LO16))
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_CALLMIPS,
|
|
|
|
|
objabi.R_JMPMIPS:
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write8(uint8(elf.R_MIPS_26))
|
2016-04-27 22:18:09 -04:00
|
|
|
}
|
2020-06-26 19:17:33 -04:00
|
|
|
out.Write64(uint64(r.Xadd))
|
2016-04-27 22:18:09 -04:00
|
|
|
|
2017-08-27 22:00:00 +09:00
|
|
|
return true
|
2015-09-10 11:32:49 -04:00
|
|
|
}
|
|
|
|
|
|
2020-03-11 12:12:41 -04:00
|
|
|
func elfsetupplt(ctxt *ld.Link, plt, gotplt *loader.SymbolBuilder, dynamic loader.Sym) {
|
2015-09-10 11:32:49 -04:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 12:33:36 -04:00
|
|
|
func machoreloc1(*sys.Arch, *ld.OutBuf, *loader.Loader, loader.Sym, loader.ExtRelocView, int64) bool {
|
2017-08-27 22:00:00 +09:00
|
|
|
return false
|
2015-09-10 11:32:49 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-08 13:17:51 -04:00
|
|
|
func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loader.Reloc2, rr *loader.ExtReloc, s loader.Sym, val int64) (o int64, needExtReloc bool, ok bool) {
|
2020-04-29 18:41:30 -04:00
|
|
|
rs := r.Sym()
|
|
|
|
|
rs = ldr.ResolveABIAlias(rs)
|
2020-02-24 21:04:50 -05:00
|
|
|
if target.IsExternal() {
|
2020-04-29 18:41:30 -04:00
|
|
|
switch r.Type() {
|
2016-04-27 22:18:09 -04:00
|
|
|
default:
|
2020-04-29 18:41:30 -04:00
|
|
|
return val, false, false
|
|
|
|
|
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_ADDRMIPS,
|
|
|
|
|
objabi.R_ADDRMIPSU:
|
2016-04-27 22:18:09 -04:00
|
|
|
// set up addend for eventual relocation via outer symbol.
|
2020-04-29 18:41:30 -04:00
|
|
|
rs, off := ld.FoldSubSymbolOffset(ldr, rs)
|
|
|
|
|
rr.Xadd = r.Add() + off
|
|
|
|
|
rst := ldr.SymType(rs)
|
|
|
|
|
if rst != sym.SHOSTOBJ && rst != sym.SDYNIMPORT && ldr.SymSect(rs) == nil {
|
|
|
|
|
ldr.Errorf(s, "missing section for %s", ldr.SymName(rs))
|
2016-04-27 22:18:09 -04:00
|
|
|
}
|
2020-04-29 18:41:30 -04:00
|
|
|
rr.Xsym = rs
|
|
|
|
|
return val, true, true
|
2016-04-27 22:18:09 -04:00
|
|
|
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_ADDRMIPSTLS,
|
|
|
|
|
objabi.R_CALLMIPS,
|
|
|
|
|
objabi.R_JMPMIPS:
|
2020-04-29 18:41:30 -04:00
|
|
|
rr.Xsym = rs
|
|
|
|
|
rr.Xadd = r.Add()
|
|
|
|
|
return val, true, true
|
2016-04-27 22:18:09 -04:00
|
|
|
}
|
2015-09-10 11:32:49 -04:00
|
|
|
}
|
|
|
|
|
|
2020-04-29 18:41:30 -04:00
|
|
|
const isOk = true
|
|
|
|
|
const noExtReloc = false
|
|
|
|
|
switch r.Type() {
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_ADDRMIPS,
|
|
|
|
|
objabi.R_ADDRMIPSU:
|
2020-04-29 18:41:30 -04:00
|
|
|
t := ldr.SymValue(rs) + r.Add()
|
|
|
|
|
o1 := target.Arch.ByteOrder.Uint32(ldr.OutData(s)[r.Off():])
|
|
|
|
|
if r.Type() == objabi.R_ADDRMIPS {
|
|
|
|
|
return int64(o1&0xffff0000 | uint32(t)&0xffff), noExtReloc, isOk
|
2015-09-10 11:32:49 -04:00
|
|
|
}
|
2020-04-29 18:41:30 -04:00
|
|
|
return int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff), noExtReloc, isOk
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_ADDRMIPSTLS:
|
2016-04-27 22:18:14 -04:00
|
|
|
// thread pointer is at 0x7000 offset from the start of TLS data area
|
2020-04-29 18:41:30 -04:00
|
|
|
t := ldr.SymValue(rs) + r.Add() - 0x7000
|
2016-04-27 22:18:14 -04:00
|
|
|
if t < -32768 || t >= 32678 {
|
2020-04-29 18:41:30 -04:00
|
|
|
ldr.Errorf(s, "TLS offset out of range %d", t)
|
2016-04-27 22:18:14 -04:00
|
|
|
}
|
2020-04-29 18:41:30 -04:00
|
|
|
o1 := target.Arch.ByteOrder.Uint32(ldr.OutData(s)[r.Off():])
|
|
|
|
|
return int64(o1&0xffff0000 | uint32(t)&0xffff), noExtReloc, isOk
|
2017-04-18 12:53:25 -07:00
|
|
|
case objabi.R_CALLMIPS,
|
|
|
|
|
objabi.R_JMPMIPS:
|
2015-09-10 11:32:49 -04:00
|
|
|
// Low 26 bits = (S + A) >> 2
|
2020-04-29 18:41:30 -04:00
|
|
|
t := ldr.SymValue(rs) + r.Add()
|
|
|
|
|
o1 := target.Arch.ByteOrder.Uint32(ldr.OutData(s)[r.Off():])
|
|
|
|
|
return int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000), noExtReloc, isOk
|
2015-09-10 11:32:49 -04:00
|
|
|
}
|
|
|
|
|
|
2020-04-29 18:41:30 -04:00
|
|
|
return val, false, false
|
2015-09-10 11:32:49 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-08 13:17:51 -04:00
|
|
|
func archrelocvariant(*ld.Target, *loader.Loader, loader.Reloc2, sym.RelocVariant, loader.Sym, int64) int64 {
|
2015-09-10 11:32:49 -04:00
|
|
|
return -1
|
|
|
|
|
}
|