Changeset cb4f078 in mainline


Ignore:
Timestamp:
2011-03-28T20:53:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8caaea7
Parents:
603c8740
Message:

unify kernel byte string implementations

Location:
kernel
Files:
8 deleted
17 edited

Legend:

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

    r603c8740 rcb4f078  
    3737.global read_efer_flag
    3838.global set_efer_flag
    39 .global memsetb
    40 .global memsetw
    41 .global memcpy
    4239.global memcpy_from_uspace
    4340.global memcpy_to_uspace
     
    4643.global early_putchar
    4744
    48 /* Wrapper for generic memsetb */
    49 memsetb:
    50         jmp _memsetb
    51 
    52 /* Wrapper for generic memsetw */
    53 memsetw:
    54         jmp _memsetw
    55 
    5645#define MEMCPY_DST   %rdi
    5746#define MEMCPY_SRC   %rsi
     
    7463 *
    7564 */
    76 memcpy:
    7765memcpy_from_uspace:
    7866memcpy_to_uspace:
  • kernel/arch/arm32/src/asm.S

    r603c8740 rcb4f078  
    2929.text
    3030
    31 .global memsetb
    32 .global memsetw
    33 .global memcpy
    3431.global memcpy_from_uspace
    3532.global memcpy_to_uspace
     
    3835.global early_putchar
    3936
    40 memsetb:
    41         b _memsetb
    42 
    43 memsetw:
    44         b _memsetw
    45 
    46 memcpy:
    4737memcpy_from_uspace:
    4838memcpy_to_uspace:
  • kernel/arch/arm32/src/exception.c

    r603c8740 rcb4f078  
    3535
    3636#include <arch/exception.h>
    37 #include <arch/memstr.h>
    3837#include <arch/regutils.h>
    3938#include <arch/machine_func.h>
  • kernel/arch/ia32/src/asm.S

    r603c8740 rcb4f078  
    3838.global paging_on
    3939.global enable_l_apic_in_msr
    40 .global memsetb
    41 .global memsetw
    42 .global memcpy
    4340.global memcpy_from_uspace
    4441.global memcpy_from_uspace_failover_address
     
    4744.global early_putchar
    4845
    49 /* Wrapper for generic memsetb */
    50 memsetb:
    51         jmp _memsetb
    52 
    53 /* Wrapper for generic memsetw */
    54 memsetw:
    55         jmp _memsetw
    56 
    5746#define MEMCPY_DST   4
    5847#define MEMCPY_SRC   8
     
    7463 *
    7564 */
    76 memcpy:
    7765memcpy_from_uspace:
    7866memcpy_to_uspace:
  • kernel/arch/ia64/src/asm.S

    r603c8740 rcb4f078  
    3030
    3131.text
    32 .global memcpy
    3332.global memcpy_from_uspace
    3433.global memcpy_to_uspace
     
    3938 *
    4039 * This memcpy() has been taken from the assembler output of
    41  * the generic _memcpy() and modified to have the failover part.
     40 * a plain C implementation of memcpy() modified to have the
     41 * failover part.
    4242 *
    4343 * @param in0 Destination address.
     
    4646 *
    4747 */
    48 memcpy:
    4948memcpy_from_uspace:
    5049memcpy_to_uspace:
     
    141140        br.ret.sptk.many rp
    142141
    143 .global memsetb
    144 memsetb:
    145         br _memsetb
    146 
    147 .global memsetw
    148 memsetw:
    149         br _memsetw
    150 
    151142.global cpu_halt
    152143cpu_halt:
  • kernel/arch/mips32/src/asm.S

    r603c8740 rcb4f078  
    5757        nop
    5858
    59 .global memsetb
    60 memsetb:
    61         j _memsetb
    62         nop
    63 
    64 .global memsetw
    65 memsetw:
    66         j _memsetw
    67         nop
    68 
    69 .global memcpy
    7059.global memcpy_from_uspace
    7160.global memcpy_to_uspace
    7261.global memcpy_from_uspace_failover_address
    7362.global memcpy_to_uspace_failover_address
    74 memcpy:
    7563memcpy_from_uspace:
    7664memcpy_to_uspace:
  • kernel/arch/ppc32/src/asm.S

    r603c8740 rcb4f078  
    3535.global iret
    3636.global iret_syscall
    37 .global memsetb
    38 .global memsetw
    39 .global memcpy
    4037.global memcpy_from_uspace
    4138.global memcpy_to_uspace
     
    208205        rfi
    209206
    210 memsetb:
    211         b _memsetb
    212 
    213 memsetw:
    214         b _memsetw
    215 
    216 memcpy:
    217207memcpy_from_uspace:
    218208memcpy_to_uspace:
  • kernel/arch/sparc64/src/asm.S

    r603c8740 rcb4f078  
    3434.register %g2, #scratch
    3535.register %g3, #scratch
    36 
    37 /*
    38  * This is the assembly language version of our _memcpy() generated by gcc.
    39  */
    40 .global memcpy
    41 memcpy:
    42         mov %o0, %o3  /* save dst */
    43         add %o1, 7, %g1
    44         and %g1, -8, %g1
    45         cmp %o1, %g1
    46         be,pn %xcc, 3f
    47         add %o0, 7, %g1
    48         mov 0, %g3
    49        
    50         0:
    51        
    52                 brz,pn %o2, 2f
    53                 mov 0, %g2
    54        
    55         1:
    56        
    57                 ldub [%g3 + %o1], %g1
    58                 add %g2, 1, %g2
    59                 cmp %o2, %g2
    60                 stb %g1, [%g3 + %o0]
    61                 bne,pt %xcc, 1b
    62                 mov %g2, %g3
    63        
    64         2:
    65        
    66                 jmp %o7 + 8  /* exit point */
    67                 mov %o3, %o0
    68        
    69         3:
    70        
    71                 and %g1, -8, %g1
    72                 cmp %o0, %g1
    73                 bne,pt %xcc, 0b
    74                 mov 0, %g3
    75                 srlx %o2, 3, %g4
    76                 brz,pn %g4, 5f
    77                 mov 0, %g5
    78        
    79         4:
    80        
    81                 sllx %g3, 3, %g2
    82                 add %g5, 1, %g3
    83                 ldx [%o1 + %g2], %g1
    84                 mov %g3, %g5
    85                 cmp %g4, %g3
    86                 bne,pt %xcc, 4b
    87                 stx %g1, [%o0 + %g2]
    88        
    89         5:
    90        
    91                 and %o2, 7, %o2
    92                 brz,pn %o2, 2b
    93                 sllx %g4, 3, %g1
    94                 mov 0, %g2
    95                 add %g1, %o0, %o0
    96                 add %g1, %o1, %g4
    97                 mov 0, %g3
    98        
    99         6:
    100        
    101                 ldub [%g2 + %g4], %g1
    102                 stb %g1, [%g2 + %o0]
    103                 add %g3, 1, %g2
    104                 cmp %o2, %g2
    105                 bne,pt %xcc, 6b
    106                 mov %g2, %g3
    107                
    108                 jmp %o7 + 8  /* exit point */
    109                 mov %o3, %o0
    11036
    11137/*
     
    264190        mov %g0, %o0  /* return 0 on failure */
    265191
    266 .global memsetb
    267 memsetb:
    268         ba %xcc, _memsetb
    269         nop
    270 
    271 .global memsetw
    272 memsetw:
    273         ba %xcc, _memsetw
    274         nop
    275 
    276192.global early_putchar
    277193early_putchar:
  • kernel/arch/sparc64/src/mm/sun4u/as.c

    r603c8740 rcb4f078  
    4343
    4444#include <arch/mm/tsb.h>
    45 #include <arch/memstr.h>
    4645#include <arch/asm.h>
    4746#include <mm/frame.h>
  • kernel/arch/sparc64/src/mm/sun4v/as.c

    r603c8740 rcb4f078  
    4646
    4747#include <arch/mm/tsb.h>
    48 #include <arch/memstr.h>
    4948#include <arch/asm.h>
    5049#include <mm/frame.h>
  • kernel/genarch/src/ofw/ebus.c

    r603c8740 rcb4f078  
    3939#include <genarch/ofw/ebus.h>
    4040#include <genarch/ofw/pci.h>
    41 #include <arch/memstr.h>
    4241#include <str.h>
    4342#include <panic.h>
  • kernel/genarch/src/ofw/fhc.c

    r603c8740 rcb4f078  
    3939#include <genarch/ofw/fhc.h>
    4040#include <arch/drivers/fhc.h>
    41 #include <arch/memstr.h>
    4241#include <str.h>
    4342#include <panic.h>
  • kernel/genarch/src/ofw/ofw_tree.c

    r603c8740 rcb4f078  
    3737
    3838#include <genarch/ofw/ofw_tree.h>
    39 #include <arch/memstr.h>
    4039#include <mm/slab.h>
    4140#include <str.h>
  • kernel/genarch/src/ofw/pci.c

    r603c8740 rcb4f078  
    4040#include <arch/drivers/pci.h>
    4141#include <arch/trap/interrupt.h>
    42 #include <arch/memstr.h>
    4342#include <str.h>
    4443#include <panic.h>
  • kernel/genarch/src/ofw/upa.c

    r603c8740 rcb4f078  
    3838#include <genarch/ofw/ofw_tree.h>
    3939#include <genarch/ofw/upa.h>
    40 #include <arch/memstr.h>
    4140#include <func.h>
    4241#include <panic.h>
  • kernel/generic/include/memstr.h

    r603c8740 rcb4f078  
    3737
    3838#include <typedefs.h>
    39 #include <arch/memstr.h>
    4039
    41 /*
    42  * Architecture independent variants.
    43  */
    44 extern void *_memcpy(void *dst, const void *src, size_t cnt);
    45 extern void _memsetb(void *dst, size_t cnt, uint8_t x);
    46 extern void _memsetw(void *dst, size_t cnt, uint16_t x);
    47 extern void *memmove(void *dst, const void *src, size_t cnt);
     40
     41extern void memsetb(void *, size_t, uint8_t);
     42extern void memsetw(void *, size_t, uint16_t);
     43extern void *memset(void *, int, size_t);
     44
     45extern void *memcpy(void *, const void *, size_t);
     46extern void *memmove(void *, const void *, size_t);
    4847
    4948#endif
  • kernel/generic/src/lib/memstr.c

    r603c8740 rcb4f078  
    2828 */
    2929
    30 /** @addtogroup generic 
     30/** @addtogroup generic
    3131 * @{
    3232 */
     
    3434/**
    3535 * @file
    36  * @brief       Memory string operations.
     36 * @brief Memory string operations.
    3737 *
    38  * This file provides architecture independent functions to manipulate blocks of
    39  * memory. These functions are optimized as much as generic functions of this
    40  * type can be. However, architectures are free to provide even more optimized
    41  * versions of these functions.
     38 * This file provides architecture independent functions to manipulate blocks
     39 * of memory. These functions are optimized as much as generic functions of
     40 * this type can be.
    4241 */
    4342
     
    4645#include <align.h>
    4746
    48 /** Copy block of memory.
     47/** Fill block of memory.
    4948 *
    50  * Copy cnt bytes from src address to dst address.  The copying is done
    51  * word-by-word and then byte-by-byte.  The source and destination memory areas
    52  * cannot overlap.
     49 * Fill cnt bytes at dst address with the value val.
    5350 *
    54  * @param src           Source address to copy from.
    55  * @param dst           Destination address to copy to.
    56  * @param cnt           Number of bytes to copy.
     51 * @param dst Destination address to fill.
     52 * @param cnt Number of bytes to fill.
     53 * @param val Value to fill.
    5754 *
    58  * @return              Destination address.
    5955 */
    60 void *_memcpy(void *dst, const void *src, size_t cnt)
     56void memsetb(void *dst, size_t cnt, uint8_t val)
    6157{
    62         unsigned int i, j;
     58        __builtin_memset(dst, val, cnt);
     59}
     60
     61/** Fill block of memory.
     62 *
     63 * Fill cnt words at dst address with the value val. The filling
     64 * is done word-by-word.
     65 *
     66 * @param dst Destination address to fill.
     67 * @param cnt Number of words to fill.
     68 * @param val Value to fill.
     69 *
     70 */
     71void memsetw(void *dst, size_t cnt, uint16_t val)
     72{
     73        size_t i;
     74        uint16_t *ptr = (uint16_t *) dst;
    6375       
    64         if (ALIGN_UP((uintptr_t) src, sizeof(sysarg_t)) != (uintptr_t) src ||
    65             ALIGN_UP((uintptr_t) dst, sizeof(sysarg_t)) != (uintptr_t) dst) {
    66                 for (i = 0; i < cnt; i++)
    67                         ((uint8_t *) dst)[i] = ((uint8_t *) src)[i];
    68         } else {
    69                 for (i = 0; i < cnt / sizeof(sysarg_t); i++)
    70                         ((sysarg_t *) dst)[i] = ((sysarg_t *) src)[i];
    71                
    72                 for (j = 0; j < cnt % sizeof(sysarg_t); j++)
    73                         ((uint8_t *)(((sysarg_t *) dst) + i))[j] =
    74                             ((uint8_t *)(((sysarg_t *) src) + i))[j];
    75         }
    76                
    77         return (char *) dst;
     76        for (i = 0; i < cnt; i++)
     77                ptr[i] = val;
     78}
     79
     80/** Fill block of memory.
     81 *
     82 * Fill cnt bytes at dst address with the value val.
     83 *
     84 * @param dst Destination address to fill.
     85 * @param val Value to fill.
     86 * @param cnt Number of bytes to fill.
     87 *
     88 * @return Destination address.
     89 *
     90 */
     91void *memset(void *dst, int val, size_t cnt)
     92{
     93        return __builtin_memset(dst, val, cnt);
     94}
     95
     96/** Move memory block without overlapping.
     97 *
     98 * Copy cnt bytes from src address to dst address. The source
     99 * and destination memory areas cannot overlap.
     100 *
     101 * @param dst Destination address to copy to.
     102 * @param src Source address to copy from.
     103 * @param cnt Number of bytes to copy.
     104 *
     105 * @return Destination address.
     106 *
     107 */
     108void *memcpy(void *dst, const void *src, size_t cnt)
     109{
     110        return __builtin_memcpy(dst, src, cnt);
    78111}
    79112
    80113/** Move memory block with possible overlapping.
    81114 *
    82  * Copy cnt bytes from src address to dst address. The source and destination
    83  * memory areas may overlap.
     115 * Copy cnt bytes from src address to dst address. The source
     116 * and destination memory areas may overlap.
    84117 *
    85  * @param src           Source address to copy from.
    86  * @param dst           Destination address to copy to.
    87  * @param cnt           Number of bytes to copy.
     118 * @param dst Destination address to copy to.
     119 * @param src Source address to copy from.
     120 * @param cnt Number of bytes to copy.
    88121 *
    89  * @return              Destination address.
     122 * @return Destination address.
     123 *
    90124 */
    91 void *memmove(void *dst, const void *src, size_t n)
     125void *memmove(void *dst, const void *src, size_t cnt)
    92126{
    93         const uint8_t *sp;
    94         uint8_t *dp;
    95 
    96127        /* Nothing to do? */
    97128        if (src == dst)
    98129                return dst;
    99 
     130       
    100131        /* Non-overlapping? */
    101         if (dst >= src + n || src >= dst + n) {
    102                 return memcpy(dst, src, n);
    103         }
    104 
     132        if ((dst >= src + cnt) || (src >= dst + cnt))
     133                return memcpy(dst, src, cnt);
     134       
     135        const uint8_t *sp;
     136        uint8_t *dp;
     137       
    105138        /* Which direction? */
    106139        if (src > dst) {
     
    108141                sp = src;
    109142                dp = dst;
    110 
    111                 while (n-- != 0)
     143               
     144                while (cnt-- != 0)
    112145                        *dp++ = *sp++;
    113146        } else {
    114147                /* Backwards. */
    115                 sp = src + (n - 1);
    116                 dp = dst + (n - 1);
    117 
    118                 while (n-- != 0)
     148                sp = src + (cnt - 1);
     149                dp = dst + (cnt - 1);
     150               
     151                while (cnt-- != 0)
    119152                        *dp-- = *sp--;
    120153        }
    121 
     154       
    122155        return dst;
    123 }
    124 
    125 /** Fill block of memory
    126  *
    127  * Fill cnt bytes at dst address with the value x.  The filling is done
    128  * byte-by-byte.
    129  *
    130  * @param dst           Destination address to fill.
    131  * @param cnt           Number of bytes to fill.
    132  * @param x             Value to fill.
    133  *
    134  */
    135 void _memsetb(void *dst, size_t cnt, uint8_t x)
    136 {
    137         unsigned int i;
    138         uint8_t *p = (uint8_t *) dst;
    139        
    140         for (i = 0; i < cnt; i++)
    141                 p[i] = x;
    142 }
    143 
    144 /** Fill block of memory.
    145  *
    146  * Fill cnt words at dst address with the value x.  The filling is done
    147  * word-by-word.
    148  *
    149  * @param dst           Destination address to fill.
    150  * @param cnt           Number of words to fill.
    151  * @param x             Value to fill.
    152  *
    153  */
    154 void _memsetw(void *dst, size_t cnt, uint16_t x)
    155 {
    156         unsigned int i;
    157         uint16_t *p = (uint16_t *) dst;
    158        
    159         for (i = 0; i < cnt; i++)
    160                 p[i] = x;       
    161156}
    162157
Note: See TracChangeset for help on using the changeset viewer.