2 * linux/arch/unicore32/kernel/module.c
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/moduleloader.h>
14 #include <linux/kernel.h>
16 #include <linux/elf.h>
17 #include <linux/vmalloc.h>
19 #include <linux/string.h>
20 #include <linux/gfp.h>
22 #include <asm/pgtable.h>
23 #include <asm/sections.h>
25 void *module_alloc(unsigned long size
)
27 return __vmalloc_node_range(size
, 1, MODULES_VADDR
, MODULES_END
,
28 GFP_KERNEL
, PAGE_KERNEL_EXEC
, 0, NUMA_NO_NODE
,
29 __builtin_return_address(0));
33 apply_relocate(Elf32_Shdr
*sechdrs
, const char *strtab
, unsigned int symindex
,
34 unsigned int relindex
, struct module
*module
)
36 Elf32_Shdr
*symsec
= sechdrs
+ symindex
;
37 Elf32_Shdr
*relsec
= sechdrs
+ relindex
;
38 Elf32_Shdr
*dstsec
= sechdrs
+ relsec
->sh_info
;
39 Elf32_Rel
*rel
= (void *)relsec
->sh_addr
;
42 for (i
= 0; i
< relsec
->sh_size
/ sizeof(Elf32_Rel
); i
++, rel
++) {
47 offset
= ELF32_R_SYM(rel
->r_info
);
48 if (offset
< 0 || offset
>
49 (symsec
->sh_size
/ sizeof(Elf32_Sym
))) {
50 printk(KERN_ERR
"%s: bad relocation, "
51 "section %d reloc %d\n",
52 module
->name
, relindex
, i
);
56 sym
= ((Elf32_Sym
*)symsec
->sh_addr
) + offset
;
58 if (rel
->r_offset
< 0 || rel
->r_offset
>
59 dstsec
->sh_size
- sizeof(u32
)) {
60 printk(KERN_ERR
"%s: out of bounds relocation, "
61 "section %d reloc %d offset %d size %d\n",
62 module
->name
, relindex
, i
, rel
->r_offset
,
67 loc
= dstsec
->sh_addr
+ rel
->r_offset
;
69 switch (ELF32_R_TYPE(rel
->r_info
)) {
75 *(u32
*)loc
+= sym
->st_value
;
80 case R_UNICORE_JUMP24
:
81 offset
= (*(u32
*)loc
& 0x00ffffff) << 2;
82 if (offset
& 0x02000000)
85 offset
+= sym
->st_value
- loc
;
87 offset
<= (s32
)0xfe000000 ||
88 offset
>= (s32
)0x02000000) {
90 "%s: relocation out of range, section "
91 "%d reloc %d sym '%s'\n", module
->name
,
92 relindex
, i
, strtab
+ sym
->st_name
);
98 *(u32
*)loc
&= 0xff000000;
99 *(u32
*)loc
|= offset
& 0x00ffffff;
103 printk(KERN_ERR
"%s: unknown relocation: %u\n",
104 module
->name
, ELF32_R_TYPE(rel
->r_info
));