u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: Fix detecting FPU support in standard extension
@ 2022-11-04 11:21 Yu Chien Peter Lin
  2022-11-05  4:39 ` Samuel Holland
  0 siblings, 1 reply; 3+ messages in thread
From: Yu Chien Peter Lin @ 2022-11-04 11:21 UTC (permalink / raw)
  To: u-boot; +Cc: ycliang, rick, Yu Chien Peter Lin

We should check the string until it hits underscore, in case it
searches for the letters in the custom extension. For example,
"rv64imac_xandes" will be treated as D extension support since
there is a "d" in "andes", resulting illegal instruction caused
by initializing FCSR.

Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
---
 arch/riscv/cpu/cpu.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
index 52ab02519f..dc949c1306 100644
--- a/arch/riscv/cpu/cpu.c
+++ b/arch/riscv/cpu/cpu.c
@@ -36,6 +36,7 @@ static inline bool supports_extension(char ext)
 #ifdef CONFIG_CPU
 	struct udevice *dev;
 	char desc[32];
+	int i;
 
 	uclass_find_first_device(UCLASS_CPU, &dev);
 	if (!dev) {
@@ -43,9 +44,16 @@ static inline bool supports_extension(char ext)
 		return false;
 	}
 	if (!cpu_get_desc(dev, desc, sizeof(desc))) {
-		/* skip the first 4 characters (rv32|rv64) */
-		if (strchr(desc + 4, ext))
-			return true;
+		/*
+		 * skip the first 4 characters (rv32|rv64) and
+		 * check until underscore
+		 */
+		for (i = 4; i < sizeof(desc); i++) {
+			if (!(desc[i] - '_'))
+				break;
+			if (desc[i] == ext)
+				return true;
+		}
 	}
 
 	return false;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: Fix detecting FPU support in standard extension
  2022-11-04 11:21 [PATCH] riscv: Fix detecting FPU support in standard extension Yu Chien Peter Lin
@ 2022-11-05  4:39 ` Samuel Holland
  2022-11-05 13:12   ` Yu-Chien Peter Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Samuel Holland @ 2022-11-05  4:39 UTC (permalink / raw)
  To: Yu Chien Peter Lin; +Cc: ycliang, rick, u-boot

On 11/4/22 06:21, Yu Chien Peter Lin wrote:
> We should check the string until it hits underscore, in case it
> searches for the letters in the custom extension. For example,
> "rv64imac_xandes" will be treated as D extension support since
> there is a "d" in "andes", resulting illegal instruction caused
> by initializing FCSR.
> 
> Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
> ---
>  arch/riscv/cpu/cpu.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
> index 52ab02519f..dc949c1306 100644
> --- a/arch/riscv/cpu/cpu.c
> +++ b/arch/riscv/cpu/cpu.c
> @@ -36,6 +36,7 @@ static inline bool supports_extension(char ext)
>  #ifdef CONFIG_CPU
>  	struct udevice *dev;
>  	char desc[32];
> +	int i;
>  
>  	uclass_find_first_device(UCLASS_CPU, &dev);
>  	if (!dev) {
> @@ -43,9 +44,16 @@ static inline bool supports_extension(char ext)
>  		return false;
>  	}
>  	if (!cpu_get_desc(dev, desc, sizeof(desc))) {
> -		/* skip the first 4 characters (rv32|rv64) */
> -		if (strchr(desc + 4, ext))
> -			return true;
> +		/*
> +		 * skip the first 4 characters (rv32|rv64) and
> +		 * check until underscore
> +		 */
> +		for (i = 4; i < sizeof(desc); i++) {
> +			if (!(desc[i] - '_'))

Why not use "if (desc[i] == '_')"? Also, you need to stop at the null
terminator.

Regards,
Samuel

> +				break;
> +			if (desc[i] == ext)
> +				return true;
> +		}
>  	}
>  
>  	return false;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: Fix detecting FPU support in standard extension
  2022-11-05  4:39 ` Samuel Holland
@ 2022-11-05 13:12   ` Yu-Chien Peter Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Yu-Chien Peter Lin @ 2022-11-05 13:12 UTC (permalink / raw)
  To: Samuel Holland; +Cc: u-boot

On Fri, Nov 04, 2022 at 11:39:43PM -0500, Samuel Holland wrote:
> On 11/4/22 06:21, Yu Chien Peter Lin wrote:
> > We should check the string until it hits underscore, in case it
> > searches for the letters in the custom extension. For example,
> > "rv64imac_xandes" will be treated as D extension support since
> > there is a "d" in "andes", resulting illegal instruction caused
> > by initializing FCSR.
> > 
> > Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com>
> > ---
> >  arch/riscv/cpu/cpu.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
> > index 52ab02519f..dc949c1306 100644
> > --- a/arch/riscv/cpu/cpu.c
> > +++ b/arch/riscv/cpu/cpu.c
> > @@ -36,6 +36,7 @@ static inline bool supports_extension(char ext)
> >  #ifdef CONFIG_CPU
> >  	struct udevice *dev;
> >  	char desc[32];
> > +	int i;
> >  
> >  	uclass_find_first_device(UCLASS_CPU, &dev);
> >  	if (!dev) {
> > @@ -43,9 +44,16 @@ static inline bool supports_extension(char ext)
> >  		return false;
> >  	}
> >  	if (!cpu_get_desc(dev, desc, sizeof(desc))) {
> > -		/* skip the first 4 characters (rv32|rv64) */
> > -		if (strchr(desc + 4, ext))
> > -			return true;
> > +		/*
> > +		 * skip the first 4 characters (rv32|rv64) and
> > +		 * check until underscore
> > +		 */
> > +		for (i = 4; i < sizeof(desc); i++) {
> > +			if (!(desc[i] - '_'))
> 
> Why not use "if (desc[i] == '_')"? Also, you need to stop at the null
> terminator.
> 
> Regards,
> Samuel

Hi Samuel,

Oops, I'll fix this.
Thanks for your review!

Best regards,
Peter Lin

> 
> > +				break;
> > +			if (desc[i] == ext)
> > +				return true;
> > +		}
> >  	}
> >  
> >  	return false;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-05  5:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 11:21 [PATCH] riscv: Fix detecting FPU support in standard extension Yu Chien Peter Lin
2022-11-05  4:39 ` Samuel Holland
2022-11-05 13:12   ` Yu-Chien Peter Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).