diff options
| author | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2002-11-17 21:38:59 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@home.transmeta.com> | 2002-11-17 21:38:59 -0800 |
| commit | bcfe6cb3fe286ec0357722a8fe02e2e4d86700e6 (patch) | |
| tree | bf244fd925b6db3a20b4e19d773c49de1e032b9b /arch/s390/kernel | |
| parent | 0817b2361a8cebd9136e2b525ebb77917bd4bb02 (diff) | |
[PATCH] s390: module loader.
Diffstat (limited to 'arch/s390/kernel')
| -rw-r--r-- | arch/s390/kernel/Makefile | 2 | ||||
| -rw-r--r-- | arch/s390/kernel/entry.S | 6 | ||||
| -rw-r--r-- | arch/s390/kernel/module.c | 174 | ||||
| -rw-r--r-- | arch/s390/kernel/traps.c | 8 |
4 files changed, 182 insertions, 8 deletions
diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile index 490166a3f0f7..f771591a94c5 100644 --- a/arch/s390/kernel/Makefile +++ b/arch/s390/kernel/Makefile @@ -10,7 +10,7 @@ obj-y := entry.o bitmap.o traps.o time.o process.o \ setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \ semaphore.o reipl.o s390_ext.o debug.o -obj-$(CONFIG_MODULES) += s390_ksyms.o +obj-$(CONFIG_MODULES) += s390_ksyms.o module.o obj-$(CONFIG_SMP) += smp.o # diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S index c6670485bc40..8c205abed224 100644 --- a/arch/s390/kernel/entry.S +++ b/arch/s390/kernel/entry.S @@ -474,10 +474,10 @@ sys_call_table: .long sys_adjtimex .long sys_mprotect /* 125 */ .long sys_sigprocmask - .long sys_create_module + .long sys_ni_syscall /* old "create module" */ .long sys_init_module .long sys_delete_module - .long sys_get_kernel_syms /* 130 */ + .long sys_ni_syscall /* 130: old get_kernel_syms */ .long sys_quotactl .long sys_getpgid .long sys_fchdir @@ -514,7 +514,7 @@ sys_call_table: .long sys_setresuid16 .long sys_getresuid16 /* 165 */ .long sys_ni_syscall /* for vm86 */ - .long sys_query_module + .long sys_ni_syscall /* old sys_query_module */ .long sys_poll .long sys_nfsservctl .long sys_setresgid16 /* 170 */ diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c new file mode 100644 index 000000000000..314160ffb68f --- /dev/null +++ b/arch/s390/kernel/module.c @@ -0,0 +1,174 @@ +/* + * arch/s390x/kernel/module.c - Kernel module help for s390x. + * + * S390 version + * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation + * Author(s): Arnd Bergmann (arndb@de.ibm.com) + * Martin Schwidefsky (schwidefsky@de.ibm.com) + * + * based on i386 version + * Copyright (C) 2001 Rusty Russell. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <linux/module.h> +#include <linux/elf.h> +#include <linux/vmalloc.h> +#include <linux/fs.h> +#include <linux/string.h> +#include <linux/kernel.h> + +#if 0 +#define DEBUGP printk +#else +#define DEBUGP(fmt , ...) +#endif + +void *module_alloc(unsigned long size) +{ + if (size == 0) + return NULL; + return vmalloc(size); +} + +/* Free memory returned from module_alloc */ +void module_free(struct module *mod, void *module_region) +{ + vfree(module_region); + /* FIXME: If module_region == mod->init_region, trim exception + table entries. */ +} + +/* s390/s390x needs additional memory for GOT/PLT sections. */ +long module_core_size(const Elf32_Ehdr *hdr, + const Elf32_Shdr *sechdrs, + const char *secstrings, + struct module *module) +{ + // FIXME: add space needed for GOT/PLT + return module->core_size; +} + +long module_init_size(const Elf32_Ehdr *hdr, + const Elf32_Shdr *sechdrs, + const char *secstrings, + struct module *module) +{ + return module->init_size; +} + + + +int apply_relocate(Elf_Shdr *sechdrs, + const char *strtab, + unsigned int symindex, + unsigned int relsec, + struct module *me) +{ + unsigned int i; + ElfW(Rel) *rel = (void *)sechdrs[relsec].sh_offset; + ElfW(Sym) *sym; + ElfW(Addr) *location; + + DEBUGP("Applying relocate section %u to %u\n", relsec, + sechdrs[relsec].sh_info); + 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_offset + + rel[i].r_offset; + /* This is the symbol it is referring to */ + sym = (ElfW(Sym) *)sechdrs[symindex].sh_offset + + ELFW(R_SYM)(rel[i].r_info); + if (!sym->st_value) { + printk(KERN_WARNING "%s: Unknown symbol %s\n", + me->name, strtab + sym->st_name); + return -ENOENT; + } + + switch (ELF_R_TYPE(rel[i].r_info)) { + case R_390_8: /* Direct 8 bit. */ + *(u8*) location += sym->st_value; + break; + case R_390_12: /* Direct 12 bit. */ + *(u16*) location = (*(u16*) location & 0xf000) | + (sym->st_value & 0xfff); + break; + case R_390_16: /* Direct 16 bit. */ + *(u16*) location += sym->st_value; + break; + case R_390_32: /* Direct 32 bit. */ + *(u32*) location += sym->st_value; + break; + case R_390_PC16: /* PC relative 16 bit. */ + *(u16*) location += sym->st_value + - (unsigned long )location; + + case R_390_PC16DBL: /* PC relative 16 bit shifted by 1. */ + *(u16*) location += (sym->st_value + - (unsigned long )location) >> 1; + case R_390_PC32: /* PC relative 32 bit. */ + *(u32*) location += sym->st_value + - (unsigned long )location; + break; + case R_390_GOT12: /* 12 bit GOT offset. */ + case R_390_GOT16: /* 16 bit GOT offset. */ + case R_390_GOT32: /* 32 bit GOT offset. */ + // FIXME: TODO + break; + + case R_390_PLT16DBL: /* 16 bit PC rel. PLT shifted by 1. */ + case R_390_PLT32: /* 32 bit PC relative PLT address. */ + // FIXME: TODO + break; + case R_390_GLOB_DAT: /* Create GOT entry. */ + case R_390_JMP_SLOT: /* Create PLT entry. */ + *location = sym->st_value; + break; + case R_390_RELATIVE: /* Adjust by program base. */ + // FIXME: TODO + break; + case R_390_GOTOFF: /* 32 bit offset to GOT. */ + // FIXME: TODO + break; + case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */ + // FIXME: TODO + break; + default: + printk(KERN_ERR "module %s: Unknown relocation: %lu\n", + me->name, + (unsigned long)ELF_R_TYPE(rel[i].r_info)); + return -ENOEXEC; + } + } + return 0; +} + +int apply_relocate_add(Elf32_Shdr *sechdrs, + const char *strtab, + unsigned int symindex, + unsigned int relsec, + struct module *me) +{ + printk(KERN_ERR "module %s: ADD RELOCATION unsupported\n", + me->name); + return -ENOEXEC; +} + +int module_finalize(const Elf_Ehdr *hdr, + const Elf_Shdr *sechdrs, + struct module *me) +{ + return 0; +} diff --git a/arch/s390/kernel/traps.c b/arch/s390/kernel/traps.c index da15086acc86..5eb5923e001b 100644 --- a/arch/s390/kernel/traps.c +++ b/arch/s390/kernel/traps.c @@ -72,8 +72,8 @@ extern char _stext, _etext; #ifdef CONFIG_MODULES -extern struct module *module_list; -extern struct module kernel_module; +/* FIXME: Accessed without a lock --RR */ +extern struct list_head modules; static inline int kernel_text_address(unsigned long addr) { @@ -84,11 +84,11 @@ static inline int kernel_text_address(unsigned long addr) addr <= (unsigned long) &_etext) return 1; - for (mod = module_list; mod != &kernel_module; mod = mod->next) { + list_for_each_entry(mod, &modules, list) { /* mod_bound tests for addr being inside the vmalloc'ed * module area. Of course it'd be better to test only * for the .text subset... */ - if (mod_bound(addr, 0, mod)) { + if (mod_bound((void*)addr, 0, mod)) { retval = 1; break; } |
