Commit 9ce5cad0 authored by diaxu01's avatar diaxu01 Committed by Cherry Zhang

cmd/internal/obj/arm64: add error checking for system registers.

This CL adds system register error checking test cases. There're two kinds of
error test cases:

1. illegal combination.
MRS should be used in this way: MRS <system register>, <general register>.
MSR should be used in this way: MSR <general register>, <system register>.
Error usage examples:
MRS     R8, VTCR_EL2    // ERROR "illegal combination"
MSR     VTCR_EL2, R8    // ERROR "illegal combination"

2. illegal read or write access.
Error usage examples:
MSR     R7, MIDR_EL1    // ERROR "expected writable system register or pstate"
MRS     OSLAR_EL1, R3   // ERROR "expected readable system register"

This CL reads system registers readable and writeable property to check whether
they're used with legal read or write access. This property is named AccessFlags
in sysRegEnc.go, and it is automatically generated by modifing the system register
generator.

Change-Id: Ic83d5f372de38d1ecd0df1ca56b354ee157f16b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/194917Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d458b868
......@@ -1221,7 +1221,7 @@ again:
MRS DBGCLAIMSET_EL1, R7 // c77830d5
MSR R13, DBGCLAIMSET_EL1 // cd7810d5
MRS DBGDTRRX_EL0, R0 // 000533d5
MSR R29, DBGDTRRX_EL0 // 1d0513d5
MSR R29, DBGDTRTX_EL0 // 1d0513d5
MRS DBGDTR_EL0, R27 // 1b0433d5
MSR R30, DBGDTR_EL0 // 1e0413d5
MRS DBGPRCR_EL1, R4 // 841430d5
......
......@@ -195,11 +195,11 @@ const (
// Special registers, after subtracting obj.RBaseARM64, bit 12 indicates
// a special register and the low bits select the register.
// AUTO_SYSREG_END is the last item in the automatically generated system register
// SYSREG_END is the last item in the automatically generated system register
// declaration, and it is defined in the sysRegEnc.go file.
const (
REG_SPECIAL = obj.RBaseARM64 + 1<<12
REG_DAIFSet = AUTO_SYSREG_END + iota
REG_DAIFSet = SYSREG_END + iota
REG_DAIFClr
REG_PLDL1KEEP
REG_PLDL1STRM
......
......@@ -3543,15 +3543,17 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
case 35: /* mov SPR,R -> mrs */
o1 = c.oprrr(p, AMRS)
v := uint32(0)
// SysRegEnc function returns the system register encoding.
_, v = SysRegEnc(p.From.Reg)
// SysRegEnc function returns the system register encoding and accessFlags.
_, v, accessFlags := SysRegEnc(p.From.Reg)
if v == 0 {
c.ctxt.Diag("illegal system register:\n%v", p)
}
if (o1 & (v &^ (3 << 19))) != 0 {
c.ctxt.Diag("MRS register value overlap\n%v", p)
}
if accessFlags&SR_READ == 0 {
c.ctxt.Diag("system register is not readable: %v", p)
}
o1 |= v
o1 |= uint32(p.To.Reg & 31)
......@@ -3559,15 +3561,17 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
case 36: /* mov R,SPR */
o1 = c.oprrr(p, AMSR)
v := uint32(0)
// SysRegEnc function returns the system register encoding.
_, v = SysRegEnc(p.To.Reg)
// SysRegEnc function returns the system register encoding and accessFlags.
_, v, accessFlags := SysRegEnc(p.To.Reg)
if v == 0 {
c.ctxt.Diag("illegal system register:\n%v", p)
}
if (o1 & (v &^ (3 << 19))) != 0 {
c.ctxt.Diag("MSR register value overlap\n%v", p)
}
if accessFlags&SR_WRITE == 0 {
c.ctxt.Diag("system register is not writable: %v", p)
}
o1 |= v
o1 |= uint32(p.From.Reg & 31)
......
......@@ -209,7 +209,7 @@ func rconv(r int) string {
return fmt.Sprintf("V%d.%s", r&31, arrange((r>>5)&15))
}
// Return system register name.
name, _ := SysRegEnc(int16(r))
name, _, _ := SysRegEnc(int16(r))
if name != "" {
return name
}
......
This diff is collapsed.
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