From patchwork Wed Feb 4 09:28:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 44327 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4165021513 for ; Wed, 4 Feb 2015 09:28:49 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf471845wgg.0 for ; Wed, 04 Feb 2015 01:28:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :precedence:reply-to:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=rNyvv2BV+KKQrHQmYfOgJelBEqFM7TMAnJ4XT2C/vMw=; b=mc2tL6RGSZAtXj9vOmQ/ekSM8BVBKXXILHUc9fdN9zTUCJQASXtWNZ0LPad3GpYSol 6+nXQ4XTehT6ExWB3J8bMSOVnxajjOS3yp/kL8CQQt7TR6pjRoGjyfYz05XYWQ2QvltZ u8tsSpYqMlPlr8zvBQHxmgtiW8G3IpE96pNmFxH6muPfOUJNVMWLC/y1hhtn737XNNBq NNuVLEeirsNi6bW420W5bGMQcPjsoYBdrMTM1/ox2tuSIlaBZfATJHGYMlfa1PH9dNVM axoHUe5YjR5CGjjQrViCUoMHY94aRLuN09Jl1XQ4zmr/4O3hOLgCEbGDDo7aF5Fp47HR CvBg== X-Gm-Message-State: ALoCoQlsuqg5RKLwRrqZ/c42iIYfW3pxw2ygAhHf1+mOv3rgeX7TdOUFP6td7wHOk+e7wysFO9Rp X-Received: by 10.152.43.166 with SMTP id x6mr3685836lal.3.1423042128441; Wed, 04 Feb 2015 01:28:48 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.229 with SMTP id d5ls8557lab.75.gmail; Wed, 04 Feb 2015 01:28:48 -0800 (PST) X-Received: by 10.112.199.39 with SMTP id jh7mr29488065lbc.46.1423042128293; Wed, 04 Feb 2015 01:28:48 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id b9si889586lak.28.2015.02.04.01.28.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Feb 2015 01:28:48 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id u10so431867lbd.12 for ; Wed, 04 Feb 2015 01:28:48 -0800 (PST) X-Received: by 10.152.3.70 with SMTP id a6mr29413012laa.71.1423042128203; Wed, 04 Feb 2015 01:28:48 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp372865lbj; Wed, 4 Feb 2015 01:28:47 -0800 (PST) X-Received: by 10.224.29.209 with SMTP id r17mr60181627qac.104.1423042126933; Wed, 04 Feb 2015 01:28:46 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j64si1442219qgd.38.2015.02.04.01.28.46 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 04 Feb 2015 01:28:46 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:35244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIwGM-0003Mi-4k for patch@linaro.org; Wed, 04 Feb 2015 04:28:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIwG6-0003Lb-FL for grub-devel@gnu.org; Wed, 04 Feb 2015 04:28:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIwG3-0001xo-9U for grub-devel@gnu.org; Wed, 04 Feb 2015 04:28:30 -0500 Received: from mail-we0-f170.google.com ([74.125.82.170]:38410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIwG3-0001xk-0e for grub-devel@gnu.org; Wed, 04 Feb 2015 04:28:27 -0500 Received: by mail-we0-f170.google.com with SMTP id w55so590555wes.1 for ; Wed, 04 Feb 2015 01:28:26 -0800 (PST) X-Received: by 10.180.79.106 with SMTP id i10mr44293852wix.35.1423042106392; Wed, 04 Feb 2015 01:28:26 -0800 (PST) Received: from mohikan.mushroom.smurfnet.nu (cpc4-cmbg17-2-0-cust71.5-4.cable.virginm.net. [86.14.224.72]) by mx.google.com with ESMTPSA id fi10sm28341004wib.13.2015.02.04.01.28.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Feb 2015 01:28:25 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH] arm: dl_helper.c cleanup Date: Wed, 4 Feb 2015 09:28:59 +0000 Message-Id: <1423042139-1323-1-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.170 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: grub-devel-bounces+patch=linaro.org@gnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: leif.lindholm@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Use the new thumb_get_instruction_word/thumb_set_instruction_word helpers throughout. Style cleanup (missing spaces). Move Thumb MOVW/MOVT handlers into Thumb relocation section of file. Signed-off-by: Leif Lindholm --- grub-core/kern/arm/dl_helper.c | 78 ++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/grub-core/kern/arm/dl_helper.c b/grub-core/kern/arm/dl_helper.c index 8a72632..21d77f7 100644 --- a/grub-core/kern/arm/dl_helper.c +++ b/grub-core/kern/arm/dl_helper.c @@ -26,14 +26,14 @@ #include static inline grub_uint32_t -thumb_get_instruction_word(grub_uint16_t *target) +thumb_get_instruction_word (grub_uint16_t *target) { /* Extract instruction word in alignment-safe manner */ return grub_le_to_cpu16 ((*target)) << 16 | grub_le_to_cpu16 (*(target + 1)); } static inline void -thumb_set_instruction_word(grub_uint16_t *target, grub_uint32_t insword) +thumb_set_instruction_word (grub_uint16_t *target, grub_uint32_t insword) { *target = grub_cpu_to_le16 (insword >> 16); *(target + 1) = grub_cpu_to_le16 (insword & 0xffff); @@ -70,9 +70,7 @@ grub_arm_thm_call_get_offset (grub_uint16_t *target) grub_uint32_t insword; grub_int32_t offset; - /* Extract instruction word in alignment-safe manner */ - insword = (grub_le_to_cpu16 (*target) << 16) - | (grub_le_to_cpu16(*(target + 1))); + insword = thumb_get_instruction_word (target); /* Extract bitfields from instruction words */ sign = (insword >> 26) & 1; @@ -97,9 +95,7 @@ grub_arm_thm_call_set_offset (grub_uint16_t *target, grub_int32_t offset) grub_uint32_t insword; int is_blx; - /* Extract instruction word in alignment-safe manner */ - insword = (grub_le_to_cpu16 (*target) << 16) - | (grub_le_to_cpu16(*(target + 1))); + insword = thumb_get_instruction_word (target); if (((insword >> 12) & 0xd) == 0xc) is_blx = 1; @@ -122,9 +118,7 @@ grub_arm_thm_call_set_offset (grub_uint16_t *target, grub_int32_t offset) (((offset >> 12) & 0x03ff) << 16) | (j1 << 13) | (j2 << 11) | ((offset >> 1) & 0x07ff); - /* Write instruction word back in alignment-safe manner */ - *target = grub_cpu_to_le16 ((insword >> 16) & 0xffff); - *(target + 1) = grub_cpu_to_le16 (insword & 0xffff); + thumb_set_instruction_word (target, insword); grub_dprintf ("dl", " *insword = 0x%08x", insword); @@ -137,9 +131,7 @@ grub_arm_thm_jump19_get_offset (grub_uint16_t *target) grub_int32_t offset; grub_uint32_t insword; - /* Extract instruction word in alignment-safe manner */ - insword = (grub_le_to_cpu16 (*target) << 16) - | (grub_le_to_cpu16(*(target + 1))); + insword = thumb_get_instruction_word (target); /* Extract and sign extend offset */ offset = ((insword >> 26) & 1) << 19 @@ -163,9 +155,7 @@ grub_arm_thm_jump19_set_offset (grub_uint16_t *target, grub_int32_t offset) offset >>= 1; offset &= 0xfffff; - /* Extract instruction word in alignment-safe manner */ - insword = grub_le_to_cpu16 ((*target)) << 16 - | grub_le_to_cpu16 (*(target + 1)); + insword = thumb_get_instruction_word (target); /* Reassemble instruction word and write back */ insword &= insmask; @@ -174,8 +164,7 @@ grub_arm_thm_jump19_set_offset (grub_uint16_t *target, grub_int32_t offset) | ((offset >> 17) & 1) << 13 | ((offset >> 11) & 0x3f) << 16 | (offset & 0x7ff); - *target = grub_cpu_to_le16 (insword >> 16); - *(target + 1) = grub_cpu_to_le16 (insword & 0xffff); + thumb_set_instruction_word (target, insword); } int @@ -186,6 +175,32 @@ grub_arm_thm_jump19_check_offset (grub_int32_t offset) return 1; } +grub_uint16_t +grub_arm_thm_movw_movt_get_value (grub_uint16_t *target) +{ + grub_uint32_t insword; + + insword = thumb_get_instruction_word (target); + + return ((insword & 0xf0000) >> 4) | ((insword & 0x04000000) >> 15) | \ + ((insword & 0x7000) >> 4) | (insword & 0xff); +} + +void +grub_arm_thm_movw_movt_set_value (grub_uint16_t *target, grub_uint16_t value) +{ + grub_uint32_t insword; + const grub_uint32_t insmask = 0xfbf08f00; + + insword = thumb_get_instruction_word (target); + insword &= insmask; + + insword |= ((value & 0xf000) << 4) | ((value & 0x0800) << 15) | \ + ((value & 0x0700) << 4) | (value & 0xff); + + thumb_set_instruction_word (target, insword); +} + /*********************************************************** * ARM (A32) relocations: * @@ -228,28 +243,3 @@ grub_arm_jump24_set_offset (grub_uint32_t *target, *target = grub_cpu_to_le32 (insword); } - -grub_uint16_t -grub_arm_thm_movw_movt_get_value (grub_uint16_t *target) -{ - grub_uint32_t insword; - - insword = thumb_get_instruction_word (target); - - return ((insword & 0xf0000) >> 4) | ((insword & 0x04000000) >> 15) | \ - ((insword & 0x7000) >> 4) | (insword & 0xff); -} - -void -grub_arm_thm_movw_movt_set_value (grub_uint16_t *target, grub_uint16_t value) -{ - grub_uint32_t insword; - - insword = thumb_get_instruction_word (target); - insword &= 0xfbf08f00; - - insword |= ((value & 0xf000) << 4) | ((value & 0x0800) << 15) | \ - ((value & 0x0700) << 4) | (value & 0xff); - - thumb_set_instruction_word (target, insword); -}