The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/mips/mips/elf_machdep.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright 1996-1998 John D. Polstra.
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   24  *
   25  *      from: src/sys/i386/i386/elf_machdep.c,v 1.20 2004/08/11 02:35:05 marcel
   26  */
   27 
   28 #include <sys/cdefs.h>
   29 __FBSDID("$FreeBSD: releng/9.0/sys/mips/mips/elf_machdep.c 219405 2011-03-08 19:01:45Z dchagin $");
   30 
   31 #include <sys/param.h>
   32 #include <sys/kernel.h>
   33 #include <sys/systm.h>
   34 #include <sys/exec.h>
   35 #include <sys/imgact.h>
   36 #include <sys/linker.h>
   37 #include <sys/sysent.h>
   38 #include <sys/imgact_elf.h>
   39 #include <sys/proc.h>
   40 #include <sys/syscall.h>
   41 #include <sys/signalvar.h>
   42 #include <sys/vnode.h>
   43 
   44 #include <vm/vm.h>
   45 #include <vm/pmap.h>
   46 #include <vm/vm_param.h>
   47 
   48 #include <machine/elf.h>
   49 #include <machine/md_var.h>
   50 #include <machine/cache.h>
   51 
   52 #ifdef __mips_n64
   53 struct sysentvec elf64_freebsd_sysvec = {
   54         .sv_size        = SYS_MAXSYSCALL,
   55         .sv_table       = sysent,
   56         .sv_mask        = 0,
   57         .sv_sigsize     = 0,
   58         .sv_sigtbl      = NULL,
   59         .sv_errsize     = 0,
   60         .sv_errtbl      = NULL,
   61         .sv_transtrap   = NULL,
   62         .sv_fixup       = __elfN(freebsd_fixup),
   63         .sv_sendsig     = sendsig,
   64         .sv_sigcode     = sigcode,
   65         .sv_szsigcode   = &szsigcode,
   66         .sv_prepsyscall = NULL,
   67         .sv_name        = "FreeBSD ELF64",
   68         .sv_coredump    = __elfN(coredump),
   69         .sv_imgact_try  = NULL,
   70         .sv_minsigstksz = MINSIGSTKSZ,
   71         .sv_pagesize    = PAGE_SIZE,
   72         .sv_minuser     = VM_MIN_ADDRESS,
   73         .sv_maxuser     = VM_MAXUSER_ADDRESS,
   74         .sv_usrstack    = USRSTACK,
   75         .sv_psstrings   = PS_STRINGS,
   76         .sv_stackprot   = VM_PROT_ALL,
   77         .sv_copyout_strings = exec_copyout_strings,
   78         .sv_setregs     = exec_setregs,
   79         .sv_fixlimit    = NULL,
   80         .sv_maxssiz     = NULL,
   81         .sv_flags       = SV_ABI_FREEBSD | SV_LP64,
   82         .sv_set_syscall_retval = cpu_set_syscall_retval,
   83         .sv_fetch_syscall_args = NULL, /* XXXKIB */
   84         .sv_syscallnames = syscallnames,
   85         .sv_schedtail   = NULL,
   86 };
   87 
   88 static Elf64_Brandinfo freebsd_brand_info = {
   89         .brand          = ELFOSABI_FREEBSD,
   90         .machine        = EM_MIPS,
   91         .compat_3_brand = "FreeBSD",
   92         .emul_path      = NULL,
   93         .interp_path    = "/libexec/ld-elf.so.1",
   94         .sysvec         = &elf64_freebsd_sysvec,
   95         .interp_newpath = NULL,
   96         .flags          = 0
   97 };
   98 
   99 SYSINIT(elf64, SI_SUB_EXEC, SI_ORDER_ANY,
  100     (sysinit_cfunc_t) elf64_insert_brand_entry,
  101     &freebsd_brand_info);
  102 
  103 void
  104 elf64_dump_thread(struct thread *td __unused, void *dst __unused,
  105     size_t *off __unused)
  106 {
  107 }
  108 #else
  109 struct sysentvec elf32_freebsd_sysvec = {
  110         .sv_size        = SYS_MAXSYSCALL,
  111         .sv_table       = sysent,
  112         .sv_mask        = 0,
  113         .sv_sigsize     = 0,
  114         .sv_sigtbl      = NULL,
  115         .sv_errsize     = 0,
  116         .sv_errtbl      = NULL,
  117         .sv_transtrap   = NULL,
  118         .sv_fixup       = __elfN(freebsd_fixup),
  119         .sv_sendsig     = sendsig,
  120         .sv_sigcode     = sigcode,
  121         .sv_szsigcode   = &szsigcode,
  122         .sv_prepsyscall = NULL,
  123         .sv_name        = "FreeBSD ELF32",
  124         .sv_coredump    = __elfN(coredump),
  125         .sv_imgact_try  = NULL,
  126         .sv_minsigstksz = MINSIGSTKSZ,
  127         .sv_pagesize    = PAGE_SIZE,
  128         .sv_minuser     = VM_MIN_ADDRESS,
  129         .sv_maxuser     = VM_MAXUSER_ADDRESS,
  130         .sv_usrstack    = USRSTACK,
  131         .sv_psstrings   = PS_STRINGS,
  132         .sv_stackprot   = VM_PROT_ALL,
  133         .sv_copyout_strings = exec_copyout_strings,
  134         .sv_setregs     = exec_setregs,
  135         .sv_fixlimit    = NULL,
  136         .sv_maxssiz     = NULL,
  137         .sv_flags       = SV_ABI_FREEBSD | SV_ILP32,
  138         .sv_set_syscall_retval = cpu_set_syscall_retval,
  139         .sv_fetch_syscall_args = NULL, /* XXXKIB */
  140         .sv_syscallnames = syscallnames,
  141         .sv_schedtail   = NULL,
  142 };
  143 
  144 static Elf32_Brandinfo freebsd_brand_info = {
  145         .brand          = ELFOSABI_FREEBSD,
  146         .machine        = EM_MIPS,
  147         .compat_3_brand = "FreeBSD",
  148         .emul_path      = NULL,
  149         .interp_path    = "/libexec/ld-elf.so.1",
  150         .sysvec         = &elf32_freebsd_sysvec,
  151         .interp_newpath = NULL,
  152         .flags          = 0
  153 };
  154 
  155 SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST,
  156     (sysinit_cfunc_t) elf32_insert_brand_entry,
  157     &freebsd_brand_info);
  158 
  159 void
  160 elf32_dump_thread(struct thread *td __unused, void *dst __unused,
  161     size_t *off __unused)
  162 {
  163 }
  164 #endif
  165 
  166 /* Process one elf relocation with addend. */
  167 static int
  168 elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
  169     int type, int local, elf_lookup_fn lookup)
  170 {
  171         Elf_Addr *where = (Elf_Addr *)NULL;
  172         Elf_Addr addr;
  173         Elf_Addr addend = (Elf_Addr)0;
  174         Elf_Word rtype = (Elf_Word)0, symidx;
  175         const Elf_Rel *rel;
  176 
  177         /*
  178          * Stash R_MIPS_HI16 info so we can use it when processing R_MIPS_LO16
  179          */
  180         static Elf_Addr ahl;
  181         static Elf_Addr *where_hi16;
  182 
  183         switch (type) {
  184         case ELF_RELOC_REL:
  185                 rel = (const Elf_Rel *)data;
  186                 where = (Elf_Addr *) (relocbase + rel->r_offset);
  187                 addend = *where;
  188                 rtype = ELF_R_TYPE(rel->r_info);
  189                 symidx = ELF_R_SYM(rel->r_info);
  190                 break;
  191         default:
  192                 panic("unknown reloc type %d\n", type);
  193         }
  194 
  195         switch (rtype) {
  196         case R_MIPS_NONE:       /* none */
  197                 break;
  198 
  199         case R_MIPS_32:         /* S + A */
  200                 addr = lookup(lf, symidx, 1);
  201                 if (addr == 0)
  202                         return (-1);
  203                 addr += addend;
  204                 if (*where != addr)
  205                         *where = addr;
  206                 break;
  207 
  208         case R_MIPS_26:         /* ((A << 2) | (P & 0xf0000000) + S) >> 2 */
  209                 addr = lookup(lf, symidx, 1);
  210                 if (addr == 0)
  211                         return (-1);
  212 
  213                 addend &= 0x03ffffff;
  214                 addend <<= 2;
  215 
  216                 addr += ((Elf_Addr)where & 0xf0000000) | addend;
  217                 addr >>= 2;
  218 
  219                 *where &= ~0x03ffffff;
  220                 *where |= addr & 0x03ffffff;
  221                 break;
  222 
  223         case R_MIPS_HI16:       /* ((AHL + S) - ((short)(AHL + S)) >> 16 */
  224                 ahl = addend << 16;
  225                 where_hi16 = where;
  226                 break;
  227 
  228         case R_MIPS_LO16:       /* AHL + S */
  229                 ahl += (int16_t)addend;
  230                 addr = lookup(lf, symidx, 1);
  231                 if (addr == 0)
  232                         return (-1);
  233 
  234                 addend &= 0xffff0000;
  235                 addend |= (uint16_t)(ahl + addr);
  236                 *where = addend;
  237 
  238                 addend = *where_hi16;
  239                 addend &= 0xffff0000;
  240                 addend |= ((ahl + addr) - (int16_t)(ahl + addr)) >> 16;
  241                 *where_hi16 = addend;
  242                 break;
  243 
  244         default:
  245                 printf("kldload: unexpected relocation type %d\n",
  246                         rtype);
  247                 return (-1);
  248         }
  249         return(0);
  250 }
  251 
  252 int
  253 elf_reloc(linker_file_t lf, Elf_Addr relocbase, const void *data, int type,
  254     elf_lookup_fn lookup)
  255 {
  256 
  257         return (elf_reloc_internal(lf, relocbase, data, type, 0, lookup));
  258 }
  259 
  260 int
  261 elf_reloc_local(linker_file_t lf, Elf_Addr relocbase, const void *data,
  262     int type, elf_lookup_fn lookup)
  263 {
  264 
  265         return (elf_reloc_internal(lf, relocbase, data, type, 1, lookup));
  266 }
  267 
  268 int
  269 elf_cpu_load_file(linker_file_t lf __unused)
  270 {
  271 
  272         /*
  273          * Sync the I and D caches to make sure our relocations are visible.
  274          */
  275         mips_icache_sync_all();
  276 
  277         return (0);
  278 }
  279 
  280 int
  281 elf_cpu_unload_file(linker_file_t lf __unused)
  282 {
  283 
  284         return (0);
  285 }

Cache object: b99944ef8392e8fcab28b7223318ac30


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.