diff mbox series

[v3,06/10] firmware: fw_base: Simplified setup trap handler

Message ID 20240117104212.1055737-7-wxjstz@126.com
State Changes Requested
Headers show
Series Improvements to fw_base.S | expand

Commit Message

Xiang W Jan. 17, 2024, 10:42 a.m. UTC
The same detection was done twice when setting mtvec and trap_exit.
Merging can reduce code size.

Signed-off-by: Xiang W <wxjstz@126.com>
---
 firmware/fw_base.S | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Comments

Anup Patel Feb. 6, 2024, 7:41 a.m. UTC | #1
On Wed, Jan 17, 2024 at 4:12 PM Xiang W <wxjstz@126.com> wrote:
>
> The same detection was done twice when setting mtvec and trap_exit.
> Merging can reduce code size.
>
> Signed-off-by: Xiang W <wxjstz@126.com>

Looks good to me.

Reviewed-by: Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
>  firmware/fw_base.S | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/firmware/fw_base.S b/firmware/fw_base.S
> index 7c7157d..d4a6d3a 100644
> --- a/firmware/fw_base.S
> +++ b/firmware/fw_base.S
> @@ -452,22 +452,14 @@ _start_warm:
>         srli    a5, a5, ('H' - 'A')
>         andi    a5, a5, 0x1
>         beq     a5, zero, _skip_trap_handler_rv32_hyp
> -       lla     a4, _trap_handler_rv32_hyp
> -_skip_trap_handler_rv32_hyp:
> -#endif
> -       csrw    CSR_MTVEC, a4
> -
> -#if __riscv_xlen == 32
>         /* Override trap exit for H-extension */
> -       csrr    a5, CSR_MISA
> -       srli    a5, a5, ('H' - 'A')
> -       andi    a5, a5, 0x1
> -       beq     a5, zero, _skip_trap_exit_rv32_hyp
> -       lla     a4, _trap_exit_rv32_hyp
>         csrr    a5, CSR_MSCRATCH
> +       lla     a4, _trap_exit_rv32_hyp
>         REG_S   a4, SBI_SCRATCH_TRAP_EXIT_OFFSET(a5)
> -_skip_trap_exit_rv32_hyp:
> +       lla     a4, _trap_handler_rv32_hyp
> +_skip_trap_handler_rv32_hyp:
>  #endif
> +       csrw    CSR_MTVEC, a4
>
>         /* Initialize SBI runtime */
>         csrr    a0, CSR_MSCRATCH
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
diff mbox series

Patch

diff --git a/firmware/fw_base.S b/firmware/fw_base.S
index 7c7157d..d4a6d3a 100644
--- a/firmware/fw_base.S
+++ b/firmware/fw_base.S
@@ -452,22 +452,14 @@  _start_warm:
 	srli	a5, a5, ('H' - 'A')
 	andi	a5, a5, 0x1
 	beq	a5, zero, _skip_trap_handler_rv32_hyp
-	lla	a4, _trap_handler_rv32_hyp
-_skip_trap_handler_rv32_hyp:
-#endif
-	csrw	CSR_MTVEC, a4
-
-#if __riscv_xlen == 32
 	/* Override trap exit for H-extension */
-	csrr	a5, CSR_MISA
-	srli	a5, a5, ('H' - 'A')
-	andi	a5, a5, 0x1
-	beq	a5, zero, _skip_trap_exit_rv32_hyp
-	lla	a4, _trap_exit_rv32_hyp
 	csrr	a5, CSR_MSCRATCH
+	lla	a4, _trap_exit_rv32_hyp
 	REG_S	a4, SBI_SCRATCH_TRAP_EXIT_OFFSET(a5)
-_skip_trap_exit_rv32_hyp:
+	lla	a4, _trap_handler_rv32_hyp
+_skip_trap_handler_rv32_hyp:
 #endif
+	csrw	CSR_MTVEC, a4
 
 	/* Initialize SBI runtime */
 	csrr	a0, CSR_MSCRATCH