Subversion Repositories Kolibri OS

Rev

Rev 1238 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /***************************************************************************************************
  2.  *  Copyright (C) Vasiliy Kosenko (vkos), 2009                                                     *
  3.  *  Kobra is free software: you can redistribute it and/or modify it under the terms of the GNU    *
  4.  *  General Public License as published by the Free Software Foundation, either version 3          *
  5.  *  of the License, or (at your option) any later version.                                         *
  6.  *                                                                                                 *
  7.  *  Kobra is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without     *
  8.  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  *
  9.  *  General Public License for more details.                                                       *
  10.  *                                                                                                 *
  11.  *  You should have received a copy of the GNU General Public License along with Kobra.            *
  12.  *  If not, see <http://www.gnu.org/licenses/>.                                                    *
  13.  ***************************************************************************************************/
  14.  
  15. /***************************************************************************************************
  16.  *  Some stdlib functions                                                                          *
  17.  ***************************************************************************************************/
  18.  
  19. #include "stdlib.h"
  20.  
  21. void *memcpy(void *dst, void *src, int length){
  22.         void *value;
  23.  
  24.         if (length & 3) {               //length not aligned in 4 bytes use rep movsb
  25.                 __asm__ __volatile__(
  26.                 "movl %%edi,%%eax\n\t"
  27.                 "cld\n\t"
  28.                 "rep\n\t"
  29.                 "movsb"
  30.                 :"=D"(value)
  31.                 :"c"(length),"S"(src),"D"(dst)
  32.                 :"eax");
  33.         } else {                        //length aligned in 4 bytes use rep movsd
  34.                 length=length >> 2;//length=length/4
  35.                 __asm__ __volatile__(
  36.                 "movl %%edi,%%eax\n\t"
  37.                 "cld\n\t"
  38.                 "rep\n\t"
  39.                 "movsd"
  40.                 :"=D"(value)
  41.                 :"c"(length),"S"(src),"D"(dst)
  42.                 :"eax");
  43.  
  44.         }
  45.         return(value);
  46. }
  47.  
  48. char strcmp(char *s1, char *s2){
  49.         while (*s1) {
  50.                 if (*s1++ != *s2++) {
  51.                         return *--s1-*--s2;
  52.                 }
  53.         }
  54.         return 0;
  55. }
  56.  
  57. int strlen(char *s){
  58.         int i;
  59.         while (*s++) {
  60.                 ++i;
  61.         }
  62.         return i;
  63. }
  64.  
  65. char *strcpy(char *dest, char *src){
  66.         while (*src) {
  67.                 *dest++ = *src++;
  68.         }
  69.         *dest = '\0';
  70. }
  71.