linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Olaf Hering <olh@suse.de>
To: linuxppc-dev@ozlabs.org
Subject: memcpy for unaligned memory regions
Date: Fri, 28 Oct 2005 23:42:59 +0200	[thread overview]
Message-ID: <20051028214258.GA30726@suse.de> (raw)

The vmlinux.coff is constantly crashing for me, depending on the size
and location of the vmlinux.gz and the ramdisk. The 601 can not handle
unaligned memory access that cross a page boundary (or whatever).
So I tweaked the memcpy.S from arch/ppc64/boot to deal with this. 
Does this look ok?


	.globl	memmove
memmove:
	cmpwi	0,r5,0
	beqlr
	cmplw	0,r3,r4
	bgt	backwards_memcpy
	/* fall through */

	.globl	memcpy
memcpy:
	cmpwi	0,r5,0
	beqlr
	andi.	r0,r4,3			/* get src word aligned */
	beq	20f
10:	subfic	r0,r0,4
	cmpd	r0,r5
	blt	11f
	mr	r0,r5
11:	mtctr	r0
12:	lbz	r7,0(r4)
	stb	r7,0(r3)
	addi	r4,r4,1
	addi	r3,r3,1
	bdnz	12b
	subf.	r5,r0,r5
	beqlr
20:	andi.	r0,r3,3			/* get dest word aligned */
	beq	30f
	subfic	r0,r0,4
	cmpd	r0,r5
	blt	21f
	mr	r0,r5
21:	mtctr	r0
22:	lbz	r7,0(r4)
	stb	r7,0(r3)
	addi	r4,r4,1
	addi	r3,r3,1
	bdnz	22b
	subf.	r5,r0,r5
	beqlr
	andi.	r0,r4,3			/* get src word aligned */
	bne	10b
30:
	rlwinm.	r7,r5,32-3,3,31		/* r7 = r5 >> 3 */
	addi	r6,r3,-4
	addi	r4,r4,-4
	beq	32f			/* if less than 8 bytes to do */
	mtctr	r7
31:	lwz	r7,4(r4)
	lwzu	r8,8(r4)
	stw	r7,4(r6)
	stwu	r8,8(r6)
	bdnz	31b
	andi.	r5,r5,7
32:	cmplwi	0,r5,4
	blt	33f
	lwzu	r0,4(r4)
	addi	r5,r5,-4
	stwu	r0,4(r6)
33:	cmpwi	0,r5,0
	beqlr
	mtctr	r5
	addi	r4,r4,3
	addi	r6,r6,3
34:	lbzu	r0,1(r4)
	stbu	r0,1(r6)
	bdnz	34b
	blr

	.globl	backwards_memcpy
backwards_memcpy:
	add	r6,r3,r5
	add	r4,r4,r5

	andi.	r0,r4,3			/* get src word aligned */
	beq	20f
10:	cmpd	r0,r5
	blt	11f
	mr	r0,r5
11:	mtctr	r0
12:	lbzu	r7,-1(r4)
	stbu	r7,-1(r6)
	bdnz	12b
	subf.	r5,r0,r5
	beqlr
20:	andi.	r0,r6,3			/* get dest word aligned */
	beq	30f
	cmpd	r0,r5
	blt	21f
	mr	r0,r5
21:	mtctr	r0
22:	lbzu	r7,-1(r4)
	stbu	r7,-1(r6)
	bdnz	22b
	subf.	r5,r0,r5
	beqlr
	andi.	r0,r4,3			/* get src word aligned */
	bne	10b
30:
	rlwinm.	r7,r5,32-3,3,31		/* r7 = r5 >> 3 */
	beq	32f
	mtctr	r7
31:	lwz	r7,-4(r4)
	lwzu	r8,-8(r4)
	stw	r7,-4(r6)
	stwu	r8,-8(r6)
	bdnz	31b
	andi.	r5,r5,7
32:	cmplwi	0,r5,4
	blt	33f
	lwzu	r0,-4(r4)
	subi	r5,r5,4
	stwu	r0,-4(r6)
33:	cmpwi	0,r5,0
	beqlr
	mtctr	r5
34:	lbzu	r0,-1(r4)
	stbu	r0,-1(r6)
	bdnz	34b
	blr

-- 
short story of a lazy sysadmin:
 alias appserv=wotan

                 reply	other threads:[~2005-10-28 21:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051028214258.GA30726@suse.de \
    --to=olh@suse.de \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).