Skip to content

Commit a40404d

Browse files
Vishwanatha-HDcherrymui
authored andcommitted
cmd/asm: add KMA and KMCTR instructions on s390x.
This CL is to add assembly instruction mnemonics for the following instructions, mainly used in crypto packages. * KMA - cipher message with authentication * KMCTR - cipher message with counter Fixes #61163 Change-Id: Iff9a69911aeb4fab4bca8755b23a106eaebb2332 Reviewed-on: https://go-review.googlesource.com/c/go/+/515195 Reviewed-by: Carlos Amedee <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Cherry Mui <[email protected]>
1 parent a2647f0 commit a40404d

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

src/cmd/asm/internal/asm/testdata/s390x.s

+2
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ TEXT main·foo(SB),DUPOK|NOSPLIT,$16-0 // TEXT main.foo(SB), DUPOK|NOSPLIT, $16-
420420
KLMD R2, R8 // b93f0028
421421
KIMD R0, R4 // b93e0004
422422
KDSA R0, R8 // b93a0008
423+
KMA R6, R2, R4 // b9296024
424+
KMCTR R6, R2, R4 // b92d6024
423425

424426
// vector add and sub instructions
425427
VAB V3, V4, V4 // e743400000f3

src/cmd/internal/obj/s390x/a.out.go

+2
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ const (
486486
AKLMD
487487
AKIMD
488488
AKDSA
489+
AKMA
490+
AKMCTR
489491

490492
// vector
491493
AVA

src/cmd/internal/obj/s390x/anames.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/internal/obj/s390x/asmz.go

+40
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ var optab = []Optab{
347347
// KDSA
348348
{i: 125, as: AKDSA, a1: C_REG, a6: C_REG},
349349

350+
// KMA
351+
{i: 126, as: AKMA, a1: C_REG, a2: C_REG, a6: C_REG},
352+
350353
// vector instructions
351354

352355
// VRX store
@@ -1492,6 +1495,8 @@ func buildop(ctxt *obj.Link) {
14921495
opset(AKMC, r)
14931496
opset(AKLMD, r)
14941497
opset(AKIMD, r)
1498+
case AKMA:
1499+
opset(AKMCTR, r)
14951500
}
14961501
}
14971502
}
@@ -1896,6 +1901,7 @@ const (
18961901
op_KM uint32 = 0xB92E // FORMAT_RRE CIPHER MESSAGE
18971902
op_KMAC uint32 = 0xB91E // FORMAT_RRE COMPUTE MESSAGE AUTHENTICATION CODE
18981903
op_KMC uint32 = 0xB92F // FORMAT_RRE CIPHER MESSAGE WITH CHAINING
1904+
op_KMA uint32 = 0xB929 // FORMAT_RRF2 CIPHER MESSAGE WITH AUTHENTICATION
18991905
op_KMCTR uint32 = 0xB92D // FORMAT_RRF2 CIPHER MESSAGE WITH COUNTER
19001906
op_KMF uint32 = 0xB92A // FORMAT_RRE CIPHER MESSAGE WITH CFB
19011907
op_KMO uint32 = 0xB92B // FORMAT_RRE CIPHER MESSAGE WITH OFB
@@ -4428,6 +4434,40 @@ func (c *ctxtz) asmout(p *obj.Prog, asm *[]byte) {
44284434
}
44294435
zRRE(op_KDSA, uint32(p.From.Reg), uint32(p.To.Reg), asm)
44304436

4437+
case 126: // KMA and KMCTR - CIPHER MESSAGE WITH AUTHENTICATION; CIPHER MESSAGE WITH
4438+
var opcode uint32
4439+
switch p.As {
4440+
default:
4441+
c.ctxt.Diag("unexpected opcode %v", p.As)
4442+
case AKMA, AKMCTR:
4443+
if p.From.Reg == REG_R0 {
4444+
c.ctxt.Diag("input argument must not be R0 in %v", p)
4445+
}
4446+
if p.From.Reg&1 != 0 {
4447+
c.ctxt.Diag("input argument must be even register in %v", p)
4448+
}
4449+
if p.To.Reg == REG_R0 {
4450+
c.ctxt.Diag("output argument must not be R0 in %v", p)
4451+
}
4452+
if p.To.Reg&1 != 0 {
4453+
c.ctxt.Diag("output argument must be an even register in %v", p)
4454+
}
4455+
if p.Reg == REG_R0 {
4456+
c.ctxt.Diag("third argument must not be R0 in %v", p)
4457+
}
4458+
if p.Reg&1 != 0 {
4459+
c.ctxt.Diag("third argument must be even register in %v", p)
4460+
}
4461+
if p.Reg == p.To.Reg || p.Reg == p.From.Reg {
4462+
c.ctxt.Diag("third argument must not be input or output argument registers in %v", p)
4463+
}
4464+
if p.As == AKMA {
4465+
opcode = op_KMA
4466+
} else if p.As == AKMCTR {
4467+
opcode = op_KMCTR
4468+
}
4469+
}
4470+
zRRF(opcode, uint32(p.From.Reg), 0, uint32(p.Reg), uint32(p.To.Reg), asm)
44314471
}
44324472
}
44334473

src/crypto/aes/asm_s390x.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ crypt:
127127
MOVD src_base+56(FP), R6 // src
128128
MOVD src_len+64(FP), R7 // len
129129
loop:
130-
WORD $0xB92D2046 // cipher message with counter (KMCTR)
130+
KMCTR R6, R2, R4 // cipher message with counter (KMCTR)
131131
BVS loop // branch back if interrupted
132132
RET
133133
crash:
@@ -180,7 +180,7 @@ TEXT ·kmaGCM(SB),NOSPLIT,$112-120
180180
MVC $8, 24(R8), 104(R1)
181181

182182
kma:
183-
WORD $0xb9296024 // kma %r6,%r2,%r4
183+
KMA R6, R2, R4 // Cipher Message with Authentication
184184
BVS kma
185185

186186
MOVD tag+104(FP), R2

src/internal/cpu/cpu_s390x.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ TEXT ·kmcQuery(SB), NOSPLIT|NOFRAME, $0-16
3030
TEXT ·kmctrQuery(SB), NOSPLIT|NOFRAME, $0-16
3131
MOVD $0, R0 // set function code to 0 (KMCTR-Query)
3232
MOVD $ret+0(FP), R1 // address of 16-byte return value
33-
WORD $0xB92D4024 // cipher message with counter (KMCTR)
33+
KMCTR R6, R2, R4 // cipher message with counter (KMCTR)
3434
RET
3535

3636
// func kmaQuery() queryResult
3737
TEXT ·kmaQuery(SB), NOSPLIT|NOFRAME, $0-16
3838
MOVD $0, R0 // set function code to 0 (KMA-Query)
3939
MOVD $ret+0(FP), R1 // address of 16-byte return value
40-
WORD $0xb9296024 // cipher message with authentication (KMA)
40+
KMA R6, R2, R4 // cipher message with authentication (KMA)
4141
RET
4242

4343
// func kimdQuery() queryResult

0 commit comments

Comments
 (0)