1;/*++ 2; 3;Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> 4;This program and the accompanying materials 5;are licensed and made available under the terms and conditions of the BSD License 6;which accompanies this distribution. The full text of the license may be found at 7;http://opensource.org/licenses/bsd-license.php 8; 9;THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10;WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11; 12;Module Name: 13; 14; EfiSetMem.asm 15; 16;Abstract: 17; 18; This is the code that supports IA32-optimized SetMem service 19; 20;--*/ 21;--------------------------------------------------------------------------- 22 .686 23 .model flat,C 24 .mmx 25 .code 26 27;--------------------------------------------------------------------------- 28;VOID 29;EfiCommonLibSetMem ( 30; IN VOID *Buffer, 31; IN UINTN Count, 32; IN UINT8 Value 33; ) 34;/*++ 35; 36;Input: VOID *Buffer - Pointer to buffer to write 37; UINTN Count - Number of bytes to write 38; UINT8 Value - Value to write 39; 40;Output: None. 41; 42;Saves: 43; 44;Modifies: 45; 46;Description: This function is an optimized set-memory function. 47; 48;Notes: This function tries to set memory 8 bytes at a time. As a result, 49; it first picks up any misaligned bytes, then words, before getting 50; in the main loop that does the 8-byte clears. 51; 52;--*/ 53EfiCommonLibSetMem PROC 54 55 push ebp 56 mov ebp, esp 57 sub esp, 10h; Reserve space for local variable UINT64 QWordValue @[ebp - 10H] & UINT64 MmxSave @[ebp - 18H] 58 push ebx 59 push edi 60 61 mov edx, [ebp + 0Ch] ; Count 62 test edx, edx 63 je _SetMemDone 64 65 push ebx 66 67 mov eax, [ebp + 8] ; Buffer 68 mov bl, [ebp + 10h] ; Value 69 mov edi, eax 70 mov bh, bl 71 72 cmp edx, 256 73 jb _SetRemindingByte 74 75 and al, 07h 76 test al, al 77 je _SetBlock 78 79 mov eax, edi 80 shr eax, 3 81 inc eax 82 shl eax, 3 83 sub eax, edi 84 cmp eax, edx 85 jnb _SetRemindingByte 86 87 sub edx, eax 88 mov ecx, eax 89 90 mov al, bl 91 rep stosb 92 93_SetBlock: 94 mov eax, edx 95 shr eax, 6 96 test eax, eax 97 je _SetRemindingByte 98 99 shl eax, 6 100 sub edx, eax 101 shr eax, 6 102 103 mov WORD PTR [ebp - 10H], bx ; QWordValue[0] 104 mov WORD PTR [ebp - 10H + 2], bx ; QWordValue[2] 105 mov WORD PTR [ebp - 10H + 4], bx ; QWordValue[4] 106 mov WORD PTR [ebp - 10H + 6], bx ; QWordValue[6] 107 108 109 movq [ebp - 8], mm0 ; Save mm0 to MmxSave 110 movq mm0, [ebp - 10H] ; Load QWordValue to mm0 111 112_B: 113 movq QWORD PTR ds:[edi], mm0 114 movq QWORD PTR ds:[edi+8], mm0 115 movq QWORD PTR ds:[edi+16], mm0 116 movq QWORD PTR ds:[edi+24], mm0 117 movq QWORD PTR ds:[edi+32], mm0 118 movq QWORD PTR ds:[edi+40], mm0 119 movq QWORD PTR ds:[edi+48], mm0 120 movq QWORD PTR ds:[edi+56], mm0 121 add edi, 64 122 dec eax 123 jnz _B 124 125; Restore mm0 126 movq mm0, [ebp - 8] ; Restore MmxSave to mm0 127 emms ; Exit MMX Instruction 128 129_SetRemindingByte: 130 mov ecx, edx 131 132 mov eax, ebx 133 shl eax, 16 134 mov ax, bx 135 shr ecx, 2 136 rep stosd 137 138 mov ecx, edx 139 and ecx, 3 140 rep stosb 141 142 pop ebx 143 144_SetMemDone: 145 146 pop edi 147 pop ebx 148 leave 149 ret 150 151EfiCommonLibSetMem ENDP 152 END 153