byte swapping redux
Quoted 2 lines · Joel Soete
I don't understand why the 32bits kernel crashed with this patche:
(gcc-3.3 and binutils-2.13.90)
uhm...perhaps the 64-bit swap is buggy for 32-bit mode? I didn't test that. It's a different code path.
Quoted 1 line
the log of the boot sequence shows me that the kernel was launched twice:
probably not. It's probably the kernel crash path just dumping out the dmesg buffer "again".
grant
Hi Grant,
Quoted 5 lines
Quoted 2 lines
I don't understand why the 32bits kernel crashed with this patche:
(gcc-3.3 and binutils-2.13.90)uhm...perhaps the 64-bit swap is buggy for 32-bit mode? I didn't test that. It's a different code path.
I hope I am not going to anoying you.
I just found related interesting stuff: <http://lwn.net/Articles/38384/>
And may be also the source of pb.
I also write this small testcase to try to point out the pb in 32bits mode:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <asm/types.h>
typedef unsigned long long u64;
typedef u_int8_t BOOLEAN;
typedef struct
{
unsigned char b7, b6, b5, b4, b3, b2, b1, b0;
}EightBytes;
static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
{
unsigned int temp;
__asm__("shd %0, %0, 16, %1\n\t" /* shift abcdabcd -> cdab
*/
"dep %1, 15, 8, %1\n\t" /* deposit cdab -> cbab */
"shd %0, %1, 8, %0" /* shift abcdcbab -> dcba
*/
: "=r" (x), "=&r" (temp)
: "0" (x));
return x;
}#define __arch__swab32(x) ___arch__swab32(x)
static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
{
__u32 t1 = (__u32) x;
__u32 t2 = (__u32) ((x) >> 32);
___arch__swab32(t1);
___arch__swab32(t2);
return (((__u64) t1 << 32) + ((__u64) t2));
}static __inline__ __const__ __u32 __fswab32(__u32 x)
{
return __arch__swab32(x);
}# define __swab32(x) __fswab32(x)
static __inline__ __const__ __u64 __fswab64(__u64 x)
{
__u32 h = x >> 32;
__u32 l = x & ((1ULL<<32)-1);
return (((__u64)__swab32(l)) << 32) | ((__u64)(__swab32(h)));
}int main(int argc, char * * argv, char * * env) {
unsigned long long TU64;
int err;
TU64=0xfedcba9876543210LL;
printf("Val of TU64: %0Lx\n", TU64);
printf("Val of ___arch__swab64(TU64): %0Lx\n", ___arch__swab64(TU64));
printf("Val of __fswab64(TU64): %0Lx\n", __fswab64(TU64));}
And here is the results:
Val of TU64: fedcba9876543210
Val of ___arch__swab64(TU64): 76543210fedcba98
Val of __fswab64(TU64): 1032547698badcfe
What is right (I could not rebuild with hppa64-linux-gcc :( )?
Thanks,
Joel
---------------------------------
Tiscali ADSL: 19,50 euros/mois...abonnez-vous sur www.tiscali.be
Quoted 1 line · Joel Soete
I hope I am not going to anoying you.
:^)
Quoted 2 lines
I just found related interesting stuff: <http://lwn.net/Articles/38384/>
And may be also the source of pb.
Maybe our userspace will encounter this problem as well since I've ripped out the __STRICT_ANSI__ test...can you work this out?
Quoted 1 line
I also write this small testcase to try to point out the pb in 32bits mode:
...
Quoted 6 lines
And here is the results:
Val of TU64:fedcba9876543210
Val of___arch__swab64(TU64):76543210fedcba98
Val of__fswab64(TU64):1032547698badcfeWhat is right (I could not rebuild with hppa64-linux-gcc :( )?
__fswab64() is correct.___arch__swab64() didn't actually swap within the 32-bit words.
asm-parisc/byteorder.h has:
static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
{
__u32 t1 = (__u32) x;
__u32 t2 = (__u32) ((x) >> 32);
___arch__swab32(t1);
___arch__swab32(t2);
return (((__u64) t2 << 32) + ((__u64) t1));
}DOH! *smack*
Probably my bad.
That should read:
static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
{
__u32 t1 = (__u32) x;
__u32 t2 = (__u32) ((x) >> 32);
return ((__u64) ___arch__swab32(t1) << 32) + ((__u64) ___arch__swab32(t2));
}Could you please test this?
thanks,
grant
Quoted 3 lines
Maybe our userspace will encounter this problem as well since I've ripped out the
__STRICT_ANSI__test...can you work this out?
I will see what I can do for this
Quoted 1 line
Quoted 1 line
I also write this small testcase to try to point out the pb in 32bits
mode:
Quoted 5 lines
...
Quoted 4 lines
And here is the results:
Val of TU64:fedcba9876543210
Val of___arch__swab64(TU64):76543210fedcba98
Val of__fswab64(TU64):1032547698badcfe
[...]
Quoted 2 lines
__fswab64()is correct.___arch__swab64()didn't actually swap within the 32-bit word
[...]
static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
{
__u32 t1 = (__u32) x;
__u32 t2 = (__u32) ((x) >> 32);
return ((__u64) ___arch__swab32(t1) << 32) + ((__u64) ___arch__swab32(t2))Quoted 1 line
}
That works for my 32bits kernel on my b2k :-) (just replace 't1' by 'l' and 't2' by 'h' ;) )
btw here is also a small patch I just test also for cdrom pb encounter by somebody else:
system_irqsave.h renamed from system_irqsave.h.orig +0 -0
@@ -7,8 +7,13 @@#define __cli () __asm__ __volatile__("rsm %0,%%r0\n" : : "i" (PSW_I) : "memory"
)
#define __sti() __asm__ __volatile__("ssm %0,%%r0\n" : : "i" (PSW_I) : "memory"
)
+#define __save_and_cli(x) do { __save_flags(x); __cli(); } while(0); +#define __save_and_sti(x) do { __save_flags(x); __sti(); } while(0); +
+/* For spinlocks etc */
#define local_irq_save(x) \
__asm__ __volatile__("rsm %1,%0" : "=r" (x) :"i" (PSW_I) : "memory" )
+#define local_irq_set(x) __save_and_sti(x)
#define local_irq_restore(x) \
__asm__ __volatile__("mtsm %0" : : "r" (x) : "memory" )
#define local_irq_disable() __cli()
( may be possible to do better ??)
Joel
---------------------------------
Tiscali ADSL: 19,50 euros/mois...abonnez-vous sur www.tiscali.be