[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#253568: soundcard.h: AFMT_S16_NE is little endian on HPPA, should be big endian



Package: linux-kernel-headers
Version: 2.5.999-test7-bk-15
Severity: normal
Tags: patch

On HPPA, <sys/soundcard.h> defines AFMT_S16_NE (the "native"-endian
sound format) as AFMT_S16_LE (little-endian), but it should be defined
as AFMT_S16_BE (big-endian).  Due to the removal of a workaround for
this in HPPA's "harmony" driver, many packages that use AFMT_S16_NE will
no longer work under HPPA (using recent parisc-linux.org kernels).

To demonstrate this:

#include <stdio.h>
#include <sys/soundcard.h>

int main()
{
        printf("AFMT_S16_NE: %i\n"
	       "AFMT_S16_BE: %i\n"
	       "AFMT_S16_LE: %i\n", AFMT_S16_NE, AFMT_S16_BE, AFMT_S16_LE);
	return 0;
}

On big-endian machines (such as HPPA), this should print:

AFMT_S16_NE: 32
AFMT_S16_BE: 32
AFMT_S16_LE: 16

On little-endian machines (x86), this should print:

AFMT_S16_NE: 16
AFMT_S16_BE: 32
AFMT_S16_LE: 16

Currently, the "little-endian" output is printed on HPPA.  PowerPC may
also be affected if the -ansi flag is used, but I cannot test this.

Here is a possible patch:

--- /usr/include/linux/soundcard.h.orig	2004-06-08 19:24:47.000000000 +0100
+++ /usr/include/linux/soundcard.h	2004-06-08 19:35:25.000000000 +0100
@@ -39,6 +39,13 @@
 /* In Linux we need to be prepared for cross compiling */
 #include <linux/ioctl.h>
 
+/* Endian macros. Note that they have a different meaning in the kernel. */
+#ifdef __KERNEL__
+#  include <asm/byteorder.h>
+#else
+#  include <endian.h>
+#endif
+
 /*
  *	Supported card ID numbers (Should be somewhere else?)
  */
@@ -179,13 +186,26 @@
  * Some big endian/little endian handling macros
  */
 
-#if defined(_AIX) || defined(AIX) || defined(sparc) || defined(__sparc__) || defined(HPPA) || defined(PPC) || defined(__mc68000__)
-/* Big endian machines */
-#  define _PATCHKEY(id) (0xfd00|id)
-#  define AFMT_S16_NE AFMT_S16_BE
-#else
-#  define _PATCHKEY(id) ((id<<8)|0xfd)
-#  define AFMT_S16_NE AFMT_S16_LE
+#if defined(__KERNEL__)
+#  if defined(__BIG_ENDIAN)
+#    define AFMT_S16_NE AFMT_S16_BE
+#    define _PATCHKEY(id) (0xfd00|id)
+#  elif defined(__LITTLE_ENDIAN)
+#    define AFMT_S16_NE AFMT_S16_LE
+#    define _PATCHKEY(id) ((id<<8)|0x00fd)
+#  else
+#    error failed to determine byte order
+#  endif
+#else
+#  if __BYTE_ORDER == __BIG_ENDIAN
+#    define AFMT_S16_NE AFMT_S16_BE
+#    define _PATCHKEY(id) (0xfd00|id)
+#  elif __BYTE_ORDER == __LITTLE_ENDIAN
+#    define AFMT_S16_NE AFMT_S16_LE
+#    define _PATCHKEY(id) ((id<<8)|0xfd)
+#  else
+#    error failed to determine byte order
+#  endif
 #endif
 
 /*

I'm not sure about the #error bits.

The quick fix would be to add __hppa__ and __powerpc__ to the list of
big-endian platforms, but then there are others missing from the list.

--- /usr/include/linux/soundcard.h.orig	2004-06-08 19:11:00.000000000 +0100
+++ /usr/include/linux/soundcard.h	2004-06-08 19:18:34.000000000 +0100
@@ -179,7 +179,7 @@
  * Some big endian/little endian handling macros
  */
 
-#if defined(_AIX) || defined(AIX) || defined(sparc) || defined(__sparc__) || defined(HPPA) || defined(PPC) || defined(__mc68000__)
+#if defined(_AIX) || defined(AIX) || defined(sparc) || defined(__sparc__) || defined(HPPA) || defined(__hppa__) || defined(PPC) || defined(__powerpc__) || defined(__mc68000__)
 /* Big endian machines */
 #  define _PATCHKEY(id) (0xfd00|id)
 #  define AFMT_S16_NE AFMT_S16_BE

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: hppa (parisc)
Kernel: Linux 2.4.26-pa4-0
Locale: LANG=C, LC_CTYPE=C (ignored: LC_ALL set to en_GB)

-- no debconf information



Reply to: