]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/asm: add KMA and KMCTR instructions on s390x.
authorroot <vishwanatha.hd@ibm.com>
Wed, 2 Aug 2023 09:46:27 +0000 (09:46 +0000)
committerCherry Mui <cherryyz@google.com>
Tue, 5 Sep 2023 16:41:03 +0000 (16:41 +0000)
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 <carlos@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>

src/cmd/asm/internal/asm/testdata/s390x.s
src/cmd/internal/obj/s390x/a.out.go
src/cmd/internal/obj/s390x/anames.go
src/cmd/internal/obj/s390x/asmz.go
src/crypto/aes/asm_s390x.s
src/internal/cpu/cpu_s390x.s

index bb1573ae5bb1b266b5983bbee224e741b5789884..82aa4453568d6a904504ef53b5308daaf012f14b 100644 (file)
@@ -420,6 +420,8 @@ TEXT main·foo(SB),DUPOK|NOSPLIT,$16-0 // TEXT main.foo(SB), DUPOK|NOSPLIT, $16-
        KLMD    R2, R8                 // b93f0028
        KIMD    R0, R4                 // b93e0004
        KDSA    R0, R8                 // b93a0008
+       KMA     R6, R2, R4              // b9296024
+       KMCTR   R6, R2, R4              // b92d6024
 
        // vector add and sub instructions
        VAB     V3, V4, V4              // e743400000f3
index ef02fed28323e599210360a5c1991a9444ac8006..1c86fe14635249823aea2f68acf68589f73d79de 100644 (file)
@@ -486,6 +486,8 @@ const (
        AKLMD
        AKIMD
        AKDSA
+       AKMA
+       AKMCTR
 
        // vector
        AVA
index 40cc5e6b0d483fc19df8f4f7641e17a5a8f7f811..fa239843323f0491be3cedd7afb0d5e72167dada 100644 (file)
@@ -212,6 +212,8 @@ var Anames = []string{
        "KLMD",
        "KIMD",
        "KDSA",
+       "KMA",
+       "KMCTR",
        "VA",
        "VAB",
        "VAH",
index a744d742cfa45480598fde0093f0180fa8b30d1f..0ab492a2a54b132d2701eb168bf461fc389fe833 100644 (file)
@@ -347,6 +347,9 @@ var optab = []Optab{
        // KDSA
        {i: 125, as: AKDSA, a1: C_REG, a6: C_REG},
 
+       // KMA
+       {i: 126, as: AKMA, a1: C_REG, a2: C_REG, a6: C_REG},
+
        // vector instructions
 
        // VRX store
@@ -1492,6 +1495,8 @@ func buildop(ctxt *obj.Link) {
                        opset(AKMC, r)
                        opset(AKLMD, r)
                        opset(AKIMD, r)
+               case AKMA:
+                       opset(AKMCTR, r)
                }
        }
 }
@@ -1896,6 +1901,7 @@ const (
        op_KM      uint32 = 0xB92E // FORMAT_RRE        CIPHER MESSAGE
        op_KMAC    uint32 = 0xB91E // FORMAT_RRE        COMPUTE MESSAGE AUTHENTICATION CODE
        op_KMC     uint32 = 0xB92F // FORMAT_RRE        CIPHER MESSAGE WITH CHAINING
+       op_KMA     uint32 = 0xB929 // FORMAT_RRF2       CIPHER MESSAGE WITH AUTHENTICATION
        op_KMCTR   uint32 = 0xB92D // FORMAT_RRF2       CIPHER MESSAGE WITH COUNTER
        op_KMF     uint32 = 0xB92A // FORMAT_RRE        CIPHER MESSAGE WITH CFB
        op_KMO     uint32 = 0xB92B // FORMAT_RRE        CIPHER MESSAGE WITH OFB
@@ -4428,6 +4434,40 @@ func (c *ctxtz) asmout(p *obj.Prog, asm *[]byte) {
                }
                zRRE(op_KDSA, uint32(p.From.Reg), uint32(p.To.Reg), asm)
 
+       case 126: // KMA and KMCTR - CIPHER MESSAGE WITH AUTHENTICATION; CIPHER MESSAGE WITH
+               var opcode uint32
+               switch p.As {
+               default:
+                       c.ctxt.Diag("unexpected opcode %v", p.As)
+               case AKMA, AKMCTR:
+                       if p.From.Reg == REG_R0 {
+                               c.ctxt.Diag("input argument must not be R0 in %v", p)
+                       }
+                       if p.From.Reg&1 != 0 {
+                               c.ctxt.Diag("input argument must be even register in %v", p)
+                       }
+                       if p.To.Reg == REG_R0 {
+                               c.ctxt.Diag("output argument must not be R0 in %v", p)
+                       }
+                       if p.To.Reg&1 != 0 {
+                               c.ctxt.Diag("output argument must be an even register in %v", p)
+                       }
+                       if p.Reg == REG_R0 {
+                               c.ctxt.Diag("third argument must not be R0 in %v", p)
+                       }
+                       if p.Reg&1 != 0 {
+                               c.ctxt.Diag("third argument must be even register in %v", p)
+                       }
+                       if p.Reg == p.To.Reg || p.Reg == p.From.Reg {
+                               c.ctxt.Diag("third argument must not be input or output argument registers in %v", p)
+                       }
+                       if p.As == AKMA {
+                               opcode = op_KMA
+                       } else if p.As == AKMCTR {
+                               opcode = op_KMCTR
+                       }
+               }
+               zRRF(opcode, uint32(p.From.Reg), 0, uint32(p.Reg), uint32(p.To.Reg), asm)
        }
 }
 
index 2b596bd34b063e7a2c80ad544d37096e0d079624..efcce3a0d93b733976573721a68e90ef0827ea32 100644 (file)
@@ -127,7 +127,7 @@ crypt:
        MOVD    src_base+56(FP), R6 // src
        MOVD    src_len+64(FP), R7  // len
 loop:
-       WORD    $0xB92D2046         // cipher message with counter (KMCTR)
+       KMCTR   R6, R2, R4          // cipher message with counter (KMCTR)
        BVS     loop                // branch back if interrupted
        RET
 crash:
@@ -180,7 +180,7 @@ TEXT ·kmaGCM(SB),NOSPLIT,$112-120
        MVC     $8, 24(R8), 104(R1)
 
 kma:
-       WORD    $0xb9296024 // kma %r6,%r2,%r4
+       KMA     R6, R2, R4       // Cipher Message with Authentication
        BVS     kma
 
        MOVD    tag+104(FP), R2
index 46b3b5348121691f630a49fad60499393ebe362a..c55a4c725dd7319505066c4c0c64714a8a81ce3d 100644 (file)
@@ -30,14 +30,14 @@ TEXT ·kmcQuery(SB), NOSPLIT|NOFRAME, $0-16
 TEXT ·kmctrQuery(SB), NOSPLIT|NOFRAME, $0-16
        MOVD $0, R0         // set function code to 0 (KMCTR-Query)
        MOVD $ret+0(FP), R1 // address of 16-byte return value
-       WORD $0xB92D4024    // cipher message with counter (KMCTR)
+       KMCTR R6, R2, R4    // cipher message with counter (KMCTR)
        RET
 
 // func kmaQuery() queryResult
 TEXT ·kmaQuery(SB), NOSPLIT|NOFRAME, $0-16
        MOVD $0, R0         // set function code to 0 (KMA-Query)
        MOVD $ret+0(FP), R1 // address of 16-byte return value
-       WORD $0xb9296024    // cipher message with authentication (KMA)
+       KMA  R6, R2, R4     // cipher message with authentication (KMA)
        RET
 
 // func kimdQuery() queryResult