NetBSD Problem Report #4277

Received: (qmail 1890 invoked from network); 16 Oct 1997 08:42:47 -0000
Message-Id: <199710160842.RAA22352@ruri.iri.co.jp>
Date: Thu, 16 Oct 1997 17:42:17 +0900 (JST)
From: tsubai@iri.co.jp
Reply-To: tsubai@iri.co.jp
To: gnats-bugs@gnats.netbsd.org
Subject: NetBSD/mips endian probrem
X-Send-Pr-Version: 3.95

>Number:         4277
>Category:       port-mips
>Synopsis:       NetBSD/mips endian probrem
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jonathan
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 16 01:50:02 +0000 1997
>Closed-Date:    Mon Oct 20 03:51:42 +0000 1997
>Last-Modified:  Wed Aug 07 21:22:28 +0000 2002
>Originator:     Tsubai Masanari
>Release:        1.2G
>Organization:
Internet Research Institute, Inc.
>Environment:
SONY NEWS3400
System: NetBSD wapiko 1.2G NetBSD 1.2G (WAPIKO) #1: Mon Aug 18 18:26:51 JST 1997 tsubai@wapiko:/a/0816/src/sys/arch/news/compile/WAPIKO news


>Description:
	I ported NetBSD to SONY NEWS3400 series.  It is based on NetBSD/mips
	and 4.4BSD Lite2.  Because NEWS3400 is BIG-ENDIAN, some modification
	is needed (locore.S, mips_opcode.h).
	Full kernel sources are
	ftp://elilin.hss.titech.ac.jp/pub/NetBSD/news/sys.news-970818.tar.gz
	(This is the newest ;-)
>How-To-Repeat:

>Fix:
	Please see following diff.


*** mips/locore.S.orig	Sat Aug  9 20:17:36 1997
--- mips/locore.S	Sun Aug 17 21:07:41 1997
***************
*** 95,100 ****
--- 95,127 ----
  #include <mips/pte.h>
  #include <machine/param.h>

+ 
+ /* #include <machine/endian.h> */
+ /* common endian.h includes function declarations */
+ #define	LITTLE_ENDIAN	1234	/* LSB first: i386, vax */
+ #define	BIG_ENDIAN	4321	/* MSB first: 68000, ibm, net */
+ #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long */
+ 
+ #ifdef __MIPSEL__
+ # define BYTE_ORDER LITTLE_ENDIAN
+ #endif
+ #ifdef __MIPSEB__
+ # define BYTE_ORDER BIG_ENDIAN
+ #endif
+ 
+ #if BYTE_ORDER == LITTLE_ENDIAN
+ # define LWHI lwr
+ # define LWLO lwl
+ # define SWHI swr
+ # define SWLO swl
+ #endif
+ #if BYTE_ORDER == BIG_ENDIAN
+ # define LWHI lwl
+ # define LWLO lwr
+ # define SWHI swl
+ # define SWLO swr
+ #endif
+ 
  /*----------------------------------------------------------------------------
   *
   *  Macros used to save and restore registers when entering and
***************
*** 259,264 ****
--- 286,292 ----
   * netorder = htonl(hostorder)
   * hostorder = ntohl(netorder)
   */
+ #if BYTE_ORDER == LITTLE_ENDIAN
  LEAF(htonl)				# a0 = 0x11223344, return 0x44332211
  ALEAF(ntohl)
  	srl	v1, a0, 24		# v1 = 0x00000011
***************
*** 286,291 ****
--- 314,320 ----
  	j	ra
  	or	v0, v0, v1
  END(htons)
+ #endif

  /*
   * strlen(str)
***************
*** 335,341 ****
  	and	a3, a3, 3
  	beq	a3, zero, 1f		# skip if word aligned
  	subu	a1, a1, a3		# subtract from remaining count
! 	swr	zero, 0(a0)		# clear 1, 2, or 3 bytes to align
  	addu	a0, a0, a3
  1:
  	and	v0, a1, 3		# compute number of words left
--- 364,370 ----
  	and	a3, a3, 3
  	beq	a3, zero, 1f		# skip if word aligned
  	subu	a1, a1, a3		# subtract from remaining count
! 	SWHI	zero, 0(a0)		# clear 1, 2, or 3 bytes to align
  	addu	a0, a0, a3
  1:
  	and	v0, a1, 3		# compute number of words left
***************
*** 372,379 ****
  	beq	a3, zero, 1f
  	subu	a2, a2, a3		# subtract from remaining count
  	move	v0, v1			# init v0,v1 so unmodified bytes match
! 	lwr	v0, 0(a0)		# read 1, 2, or 3 bytes
! 	lwr	v1, 0(a1)
  	addu	a1, a1, a3
  	bne	v0, v1, nomatch
  	addu	a0, a0, a3
--- 401,408 ----
  	beq	a3, zero, 1f
  	subu	a2, a2, a3		# subtract from remaining count
  	move	v0, v1			# init v0,v1 so unmodified bytes match
! 	LWHI	v0, 0(a0)		# read 1, 2, or 3 bytes
! 	LWHI	v1, 0(a1)
  	addu	a1, a1, a3
  	bne	v0, v1, nomatch
  	addu	a0, a0, a3
***************
*** 408,415 ****
  	subu	a2, a2, a3		#   which has to be >= (16-3) & ~3
  	addu	a3, a3, a0		# compute ending address
  3:
! 	lwr	v0, 0(a0)		# compare words a0 unaligned, a1 aligned
! 	lwl	v0, 3(a0)
  	lw	v1, 0(a1)
  	addu	a0, a0, 4
  	bne	v0, v1, nomatch
--- 437,444 ----
  	subu	a2, a2, a3		#   which has to be >= (16-3) & ~3
  	addu	a3, a3, a0		# compute ending address
  3:
! 	LWHI	v0, 0(a0)		# compare words a0 unaligned, a1 aligned
! 	LWLO	v0, 3(a0)
  	lw	v1, 0(a1)
  	addu	a0, a0, 4
  	bne	v0, v1, nomatch
***************
*** 552,564 ****
  	addu	a3,a0,a3	# stop point

  3:
! #if MIPSEL	/* little-endian */
! 	lwr	v0,0(a0)
! 	lwl	v0,3(a0)
! #else		/* big-endian */
! 	lwl	v0,0(a0)
! 	lwr	v0,3(a0)
! #endif
  	addi	a0,4
  	sw	v0,0(a1)
  	bne	a0,a3,3b
--- 581,588 ----
  	addu	a3,a0,a3	# stop point

  3:
! 	LWHI	v0,0(a0)
! 	LWLO	v0,3(a0)
  	addi	a0,4
  	sw	v0,0(a1)
  	bne	a0,a3,3b
*** include/mips_opcode.h.orig	Mon Mar 25 21:24:19 1996
--- include/mips_opcode.h	Sun Jul 20 16:45:18 1997
***************
*** 81,86 ****
--- 81,118 ----
  		unsigned op: 6;		/* always '0x11' */
  	} FRType;
  #endif
+ #if BYTE_ORDER == BIG_ENDIAN
+ 	struct {
+ 		unsigned op: 6;
+ 		unsigned rs: 5;
+ 		unsigned rt: 5;
+ 		unsigned imm: 16;
+ 	} IType;
+ 
+ 	struct {
+ 		unsigned op: 6;
+ 		unsigned target: 26;
+ 	} JType;
+ 
+ 	struct {
+ 		unsigned op: 6;
+ 		unsigned rs: 5;
+ 		unsigned rt: 5;
+ 		unsigned rd: 5;
+ 		unsigned shamt: 5;
+ 		unsigned func: 6;
+ 	} RType;
+ 
+ 	struct {
+ 		unsigned op: 6;		/* always '0x11' */
+ 		unsigned : 1;		/* always '1' */
+ 		unsigned fmt: 4;
+ 		unsigned ft: 5;
+ 		unsigned fs: 5;
+ 		unsigned fd: 5;
+ 		unsigned func: 6;
+ 	} FRType;
+ #endif
  } InstFmt;

  /*
>Release-Note:
>Audit-Trail:

From: Jonathan Stone <jonathan@netbsd1.cygnus.com>
To: tsubai@iri.co.jp
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: port-mips/4277
Date: 17 Oct 1997 02:54:38 -0000

 hi,

 If at all possible, I would like to get the necessary support for
 big-endian mips support into the 1.3 release, to make post-1.3 kits
 for Sony News easier to distribute.

 I 've lbread the patch in your change-request.  the changes to
 locore.S seem to duplicate much of <mips/endian.h> I would be happier
 if we could change <mips/endian.h> so that it can be safely included
 in assembler source code.  We can do that by putting

   #ifndef _LOCORE/ #endif

 after everything following the ENDIAN definitions.

 I'm not sure about __MIPSEL__ vs __MIPSEB__.  Are you assuming those
 get defined by the compiler?  Is that safe for cross-compilation?
 I don't know if it's better to use them, or to put explicit
 	#define  BYTE_ORDER BIG_ENDIAN
 or
 	#define  BYTE_ORDER LITTLE_ENDIAN

 in sys/arch/{pmax,pica,news3400,..}/include/endian.h.

 The other changes (LWHI/LWLO, SWHI/SWLO and using them, and the opcode
 changes) look fine to me.

 thanks for the change request!
 --Jonathan

From: Jonathan Stone <jonathan@netbsd1.cygnus.com>
To: tsubai@iri.co.jp
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: port-mips/4277
Date: 17 Oct 1997 05:10:30 -0000

 Hi,

 I've applied the suggested change to mips_opcode.h and some slightly
 different changes to mips/include/endian.h, mips/mips/locore.h, and
 the {pica/pmax}/include/endian.h.  I compared an objdump --disassemble
 of locore.o on a MIPSEL before and after the changes, and they were
 identical.  I'm assuming the MIPSEB changes are correct, i haven't
 tested them.

 I also realized that the changes you suggested for the kernel bcopy
 and bzero() should also be applied to the user-space routines: they
 are derived from the same source code base.  I suggest adding
 	#define _LOCORE	/* (needs a better name!) */
 	#include <machine/endian.h>

 to the libc source for bzero and bcopy() , and patching them to use
 LWHI/LWLO, and SWHI/SWLO.  Can you test that on a big-endian mips?

 I had closed the PR. Now I've changed it again to feedback state,
 until we get the userland code cleaned up for mipseb too.

 Thanks again for the change-request!

 --Jonathan

From: Tsubai Masanari <tsubai@iri.co.jp>
To: Jonathan Stone <jonathan@netbsd1.cygnus.com>
Cc: tsubai@iri.co.jp, gnats-bugs@gnats.netbsd.org
Subject: Re: port-mips/4277
Date: Fri, 17 Oct 1997 18:48:58 +0900 (JST)

 >I'm not sure about __MIPSEL__ vs __MIPSEB__.  Are you assuming those
 >get defined by the compiler?  Is that safe for cross-compilation?

 The compiler does.

 I think that to put explicit definiton:

 >	#define  BYTE_ORDER BIG_ENDIAN
 >or
 >	#define  BYTE_ORDER LITTLE_ENDIAN
 >
 >in sys/arch/{pmax,pica,news3400,..}/include/endian.h.

 is better.  When cross-compiling, like ``-U__MIPSEL__ -D__MIPSEB__''
 seems to be ugly for me. (and perhaps not safe.)


From: Tsubai Masanari <tsubai@iri.co.jp>
To: Jonathan Stone <jonathan@netbsd1.cygnus.com>
Cc: gnats-bugs@gnats.netbsd.org, mhitch@netbsd.org
Subject: Re: port-mips/4277
Date: Mon, 20 Oct 1997 17:45:11 +0900 (JST)

 >I've applied the suggested change to mips_opcode.h and some slightly
 >different changes to mips/include/endian.h, mips/mips/locore.h, and
 >the {pica/pmax}/include/endian.h.

 Please take care of _QUAD_HIGHWORD and _QUAD_LOWWORD in mips/endian.h, like

 #if BYTE_ORDER == LITTLE_ENDIAN
 #define _QUAD_HIGHWORD 1
 #define _QUAD_LOWWORD 0
 #endif
 #if BYTE_ORDER == BIG_ENDIAN
 #define _QUAD_HIGHWORD 0
 #define _QUAD_LOWWORD 1
 #endif

 or explicitly define in machine/endian.h.  I don't know which is better.

 With this fix, my big endian mips runs correctly.


 >I also realized that the changes you suggested for the kernel bcopy
 >and bzero() should also be applied to the user-space routines: they
 >are derived from the same source code base.  I suggest adding
 >	#define _LOCORE	/* (needs a better name!) */
 >	#include <machine/endian.h>
 >
 >to the libc source for bzero and bcopy() , and patching them to use
 >LWHI/LWLO, and SWHI/SWLO.  Can you test that on a big-endian mips?

 "egrep '[ls]w[lr]' *" in lib/libc/arch/mips/string says that:

  * bzero.S uses "swr".
  * bcmp.S defines LWHI/LWLO/... itself.

 These files need to change, too.

 bzero.o is OK on MIPSBE. (objdump and compare agrees.)

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.