1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
;*************************************************************************
;*************************************************************************
;** **
;** (C)Copyright 1985-2009, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
;** **
;** Phone: (770)-246-8600 **
;** **
;*************************************************************************
;*************************************************************************
;*************************************************************************
; $Header: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemSet.asm 1 10/01/10 5:08p Felixp $
;
; $Revision: 1 $
;
; $Date: 10/01/10 5:08p $
;*************************************************************************
; Revision History
; ----------------
; $Log: /Alaska/SOURCE/Core/Modules/x64Core/x64AsmLib/MemSet.asm $
;
; 1 10/01/10 5:08p Felixp
;
; 1 8/24/06 12:57p Felixp
;
;*************************************************************************
;<AMI_FHDR_START>
;
; Name:
;
; Description:
;
;<AMI_FHDR_END>
;*************************************************************************
.code
;*************************************************************************
;<AMI_PHDR_START>
;
; Name: MemSet
;
; Description:
; VOID MemSet(IN VOID *pBuffer, IN UINTN Count, IN UINT8 Value) fills Count
; bytes of memory in pBuffer with Value.
;
; Input:
; IN VOID *pBuffer
; The starting location in memory where to begin filling.
;
; IN UINTN Count
; The number of bytes to fill with Value.
;
; IN UINT8 Value
; The value to fill memory with starting at pBuffer.
;
; Output:
; VOID.
;
; Modified:
;
; Referrals:
;
; Notes:
;
;<AMI_PHDR_END>
;*************************************************************************
MemSet proc
push rdi
push rbx
mov rdi, rcx ; rdi = pBuffer
mov rcx, rdx ; rcx = Count
mov rax, r8 ; al = Value
; fill EAX with the Value so that we can perform DWORD operatins
mov ah, al
mov bx,ax
shl rax,16
mov ax,bx
; if Counter is less then 4, jump to byte copy
cmp rcx, 4
jb CopyByte
; check if the Buffer is 4-bytes aligned
mov rdx,rdi
and rdx, 3
; if the Buffer is 4-bytes aligned, jump to DWORD copy
jz CopyDword
; Buffer is not 4-bytes aligned
; Calculate 4-(Buffer%4), which is a number of bytes we have to copy before
; Buffer will reach 4-bytes boundary, and perform byte copy
neg rdx
add rdx, 4
xchg rcx, rdx
sub rdx, rcx
rep stosb
mov rcx, rdx
CopyDword:
; perform DWORD copy
mov rdx, rcx
shr rcx, 2
rep stosd
; copy the remainder
and rdx,3
mov rcx, rdx
CopyByte:
rep stosb
;;;
pop rbx
pop rdi
ret
MemSet endp
END
;*************************************************************************
;*************************************************************************
;** **
;** (C)Copyright 1985-2009, American Megatrends, Inc. **
;** **
;** All Rights Reserved. **
;** **
;** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
;** **
;** Phone: (770)-246-8600 **
;** **
;*************************************************************************
|