]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/riscvcap.c
db75c21b2895c34cd98166535ef484bd5d87b616
2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 #include <openssl/crypto.h>
15 #include "internal/cryptlib.h"
17 #define OPENSSL_RISCVCAP_IMPL
18 #include "crypto/riscv_arch.h"
20 extern size_t riscv_vlen_asm(void);
22 static void parse_env(const char *envstr
);
23 static void strtoupper(char *str
);
25 static size_t vlen
= 0;
27 uint32_t OPENSSL_rdtsc(void)
32 size_t OPENSSL_instrument_bus(unsigned int *out
, size_t cnt
)
37 size_t OPENSSL_instrument_bus2(unsigned int *out
, size_t cnt
, size_t max
)
42 static void strtoupper(char *str
)
44 for (char *x
= str
; *x
; ++x
)
48 /* parse_env() parses a RISC-V architecture string. An example of such a string
49 * is "rv64gc_zba_zbb_zbc_zbs". Currently, the rv64gc part is ignored
50 * and we simply search for "_[extension]" in the arch string to see if we
51 * should enable a given extension.
54 static void parse_env(const char *envstr
)
56 char envstrupper
[BUFLEN
];
59 /* Convert env str to all uppercase */
60 OPENSSL_strlcpy(envstrupper
, envstr
, sizeof(envstrupper
));
61 strtoupper(envstrupper
);
63 for (size_t i
= 0; i
< kRISCVNumCaps
; ++i
) {
64 /* Prefix capability with underscore in preparation for search */
65 BIO_snprintf(buf
, BUFLEN
, "_%s", RISCV_capabilities
[i
].name
);
66 if (strstr(envstrupper
, buf
) != NULL
) {
67 /* Match, set relevant bit in OPENSSL_riscvcap_P[] */
68 OPENSSL_riscvcap_P
[RISCV_capabilities
[i
].index
] |=
69 (1 << RISCV_capabilities
[i
].bit_offset
);
74 size_t riscv_vlen(void)
79 # if defined(__GNUC__) && __GNUC__>=2
80 __attribute__ ((constructor
))
82 void OPENSSL_cpuid_setup(void)
85 static int trigger
= 0;
91 if ((e
= getenv("OPENSSL_riscvcap"))) {
96 vlen
= riscv_vlen_asm();