2016-03-01 22:57:46 +00:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
2015-01-19 14:34:58 -05:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package obj
|
|
|
|
|
|
|
|
|
|
import (
|
2015-03-05 10:39:23 -08:00
|
|
|
"bytes"
|
2017-04-18 12:53:25 -07:00
|
|
|
"cmd/internal/objabi"
|
2015-01-19 14:34:58 -05:00
|
|
|
"fmt"
|
2015-02-25 09:07:02 -08:00
|
|
|
"strings"
|
2015-01-19 14:34:58 -05:00
|
|
|
)
|
|
|
|
|
|
2015-02-25 09:07:02 -08:00
|
|
|
const REG_NONE = 0
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func (p *Prog) Line() string {
|
2017-03-08 14:26:23 -08:00
|
|
|
return p.Ctxt.OutermostPos(p.Pos).Format(false)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-05 10:39:23 -08:00
|
|
|
var armCondCode = []string{
|
|
|
|
|
".EQ",
|
|
|
|
|
".NE",
|
|
|
|
|
".CS",
|
|
|
|
|
".CC",
|
|
|
|
|
".MI",
|
|
|
|
|
".PL",
|
|
|
|
|
".VS",
|
|
|
|
|
".VC",
|
|
|
|
|
".HI",
|
|
|
|
|
".LS",
|
|
|
|
|
".GE",
|
|
|
|
|
".LT",
|
|
|
|
|
".GT",
|
|
|
|
|
".LE",
|
|
|
|
|
"",
|
|
|
|
|
".NV",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARM scond byte */
|
|
|
|
|
const (
|
|
|
|
|
C_SCOND = (1 << 4) - 1
|
|
|
|
|
C_SBIT = 1 << 4
|
|
|
|
|
C_PBIT = 1 << 5
|
|
|
|
|
C_WBIT = 1 << 6
|
|
|
|
|
C_FBIT = 1 << 7
|
|
|
|
|
C_UBIT = 1 << 7
|
|
|
|
|
C_SCOND_XOR = 14
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CConv formats ARM condition codes.
|
|
|
|
|
func CConv(s uint8) string {
|
|
|
|
|
if s == 0 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
sc := armCondCode[(s&C_SCOND)^C_SCOND_XOR]
|
|
|
|
|
if s&C_SBIT != 0 {
|
|
|
|
|
sc += ".S"
|
|
|
|
|
}
|
|
|
|
|
if s&C_PBIT != 0 {
|
|
|
|
|
sc += ".P"
|
|
|
|
|
}
|
|
|
|
|
if s&C_WBIT != 0 {
|
|
|
|
|
sc += ".W"
|
|
|
|
|
}
|
|
|
|
|
if s&C_UBIT != 0 { /* ambiguous with FBIT */
|
|
|
|
|
sc += ".U"
|
|
|
|
|
}
|
|
|
|
|
return sc
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func (p *Prog) String() string {
|
2016-02-25 10:44:31 -08:00
|
|
|
if p == nil {
|
|
|
|
|
return "<nil Prog>"
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
if p.Ctxt == nil {
|
2015-02-28 20:31:32 +00:00
|
|
|
return "<Prog without ctxt>"
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
2015-03-05 10:39:23 -08:00
|
|
|
|
|
|
|
|
sc := CConv(p.Scond)
|
|
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
2016-07-18 21:59:14 -07:00
|
|
|
fmt.Fprintf(&buf, "%.5d (%v)\t%v%s", p.Pc, p.Line(), p.As, sc)
|
2015-03-05 10:39:23 -08:00
|
|
|
sep := "\t"
|
cmd/internal/obj/x86: add AVX2 instrutions needed for sha1/sha512/sha256 acceleration
This means: VPSHUFB, VPSHUFD, VPERM2F128, VPALIGNR, VPADDQ, VPADDD, VPSRLDQ,
VPSLLDQ, VPSRLQ, VPSLLQ, VPSRLD, VPSLLD, VPOR, VPBLENDD, VINSERTI128,
VPERM2I128, RORXL, RORXQ.
Change-Id: Ief27190ee6acfa86b109262af5d999bc101e923d
Reviewed-on: https://go-review.googlesource.com/22606
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-04-29 16:14:57 +03:00
|
|
|
quadOpAmd64 := p.RegTo2 == -1
|
|
|
|
|
if quadOpAmd64 {
|
|
|
|
|
fmt.Fprintf(&buf, "%s$%d", sep, p.From3.Offset)
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
2015-03-05 10:39:23 -08:00
|
|
|
if p.From.Type != TYPE_NONE {
|
|
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.From))
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
|
|
|
|
if p.Reg != REG_NONE {
|
|
|
|
|
// Should not happen but might as well show it if it does.
|
|
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Rconv(int(p.Reg)))
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
2015-05-27 15:01:44 -04:00
|
|
|
if p.From3Type() != TYPE_NONE {
|
cmd/internal/obj: stop storing Text flags in From3
Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-11 15:15:04 -07:00
|
|
|
if quadOpAmd64 {
|
cmd/internal/obj/x86: add AVX2 instrutions needed for sha1/sha512/sha256 acceleration
This means: VPSHUFB, VPSHUFD, VPERM2F128, VPALIGNR, VPADDQ, VPADDD, VPSRLDQ,
VPSLLDQ, VPSRLQ, VPSLLQ, VPSRLD, VPSLLD, VPOR, VPBLENDD, VINSERTI128,
VPERM2I128, RORXL, RORXQ.
Change-Id: Ief27190ee6acfa86b109262af5d999bc101e923d
Reviewed-on: https://go-review.googlesource.com/22606
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-04-29 16:14:57 +03:00
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Rconv(int(p.From3.Reg)))
|
2015-03-05 10:39:23 -08:00
|
|
|
} else {
|
2015-05-27 15:01:44 -04:00
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, p.From3))
|
2015-03-05 10:39:23 -08:00
|
|
|
}
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
cmd/internal/obj: stop storing Text flags in From3
Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-11 15:15:04 -07:00
|
|
|
if p.As == ATEXT {
|
|
|
|
|
// If there are attributes, print them. Otherwise, skip the comma.
|
|
|
|
|
// In short, print one of these two:
|
|
|
|
|
// TEXT foo(SB), DUPOK|NOSPLIT, $0
|
|
|
|
|
// TEXT foo(SB), $0
|
|
|
|
|
s := p.From.Sym.Attribute.TextAttrString()
|
|
|
|
|
if s != "" {
|
|
|
|
|
fmt.Fprintf(&buf, "%s%s", sep, s)
|
|
|
|
|
sep = ", "
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-05 10:39:23 -08:00
|
|
|
if p.To.Type != TYPE_NONE {
|
|
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Dconv(p, &p.To))
|
|
|
|
|
}
|
cmd/internal/obj/x86: add AVX2 instrutions needed for sha1/sha512/sha256 acceleration
This means: VPSHUFB, VPSHUFD, VPERM2F128, VPALIGNR, VPADDQ, VPADDD, VPSRLDQ,
VPSLLDQ, VPSRLQ, VPSLLQ, VPSRLD, VPSLLD, VPOR, VPBLENDD, VINSERTI128,
VPERM2I128, RORXL, RORXQ.
Change-Id: Ief27190ee6acfa86b109262af5d999bc101e923d
Reviewed-on: https://go-review.googlesource.com/22606
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-04-29 16:14:57 +03:00
|
|
|
if p.RegTo2 != REG_NONE && !quadOpAmd64 {
|
2015-05-21 17:51:34 -04:00
|
|
|
fmt.Fprintf(&buf, "%s%v", sep, Rconv(int(p.RegTo2)))
|
cmd/internal/obj, cmd/internal/obj/arm64: add support for GOARCH=arm64
ARM64 (ARMv8) has 32 general purpose, 64-bit integer registers
(R0-R31), 32 64-bit scalar floating point registers (F0-F31), and
32 128-bit vector registers (unused, V0-V31).
R31 is either the stack pointer (RSP), or the zero register (ZR),
depending on the instruction. Note the distinction between the
hardware stack pointer, RSP, and the virtual stack pointer SP.
The (hardware) stack pointer must be 16-byte aligned at all times;
the RSP register itself must be aligned, offset(RSP) only has to
have natural alignment.
Instructions are fixed-width, and are 32-bit wide. ARM64 supports
ARMv7 too (32-bit ARM), but not in the same process. In general,
there is not much in common between 32-bit ARM and ARM64, it's a
new architecture.
All implementations have floating point instructions.
This change adds a Prog.To3 field analogous to Prog.To. It is used
by exclusive load/store instructions such as STLXR which read from
one register, and write to both a register and a memory address.
STLXRW R1, (R0), R3
This will store the word contained in R1 to the memory address
pointed by R0. R3 will be updated with the status result of the
store. It is used to implement atomic operations.
No other changes are made to the portable Prog and Addr structures.
Change-Id: Ie839029aa5265bbad35769d9689eca11e1c48c47
Reviewed-on: https://go-review.googlesource.com/7046
Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-08 13:58:16 +01:00
|
|
|
}
|
2015-03-05 10:39:23 -08:00
|
|
|
return buf.String()
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
2015-01-21 21:45:29 -05:00
|
|
|
|
|
|
|
|
func (ctxt *Link) NewProg() *Prog {
|
2017-04-05 07:05:35 -07:00
|
|
|
p := new(Prog)
|
2015-01-21 21:45:29 -05:00
|
|
|
p.Ctxt = ctxt
|
|
|
|
|
return p
|
|
|
|
|
}
|
2017-04-05 07:05:35 -07:00
|
|
|
|
|
|
|
|
func (ctxt *Link) CanReuseProgs() bool {
|
|
|
|
|
return !ctxt.Debugasm
|
2016-02-24 09:53:27 -08:00
|
|
|
}
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
|
2015-02-25 09:07:02 -08:00
|
|
|
func (ctxt *Link) Dconv(a *Addr) string {
|
2015-02-26 17:09:16 -08:00
|
|
|
return Dconv(nil, a)
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 17:09:16 -08:00
|
|
|
func Dconv(p *Prog, a *Addr) string {
|
2015-02-25 09:07:02 -08:00
|
|
|
var str string
|
|
|
|
|
|
|
|
|
|
switch a.Type {
|
|
|
|
|
default:
|
|
|
|
|
str = fmt.Sprintf("type=%d", a.Type)
|
|
|
|
|
|
|
|
|
|
case TYPE_NONE:
|
|
|
|
|
str = ""
|
|
|
|
|
if a.Name != NAME_NONE || a.Reg != 0 || a.Sym != nil {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("%v(%v)(NONE)", Mconv(a), Rconv(int(a.Reg)))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_REG:
|
|
|
|
|
// TODO(rsc): This special case is for x86 instructions like
|
|
|
|
|
// PINSRQ CX,$1,X6
|
|
|
|
|
// where the $1 is included in the p->to Addr.
|
|
|
|
|
// Move into a new field.
|
|
|
|
|
if a.Offset != 0 {
|
|
|
|
|
str = fmt.Sprintf("$%d,%v", a.Offset, Rconv(int(a.Reg)))
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 13:50:46 -07:00
|
|
|
str = Rconv(int(a.Reg))
|
2015-05-14 20:11:28 -07:00
|
|
|
if a.Name != NAME_NONE || a.Sym != nil {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("%v(%v)(REG)", Mconv(a), Rconv(int(a.Reg)))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_BRANCH:
|
|
|
|
|
if a.Sym != nil {
|
|
|
|
|
str = fmt.Sprintf("%s(SB)", a.Sym.Name)
|
|
|
|
|
} else if p != nil && p.Pcond != nil {
|
2015-04-20 13:50:46 -07:00
|
|
|
str = fmt.Sprint(p.Pcond.Pc)
|
2015-03-16 15:54:44 -04:00
|
|
|
} else if a.Val != nil {
|
2015-04-20 13:50:46 -07:00
|
|
|
str = fmt.Sprint(a.Val.(*Prog).Pc)
|
2015-02-25 09:07:02 -08:00
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("%d(PC)", a.Offset)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 10:58:48 -08:00
|
|
|
case TYPE_INDIR:
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("*%s", Mconv(a))
|
2015-02-26 10:58:48 -08:00
|
|
|
|
2015-02-25 09:07:02 -08:00
|
|
|
case TYPE_MEM:
|
2015-02-26 17:09:16 -08:00
|
|
|
str = Mconv(a)
|
2015-02-25 09:07:02 -08:00
|
|
|
if a.Index != REG_NONE {
|
|
|
|
|
str += fmt.Sprintf("(%v*%d)", Rconv(int(a.Index)), int(a.Scale))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_CONST:
|
|
|
|
|
if a.Reg != 0 {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("$%v(%v)", Mconv(a), Rconv(int(a.Reg)))
|
2015-02-25 09:07:02 -08:00
|
|
|
} else {
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("$%v", Mconv(a))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_TEXTSIZE:
|
2017-04-18 12:53:25 -07:00
|
|
|
if a.Val.(int32) == objabi.ArgsSizeUnknown {
|
2015-02-25 09:07:02 -08:00
|
|
|
str = fmt.Sprintf("$%d", a.Offset)
|
|
|
|
|
} else {
|
2015-03-16 15:54:44 -04:00
|
|
|
str = fmt.Sprintf("$%d-%d", a.Offset, a.Val.(int32))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_FCONST:
|
2015-03-16 15:54:44 -04:00
|
|
|
str = fmt.Sprintf("%.17g", a.Val.(float64))
|
2015-02-25 09:07:02 -08:00
|
|
|
// Make sure 1 prints as 1.0
|
|
|
|
|
if !strings.ContainsAny(str, ".e") {
|
|
|
|
|
str += ".0"
|
|
|
|
|
}
|
|
|
|
|
str = fmt.Sprintf("$(%s)", str)
|
|
|
|
|
|
|
|
|
|
case TYPE_SCONST:
|
2015-03-16 15:54:44 -04:00
|
|
|
str = fmt.Sprintf("$%q", a.Val.(string))
|
2015-02-25 09:07:02 -08:00
|
|
|
|
|
|
|
|
case TYPE_ADDR:
|
2015-02-26 17:09:16 -08:00
|
|
|
str = fmt.Sprintf("$%s", Mconv(a))
|
2015-02-25 09:07:02 -08:00
|
|
|
|
|
|
|
|
case TYPE_SHIFT:
|
|
|
|
|
v := int(a.Offset)
|
2016-08-10 13:24:03 -04:00
|
|
|
ops := "<<>>->@>"
|
2017-04-18 12:53:25 -07:00
|
|
|
switch objabi.GOARCH {
|
2016-08-10 13:24:03 -04:00
|
|
|
case "arm":
|
|
|
|
|
op := ops[((v>>5)&3)<<1:]
|
|
|
|
|
if v&(1<<4) != 0 {
|
|
|
|
|
str = fmt.Sprintf("R%d%c%cR%d", v&15, op[0], op[1], (v>>8)&15)
|
|
|
|
|
} else {
|
|
|
|
|
str = fmt.Sprintf("R%d%c%c%d", v&15, op[0], op[1], (v>>7)&31)
|
|
|
|
|
}
|
|
|
|
|
if a.Reg != 0 {
|
|
|
|
|
str += fmt.Sprintf("(%v)", Rconv(int(a.Reg)))
|
|
|
|
|
}
|
|
|
|
|
case "arm64":
|
|
|
|
|
op := ops[((v>>22)&3)<<1:]
|
|
|
|
|
str = fmt.Sprintf("R%d%c%c%d", (v>>16)&31, op[0], op[1], (v>>10)&63)
|
|
|
|
|
default:
|
2017-04-18 12:53:25 -07:00
|
|
|
panic("TYPE_SHIFT is not supported on " + objabi.GOARCH)
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TYPE_REGREG:
|
|
|
|
|
str = fmt.Sprintf("(%v, %v)", Rconv(int(a.Reg)), Rconv(int(a.Offset)))
|
|
|
|
|
|
|
|
|
|
case TYPE_REGREG2:
|
2017-04-28 10:55:41 +00:00
|
|
|
str = fmt.Sprintf("%v, %v", Rconv(int(a.Offset)), Rconv(int(a.Reg)))
|
2015-02-27 13:50:26 -08:00
|
|
|
|
|
|
|
|
case TYPE_REGLIST:
|
|
|
|
|
str = regListConv(int(a.Offset))
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 17:09:16 -08:00
|
|
|
func Mconv(a *Addr) string {
|
2015-02-25 09:07:02 -08:00
|
|
|
var str string
|
|
|
|
|
|
|
|
|
|
switch a.Name {
|
|
|
|
|
default:
|
|
|
|
|
str = fmt.Sprintf("name=%d", a.Name)
|
|
|
|
|
|
|
|
|
|
case NAME_NONE:
|
|
|
|
|
switch {
|
|
|
|
|
case a.Reg == REG_NONE:
|
2015-04-20 13:50:46 -07:00
|
|
|
str = fmt.Sprint(a.Offset)
|
2015-02-25 09:07:02 -08:00
|
|
|
case a.Offset == 0:
|
|
|
|
|
str = fmt.Sprintf("(%v)", Rconv(int(a.Reg)))
|
|
|
|
|
case a.Offset != 0:
|
|
|
|
|
str = fmt.Sprintf("%d(%v)", a.Offset, Rconv(int(a.Reg)))
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 09:37:22 -08:00
|
|
|
// Note: a.Reg == REG_NONE encodes the default base register for the NAME_ type.
|
2015-02-25 09:07:02 -08:00
|
|
|
case NAME_EXTERN:
|
2017-02-19 09:37:22 -08:00
|
|
|
reg := "SB"
|
|
|
|
|
if a.Reg != REG_NONE {
|
|
|
|
|
reg = Rconv(int(a.Reg))
|
|
|
|
|
}
|
2015-09-15 10:59:27 -07:00
|
|
|
if a.Sym != nil {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
|
2015-09-15 10:59:27 -07:00
|
|
|
} else {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s(%s)", offConv(a.Offset), reg)
|
2015-09-15 10:59:27 -07:00
|
|
|
}
|
2015-02-25 09:07:02 -08:00
|
|
|
|
2015-03-30 00:49:25 +00:00
|
|
|
case NAME_GOTREF:
|
2017-02-19 09:37:22 -08:00
|
|
|
reg := "SB"
|
|
|
|
|
if a.Reg != REG_NONE {
|
|
|
|
|
reg = Rconv(int(a.Reg))
|
|
|
|
|
}
|
2015-09-15 10:59:27 -07:00
|
|
|
if a.Sym != nil {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s%s@GOT(%s)", a.Sym.Name, offConv(a.Offset), reg)
|
2015-09-15 10:59:27 -07:00
|
|
|
} else {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s@GOT(%s)", offConv(a.Offset), reg)
|
2015-09-15 10:59:27 -07:00
|
|
|
}
|
2015-03-30 00:49:25 +00:00
|
|
|
|
2015-02-25 09:07:02 -08:00
|
|
|
case NAME_STATIC:
|
2017-02-19 09:37:22 -08:00
|
|
|
reg := "SB"
|
|
|
|
|
if a.Reg != REG_NONE {
|
|
|
|
|
reg = Rconv(int(a.Reg))
|
|
|
|
|
}
|
2015-09-15 10:59:27 -07:00
|
|
|
if a.Sym != nil {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s<>%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
|
2015-09-15 10:59:27 -07:00
|
|
|
} else {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("<>%s(%s)", offConv(a.Offset), reg)
|
2015-09-15 10:59:27 -07:00
|
|
|
}
|
2015-02-25 09:07:02 -08:00
|
|
|
|
|
|
|
|
case NAME_AUTO:
|
2017-02-19 09:37:22 -08:00
|
|
|
reg := "SP"
|
|
|
|
|
if a.Reg != REG_NONE {
|
|
|
|
|
reg = Rconv(int(a.Reg))
|
|
|
|
|
}
|
2015-02-25 09:07:02 -08:00
|
|
|
if a.Sym != nil {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
|
2015-02-25 09:07:02 -08:00
|
|
|
} else {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s(%s)", offConv(a.Offset), reg)
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case NAME_PARAM:
|
2017-02-19 09:37:22 -08:00
|
|
|
reg := "FP"
|
|
|
|
|
if a.Reg != REG_NONE {
|
|
|
|
|
reg = Rconv(int(a.Reg))
|
|
|
|
|
}
|
2015-02-25 09:07:02 -08:00
|
|
|
if a.Sym != nil {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
|
2015-02-25 09:07:02 -08:00
|
|
|
} else {
|
2017-02-19 09:37:22 -08:00
|
|
|
str = fmt.Sprintf("%s(%s)", offConv(a.Offset), reg)
|
2015-02-25 09:07:02 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func offConv(off int64) string {
|
|
|
|
|
if off == 0 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%+d", off)
|
|
|
|
|
}
|
2015-02-26 17:09:16 -08:00
|
|
|
|
|
|
|
|
type regSet struct {
|
|
|
|
|
lo int
|
|
|
|
|
hi int
|
|
|
|
|
Rconv func(int) string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Few enough architectures that a linear scan is fastest.
|
|
|
|
|
// Not even worth sorting.
|
|
|
|
|
var regSpace []regSet
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Each architecture defines a register space as a unique
|
|
|
|
|
integer range.
|
|
|
|
|
Here is the list of architectures and the base of their register spaces.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// Because of masking operations in the encodings, each register
|
|
|
|
|
// space should start at 0 modulo some power of 2.
|
2016-10-18 23:50:37 +02:00
|
|
|
RBase386 = 1 * 1024
|
|
|
|
|
RBaseAMD64 = 2 * 1024
|
|
|
|
|
RBaseARM = 3 * 1024
|
|
|
|
|
RBasePPC64 = 4 * 1024 // range [4k, 8k)
|
|
|
|
|
RBaseARM64 = 8 * 1024 // range [8k, 13k)
|
|
|
|
|
RBaseMIPS = 13 * 1024 // range [13k, 14k)
|
|
|
|
|
RBaseS390X = 14 * 1024 // range [14k, 15k)
|
2015-02-26 17:09:16 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RegisterRegister binds a pretty-printer (Rconv) for register
|
2016-03-01 23:21:55 +00:00
|
|
|
// numbers to a given register number range. Lo is inclusive,
|
2015-02-26 17:09:16 -08:00
|
|
|
// hi exclusive (valid registers are lo through hi-1).
|
|
|
|
|
func RegisterRegister(lo, hi int, Rconv func(int) string) {
|
|
|
|
|
regSpace = append(regSpace, regSet{lo, hi, Rconv})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Rconv(reg int) string {
|
|
|
|
|
if reg == REG_NONE {
|
|
|
|
|
return "NONE"
|
|
|
|
|
}
|
|
|
|
|
for i := range regSpace {
|
|
|
|
|
rs := ®Space[i]
|
|
|
|
|
if rs.lo <= reg && reg < rs.hi {
|
|
|
|
|
return rs.Rconv(reg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("R???%d", reg)
|
|
|
|
|
}
|
2015-02-27 13:50:26 -08:00
|
|
|
|
|
|
|
|
func regListConv(list int) string {
|
|
|
|
|
str := ""
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 16; i++ { // TODO: 16 is ARM-specific.
|
|
|
|
|
if list&(1<<uint(i)) != 0 {
|
|
|
|
|
if str == "" {
|
|
|
|
|
str += "["
|
|
|
|
|
} else {
|
|
|
|
|
str += ","
|
|
|
|
|
}
|
|
|
|
|
// This is ARM-specific; R10 is g.
|
|
|
|
|
if i == 10 {
|
|
|
|
|
str += "g"
|
|
|
|
|
} else {
|
|
|
|
|
str += fmt.Sprintf("R%d", i)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
str += "]"
|
|
|
|
|
return str
|
|
|
|
|
}
|
2015-03-02 20:17:20 -08:00
|
|
|
|
|
|
|
|
type opSet struct {
|
2016-03-07 18:00:08 -08:00
|
|
|
lo As
|
2015-03-02 20:17:20 -08:00
|
|
|
names []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Not even worth sorting
|
|
|
|
|
var aSpace []opSet
|
|
|
|
|
|
|
|
|
|
// RegisterOpcode binds a list of instruction names
|
|
|
|
|
// to a given instruction number range.
|
2016-03-07 18:00:08 -08:00
|
|
|
func RegisterOpcode(lo As, Anames []string) {
|
2016-06-17 12:28:31 -07:00
|
|
|
if len(Anames) > AllowedOpCodes {
|
|
|
|
|
panic(fmt.Sprintf("too many instructions, have %d max %d", len(Anames), AllowedOpCodes))
|
|
|
|
|
}
|
2015-03-02 20:17:20 -08:00
|
|
|
aSpace = append(aSpace, opSet{lo, Anames})
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 21:59:14 -07:00
|
|
|
func (a As) String() string {
|
2016-03-07 18:00:08 -08:00
|
|
|
if 0 <= a && int(a) < len(Anames) {
|
2015-03-02 20:17:20 -08:00
|
|
|
return Anames[a]
|
|
|
|
|
}
|
|
|
|
|
for i := range aSpace {
|
|
|
|
|
as := &aSpace[i]
|
2016-03-07 18:00:08 -08:00
|
|
|
if as.lo <= a && int(a-as.lo) < len(as.names) {
|
2015-03-02 20:17:20 -08:00
|
|
|
return as.names[a-as.lo]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("A???%d", a)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Anames = []string{
|
|
|
|
|
"XXX",
|
|
|
|
|
"CALL",
|
|
|
|
|
"DUFFCOPY",
|
|
|
|
|
"DUFFZERO",
|
|
|
|
|
"END",
|
|
|
|
|
"FUNCDATA",
|
|
|
|
|
"JMP",
|
|
|
|
|
"NOP",
|
|
|
|
|
"PCDATA",
|
|
|
|
|
"RET",
|
|
|
|
|
"TEXT",
|
|
|
|
|
"UNDEF",
|
|
|
|
|
}
|
2015-04-22 12:41:14 +12:00
|
|
|
|
|
|
|
|
func Bool2int(b bool) int {
|
2016-08-18 18:24:21 -07:00
|
|
|
// The compiler currently only optimizes this form.
|
|
|
|
|
// See issue 6011.
|
|
|
|
|
var i int
|
2015-04-22 12:41:14 +12:00
|
|
|
if b {
|
2016-08-18 18:24:21 -07:00
|
|
|
i = 1
|
|
|
|
|
} else {
|
|
|
|
|
i = 0
|
2015-04-22 12:41:14 +12:00
|
|
|
}
|
2016-08-18 18:24:21 -07:00
|
|
|
return i
|
2015-04-22 12:41:14 +12:00
|
|
|
}
|