Commit 98139510 authored by Cherry Zhang's avatar Cherry Zhang Committed by Minux Ma

cmd/internal/obj/mips et al.: introduce SB register on mips64x

SB register (R28) is introduced for access external addresses with shorter
instruction sequences. It is loaded at entry points. External data within
2G of SB can be accessed this way.

cmd/internal/obj: relocaltion R_ADDRMIPS is split into two relocations
R_ADDRMIPS and R_ADDRMIPSU, handling the low 16 bits and the "upper" 16
bits of external addresses, respectively, since the instructios may not
be adjacent. It might be better if relocation Variant could be used.

cmd/link/internal/mips64: support new relocations.

cmd/compile/internal/mips64: reserve SB register.

runtime: initialize SB register at entry points.

Change-Id: I5f34868f88c5a9698c042a8a1f12f76806c187b9
Reviewed-on: https://go-review.googlesource.com/19802Reviewed-by: default avatarMinux Ma <minux@golang.org>
parent 8dc0444a
...@@ -41,6 +41,7 @@ import ( ...@@ -41,6 +41,7 @@ import (
var resvd = []int{ var resvd = []int{
mips.REGZERO, mips.REGZERO,
mips.REGSP, // reserved for SP mips.REGSP, // reserved for SP
mips.REGSB, // reserved for SB
mips.REGLINK, // reserved for link mips.REGLINK, // reserved for link
mips.REGG, mips.REGG,
mips.REGTMP, mips.REGTMP,
......
...@@ -111,7 +111,7 @@ func regnames(n *int) []string { ...@@ -111,7 +111,7 @@ func regnames(n *int) []string {
func excludedregs() uint64 { func excludedregs() uint64 {
// Exclude registers with fixed functions // Exclude registers with fixed functions
regbits := 1<<0 | RtoB(mips.REGSP) | RtoB(mips.REGG) | RtoB(mips.REGTMP) | RtoB(mips.REGLINK) | RtoB(mips.REG_R26) | RtoB(mips.REG_R27) regbits := 1<<0 | RtoB(mips.REGSP) | RtoB(mips.REGG) | RtoB(mips.REGSB) | RtoB(mips.REGTMP) | RtoB(mips.REGLINK) | RtoB(mips.REG_R26) | RtoB(mips.REG_R27)
// Also exclude floating point registers with fixed constants // Also exclude floating point registers with fixed constants
regbits |= RtoB(mips.FREGZERO) | RtoB(mips.FREGHALF) | RtoB(mips.FREGONE) | RtoB(mips.FREGTWO) regbits |= RtoB(mips.FREGZERO) | RtoB(mips.FREGHALF) | RtoB(mips.FREGONE) | RtoB(mips.FREGTWO)
......
...@@ -454,8 +454,8 @@ const ( ...@@ -454,8 +454,8 @@ const (
// R_ADDRARM64 relocates an adrp, add pair to compute the address of the // R_ADDRARM64 relocates an adrp, add pair to compute the address of the
// referenced symbol. // referenced symbol.
R_ADDRARM64 R_ADDRARM64
// R_ADDRMIPS (only used on mips64) resolves to a 32-bit external address, // R_ADDRMIPS (only used on mips64) resolves to the low 16 bits of an external
// by loading the address into a register with two instructions (lui, ori). // address, by encoding it into the instruction.
R_ADDRMIPS R_ADDRMIPS
// R_ADDROFF resolves to a 32-bit offset from the beginning of the section // R_ADDROFF resolves to a 32-bit offset from the beginning of the section
// holding the data being relocated to the referenced symbol. // holding the data being relocated to the referenced symbol.
...@@ -581,6 +581,10 @@ const ( ...@@ -581,6 +581,10 @@ const (
// R_PCRELDBL relocates s390x 2-byte aligned PC-relative addresses. // R_PCRELDBL relocates s390x 2-byte aligned PC-relative addresses.
// TODO(mundaym): remove once variants can be serialized - see issue 14218. // TODO(mundaym): remove once variants can be serialized - see issue 14218.
R_PCRELDBL R_PCRELDBL
// R_ADDRMIPSU (only used on mips64) resolves to the sign-adjusted "upper" 16
// bits (bit 16-31) of an external address, by encoding it into the instruction.
R_ADDRMIPSU
) )
type Auto struct { type Auto struct {
......
This diff is collapsed.
...@@ -34,7 +34,6 @@ import ( ...@@ -34,7 +34,6 @@ import (
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/sys" "cmd/internal/sys"
"cmd/link/internal/ld" "cmd/link/internal/ld"
"encoding/binary"
"fmt" "fmt"
"log" "log"
) )
...@@ -71,24 +70,14 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int { ...@@ -71,24 +70,14 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0)) *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ld.Linklookup(ld.Ctxt, ".got", 0))
return 0 return 0
case obj.R_ADDRMIPS: case obj.R_ADDRMIPS,
obj.R_ADDRMIPSU:
t := ld.Symaddr(r.Sym) + r.Add t := ld.Symaddr(r.Sym) + r.Add
if t >= 1<<32 || t < -1<<32 {
ld.Diag("program too large, address relocation = %v", t)
}
// the first instruction is always at the lower address, this is endian neutral;
// but note that o1 and o2 should still use the target endian.
o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:]) o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
o2 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off+4:]) if r.Type == obj.R_ADDRMIPS {
o1 = o1&0xffff0000 | uint32(t>>16)&0xffff *val = int64(o1&0xffff0000 | uint32(t)&0xffff)
o2 = o2&0xffff0000 | uint32(t)&0xffff
// when laid out, the instruction order must always be o1, o2.
if ld.Ctxt.Arch.ByteOrder == binary.BigEndian {
*val = int64(o1)<<32 | int64(o2)
} else { } else {
*val = int64(o2)<<32 | int64(o1) *val = int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff)
} }
return 0 return 0
......
...@@ -27,5 +27,10 @@ TEXT _main<>(SB),NOSPLIT,$-8 ...@@ -27,5 +27,10 @@ TEXT _main<>(SB),NOSPLIT,$-8
JMP main(SB) JMP main(SB)
TEXT main(SB),NOSPLIT,$-8 TEXT main(SB),NOSPLIT,$-8
// initalize REGSB = PC&0xffffffff00000000
BGEZAL R0, 1(PC)
SRLV $32, R31, RSB
SLLV $32, RSB
MOVV $runtime·rt0_go(SB), R4 MOVV $runtime·rt0_go(SB), R4
JMP (R4) JMP (R4)
...@@ -233,6 +233,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32 ...@@ -233,6 +233,11 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
RET RET
TEXT runtime·sigtramp(SB),NOSPLIT,$64 TEXT runtime·sigtramp(SB),NOSPLIT,$64
// initialize REGSB = PC&0xffffffff00000000
BGEZAL R0, 1(PC)
SRLV $32, R31, RSB
SLLV $32, RSB
// initialize essential registers (just in case) // initialize essential registers (just in case)
JAL runtime·reginit(SB) JAL runtime·reginit(SB)
...@@ -250,8 +255,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$64 ...@@ -250,8 +255,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$64
RET RET
TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
MOVV $runtime·sigtramp(SB), R1 JMP runtime·sigtramp(SB)
JMP (R1)
TEXT runtime·mmap(SB),NOSPLIT,$-8 TEXT runtime·mmap(SB),NOSPLIT,$-8
MOVV addr+0(FP), R4 MOVV addr+0(FP), R4
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment