Subject: port-powerpc/24830: arch/powerpc/ibm4xx: bad asm volatile register constraints
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <k.luedtke@teles.de>
List: netbsd-bugs
Date: 03/17/2004 18:15:09
>Number:         24830
>Category:       port-powerpc
>Synopsis:       arch/powerpc/ibm4xx: bad asm volatile register constraints
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-powerpc-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 17 18:16:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Karsten Luedtke
>Release:        1.6ZK
>Organization:
TELES AG, Berlin, Germany
>Environment:
NetBSD TAG5800 1.6ZK NetBSD 1.6ZK (TAG5800) #18: 
Wed Mar 17 17:13:12 UTC 2004  luedtke@TAG5800:/usr/src/sys.ZK/arch/evbppc/compile/TAG5800 evbppc

>Description:
System does not boot. No /sbin/init found.

sys/arch/powerpc/ibm4xx/trap.c, copyinstr.c, copyoutstr.c:
copyin() / copyout() / copyinstr() / copyoutstr():
The asm volatile statments specify the constraint for
len, udadd and kaddr to be a general register "r".
Actually they must be placed in a general register, but
that register must not be r0, since r0 is a special operand for addi.
The instruction "addi r0,0,1" is equal to "li r0,1", so instead of
incrementing r0 the constant 1 is moved to r0.
The result is that copyout etc. will never copy a single byte, and
sys_execve ("/sbin/init", ...) doesn't find a path argument.
FIX: specify powerpc specific constraint "b" in asm volatile.

sys/arch/powerpc/ibm4xx/clock.c:
delay():
scratch is clobbered before tbh and tbl are evaluated, so the
constraint for scratch should be "=&r" instead of "=r".
Otherwise gcc will reuse the register and either tbh or tbl will
be overwritten.
>How-To-Repeat:
Compile the kernel using gcc3, and try to boot it.
>Fix:
Specify other constraints in asm volatile (see above).
>Release-Note:
>Audit-Trail:
>Unformatted: