1*b7d1e043Sjoerg /*	$NetBSD: loadfile_machdep.h,v 1.3 2014/08/06 21:57:49 joerg Exp $	 */
2ba7cbe76Scherry 
3ba7cbe76Scherry /*-
4ba7cbe76Scherry  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5ba7cbe76Scherry  * All rights reserved.
6ba7cbe76Scherry  *
7ba7cbe76Scherry  * This code is derived from software contributed to The NetBSD Foundation
8ba7cbe76Scherry  * by Christos Zoulas and Ross Harvey.
9ba7cbe76Scherry  *
10ba7cbe76Scherry  * Redistribution and use in source and binary forms, with or without
11ba7cbe76Scherry  * modification, are permitted provided that the following conditions
12ba7cbe76Scherry  * are met:
13ba7cbe76Scherry  * 1. Redistributions of source code must retain the above copyright
14ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer.
15ba7cbe76Scherry  * 2. Redistributions in binary form must reproduce the above copyright
16ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer in the
17ba7cbe76Scherry  *    documentation and/or other materials provided with the distribution.
18ba7cbe76Scherry  *
19ba7cbe76Scherry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20ba7cbe76Scherry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21ba7cbe76Scherry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22ba7cbe76Scherry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23ba7cbe76Scherry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ba7cbe76Scherry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ba7cbe76Scherry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ba7cbe76Scherry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ba7cbe76Scherry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ba7cbe76Scherry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ba7cbe76Scherry  * POSSIBILITY OF SUCH DAMAGE.
30ba7cbe76Scherry  */
31ba7cbe76Scherry 
32ba7cbe76Scherry #define BOOT_ELF64
33ba7cbe76Scherry 
34ba7cbe76Scherry #define LOAD_KERNEL	(LOAD_ALL & ~LOAD_TEXTA)
35ba7cbe76Scherry #define COUNT_KERNEL	(COUNT_ALL & ~COUNT_TEXTA)
36ba7cbe76Scherry 
37ba7cbe76Scherry #ifndef MD_LOADSEG
38ba7cbe76Scherry /* XXX: Multiple unwind sections are ignored, and the last one found returned... Fixme! */
39ba7cbe76Scherry extern	vaddr_t ia64_unwindtab;
40ba7cbe76Scherry extern	vsize_t ia64_unwindtablen;
41ba7cbe76Scherry #define MD_LOADSEG(phdr) ((phdr)->p_type == PT_IA_64_UNWIND ? ia64_unwindtab = (phdr)->p_vaddr, ia64_unwindtablen = (phdr)->p_filesz, 1 : 0)
42ba7cbe76Scherry #endif
43ba7cbe76Scherry 
44ba7cbe76Scherry #ifdef _STANDALONE
45ba7cbe76Scherry 
46ba7cbe76Scherry /* XXX: cherry: This whole thing is glue between the NetBSD pread/vpbcopy etc. etc
47ba7cbe76Scherry  *      and the FreeBSD kern_pread/bzero etc. etc. Needs to be cleaned up
48ba7cbe76Scherry  *      after discussion.
49ba7cbe76Scherry  */
50ba7cbe76Scherry 
51ba7cbe76Scherry #include "bootstrap.h"
52ba7cbe76Scherry 
53ba7cbe76Scherry #define LOADADDR(a)		((a) + offset)
54ba7cbe76Scherry #define ALIGNENTRY(a)		Error! alpha supports ECOFF and ELF only! /* Fixme: for ia64 */
55ba7cbe76Scherry #define READ(f, b, c)		pread((f), LOADADDR(b), (c))
56ba7cbe76Scherry #define BCOPY(s, d, c)		vpbcopy((s), LOADADDR(d), (c))
57ba7cbe76Scherry #define BZERO(d, c)		pbzero(LOADADDR(d), (c))
58*b7d1e043Sjoerg #define	WARN(a)			do { \
59*b7d1e043Sjoerg 					(void)printf a; \
60*b7d1e043Sjoerg 					if (errno) \
61*b7d1e043Sjoerg 						(void)printf(": %s\n", \
62*b7d1e043Sjoerg 						             strerror(errno)); \
63*b7d1e043Sjoerg 					else \
64*b7d1e043Sjoerg 						(void)printf("\n"); \
65*b7d1e043Sjoerg 				} while(/* CONSTCOND */0)
66ba7cbe76Scherry #define PROGRESS(a)		(void) printf a
67ba7cbe76Scherry #define ALLOC(a)		alloc(a)
68ba7cbe76Scherry #define DEALLOC(a, b)		dealloc(a, b)
69ba7cbe76Scherry #define OKMAGIC(a)		Error! ia64 supports ELF only!
70ba7cbe76Scherry 
71ba7cbe76Scherry 
72ba7cbe76Scherry /* XXX: defines below glues NetBSD conventions with bootstrap.h. */
73ba7cbe76Scherry 
74ba7cbe76Scherry #define	vpbcopy archsw.arch_copyin
75ba7cbe76Scherry #define	pbzero  kern_bzero
76ba7cbe76Scherry #define pread archsw.arch_readin
77ba7cbe76Scherry 
78ba7cbe76Scherry #else
79ba7cbe76Scherry 
80ba7cbe76Scherry #define LOADADDR(a)		(((u_long)(a)) + offset)
81ba7cbe76Scherry #define ALIGNENTRY(a)		((u_long)(a))
82ba7cbe76Scherry #define READ(f, b, c)		read((f), (void *)LOADADDR(b), (c))
83ba7cbe76Scherry #define BCOPY(s, d, c)		memcpy((void *)LOADADDR(d), (void *)(s), (c))
84ba7cbe76Scherry #define BZERO(d, c)		memset((void *)LOADADDR(d), 0, (c))
85ba7cbe76Scherry #define WARN(a)			warn a
86ba7cbe76Scherry #define PROGRESS(a)		/* nothing */
87ba7cbe76Scherry #define ALLOC(a)		malloc(a)
88ba7cbe76Scherry #define DEALLOC(a, b)		free(a)
89ba7cbe76Scherry #define OKMAGIC(a)		((a) == OMAGIC)
90ba7cbe76Scherry 
91ba7cbe76Scherry ssize_t vread(int, u_long, u_long *, size_t);
92ba7cbe76Scherry void vcopy(u_long, u_long, u_long *, size_t);
93ba7cbe76Scherry void vzero(u_long, u_long *, size_t);
94ba7cbe76Scherry 
95ba7cbe76Scherry #endif
96