diff options
| author | Guoqi Chen <chenguoqi@loongson.cn> | 2023-05-08 06:20:21 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-05-13 15:52:19 +0000 |
| commit | 9ea4770e144d27877e5fe7635b662d20f6b86a6b (patch) | |
| tree | 780eb51e8e72757ba01b5e7325171982250d1237 /src/cmd/internal/obj | |
| parent | ec711aaaaa31b551a47b3677d05014e8aa60f9ea (diff) | |
| download | go-9ea4770e144d27877e5fe7635b662d20f6b86a6b.tar.xz | |
cmd/internal/obj/loong64: improve the definition of plan9 assembly format in optab
In the three formats corresponding to case 7 of the function asmout, BREAK actually
corresponds to the cacop instruction of Loong64, refer to the loong64 instruction
manual volume 1 [1], the cacop instruction is a privileged instruction used to
maintain the cache, and the user mode does not have permission to execute.
Referring to the loong64 instruction manual volume 1 [1], the SYSCALL, BREAK and DBAR
instructions have similar formats and can be grouped into one category, the RDTIMED,
RDTIMELW and RDTIMEHW instructions can be grouped into one category, and the NOOP and
UNDEF instructions can be grouped into one category.
[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html
Change-Id: I0b8998270102d1557fc2b2410cf8c0b078bd0c2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/493435
Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Meidan Li <limeidan@loongson.cn>
Reviewed-by: Carlos Amedee <carlos@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/obj')
| -rw-r--r-- | src/cmd/internal/obj/loong64/asm.go | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/src/cmd/internal/obj/loong64/asm.go b/src/cmd/internal/obj/loong64/asm.go index 6b950f8d05..5b823c09af 100644 --- a/src/cmd/internal/obj/loong64/asm.go +++ b/src/cmd/internal/obj/loong64/asm.go @@ -263,6 +263,7 @@ var optab = []Optab{ {ASLLV, C_SCON, C_NONE, C_NONE, C_REG, C_NONE, 16, 4, 0, 0}, {ASYSCALL, C_NONE, C_NONE, C_NONE, C_NONE, C_NONE, 5, 4, 0, 0}, + {ASYSCALL, C_ANDCON, C_NONE, C_NONE, C_NONE, C_NONE, 5, 4, 0, 0}, {ABEQ, C_REG, C_REG, C_NONE, C_SBRA, C_NONE, 6, 4, 0, 0}, {ABEQ, C_REG, C_NONE, C_NONE, C_SBRA, C_NONE, 6, 4, 0, 0}, @@ -354,16 +355,10 @@ var optab = []Optab{ {ATEQ, C_SCON, C_REG, C_NONE, C_REG, C_NONE, 15, 8, 0, 0}, {ATEQ, C_SCON, C_NONE, C_NONE, C_REG, C_NONE, 15, 8, 0, 0}, - {ABREAK, C_REG, C_NONE, C_NONE, C_SEXT, C_NONE, 7, 4, 0, 0}, // really CACHE instruction - {ABREAK, C_REG, C_NONE, C_NONE, C_SAUTO, C_NONE, 7, 4, REGSP, 0}, - {ABREAK, C_REG, C_NONE, C_NONE, C_SOREG, C_NONE, 7, 4, REGZERO, 0}, - {ABREAK, C_NONE, C_NONE, C_NONE, C_NONE, C_NONE, 5, 4, 0, 0}, - {ARDTIMELW, C_NONE, C_NONE, C_NONE, C_REG, C_REG, 62, 4, 0, 0}, - {ARDTIMEHW, C_NONE, C_NONE, C_NONE, C_REG, C_REG, 62, 4, 0, 0}, - {ARDTIMED, C_NONE, C_NONE, C_NONE, C_REG, C_REG, 62, 4, 0, 0}, - {obj.AUNDEF, C_NONE, C_NONE, C_NONE, C_NONE, C_NONE, 49, 4, 0, 0}, + {ANOOP, C_NONE, C_NONE, C_NONE, C_NONE, C_NONE, 49, 4, 0, 0}, + {obj.APCALIGN, C_SCON, C_NONE, C_NONE, C_NONE, C_NONE, 0, 0, 0, 0}, {obj.APCDATA, C_LCON, C_NONE, C_NONE, C_LCON, C_NONE, 0, 0, 0, 0}, {obj.APCDATA, C_DCON, C_NONE, C_NONE, C_DCON, C_NONE, 0, 0, 0, 0}, @@ -567,7 +562,7 @@ func span0(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { v := pcAlignPadLength(c.ctxt, p.Pc, alignedValue) for i = 0; i < int32(v/4); i++ { // emit ANOOP instruction by the padding size - c.ctxt.Arch.ByteOrder.PutUint32(bp, c.oprrr(ANOOP)) + c.ctxt.Arch.ByteOrder.PutUint32(bp, OP_12IRR(c.opirr(AAND), 0, 0, 0)) bp = bp[4:] } continue @@ -1130,7 +1125,7 @@ func buildop(ctxt *obj.Link) { case ASYSCALL: opset(ADBAR, r0) - opset(ANOOP, r0) + opset(ABREAK, r0) case ACMPEQF: opset(ACMPGTF, r0) @@ -1152,7 +1147,6 @@ func buildop(ctxt *obj.Link) { AMOVD, AMOVF, AMOVV, - ABREAK, ARFE, AJAL, AJMP, @@ -1164,12 +1158,8 @@ func buildop(ctxt *obj.Link) { ANEGW, ANEGV, AWORD, - ARDTIMELW, - ARDTIMEHW, - ARDTIMED, obj.ANOP, obj.ATEXT, - obj.AUNDEF, obj.AFUNCDATA, obj.APCALIGN, obj.APCDATA, @@ -1177,6 +1167,10 @@ func buildop(ctxt *obj.Link) { obj.ADUFFCOPY: break + case ARDTIMELW: + opset(ARDTIMEHW, r0) + opset(ARDTIMED, r0) + case ACLO: opset(ACLZ, r0) @@ -1185,6 +1179,9 @@ func buildop(ctxt *obj.Link) { case AMASKEQZ: opset(AMASKNEZ, r0) + + case ANOOP: + opset(obj.AUNDEF, r0) } } } @@ -1230,6 +1227,10 @@ func OP_IR(op uint32, i uint32, r2 uint32) uint32 { return op | (i&0xFFFFF)<<5 | (r2&0x1F)<<0 // ui20, rd5 } +func OP_15I(op uint32, i uint32) uint32 { + return op | (i&0x7FFF)<<0 +} + // Encoding for the 'b' or 'bl' instruction. func OP_B_BL(op uint32, i uint32) uint32 { return op | ((i & 0xFFFF) << 10) | ((i >> 16) & 0x3FF) @@ -1295,7 +1296,8 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 = OP_12IRR(c.opirr(p.As), uint32(v), uint32(r), uint32(p.To.Reg)) case 5: // syscall - o1 = c.oprrr(p.As) + v := c.regoff(&p.From) + o1 = OP_15I(c.opi(p.As), uint32(v)) case 6: // beq r1,[r2],sbra v := int32(0) @@ -1439,7 +1441,7 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) { } else { // ATNE o1 = OP_16IRR(c.opirr(ABEQ), uint32(2), uint32(r), uint32(p.To.Reg)) } - o2 = c.oprrr(ABREAK) | (uint32(v) & 0x7FFF) + o2 = OP_15I(c.opi(ABREAK), uint32(v)) case 16: // sll $c,[r1],r2 v := c.regoff(&p.From) @@ -1609,9 +1611,14 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) { a := OP_TEN(8, 1326) // movfr2gr.d o1 = OP_RR(a, uint32(p.From.Reg), uint32(p.To.Reg)) - case 49: // undef - o1 = c.oprrr(ABREAK) - + case 49: + if p.As == ANOOP { + // andi r0, r0, 0 + o1 = OP_12IRR(c.opirr(AAND), 0, 0, 0) + } else { + // undef + o1 = OP_15I(c.opi(ABREAK), 0) + } // relocation operations case 50: // mov r,addr ==> pcalau12i + sw o1 = OP_IR(c.opir(APCALAU12I), uint32(0), uint32(REGTMP)) @@ -1918,10 +1925,6 @@ func (c *ctxt0) oprrr(a obj.As) uint32 { case AJAL: return (0x13 << 26) | 1 // jirl r1, rj, 0 - case ABREAK: - return 0x54 << 15 - case ASYSCALL: - return 0x56 << 15 case ADIVF: return 0x20d << 15 case ADIVD: @@ -1995,12 +1998,6 @@ func (c *ctxt0) oprrr(a obj.As) uint32 { return 0x4511 << 10 case ASQRTD: return 0x4512 << 10 - - case ADBAR: - return 0x70e4 << 15 - case ANOOP: - // andi r0, r0, 0 - return 0x03400000 } if a < 0 { @@ -2029,6 +2026,21 @@ func (c *ctxt0) oprr(a obj.As) uint32 { return 0 } +func (c *ctxt0) opi(a obj.As) uint32 { + switch a { + case ASYSCALL: + return 0x56 << 15 + case ABREAK: + return 0x54 << 15 + case ADBAR: + return 0x70e4 << 15 + } + + c.ctxt.Diag("bad ic opcode %v", a) + + return 0 +} + func (c *ctxt0) opir(a obj.As) uint32 { switch a { case ALU12IW: @@ -2125,10 +2137,6 @@ func (c *ctxt0) opirr(a obj.As) uint32 { return 0x0be << 22 case AMOVVR: return 0x0bf << 22 - - case ABREAK: - return 0x018 << 22 - case -AMOVWL: return 0x0b8 << 22 case -AMOVWR: |
