riscv: use simplest asm expression when possible
Let's take advantage of assembler pseudoinstructions: - convert `addi rd, rs, 0` to `mv rd, rs` - convert `jal x0, somewhere` to `j somewhere` - convert `csrrs x0, csrreg, rs` to `csrs csrreg, rs` - convert `fscsr x0, rs` to `fscsr rs` And simplify zero offsets to simply 0. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
f2bb937547
commit
9ed17943b9
3 changed files with 18 additions and 18 deletions
|
@ -66,7 +66,7 @@
|
||||||
|
|
||||||
#define LOAD_FP_CALLEE_SAVED(reg) \
|
#define LOAD_FP_CALLEE_SAVED(reg) \
|
||||||
RV_OP_LOADREG t2, _thread_offset_to_fcsr(reg) ;\
|
RV_OP_LOADREG t2, _thread_offset_to_fcsr(reg) ;\
|
||||||
fscsr x0, t2 ;\
|
fscsr t2 ;\
|
||||||
DO_FP_CALLEE_SAVED(RV_OP_LOADFPREG, reg)
|
DO_FP_CALLEE_SAVED(RV_OP_LOADFPREG, reg)
|
||||||
|
|
||||||
#define COPY_ESF_FP_STATE(to_reg, from_reg, temp) \
|
#define COPY_ESF_FP_STATE(to_reg, from_reg, temp) \
|
||||||
|
@ -362,7 +362,7 @@ skip_store_fp_callee_saved_user:
|
||||||
is_priv_sp:
|
is_priv_sp:
|
||||||
/* Clear user mode variable */
|
/* Clear user mode variable */
|
||||||
la t0, is_user_mode
|
la t0, is_user_mode
|
||||||
sb zero, 0x00(t0)
|
sb zero, 0(t0)
|
||||||
#endif /* CONFIG_USERSPACE */
|
#endif /* CONFIG_USERSPACE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -378,13 +378,13 @@ is_priv_sp:
|
||||||
jal ra, __soc_is_irq
|
jal ra, __soc_is_irq
|
||||||
|
|
||||||
/* If a0 != 0, jump to is_interrupt */
|
/* If a0 != 0, jump to is_interrupt */
|
||||||
addi t1, x0, 0
|
mv t1, zero
|
||||||
bnez a0, is_interrupt
|
bnez a0, is_interrupt
|
||||||
|
|
||||||
#ifdef CONFIG_USERSPACE
|
#ifdef CONFIG_USERSPACE
|
||||||
/* Reset IRQ flag */
|
/* Reset IRQ flag */
|
||||||
la t1, irq_flag
|
la t1, irq_flag
|
||||||
sb zero, 0x00(t1)
|
sb zero, 0(t1)
|
||||||
#endif /* CONFIG_USERSPACE */
|
#endif /* CONFIG_USERSPACE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -420,7 +420,7 @@ is_priv_sp:
|
||||||
* If _Fault shall return, set return address to
|
* If _Fault shall return, set return address to
|
||||||
* no_reschedule to restore stack.
|
* no_reschedule to restore stack.
|
||||||
*/
|
*/
|
||||||
addi a0, sp, 0
|
mv a0, sp
|
||||||
|
|
||||||
#ifdef CONFIG_USERSPACE
|
#ifdef CONFIG_USERSPACE
|
||||||
/* Check if we are in user thread */
|
/* Check if we are in user thread */
|
||||||
|
@ -654,7 +654,7 @@ is_interrupt:
|
||||||
#ifdef CONFIG_USERSPACE
|
#ifdef CONFIG_USERSPACE
|
||||||
la t0, irq_flag
|
la t0, irq_flag
|
||||||
li t2, 0x1
|
li t2, 0x1
|
||||||
sb t2, 0x00(t0)
|
sb t2, 0(t0)
|
||||||
#endif /* CONFIG_USERSPACE */
|
#endif /* CONFIG_USERSPACE */
|
||||||
|
|
||||||
#if (CONFIG_USERSPACE == 0) && (CONFIG_PMP_STACK_GUARD == 0)
|
#if (CONFIG_USERSPACE == 0) && (CONFIG_PMP_STACK_GUARD == 0)
|
||||||
|
@ -664,7 +664,7 @@ is_interrupt:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Save thread stack pointer to temp register t0 */
|
/* Save thread stack pointer to temp register t0 */
|
||||||
addi t0, sp, 0
|
mv t0, sp
|
||||||
|
|
||||||
/* Switch to interrupt stack */
|
/* Switch to interrupt stack */
|
||||||
la t2, _kernel
|
la t2, _kernel
|
||||||
|
@ -747,7 +747,7 @@ on_thread_stack:
|
||||||
#if !defined(CONFIG_USERSPACE) && !defined(CONFIG_PMP_STACK_GUARD)
|
#if !defined(CONFIG_USERSPACE) && !defined(CONFIG_PMP_STACK_GUARD)
|
||||||
/* Restore thread stack pointer */
|
/* Restore thread stack pointer */
|
||||||
RV_OP_LOADREG t0, 0x00(sp)
|
RV_OP_LOADREG t0, 0x00(sp)
|
||||||
addi sp, t0, 0
|
mv sp, t0
|
||||||
#endif /* !CONFIG_USERSPACE && !CONFIG_PMP_STACK_GUARD */
|
#endif /* !CONFIG_USERSPACE && !CONFIG_PMP_STACK_GUARD */
|
||||||
|
|
||||||
#ifdef CONFIG_STACK_SENTINEL
|
#ifdef CONFIG_STACK_SENTINEL
|
||||||
|
@ -886,7 +886,7 @@ skip_callee_saved_reg:
|
||||||
*/
|
*/
|
||||||
RV_OP_STOREREG sp, _thread_offset_to_sp(t1)
|
RV_OP_STOREREG sp, _thread_offset_to_sp(t1)
|
||||||
la t2, _k_neg_eagain
|
la t2, _k_neg_eagain
|
||||||
lw t3, 0x00(t2)
|
lw t3, 0(t2)
|
||||||
sw t3, _thread_offset_to_swap_return_value(t1)
|
sw t3, _thread_offset_to_swap_return_value(t1)
|
||||||
|
|
||||||
/* Get next thread to schedule. */
|
/* Get next thread to schedule. */
|
||||||
|
@ -916,7 +916,7 @@ skip_callee_saved_reg:
|
||||||
* mstatus will be restored later on.
|
* mstatus will be restored later on.
|
||||||
*/
|
*/
|
||||||
li t2, MSTATUS_FS_INIT
|
li t2, MSTATUS_FS_INIT
|
||||||
csrrs x0, mstatus, t2
|
csrs mstatus, t2
|
||||||
|
|
||||||
LOAD_FP_CALLEE_SAVED(t1)
|
LOAD_FP_CALLEE_SAVED(t1)
|
||||||
|
|
||||||
|
@ -956,7 +956,7 @@ skip_load_fp_callee_saved:
|
||||||
/* Set user mode variable */
|
/* Set user mode variable */
|
||||||
li t2, 0x1
|
li t2, 0x1
|
||||||
la t3, is_user_mode
|
la t3, is_user_mode
|
||||||
sb t2, 0x00(t3)
|
sb t2, 0(t3)
|
||||||
|
|
||||||
kernel_swap:
|
kernel_swap:
|
||||||
#endif /* CONFIG_USERSPACE */
|
#endif /* CONFIG_USERSPACE */
|
||||||
|
@ -1025,10 +1025,10 @@ no_reschedule:
|
||||||
/* Set user mode variable */
|
/* Set user mode variable */
|
||||||
li t1, 0x1
|
li t1, 0x1
|
||||||
la t0, is_user_mode
|
la t0, is_user_mode
|
||||||
sb t1, 0x00(t0)
|
sb t1, 0(t0)
|
||||||
|
|
||||||
la t0, irq_flag
|
la t0, irq_flag
|
||||||
lb t0, 0x00(t0)
|
lb t0, 0(t0)
|
||||||
bnez t0, no_enter_user
|
bnez t0, no_enter_user
|
||||||
|
|
||||||
/* Clear ESF saved in User Stack */
|
/* Clear ESF saved in User Stack */
|
||||||
|
|
|
@ -52,14 +52,14 @@ boot_first_core:
|
||||||
/*
|
/*
|
||||||
* Enable floating-point.
|
* Enable floating-point.
|
||||||
*/
|
*/
|
||||||
li t0, MSTATUS_FS_INIT
|
li t0, MSTATUS_FS_INIT
|
||||||
csrrs x0, mstatus, t0
|
csrs mstatus, t0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Floating-point rounding mode set to IEEE-754 default, and clear
|
* Floating-point rounding mode set to IEEE-754 default, and clear
|
||||||
* all exception flags.
|
* all exception flags.
|
||||||
*/
|
*/
|
||||||
fscsr x0, x0
|
fscsr zero
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_INIT_STACKS
|
#ifdef CONFIG_INIT_STACKS
|
||||||
|
|
|
@ -51,7 +51,7 @@ SECTION_FUNC(exception.other, arch_swap)
|
||||||
csrrs t0, mstatus, a0
|
csrrs t0, mstatus, a0
|
||||||
|
|
||||||
/* Set value of return register a0 to value of register t2 */
|
/* Set value of return register a0 to value of register t2 */
|
||||||
addi a0, t2, 0
|
mv a0, t2
|
||||||
|
|
||||||
/* Return */
|
/* Return */
|
||||||
ret
|
ret
|
||||||
|
@ -72,4 +72,4 @@ SECTION_FUNC(TEXT, z_thread_entry_wrapper)
|
||||||
* return address set to 0 to indicate a non-returning function call.
|
* return address set to 0 to indicate a non-returning function call.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
jal x0, z_thread_entry
|
j z_thread_entry
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue