summaryrefslogtreecommitdiff
path: root/crypto/perlasm
diff options
context:
space:
mode:
authorChristoph Müllner <christoph.muellner@vrull.eu>2023-02-01 00:20:43 +0100
committerPauli <pauli@openssl.org>2023-03-16 13:12:19 +1100
commitac97cd6005878700653d8e50b6e7319728c523a1 (patch)
tree9143af0da8fc6bd1210fc3a64e42d07a312cd835 /crypto/perlasm
parentc8a641c39f524051900feac7175ca7300f151f85 (diff)
downloadopenssl-new-ac97cd6005878700653d8e50b6e7319728c523a1.tar.gz
riscv.pm: Add improved error messages to read_reg code
On systems where Devel::StackTrace is available, we can use this module to create more usable error messages. Further, don't print error messages in case of official register aliases, but simply accept them. Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20078)
Diffstat (limited to 'crypto/perlasm')
-rw-r--r--crypto/perlasm/riscv.pm26
1 files changed, 24 insertions, 2 deletions
diff --git a/crypto/perlasm/riscv.pm b/crypto/perlasm/riscv.pm
index 384ac5f385..6f862210ff 100644
--- a/crypto/perlasm/riscv.pm
+++ b/crypto/perlasm/riscv.pm
@@ -9,20 +9,42 @@
use strict;
use warnings;
+# Set $have_stacktrace to 1 if we have Devel::StackTrace
+my $have_stacktrace = 0;
+if (eval {require Devel::StackTrace;1;}) {
+ $have_stacktrace = 1;
+}
+
my @regs = map("x$_",(0..31));
+# Mapping from the RISC-V psABI ABI mnemonic names to the register number.
+my @regaliases = ('zero','ra','sp','gp','tp','t0','t1','t2','s0','s1',
+ map("a$_",(0..7)),
+ map("s$_",(2..11)),
+ map("t$_",(3..6))
+);
+
my %reglookup;
@reglookup{@regs} = @regs;
+@reglookup{@regaliases} = @regs;
# Takes a register name, possibly an alias, and converts it to a register index
# from 0 to 31
sub read_reg {
my $reg = lc shift;
if (!exists($reglookup{$reg})) {
- die("Unknown register ".$reg);
+ my $trace = "";
+ if ($have_stacktrace) {
+ $trace = Devel::StackTrace->new->as_string;
+ }
+ die("Unknown register ".$reg."\n".$trace);
}
my $regstr = $reglookup{$reg};
if (!($regstr =~ /^x([0-9]+)$/)) {
- die("Could not process register ".$reg);
+ my $trace = "";
+ if ($have_stacktrace) {
+ $trace = Devel::StackTrace->new->as_string;
+ }
+ die("Could not process register ".$reg."\n".$trace);
}
return $1;
}