akaros/kern/arch/x86/support64.S
<<
>>
Prefs
   1/*-
   2 * Copyright (c) 2003 Peter Wemm.
   3 * Copyright (c) 1993 The Regents of the University of California.
   4 * All rights reserved.
   5 *
   6 * Redistribution and use in source and binary forms, with or without
   7 * modification, are permitted provided that the following conditions
   8 * are met:
   9 * 1. Redistributions of source code must retain the above copyright
  10 *    notice, this list of conditions and the following disclaimer.
  11 * 2. Redistributions in binary form must reproduce the above copyright
  12 *    notice, this list of conditions and the following disclaimer in the
  13 *    documentation and/or other materials provided with the distribution.
  14 * 4. Neither the name of the University nor the names of its contributors
  15 *    may be used to endorse or promote products derived from this software
  16 *    without specific prior written permission.
  17 *
  18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28 * SUCH DAMAGE.
  29 *
  30 * $FreeBSD$
  31 */
  32
  33
  34
  35/*
  36 * bcopy(src, dst, cnt)
  37 *       rdi, rsi, rdx
  38 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
  39 */
  40.text
  41.align 4
  42.globl bcopy
  43.type bcopy,  @function
  44bcopy:
  45        xchgq   %rsi,%rdi
  46        movq    %rdx,%rcx
  47
  48        movq    %rdi,%rax
  49        subq    %rsi,%rax
  50        cmpq    %rcx,%rax                       /* overlapping && src < dst? */
  51        jb      1f
  52
  53        shrq    $3,%rcx                         /* copy by 64-bit words */
  54        cld                                     /* nope, copy forwards */
  55        rep
  56        movsq
  57        movq    %rdx,%rcx
  58        andq    $7,%rcx                         /* any bytes left? */
  59        rep
  60        movsb
  61        ret
  62
  63        /* ALIGN_TEXT */
  641:
  65        addq    %rcx,%rdi                       /* copy backwards */
  66        addq    %rcx,%rsi
  67        decq    %rdi
  68        decq    %rsi
  69        andq    $7,%rcx                         /* any fractional bytes? */
  70        std
  71        rep
  72        movsb
  73        movq    %rdx,%rcx                       /* copy remainder by 32-bit words */
  74        shrq    $3,%rcx
  75        subq    $7,%rsi
  76        subq    $7,%rdi
  77        rep
  78        movsq
  79        cld
  80        ret
  81.size bcopy,.-bcopy
  82
  83
  84