archdep.h revision 1.3
1/*	$OpenBSD: archdep.h,v 1.3 2001/09/24 23:40:10 art 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#include <machine/reloc.h>
48
49int	_dl_write __P((int, const char *, int));
50
51/*
52 *	The following functions are declared inline so they can
53 *	be used before bootstrap linking has been finished.
54 */
55static inline void
56_dl_wrstderr(const char *s)
57{
58	while(*s) {
59		_dl_write(2, s, 1);
60		s++;
61	}
62}
63
64static inline void *
65_dl_memset(void *p, const char v, size_t c)
66{
67	char *ip = p;
68
69	while(c--)
70		*ip++ = v;
71	return(p);
72}
73
74static inline int
75_dl_strlen(const char *p)
76{
77	const char *s = p;
78
79	while(*s != '\0')
80		s++;
81	return(s - p);
82}
83
84static inline char *
85_dl_strcpy(char *d, const char *s)
86{
87	char *rd = d;
88
89	while((*d++ = *s++) != '\0');
90
91	return(rd);
92}
93
94static inline int
95_dl_strncmp(const char *d, const char *s, int c)
96{
97	while(c-- && *d && *d == *s) {
98		d++;
99		s++;
100	};
101	if(c < 0) {
102		return(0);
103	}
104	return(*d - *s);
105}
106
107static inline int
108_dl_strcmp(const char *d, const char *s)
109{
110	while(*d && *d == *s) {
111		d++;
112		s++;
113	}
114	return(*d - *s);
115}
116
117static inline const char *
118_dl_strchr(const char *p, const int c)
119{
120	while(*p) {
121		if(*p == c) {
122			return(p);
123		}
124		p++;
125	}
126	return(0);
127}
128
129static inline void
130RELOC_RELA(Elf_RelA *r, const Elf_Sym *s, Elf_Addr *p, unsigned long v)
131{
132	if (ELF_R_TYPE(r->r_info) == RELOC_RELATIVE) {
133		*p += (Elf_Addr)v;
134	} else {
135		/* XXX - printf might not work here, but we give it a shot. */
136		_dl_printf("Unkown bootstrap relocation.\n");
137		_dl_exit(6);
138	}
139}
140
141#endif /* _SPARC64_ARCHDEP_H_ */
142