📄 balib.s
字号:
/* bALib.s - i80x86 buffer manipulation library assembly routines *//* Copyright 1984-2001 Wind River Systems, Inc. *//*modification history--------------------01d,22aug01,hdn added FUNC/FUNC_LABEL, replaced .align with .balign01c,01jun93,hdn updated to 5.1. - fixed #else and #endif - changed VOID to void - changed ASMLANGUAGE to _ASMLANGUAGE - changed copyright notice01b,13oct92,hdn debugged.01a,07apr92,hdn written based on TRON version.*//*DESCRIPTIONThis library contains optimized versions of the routines in bLib.cfor manipulating buffers of variable-length byte arrays.NOMANUALINTERNALi80386 transfer bus cycles for bytes, words, dwords. -------------------------------------+----+----------------+---------------+ byte length of logical operand 1 2 4 -------------------------------------+----+----------------+---------------+ physical byte address in memory xx 00 01 10 11 00 01 10 11 -------------------------------------+----+----------------+---------------+ transfer cycles over 32bits data bus b w w w hb d hb hw h3 lb l3 lw lb -------------------------------------+----+----------------+---------------+ transfer cycles over 16bits data bus b w lb w hb lw hb hw mw hb lb hw lb lw hb mw lb -------------------------------------+----+----------------+---------------+ b: byte transfer l: low order portion w: word transfer h: high order portion 3: 3-byte transfer m: middle order portion d: dword transfer x: don't careSEE ALSO: bLib(1), strLib(1)*/#define _ASMLANGUAGE#include "vxWorks.h"#include "asm.h" .data .globl FUNC(copyright_wind_river) .long FUNC(copyright_wind_river)#ifndef PORTABLE /* internals */ .globl GTEXT(bcopy) .globl GTEXT(bcopyBytes) .globl GTEXT(bcopyWords) .globl GTEXT(bcopyLongs) .globl GTEXT(bfill) .globl GTEXT(bfillBytes) .globl GTEXT(bfillWords) .globl GTEXT(bfillLongs) .text .balign 16/********************************************************************************* bcopy - copy one buffer to another** This routine copies the first `nbytes' characters from* `source' to `destination'. Overlapping buffers are handled correctly.* The copy is optimized by copying 4 bytes at a time if possible,* (see bcopyBytes (2) for copying a byte at a time only).** SEE ALSO: bcopyBytes (2)** NOMANUAL - manual entry in bLib (1)* void bcopy (source, destination, nbytes)* char *source; /* pointer to source buffer ** char *destination; /* pointer to destination buffer ** int nbytes; /* number of bytes to copy **/FUNC_LABEL(bcopy) pushl %ebp movl %esp,%ebp pushl %esi pushl %edi pushf /* put src in %esi, dest in %edi, and count in %edx */ movl ARG1(%ebp),%esi /* source */ movl ARG2(%ebp),%edi /* destination */ movl ARG3(%ebp),%edx /* nbytes */ /* Find out if there is an overlap problem. * We have to copy backwards if destination lies within source, * i.e. ((destination - source) > 0 && < nbytes) */ movl %edi,%eax /* destination */ subl %esi,%eax /* - source */ jle bCopyFwd0 /* <= 0 means copy forward */ cmpl %edx,%eax /* compare to nbytes */ jl bCopyBck0 /* < nbytes means copy backwards */bCopyFwd0: cld /* if length is less than 10, it's cheaper to do a byte copy */ cmpl $10,%edx /* test count */ jl bCopyFwd5 /* do byte copy */ /* If destination and source are not both odd, or both even, * we must do a byte copy, rather than a long copy */ movl %edi,%eax xorl %esi,%eax /* %eax = destination ^ source */ btl $0,%eax jc bCopyFwd5 /* If the buffers are odd-aligned, copy the first 1 - 3 bytes */ movl %esi,%eax andl $3,%eax /* %eax has 0 - 3 */ je bCopyFwd1 /* if long-aligned ? */ movl %eax,%ecx /* %ecx has count */ rep movsb /* copy the bytes */ subl %eax,%edx /* decrement count by %eax */bCopyFwd1: /* Since we're copying 4 bytes at a crack, divide count by 4. * Keep the remainder in %edx, so we can do those bytes at the * end of the loop. */ movl %edx,%ecx shrl $2,%ecx /* count /= 4 */ je bCopyFwd2 /* do the test first */ rep movsl /* copy long by long */bCopyFwd2: andl $3,%edx /* remainder in %edx */ /* Copy byte by byte */bCopyFwd5: movl %edx,%ecx /* Set up %ecx as the loop ctr */ cmpl $0,%ecx je bCopy6 /* do the test first */ rep movsb /* copy byte by byte */ jmp bCopy6 /* ---------------------- copy backwards ---------------------- */ .balign 16,0x90bCopyBck0: addl %edx,%esi addl %edx,%edi std /* if length is less than 10, it's cheaper to do a byte copy */ cmpl $10,%edx /* test count */ jl bCopyBck5 /* do byte copy */ /* If destination and source are not both odd, or both even, * we must do a byte copy, rather than a long copy */ movl %edi,%eax xorl %esi,%eax /* %eax = destination ^ source */ btl $0,%eax jc bCopyBck5 /* If the buffers are odd-aligned, copy the first 1 - 3 bytes */ movl %esi,%eax andl $3,%eax /* %eax has 0 - 3 */ je bCopyBck1 /* if long-aligned ? */ movl %eax,%ecx /* %ecx has count */ decl %esi decl %edi rep movsb /* copy the bytes */ incl %esi incl %edi subl %eax,%edx /* decrement count by %eax */bCopyBck1: /* Since we're copying 4 bytes at a crack, divide count by 4. * Keep the remainder in %edx, so we can do those bytes at the * end of the loop. */ movl %edx,%ecx shrl $2,%ecx /* count /= 4 */ je bCopyBck2 /* do the test first */ addl $-4,%esi addl $-4,%edi rep movsl /* copy long by long */ addl $4,%esi addl $4,%edibCopyBck2: andl $3,%edx /* remainder in %edx */ /* Copy byte by byte */bCopyBck5: movl %edx,%ecx /* Set up %ecx as the loop ctr */ cmpl $0,%ecx je bCopy6 /* do the test first */ decl %esi decl %edi rep movsb /* copy byte by byte */bCopy6: popf popl %edi popl %esi leave ret/********************************************************************************* 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 **/ .balign 16,0x90FUNC_LABEL(bcopyBytes) pushl %ebp movl %esp,%ebp pushl %esi pushl %edi pushf /* put src in %esi, dest in %edi, and count in %ecx */ movl ARG1(%ebp),%esi /* source */ movl ARG2(%ebp),%edi /* destination */ movl ARG3(%ebp),%ecx /* count */ cmpl $0,%ecx /* if (count==0) */ je bCopyB1 /* then exit */ /* Find out if there is an overlap problem. * We have to copy backwards if destination lies within source, * i.e. ((destination - source) > 0 && < nbytes) */ cld movl %edi,%eax /* destination */ subl %esi,%eax /* - source */ jle bCopyB0 /* <= 0 means copy forward */ cmpl %ecx,%eax /* compare to nbytes */ jge bCopyB0 /* >= nbytes means copy forward */ addl %ecx,%esi addl %ecx,%edi decl %esi decl %edi std /* Copy the whole thing, byte by byte */bCopyB0: rep movsbbCopyB1: popf popl %edi popl %esi leave ret/********************************************************************************* bcopyWords - copy one buffer to another a word at a time** This routine copies the first `nwords' words 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 **/ .balign 16,0x90FUNC_LABEL(bcopyWords) pushl %ebp movl %esp,%ebp pushl %esi pushl %edi pushf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -