NetBSD Problem Report #55854

From dholland@netbsd.org  Wed Dec  9 02:59:04 2020
Return-Path: <dholland@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 3D6421A9217
	for <gnats-bugs@gnats.NetBSD.org>; Wed,  9 Dec 2020 02:59:04 +0000 (UTC)
Message-Id: <20201209025903.9E79D84DA2@mail.netbsd.org>
Date: Wed,  9 Dec 2020 02:59:03 +0000 (UTC)
From: dholland@NetBSD.org
Reply-To: dholland@NetBSd.org
To: gnats-bugs@NetBSD.org
Subject: bogus thumb code in bswap32
X-Send-Pr-Version: 3.95

>Number:         55854
>Category:       port-arm
>Synopsis:       bogus thumb code in bswap32
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    port-arm-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 09 03:00:00 +0000 2020
>Closed-Date:    Fri Dec 11 09:12:21 +0000 2020
>Last-Modified:  Fri Dec 11 09:12:21 +0000 2020
>Originator:     David A. Holland
>Release:        NetBSD 9.99.75 (20201208)
>Organization:
>Environment:
System: n/a
Architecture: arm
Machine: arm
>Description:

I found this in byte_swap_4.S:

#ifdef _ARM_ARCH_6
   :
#elif !defined(__thumb__)
   :
#else
        movs    r3, #16
        lsls    r1, r0, #8              /* d.c.b.a -> c.b.a.0 /*
        lsrs    r0, r0, #8              /* d.c.b.a -> 0.d.c.b */
        rors    r1, r3                  /* c.b.a.0 -> a.0.c.b */
        rors    r0, r3                  /* 0.d.c.b -> c.b.0.d */
        lsrs    r1, r1, #8              /* a.0.c.b -> 0.a.0.c */
        lsls    r1, r1, #8              /* 0.a.0.c -> a.0.c.0 */
        lsls    r0, r0, #8              /* c.b.0.d -> b.0.d.0 */
        lsrs    r0, r0, #8              /* b.0.d.0 -> 0.b.0.d */
        orrs    r0, r0, r1              /* a.0.c.0 | 0.b.0.d -> a.b.c.d */
#endif

Note the comment delimiter at the end of the second line; that
silently comments out the third line, which according to the byte flow
comments (which I just went over to change [1-4] to [a-d], so I'm
pretty sure they're right) makes the code wrong.

It's been this way since the thumb version was first committed in
2013. Likely as not it's just a typo, but...

Is the thumb code actually used/tested at all? Enquiring minds would
like to know.

>How-To-Repeat:

Code inspection.

>Fix:
apply bswap16 to the comment delimiter :-)

>Release-Note:

>Audit-Trail:
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@netbsd.org
Cc: port-arm-maintainer@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: port-arm/55854: bogus thumb code in bswap32
Date: Wed, 09 Dec 2020 17:10:37 +1100

 > Is the thumb code actually used/tested at all? Enquiring minds would
 > like to know.

 not by default.

 there was an attempt to build a thumb userland but that
 was a long time ago...


 .mrg.

From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55854 CVS commit: src/common/lib/libc/arch/arm/gen
Date: Fri, 11 Dec 2020 09:02:33 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Fri Dec 11 09:02:33 UTC 2020

 Modified Files:
 	src/common/lib/libc/arch/arm/gen: byte_swap_4.S

 Log Message:
 arm bswap32: fix fatal typo in thumb code (PR 55854)


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/arch/arm/gen/byte_swap_4.S

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Fri, 11 Dec 2020 09:12:21 +0000
State-Changed-Why:
fixed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.