Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 0ca441c in mainline


Ignore:
Timestamp:
2013-03-29T16:57:20Z (9 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
26346bd
Parents:
8a5a902
Message:

amd64: implement memset() and memcpy()

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/asm.S

    r8a5a902 r0ca441c  
    3737.global read_efer_flag
    3838.global set_efer_flag
     39.global memset
     40.global memcpy
    3941.global memcpy_from_uspace
    4042.global memcpy_to_uspace
     
    4345.global early_putchar
    4446
     47#define MEMSET_DST   %rdi
     48#define MEMSET_VAL   %rsi
     49#define MEMSET_SIZE  %rdx
     50
    4551#define MEMCPY_DST   %rdi
    4652#define MEMCPY_SRC   %rsi
    4753#define MEMCPY_SIZE  %rdx
    4854
    49 /**
    50  * Copy memory from/to userspace.
     55/* Fill memory with byte pattern
     56 *
     57 * This is a conventional memset().
     58 *
     59 * @param MEMSET_DST  Destination address.
     60 * @param MEMSET_VAL  Value to fill.
     61 * @param MEMSET_SIZE Size.
     62 *
     63 * @return MEMSET_DST.
     64 *
     65 */
     66memset:
     67        movq MEMSET_DST, %r8    /* save %rdi */
     68       
     69        /* Create byte pattern */
     70        movzbl %sil, %esi       /* MEMSET_VAL */
     71        movabs $0x0101010101010101, %rax
     72        imulq %rsi, %rax
     73       
     74        movq MEMSET_SIZE, %rcx
     75        shrq $3, %rcx           /* size / 8 */
     76       
     77        rep stosq               /* store as much as possible word by word */
     78       
     79        movq MEMSET_SIZE, %rcx
     80        andq $7, %rcx           /* size % 8 */
     81        jz 0f
     82       
     83        rep stosb               /* store the rest byte by byte */
     84       
     85        0:
     86                movq %r8, %rax
     87                ret                 /* return MEMCPY_SRC, success */
     88
     89/** Copy memory from/to userspace.
    5190 *
    5291 * This is almost conventional memcpy().
     
    63102 *
    64103 */
     104memcpy:
    65105memcpy_from_uspace:
    66106memcpy_to_uspace:
  • uspace/lib/c/arch/amd64/Makefile.inc

    r8a5a902 r0ca441c  
    2828
    2929ARCH_SOURCES = \
     30        arch/$(UARCH)/src/asm.S \
    3031        arch/$(UARCH)/src/entry.s \
    3132        arch/$(UARCH)/src/entryjmp.s \
Note: See TracChangeset for help on using the changeset viewer.