Received: by 10.213.65.68 with SMTP id h4csp1520621imn; Thu, 15 Mar 2018 01:53:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELvnRQu4dC2bQ3oSgHhpip+xC6GTksozdubWVXiYuZzlI1pzdsmuaDNSg+Mxtqq2gbVE2Rds X-Received: by 10.99.50.66 with SMTP id y63mr6317854pgy.207.1521104013698; Thu, 15 Mar 2018 01:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521104013; cv=none; d=google.com; s=arc-20160816; b=mWxIJzOdmWYU7huQ3YMTCqk3IcrZwwzEYYyJTJOJrLYvjV9LZbNchg1LxVAQvSgRGt T5CPGTGb+uZLqJ9fjRAvMusMQKx9HF2TzO6AZL8wT8L1/C4aks9CHO5tEU7s+OGsALaV SWq3qrPtumPoKS8Wfve637PbQ/KKg/KUxQ2M7/5XaUw4GV2HKennQDJ0LScFdnzlFfzY YQafLmkFQKkyyv94o7oYX8cHrgblf4pzy/S5fD7omlnX/eCzteubnXeBdxzJnrYrutIw PXGLBOfYL98dQMd/ADBFYFirlyODWLx7Sz8bkjaS3ty4ZKkGDIuou+b4wnodxk5TGlAf ilWg== 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=T9nw3/Ayt8T6txD3tuDpZSHKPFH/jwmLbJ+UVnoWT/E=; b=aTjTslJ238cnsjkQDvJ6/CBPsDY+w68VEqrIuQ4dUfyLRo+Qwm5kyjmLgwOGYbB9tM eZGXKpyF3vKVwBYsNQa6n3tjjknAsV4Vn/2YvJFUWNedawvGTz1EW7wzlgXgjzuznJM4 oey2tCZeag0C8lXud+DFHIqxmKD7+r+hgRZqU10tNymmwnRwYMvDrEYPbcJB3t6sy545 dFuQcXWOnjesEaRBAC90h1q2pi6A46VKE3f93/Hp+TrCeYEyLFZHByVNSo6cI9VnklZo EN/7HP9P9eNSEk9u4SwSL+q8hEHg4B/g9AcFGddQYgYygQxK1s4DZAccqkcYqi+2txw7 Z6MQ== 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 v13-v6si3858477plk.153.2018.03.15.01.53.19; Thu, 15 Mar 2018 01:53:33 -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 S1751931AbeCOIwJ (ORCPT + 99 others); Thu, 15 Mar 2018 04:52:09 -0400 Received: from exmail.andestech.com ([59.124.169.137]:7659 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751459AbeCOIwE (ORCPT ); Thu, 15 Mar 2018 04:52:04 -0400 Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id w2F8luE5080966; Thu, 15 Mar 2018 16:47:56 +0800 (GMT-8) (envelope-from zong@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; Thu, 15 Mar 2018 16:51:32 +0800 From: Zong Li To: , , , , , CC: Subject: [PATCH v2 06/11] RISC-V: Support RVC_BRANCH/JUMP relocation type in kernel modulewq Date: Thu, 15 Mar 2018 16:50:46 +0800 Message-ID: X-Mailer: git-send-email 2.7.4 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 w2F8luE5080966 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Zong Li --- arch/riscv/kernel/module.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index f1bd6b1a4520..7ab6a9b72384 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -49,6 +49,39 @@ static int apply_r_riscv_jal_rela(struct module *me, u32 *location, return 0; } +static int apply_r_riscv_rcv_branch_rela(struct module *me, u32 *location, + Elf_Addr v) +{ + s64 offset = (void *)v - (void *)location; + u16 imm8 = (offset & 0x100) << (12 - 8); + u16 imm7_6 = (offset & 0xc0) >> (6 - 5); + u16 imm5 = (offset & 0x20) >> (5 - 2); + u16 imm4_3 = (offset & 0x18) << (12 - 5); + u16 imm2_1 = (offset & 0x6) << (12 - 10); + + *(u16 *)location = (*(u16 *)location & 0xe383) | + imm8 | imm7_6 | imm5 | imm4_3 | imm2_1; + return 0; +} + +static int apply_r_riscv_rvc_jump_rela(struct module *me, u32 *location, + Elf_Addr v) +{ + s64 offset = (void *)v - (void *)location; + u16 imm11 = (offset & 0x800) << (12 - 11); + u16 imm10 = (offset & 0x400) >> (10 - 8); + u16 imm9_8 = (offset & 0x300) << (12 - 11); + u16 imm7 = (offset & 0x80) >> (7 - 6); + u16 imm6 = (offset & 0x40) << (12 - 11); + u16 imm5 = (offset & 0x20) >> (5 - 2); + u16 imm4 = (offset & 0x10) << (12 - 5); + u16 imm3_1 = (offset & 0xe) << (12 - 10); + + *(u16 *)location = (*(u16 *)location & 0xe003) | + imm11 | imm10 | imm9_8 | imm7 | imm6 | imm5 | imm4 | imm3_1; + return 0; +} + static int apply_r_riscv_pcrel_hi20_rela(struct module *me, u32 *location, Elf_Addr v) { @@ -212,6 +245,8 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location, [R_RISCV_64] = apply_r_riscv_64_rela, [R_RISCV_BRANCH] = apply_r_riscv_branch_rela, [R_RISCV_JAL] = apply_r_riscv_jal_rela, + [R_RISCV_RVC_BRANCH] = apply_r_riscv_rcv_branch_rela, + [R_RISCV_RVC_JUMP] = apply_r_riscv_rvc_jump_rela, [R_RISCV_PCREL_HI20] = apply_r_riscv_pcrel_hi20_rela, [R_RISCV_PCREL_LO12_I] = apply_r_riscv_pcrel_lo12_i_rela, [R_RISCV_PCREL_LO12_S] = apply_r_riscv_pcrel_lo12_s_rela, -- 2.16.1