archdep.h revision 1.1
1/*	$OpenBSD: archdep.h,v 1.1 2001/09/21 14:57:43 jason Exp $ */
2
3/*
4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed under OpenBSD by
17 *	Per Fogelstrom, Opsycon AB, Sweden.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 */
34
35#ifndef _SPARC64_ARCHDEP_H_
36#define _SPARC64_ARCHDEP_H_
37
38#define	DL_MALLOC_ALIGN	8	/* Arch constraint or otherwise */
39
40#define	MACHID	EM_SPARCV9	/* ELF e_machine ID value checked */
41
42#define	RELTYPE	Elf64_Rela
43#define	RELSIZE	sizeof(Elf64_Rela)
44
45#include <elf_abi.h>
46#include <machine/exec.h>
47
48int	_dl_write __P((int, const char *, int));
49
50/*
51 *	The following functions are declared inline so they can
52 *	be used before bootstrap linking has been finished.
53 */
54static inline void
55_dl_wrstderr(const char *s)
56{
57	while(*s) {
58		_dl_write(2, s, 1);
59		s++;
60	}
61}
62
63static inline void *
64_dl_memset(void *p, const char v, size_t c)
65{
66	char *ip = p;
67
68	while(c--)
69		*ip++ = v;
70	return(p);
71}
72
73static inline int
74_dl_strlen(const char *p)
75{
76	const char *s = p;
77
78	while(*s != '\0')
79		s++;
80	return(s - p);
81}
82
83static inline char *
84_dl_strcpy(char *d, const char *s)
85{
86	char *rd = d;
87
88	while((*d++ = *s++) != '\0');
89
90	return(rd);
91}
92
93static inline int
94_dl_strncmp(const char *d, const char *s, int c)
95{
96	while(c-- && *d && *d == *s) {
97		d++;
98		s++;
99	};
100	if(c < 0) {
101		return(0);
102	}
103	return(*d - *s);
104}
105
106static inline int
107_dl_strcmp(const char *d, const char *s)
108{
109	while(*d && *d == *s) {
110		d++;
111		s++;
112	}
113	return(*d - *s);
114}
115
116static inline const char *
117_dl_strchr(const char *p, const int c)
118{
119	while(*p) {
120		if(*p == c) {
121			return(p);
122		}
123		p++;
124	}
125	return(0);
126}
127
128static inline void
129RELOC_RELA(Elf64_Rela *r, const Elf64_Sym *s, Elf64_Addr *p, unsigned long v)
130{
131#error "haven't fixed for sparc64 yet..."
132	extern Elf_Addr  _GLOBAL_OFFSET_TABLE_[];
133
134	if (ELF64_R_TYPE(r->r_info) == RELOC_RELATIVE) {
135		if ((caddr_t)p < (caddr_t)_GLOBAL_OFFSET_TABLE_ ||
136		    (caddr_t)p >= (caddr_t)&_DYNAMIC)
137			*p += (Elf_Addr)v;
138	} else if (ELF64_R_TYPE(r->r_info) == RELOC_JMP_SLOT) {
139		Elf64_Addr val = v + s->st_value + r->r_addend -
140			(Elf64_Addr)(p);
141		*p = val;
142		__asm __volatile("imb" : : : "memory");
143	} else if (ELF64_R_TYPE(r->r_info) == RELOC_GLOB_DAT) {
144		*p = v + s->st_value + r->r_addend;
145	} else {
146		_dl_printf("unknown bootstrap relocation\n");
147		_dl_exit(6);
148	}
149}
150
151#endif /* _SPARC64_ARCHDEP_H_ */
152