Skip to contentSkip to conversation

Script for decoding PSR in oopses

Linux-ia64 Peter Chubb 6 participants 9 messages Jan 31, 2003 – Feb 10, 2003

lore
Share & tools
lore
#0 lore raw

hi,
I find trying to work out what the PSR is after an oops to be
a bit of a pain, so here's an awk script to do it for you.

Usage is
decode_psr hex_number
if you save the script as decode_psr.

#!/bin/sh
echo $1 | awk '

function readhex(hexval, i, digits, value, ndigit) {

	 tolower(hexval);

	 ndigit = gsub("[a-f0-9]", " &", hexval);
	 split(hexval, digits, " ");


	 value = 0;
	 for ( i = 1; i <= ndigit; i++) {
	     value *= 16;
	     value += values[digits[i]];
	 }
	 return value;
}
function decode_psr(psr,   decoded, cpl) {
	 psr = int(psr / 2);
	 if (psr % 2 == 1)
	    decoded = "be "
	 psr = int(psr / 2);
	 if (psr % 2 == 1)
	    decoded = decoded "up "
	 psr = int(psr / 2);
	 if (psr % 2 == 1)
	    decoded = decoded "ac "
	 psr = int(psr / 2);
	 if (psr % 2 == 1)
	    decoded = decoded "mfl "
	 psr = int(psr / 2);
	 if (psr % 2 == 1)
	    decoded = decoded "mfh "
	 psr = int(psr / 256);
	 if (psr % 2)
	    decoded = decoded "ic "

	 psr = int(psr / 2);
	 if (psr % 2 == 1)
	    decoded = decoded "i "
	 psr = int(psr / 2);
	 if (psr % 2 == 1)
	    decoded = decoded "pk "
	 psr = int(psr / 4)
	 if (psr % 2 == 1)
	    decoded = decoded "dt "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "dfl "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "dfh "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "sp "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "pp "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "di "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "si "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "db "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "lb "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "tb "
	 psr = int(psr / 2)
	 if (psr % 2 == 1)
	    decoded = decoded "rt "
	 psr = int(psr / 16)

	 cpl = psr % 4;
	 decoded = decoded "cpl=" cpl " "

	 psr = int(psr/4)
	 if (psr % 2)
	    decoded = decoded "IA32 "
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "mc "
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "it "
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "id "
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "da "
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "dd "
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "ss "
	 psr = int(psr / 2)
	 cpl = psr %4
	 decoded= decoded "ri=" cpl " "
	 psr = int(psr / 4)
	 if (psr % 2)
	    decoded = decoded "ed "
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "bn"
	 psr = int(psr / 2)
	 if (psr % 2)
	    decoded = decoded "ia"

	 psr = int(psr / 2)
	 if (psr)
	    decoded = decoded "Reserved = " psr

	 return decoded
}
BEGIN {
      for (i = 0; i < 10; i++)
	  values[i ""] = i;
      values["a"] = 10;	
      values["b"] = 11;	
      values["c"] = 12;	
      values["d"] = 13;	
      values["e"] = 14;	
      values["f"] = 15;	

}

	{ print $1, decode_psr(readhex($1)) }

'

#1 lore raw
Quoted 6 lines · Peter Chubb

I find trying to work out what the PSR is after an oops to be
a bit of a pain, so here's an awk script to do it for you.

Usage is
decode_psr hex_number
if you save the script as decode_psr.

Below are Perl ia64_psr and ia64_isr. Run as
echo hex_number | ia64_[pi]sr

== ia64_psr =
#!/usr/bin/perl -w
use strict;
use integer;

my @fields = (

	[ 0, 6, "User mask" ],
	[ 0, 1, "rv" ],
	[ 1, 1, "be" ],
	[ 2, 1, "up" ],
	[ 3, 1, "ac" ],
	[ 4, 1, "mfl" ],
	[ 5, 1, "mfh" ],
	[ 0, 24, "System mask" ],
	[ 6, 6, "rv" ],
	[ 13, 1, "ic" ],
	[ 14, 1, "i" ],
	[ 15, 1, "pk" ],
	[ 16, 1, "rv" ],
	[ 17, 1, "dt" ],
	[ 18, 1, "dfl" ],
	[ 19, 1, "dfh" ],
	[ 20, 1, "sp" ],
	[ 21, 1, "pp" ],
	[ 22, 1, "di" ],
	[ 23, 1, "si" ],
	[ 24, 1, "db" ],
	[ 25, 1, "lp" ],
	[ 26, 1, "tb" ],
	[ 27, 1, "rt" ],
	[ 28, 4, "rv" ],
	[ 32, 2, "cpl" ],
	[ 34, 1, "is" ],
	[ 35, 1, "mc" ],
	[ 36, 1, "it" ],
	[ 37, 1, "id" ],
	[ 38, 1, "da" ],
	[ 39, 1, "dd" ],
	[ 40, 1, "ss" ],
	[ 41, 2, "ri" ],
	[ 43, 1, "ed" ],
	[ 44, 1, "bn" ],
	[ 45, 1, "ia" ],
	[ 46, 18, "rv" ]
	);
while (defined($_ = <STDIN>)) {
	chomp();
	my $w0 = hex(substr($_, 0, -8));
	my $w1 = hex(substr($_, -8));
	printf("psr %s\n", $_);
	&ia64_psr($w1, 0, 32);
	&ia64_psr($w0, 32, 64);
}

sub ia64_psr()

{
	my ($w, $s, $e) = @_;
	my $v;
	foreach (@fields) {
		next if ($_->[0] >= $e);
		next if ($_->[0] < $s);
		# use integer implies signed shift, I want unsigned
		no integer;
		$v = ($w >> ($_->[0] - $s)) & (~0 >> (32 - $_->[1]));
		printf("%2d %2d %12s %x\n", $_->[0], $_->[1], $_->[2], $v);
	}
}

== ia64_isr =
#!/usr/bin/perl -w
use strict;
use integer;

my @fields = (

	[ 0, 16, "Code" ],
	[ 16, 8, "Vector" ],
	[ 24, 8, "rv" ],
	[ 32, 1, "x" ],
	[ 33, 1, "w" ],
	[ 34, 1, "r" ],
	[ 35, 1, "na" ],
	[ 36, 1, "sp" ],
	[ 37, 1, "rs" ],
	[ 39, 1, "ni" ],
	[ 40, 1, "so" ],
	[ 41, 2, "ei" ],
	[ 43, 1, "ed" ],
	[ 44, 20, "rv" ],
	);
while (defined($_ = <STDIN>)) {
	chomp();
	my $w0 = hex(substr($_, 0, -8));
	my $w1 = hex(substr($_, -8));
	printf("isr %s\n", $_);
	&ia64_isr($w1, 0, 32);
	&ia64_isr($w0, 32, 64);
}

sub ia64_isr()

{
	my ($w, $s, $e) = @_;
	my $v;
	foreach (@fields) {
		next if ($_->[0] >= $e);
		next if ($_->[0] < $s);
		# use integer implies signed shift, I want unsigned
		no integer;
		$v = ($w >> ($_->[0] - $s)) & (~0 >> (32 - $_->[1]));
		printf("%2d %2d %12s %x\n", $_->[0], $_->[1], $_->[2], $v);
	}
}
#2 lore raw
In reply to Peter Chubb
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Keith Owens

Keith> On Fri, 31 Jan 2003 12:46:00 +1100, Peter Chubb

Quoted 5 lines · Keith> <[email protected]> wrote:
Quoted 5 lines

I find trying to work out what the PSR is after an oops to be a bit of a pain, so here's an awk script to do it for you.

Usage is decode_psr hex_number if you save the script as decode_psr.

Keith> Below are Perl ia64_psr and ia64_isr. Run as echo hex_number Keith> | ia64_[pi]sr

OK, now where is the Python version?? ;-))

	--david
#3 lore raw
In reply to Peter Chubb
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

"David" = David Mosberger <[email protected]> writes:

On Fri, 31 Jan 2003 13:10:58 +1100, Keith Owens <[email protected]> said:

Keith> On Fri, 31 Jan 2003 12:46:00 +1100, Peter Chubb

Quoted 5 lines · Keith> <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines

I find trying to work out what the PSR is after an oops to be a bit of a pain, so here's an awk script to do it for you.

Usage is decode_psr hex_number if you save the script as decode_psr.

Keith> Below are Perl ia64_psr and ia64_isr. Run as echo hex_number | Keith> ia64_[pi]sr

David> OK, now where is the Python version?? ;-))

Who cares? Once you've got a script you can use it.

BTW, there's a bug in the AWK script:

decode_psr renamed from decode_psr-old 2003-01-31 13:33:51.000000000 +1100 +1 -1
@@ -77,7 +77,7 @@
 	psr = int(psr / 2)
 	if (psr % 2 = 1)
 	   decoded = decoded "rt "
-	psr = int(psr / 16)
+	psr = int(psr / 32)
  
 	cpl = psr % 4;
 	decoded = decoded "cpl=" cpl " "
#4 lore raw
In reply to Peter Chubb
Quoted 4 lines

Keith> Below are Perl ia64_psr and ia64_isr. Run as echo hex_number Keith> | ia64_[pi]sr

OK, now where is the Python version?? ;-))

For once :-) the Perl isn't obtuse enough to
make it necessary. (grin)

#5 lore raw
In reply to Peter Chubb
Quoted 5 lines · Mats D

david mosberger wrote

Quoted 1 line

OK, now where is the Python version?? ;-))

For once :-) the Perl isn't obtuse enough to
make it necessary. (grin)

Damn! Now I have to return my "Perl Obfuscator" badge. OTOH, this bit from a Perl decoder for ia64 unwind data should reinstate my rating. <ducks and runs>

my @decode_type;

sub set_decode_type()

{
    my ($i, $mask, $type, $start, $end);
    for ($i = 0; $i < 256; ++$i) {
	$decode_type[0][$i] = '?';
	$decode_type[1][$i] = '?';
    }
    foreach (
	#       prologue                    body
	[ 0, '00-- ----', 'R1' ], [ 1, '00-- ----', 'R1' ],
	[ 0, '0100 0---', 'R2' ], [ 1, '0100 0---', 'R2' ],
	[ 0, '0110 00--', 'R3' ], [ 1, '0110 00--', 'R3' ],
	[ 0, '100- ----', 'P1' ],
	[ 0, '1010 ----', 'P2' ],
	[ 0, '1011 0---', 'P3' ],
	[ 0, '1011 1000', 'P4' ],
	[ 0, '1011 1001', 'P5' ],
	[ 0, '110- ----', 'P6' ],
	[ 0, '1110 ----', 'P7' ],
	[ 0, '1111 0000', 'P8' ],
	[ 0, '1111 0001', 'P9' ],
	[ 0, '1111 1001', 'X1' ],
	[ 0, '1111 1010', 'X2' ],
	[ 0, '1111 1011', 'X3' ],
	[ 0, '1111 1100', 'X4' ],
	[ 0, '1111 1111', 'P10' ],
				   [ 1, '10-- ----', 'B1' ],
				   [ 1, '110- ----', 'B2' ],
				   [ 1, '1110 0000', 'B3' ],	# manual only lists this form for B3 ...
				   [ 1, '1110 1010', 'ea' ],	# ... but this one is used as well :(
				   [ 1, '1111 0000', 'B4' ],
				   [ 1, '1111 1000', 'B4' ],
				   [ 1, '1111 1001', 'X1' ],
				   [ 1, '1111 1010', 'X2' ],
				   [ 1, '1111 1011', 'X3' ],
				   [ 1, '1111 1100', 'X4' ],
    ) {
	$mask = '0b' . $_->[1];
	$mask =~ s/ //g;
	$start = $end = $mask;
	$start =~ s/-/0/g;
	$end =~ s/-/1/g;
	for ($i = oct($start); $i <= oct($end); ++$i) {
	    if ($decode_type[$_->[0]][$i] ne '?') {
		die("$0 decode_type[$_->[0]][$i] already set to $decode_type[$_->[0]][$i], ignoring $_->[2]\n");
	    }
	    $decode_type[$_->[0]][$i] = $_->[2];
	}
    }
}
#6 lore raw
In reply to Peter Chubb
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · Peter Chubb

Usage is decode_psr hex_number if you save the script as decode_psr.

Keith> Below are Perl ia64_psr and ia64_isr. Run as echo hex_number Keith> ia64_[pi]sr

David> OK, now where is the Python version?? ;-))

Peter> Who cares? Once you've got a script you can use it.

Oh, man, are you one of those heathens who think that _any_ language will do??

	--david

PS: Sorry if my jokes aren't funny. Just couldn't resist... ;-)

#7 lore raw
In reply to Peter Chubb
Quoted 1 line · Peter

BTW, there's a bug in the AWK script:

There's also a bug in perl version of ia64_psr:

ia64_psr renamed from ia64_psr_orig +1 -1
@@ -11,7 +11,7 @@
 	[ 4, 1, "mfl" ],
 	[ 5, 1, "mfh" ],
 	[ 0, 24, "System mask" ],
-	[ 6, 6, "rv" ],
+	[ 6, 7, "rv" ],
 	[ 13, 1, "ic" ],
 	[ 14, 1, "i" ],
 	[ 15, 1, "pk" ],

-- Jim

#8 lore raw
In reply to Peter Chubb
Quoted 5 lines · Jim Hull
Quoted 1 line · Peter

BTW, there's a bug in the AWK script:

There's also a bug in perl version of ia64_psr:

And ia64_isr is missing ir:

ia64_isr Mon Feb 10 16:08:28 2003 renamed from ia64_isr.orig Mon Feb 10 16:03:42 2003 +1 -0
@@ -12,6 +12,7 @@
        [ 35, 1, "na" ],
        [ 36, 1, "sp" ],
        [ 37, 1, "rs" ],
+       [ 38, 1, "ir" ],
        [ 39, 1, "ni" ],
        [ 40, 1, "so" ],
        [ 41, 2, "ei" ],

Matt