mirror of
https://github.com/golang/go
synced 2024-11-19 17:44:43 -07:00
cmd/internal/obj/mips: support NEG, avoid crash with illegal instruction
Add support of NEG{V,W} pseudo-instructions, which are translated to a SUB instruction from R0 with proper width. Also turn illegal instruction to UNDEF, to avoid crashing in asmout when it tries to read the operands. Fixes #23548. Change-Id: I047b27559ccd9594c3dcf62ab039b636098f30a3 Reviewed-on: https://go-review.googlesource.com/89896 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
parent
1fccbfe90e
commit
0938e4cf90
2
src/cmd/asm/internal/asm/testdata/mips.s
vendored
2
src/cmd/asm/internal/asm/testdata/mips.s
vendored
@ -423,6 +423,8 @@ label4:
|
|||||||
JMP foo(SB)
|
JMP foo(SB)
|
||||||
CALL foo(SB)
|
CALL foo(SB)
|
||||||
|
|
||||||
|
NEGW R1, R2 // 00011023
|
||||||
|
|
||||||
// END
|
// END
|
||||||
//
|
//
|
||||||
// LEND comma // asm doesn't support the trailing comma.
|
// LEND comma // asm doesn't support the trailing comma.
|
||||||
|
3
src/cmd/asm/internal/asm/testdata/mips64.s
vendored
3
src/cmd/asm/internal/asm/testdata/mips64.s
vendored
@ -403,6 +403,9 @@ label4:
|
|||||||
JMP foo(SB)
|
JMP foo(SB)
|
||||||
CALL foo(SB)
|
CALL foo(SB)
|
||||||
|
|
||||||
|
NEGW R1, R2 // 00011023
|
||||||
|
NEGV R1, R2 // 0001102f
|
||||||
|
|
||||||
// END
|
// END
|
||||||
//
|
//
|
||||||
// LEND comma // asm doesn't support the trailing comma.
|
// LEND comma // asm doesn't support the trailing comma.
|
||||||
|
@ -324,6 +324,7 @@ const (
|
|||||||
ANEGD
|
ANEGD
|
||||||
ANEGF
|
ANEGF
|
||||||
ANEGW
|
ANEGW
|
||||||
|
ANEGV
|
||||||
ANOOP // hardware nop
|
ANOOP // hardware nop
|
||||||
ANOR
|
ANOR
|
||||||
AOR
|
AOR
|
||||||
|
@ -70,6 +70,7 @@ var Anames = []string{
|
|||||||
"NEGD",
|
"NEGD",
|
||||||
"NEGF",
|
"NEGF",
|
||||||
"NEGW",
|
"NEGW",
|
||||||
|
"NEGV",
|
||||||
"NOOP",
|
"NOOP",
|
||||||
"NOR",
|
"NOR",
|
||||||
"OR",
|
"OR",
|
||||||
|
@ -92,6 +92,8 @@ var optab = []Optab{
|
|||||||
{AADDV, C_REG, C_NONE, C_REG, 2, 4, 0, sys.MIPS64},
|
{AADDV, C_REG, C_NONE, C_REG, 2, 4, 0, sys.MIPS64},
|
||||||
{AAND, C_REG, C_NONE, C_REG, 2, 4, 0, 0},
|
{AAND, C_REG, C_NONE, C_REG, 2, 4, 0, 0},
|
||||||
{ACMOVN, C_REG, C_REG, C_REG, 2, 4, 0, 0},
|
{ACMOVN, C_REG, C_REG, C_REG, 2, 4, 0, 0},
|
||||||
|
{ANEGW, C_REG, C_NONE, C_REG, 2, 4, 0, 0},
|
||||||
|
{ANEGV, C_REG, C_NONE, C_REG, 2, 4, 0, sys.MIPS64},
|
||||||
|
|
||||||
{ASLL, C_REG, C_NONE, C_REG, 9, 4, 0, 0},
|
{ASLL, C_REG, C_NONE, C_REG, 9, 4, 0, 0},
|
||||||
{ASLL, C_REG, C_REG, C_REG, 9, 4, 0, 0},
|
{ASLL, C_REG, C_REG, C_REG, 9, 4, 0, 0},
|
||||||
@ -740,7 +742,8 @@ func (c *ctxt0) oplook(p *obj.Prog) *Optab {
|
|||||||
if ops == nil {
|
if ops == nil {
|
||||||
ops = optab
|
ops = optab
|
||||||
}
|
}
|
||||||
return &ops[0]
|
// Turn illegal instruction into an UNDEF, avoid crashing in asmout.
|
||||||
|
return &Optab{obj.AUNDEF, C_NONE, C_NONE, C_NONE, 49, 4, 0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmp(a int, b int) bool {
|
func cmp(a int, b int) bool {
|
||||||
@ -1021,6 +1024,8 @@ func buildop(ctxt *obj.Link) {
|
|||||||
ALLV,
|
ALLV,
|
||||||
ASC,
|
ASC,
|
||||||
ASCV,
|
ASCV,
|
||||||
|
ANEGW,
|
||||||
|
ANEGV,
|
||||||
AWORD,
|
AWORD,
|
||||||
obj.ANOP,
|
obj.ANOP,
|
||||||
obj.ATEXT,
|
obj.ATEXT,
|
||||||
@ -1126,7 +1131,9 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
|
|||||||
|
|
||||||
case 2: /* add/sub r1,[r2],r3 */
|
case 2: /* add/sub r1,[r2],r3 */
|
||||||
r := int(p.Reg)
|
r := int(p.Reg)
|
||||||
|
if p.As == ANEGW || p.As == ANEGV {
|
||||||
|
r = REGZERO
|
||||||
|
}
|
||||||
if r == 0 {
|
if r == 0 {
|
||||||
r = int(p.To.Reg)
|
r = int(p.To.Reg)
|
||||||
}
|
}
|
||||||
@ -1626,7 +1633,7 @@ func (c *ctxt0) oprrr(a obj.As) uint32 {
|
|||||||
return OP(4, 6)
|
return OP(4, 6)
|
||||||
case ASUB:
|
case ASUB:
|
||||||
return OP(4, 2)
|
return OP(4, 2)
|
||||||
case ASUBU:
|
case ASUBU, ANEGW:
|
||||||
return OP(4, 3)
|
return OP(4, 3)
|
||||||
case ANOR:
|
case ANOR:
|
||||||
return OP(4, 7)
|
return OP(4, 7)
|
||||||
@ -1648,7 +1655,7 @@ func (c *ctxt0) oprrr(a obj.As) uint32 {
|
|||||||
return OP(5, 5)
|
return OP(5, 5)
|
||||||
case ASUBV:
|
case ASUBV:
|
||||||
return OP(5, 6)
|
return OP(5, 6)
|
||||||
case ASUBVU:
|
case ASUBVU, ANEGV:
|
||||||
return OP(5, 7)
|
return OP(5, 7)
|
||||||
case AREM,
|
case AREM,
|
||||||
ADIV:
|
ADIV:
|
||||||
|
Loading…
Reference in New Issue
Block a user