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

📄 balib.s

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 S
📖 第 1 页 / 共 2 页
字号:
byteOptBwd:	sltu	t0, a2, RS 		/* compare with width bytes */	bne	zero, t0, bloopbwd	/* less than width, do bytes */	srl	t1, a2, RSLOG2		/* bytes div width */	addu	a0, a0, 1		/* one beyond last source byte */	addu	a1, a1, 1		/* one beyond last dest byte */bOptBwdLoop:	addu	a0, a0,-RS		/* decrement source word pointer */	LHI	t0, 0(a0)		/* read first part */	addu	a1, a1,-RS		/* decrement dest word pointer */	LLO	t0, RS-1(a0)		/* read second part */	subu	t1, 1			/* decrement word counter */	SHI	t0, 0(a1)		/* store first part */	bne	zero, t1, bOptBwdLoop	/* are we done ? */	SLO	t0, RS-1(a1)		/* store second part */	.set noat	sltu	AT,a1,v0		/* compare dest and destend */	bne	AT,zero,cEnd 		/* are we done ? */	nop	.set atbloopbwd:	addiu	a1,a1,-1		/* back up dest ptr	*/	lbu	t9,0(a0)		/* load a byte 		*/	.set	noat	sltu	AT,a1,v0		/* check for done ?	*/	addiu	a0,a0,-1		/* back up source ptr 	*/	beq	AT,zero,bloopbwd	/* one more time? 	*/	.set	at	sb	t9,1(a1)		/* store in delay slot	*/cEnd:	j	ra			/* over and out */	nop	.set	reorder	.end	bcopy/********************************************************************************* bcopyBytes - copy one buffer to another a byte at a time** This routine copies the first `nbytes' characters from* `source' to `destination'.* It is identical to bcopy except that the copy is always performed* a byte at a time.  This may be desirable if one of the buffers* can only be accessed with byte instructions, as in certain byte-wide* memory-mapped peripherals.** SEE ALSO: bcopy (2)** NOMANUAL - manual entry in bLib (1)* void bcopyBytes (source, destination, nbytes)*     char *source;       /* pointer to source buffer      **     char *destination;  /* pointer to destination buffer **     int nbytes;         /* number of bytes to copy       **/	.ent	bcopyBytesbcopyBytes:	/* Find out if there is an overlap problem.	 * We have to copy backwards if destination lies within source,	 * i.e. ((destination - source) > 0 && < nbytes) */	blez	a2, cbEnd		/* optimize first while */	subu	t3, a1, a0		/* destination - source */	blez	t3, cbFwd		/* <= 0 means copy forward */	bltu	t3, a2, cbBak		/* < nbytes means copy backwards */	/* Copy the whole thing forward, byte by byte */cbFwd:	addu	a3, a2, a1		/* add bytes + destination */cbFwdLoop:	lbu	t4, 0(a0)		/* load source byte */	sb	t4, 0(a1)		/* store dest byte */	addiu	a0, a0, 1		/* bump source pointer */	addiu	a1, a1, 1		/* bump dest pointer */	sltu	t0, a1, a3		/* compare destination and end */	bne	t0, zero, cbFwdLoop	/* done? */	j	ra			/* return */	/* Copy the whole thing backward, byte by byte */cbBak:	move	a3, a1			/* copy destination to a3 */	addu	a1, a1, a2		/* point to end of dest */	addu	a0, a0, a2		/* point to end of source */	addiu	a0, a0, -1		/* adjust to last source byte */	addiu	a1, a1, -1		/* adjust to last dest byte */cbBak1:	lbu	t4, 0(a0)		/* load source byte */	sb	t4, 0(a1)		/* store dest byte */	addiu	a0, a0, -1		/* decrement source pointer */	addiu	a1, a1, -1		/* decrement dest pointer */	subu	t0, a1, a3		/* t0 <-- (destination - end) */	bgez	t0, cbBak1		/* done? */cbEnd:	j	ra			/* return */	.end	bcopyBytes/********************************************************************************	!!!!!!! in this context bcopyWords refers to 2 byte entities !!!!!!* bcopyWords - copy one buffer to another a word at a time** This routine copies the first `nwords' characters from* `source' to `destination'.* It is similar to bcopy except that the copy is always performed* a word at a time.  This may be desirable if one of the buffers* can only be accessed with word instructions, as in certain word-wide* memory-mapped peripherals.  The source and destination must be word-aligned.** SEE ALSO: bcopy (2)** NOMANUAL - manual entry in bLib (1)* void bcopyWords (source, destination, nwords)*     char *source;       /* pointer to source buffer      **     char *destination;  /* pointer to destination buffer **     int nwords;         /* number of words to copy       **/	.ent	bcopyWordsbcopyWords:	/* Find out if there is an overlap problem.	 * We have to copy backwards if destination lies within source,	 * i.e. ((destination - source) > 0 && < nbytes) */	blez	a2, cwEnd		/* do we have at least one */	move	t2,a2			/* save half word count */	sll	t4,a2,1			/* convert to bytes */	subu	t3, a1, a0		/* destination - source */	blez	t3,cwFwd		/* <= 0 means copy forward */	bltu	t3,t4,cwBak		/* < nbytes means copy backwards */	/* Copy the whole thing forward, 2 byte by 2 byte */cwFwd:	lh 	t4,0(a0)		/* load source 2 byte */	sh	t4,0(a1)		/* store dest 2 byte */	addiu	a0,a0,2			/* bump source pointer */	addiu	a1,a1,2			/* bump dest pointer */	addiu	t2,t2,-1		/* decrement counter */	bne	t2,zero,cwFwd		/* done? */	j	ra			/* return */	/* Copy the whole thing backward, 2 byte by 2 byte */cwBak:	sll	t3, t2, 1		/* convert half to bytes */	addu	a0,a0,t3		/* point to end of source */	addu	a1,a1,t3		/* point to end of dest */	addiu	a0,a0,-2		/* adjust to last source byte */	addiu	a1,a1,-2		/* adjust to last dest byte */cwBak1:	lh 	t4,0(a0)		/* load source 2 byte */	sh	t4,0(a1)		/* store dest 2 byte */	addiu	a0,a0,-2		/* decrement source pointer */	addiu	a1,a1,-2		/* decrement dest pointer */	addiu	t2,t2,-1		/* decrement counter */	bne	t2,zero,cwBak1		/* done? */cwEnd:	j	ra			/* return */	.end	bcopyWords/********************************************************************************	!!!!!!!! in this context longs refers to 4 byte quantities !!!!!!!!* bcopyLongs - copy one buffer to another a long at a time** This routine copies the first `nlongs' characters from* `source' to `destination'.* It is similar to bcopy except that the copy is always performed* a long at a time.  This may be desirable if one of the buffers* can only be accessed with long instructions, as in certain long-wide* memory-mapped peripherals.  The source and destination must be long-aligned.** SEE ALSO: bcopy (2)** NOMANUAL - manual entry in bLib (1)* void bcopyLongs (source, destination, nlongs)*     char *source;       /* pointer to source buffer      **     char *destination;  /* pointer to destination buffer **     int nlongs;         /* number of longs to copy       **/	.ent	bcopyLongsbcopyLongs:	/* Find out if there is an overlap problem.	 * We have to copy backwards if destination lies within source,	 * i.e. ((destination - source) > 0 && < nbytes) */	blez	a2, clEnd		/* do we have at least one */	move	t2,a2			/* save long word count */	sll	t4,a2,2			/* convert to bytes */	subu	t3, a1, a0		/* destination - source */	blez	t3,clFwd		/* <= 0 means copy forward */	bltu	t3,t4,clBak		/* < nbytes means copy backwards */	/* Copy the whole thing forward, word by word */clFwd:	lw	t4,0(a0)		/* load source word */	sw	t4,0(a1)		/* store dest word */	addiu	a0,a0,4			/* bump source pointer */	addiu	a1,a1,4			/* bump dest pointer */	addiu	t2,t2,-1		/* decrement counter */	bne	t2,zero,clFwd		/* done? */	j	ra			/* return */	/* Copy the whole thing backward, word by word */clBak:	sll	t3, t2, 2		/* convert word to bytes */	addu	a0,a0,t3		/* point to end of source */	addu	a1,a1,t3		/* point to end of dest */	addiu	a0,a0,-4		/* adjust to last source byte */	addiu	a1,a1,-4		/* adjust to last dest byte */clBak1:	lw	t4,0(a0)		/* load source word */	sw	t4,0(a1)		/* store dest word */	addiu	a0,a0,-4		/* decrement source pointer */	addiu	a1,a1,-4		/* decrement dest pointer */	addiu	t2,t2,-1		/* decrement counter */	bne	t2,zero,clBak1		/* done? */clEnd:	j	ra			/* return */	.end	bcopyLongs/********************************************************************************* bfill - fill buffer with character** This routine fills the first `nbytes' characters of the specified buffer* with the specified character.* The fill is optimized by filling 4 bytes at a time if possible,* (see bfillBytes (2) for filling a byte at a time only).** SEE ALSO: bfillBytes (2)** NOMANUAL - manual entry in bLib (1)* void bfill (buf, nbytes, ch)*     char *buf;		/* pointer to buffer              **     int nbytes;		/* number of bytes to fill        **     char ch;			/* char with which to fill buffer **/	.ent	bfillbfill:	beq	zero, a1, bFild		/* take care of no byte copy */	addiu	t4,a1,-(2*RS+2)		/* nbytes < 2 * width + pad */	bltz	t4,bFilb	/* propogate byte across word */	and 	a2,0xff	SLL	t3,a2,8			/* move to bits 8-15 */	or	t3,a2			/* combine with 0-7 */	SLL	t1,t3,16		/* move result to 16-31 */	or	t3,t1			/* combine again */#if (_WRS_INT_REGISTER_SIZE == 8)	dsll32	t1,t3,0			/* move to bits 32-64 */	or	t3,t1			/* combine again */#endif	and	t0,a0,RS-1		/* pointer offset */	beq	t0,zero,bFil1		/* start on word boundry */	SHI	t3,0(a0)		/* store partial word */	li	t4,RS			/* set to compute bytes moved */	subu	t4,t0			/* width - ptr mod width = # bytes moved */	addu	a0,t4			/* update pointer */	subu	a1,t4			/*   and counter */bFil1:	and 	t2,a1,RS-1		/* count modulo n */	srl	a3,a1,RSLOG2		/* byte count to word count */	blez	a3, bFilb		/* if no more word count					 * but with bytes left */bFil2:	S	t3,0(a0)		/* store n bytes */	addu	a0,RS			/* bump pointer */	sub	a3,1			/* decrement word counter */	bgtz	a3,bFil2		/* done ? */	beqz	t2,bFild		/* partial word left? */#ifdef	FULLY_OPTIMIZED	addu	a0,t2			/* need to point at last byte */	SLO	t3,-1(a0)		/* store partial word */	j	ra			/* return */#else	/* FULLY_OPTIMIZED */	move	a1, t2			/* bytes left to copy */#endif	/* FULLY_OPTIMIZED */bFilb:	sb	a2,0(a0)		/* byte to buffer */	addiu	a0,a0,1			/* increment buffer pointer */	addiu	a1,a1,-1		/* decrement counter */	bne	a1,zero,bFilb		/* done? */bFild:	j	ra			/* return */	.end	bfill/********************************************************************************* bfillBytes - fill buffer with character a byte at a time** This routine fills the first `nbytes' characters of the* specified buffer with the specified character.* It is identical to bfill (2) except that the fill is always performed* a byte at a time.  This may be desirable if the buffer* can only be accessed with byte instructions, as in certain byte-wide* memory-mapped peripherals.** SEE ALSO: bfill (2)** NOMANUAL - manual entry in bLib (1)* void bfillBytes (buf, nbytes, ch)*     char *buf;	/* pointer to buffer              **     int nbytes;	/* number of bytes to fill        **     char ch;		/* char with which to fill buffer **/	.ent	bfillBytesbfillBytes:	blez	a1,bfillBytesEnd        /* return if nbytes <= 0 */bFilby:	sb	a2,0(a0)		/* byte to buffer */	addiu	a0,a0,1			/* increment buffer pointer */	addiu	a1,a1,-1		/* decrement counter */	bne	a1,zero,bFilby		/* done? */bfillBytesEnd:	j	ra			/* return */	.end	bfillBytes#endif /* bALib_PORTABLE */

⌨️ 快捷键说明

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