refactor(bl31): use elx_panic for sysreg_handler64

When we reach sysreg_handler64 from any trap handling we are entering
this path from lower EL and thus we should be calling lower_el_panic
reporting mechanism to print panic report.

Make report_elx_panic available through assembly func elx_panic which
could be used for reporting any lower_el_panic.

Change-Id: Ieb260cf20ea327a59db84198b2c6a6bfc9ca9537
Signed-off-by: Govindraj Raja <govindraj.raja@arm.com>
diff --git a/bl31/aarch64/runtime_exceptions.S b/bl31/aarch64/runtime_exceptions.S
index cf79361..2f00e7a 100644
--- a/bl31/aarch64/runtime_exceptions.S
+++ b/bl31/aarch64/runtime_exceptions.S
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2022, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2023, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -563,7 +563,7 @@
 	 */
 
 	tst	w0, w0
-	b.mi	el3_panic	/* negative return value: panic */
+	b.mi	elx_panic	/* negative return value: panic */
 	b.eq	1f		/* zero: do not change ELR_EL3 */
 
 	/* advance the PC to continue after the instruction */
diff --git a/common/aarch64/debug.S b/common/aarch64/debug.S
index 82d57d7..8768a1f 100644
--- a/common/aarch64/debug.S
+++ b/common/aarch64/debug.S
@@ -14,6 +14,7 @@
 	.globl	asm_print_newline
 	.globl	asm_assert
 	.globl	el3_panic
+	.globl	elx_panic
 
 /* Since the max decimal input number is 65536 */
 #define MAX_DEC_DIVISOR		10000
@@ -151,6 +152,14 @@
 .section .rodata.panic_str, "aS"
 	panic_msg: .asciz "PANIC at PC : 0x"
 
+func elx_panic
+#if CRASH_REPORTING && defined(IMAGE_BL31)
+	b	report_elx_panic
+#endif /* CRASH_REPORTING && IMAGE_BL31 */
+
+	b	panic_common
+endfunc elx_panic
+
 /* ---------------------------------------------------------------------------
  * el3_panic assumes that it is invoked from a C Runtime Environment ie a
  * valid stack exists. This call will not return.
@@ -163,6 +172,7 @@
 	b	report_el3_panic
 #endif /* CRASH_REPORTING && IMAGE_BL31 */
 
+panic_common:
 	mov	x6, x30
 	bl	plat_crash_console_init
 
@@ -189,4 +199,4 @@
 	mov	x30, x6
 	b	plat_panic_handler
 
-endfunc el3_panic
\ No newline at end of file
+endfunc el3_panic
diff --git a/docs/getting_started/porting-guide.rst b/docs/getting_started/porting-guide.rst
index 98568cd..6ac284b 100644
--- a/docs/getting_started/porting-guide.rst
+++ b/docs/getting_started/porting-guide.rst
@@ -3204,6 +3204,17 @@
 
 Common helper functions
 -----------------------
+Function : elx_panic()
+~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+    Argument : void
+    Return   : void
+
+This API is called from assembly files when reporting a critical failure
+that has occured in lower EL and is been trapped in EL3. This call
+**must not** return.
 
 Function : el3_panic()
 ~~~~~~~~~~~~~~~~~~~~~~
@@ -3539,7 +3550,7 @@
 
 --------------
 
-*Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.*
+*Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.*
 
 .. _PSCI: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
 .. _Arm Generic Interrupt Controller version 2.0 (GICv2): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html
diff --git a/include/common/debug.h b/include/common/debug.h
index e0b3a1c..5ea541d 100644
--- a/include/common/debug.h
+++ b/include/common/debug.h
@@ -100,7 +100,7 @@
 #endif
 
 void __dead2 el3_panic(void);
-void __dead2 report_elx_panic(void);
+void __dead2 elx_panic(void);
 
 #define panic()				\
 	do {				\
@@ -118,7 +118,7 @@
 #define	lower_el_panic()		\
 	do {				\
 		console_flush();	\
-		report_elx_panic();	\
+		elx_panic();		\
 	} while (false)
 #else
 #define	lower_el_panic()