1*eb6cc752Sjoerg /* $NetBSD: loadfile_machdep.h,v 1.6 2014/08/06 21:57:51 joerg Exp $ */ 2a06455d0Sad 3a06455d0Sad /*- 43c11640eSad * Copyright (c) 1998, 2007, 2009 The NetBSD Foundation, Inc. 5a06455d0Sad * All rights reserved. 6a06455d0Sad * 7a06455d0Sad * This code is derived from software contributed to The NetBSD Foundation 8a06455d0Sad * by Christos Zoulas. 9a06455d0Sad * 10a06455d0Sad * Redistribution and use in source and binary forms, with or without 11a06455d0Sad * modification, are permitted provided that the following conditions 12a06455d0Sad * are met: 13a06455d0Sad * 1. Redistributions of source code must retain the above copyright 14a06455d0Sad * notice, this list of conditions and the following disclaimer. 15a06455d0Sad * 2. Redistributions in binary form must reproduce the above copyright 16a06455d0Sad * notice, this list of conditions and the following disclaimer in the 17a06455d0Sad * documentation and/or other materials provided with the distribution. 18a06455d0Sad * 19a06455d0Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20a06455d0Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21a06455d0Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22a06455d0Sad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23a06455d0Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24a06455d0Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25a06455d0Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26a06455d0Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27a06455d0Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28a06455d0Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29a06455d0Sad * POSSIBILITY OF SUCH DAMAGE. 30a06455d0Sad */ 31a06455d0Sad 32a06455d0Sad #define BOOT_ELF32 33a06455d0Sad #define BOOT_ELF64 34a06455d0Sad 35a06455d0Sad #define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA) 36a06455d0Sad #define COUNT_KERNEL (COUNT_ALL & ~COUNT_TEXTA) 37a06455d0Sad 38a06455d0Sad #ifdef _STANDALONE 39a06455d0Sad 40a06455d0Sad #define LOADADDR(a) ((((u_long)(a)) & 0x07ffffff) + offset) 41a06455d0Sad #define ALIGNENTRY(a) ((u_long)(a) & 0x00100000) 42a06455d0Sad #define READ(f, b, c) pread((f), (void *)LOADADDR(b), (c)) 43a06455d0Sad #define BCOPY(s, d, c) vpbcopy((s), (void *)LOADADDR(d), (c)) 44a06455d0Sad #define BZERO(d, c) pbzero((void *)LOADADDR(d), (c)) 45*eb6cc752Sjoerg #define WARN(a) do { \ 46*eb6cc752Sjoerg (void)printf a; \ 47*eb6cc752Sjoerg if (errno) \ 48*eb6cc752Sjoerg (void)printf(": %s\n", \ 49*eb6cc752Sjoerg strerror(errno)); \ 50*eb6cc752Sjoerg else \ 51*eb6cc752Sjoerg (void)printf("\n"); \ 52*eb6cc752Sjoerg } while(/* CONSTCOND */0) 533c11640eSad #define PROGRESS(a) x86_progress a 54a06455d0Sad #define ALLOC(a) alloc(a) 55a06455d0Sad #define DEALLOC(a, b) dealloc(a, b) 56a06455d0Sad #define OKMAGIC(a) ((a) == ZMAGIC) 57a06455d0Sad 58b98dd0fbSjoerg void x86_progress(const char *, ...) __printflike(1, 2); 59a06455d0Sad void vpbcopy(const void *, void *, size_t); 60a06455d0Sad void pbzero(void *, size_t); 61a06455d0Sad ssize_t pread(int, void *, size_t); 62a06455d0Sad 63a06455d0Sad #else 64d395ac93Schristos #ifdef TEST 65d395ac93Schristos #define LOADADDR(a) offset 66d395ac93Schristos #define READ(f, b, c) c 67d395ac93Schristos #define BCOPY(s, d, c) 68d395ac93Schristos #define BZERO(d, c) 69d395ac93Schristos #define PROGRESS(a) (void) printf a 70d395ac93Schristos #else 71a06455d0Sad #define LOADADDR(a) (((u_long)(a)) + offset) 72a06455d0Sad #define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) 73a06455d0Sad #define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) 74a06455d0Sad #define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) 75a06455d0Sad #define PROGRESS(a) /* nothing */ 76d395ac93Schristos #endif 77d395ac93Schristos #define WARN(a) warn a 78d395ac93Schristos #define ALIGNENTRY(a) ((u_long)(a)) 79a06455d0Sad #define ALLOC(a) malloc(a) 80a06455d0Sad #define DEALLOC(a, b) free(a) 81a06455d0Sad #define OKMAGIC(a) ((a) == OMAGIC) 82a06455d0Sad 83a06455d0Sad ssize_t vread(int, u_long, u_long *, size_t); 84a06455d0Sad void vcopy(u_long, u_long, u_long *, size_t); 85a06455d0Sad void vzero(u_long, u_long *, size_t); 86a06455d0Sad 87a06455d0Sad #endif 88