diff --git a/kernel/common/glib.h b/kernel/common/glib.h index dcfb5bcb..51d7e0b2 100644 --- a/kernel/common/glib.h +++ b/kernel/common/glib.h @@ -134,6 +134,37 @@ void *memset(void *dst, unsigned char C, ul Count) : "memory"); return dst; } + +/** + * @brief 内存拷贝函数 + * + * @param dst 目标数组 + * @param src 源数组 + * @param Num 字节数 + * @return void* + */ +void * memcpy(void *dst,void * src,long Num) +{ + int d0,d1,d2; + __asm__ __volatile__ ( "cld \n\t" + "rep \n\t" + "movsq \n\t" + "testb $4,%b4 \n\t" + "je 1f \n\t" + "movsl \n\t" + "1:\ttestb $2,%b4 \n\t" + "je 2f \n\t" + "movsw \n\t" + "2:\ttestb $1,%b4 \n\t" + "je 3f \n\t" + "movsb \n\t" + "3: \n\t" + :"=&c"(d0),"=&D"(d1),"=&S"(d2) + :"0"(Num/8),"q"(Num),"1"(src),"2"(dst) + :"memory" + ); + return dst; +} void *memset_c(void *dst, unsigned char c, ul n) { unsigned char *s = (unsigned char *)dst; @@ -184,4 +215,5 @@ void io_out32(unsigned short port,unsigned int value) : :"a"(value),"d"(port) :"memory"); -} \ No newline at end of file +} +