xref: /openbsd/libexec/ld.so/powerpc/archdep.h (revision 1e43641e)
1*1e43641eSderaadt /*	$OpenBSD: archdep.h,v 1.26 2023/11/18 16:26:17 deraadt Exp $ */
289c547eeSrahnds 
389c547eeSrahnds /*
489c547eeSrahnds  * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
589c547eeSrahnds  *
689c547eeSrahnds  * Redistribution and use in source and binary forms, with or without
789c547eeSrahnds  * modification, are permitted provided that the following conditions
889c547eeSrahnds  * are met:
989c547eeSrahnds  * 1. Redistributions of source code must retain the above copyright
1089c547eeSrahnds  *    notice, this list of conditions and the following disclaimer.
1189c547eeSrahnds  * 2. Redistributions in binary form must reproduce the above copyright
1289c547eeSrahnds  *    notice, this list of conditions and the following disclaimer in the
1389c547eeSrahnds  *    documentation and/or other materials provided with the distribution.
1489c547eeSrahnds  *
1589c547eeSrahnds  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1689c547eeSrahnds  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1789c547eeSrahnds  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1889c547eeSrahnds  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
1989c547eeSrahnds  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2089c547eeSrahnds  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2189c547eeSrahnds  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2289c547eeSrahnds  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2389c547eeSrahnds  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2489c547eeSrahnds  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2589c547eeSrahnds  * SUCH DAMAGE.
2689c547eeSrahnds  *
2789c547eeSrahnds  */
2889c547eeSrahnds 
2989c547eeSrahnds #ifndef _POWERPC_ARCHDEP_H_
3089c547eeSrahnds #define _POWERPC_ARCHDEP_H_
3189c547eeSrahnds 
3201804a41Sguenther #define	RELOC_TAG	DT_RELA
3389c547eeSrahnds #define	MACHID		EM_PPC		/* ELF e_machine ID value checked */
3489c547eeSrahnds 
35bcbffc12Sdrahn 
3689c547eeSrahnds static inline void
_dl_dcbf(void * addr)37b0714f38Sguenther _dl_dcbf(void *addr)
3889c547eeSrahnds {
39c6ba0247Srahnds 	__asm__ volatile ("dcbst 0, %0\n\t"
40c6ba0247Srahnds 	    "sync\n\t"
41c6ba0247Srahnds 	    "icbi 0, %0\n\t"
42c6ba0247Srahnds 	    "sync\n\t"
43c6ba0247Srahnds 	    "isync"
4489c547eeSrahnds 	    : : "r" (addr) : "0");
4589c547eeSrahnds }
4689c547eeSrahnds 
47246ef78eSguenther /* Only used in lib/csu/boot.h */
48b0714f38Sguenther #ifdef RCRT0
49b0714f38Sguenther 
5089c547eeSrahnds static inline void
RELOC_DYN(const Elf_RelA * r,const Elf_Sym * s,Elf_Addr * p,unsigned long v)51b0714f38Sguenther RELOC_DYN(const Elf_RelA *r, const Elf_Sym *s, Elf_Addr *p, unsigned long v)
5289c547eeSrahnds {
53e3b0f1d9Sguenther 	if (ELF_R_TYPE(r->r_info) == RELOC_RELATIVE) {
5419b70b43Sdrahn 		*p = v + r->r_addend;
55e3b0f1d9Sguenther 	} else if (ELF_R_TYPE(r->r_info) == RELOC_JMP_SLOT) {
56e3b0f1d9Sguenther 		Elf_Addr val = v + s->st_value + r->r_addend -
57e3b0f1d9Sguenther 		    (Elf_Addr)(p);
5889c547eeSrahnds 		if (((val & 0xfe000000) != 0) &&
5939b7d201Sderaadt 		    ((val & 0xfe000000) != 0xfe000000)) {
6089c547eeSrahnds 			/* invalid offset */
61*1e43641eSderaadt 			_csu_abort();
6289c547eeSrahnds 		}
6389c547eeSrahnds 		val &= ~0xfc000000;
6489c547eeSrahnds 		val |=  0x48000000;
6519b70b43Sdrahn 		*p = val;
6689c547eeSrahnds 		_dl_dcbf(p);
67e3b0f1d9Sguenther 	} else if (ELF_R_TYPE((r)->r_info) == RELOC_GLOB_DAT) {
6819b70b43Sdrahn 		*p = v + s->st_value + r->r_addend;
6989c547eeSrahnds 	} else {
70*1e43641eSderaadt 		_csu_abort();
7189c547eeSrahnds 	}
7289c547eeSrahnds }
7389c547eeSrahnds 
74b0714f38Sguenther #endif /* RCRT0 */
7589c547eeSrahnds #endif /* _POWERPC_ARCHDEP_H_ */
76