diff mbox series

[kvm-unit-tests,2/2] arm64: Output PC load offset on unhandled exceptions

Message ID 20210325155657.600897-3-drjones@redhat.com (mailing list archive)
State New, archived
Headers show
Series arm64: One fix and one improvement | expand

Commit Message

Andrew Jones March 25, 2021, 3:56 p.m. UTC
Since for arm64 we can load the unit tests at different addresses,
then let's make it easier to debug by calculating the PC offset for
the user. The offset can then be directly used when looking at the
disassembly of the test's elf file.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/flat.lds          | 1 +
 lib/arm64/processor.c | 7 +++++++
 2 files changed, 8 insertions(+)

Comments

Nikos Nikoleris March 25, 2021, 4:20 p.m. UTC | #1
On 25/03/2021 15:56, Andrew Jones wrote:
> Since for arm64 we can load the unit tests at different addresses,
> then let's make it easier to debug by calculating the PC offset for
> the user. The offset can then be directly used when looking at the
> disassembly of the test's elf file.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>

> ---
>   arm/flat.lds          | 1 +
>   lib/arm64/processor.c | 7 +++++++
>   2 files changed, 8 insertions(+)
> 
> diff --git a/arm/flat.lds b/arm/flat.lds
> index 4d43cdfeab41..6ed377c0eaa0 100644
> --- a/arm/flat.lds
> +++ b/arm/flat.lds
> @@ -1,6 +1,7 @@
>   
>   SECTIONS
>   {
> +    PROVIDE(_text = .);
>       .text : { *(.init) *(.text) *(.text.*) }
>       . = ALIGN(64K);
>       PROVIDE(etext = .);
> diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c
> index ef558625e284..831207c16587 100644
> --- a/lib/arm64/processor.c
> +++ b/lib/arm64/processor.c
> @@ -99,12 +99,19 @@ bool get_far(unsigned int esr, unsigned long *far)
>   	return false;
>   }
>   
> +extern unsigned long _text;
> +
>   static void bad_exception(enum vector v, struct pt_regs *regs,
>   			  unsigned int esr, bool esr_valid, bool bad_vector)
>   {
>   	unsigned long far;
>   	bool far_valid = get_far(esr, &far);
>   	unsigned int ec = esr >> ESR_EL1_EC_SHIFT;
> +	uintptr_t text = (uintptr_t)&_text;
> +
> +	printf("Load address: %" PRIxPTR "\n", text);
> +	printf("PC: %" PRIxPTR " PC offset: %" PRIxPTR "\n",
> +	       (uintptr_t)regs->pc, (uintptr_t)regs->pc - text);
>   
>   	if (bad_vector) {
>   		if (v < VECTOR_MAX)
>
diff mbox series

Patch

diff --git a/arm/flat.lds b/arm/flat.lds
index 4d43cdfeab41..6ed377c0eaa0 100644
--- a/arm/flat.lds
+++ b/arm/flat.lds
@@ -1,6 +1,7 @@ 
 
 SECTIONS
 {
+    PROVIDE(_text = .);
     .text : { *(.init) *(.text) *(.text.*) }
     . = ALIGN(64K);
     PROVIDE(etext = .);
diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c
index ef558625e284..831207c16587 100644
--- a/lib/arm64/processor.c
+++ b/lib/arm64/processor.c
@@ -99,12 +99,19 @@  bool get_far(unsigned int esr, unsigned long *far)
 	return false;
 }
 
+extern unsigned long _text;
+
 static void bad_exception(enum vector v, struct pt_regs *regs,
 			  unsigned int esr, bool esr_valid, bool bad_vector)
 {
 	unsigned long far;
 	bool far_valid = get_far(esr, &far);
 	unsigned int ec = esr >> ESR_EL1_EC_SHIFT;
+	uintptr_t text = (uintptr_t)&_text;
+
+	printf("Load address: %" PRIxPTR "\n", text);
+	printf("PC: %" PRIxPTR " PC offset: %" PRIxPTR "\n",
+	       (uintptr_t)regs->pc, (uintptr_t)regs->pc - text);
 
 	if (bad_vector) {
 		if (v < VECTOR_MAX)