1
0
mirror of https://github.com/golang/go synced 2024-11-22 23:50:03 -07:00

cmd/asm/internal/arch: adds the missing type check for arm64 SXTB extension

Operands of memory type do not support SXTB extension. This CL adds this
missing check.

Change-Id: I1fa438dd314fc8aeb889637079cc67b538e83a89
Reviewed-on: https://go-review.googlesource.com/c/go/+/342769
Reviewed-by: eric fang <eric.fang@arm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: eric fang <eric.fang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
eric fang 2021-08-16 06:41:15 +00:00
parent c92c2c9d62
commit e9e0d1ef70

View File

@ -165,27 +165,21 @@ func ARM64RegisterExtension(a *obj.Addr, ext string, reg, num int16, isAmount, i
} }
} }
if reg <= arm64.REG_R31 && reg >= arm64.REG_R0 { if reg <= arm64.REG_R31 && reg >= arm64.REG_R0 {
switch ext {
case "UXTB":
if !isAmount { if !isAmount {
return errors.New("invalid register extension") return errors.New("invalid register extension")
} }
switch ext {
case "UXTB":
if a.Type == obj.TYPE_MEM { if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode") return errors.New("invalid shift for the register offset addressing mode")
} }
a.Reg = arm64.REG_UXTB + Rnum a.Reg = arm64.REG_UXTB + Rnum
case "UXTH": case "UXTH":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM { if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode") return errors.New("invalid shift for the register offset addressing mode")
} }
a.Reg = arm64.REG_UXTH + Rnum a.Reg = arm64.REG_UXTH + Rnum
case "UXTW": case "UXTW":
if !isAmount {
return errors.New("invalid register extension")
}
// effective address of memory is a base register value and an offset register value. // effective address of memory is a base register value and an offset register value.
if a.Type == obj.TYPE_MEM { if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_UXTW + Rnum a.Index = arm64.REG_UXTW + Rnum
@ -193,48 +187,33 @@ func ARM64RegisterExtension(a *obj.Addr, ext string, reg, num int16, isAmount, i
a.Reg = arm64.REG_UXTW + Rnum a.Reg = arm64.REG_UXTW + Rnum
} }
case "UXTX": case "UXTX":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM { if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode") return errors.New("invalid shift for the register offset addressing mode")
} }
a.Reg = arm64.REG_UXTX + Rnum a.Reg = arm64.REG_UXTX + Rnum
case "SXTB": case "SXTB":
if !isAmount { if a.Type == obj.TYPE_MEM {
return errors.New("invalid register extension") return errors.New("invalid shift for the register offset addressing mode")
} }
a.Reg = arm64.REG_SXTB + Rnum a.Reg = arm64.REG_SXTB + Rnum
case "SXTH": case "SXTH":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM { if a.Type == obj.TYPE_MEM {
return errors.New("invalid shift for the register offset addressing mode") return errors.New("invalid shift for the register offset addressing mode")
} }
a.Reg = arm64.REG_SXTH + Rnum a.Reg = arm64.REG_SXTH + Rnum
case "SXTW": case "SXTW":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM { if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_SXTW + Rnum a.Index = arm64.REG_SXTW + Rnum
} else { } else {
a.Reg = arm64.REG_SXTW + Rnum a.Reg = arm64.REG_SXTW + Rnum
} }
case "SXTX": case "SXTX":
if !isAmount {
return errors.New("invalid register extension")
}
if a.Type == obj.TYPE_MEM { if a.Type == obj.TYPE_MEM {
a.Index = arm64.REG_SXTX + Rnum a.Index = arm64.REG_SXTX + Rnum
} else { } else {
a.Reg = arm64.REG_SXTX + Rnum a.Reg = arm64.REG_SXTX + Rnum
} }
case "LSL": case "LSL":
if !isAmount {
return errors.New("invalid register extension")
}
a.Index = arm64.REG_LSL + Rnum a.Index = arm64.REG_LSL + Rnum
default: default:
return errors.New("unsupported general register extension type: " + ext) return errors.New("unsupported general register extension type: " + ext)