Home | History | Annotate | Line # | Download | only in arm32
kobj_machdep.c revision 1.1
      1 /*	$NetBSD: kobj_machdep.c,v 1.1 2008/01/04 16:23:39 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the NetBSD
     18  *	Foundation, Inc. and its contributors.
     19  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  *    contributors may be used to endorse or promote products derived
     21  *    from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  * POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 /*-
     37  * Copyright 1996-1998 John D. Polstra.
     38  * All rights reserved.
     39  *
     40  * Redistribution and use in source and binary forms, with or without
     41  * modification, are permitted provided that the following conditions
     42  * are met:
     43  * 1. Redistributions of source code must retain the above copyright
     44  *    notice, this list of conditions and the following disclaimer.
     45  * 2. Redistributions in binary form must reproduce the above copyright
     46  *    notice, this list of conditions and the following disclaimer in the
     47  *    documentation and/or other materials provided with the distribution.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     50  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     51  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     52  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     53  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     54  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     55  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     56  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     57  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     58  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     59  */
     60 
     61 #include <sys/cdefs.h>
     62 __KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.1 2008/01/04 16:23:39 ad Exp $");
     63 
     64 #define	ELFSIZE		ARCH_ELFSIZE
     65 
     66 #include <sys/param.h>
     67 #include <sys/systm.h>
     68 #include <sys/kobj.h>
     69 #include <sys/exec.h>
     70 #include <sys/exec_elf.h>
     71 
     72 #include <arm/cpufunc.h>
     73 
     74 int
     75 kobj_reloc(kobj_t ko, uintptr_t relocbase, const void *data,
     76 	   bool isrela, bool local)
     77 {
     78 	Elf_Addr *where;
     79 	Elf_Addr addr;
     80 	Elf_Addr addend;
     81 	Elf_Word rtype, symidx;
     82 	const Elf_Rel *rel;
     83 	const Elf_Rela *rela;
     84 
     85 	if (isrela) {
     86 		rela = (const Elf_Rela *)data;
     87 		where = (Elf_Addr *) (relocbase + rela->r_offset);
     88 		addend = rela->r_addend;
     89 		rtype = ELF_R_TYPE(rela->r_info);
     90 		symidx = ELF_R_SYM(rela->r_info);
     91 	} else {
     92 		rel = (const Elf_Rel *)data;
     93 		where = (Elf_Addr *) (relocbase + rel->r_offset);
     94 		addend = *where;
     95 		rtype = ELF_R_TYPE(rel->r_info);
     96 		symidx = ELF_R_SYM(rel->r_info);
     97 	}
     98 
     99 	switch (rtype) {
    100 	case R_ARM_NONE:	/* none */
    101 		break;
    102 
    103 	case R_ARM_ABS32:
    104 		addr = kobj_sym_lookup(ko, symidx);
    105 		if (addr == 0)
    106 			return -1;
    107 		if (*where != addr)
    108 			*where = addr;
    109 
    110 		break;
    111 
    112 	case R_ARM_COPY:	/* none */
    113 		/*
    114 		 * There shouldn't be copy relocations in kernel
    115 		 * objects.
    116 		 */
    117 		printf("kobj_reloc: unexpected R_COPY relocation\n");
    118 		return -1;
    119 
    120 	case R_ARM_JUMP_SLOT:
    121 		addr = kobj_sym_lookup(ko, symidx);
    122 		if (addr) {
    123 			*where = addr;
    124 			return 0;
    125 		}
    126 		return -1;
    127 
    128 	case R_ARM_RELATIVE:	/* A + B */
    129 		addr = relocbase + addend;
    130 		if (*where != addr)
    131 			*where = addr;
    132 		break;
    133 
    134 	default:
    135 		printf("kobj_reloc: unexpected relocation type %d\n", rtype);
    136 		return -1;
    137 	}
    138 	return 0;
    139 }
    140 
    141 int
    142 kobj_machdep(kobj_t ko, void *base, size_t size, bool load)
    143 {
    144 
    145 	if (load) {
    146 		cpu_idcache_wbinv_all();
    147 		cpu_tlb_flushID();
    148 	}
    149 
    150 	return 0;
    151 }
    152