1/*- 2 * Copyright (c) 2008, 2009 3 * Thorsten Glaser <tg@mirbsd.org> 4 * 5 * Provided that these terms and disclaimer and all copyright notices 6 * are retained or reproduced in an accompanying document, permission 7 * is granted to deal in this work without restriction, including un- 8 * limited rights to use, publicly perform, distribute, sell, modify, 9 * merge, give away, or sublicence. 10 * 11 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 12 * the utmost extent permitted by applicable law, neither express nor 13 * implied; without malicious intent or gross negligence. In no event 14 * may a licensor, author or contributor be held liable for indirect, 15 * direct, other damage, loss, or other issues arising in any way out 16 * of dealing in the work, even if advised of the possibility of such 17 * damage or existence of a defect, except proven that it results out 18 * of said person's immediate fault when using the work as intended. 19 */ 20 21#include <machine/asm.h> 22 23RCSID("$MirOS: src/kern/c/i386/memset.S,v 1.6 2009/01/21 19:57:54 tg Exp $") 24 25 .intel_syntax noprefix 26 .text 27 28/* the kernel has sse_pagezero and friends */ 29#ifndef _KERNEL 30ENTRY(bzero) 31 mov edx,8[esp] 32 xor eax,eax 33 jmp 1f 34#endif 35 36ENTRY(memset) 37 mov edx,12[esp] 38 39 movzx eax,byte ptr 8[esp] 40 mov ah,al 41 mov cx,ax 42 shl eax,16 43 mov ax,cx 44 451: push edi 46 mov edi,8[esp] 47 push edi 48 cld 49 50 /* do not align for short strings */ 51 cmp edx,16 52 jb Lrest 53 54 /* dword align */ 55 mov ecx,edi 56 neg ecx 57 and ecx,3 58 sub edx,ecx 59 rep stosb 60 61 /* fill whole dwords */ 62 mov ecx,edx 63 shr ecx,2 64 and edx,3 65 rep stosd 66 67 _ALIGN_TEXT 68Lrest: /* remaining bytes */ 69 mov ecx,edx 70 rep stosb 71 72 pop eax 73 pop edi 74 ret 75