From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D24281A1F32 for ; Thu, 22 Sep 2016 01:54:35 -0700 (PDT) Received: by mail-wm0-x22d.google.com with SMTP id d66so36698971wmf.0 for ; Thu, 22 Sep 2016 01:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=uRxwg90vgmRpSGyyouQE521f4N/gPGZkv2eRpMorbgM=; b=IBE3/mBdXKZJV40i7KWCyw+4k3Ejt9kzRMzgpNVABXiHQCBylxI7ok0QG8MIrkZF4a VDVAgCTq/JffP7zOi5TRB7brknOGDgXRaC0gacpiMIv87OiTm9Q7bsL7/Qp2KKhrWf2F THsyFVIXxKVl2oABzkuNXBL8yQn1ucvb5Sb/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=uRxwg90vgmRpSGyyouQE521f4N/gPGZkv2eRpMorbgM=; b=ddvvR8kIi8k1zjV7pJn0z48d6V0/0kUJshC/1Pn8mrnID+rNGf7lJtaSXuEm+NEe9A iEkAu2ID0QBtjamCtj77WpkmLXCKL0GlaEygu65+aq51c568jlM3TApjgcSuLc8VfNz0 D3hFLLv87/tp9ncZv45vWuoQqxNu7M1K1wJt1RrusLssJj51SvcL70OSZKx4NyFWF5JY +w6G0OZHhiFy9C02S0LB5LktrilYSJlPAhv/n/pGARwpPfiQRKVvjUbODK0OGoJSqY44 HPM6+fVc1x+i3wawvSe6asy/7PYCeFetMhD5fe51Hu8PZ+c3oO/WuDxKL4WgJ8yX+7B5 gyUQ== X-Gm-Message-State: AE9vXwPkkbKYLO+fc+s6DOKuAOY7SeHkogh0JFDUphtoXdmP6juahSowVdjvExdyzXZPeXZx X-Received: by 10.28.163.6 with SMTP id m6mr7272291wme.110.1474534474253; Thu, 22 Sep 2016 01:54:34 -0700 (PDT) Received: from localhost.localdomain ([105.138.52.229]) by smtp.gmail.com with ESMTPSA id ir9sm973339wjb.16.2016.09.22.01.54.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Sep 2016 01:54:33 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, liming.gao@intel.com Cc: lersek@redhat.com, leif.lindholm@linaro.org, Ard Biesheuvel Date: Thu, 22 Sep 2016 09:54:29 +0100 Message-Id: <1474534469-18442-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [PATCH] MdePkg/BaseMemoryLibOptDxe ARM AARCH64: fix thinko in SetMem## X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2016 08:54:36 -0000 The new InternalMemSetMem##() implementations for ARM and AARCH64 in BaseMemoryLibOptDxe fail to take into account that the 'length' argument is not in bytes, but in number of items to be copied. So multiply by the item size before proceeding. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S | 3 ++ MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.S | 32 +++++++++++++------- MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.asm | 28 ++++++++++++----- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S b/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S index 7f361110d4fe..ec58f759d7b6 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S +++ b/MdePkg/Library/BaseMemoryLibOptDxe/AArch64/SetMem.S @@ -78,16 +78,19 @@ ASM_GLOBAL ASM_PFX(InternalMemSetMem16) ASM_PFX(InternalMemSetMem16): dup v0.8H, valw + lsl count, count, #1 b 0f ASM_GLOBAL ASM_PFX(InternalMemSetMem32) ASM_PFX(InternalMemSetMem32): dup v0.4S, valw + lsl count, count, #2 b 0f ASM_GLOBAL ASM_PFX(InternalMemSetMem64) ASM_PFX(InternalMemSetMem64): dup v0.2D, val + lsl count, count, #3 b 0f ASM_GLOBAL ASM_PFX(InternalMemZeroMem) diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.S b/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.S index c1755539d36a..add04443b2e9 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.S +++ b/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.S @@ -16,27 +16,37 @@ .thumb .syntax unified .align 5 -ASM_GLOBAL ASM_PFX(InternalMemZeroMem) -ASM_PFX(InternalMemZeroMem): - movs r2, #0 - -ASM_GLOBAL ASM_PFX(InternalMemSetMem) -ASM_PFX(InternalMemSetMem): - uxtb r2, r2 - orr r2, r2, r2, lsl #8 - ASM_GLOBAL ASM_PFX(InternalMemSetMem16) ASM_PFX(InternalMemSetMem16): uxth r2, r2 + lsl r1, r1, #1 orr r2, r2, r2, lsl #16 + b 0f ASM_GLOBAL ASM_PFX(InternalMemSetMem32) ASM_PFX(InternalMemSetMem32): - mov r3, r2 + lsl r1, r1, #2 + b 0f ASM_GLOBAL ASM_PFX(InternalMemSetMem64) ASM_PFX(InternalMemSetMem64): - push {r4, lr} + lsl r1, r1, #3 + b 1f + + .align 5 +ASM_GLOBAL ASM_PFX(InternalMemSetMem) +ASM_PFX(InternalMemSetMem): + uxtb r2, r2 + orr r2, r2, r2, lsl #8 + orr r2, r2, r2, lsl #16 + b 0f + +ASM_GLOBAL ASM_PFX(InternalMemZeroMem) +ASM_PFX(InternalMemZeroMem): + movs r2, #0 +0: mov r3, r2 + +1: push {r4, lr} cmp r1, #16 // fewer than 16 bytes of input? add r1, r1, r0 // r1 := dst + length add lr, r0, #16 diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.asm b/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.asm index 2a8dc7d019f4..c2e2842a6323 100644 --- a/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.asm +++ b/MdePkg/Library/BaseMemoryLibOptDxe/Arm/SetMem.asm @@ -21,21 +21,33 @@ AREA SetMem, CODE, READONLY, CODEALIGN, ALIGN=5 THUMB -InternalMemZeroMem - movs r2, #0 +InternalMemSetMem16 + uxth r2, r2 + lsl r1, r1, #1 + orr r2, r2, r2, lsl #16 + b B0 + +InternalMemSetMem32 + lsl r1, r1, #2 + b B0 + +InternalMemSetMem64 + lsl r1, r1, #3 + b B1 + ALIGN 32 InternalMemSetMem uxtb r2, r2 orr r2, r2, r2, lsl #8 + orr r2, r2, r2, lsl #16 + b B0 -InternalMemSetMem16 - uxth r2, r2 - orr r2, r2, r2, lsr #16 - -InternalMemSetMem32 +InternalMemZeroMem + movs r2, #0 +B0 mov r3, r2 -InternalMemSetMem64 +B1 push {r4, lr} cmp r1, #16 ; fewer than 16 bytes of input? add r1, r1, r0 ; r1 := dst + length -- 2.7.4