~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/hexagon/kernel/module.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/hexagon/kernel/module.c (Architecture alpha) and /arch/sparc/kernel/module.c (Architecture sparc)


  1 // SPDX-License-Identifier: GPL-2.0-only       !!   1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                             !!   2 /* Kernel module help for sparc64.
  3  * Kernel module loader for Hexagon            << 
  4  *                                                  3  *
  5  * Copyright (c) 2010-2011, The Linux Foundati !!   4  * Copyright (C) 2001 Rusty Russell.
                                                   >>   5  * Copyright (C) 2002 David S. Miller.
  6  */                                                 6  */
  7                                                     7 
  8 #include <asm/module.h>                        << 
  9 #include <linux/elf.h>                         << 
 10 #include <linux/module.h>                      << 
 11 #include <linux/moduleloader.h>                     8 #include <linux/moduleloader.h>
                                                   >>   9 #include <linux/kernel.h>
                                                   >>  10 #include <linux/elf.h>
 12 #include <linux/vmalloc.h>                         11 #include <linux/vmalloc.h>
 13                                                !!  12 #include <linux/fs.h>
 14 #if 0                                          !!  13 #include <linux/gfp.h>
 15 #define DEBUGP printk                          !!  14 #include <linux/string.h>
 16 #else                                          !!  15 #include <linux/ctype.h>
 17 #define DEBUGP(fmt , ...)                      !!  16 #include <linux/mm.h>
 18 #endif                                         !!  17 
 19                                                !!  18 #include <asm/processor.h>
 20 /*                                             !!  19 #include <asm/spitfire.h>
 21  * module_frob_arch_sections - tweak got/plt s !!  20 #include <asm/cacheflush.h>
 22  * @hdr - pointer to elf header                !!  21 
 23  * @sechdrs - pointer to elf load section head !!  22 #include "entry.h"
 24  * @secstrings - symbol names                  !!  23 
 25  * @mod - pointer to module                    !!  24 /* Make generic code ignore STT_REGISTER dummy undefined symbols.  */
 26  */                                            !!  25 int module_frob_arch_sections(Elf_Ehdr *hdr,
 27 int module_frob_arch_sections(Elf_Ehdr *hdr, E !!  26                               Elf_Shdr *sechdrs,
 28                                 char *secstrin !!  27                               char *secstrings,
 29                                 struct module  !!  28                               struct module *mod)
 30 {                                                  29 {
 31         unsigned int i;                        !!  30         unsigned int symidx;
 32         int found = 0;                         !!  31         Elf_Sym *sym;
 33                                                !!  32         char *strtab;
 34         /* Look for .plt and/or .got.plt and/o !!  33         int i;
 35         for (i = 0; i < hdr->e_shnum; i++) {   !!  34 
 36                 DEBUGP("Section %d is %s\n", i !!  35         for (symidx = 0; sechdrs[symidx].sh_type != SHT_SYMTAB; symidx++) {
 37                        secstrings + sechdrs[i] !!  36                 if (symidx == hdr->e_shnum-1) {
 38                 if (strcmp(secstrings + sechdr !!  37                         printk("%s: no symtab found.\n", mod->name);
 39                         found = i+1;           !!  38                         return -ENOEXEC;
 40                 if (strcmp(secstrings + sechdr !!  39                 }
 41                         found = i+1;           << 
 42                 if (strcmp(secstrings + sechdr << 
 43                         found = i+1;           << 
 44         }                                      << 
 45                                                << 
 46         /* At this time, we don't support modu << 
 47         if (found) {                           << 
 48                 printk(KERN_WARNING            << 
 49                         "Module '%s' contains  << 
 50                         mod->name);            << 
 51                 /*  return -ENOEXEC;  */       << 
 52         }                                          40         }
                                                   >>  41         sym = (Elf_Sym *)sechdrs[symidx].sh_addr;
                                                   >>  42         strtab = (char *)sechdrs[sechdrs[symidx].sh_link].sh_addr;
 53                                                    43 
                                                   >>  44         for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
                                                   >>  45                 if (sym[i].st_shndx == SHN_UNDEF) {
                                                   >>  46                         if (ELF_ST_TYPE(sym[i].st_info) == STT_REGISTER)
                                                   >>  47                                 sym[i].st_shndx = SHN_ABS;
                                                   >>  48                 }
                                                   >>  49         }
 54         return 0;                                  50         return 0;
 55 }                                                  51 }
 56                                                    52 
 57 /*                                             !!  53 int apply_relocate_add(Elf_Shdr *sechdrs,
 58  * apply_relocate_add - perform rela relocatio !!  54                        const char *strtab,
 59  * @sechdrs - pointer to section headers       !!  55                        unsigned int symindex,
 60  * @strtab - some sort of start address?       !!  56                        unsigned int relsec,
 61  * @symindex - symbol index offset or somethin !!  57                        struct module *me)
 62  * @relsec - address to relocate to?           << 
 63  * @module - pointer to module                 << 
 64  *                                             << 
 65  * Perform rela relocations.                   << 
 66  */                                            << 
 67 int apply_relocate_add(Elf_Shdr *sechdrs, cons << 
 68                         unsigned int symindex, << 
 69                         struct module *module) << 
 70 {                                                  58 {
 71         unsigned int i;                            59         unsigned int i;
 72         Elf32_Sym *sym;                        !!  60         Elf_Rela *rel = (void *)sechdrs[relsec].sh_addr;
 73         uint32_t *location;                    !!  61         Elf_Sym *sym;
 74         uint32_t value;                        !!  62         u8 *location;
 75         unsigned int nrelocs = sechdrs[relsec] !!  63         u32 *loc32;
 76         Elf32_Rela *rela = (void *)sechdrs[rel !!  64 
 77         Elf32_Word sym_info = sechdrs[relsec]. !!  65         for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
 78         Elf32_Sym *sym_base = (Elf32_Sym *) se !!  66                 Elf_Addr v;
 79         void *loc_base = (void *) sechdrs[sym_ !!  67 
 80                                                !!  68                 /* This is where to make the change */
 81         DEBUGP("Applying relocations in sectio !!  69                 location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
 82                relsec, sym_info, loc_base);    !!  70                         + rel[i].r_offset;
 83                                                !!  71                 loc32 = (u32 *) location;
 84         for (i = 0; i < nrelocs; i++) {        !!  72 
 85                                                !!  73 #ifdef CONFIG_SPARC64
 86                 /* Symbol to relocate */       !!  74                 BUG_ON(((u64)location >> (u64)32) != (u64)0);
 87                 sym = sym_base + ELF32_R_SYM(r !!  75 #endif /* CONFIG_SPARC64 */
 88                                                !!  76 
 89                 /* Where to make the change */ !!  77                 /* This is the symbol it is referring to.  Note that all
 90                 location = loc_base + rela[i]. !!  78                    undefined symbols have been resolved.  */
 91                                                !!  79                 sym = (Elf_Sym *)sechdrs[symindex].sh_addr
 92                 /* `Everything is relative'. * !!  80                         + ELF_R_SYM(rel[i].r_info);
 93                 value = sym->st_value + rela[i !!  81                 v = sym->st_value + rel[i].r_addend;
 94                                                !!  82 
 95                 DEBUGP("%d: value=%08x loc=%p  !!  83                 switch (ELF_R_TYPE(rel[i].r_info) & 0xff) {
 96                        i, value, location, ELF !!  84                 case R_SPARC_DISP32:
 97                        sym->st_name ?          !!  85                         v -= (Elf_Addr) location;
 98                        &strtab[sym->st_name] : !!  86                         *loc32 = v;
 99                                                << 
100                 switch (ELF32_R_TYPE(rela[i].r << 
101                 case R_HEXAGON_B22_PCREL: {    << 
102                         int dist = (int)(value << 
103                         if ((dist < -0x0080000 << 
104                             (dist >= 0x0080000 << 
105                                 printk(KERN_ER << 
106                                        "%s: %s << 
107                                        module- << 
108                                        "R_HEXA << 
109                                        dist, v << 
110                                        sym->st << 
111                                        &strtab << 
112                                 return -ENOEXE << 
113                         }                      << 
114                         DEBUGP("B22_PCREL cont << 
115                         *location &= ~0x01ff3f << 
116                         *location |= 0x00003ff << 
117                         *location |= 0x01ff000 << 
118                         DEBUGP("Contents after << 
119                         break;                     87                         break;
120                 }                              !!  88 #ifdef CONFIG_SPARC64
121                 case R_HEXAGON_HI16:           !!  89                 case R_SPARC_64:
122                         value = (value>>16) &  !!  90                         location[0] = v >> 56;
123                         fallthrough;           !!  91                         location[1] = v >> 48;
124                 case R_HEXAGON_LO16:           !!  92                         location[2] = v >> 40;
125                         *location &= ~0x00c03f !!  93                         location[3] = v >> 32;
126                         *location |= value & 0 !!  94                         location[4] = v >> 24;
127                         *location |= (value &  !!  95                         location[5] = v >> 16;
128                         break;                 !!  96                         location[6] = v >>  8;
129                 case R_HEXAGON_32:             !!  97                         location[7] = v >>  0;
130                         *location = value;     !!  98                         break;
131                         break;                 !!  99 
132                 case R_HEXAGON_32_PCREL:       !! 100                 case R_SPARC_WDISP19:
133                         *location = value - (u !! 101                         v -= (Elf_Addr) location;
134                         break;                 !! 102                         *loc32 = (*loc32 & ~0x7ffff) |
135                 case R_HEXAGON_PLT_B22_PCREL:  !! 103                                 ((v >> 2) & 0x7ffff);
136                 case R_HEXAGON_GOTOFF_LO16:    !! 104                         break;
137                 case R_HEXAGON_GOTOFF_HI16:    !! 105 
138                         printk(KERN_ERR "%s: G !! 106                 case R_SPARC_OLO10:
139                                module->name);  !! 107                         *loc32 = (*loc32 & ~0x1fff) |
140                         return -ENOEXEC;       !! 108                                 (((v & 0x3ff) +
                                                   >> 109                                   (ELF_R_TYPE(rel[i].r_info) >> 8))
                                                   >> 110                                  & 0x1fff);
                                                   >> 111                         break;
                                                   >> 112 #endif /* CONFIG_SPARC64 */
                                                   >> 113 
                                                   >> 114                 case R_SPARC_32:
                                                   >> 115                 case R_SPARC_UA32:
                                                   >> 116                         location[0] = v >> 24;
                                                   >> 117                         location[1] = v >> 16;
                                                   >> 118                         location[2] = v >>  8;
                                                   >> 119                         location[3] = v >>  0;
                                                   >> 120                         break;
                                                   >> 121 
                                                   >> 122                 case R_SPARC_WDISP30:
                                                   >> 123                         v -= (Elf_Addr) location;
                                                   >> 124                         *loc32 = (*loc32 & ~0x3fffffff) |
                                                   >> 125                                 ((v >> 2) & 0x3fffffff);
                                                   >> 126                         break;
                                                   >> 127 
                                                   >> 128                 case R_SPARC_WDISP22:
                                                   >> 129                         v -= (Elf_Addr) location;
                                                   >> 130                         *loc32 = (*loc32 & ~0x3fffff) |
                                                   >> 131                                 ((v >> 2) & 0x3fffff);
                                                   >> 132                         break;
                                                   >> 133 
                                                   >> 134                 case R_SPARC_LO10:
                                                   >> 135                         *loc32 = (*loc32 & ~0x3ff) | (v & 0x3ff);
                                                   >> 136                         break;
                                                   >> 137 
                                                   >> 138                 case R_SPARC_HI22:
                                                   >> 139                         *loc32 = (*loc32 & ~0x3fffff) |
                                                   >> 140                                 ((v >> 10) & 0x3fffff);
                                                   >> 141                         break;
                                                   >> 142 
141                 default:                          143                 default:
142                         printk(KERN_ERR "%s: u !! 144                         printk(KERN_ERR "module %s: Unknown relocation: %x\n",
143                                module->name,   !! 145                                me->name,
144                                ELF32_R_TYPE(re !! 146                                (int) (ELF_R_TYPE(rel[i].r_info) & 0xff));
145                         return -ENOEXEC;          147                         return -ENOEXEC;
146                 }                                 148                 }
147         }                                         149         }
148         return 0;                                 150         return 0;
149 }                                                 151 }
                                                   >> 152 
                                                   >> 153 #ifdef CONFIG_SPARC64
                                                   >> 154 static void do_patch_sections(const Elf_Ehdr *hdr,
                                                   >> 155                               const Elf_Shdr *sechdrs)
                                                   >> 156 {
                                                   >> 157         const Elf_Shdr *s, *sun4v_1insn = NULL, *sun4v_2insn = NULL;
                                                   >> 158         char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
                                                   >> 159 
                                                   >> 160         for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
                                                   >> 161                 if (!strcmp(".sun4v_1insn_patch", secstrings + s->sh_name))
                                                   >> 162                         sun4v_1insn = s;
                                                   >> 163                 if (!strcmp(".sun4v_2insn_patch", secstrings + s->sh_name))
                                                   >> 164                         sun4v_2insn = s;
                                                   >> 165         }
                                                   >> 166 
                                                   >> 167         if (sun4v_1insn && tlb_type == hypervisor) {
                                                   >> 168                 void *p = (void *) sun4v_1insn->sh_addr;
                                                   >> 169                 sun4v_patch_1insn_range(p, p + sun4v_1insn->sh_size);
                                                   >> 170         }
                                                   >> 171         if (sun4v_2insn && tlb_type == hypervisor) {
                                                   >> 172                 void *p = (void *) sun4v_2insn->sh_addr;
                                                   >> 173                 sun4v_patch_2insn_range(p, p + sun4v_2insn->sh_size);
                                                   >> 174         }
                                                   >> 175 }
                                                   >> 176 
                                                   >> 177 int module_finalize(const Elf_Ehdr *hdr,
                                                   >> 178                     const Elf_Shdr *sechdrs,
                                                   >> 179                     struct module *me)
                                                   >> 180 {
                                                   >> 181         do_patch_sections(hdr, sechdrs);
                                                   >> 182 
                                                   >> 183         /* Cheetah's I-cache is fully coherent.  */
                                                   >> 184         if (tlb_type == spitfire) {
                                                   >> 185                 unsigned long va;
                                                   >> 186 
                                                   >> 187                 flushw_all();
                                                   >> 188                 for (va =  0; va < (PAGE_SIZE << 1); va += 32)
                                                   >> 189                         spitfire_put_icache_tag(va, 0x0);
                                                   >> 190                 __asm__ __volatile__("flush %g6");
                                                   >> 191         }
                                                   >> 192 
                                                   >> 193         return 0;
                                                   >> 194 }
                                                   >> 195 #endif /* CONFIG_SPARC64 */
150                                                   196 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php