Re: [PATCH 7/9] RISC-V: don't use x8/s0/fp in assembly

2022-01-10 Thread Antony Pavlov
On Sat, 8 Jan 2022 19:25:03 +0100
Ahmad Fatoum  wrote:

Hi Ahmad!

> Hello Antony,
> 
> On 08.01.22 18:15, Ahmad Fatoum wrote:
> > Free up the register to allow building a configuration with x8/s0 used
> > as the frame pointer.
> > 
> > Signed-off-by: Ahmad Fatoum 
> > ---
> >  arch/riscv/include/asm/debug_ll_litex.h   | 12 +++---
> >  arch/riscv/include/asm/debug_ll_ns16550.h |  8 ++--
> >  arch/riscv/include/asm/riscv_nmon.h   | 50 +++
> 
> I just bumped the s register: s2 -> s3, s1 -> s2, s0 -> s1 to
> clear s0. Is that ok?

I suppose that there is no problem if nmon still works under qemu.


> >  3 files changed, 35 insertions(+), 35 deletions(-)
> > 
> > diff --git a/arch/riscv/include/asm/debug_ll_litex.h 
> > b/arch/riscv/include/asm/debug_ll_litex.h
> > index 2fcdd9b0ec3e..295477fc1010 100644
> > --- a/arch/riscv/include/asm/debug_ll_litex.h
> > +++ b/arch/riscv/include/asm/debug_ll_litex.h
> > @@ -90,11 +90,11 @@ static inline void PUTC_LL(char ch)
> > li  t0, DEBUG_LL_UART_ADDR
> >  
> > /* get line status and check for data present */
> > -   lbu s0, UART_RXEMPTY(t0)
> > -   bnezs0, 243f
> > -   li  s0, 1
> > +   lbu s1, UART_RXEMPTY(t0)
> > +   bnezs1, 243f
> > +   li  s1, 1
> > j   244f
> > -243:   li  s0, 0
> > +243:   li  s1, 0
> >  244:   nop
> >  #endif /* CONFIG_DEBUG_LL */
> >  .endm
> > @@ -109,10 +109,10 @@ static inline void PUTC_LL(char ch)
> > debug_ll_tstc
> >  
> > /* try again */
> > -   beqzs0, 204b
> > +   beqzs1, 204b
> >  
> > /* read a character */
> > -   lb  s0, UART_RXTX(t0)
> > +   lb  s1, UART_RXTX(t0)
> > li  t1, UART_EV_RX
> > sb  t1, UART_EV_PENDING(t0)
> >  
> > diff --git a/arch/riscv/include/asm/debug_ll_ns16550.h 
> > b/arch/riscv/include/asm/debug_ll_ns16550.h
> > index e208ef4fb1e1..47f0be328ce8 100644
> > --- a/arch/riscv/include/asm/debug_ll_ns16550.h
> > +++ b/arch/riscv/include/asm/debug_ll_ns16550.h
> > @@ -143,8 +143,8 @@ static inline void debug_ll_ns16550_init(void)
> > li  t0, DEBUG_LL_UART_ADDR
> >  
> > /* get line status and check for data present */
> > -   UART_REG_L  s0, UART_LSR(DEBUG_LL_UART_SHIFT)(t0)
> > -   andis0, s0, UART_LSR_DR
> > +   UART_REG_L  s1, UART_LSR(DEBUG_LL_UART_SHIFT)(t0)
> > +   andis1, s1, UART_LSR_DR
> >  
> >  #endif /* CONFIG_DEBUG_LL */
> >  .endm
> > @@ -159,10 +159,10 @@ static inline void debug_ll_ns16550_init(void)
> > debug_ll_tstc
> >  
> > /* try again */
> > -   beqzs0, 204b
> > +   beqzs1, 204b
> >  
> > /* read a character */
> > -   UART_REG_L  s0, UART_RBR(DEBUG_LL_UART_SHIFT)(t0)
> > +   UART_REG_L  s1, UART_RBR(DEBUG_LL_UART_SHIFT)(t0)
> >  
> >  #endif /* CONFIG_DEBUG_LL */
> >  .endm
> > diff --git a/arch/riscv/include/asm/riscv_nmon.h 
> > b/arch/riscv/include/asm/riscv_nmon.h
> > index 8a44e216d72d..3e349025febc 100644
> > --- a/arch/riscv/include/asm/riscv_nmon.h
> > +++ b/arch/riscv/include/asm/riscv_nmon.h
> > @@ -84,7 +84,7 @@ nmon_main:
> > debug_ll_getc
> >  
> > li  a0, 'q'
> > -   bne s0, a0, 3f
> > +   bne s1, a0, 3f
> >  
> > jal a2, _nmon_outc_a0
> >  
> > @@ -92,13 +92,13 @@ nmon_main:
> >  
> >  3:
> > li  a0, 'd'
> > -   beq s0, a0, nmon_cmd_d
> > +   beq s1, a0, nmon_cmd_d
> >  
> > li  a0, 'w'
> > -   beq s0, a0, nmon_cmd_w
> > +   beq s1, a0, nmon_cmd_w
> >  
> > li  a0, 'g'
> > -   beq s0, a0, nmon_cmd_g
> > +   beq s1, a0, nmon_cmd_g
> >  
> > j   nmon_main_help
> >  
> > @@ -112,7 +112,7 @@ nmon_cmd_d:
> >  
> > nmon_outs   msg_nl
> >  
> > -   lw  a0, (s0)
> > +   lw  a0, (s1)
> > debug_ll_outhexw
> >  
> > j   nmon_main
> > @@ -124,13 +124,13 @@ nmon_cmd_w:
> > jal a2, _nmon_outc_a0
> >  
> > jal a2, _nmon_gethexw
> > -   moves2, s0
> > +   moves3, s1
> >  
> > li  a0, ' '
> > jal a2, _nmon_outc_a0
> > jal a2, _nmon_gethexw
> >  
> > -   sw  s0, 0(s2)
> > +   sw  s1, 0(s3)
> > j   nmon_main
> >  
> >  nmon_cmd_g:
> > @@ -140,11 +140,11 @@ nmon_cmd_g:
> > jal a2, _nmon_outc_a0
> >  
> > jal a2, _nmon_gethexw
> > -   moves2, s0
> > +   moves3, s1
> >  
> > nmon_outs   msg_nl
> >  
> > -   jalrs2
> > +   jalrs3
> > j   nmon_main
> >  
> >  _nmon_outc_a0:
> > @@ -169,37 +169,37 @@ _nmon_gethexw:
> >  _get_hex_digit:
> > debug_ll_getc
> >  
> > -   li  s1, CODE_ESC
> > -   beq s0, s1, nmon_main
> > +   li  s2, CODE_ESC
> > +   beq s1, s2, nmon_main
> >  
> > -   li  s1, '0'
> > -   bge s0, s1, 0f
> > +   li  s2, '0'
> > +   bge s1, s2, 0f
> > j   _get_hex_digit
> >  
> >  0:
> > -   li  s1, '9'
> > -   ble s0, s1, 9f
> > +   li  s2, '9'
> > +   ble s1, s2, 9f
> >  
> > -   li  s1, 'f'
> > -   ble s0, s1, 1f
> > +  

Re: [PATCH 7/9] RISC-V: don't use x8/s0/fp in assembly

2022-01-08 Thread Ahmad Fatoum
Hello Antony,

On 08.01.22 18:15, Ahmad Fatoum wrote:
> Free up the register to allow building a configuration with x8/s0 used
> as the frame pointer.
> 
> Signed-off-by: Ahmad Fatoum 
> ---
>  arch/riscv/include/asm/debug_ll_litex.h   | 12 +++---
>  arch/riscv/include/asm/debug_ll_ns16550.h |  8 ++--
>  arch/riscv/include/asm/riscv_nmon.h   | 50 +++

I just bumped the s register: s2 -> s3, s1 -> s2, s0 -> s1 to
clear s0. Is that ok?

>  3 files changed, 35 insertions(+), 35 deletions(-)
> 
> diff --git a/arch/riscv/include/asm/debug_ll_litex.h 
> b/arch/riscv/include/asm/debug_ll_litex.h
> index 2fcdd9b0ec3e..295477fc1010 100644
> --- a/arch/riscv/include/asm/debug_ll_litex.h
> +++ b/arch/riscv/include/asm/debug_ll_litex.h
> @@ -90,11 +90,11 @@ static inline void PUTC_LL(char ch)
>   li  t0, DEBUG_LL_UART_ADDR
>  
>   /* get line status and check for data present */
> - lbu s0, UART_RXEMPTY(t0)
> - bnezs0, 243f
> - li  s0, 1
> + lbu s1, UART_RXEMPTY(t0)
> + bnezs1, 243f
> + li  s1, 1
>   j   244f
> -243: li  s0, 0
> +243: li  s1, 0
>  244: nop
>  #endif /* CONFIG_DEBUG_LL */
>  .endm
> @@ -109,10 +109,10 @@ static inline void PUTC_LL(char ch)
>   debug_ll_tstc
>  
>   /* try again */
> - beqzs0, 204b
> + beqzs1, 204b
>  
>   /* read a character */
> - lb  s0, UART_RXTX(t0)
> + lb  s1, UART_RXTX(t0)
>   li  t1, UART_EV_RX
>   sb  t1, UART_EV_PENDING(t0)
>  
> diff --git a/arch/riscv/include/asm/debug_ll_ns16550.h 
> b/arch/riscv/include/asm/debug_ll_ns16550.h
> index e208ef4fb1e1..47f0be328ce8 100644
> --- a/arch/riscv/include/asm/debug_ll_ns16550.h
> +++ b/arch/riscv/include/asm/debug_ll_ns16550.h
> @@ -143,8 +143,8 @@ static inline void debug_ll_ns16550_init(void)
>   li  t0, DEBUG_LL_UART_ADDR
>  
>   /* get line status and check for data present */
> - UART_REG_L  s0, UART_LSR(DEBUG_LL_UART_SHIFT)(t0)
> - andis0, s0, UART_LSR_DR
> + UART_REG_L  s1, UART_LSR(DEBUG_LL_UART_SHIFT)(t0)
> + andis1, s1, UART_LSR_DR
>  
>  #endif /* CONFIG_DEBUG_LL */
>  .endm
> @@ -159,10 +159,10 @@ static inline void debug_ll_ns16550_init(void)
>   debug_ll_tstc
>  
>   /* try again */
> - beqzs0, 204b
> + beqzs1, 204b
>  
>   /* read a character */
> - UART_REG_L  s0, UART_RBR(DEBUG_LL_UART_SHIFT)(t0)
> + UART_REG_L  s1, UART_RBR(DEBUG_LL_UART_SHIFT)(t0)
>  
>  #endif /* CONFIG_DEBUG_LL */
>  .endm
> diff --git a/arch/riscv/include/asm/riscv_nmon.h 
> b/arch/riscv/include/asm/riscv_nmon.h
> index 8a44e216d72d..3e349025febc 100644
> --- a/arch/riscv/include/asm/riscv_nmon.h
> +++ b/arch/riscv/include/asm/riscv_nmon.h
> @@ -84,7 +84,7 @@ nmon_main:
>   debug_ll_getc
>  
>   li  a0, 'q'
> - bne s0, a0, 3f
> + bne s1, a0, 3f
>  
>   jal a2, _nmon_outc_a0
>  
> @@ -92,13 +92,13 @@ nmon_main:
>  
>  3:
>   li  a0, 'd'
> - beq s0, a0, nmon_cmd_d
> + beq s1, a0, nmon_cmd_d
>  
>   li  a0, 'w'
> - beq s0, a0, nmon_cmd_w
> + beq s1, a0, nmon_cmd_w
>  
>   li  a0, 'g'
> - beq s0, a0, nmon_cmd_g
> + beq s1, a0, nmon_cmd_g
>  
>   j   nmon_main_help
>  
> @@ -112,7 +112,7 @@ nmon_cmd_d:
>  
>   nmon_outs   msg_nl
>  
> - lw  a0, (s0)
> + lw  a0, (s1)
>   debug_ll_outhexw
>  
>   j   nmon_main
> @@ -124,13 +124,13 @@ nmon_cmd_w:
>   jal a2, _nmon_outc_a0
>  
>   jal a2, _nmon_gethexw
> - moves2, s0
> + moves3, s1
>  
>   li  a0, ' '
>   jal a2, _nmon_outc_a0
>   jal a2, _nmon_gethexw
>  
> - sw  s0, 0(s2)
> + sw  s1, 0(s3)
>   j   nmon_main
>  
>  nmon_cmd_g:
> @@ -140,11 +140,11 @@ nmon_cmd_g:
>   jal a2, _nmon_outc_a0
>  
>   jal a2, _nmon_gethexw
> - moves2, s0
> + moves3, s1
>  
>   nmon_outs   msg_nl
>  
> - jalrs2
> + jalrs3
>   j   nmon_main
>  
>  _nmon_outc_a0:
> @@ -169,37 +169,37 @@ _nmon_gethexw:
>  _get_hex_digit:
>   debug_ll_getc
>  
> - li  s1, CODE_ESC
> - beq s0, s1, nmon_main
> + li  s2, CODE_ESC
> + beq s1, s2, nmon_main
>  
> - li  s1, '0'
> - bge s0, s1, 0f
> + li  s2, '0'
> + bge s1, s2, 0f
>   j   _get_hex_digit
>  
>  0:
> - li  s1, '9'
> - ble s0, s1, 9f
> + li  s2, '9'
> + ble s1, s2, 9f
>  
> - li  s1, 'f'
> - ble s0, s1, 1f
> + li  s2, 'f'
> + ble s1, s2, 1f
>   j   _get_hex_digit
>  
>  1:
> - li  s1, 'a'
> - bge s0, s1, 8f
> + li  s2, 'a'
> + bge s1, s2, 8f
>  
>   j   _get_hex_digit
>  
> -8: /* s0 \in {'a', 'b' ... 'f'} */
> - sub a3, s0, s1
> +8: /* s1 \in {'a', 'b' ... 'f'} 

[PATCH 7/9] RISC-V: don't use x8/s0/fp in assembly

2022-01-08 Thread Ahmad Fatoum
Free up the register to allow building a configuration with x8/s0 used
as the frame pointer.

Signed-off-by: Ahmad Fatoum 
---
 arch/riscv/include/asm/debug_ll_litex.h   | 12 +++---
 arch/riscv/include/asm/debug_ll_ns16550.h |  8 ++--
 arch/riscv/include/asm/riscv_nmon.h   | 50 +++
 3 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/arch/riscv/include/asm/debug_ll_litex.h 
b/arch/riscv/include/asm/debug_ll_litex.h
index 2fcdd9b0ec3e..295477fc1010 100644
--- a/arch/riscv/include/asm/debug_ll_litex.h
+++ b/arch/riscv/include/asm/debug_ll_litex.h
@@ -90,11 +90,11 @@ static inline void PUTC_LL(char ch)
li  t0, DEBUG_LL_UART_ADDR
 
/* get line status and check for data present */
-   lbu s0, UART_RXEMPTY(t0)
-   bnezs0, 243f
-   li  s0, 1
+   lbu s1, UART_RXEMPTY(t0)
+   bnezs1, 243f
+   li  s1, 1
j   244f
-243:   li  s0, 0
+243:   li  s1, 0
 244:   nop
 #endif /* CONFIG_DEBUG_LL */
 .endm
@@ -109,10 +109,10 @@ static inline void PUTC_LL(char ch)
debug_ll_tstc
 
/* try again */
-   beqzs0, 204b
+   beqzs1, 204b
 
/* read a character */
-   lb  s0, UART_RXTX(t0)
+   lb  s1, UART_RXTX(t0)
li  t1, UART_EV_RX
sb  t1, UART_EV_PENDING(t0)
 
diff --git a/arch/riscv/include/asm/debug_ll_ns16550.h 
b/arch/riscv/include/asm/debug_ll_ns16550.h
index e208ef4fb1e1..47f0be328ce8 100644
--- a/arch/riscv/include/asm/debug_ll_ns16550.h
+++ b/arch/riscv/include/asm/debug_ll_ns16550.h
@@ -143,8 +143,8 @@ static inline void debug_ll_ns16550_init(void)
li  t0, DEBUG_LL_UART_ADDR
 
/* get line status and check for data present */
-   UART_REG_L  s0, UART_LSR(DEBUG_LL_UART_SHIFT)(t0)
-   andis0, s0, UART_LSR_DR
+   UART_REG_L  s1, UART_LSR(DEBUG_LL_UART_SHIFT)(t0)
+   andis1, s1, UART_LSR_DR
 
 #endif /* CONFIG_DEBUG_LL */
 .endm
@@ -159,10 +159,10 @@ static inline void debug_ll_ns16550_init(void)
debug_ll_tstc
 
/* try again */
-   beqzs0, 204b
+   beqzs1, 204b
 
/* read a character */
-   UART_REG_L  s0, UART_RBR(DEBUG_LL_UART_SHIFT)(t0)
+   UART_REG_L  s1, UART_RBR(DEBUG_LL_UART_SHIFT)(t0)
 
 #endif /* CONFIG_DEBUG_LL */
 .endm
diff --git a/arch/riscv/include/asm/riscv_nmon.h 
b/arch/riscv/include/asm/riscv_nmon.h
index 8a44e216d72d..3e349025febc 100644
--- a/arch/riscv/include/asm/riscv_nmon.h
+++ b/arch/riscv/include/asm/riscv_nmon.h
@@ -84,7 +84,7 @@ nmon_main:
debug_ll_getc
 
li  a0, 'q'
-   bne s0, a0, 3f
+   bne s1, a0, 3f
 
jal a2, _nmon_outc_a0
 
@@ -92,13 +92,13 @@ nmon_main:
 
 3:
li  a0, 'd'
-   beq s0, a0, nmon_cmd_d
+   beq s1, a0, nmon_cmd_d
 
li  a0, 'w'
-   beq s0, a0, nmon_cmd_w
+   beq s1, a0, nmon_cmd_w
 
li  a0, 'g'
-   beq s0, a0, nmon_cmd_g
+   beq s1, a0, nmon_cmd_g
 
j   nmon_main_help
 
@@ -112,7 +112,7 @@ nmon_cmd_d:
 
nmon_outs   msg_nl
 
-   lw  a0, (s0)
+   lw  a0, (s1)
debug_ll_outhexw
 
j   nmon_main
@@ -124,13 +124,13 @@ nmon_cmd_w:
jal a2, _nmon_outc_a0
 
jal a2, _nmon_gethexw
-   moves2, s0
+   moves3, s1
 
li  a0, ' '
jal a2, _nmon_outc_a0
jal a2, _nmon_gethexw
 
-   sw  s0, 0(s2)
+   sw  s1, 0(s3)
j   nmon_main
 
 nmon_cmd_g:
@@ -140,11 +140,11 @@ nmon_cmd_g:
jal a2, _nmon_outc_a0
 
jal a2, _nmon_gethexw
-   moves2, s0
+   moves3, s1
 
nmon_outs   msg_nl
 
-   jalrs2
+   jalrs3
j   nmon_main
 
 _nmon_outc_a0:
@@ -169,37 +169,37 @@ _nmon_gethexw:
 _get_hex_digit:
debug_ll_getc
 
-   li  s1, CODE_ESC
-   beq s0, s1, nmon_main
+   li  s2, CODE_ESC
+   beq s1, s2, nmon_main
 
-   li  s1, '0'
-   bge s0, s1, 0f
+   li  s2, '0'
+   bge s1, s2, 0f
j   _get_hex_digit
 
 0:
-   li  s1, '9'
-   ble s0, s1, 9f
+   li  s2, '9'
+   ble s1, s2, 9f
 
-   li  s1, 'f'
-   ble s0, s1, 1f
+   li  s2, 'f'
+   ble s1, s2, 1f
j   _get_hex_digit
 
 1:
-   li  s1, 'a'
-   bge s0, s1, 8f
+   li  s2, 'a'
+   bge s1, s2, 8f
 
j   _get_hex_digit
 
-8: /* s0 \in {'a', 'b' ... 'f'} */
-   sub a3, s0, s1
+8: /* s1 \in {'a', 'b' ... 'f'} */
+   sub a3, s1, s2
addia3, a3, 0xa
j   0f
 
-9: /* s0 \in {'0', '1' ... '9'} */
+9: /* s1 \in {'0', '1' ... '9'} */
li  a3, '0'
-   sub a3, s0, a3
+   sub a3, s1, a3
 
-0: movea0, s0
+0: movea0, s1
debug_ll_outc_a0