]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmPkg/Library/BaseMemoryLibStm/Arm/CopyMem.S
QuarkPlatformPkg: Add modules required for TCG MOR feature
[mirror_edk2.git] / ArmPkg / Library / BaseMemoryLibStm / Arm / CopyMem.S
... / ...
CommitLineData
1#------------------------------------------------------------------------------\r
2#\r
3# CopyMem() worker for ARM\r
4#\r
5# This file started out as C code that did 64 bit moves if the buffer was\r
6# 32-bit aligned, else it does a byte copy. It also does a byte copy for\r
7# any trailing bytes. It was updated to do 32-byte copies using stm/ldm.\r
8#\r
9# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
10# This program and the accompanying materials\r
11# are licensed and made available under the terms and conditions of the BSD License\r
12# which accompanies this distribution. The full text of the license may be found at\r
13# http://opensource.org/licenses/bsd-license.php\r
14#\r
15# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17#\r
18#------------------------------------------------------------------------------\r
19\r
20/**\r
21 Copy Length bytes from Source to Destination. Overlap is OK.\r
22\r
23 This implementation\r
24\r
25 @param Destination Target of copy\r
26 @param Source Place to copy from\r
27 @param Length Number of bytes to copy\r
28\r
29 @return Destination\r
30\r
31\r
32VOID *\r
33EFIAPI\r
34InternalMemCopyMem (\r
35 OUT VOID *DestinationBuffer,\r
36 IN CONST VOID *SourceBuffer,\r
37 IN UINTN Length\r
38 )\r
39**/\r
40.text\r
41.align 2\r
42GCC_ASM_EXPORT(InternalMemCopyMem)\r
43\r
44ASM_PFX(InternalMemCopyMem):\r
45 stmfd sp!, {r4-r11, lr}\r
46 // Save the input parameters in extra registers (r11 = destination, r14 = source, r12 = length)\r
47 mov r11, r0\r
48 mov r10, r0\r
49 mov r12, r2\r
50 mov r14, r1\r
51\r
52memcopy_check_overlapped:\r
53 cmp r11, r1\r
54 // If (dest < source)\r
55 bcc memcopy_check_optim_default\r
56 // If (dest <= source). But with the previous condition -> If (dest == source)\r
57 bls memcopy_end\r
58\r
59 // If (source + length < dest)\r
60 rsb r3, r1, r11\r
61 cmp r12, r3\r
62 bcc memcopy_check_optim_default\r
63\r
64 // If (length == 0)\r
65 cmp r12, #0\r
66 beq memcopy_end\r
67\r
68 b memcopy_check_optim_overlap\r
69\r
70memcopy_check_optim_default:\r
71 // Check if we can use an optimized path ((length >= 32) && destination word-aligned && source word-aligned) for the memcopy (optimized path if r0 == 1)\r
72 tst r0, #0xF\r
73 movne r0, #0\r
74 bne memcopy_default\r
75 tst r1, #0xF\r
76 movne r3, #0\r
77 moveq r3, #1\r
78 cmp r2, #31\r
79 movls r0, #0\r
80 andhi r0, r3, #1\r
81 b memcopy_default\r
82\r
83memcopy_check_optim_overlap:\r
84 // r10 = dest_end, r14 = source_end\r
85 add r10, r11, r12\r
86 add r14, r12, r1\r
87\r
88 // Are we in the optimized case ((length >= 32) && dest_end word-aligned && source_end word-aligned)\r
89 cmp r2, #31\r
90 movls r0, #0\r
91 movhi r0, #1\r
92 tst r10, #0xF\r
93 movne r0, #0\r
94 tst r14, #0xF\r
95 movne r0, #0\r
96 b memcopy_overlapped\r
97\r
98memcopy_overlapped_non_optim:\r
99 // We read 1 byte from the end of the source buffer\r
100 sub r3, r14, #1\r
101 sub r12, r12, #1\r
102 ldrb r3, [r3, #0]\r
103 sub r2, r10, #1\r
104 cmp r12, #0\r
105 // We write 1 byte at the end of the dest buffer\r
106 sub r10, r10, #1\r
107 sub r14, r14, #1\r
108 strb r3, [r2, #0]\r
109 bne memcopy_overlapped_non_optim\r
110 b memcopy_end\r
111\r
112// r10 = dest_end, r14 = source_end\r
113memcopy_overlapped:\r
114 // Are we in the optimized case ?\r
115 cmp r0, #0\r
116 beq memcopy_overlapped_non_optim\r
117\r
118 // Optimized Overlapped - Read 32 bytes\r
119 sub r14, r14, #32\r
120 sub r12, r12, #32\r
121 cmp r12, #31\r
122 ldmia r14, {r2-r9}\r
123\r
124 // If length is less than 32 then disable optim\r
125 movls r0, #0\r
126\r
127 cmp r12, #0\r
128\r
129 // Optimized Overlapped - Write 32 bytes\r
130 sub r10, r10, #32\r
131 stmia r10, {r2-r9}\r
132\r
133 // while (length != 0)\r
134 bne memcopy_overlapped\r
135 b memcopy_end\r
136\r
137memcopy_default_non_optim:\r
138 // Byte copy\r
139 ldrb r3, [r14], #1\r
140 sub r12, r12, #1\r
141 strb r3, [r10], #1\r
142\r
143memcopy_default:\r
144 cmp r12, #0\r
145 beq memcopy_end\r
146\r
147// r10 = dest, r14 = source\r
148memcopy_default_loop:\r
149 cmp r0, #0\r
150 beq memcopy_default_non_optim\r
151\r
152 // Optimized memcopy - Read 32 Bytes\r
153 sub r12, r12, #32\r
154 cmp r12, #31\r
155 ldmia r14!, {r2-r9}\r
156\r
157 // If length is less than 32 then disable optim\r
158 movls r0, #0\r
159\r
160 cmp r12, #0\r
161\r
162 // Optimized memcopy - Write 32 Bytes\r
163 stmia r10!, {r2-r9}\r
164\r
165 // while (length != 0)\r
166 bne memcopy_default_loop\r
167\r
168memcopy_end:\r
169 mov r0, r11\r
170 ldmfd sp!, {r4-r11, pc}\r
171\r