Commit a66af29876b086d8279b48515b83ced66803fb15

Authored by Greg Ungerer
1 parent 6617eaf33d

m68k: merge the non-mmu and mmu versions of module.c

The non-mmu and mmu versions of the module loader module.c are
nearly identical. Merge them back to a single module.c. There is
a little bit of re-ordering of the struct and enum definitions in
module.h to keep the ifdefery to a minimum.

Signed-off-by: Greg Ungerer <gerg@uclinux.org>

Showing 4 changed files with 140 additions and 241 deletions Side-by-side Diff

arch/m68k/include/asm/module.h
1 1 #ifndef _ASM_M68K_MODULE_H
2 2 #define _ASM_M68K_MODULE_H
3 3  
4   -#ifdef CONFIG_MMU
  4 +enum m68k_fixup_type {
  5 + m68k_fixup_memoffset,
  6 + m68k_fixup_vnode_shift,
  7 +};
5 8  
  9 +struct m68k_fixup_info {
  10 + enum m68k_fixup_type type;
  11 + void *addr;
  12 +};
  13 +
6 14 struct mod_arch_specific {
7 15 struct m68k_fixup_info *fixup_start, *fixup_end;
8 16 };
9 17  
  18 +#ifdef CONFIG_MMU
  19 +
10 20 #define MODULE_ARCH_INIT { \
11 21 .fixup_start = __start_fixup, \
12 22 .fixup_end = __stop_fixup, \
13 23 }
14 24  
15 25  
16   -enum m68k_fixup_type {
17   - m68k_fixup_memoffset,
18   - m68k_fixup_vnode_shift,
19   -};
20   -
21   -struct m68k_fixup_info {
22   - enum m68k_fixup_type type;
23   - void *addr;
24   -};
25   -
26 26 #define m68k_fixup(type, addr) \
27 27 " .section \".m68k_fixup\",\"aw\"\n" \
28 28 " .long " #type "," #addr "\n" \
29 29 " .previous\n"
30 30  
  31 +#endif /* CONFIG_MMU */
  32 +
31 33 extern struct m68k_fixup_info __start_fixup[], __stop_fixup[];
32 34  
33 35 struct module;
34 36 extern void module_fixup(struct module *mod, struct m68k_fixup_info *start,
35 37 struct m68k_fixup_info *end);
36   -
37   -#else
38   -
39   -struct mod_arch_specific {
40   -};
41   -
42   -#endif /* CONFIG_MMU */
43 38  
44 39 #define Elf_Shdr Elf32_Shdr
45 40 #define Elf_Sym Elf32_Sym
arch/m68k/kernel/module.c
1   -#ifdef CONFIG_MMU
2   -#include "module_mm.c"
  1 +/*
  2 + * This file is subject to the terms and conditions of the GNU General Public
  3 + * License. See the file COPYING in the main directory of this archive
  4 + * for more details.
  5 + */
  6 +
  7 +#include <linux/moduleloader.h>
  8 +#include <linux/elf.h>
  9 +#include <linux/vmalloc.h>
  10 +#include <linux/fs.h>
  11 +#include <linux/string.h>
  12 +#include <linux/kernel.h>
  13 +
  14 +#if 0
  15 +#define DEBUGP printk
3 16 #else
4   -#include "module_no.c"
  17 +#define DEBUGP(fmt...)
5 18 #endif
  19 +
  20 +#ifdef CONFIG_MODULES
  21 +
  22 +int apply_relocate(Elf32_Shdr *sechdrs,
  23 + const char *strtab,
  24 + unsigned int symindex,
  25 + unsigned int relsec,
  26 + struct module *me)
  27 +{
  28 + unsigned int i;
  29 + Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
  30 + Elf32_Sym *sym;
  31 + uint32_t *location;
  32 +
  33 + DEBUGP("Applying relocate section %u to %u\n", relsec,
  34 + sechdrs[relsec].sh_info);
  35 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
  36 + /* This is where to make the change */
  37 + location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
  38 + + rel[i].r_offset;
  39 + /* This is the symbol it is referring to. Note that all
  40 + undefined symbols have been resolved. */
  41 + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
  42 + + ELF32_R_SYM(rel[i].r_info);
  43 +
  44 + switch (ELF32_R_TYPE(rel[i].r_info)) {
  45 + case R_68K_32:
  46 + /* We add the value into the location given */
  47 + *location += sym->st_value;
  48 + break;
  49 + case R_68K_PC32:
  50 + /* Add the value, subtract its postition */
  51 + *location += sym->st_value - (uint32_t)location;
  52 + break;
  53 + default:
  54 + printk(KERN_ERR "module %s: Unknown relocation: %u\n",
  55 + me->name, ELF32_R_TYPE(rel[i].r_info));
  56 + return -ENOEXEC;
  57 + }
  58 + }
  59 + return 0;
  60 +}
  61 +
  62 +int apply_relocate_add(Elf32_Shdr *sechdrs,
  63 + const char *strtab,
  64 + unsigned int symindex,
  65 + unsigned int relsec,
  66 + struct module *me)
  67 +{
  68 + unsigned int i;
  69 + Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
  70 + Elf32_Sym *sym;
  71 + uint32_t *location;
  72 +
  73 + DEBUGP("Applying relocate_add section %u to %u\n", relsec,
  74 + sechdrs[relsec].sh_info);
  75 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
  76 + /* This is where to make the change */
  77 + location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
  78 + + rel[i].r_offset;
  79 + /* This is the symbol it is referring to. Note that all
  80 + undefined symbols have been resolved. */
  81 + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
  82 + + ELF32_R_SYM(rel[i].r_info);
  83 +
  84 + switch (ELF32_R_TYPE(rel[i].r_info)) {
  85 + case R_68K_32:
  86 + /* We add the value into the location given */
  87 + *location = rel[i].r_addend + sym->st_value;
  88 + break;
  89 + case R_68K_PC32:
  90 + /* Add the value, subtract its postition */
  91 + *location = rel[i].r_addend + sym->st_value - (uint32_t)location;
  92 + break;
  93 + default:
  94 + printk(KERN_ERR "module %s: Unknown relocation: %u\n",
  95 + me->name, ELF32_R_TYPE(rel[i].r_info));
  96 + return -ENOEXEC;
  97 + }
  98 + }
  99 + return 0;
  100 +}
  101 +
  102 +int module_finalize(const Elf_Ehdr *hdr,
  103 + const Elf_Shdr *sechdrs,
  104 + struct module *mod)
  105 +{
  106 + module_fixup(mod, mod->arch.fixup_start, mod->arch.fixup_end);
  107 + return 0;
  108 +}
  109 +
  110 +#endif /* CONFIG_MODULES */
  111 +
  112 +void module_fixup(struct module *mod, struct m68k_fixup_info *start,
  113 + struct m68k_fixup_info *end)
  114 +{
  115 +#ifdef CONFIG_MMU
  116 + struct m68k_fixup_info *fixup;
  117 +
  118 + for (fixup = start; fixup < end; fixup++) {
  119 + switch (fixup->type) {
  120 + case m68k_fixup_memoffset:
  121 + *(u32 *)fixup->addr = m68k_memoffset;
  122 + break;
  123 + case m68k_fixup_vnode_shift:
  124 + *(u16 *)fixup->addr += m68k_virt_to_node_shift;
  125 + break;
  126 + }
  127 + }
  128 +#endif
  129 +}
arch/m68k/kernel/module_mm.c
1   -/*
2   - * This file is subject to the terms and conditions of the GNU General Public
3   - * License. See the file COPYING in the main directory of this archive
4   - * for more details.
5   - */
6   -
7   -#include <linux/moduleloader.h>
8   -#include <linux/elf.h>
9   -#include <linux/vmalloc.h>
10   -#include <linux/fs.h>
11   -#include <linux/string.h>
12   -#include <linux/kernel.h>
13   -
14   -#if 0
15   -#define DEBUGP printk
16   -#else
17   -#define DEBUGP(fmt...)
18   -#endif
19   -
20   -#ifdef CONFIG_MODULES
21   -
22   -int apply_relocate(Elf32_Shdr *sechdrs,
23   - const char *strtab,
24   - unsigned int symindex,
25   - unsigned int relsec,
26   - struct module *me)
27   -{
28   - unsigned int i;
29   - Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
30   - Elf32_Sym *sym;
31   - uint32_t *location;
32   -
33   - DEBUGP("Applying relocate section %u to %u\n", relsec,
34   - sechdrs[relsec].sh_info);
35   - for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
36   - /* This is where to make the change */
37   - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
38   - + rel[i].r_offset;
39   - /* This is the symbol it is referring to. Note that all
40   - undefined symbols have been resolved. */
41   - sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
42   - + ELF32_R_SYM(rel[i].r_info);
43   -
44   - switch (ELF32_R_TYPE(rel[i].r_info)) {
45   - case R_68K_32:
46   - /* We add the value into the location given */
47   - *location += sym->st_value;
48   - break;
49   - case R_68K_PC32:
50   - /* Add the value, subtract its postition */
51   - *location += sym->st_value - (uint32_t)location;
52   - break;
53   - default:
54   - printk(KERN_ERR "module %s: Unknown relocation: %u\n",
55   - me->name, ELF32_R_TYPE(rel[i].r_info));
56   - return -ENOEXEC;
57   - }
58   - }
59   - return 0;
60   -}
61   -
62   -int apply_relocate_add(Elf32_Shdr *sechdrs,
63   - const char *strtab,
64   - unsigned int symindex,
65   - unsigned int relsec,
66   - struct module *me)
67   -{
68   - unsigned int i;
69   - Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
70   - Elf32_Sym *sym;
71   - uint32_t *location;
72   -
73   - DEBUGP("Applying relocate_add section %u to %u\n", relsec,
74   - sechdrs[relsec].sh_info);
75   - for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
76   - /* This is where to make the change */
77   - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
78   - + rel[i].r_offset;
79   - /* This is the symbol it is referring to. Note that all
80   - undefined symbols have been resolved. */
81   - sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
82   - + ELF32_R_SYM(rel[i].r_info);
83   -
84   - switch (ELF32_R_TYPE(rel[i].r_info)) {
85   - case R_68K_32:
86   - /* We add the value into the location given */
87   - *location = rel[i].r_addend + sym->st_value;
88   - break;
89   - case R_68K_PC32:
90   - /* Add the value, subtract its postition */
91   - *location = rel[i].r_addend + sym->st_value - (uint32_t)location;
92   - break;
93   - default:
94   - printk(KERN_ERR "module %s: Unknown relocation: %u\n",
95   - me->name, ELF32_R_TYPE(rel[i].r_info));
96   - return -ENOEXEC;
97   - }
98   - }
99   - return 0;
100   -}
101   -
102   -int module_finalize(const Elf_Ehdr *hdr,
103   - const Elf_Shdr *sechdrs,
104   - struct module *mod)
105   -{
106   - module_fixup(mod, mod->arch.fixup_start, mod->arch.fixup_end);
107   -
108   - return 0;
109   -}
110   -
111   -#endif /* CONFIG_MODULES */
112   -
113   -void module_fixup(struct module *mod, struct m68k_fixup_info *start,
114   - struct m68k_fixup_info *end)
115   -{
116   - struct m68k_fixup_info *fixup;
117   -
118   - for (fixup = start; fixup < end; fixup++) {
119   - switch (fixup->type) {
120   - case m68k_fixup_memoffset:
121   - *(u32 *)fixup->addr = m68k_memoffset;
122   - break;
123   - case m68k_fixup_vnode_shift:
124   - *(u16 *)fixup->addr += m68k_virt_to_node_shift;
125   - break;
126   - }
127   - }
128   -}
arch/m68k/kernel/module_no.c
1   -#include <linux/moduleloader.h>
2   -#include <linux/elf.h>
3   -#include <linux/vmalloc.h>
4   -#include <linux/fs.h>
5   -#include <linux/string.h>
6   -#include <linux/kernel.h>
7   -
8   -#if 0
9   -#define DEBUGP printk
10   -#else
11   -#define DEBUGP(fmt...)
12   -#endif
13   -
14   -int apply_relocate(Elf32_Shdr *sechdrs,
15   - const char *strtab,
16   - unsigned int symindex,
17   - unsigned int relsec,
18   - struct module *me)
19   -{
20   - unsigned int i;
21   - Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
22   - Elf32_Sym *sym;
23   - uint32_t *location;
24   -
25   - DEBUGP("Applying relocate section %u to %u\n", relsec,
26   - sechdrs[relsec].sh_info);
27   - for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
28   - /* This is where to make the change */
29   - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
30   - + rel[i].r_offset;
31   - /* This is the symbol it is referring to. Note that all
32   - undefined symbols have been resolved. */
33   - sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
34   - + ELF32_R_SYM(rel[i].r_info);
35   -
36   - switch (ELF32_R_TYPE(rel[i].r_info)) {
37   - case R_68K_32:
38   - /* We add the value into the location given */
39   - *location += sym->st_value;
40   - break;
41   - case R_68K_PC32:
42   - /* Add the value, subtract its postition */
43   - *location += sym->st_value - (uint32_t)location;
44   - break;
45   - default:
46   - printk(KERN_ERR "module %s: Unknown relocation: %u\n",
47   - me->name, ELF32_R_TYPE(rel[i].r_info));
48   - return -ENOEXEC;
49   - }
50   - }
51   - return 0;
52   -}
53   -
54   -int apply_relocate_add(Elf32_Shdr *sechdrs,
55   - const char *strtab,
56   - unsigned int symindex,
57   - unsigned int relsec,
58   - struct module *me)
59   -{
60   - unsigned int i;
61   - Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
62   - Elf32_Sym *sym;
63   - uint32_t *location;
64   -
65   - DEBUGP("Applying relocate_add section %u to %u\n", relsec,
66   - sechdrs[relsec].sh_info);
67   - for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
68   - /* This is where to make the change */
69   - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
70   - + rel[i].r_offset;
71   - /* This is the symbol it is referring to. Note that all
72   - undefined symbols have been resolved. */
73   - sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
74   - + ELF32_R_SYM(rel[i].r_info);
75   -
76   - switch (ELF32_R_TYPE(rel[i].r_info)) {
77   - case R_68K_32:
78   - /* We add the value into the location given */
79   - *location = rel[i].r_addend + sym->st_value;
80   - break;
81   - case R_68K_PC32:
82   - /* Add the value, subtract its postition */
83   - *location = rel[i].r_addend + sym->st_value - (uint32_t)location;
84   - break;
85   - default:
86   - printk(KERN_ERR "module %s: Unknown relocation: %u\n",
87   - me->name, ELF32_R_TYPE(rel[i].r_info));
88   - return -ENOEXEC;
89   - }
90   - }
91   - return 0;
92   -}