linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Salter <msalter@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, Mark Salter <msalter@redhat.com>
Subject: [PATCH v3 17/24] C6X: loadable module support
Date: Tue, 27 Sep 2011 16:29:58 -0400	[thread overview]
Message-ID: <1317155405-26235-18-git-send-email-msalter@redhat.com> (raw)
In-Reply-To: <1317155405-26235-1-git-send-email-msalter@redhat.com>

Signed-off-by: Mark Salter <msalter@redhat.com>
---
 arch/c6x/include/asm/module.h |   33 +++++++++++
 arch/c6x/kernel/c6x_ksyms.c   |   68 +++++++++++++++++++++
 arch/c6x/kernel/module.c      |  129 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 230 insertions(+), 0 deletions(-)
 create mode 100644 arch/c6x/include/asm/module.h
 create mode 100644 arch/c6x/kernel/c6x_ksyms.c
 create mode 100644 arch/c6x/kernel/module.c

diff --git a/arch/c6x/include/asm/module.h b/arch/c6x/include/asm/module.h
new file mode 100644
index 0000000..a453f97
--- /dev/null
+++ b/arch/c6x/include/asm/module.h
@@ -0,0 +1,33 @@
+/*
+ *  Port on Texas Instruments TMS320C6x architecture
+ *
+ *  Copyright (C) 2004, 2009, 2010 Texas Instruments Incorporated
+ *  Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
+ *
+ *  Updated for 2.6.34 by: Mark Salter (msalter@redhat.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+#ifndef _ASM_C6X_MODULE_H
+#define _ASM_C6X_MODULE_H
+
+#define Elf_Shdr	Elf32_Shdr
+#define Elf_Sym		Elf32_Sym
+#define Elf_Ehdr	Elf32_Ehdr
+#define Elf_Addr	Elf32_Addr
+#define Elf_Word	Elf32_Word
+
+/*
+ * This file contains the C6x architecture specific module code.
+ */
+struct mod_arch_specific {
+};
+
+struct loaded_sections {
+	unsigned int new_vaddr;
+	unsigned int loaded;
+};
+
+#endif /* _ASM_C6X_MODULE_H */
diff --git a/arch/c6x/kernel/c6x_ksyms.c b/arch/c6x/kernel/c6x_ksyms.c
new file mode 100644
index 0000000..358d097
--- /dev/null
+++ b/arch/c6x/kernel/c6x_ksyms.c
@@ -0,0 +1,68 @@
+/*
+ *  Port on Texas Instruments TMS320C6x architecture
+ *
+ *  Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
+ *  Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ */
+#include <linux/module.h>
+#include <asm/checksum.h>
+#include <linux/io.h>
+
+/*
+ * libgcc functions - used internally by the compiler...
+ */
+extern int __c6xabi_divi(int dividend, int divisor);
+EXPORT_SYMBOL(__c6xabi_divi);
+
+extern unsigned __c6xabi_divu(unsigned	dividend, unsigned divisor);
+EXPORT_SYMBOL(__c6xabi_divu);
+
+extern int __c6xabi_remi(int dividend, int divisor);
+EXPORT_SYMBOL(__c6xabi_remi);
+
+extern unsigned __c6xabi_remu(unsigned	dividend, unsigned divisor);
+EXPORT_SYMBOL(__c6xabi_remu);
+
+extern int __c6xabi_divremi(int dividend, int divisor);
+EXPORT_SYMBOL(__c6xabi_divremi);
+
+extern unsigned __c6xabi_divremu(unsigned  dividend, unsigned divisor);
+EXPORT_SYMBOL(__c6xabi_divremu);
+
+extern unsigned long long __c6xabi_mpyll(unsigned long long src1,
+					 unsigned long long src2);
+EXPORT_SYMBOL(__c6xabi_mpyll);
+
+extern long long __c6xabi_negll(long long src);
+EXPORT_SYMBOL(__c6xabi_negll);
+
+extern unsigned long long __c6xabi_llshl(unsigned long long src1, uint src2);
+EXPORT_SYMBOL(__c6xabi_llshl);
+
+extern long long __c6xabi_llshr(long long src1, uint src2);
+EXPORT_SYMBOL(__c6xabi_llshr);
+
+extern unsigned long long __c6xabi_llshru(unsigned long long src1, uint src2);
+EXPORT_SYMBOL(__c6xabi_llshru);
+
+extern void __c6xabi_strasgi(int *dst, const int *src, unsigned cnt);
+EXPORT_SYMBOL(__c6xabi_strasgi);
+
+extern void __c6xabi_push_rts(void);
+EXPORT_SYMBOL(__c6xabi_push_rts);
+
+extern void __c6xabi_pop_rts(void);
+EXPORT_SYMBOL(__c6xabi_pop_rts);
+
+extern void __c6xabi_strasgi_64plus(int *dst, const int *src, unsigned cnt);
+EXPORT_SYMBOL(__c6xabi_strasgi_64plus);
+
+/* lib functions */
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(csum_partial);
+EXPORT_SYMBOL(ip_fast_csum);
diff --git a/arch/c6x/kernel/module.c b/arch/c6x/kernel/module.c
new file mode 100644
index 0000000..ba7159d
--- /dev/null
+++ b/arch/c6x/kernel/module.c
@@ -0,0 +1,129 @@
+/*
+ *  Port on Texas Instruments TMS320C6x architecture
+ *
+ *  Copyright (C) 2005, 2009, 2010, 2011 Texas Instruments Incorporated
+ *  Author: Thomas Charleux (thomas.charleux@jaluna.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ */
+#include <linux/moduleloader.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/kernel.h>
+
+#ifdef DEBUG
+#define DBG(fmt...) pr_debug(fmt)
+#else
+#define DBG(fmt...)
+#endif
+
+static inline int fixup_pcr(u32 *ip, Elf32_Addr dest, u32 maskbits, int shift)
+{
+	u32 opcode;
+	long ep = (long)ip & ~31;
+	long delta = ((long)dest - ep) >> 2;
+	long mask = (1 << maskbits) - 1;
+
+	if ((delta >> (maskbits - 1)) == 0 ||
+	    (delta >> (maskbits - 1)) == -1) {
+		opcode = *ip;
+		opcode &= ~(mask << shift);
+		opcode |= ((delta & mask) << shift);
+		*ip = opcode;
+
+		DBG("REL PCR_S%d[%p] dest[0p] opcode[%08x]\n",
+		    maskbits, ip, (void *)dest, opcode);
+
+		return 0;
+	}
+	pr_err("PCR_S%d reloc %p -> %p out of range!\n",
+	       maskbits, ip, (void *)dest);
+
+	return -1;
+}
+
+/*
+ * apply a RELA relocation
+ */
+int apply_relocate_add(Elf32_Shdr *sechdrs,
+		       const char *strtab,
+		       unsigned int symindex,
+		       unsigned int relsec,
+		       struct module *me)
+{
+	Elf32_Rela *rel = (void *) sechdrs[relsec].sh_addr;
+	Elf_Sym *sym;
+	u32 *location, opcode;
+	unsigned int i;
+	Elf32_Addr v;
+	Elf_Addr offset = 0;
+
+	DBG("Applying relocate section %u to %u with offset 0x%x\n", relsec,
+	    sechdrs[relsec].sh_info, offset);
+
+	for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
+		/* This is where to make the change */
+		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
+			+ rel[i].r_offset - offset;
+
+		/* This is the symbol it is referring to.  Note that all
+		   undefined symbols have been resolved.  */
+		sym = (Elf_Sym *)sechdrs[symindex].sh_addr
+			+ ELF32_R_SYM(rel[i].r_info);
+
+		/* this is the adjustment to be made */
+		v = sym->st_value + rel[i].r_addend;
+
+		switch (ELF32_R_TYPE(rel[i].r_info)) {
+		case R_C6000_ABS32:
+			DBG("RELA ABS32: [%p] = 0x%x\n", location, v);
+			*location = v;
+			break;
+		case R_C6000_ABS16:
+			DBG("RELA ABS16: [%p] = 0x%x\n", location, v);
+			*(u16 *)location = v;
+			break;
+		case R_C6000_ABS8:
+			DBG("RELA ABS8: [%p] = 0x%x\n", location, v);
+			*(u8 *)location = v;
+			break;
+		case R_C6000_ABS_L16:
+			opcode = *location;
+			opcode &= ~0x7fff80;
+			opcode |= ((v & 0xffff) << 7);
+			DBG("RELA ABS_L16[%p] v[0x%x] opcode[0x%x]\n",
+			    location, v, opcode);
+			*location = opcode;
+			break;
+		case R_C6000_ABS_H16:
+			opcode = *location;
+			opcode &= ~0x7fff80;
+			opcode |= ((v >> 9) & 0x7fff80);
+			DBG("RELA ABS_H16[%p] v[0x%x] opcode[0x%x]\n",
+			    location, v, opcode);
+			*location = opcode;
+			break;
+		case R_C6000_PCR_S21:
+			if (fixup_pcr(location, v, 21, 7))
+				return -ENOEXEC;
+			break;
+		case R_C6000_PCR_S12:
+			if (fixup_pcr(location, v, 12, 16))
+				return -ENOEXEC;
+			break;
+		case R_C6000_PCR_S10:
+			if (fixup_pcr(location, v, 10, 13))
+				return -ENOEXEC;
+			break;
+		default:
+			pr_err("module %s: Unknown RELA relocation: %u\n",
+			       me->name, ELF32_R_TYPE(rel[i].r_info));
+			return -ENOEXEC;
+		}
+	}
+
+	return 0;
+}
-- 
1.7.6.2


  parent reply	other threads:[~2011-09-27 20:31 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-27 20:29 [PATCH v3 00/24] C6X: New architecture Mark Salter
2011-09-27 20:29 ` [PATCH v3 01/24] fix default __strnlen_user macro Mark Salter
2011-09-28 13:20   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 02/24] fixed generic page.h for non-zero PAGE_OFFSET Mark Salter
2011-09-27 20:29 ` [PATCH v3 03/24] add ELF machine define for TI C6X DSPs Mark Salter
2011-09-27 20:29 ` [PATCH v3 04/24] add missing __iomem to generic iounmap declaration Mark Salter
2011-09-28 13:19   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 05/24] C6X: build infrastructure Mark Salter
2011-09-28 13:23   ` Arnd Bergmann
2011-09-28 14:32     ` Mark Salter
2011-09-28 14:57       ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 06/24] C6X: early boot code Mark Salter
2011-09-28 13:26   ` Arnd Bergmann
2011-09-28 14:06     ` Mark Salter
2011-09-28 15:00       ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 07/24] C6X: devicetree support Mark Salter
2011-09-28 13:31   ` Arnd Bergmann
2011-09-28 14:44     ` Mark Salter
2011-09-28 14:57       ` Arnd Bergmann
2011-09-28 23:11     ` Grant Likely
2011-09-27 20:29 ` [PATCH v3 08/24] C6X: memory management and DMA support Mark Salter
2011-09-28 13:46   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 09/24] C6X: process management Mark Salter
2011-09-28 13:47   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 10/24] C6X: signal management Mark Salter
2011-09-28 13:48   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 11/24] C6X: time management Mark Salter
2011-09-27 23:41   ` Thomas Gleixner
2011-09-28 12:48     ` Mark Salter
2011-09-27 20:29 ` [PATCH v3 12/24] C6X: interrupt handling Mark Salter
2011-09-27 23:30   ` Thomas Gleixner
2011-09-27 20:29 ` [PATCH v3 13/24] C6X: syscalls Mark Salter
2011-09-28 13:49   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 14/24] C6X: traps Mark Salter
2011-09-28 13:50   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 15/24] C6X: clocks Mark Salter
2011-09-28 13:51   ` Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 16/24] C6X: cache control Mark Salter
2011-09-28 13:52   ` Arnd Bergmann
2011-09-27 20:29 ` Mark Salter [this message]
2011-09-28 13:54   ` [PATCH v3 17/24] C6X: loadable module support Arnd Bergmann
2011-09-27 20:29 ` [PATCH v3 18/24] C6X: ptrace support Mark Salter
2011-09-28 13:57   ` Arnd Bergmann
2011-09-27 20:30 ` [PATCH v3 19/24] C6X: headers Mark Salter
2011-09-28 14:07   ` Arnd Bergmann
2011-09-29 13:32     ` Mark Salter
2011-09-29 14:24     ` Mark Salter
2011-09-29 14:41       ` Arnd Bergmann
2011-09-27 20:30 ` [PATCH v3 20/24] C6X: library code Mark Salter
2011-09-28 14:09   ` Arnd Bergmann
2011-09-27 20:30 ` [PATCH v3 21/24] C6X: general SoC support Mark Salter
2011-09-28 14:19   ` Arnd Bergmann
2011-09-27 20:30 ` [PATCH v3 22/24] C6X: EMIF - External Memory Interface Mark Salter
2011-09-28 14:13   ` Arnd Bergmann
2011-09-27 20:30 ` [PATCH v3 23/24] C6X: DSCR - Device State Configuration Registers Mark Salter
2011-09-28 14:11   ` Arnd Bergmann
2011-09-27 20:30 ` [PATCH v3 24/24] C6X: MAINTAINERS Mark Salter
2011-09-28 14:09   ` Arnd Bergmann
2011-09-27 23:15 ` [PATCH v3 00/24] C6X: New architecture Stephen Rothwell
2011-09-28 14:33   ` Arnd Bergmann
2011-09-28 21:49 ` Valdis.Kletnieks
2011-09-29 10:33   ` Arnd Bergmann
2011-09-29 12:21     ` Mark Salter
2011-09-29 12:42       ` Valdis.Kletnieks
2011-09-29 13:02         ` Mark Salter
2011-09-29 13:18           ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1317155405-26235-18-git-send-email-msalter@redhat.com \
    --to=msalter@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).