ArmPkg/CompilerIntrinsicsLib: replace memcpy and memset with C code

This replaces the various implementations of memset and memcpy,
including the ARM RTABI ones (__aeabi_mem[set|clr]_[|4|8]) with
a single C implementation for each. The ones we have are either not
very sophisticated (ARM), or they are too sophisticated (memcpy() on
AARCH64, which may perform unaligned accesses) or already coded in C
(memset on AArch64).

The Tianocore codebase mandates the explicit use of its SetMem() and
CopyMem() equivalents, of which various implementations exist for use
in different contexts (PEI, DXE). Few compiler generated references to
these functions should remain, and so our implementations in this BASE
library should be small and usable with the MMU off.

So replace them with a simple C implementation that builds correctly
on GCC/AARCH64, CLANG/AARCH64, GCC/ARM, CLANG/ARM and RVCT/ARM.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
This commit is contained in:
Ard Biesheuvel
2016-08-11 16:01:24 +02:00
parent 00afc8f820
commit a0cf6b8d93
10 changed files with 103 additions and 395 deletions

View File

@@ -1,32 +0,0 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#------------------------------------------------------------------------------
.text
.align 2
GCC_ASM_EXPORT(__aeabi_memcpy)
GCC_ASM_EXPORT(memcpy)
ASM_PFX(__aeabi_memcpy):
ASM_PFX(memcpy):
cmp r2, #0
bxeq lr
push {lr}
mov lr, r0
L5:
ldrb r3, [r1], #1 @ zero_extendqisi2
strb r3, [lr], #1
subs r2, r2, #1
bne L5
pop {pc}

View File

@@ -1,40 +0,0 @@
//------------------------------------------------------------------------------
//
// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
//
// This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
//------------------------------------------------------------------------------
INCLUDE AsmMacroExport.inc
;
;VOID
;EFIAPI
;__aeabi_memcpy (
; IN VOID *Destination,
; IN VOID *Source,
; IN UINT32 Size
; );
;
RVCT_ASM_EXPORT __aeabi_memcpy
cmp r2, #0
bxeq lr
push {lr}
mov lr, r0
L5
ldrb r3, [r1], #1
strb r3, [lr], #1
subs r2, r2, #1
bne L5
pop {pc}
END

View File

@@ -1,60 +0,0 @@
//------------------------------------------------------------------------------
//
// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
//
// This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
//------------------------------------------------------------------------------
INCLUDE AsmMacroExport.inc
;
;VOID
;EFIAPI
;__aeabi_memcpy (
; IN VOID *Destination,
; IN VOID *Source,
; IN UINT32 Size
; );
;
RVCT_ASM_EXPORT __aeabi_memcpy4
stmdb sp!, {r4, lr}
subs r2, r2, #32 ; 0x20
bcc memcpy4_label2
memcpy4_label1
ldmcsia r1!, {r3, r4, ip, lr}
stmcsia r0!, {r3, r4, ip, lr}
ldmcsia r1!, {r3, r4, ip, lr}
stmcsia r0!, {r3, r4, ip, lr}
subcss r2, r2, #32 ; 0x20
bcs memcpy4_label1
memcpy4_label2
movs ip, r2, lsl #28
ldmcsia r1!, {r3, r4, ip, lr}
stmcsia r0!, {r3, r4, ip, lr}
ldmmiia r1!, {r3, r4}
stmmiia r0!, {r3, r4}
ldmia sp!, {r4, lr}
movs ip, r2, lsl #30
ldrcs r3, [r1], #4
strcs r3, [r0], #4
bxeq lr
_memcpy4_lastbytes_aligned
movs r2, r2, lsl #31
ldrcsh r3, [r1], #2
ldrmib r2, [r1], #1
strcsh r3, [r0], #2
strmib r2, [r0], #1
bx lr
END

View File

@@ -1,61 +0,0 @@
#------------------------------------------------------------------------------
#
# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
# Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#------------------------------------------------------------------------------
.text
.syntax unified
.align 2
GCC_ASM_EXPORT (memset)
GCC_ASM_EXPORT (__aeabi_memset)
# VOID
# EFIAPI
# __aeabi_memset (
# IN VOID *Destination,
# IN UINT32 Size
# IN UINT32 Character,
# );
ASM_PFX(__aeabi_memset):
subs ip, r1, #0
bxeq lr
mov r1, r2
b L10
# VOID
# EFIAPI
# memset (
# IN VOID *Destination,
# IN UINT32 Character,
# IN UINT32 Size
# );
//
// This object may be pulled in to satisfy an undefined reference to
// __aeabi_memset above, but in some cases, memset() is already provided
// by another library (i.e., CryptoPkg/IntrinsicLib), in which case we
// prefer the other version. So allow this one to be overridden by
// giving it weak linkage.
//
.weak memset
ASM_PFX(memset):
subs ip, r2, #0
bxeq lr
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 1, uses_anonymous_args = 0
L10:
strb r1, [r0], #1
subs ip, ip, #1
@ While size is not 0
bne L10
bx lr

View File

@@ -1,50 +0,0 @@
//------------------------------------------------------------------------------
//
// Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
// Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
//
// This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
//------------------------------------------------------------------------------
EXPORT __aeabi_memset
EXPORT __aeabi_memclr
EXPORT __aeabi_memclr4
AREA Memset, CODE, READONLY
; void __aeabi_memclr4(void *dest, size_t n);
; void __aeabi_memclr(void *dest, size_t n);
__aeabi_memclr
__aeabi_memclr4
mov r2, #0
;
;VOID
;EFIAPI
;__aeabi_memset (
; IN VOID *Destination,
; IN UINT32 Size,
; IN UINT32 Character
; );
;
__aeabi_memset
cmp r1, #0
bxeq lr
; args = 0, pretend = 0, frame = 0
; frame_needed = 1, uses_anonymous_args = 0
L10
strb r2, [r0], #1
subs r1, r1, #1
; While size is not 0
bne L10
bx lr
END