powerpc port

jim hopper hopperj at macconnect.com
Thu Aug 12 20:46:57 PDT 1999


>
>The segfault must be caused by something else.
>What does your sysdepCallMethod() look like?
>
>	- Godmar


I got the following from an incomplete port of kaffe 1.0.b1 that 
tenon did and never finished.  the b1 port didnt core dump but failed 
a lot of the tests in test dir (although it passed a lot as well)

anyway here it is if anyone can point out any possibilities with it i 
would be grateful.

jim


************

# kaffe function call struct - see support.h: callMethodInfo

MAXMARGS		=		64
KAF_FUNC		=		0		# function to call
KAF_ARGS		=		4		# arg list pointer
KAF_RET			=		8		# ret pointer
KAF_NARGS		=		12		# number of arguments
KAF_ARGSIZE		=		16		# Num arg bytes?
KAF_RETSIZE		=		20		# 0 | 1 | 2 
bytes to store in KAF_RET
KAF_RETTYPE		=		21		# type 'J', 'F' ...
KAF_CALLSIZE		=		22		# array of 
param sizes also 0 | 1 | 2
KAF_CALLTYPE		=		22+MAXMARGS	# call types 
'J', 'F', ...
KAF_STRU_SIZE		=		22+MAXMARGS+MAXMARGS

KAF_TYPE_OFFSET		=		MAXMARGS	# offset from 
CALLSIZE entry to CALLTYPE entry

KAF_FLOAT_TYPE		=		'F'		# float type
KAF_DOUBLE_TYPE		=		'D'		# double type

PPC_LINK_SIZE		=		24		# ppc linkage 
area 24 bytes
PPC_LINK_SP		=		0		# offset to saved sp
PPC_LINK_CR		=		4		# offset to saved cr
PPC_LINK_LR		=		8		# offset to saved lr
PPC_LINK_RESV1		=		12		# reserved 1
PPC_LINK_RESV2		=		16		# reserved 2
PPC_LINK_RTOC		=		20		# offset to saved rtoc

         .toc

         .globl  powerpcCallMethod{DS}
         .globl  .powerpcCallMethod{PR}

         .csect  powerpcCallMethod{DS}
powerpcCallMethod:
         .long   .powerpcCallMethod{PR}
         .long   TOC{TC0}
         .long   0

         .csect  .powerpcCallMethod{PR}

	mflr	r0				# get link
	stw	r0,8(sp)			# save link in standard place
	stmw	r27,-20(sp)			# save r27-r31
	stwu	sp,-80(sp)			# update the stack ptr

	mr	r12,r3				# r12 is base of the 
callMethodInfo struct

	# num bytes to extend stack
	# ((nargs + ndouble)*4) + PPC_LINK_SIZE

	lwz	r0,KAF_NARGS(r12)		# get num args
	mr.	r3,r0				# save and test

	rlwinm	r0,r0,3,0,31			# shift left 3  - multiply by 8
	subf	r11,r0,sp			# point to param area in r11
	subi	r4,r11,PPC_LINK_SIZE		# add link area size 
and were done

	stw	sp,PPC_LINK_SP(r4)		# store the old sp 
for recovery later
	mr	sp,r4				# update the stack

	stw	r12,PPC_LINK_RESV1(sp)		# store call data 
stru for later as well

	# use test at mr. above
	beq	do_call				# just go call

	mtctr	r3				# load up ctr

	addi	r27,r12,KAF_CALLSIZE-1		# point at size array
	li	r28,0				# next general reg avail
	li	r29,0				# next fp reg avail
	lwz	r30,KAF_ARGS(r12)		# point at args

top_type:
	lbzu	r0,1(r27)			# get arg size

	cmpwi	r0,1				# one word long?
	bne	try_double

	lbz	r0,KAF_TYPE_OFFSET(r27)		# float or int
	cmpwi	r0,KAF_FLOAT_TYPE
	bne	do_int_param			# do int or less here
	b	do_float_param			# do float

try_double:
	cmpwi	r0,2
	beq	do_double_param			# do the double thing

next_type:
	bdnz	top_type			# back to next param

do_call:
	lwz	r12,KAF_FUNC(r12)		# get pointer to 
function descriptor

	lwz	r0,0(r12)			# get addr
	mtlr	r0				# get to the ctr reg
	stw	rtoc,PPC_LINK_RTOC(sp)		# save our rtoc
	lwz	rtoc,4(r12)			# load the new rtoc

	blrl					# to make the call
	lwz	rtoc,PPC_LINK_RTOC(sp)		# restore our rtoc

	lwz	r12,PPC_LINK_RESV1(sp)		# restore ptr to call struct

	lwz	r5,KAF_RET(r12)			# get pointer to return

	lbz	r0,KAF_RETSIZE(r12)		# get return size

	cmpwi	r0,1				# normal int return
	bne	try_ret_double

	lbz	r0,KAF_RETTYPE(r12)		# float or int
	cmpwi	r0,KAF_FLOAT_TYPE
	bne	do_int_return

	stfs	1,0(r5)				# store the float
	b	exit_routine

try_ret_double:
	cmpwi	r0,2
	bne	exit_routine

	lbz	r0,KAF_RETTYPE(r12)		# get ret type
	cmpwi	r0,KAF_DOUBLE_TYPE		# double
	bne	do_long_int_ret

	stfd	1,0(r5)				# store the double
	b 	exit_routine

do_long_int_ret:
	stw	r3,0(r5)			# store the first
	stw	r4,4(r5)			# store the second
	b	exit_routine

do_int_return:
	stw	r3,0(r5)			# just store the word

exit_routine:
	lwz	sp,PPC_LINK_SP(sp)		# restore the stack

	lwz	r0,88(sp)			# get my link
	addi	sp,sp,80			# reset the stack
	mtlr	r0				# restore the link reg
	lmw	r27,-20(sp)			# restore gen regs

	blr					# go there

do_int_param:
	cmpwi	r28,0				# r3 avail
	bne	dip1

	lwz	r3,0(r30)			# load r3
	b	dip_exit
dip1:
	cmpwi	r28,1				# r4 avail
	bne 	dip2

	lwz	r4,0(r30)			# load r4
	b	dip_exit
dip2:
	cmpwi	r28,2
	bne	dip3				# r5 avail

	lwz	r5,0(r30)			# load r5
	b 	dip_exit
dip3:
	cmpwi	r28,3
	bne	dip4				# r6 avail

	lwz	r6,0(r30)
	b	dip_exit
dip4:
	cmpwi	r28,4
	bne	dip5				# r7 avail

	lwz	r7,0(r30)
	b	dip_exit
dip5:
	cmpwi	r28,5
	bne	dip6				# r8 avail

	lwz	r8,0(r30)
	b	dip_exit
dip6:
	cmpwi	r28,6
	bne	dip7				# r9 avail

	lwz	r9,0(r30)
	b	dip_exit
dip7:
	cmpwi	r28,7
	bne	dip8				# r10 avail

	lwz	r10,0(17)
	b	dip_exit
dip8:
	lwz	r0,0(r30)
	stw	r0,0(r11)			# store on stack

	b	dip_exit

dip_exit:
	addi	r11,r11,4			# update stack image ptr
	addi	r30,r30,8			# update args ptr
	addi	r28,r28,1			# say one less gen reg avail

	b	next_type

do_float_param:

	cmpwi	r29,0				# fp1 avail
	bne	dfp1

	lfs	1,0(r30)			# load fp1
	b	dfp_exit
dfp1:
	cmpwi	r29,1				# fp2 avail
	bne 	dfp2

	lfs	2,0(r30)			# load fp2
	b	dfp_exit
dfp2:
	cmpwi	r29,2
	bne	dfp3				# fp3 avail

	lfs	3,0(r30)			# load fp3
	b 	dfp_exit
dfp3:
	cmpwi	r29,3
	bne	dfp4				# fp4 avail

	lfs	4,0(r30)
	b	dfp_exit
dfp4:
	cmpwi	r29,4
	bne	dfp5				# fp5 avail

	lfs	5,0(r30)
	b	dfp_exit
dfp5:
	cmpwi	r29,5
	bne	dfp6				# fp6 avail

	lfs	6,0(r30)
	b	dfp_exit
dfp6:
	cmpwi	r29,6
	bne	dfp7				# fp7 avail

	lfs	7,0(r30)
	b	dfp_exit
dfp7:
	cmpwi	r29,7
	bne	dfp8				# fp8 avail

	lfs	8,0(r30)
	b	dfp_exit
dfp8:
	cmpwi	r29,8
	bne	dfp9				# fp9 avail

	lfs	9,0(r30)
	b 	dfp_exit
dfp9:
	cmpwi	r29,9
	bne	dfp10				# fp10 avail

	lfs	10,0(r30)
	b	dfp_exit
dfp10:
	cmpwi	r29,10
	bne	dfp11				# fp11 avail

	lfs	11,0(r30)
	b	dfp_exit
dfp11:
	cmpwi	r29,11
	bne	dfp12				# fp12 avail

	lfs	12,0(r30)
	b	dfp_exit
dfp12:
	cmpwi	r29,12
	bne	dfp13				# fp13 avail

	lfs	13,0(r30)
	b	dfp_exit
dfp13:
	lfs	0,0(r30)
	stfs	0,0(r11)			# store on stack

	b	dfp_exit

dfp_exit:
	addi	r11,r11,4			# update stack image ptr
	addi	r30,r30,8			# update args ptr
	addi	r29,r29,1			# say one less fp reg avail
	addi	r28,r28,1			# say one less gen reg avail

	b	next_type

do_double_param:
	cmpwi	r29,0				# fp1 avail
	bne	ddp1

	lfd	1,0(r30)			# load fp1
	b	ddp_exit
ddp1:
	cmpwi	r29,1				# fp2 avail
	bne 	ddp2

	lfd	2,0(r30)			# load fp2
	b	ddp_exit
ddp2:
	cmpwi	r29,2
	bne	ddp3				# fp3 avail

	lfd	3,0(r30)			# load fp3
	b 	ddp_exit
ddp3:
	cmpwi	r29,3
	bne	ddp4				# fp4 avail

	lfd	4,0(r30)
	b	ddp_exit
ddp4:
	cmpwi	r29,4
	bne	ddp5				# fp5 avail

	lfd	5,0(r30)
	b	ddp_exit
ddp5:
	cmpwi	r29,5
	bne	ddp6				# fp6 avail

	lfd	6,0(r30)
	b	ddp_exit
ddp6:
	cmpwi	r29,6
	bne	ddp7				# fp7 avail

	lfd	7,0(r30)
	b	ddp_exit
ddp7:
	cmpwi	r29,7
	bne	ddp8				# fp8 avail

	lfd	8,0(r30)
	b	ddp_exit
ddp8:
	cmpwi	r29,8
	bne	ddp9				# fp9 avail

	lfd	9,0(r30)
	b 	ddp_exit
ddp9:
	cmpwi	r29,9
	bne	ddp10				# fp10 avail

	lfd	10,0(r30)
	b	ddp_exit
ddp10:
	cmpwi	r29,10
	bne	ddp11				# fp11 avail

	lfd	11,0(r30)
	b	ddp_exit
ddp11:
	cmpwi	r29,11
	bne	ddp12				# fp12 avail

	lfd	12,0(r30)
	b	ddp_exit
ddp12:
	cmpwi	r29,12
	bne	ddp13				# fp13 avail

	lfd	13,0(r30)
	b	ddp_exit
ddp13:
	lfd	0,0(r30)
	stfd	0,0(r11)			# store on stack

	b	ddp_exit

ddp_exit:
	addi	r11,r11,8			# update stack image ptr
	addi	r30,r30,8			# update args ptr
	addi	r29,r29,1			# say one less fp reg avail
	addi	r28,r28,2			# say two less gen reg avail

	b	next_type

At a recent computer software engineering course in the US, the participants
were given an awkward question to answer.  "If you had just boarded an
airliner and discovered that your team of programmers had been responsible
for the flight control software, how many of you would disembark
immediately?"
                     unknown author


More information about the kaffe mailing list