<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 22, 2021 at 12:53 PM Alex White <<a href="mailto:alex.white@oarcorp.com">alex.white@oarcorp.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">---<br>
.../aarch64/aarch64-exception-frame-print.c | 106 +++++++++++++++++-<br>
1 file changed, 102 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/cpukit/score/cpu/aarch64/aarch64-exception-frame-print.c b/cpukit/score/cpu/aarch64/aarch64-exception-frame-print.c<br>
index 59b5d06032..b22d99a0ca 100644<br>
--- a/cpukit/score/cpu/aarch64/aarch64-exception-frame-print.c<br>
+++ b/cpukit/score/cpu/aarch64/aarch64-exception-frame-print.c<br>
@@ -45,8 +45,91 @@<br>
#include <inttypes.h><br>
<br>
#include <rtems/score/cpu.h><br>
+#include <rtems/score/io.h><br>
#include <rtems/bspIo.h><br>
<br>
+static const char* _exception_class_to_string( uint16_t exception_class );<br>
+<br>
+static void _binary_sprintf(<br>
+ char *s,<br>
+ size_t maxlen,<br>
+ uint32_t num_bits,<br>
+ uint32_t value<br>
+);<br>
+<br>
+static const char* _exception_class_to_string( uint16_t exception_class )<br>
+{<br>
+ switch (exception_class)<br>
+ {<br>
+ case 0b000001: return "Trapped WFI or WFE instruction";<br>
+ case 0b000011: return "Trapped MCR or MRC access with (coproc==0b1111)";<br>
+ case 0b000100: return "Trapped MCRR or MRRC access with (coproc==0b1111)";<br>
+ case 0b000101: return "Trapped MCR or MRC access with (coproc==0b1110)";<br>
+ case 0b000110: return "Trapped LDC or STC access";<br>
+ case 0b001100: return "Trapped MRRC access with (coproc==0b1110)";<br>
+ case 0b001110: return "Illegal Execution state";<br>
+ case 0b011000: return "Trapped MSR, MRS, or System instruction";<br>
+ case 0b100000: return "Instruction Abort from a lower Exception level";<br>
+ case 0b100001: return "Instruction Abort taken without a change in Exception "<br>
+ "level";<br>
+ case 0b100010: return "PC alignment fault";<br>
+ case 0b100100: return "Data Abort from a lower Exception level";<br>
+ case 0b100101: return "Data Abort taken without a change in Exception level";<br>
+ case 0b100110: return "SP alignment fault";<br>
+ case 0b110000: return "Breakpoint exception from a lower Exception level";<br>
+ case 0b110001: return "Breakpoint exception taken without a change in "<br>
+ "Exception level";<br>
+ case 0b110010: return "Software Step exception from a lower Exception level";<br>
+ case 0b110011: return "Software Step exception taken without a change in "<br>
+ "Exception level";<br>
+ case 0b110100: return "Watchpoint exception from a lower Exception level";<br>
+ case 0b110101: return "Watchpoint exception taken without a change in "<br>
+ "Exception level";<br>
+ case 0b111000: return "BKPT instruction execution in AArch32 state";<br>
+ case 0b111100: return "BRK instruction execution in AArch64 state";<br></blockquote><div><br></div><div>Before someone else asks...</div><div><br></div><div>(1) Are binary constants standard C? The stackover flow discussion I found</div><div>says they are a GNU extension which puts them off-limits.</div><div><br></div><div>(2). These appear to be 6 bits and there is nothing ensuring only those six </div><div>bits are set before the switch. Is there a chance other bits could be set </div><div>messing up this switch?</div><div><br></div><div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ default: return "Unknown";<br>
+ }<br>
+}<br>
+<br>
+typedef struct {<br>
+ char *s;<br>
+ size_t n;<br>
+} string_context;<br>
+<br>
+static void put_char(int c, void *arg)<br>
+{<br>
+ string_context *sctx = arg;<br>
+ size_t n = sctx->n;<br>
+<br>
+ if (n > 0) {<br>
+ char *s = sctx->s;<br>
+ *s = (char)c;<br>
+ sctx->s = s + 1;<br>
+ sctx->n = n - 1;<br>
+ }<br>
+}<br>
+<br>
+static void _binary_sprintf(<br>
+ char *s,<br>
+ size_t maxlen,<br>
+ uint32_t num_bits,<br>
+ uint32_t value<br>
+)<br>
+{<br>
+ string_context sctx = {<br>
+ .s = s,<br>
+ .n = maxlen<br>
+ };<br>
+ uint32_t mask = 1<<(num_bits-1);<br>
+ int cx = 0;<br>
+<br>
+ while ( mask != 0 ) {<br>
+ cx += _IO_Printf(put_char, &sctx, "%d", (value & mask ? 1 : 0));<br>
+ //cx += snprintf(s + cx, maxlen - cx, "%d", (value&mask ? 1 : 0));<br></blockquote><div><br></div><div>Commented out.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ mask >>= 1;<br>
+ }<br>
+}<br>
+<br>
void _CPU_Exception_frame_print( const CPU_Exception_frame *frame )<br>
{<br>
printk(<br>
@@ -68,8 +151,7 @@ void _CPU_Exception_frame_print( const CPU_Exception_frame *frame )<br>
"X14 = 0x%016" PRIx64 " SP = 0x%016" PRIxPTR "\n"<br>
"X15 = 0x%016" PRIx64 " PC = 0x%016" PRIxPTR "\n"<br>
"X16 = 0x%016" PRIx64 " DAIF = 0x%016" PRIx64 "\n"<br>
- "VEC = 0x%016" PRIxPTR " CPSR = 0x%016" PRIx64 "\n"<br>
- "ESR = 0x%016" PRIx64 " FAR = 0x%016" PRIx64 "\n",<br>
+ "VEC = 0x%016" PRIxPTR " CPSR = 0x%016" PRIx64 "\n",<br>
frame->register_x0, frame->register_x17,<br>
frame->register_x1, frame->register_x18,<br>
frame->register_x2, frame->register_x19,<br>
@@ -87,10 +169,26 @@ void _CPU_Exception_frame_print( const CPU_Exception_frame *frame )<br>
frame->register_x14, (intptr_t)frame->register_sp,<br>
frame->register_x15, (intptr_t)frame->register_pc,<br>
frame->register_x16, frame->register_daif,<br>
- (intptr_t) frame->vector, frame->register_cpsr,<br>
- frame->register_syndrome, frame->register_fault_address<br>
+ (intptr_t) frame->vector, frame->register_cpsr<br>
);<br>
<br>
+ uint32_t ec = (frame->register_syndrome >> 26) & 0x3f;<br>
+ uint32_t il = (frame->register_syndrome >> 25) & 0x1;<br>
+ uint32_t iss = frame->register_syndrome & 0x1ffffff;<br>
+ char ec_str[7] = {0};<br>
+ char iss_str[26] = {0};<br>
+<br>
+ _binary_sprintf(ec_str, 7, 6, ec);<br>
+ _binary_sprintf(iss_str, 26, 25, iss);<br>
+<br>
+ printk(<br>
+ "ESR = EC: 0b%s" " IL: 0b%d" " ISS: 0b%s" "\n"<br>
+ " %s\n",<br>
+ ec_str, il, iss_str, _exception_class_to_string(ec)<br>
+ );<br>
+<br>
+ printk( "FAR = 0x%016" PRIx64 "\n", frame->register_fault_address );<br>
+<br>
const uint128_t *qx = &frame->register_q0;<br>
int i;<br>
<br>
-- <br>
2.27.0<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>