Subject: Re: assertion failure with pthreads
To: None <port-sh3@netbsd.org>
From: Christian Groessler <cpg@aladdin.de>
List: port-sh3
Date: 06/21/2003 16:02:19
--=-=-=

Hi,

> > ftp.groessler.org/pub/chris/dreamcast/netbsd/tmp/pthread-sh3.tgz .

> Hi, I unpacked this archive to /usr/src/lib and tried to cross compile 
> everything using build.sh. The result was undefined references to 
> debout, dumpregs, and pthread__switch_return_point. Is there a simple 
> way to make this compile? Vesa

Sorry, I forgot to include some things for compilation with DEBUG
defined.

Add the following to lib/libpthread/pthread_alarms.c:

-------------------------------
#ifdef __sh__
#include <stdio.h>
void dumpiter(void)
{
	struct pt_alarm_t *iterator;
        for ((iterator) = ((&pthread_alarmqueue)->ptqh_first);
	     (iterator);
	     (iterator) = ((iterator)->pta_next.ptqe_next)) {

		printf("dumpiter: (iterator = %p, iterator->pta_time = %p\n\tnext = %p)\n",
		       iterator, iterator ? iterator->pta_time: NULL,
		       iterator->pta_next.ptqe_next
		       ); fflush(stdout);
        }
}


void dumpregs(const ucontext_t *ctx);
void dumpregs(const ucontext_t *ctx)
{
	printf("dumpregs %p\n", ctx);
	printf("\tr0\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R0]);
	printf("\tr1\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R1]);
	printf("\tr2\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R2]);
	printf("\tr3\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R3]);
	printf("\tr4\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R4]);
	printf("\tr5\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R5]);
	printf("\tr6\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R6]);
	printf("\tr7\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R7]);
	printf("\tr8\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R8]);
	printf("\tr9\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R9]);
	printf("\tr10\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R10]);
	printf("\tr11\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R11]);
	printf("\tr12\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R12]);
	printf("\tr13\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R13]);
	printf("\tr14\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R14]);
	printf("\tr15\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_R15]);
	printf("\tpr\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_PR]);
	printf("\tsr\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_SR]);
	printf("\tpc\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_PC]);
	printf("\tmach\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_MACH]);
	printf("\tmacl\t= %8x\n", ctx->uc_mcontext.__gregs[_REG_MACL]);
	fflush(stdout);
	/*asm(".word 0xfffd");*/
}
#endif
-------------------------------


debout is provided in the following file:


--=-=-=
Content-Disposition: attachment; filename=debout.s
Content-Description: debout.s

! $Id$
!
! debug text output (NetBSD)
! (c) 2003 Copyright Christian Groessler, chris@groessler.org
!

SYS_write	=	4
OUTFD		=	1		! stdout

	.little
	.align	1

	.global	debout
debout:
	mov.l	r0,@-r15
	mov.l	r1,@-r15
	mov.l	r2,@-r15
	mov.l	r3,@-r15
	mov.l	r4,@-r15
	mov.l	r5,@-r15
	mov.l	r6,@-r15
	mov.l	r7,@-r15
	mov.l	r8,@-r15
	mov.l	r9,@-r15
	mov.l	r10,@-r15
	mov.l	r11,@-r15
	mov.l	r12,@-r15
	mov.l	r13,@-r15
	mov.l	r14,@-r15

	sts	pr,r1			! return address is start of output string
	mov	r1,r5			! r5 - buffer address for syscall
	sub	r2,r2
	mov	#0,r2			! length
loop:	mov.b	@r1+,r0
	and	#255,r0
	tst	r0,r0
	bt	end
	add	#1,r2			! adjust length
	bf	loop

end:	mov	r2,r6			! r6 - length parameter for syscall
	mov.l	r1,@-r15		! save address of end of string
	mov	#OUTFD,r4		! r4 - fd parameter for syscall
	mov	#SYS_write,r0		! do the syscall
	!.word	0xfffd

	trapa	#0x80
	nop

	mov.l	@r15+,r0		! get address of end of string again
	add	#1,r0
	mov	#-2,r1
	and	r1,r0			! word align it

	lds	r0,pr			! set return address

	mov.l	@r15+,r14
	mov.l	@r15+,r13
	mov.l	@r15+,r12
	mov.l	@r15+,r11
	mov.l	@r15+,r10
	mov.l	@r15+,r9
	mov.l	@r15+,r8
	mov.l	@r15+,r7
	mov.l	@r15+,r6
	mov.l	@r15+,r5
	mov.l	@r15+,r4
	mov.l	@r15+,r3
	mov.l	@r15+,r2
	mov.l	@r15+,r1
	mov.l	@r15+,r0
	rts
	nop

	.end

--=-=-=



pthread__switch_return_point comes from a recent change in
pthread_sa.c, which isn't integrated into the sh3 files yet.

regards,
chris

--=-=-=--