Received: by 10.192.165.148 with SMTP id m20csp2749790imm; Sun, 6 May 2018 23:55:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrrCdzgJzTpMZt5brEbdXK3hSxfP/1XIC66k2RLwlo040ylA1B749dIgARXrJcCkRdaN7B1 X-Received: by 10.98.102.66 with SMTP id a63mr15131233pfc.162.1525676112601; Sun, 06 May 2018 23:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525676112; cv=none; d=google.com; s=arc-20160816; b=kcJRDW902chy+hdii0nQ2qtP/HBo5iUllVZElHgp4rjQgrbMv8vQOnmn7hDM1+JSwd sP1Oa/Bx+6K++tI+kr/MLVrHMLejDnNgY8uskgBb2M+MRBvPrEXU6B4lpEgpqE05E+BI Q221JIJR8MfbEV9Ges3nlYpFm0IQrqLt62pao/pG0G9WFK5TSGRqRMQ+yp6CQTTEFhKx XvtBqXlwAacECVK4HqZDQW4/Kgw/0uCzsofvxh9UIRJMbZI7chohrSiyNBTU+mFDjpEg C/A9ShVzktP77CDYNjwvm7Rt8DysmX+HJOOWyvl0xXqnHlHiLe/3uq3izisMhmw4lQL5 juLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=VEFT9BYdDgb8uK3f4BRqcHMC13aGqRgvhWS7INO7lNE=; b=MCxJEkkfDMRh/QtjIt4s+Db7Vf0XN7Sv3feNkY0PbGW8JSBlhM31vtYHwsG5bmpbAv lIE8x/+QH1I31ez43IEKMzxuJ6nNujSfTuMhx3SB6j4MWQV4UjNI5juh3GCffszaVaHA vdwXIXfgkgPO/UPxVOK6/9YlCTv3uY1rdSvZZ3qPO8yOUr+U/vhxQojREBrngdzq6PNS rpKa6YpQUVB4kjQi6oxkgisYMh6JTK8v9uHsuVT/zC4Pr1QjT8mczJQkwLYTmsT2/LYu U9Hzb19PwJdQ4UBZ8ltGhneyBEXaWL0rZZbxDUnoP6ynN8ClvbssgStGZneejERM+37b yJHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si19144996pfd.73.2018.05.06.23.54.58; Sun, 06 May 2018 23:55:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751975AbeEGGym (ORCPT + 99 others); Mon, 7 May 2018 02:54:42 -0400 Received: from exmail.andestech.com ([59.124.169.137]:57471 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751884AbeEGGyh (ORCPT ); Mon, 7 May 2018 02:54:37 -0400 Received: from ATCSQR.andestech.com (localhost [127.0.0.2] (may be forged)) by ATCSQR.andestech.com with ESMTP id w476blld068207 for ; Mon, 7 May 2018 14:37:47 +0800 (GMT-8) (envelope-from nickhu@andestech.com) Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w476bYCY068190; Mon, 7 May 2018 14:37:34 +0800 (GMT-8) (envelope-from nickhu@andestech.com) Received: from atcsqa06.andestech.com (10.0.1.85) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Mon, 7 May 2018 14:45:26 +0800 From: Nickhu To: , , , , CC: Nickhu Subject: [PATCH 2/2] nds32: Fix the unaligned access handler Date: Mon, 7 May 2018 14:45:02 +0800 Message-ID: <737baa062b19428816afc1fccf3bca03210b45c5.1525673368.git.nickhu@andestech.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.1.85] X-DNSRBL: X-MAIL: ATCSQR.andestech.com w476bYCY068190 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the kernel config 'CONFIG_ALIGNMENT_TRAP' and the file '/proc/sys/nds32/unaligned_access/enable' are set, the kernel unaligned access handler does not handle correctly when the value of immediate field is negative. This commit fixes the unaligned access handler in kernel. Signed-off-by: Nickhu --- arch/nds32/mm/alignment.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/nds32/mm/alignment.c b/arch/nds32/mm/alignment.c index e515f6f3d247..e1aed9dc692d 100644 --- a/arch/nds32/mm/alignment.c +++ b/arch/nds32/mm/alignment.c @@ -19,7 +19,7 @@ #define RA(inst) (((inst) >> 15) & 0x1FUL) #define RB(inst) (((inst) >> 10) & 0x1FUL) #define SV(inst) (((inst) >> 8) & 0x3UL) -#define IMM(inst) (((inst) >> 0) & 0x3FFFUL) +#define IMM(inst) (((inst) >> 0) & 0x7FFFUL) #define RA3(inst) (((inst) >> 3) & 0x7UL) #define RT3(inst) (((inst) >> 6) & 0x7UL) @@ -28,6 +28,9 @@ #define RA5(inst) (((inst) >> 0) & 0x1FUL) #define RT4(inst) (((inst) >> 5) & 0xFUL) +#define GET_IMMSVAL(imm_value) \ + (((imm_value >> 14) & 0x1) ? (imm_value - 0x8000) : imm_value) + #define __get8_data(val,addr,err) \ __asm__( \ "1: lbi.bi %1, [%2], #1\n" \ @@ -467,7 +470,7 @@ static inline int do_32(unsigned long inst, struct pt_regs *regs) } if (imm) - shift = IMM(inst) * len; + shift = GET_IMMSVAL(IMM(inst)) * len; else shift = *idx_to_addr(regs, RB(inst)) << SV(inst); -- 2.17.0