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/powerpc/powerpc/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  * $FreeBSD: releng/7.4/sys/powerpc/powerpc/elf_machdep.c 191210 2009-04-17 16:42:57Z dchagin $
   26  */
   27 
   28 #include <sys/param.h>
   29 #include <sys/kernel.h>
   30 #include <sys/systm.h>
   31 #include <sys/exec.h>
   32 #include <sys/imgact.h>
   33 #include <sys/malloc.h>
   34 #include <sys/proc.h>
   35 #include <sys/namei.h>
   36 #include <sys/fcntl.h>
   37 #include <sys/sysent.h>
   38 #include <sys/imgact_elf.h>
   39 #include <sys/syscall.h>
   40 #include <sys/signalvar.h>
   41 #include <sys/vnode.h>
   42 #include <sys/linker.h>
   43 
   44 #include <vm/vm.h>
   45 #include <vm/vm_param.h>
   46 
   47 #include <machine/cpu.h>
   48 #include <machine/elf.h>
   49 #include <machine/md_var.h>
   50 
   51 struct sysentvec elf32_freebsd_sysvec = {
   52         .sv_size        = SYS_MAXSYSCALL,
   53         .sv_table       = sysent,
   54         .sv_mask        = 0,
   55         .sv_sigsize     = 0,
   56         .sv_sigtbl      = NULL,
   57         .sv_errsize     = 0,
   58         .sv_errtbl      = NULL,
   59         .sv_transtrap   = NULL,
   60         .sv_fixup       = __elfN(freebsd_fixup),
   61         .sv_sendsig     = sendsig,
   62         .sv_sigcode     = sigcode,
   63         .sv_szsigcode   = &szsigcode,
   64         .sv_prepsyscall = NULL,
   65         .sv_name        = "FreeBSD ELF32",
   66         .sv_coredump    = __elfN(coredump),
   67         .sv_imgact_try  = NULL,
   68         .sv_minsigstksz = MINSIGSTKSZ,
   69         .sv_pagesize    = PAGE_SIZE,
   70         .sv_minuser     = VM_MIN_ADDRESS,
   71         .sv_maxuser     = VM_MAXUSER_ADDRESS,
   72         .sv_usrstack    = USRSTACK,
   73         .sv_psstrings   = PS_STRINGS,
   74         .sv_stackprot   = VM_PROT_ALL,
   75         .sv_copyout_strings = exec_copyout_strings,
   76         .sv_setregs     = exec_setregs,
   77         .sv_fixlimit    = NULL,
   78         .sv_maxssiz     = NULL
   79 };
   80 
   81 static Elf32_Brandinfo freebsd_brand_info = {
   82         .brand          = ELFOSABI_FREEBSD,
   83         .machine        = EM_PPC,
   84         .compat_3_brand = "FreeBSD",
   85         .emul_path      = NULL,
   86         .interp_path    = "/libexec/ld-elf.so.1",
   87         .sysvec         = &elf32_freebsd_sysvec,
   88         .interp_newpath = NULL,
   89         .brand_note     = &elf32_freebsd_brandnote,
   90         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
   91 };
   92 
   93 SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_ANY,
   94     (sysinit_cfunc_t) elf32_insert_brand_entry,
   95     &freebsd_brand_info);
   96 
   97 static Elf32_Brandinfo freebsd_brand_oinfo = {
   98         .brand          = ELFOSABI_FREEBSD,
   99         .machine        = EM_PPC,
  100         .compat_3_brand = "FreeBSD",
  101         .emul_path      = NULL,
  102         .interp_path    = "/usr/libexec/ld-elf.so.1",
  103         .sysvec         = &elf32_freebsd_sysvec,
  104         .interp_newpath = NULL,
  105         .brand_note     = &elf32_freebsd_brandnote,
  106         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
  107 };
  108 
  109 SYSINIT(oelf32, SI_SUB_EXEC, SI_ORDER_ANY,
  110         (sysinit_cfunc_t) elf32_insert_brand_entry,
  111         &freebsd_brand_oinfo);
  112 
  113 
  114 void
  115 elf32_dump_thread(struct thread *td __unused, void *dst __unused,
  116     size_t *off __unused)
  117 {
  118 }
  119 
  120 
  121 /* Process one elf relocation with addend. */
  122 static int
  123 elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
  124     int type, int local, elf_lookup_fn lookup)
  125 {
  126         Elf_Addr *where;
  127         Elf_Half *hwhere;
  128         Elf_Addr addr;
  129         Elf_Addr addend;
  130         Elf_Word rtype, symidx;
  131         const Elf_Rela *rela;
  132 
  133         switch (type) {
  134         case ELF_RELOC_REL:
  135                 panic("PPC only supports RELA relocations");
  136                 break;
  137         case ELF_RELOC_RELA:
  138                 rela = (const Elf_Rela *)data;
  139                 where = (Elf_Addr *) (relocbase + rela->r_offset);
  140                 hwhere = (Elf_Half *) (relocbase + rela->r_offset);
  141                 addend = rela->r_addend;
  142                 rtype = ELF_R_TYPE(rela->r_info);
  143                 symidx = ELF_R_SYM(rela->r_info);
  144                 break;
  145         default:
  146                 panic("elf_reloc: unknown relocation mode %d\n", type);
  147         }
  148 
  149         switch (rtype) {
  150 
  151         case R_PPC_NONE:
  152                 break;
  153 
  154         case R_PPC_ADDR32: /* word32 S + A */
  155                 addr = lookup(lf, symidx, 1);
  156                 if (addr == 0)
  157                         return -1;
  158                 addr += addend;
  159                 *where = addr;
  160                 break;
  161 
  162         case R_PPC_ADDR16_LO: /* #lo(S) */
  163                 addr = lookup(lf, symidx, 1);
  164                 if (addr == 0)
  165                         return -1;
  166                 /*
  167                  * addend values are sometimes relative to sections
  168                  * (i.e. .rodata) in rela, where in reality they
  169                  * are relative to relocbase. Detect this condition.
  170                  */
  171                 if (addr > relocbase && addr <= (relocbase + addend))
  172                         addr = relocbase + addend;
  173                 else
  174                         addr += addend;
  175                 *hwhere = addr & 0xffff;
  176                 break;
  177 
  178         case R_PPC_ADDR16_HA: /* #ha(S) */
  179                 addr = lookup(lf, symidx, 1);
  180                 if (addr == 0)
  181                         return -1;
  182                 /*
  183                  * addend values are sometimes relative to sections
  184                  * (i.e. .rodata) in rela, where in reality they
  185                  * are relative to relocbase. Detect this condition.
  186                  */
  187                 if (addr > relocbase && addr <= (relocbase + addend))
  188                         addr = relocbase + addend;
  189                 else
  190                         addr += addend;
  191                 *hwhere = ((addr >> 16) + ((addr & 0x8000) ? 1 : 0))
  192                     & 0xffff;
  193                 break;
  194 
  195         case R_PPC_RELATIVE: /* word32 B + A */
  196                 *where = relocbase + addend;
  197                 break;
  198 
  199         default:
  200                 printf("kldload: unexpected relocation type %d\n",
  201                     (int) rtype);
  202                 return -1;
  203         }
  204         return(0);
  205 }
  206 
  207 int
  208 elf_reloc(linker_file_t lf, Elf_Addr relocbase, const void *data, int type,
  209     elf_lookup_fn lookup)
  210 {
  211 
  212         return (elf_reloc_internal(lf, relocbase, data, type, 0, lookup));
  213 }
  214 
  215 int
  216 elf_reloc_local(linker_file_t lf, Elf_Addr relocbase, const void *data,
  217     int type, elf_lookup_fn lookup)
  218 {
  219 
  220         return (elf_reloc_internal(lf, relocbase, data, type, 1, lookup));
  221 }
  222 
  223 int
  224 elf_cpu_load_file(linker_file_t lf)
  225 {
  226         /* Only sync the cache for non-kernel modules */
  227         if (lf->id != 1)
  228                 __syncicache(lf->address, lf->size);
  229         return (0);
  230 }
  231 
  232 int
  233 elf_cpu_unload_file(linker_file_t lf __unused)
  234 {
  235 
  236         return (0);
  237 }

Cache object: c4bdf16cd84206c029f4b01d0fee533b


[ 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.