diff mbox series

[U-Boot,v3,1/2] arm: print instructions pointed to by pc

Message ID 20180515174224.10270-2-xypron.glpk@gmx.de
State Accepted
Commit bd2a13f32959a851d43d9681d9dc9b8bb3eec398
Delegated to: Tom Rini
Headers show
Series arm: print instructions pointed to by pc | expand

Commit Message

Heinrich Schuchardt May 15, 2018, 5:42 p.m. UTC
If an exception occurs in a loaded image and the relocation offset is
unknown, it is helful to know the instructions pointed to by the
program counter. This patch adds the missing output.

A possible output is:
    Code: e1c560d0 e12fff1e e120077b e12fff1e (e7f7defb)

The parentheses indicate the instruction causing the exception.

The output can be disassembled using the decodecode script provided
by the Linux kernel project.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3:
	use the Linux output format for the 'Code:' line
---
 arch/arm/lib/interrupts.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Alexander Graf May 24, 2018, 8:54 a.m. UTC | #1
On 15.05.18 19:42, Heinrich Schuchardt wrote:
> If an exception occurs in a loaded image and the relocation offset is
> unknown, it is helful to know the instructions pointed to by the
> program counter. This patch adds the missing output.
> 
> A possible output is:
>     Code: e1c560d0 e12fff1e e120077b e12fff1e (e7f7defb)
> 
> The parentheses indicate the instruction causing the exception.
> 
> The output can be disassembled using the decodecode script provided
> by the Linux kernel project.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

This is even better than my suggestion. Aweseome ;).

Reviewed-by: Alexander Graf <agraf@suse.de>


Alex
Tom Rini May 24, 2018, 12:42 p.m. UTC | #2
On Tue, May 15, 2018 at 07:42:23PM +0200, Heinrich Schuchardt wrote:

> If an exception occurs in a loaded image and the relocation offset is
> unknown, it is helful to know the instructions pointed to by the
> program counter. This patch adds the missing output.
> 
> A possible output is:
>     Code: e1c560d0 e12fff1e e120077b e12fff1e (e7f7defb)
> 
> The parentheses indicate the instruction causing the exception.
> 
> The output can be disassembled using the decodecode script provided
> by the Linux kernel project.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/arch/arm/lib/interrupts.c b/arch/arm/lib/interrupts.c
index 28ba3f14f36..930b25ccb81 100644
--- a/arch/arm/lib/interrupts.c
+++ b/arch/arm/lib/interrupts.c
@@ -56,6 +56,30 @@  static void show_efi_loaded_images(struct pt_regs *regs)
 	efi_print_image_infos((void *)instruction_pointer(regs));
 }
 
+static void dump_instr(struct pt_regs *regs)
+{
+	unsigned long addr = instruction_pointer(regs);
+	const int thumb = thumb_mode(regs);
+	const int width = thumb ? 4 : 8;
+	int i;
+
+	if (thumb)
+		addr &= ~1L;
+	else
+		addr &= ~3L;
+	printf("Code: ");
+	for (i = -4; i < 1 + !!thumb; i++) {
+		unsigned int val;
+
+		if (thumb)
+			val = ((u16 *)addr)[i];
+		else
+			val = ((u32 *)addr)[i];
+		printf(i == 0 ? "(%0*x) " : "%0*x ", width, val);
+	}
+	printf("\n");
+}
+
 void show_regs (struct pt_regs *regs)
 {
 	unsigned long __maybe_unused flags;
@@ -96,6 +120,7 @@  void show_regs (struct pt_regs *regs)
 		fast_interrupts_enabled (regs) ? "on" : "off",
 		processor_modes[processor_mode (regs)],
 		thumb_mode (regs) ? " (T)" : "");
+	dump_instr(regs);
 }
 
 /* fixup PC to point to the instruction leading to the exception */