⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 balib.s

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 S
📖 第 1 页 / 共 2 页
字号:
/* bALib.s - buffer manipulation library assembly language routines *//* Copyright 1984-1995 Wind River Systems, Inc. *//*modification history--------------------01d,25sep01,yvp  Fix SPR62760: Use _WRS_TEXT_SEG_START macro instead of .align01c,08may01,pch  Add assembler abstractions (FUNC_EXPORT, FUNC_BEGIN, etc.)01b,17apr01,dtr  Making bfill etc into funtions fot linking.01a,27apr95,caf  made bcopy() use cr6 instead of nonvolatile cr2.01a,30jan95,caf  created.*//*DESCRIPTIONThis library contains optimized versions of the routines in bLib.cfor manipulating buffers of variable-length byte arrays.NOMANUALSEE ALSO: bLib, ansiString*/#define _ASMLANGUAGE#include "vxWorks.h"#include "asm.h"#ifndef	PORTABLE	/* functions */	FUNC_EXPORT(bcopy)	FUNC_EXPORT(bcopyBytes)	FUNC_EXPORT(bcopyWords)	FUNC_EXPORT(bcopyLongs)	FUNC_EXPORT(bfill)	FUNC_EXPORT(bfillBytes)	FUNC_EXPORT(swab)	_WRS_TEXT_SEG_START	/********************************************************************************* bcopy - copy one buffer to another** This routine copies the first <nbytes> characters from <source> to* <destination>.  Overlapping buffers are handled correctly.  Copying is done* in the most efficient way possible, which may include long-word, or even* multiple-long-word moves on some architectures.  In general, the copy* will be significantly faster if both buffers are long-word aligned.* (For copying that is restricted to byte, word, or long-word moves, see* the manual entries for bcopyBytes(), bcopyWords(), and bcopyLongs().)** RETURNS: N/A** SEE ALSO: bcopyBytes(), bcopyWords(), bcopyLongs()** NOMANUAL - manual entry in bLib* void bcopy*     (*     const char *source,         /@ pointer to source buffer      @/*     char *destination,          /@ pointer to destination buffer @/*     int nbytes                  /@ number of bytes to copy       @/*     )*/FUNC_LABEL(bcopy)	cmpwi	p2,0	beqlr			/* if (<nbytes> == 0) we're done            */	cmplw	p0,p1	beqlr			/* if (<dst> == <src>) we're done           */      	cmpwi	cr6,p2,8	bgt	bcfwd		/* if (<src> > <dst>) copy forward          */	/* copy reverse */	add	p0,p0,p2	/* <src> += <nbytes>                        */	add	p1,p1,p2	/* <dst> += <nbytes>                        */      	blt	cr6,bcrBCopy	/* if (<nbytes> < 8) byte copy reverse   */	andi.	r11,p0,3	andi.	r12,p1,3	xor.	p5,r11,r12	/* p5 = ((<src> & 3) ^ (<dst> & 3)) */	/* p5 reflects relative alignment of <src> and <drv> (0 - 3) */	beq	bcrL1		/* if (p5 == 0) then reverse longword copy  */      	cmpwi	p5,2	beq	bcrH1		/* if (p5 == 2) then reverse halfword copy  */      	b	bcrBCopy	/* ...otherwise reverse byte copy           */	/* longword reverse copy */bcrL1:	cmpwi	r11,0		/* already longword aligned?                */	beq	bcrL3	/* copy 1 - 3 bytes to align on longword boundary */	mtctr	r11bcrL2:  lbzu    p4,-1(p0)	/* load...                                  */	addi	p2,p2,-1	/* -- <nbytes>                              */        stbu    p4,-1(p1)	/* ...store                                 */        bdnz    bcrL2           /* decrement CTR and branch if != 0         */bcrL3:  andi.	p3,p2,3		/* p3 = (<nbytes> & 3)                      */        srwi	p2,p2,2		/* <nbytes> = (<nbytes> / 4)                */bcrLCopy:	/*         * Entry point from bcopyLongs()         *         *   p0 = source pointer         *   p1 = destination pointer         *   p2 = number of longwords (1 or more)         *   p3 = number of trailing bytes (0 to 3)	 */        mtctr   p2		/* CTR = <nlongs>                           */bcrLGO: lwzu    p4,-4(p0)	/* load...                                  */        stwu    p4,-4(p1)	/* ...store                                 */        bdnz    bcrLGO          /* decrement CTR and branch if != 0         */       	or.	p2,p3,p3	beqlr			/* if (p3 == 0) we're done                  */bcrBCopy:	/*         * Entry point from bcopyBytes()         *         *   p0 = source pointer         *   p1 = destination pointer         *   p2 = number of bytes (1 or more)	 */        mtctr   p2		/* CTR = <nbytes>                           */bcrBGO: lbzu    p4,-1(p0)	/* load...                                  */        stbu    p4,-1(p1)	/* ...store                                 */        bdnz    bcrBGO          /* decrement CTR and branch if != 0         */	blr			/* return                                   */	/* halfword reverse copy */bcrH1:	andi.	r11,r11,1	/* already halfword aligned?                */	beq	bcrH2	/* copy one byte to align on halfword boundary */	lbzu    p4,-1(p0)	/* load...                                  */	addi	p2,p2,-1	/* -- <nbytes>                              */        stbu    p4,-1(p1)	/* ...store                                 */	bcrH2:  andi.	p3,p2,1		/* p3 = (<nbytes> & 1)                      */        srwi	p2,p2,1		/* <nbytes> = (<nbytes> / 2)                */bcrHCopy:	/*         * Entry point from bcopyWords()         *         *   p0 = source pointer         *   p1 = destination pointer         *   p2 = number of halfwords (1 or more)         *   p3 = number of trailing bytes (0 to 1)	 */        mtctr   p2		/* CTR = <nwords>                           */bcrHGO:	lhzu    p4,-2(p0)	/* load...                                  */        sthu    p4,-2(p1)	/* ...store                                 */        bdnz    bcrHGO          /* decrement CTR and branch if != 0         */       	cmplwi	p3,0	beqlr			/* if (p3 == 0) we're done                  */	/* copy last byte */	lbz     p4,-1(p0)	/* load...                                  */        stb     p4,-1(p1)	/* ...store                                 */	blr			/* finally done                             */	/* copy forward */bcfwd:	blt	cr6,bcfBCopy	/* if (<nbytes> < 8) byte copy forward   */	andi.	r11,p0,3	andi.	r12,p1,3	xor.	p5,r11,r12	/* p5 = ((<src> & 3) ^ (<dst> & 3)) */	/* p5 reflects relative alignment of <src> and <drv> (0 - 3) */	beq	bcfL1		/* if (p5 == 0) then forward longword copy  */      	cmpwi	p5,2	beq	bcfH1		/* if (p5 == 2) then forward halfword copy  */      	b	bcfBCopy	/* ...otherwise forward byte copy           */	/* forward longword copy */bcfL1:	cmpwi	r11,0		/* already longword aligned?                */	beq	bcfL3	/* copy 1 - 3 bytes to align on longword boundary */bcfL2:  lbzu    p4,0(p0)	/* load...                                  */	addi	p2,p2,-1	/* -- <nbytes>                              */	addi	r11,r11,1	/* ++ r11                                   */        stbu    p4,0(p1)	/* ...store                                 */	addi	p0,p0,1		/* ++ <src>                                 */	addi	p1,p1,1		/* ++ <dst>                                 */      	cmpwi	r11,4		/* longword aligned?                        */        bne     bcfL2	bcfL3:  andi.	p3,p2,3		/* p3 = (<nbytes> & 3)                      */        srwi	p2,p2,2		/* p2 = (<nbytes> / 4)                      */bcfLCopy:	/*         * Entry point from bcopyLongs()         *         *   p0 = source pointer         *   p1 = destination pointer         *   p2 = number of longwords (1 or more)         *   p3 = number of trailing bytes (0 to 3)	 */	addi    p0,p0,-4	/* <src> -= 4                               */	addi    p1,p1,-4	/* <dst> -= 4                               */	mtctr   p2		/* CTR = <nlongs>                           */bcfLGO: lwzu    p4,4(p0)	/* load...                                  */	stwu    p4,4(p1)	/* ...store                                 */	bdnz    bcfLGO          /* decrement CTR and branch if != 0         */	or.	p2,p3,p3	beqlr			/* if (p3 == 0) we're done                  */	addi    p0,p0,4		/* <src> += 4                               */	addi    p1,p1,4		/* <dst> += 4                               */bcfBCopy:	/*         * Entry point from bcopyBytes()         *         *   p0 = source pointer         *   p1 = destination pointer         *   p2 = number of bytes (1 or more)	 */	addi    p0,p0,-1	/* <src> -= 1                               */	addi    p1,p1,-1	/* <dst> -= 1                               */        mtctr   p2		/* CTR = <nbytes>                           */bcfBGO: lbzu    p4,1(p0)	/* load...                                  */        stbu    p4,1(p1)	/* ...store                                 */        bdnz    bcfBGO          /* decrement CTR and branch if != 0         */	blr			/* return                                   */	/* halfword forward copy */bcfH1:	andi.	r11,r11,1	/* already halfword aligned?                */	beq	bcfH2	/* copy one byte to align on halfword boundary */	lbzu    p4,0(p0)	/* load...                                  */	addi	p2,p2,-1	/* -- <nbytes>                              */        stbu    p4,0(p1)	/* ...store                                 */	addi    p0,p0,1		/* <src> += 1                               */	addi    p1,p1,1		/* <dst> += 1                               */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -