]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/mips: support NEG, avoid crash with illegal instruction
authorCherry Zhang <cherryyz@google.com>
Thu, 25 Jan 2018 16:46:06 +0000 (11:46 -0500)
committerCherry Zhang <cherryyz@google.com>
Wed, 14 Feb 2018 17:09:37 +0000 (17:09 +0000)
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>
src/cmd/asm/internal/asm/testdata/mips.s
src/cmd/asm/internal/asm/testdata/mips64.s
src/cmd/internal/obj/mips/a.out.go
src/cmd/internal/obj/mips/anames.go
src/cmd/internal/obj/mips/asm0.go

index 0f0226de0cd44dd4635bf10d90ca227f7eaa74a6..6d62c4324251d49582251377ed9448b9e579c13e 100644 (file)
@@ -423,6 +423,8 @@ label4:
        JMP     foo(SB)
        CALL    foo(SB)
 
+       NEGW    R1, R2 // 00011023
+
        // END
        //
        //      LEND    comma // asm doesn't support the trailing comma.
index 50a269457609980fad5a0feedf25ade9533b5057..a945e590ab7656ea1125656de18b4812e77e3a4c 100644 (file)
@@ -403,6 +403,9 @@ label4:
        JMP     foo(SB)
        CALL    foo(SB)
 
+       NEGW    R1, R2 // 00011023
+       NEGV    R1, R2 // 0001102f
+
 // END
 //
 //     LEND    comma // asm doesn't support the trailing comma.
index 46329a8d0304fac927deb76343e2e2a3bf0e6364..49ceac1028b1720ac60ea300e8956b04b9a9ec80 100644 (file)
@@ -324,6 +324,7 @@ const (
        ANEGD
        ANEGF
        ANEGW
+       ANEGV
        ANOOP // hardware nop
        ANOR
        AOR
index ed2143a8d56bc3637f5210fe3c43ec6aa153333b..cb0d56847e714ff066c019000de41fa03de8b012 100644 (file)
@@ -70,6 +70,7 @@ var Anames = []string{
        "NEGD",
        "NEGF",
        "NEGW",
+       "NEGV",
        "NOOP",
        "NOR",
        "OR",
index 2dcfa97bf704da7409f0eb005fceb7bd832b1289..94296f9351192c247bf03923230d96e91ef316e0 100644 (file)
@@ -92,6 +92,8 @@ var optab = []Optab{
        {AADDV, C_REG, C_NONE, C_REG, 2, 4, 0, sys.MIPS64},
        {AAND, C_REG, C_NONE, 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_REG, C_REG, 9, 4, 0, 0},
@@ -740,7 +742,8 @@ func (c *ctxt0) oplook(p *obj.Prog) *Optab {
        if ops == nil {
                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 {
@@ -1021,6 +1024,8 @@ func buildop(ctxt *obj.Link) {
                        ALLV,
                        ASC,
                        ASCV,
+                       ANEGW,
+                       ANEGV,
                        AWORD,
                        obj.ANOP,
                        obj.ATEXT,
@@ -1126,7 +1131,9 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
 
        case 2: /* add/sub r1,[r2],r3 */
                r := int(p.Reg)
-
+               if p.As == ANEGW || p.As == ANEGV {
+                       r = REGZERO
+               }
                if r == 0 {
                        r = int(p.To.Reg)
                }
@@ -1626,7 +1633,7 @@ func (c *ctxt0) oprrr(a obj.As) uint32 {
                return OP(4, 6)
        case ASUB:
                return OP(4, 2)
-       case ASUBU:
+       case ASUBU, ANEGW:
                return OP(4, 3)
        case ANOR:
                return OP(4, 7)
@@ -1648,7 +1655,7 @@ func (c *ctxt0) oprrr(a obj.As) uint32 {
                return OP(5, 5)
        case ASUBV:
                return OP(5, 6)
-       case ASUBVU:
+       case ASUBVU, ANEGV:
                return OP(5, 7)
        case AREM,
                ADIV: