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