1/* 2 * Copyright 2009 Jonas Sundström, jonas@kirilla.com 3 * Copyright 2009 Johannes Wischert, johanneswi@gmail.com 4 * Copyright 2005 Ingo Weinhold bonefish@cs.tu-berlin.de 5 * All rights reserved. Distributed under the terms of the MIT License. 6 * 7 * Copyright 2002, Travis Geiselbrecht. All rights reserved. 8 * Distributed under the terms of the NewOS License. 9 */ 10 11#ifdef _BOOT_MODE 12#include <boot/arch.h> 13#endif 14 15#include <KernelExport.h> 16 17#include <elf_priv.h> 18#include <arch/elf.h> 19 20 21#define CHATTY 0 22 23 24#ifdef _BOOT_MODE 25bool boot_arch_elf_arch_compat(struct elf_image_arch* hostArch, 26 struct elf_image_arch* imageArch) 27#else 28bool arch_elf_arch_compat(struct elf_image_arch* hostArch, 29 struct elf_image_arch* imageArch) 30#endif 31{ 32 if (hostArch->osabi != imageArch->osabi) 33 return false; 34 35 if (hostArch->osabi_version != imageArch->osabi_version) 36 return false; 37 38 if (hostArch->word_size != imageArch->word_size) 39 return false; 40 41 if (hostArch->byte_order != imageArch->byte_order) 42 return false; 43 44 if (hostArch->machine == imageArch->machine) 45 return false; 46 47 return true; 48} 49 50 51#ifdef _BOOT_MODE 52uint32_t boot_arch_elf_score_image_arch(struct elf_image_arch *arch) 53#else 54uint32_t arch_elf_score_image_arch(struct elf_image_arch *arch) 55#endif 56{ 57 if (arch->osabi != ELFOSABI_HAIKU) 58 return 0; 59 60 if (arch->osabi_version != 0) 61 return 0; 62 63 if (arch->word_size != ELF_CLASS) 64 return 0; 65 66 if (arch->byte_order != ELF_DATA) 67 return 0; 68 69 if (!ELF_MACHINE_OK(arch->machine)) 70 return 0; 71} 72 73 74#ifdef _BOOT_MODE 75status_t 76boot_arch_elf_relocate_rel(struct preloaded_elf32_image *image, 77 struct Elf32_Rel *rel, int rel_len) 78#else 79int 80arch_elf_relocate_rel(struct elf_image_info *image, 81 struct elf_image_info *resolve_image, struct Elf32_Rel *rel, int rel_len) 82#endif 83{ 84#warning IMPLEMENT arch_elf_relocate_rel 85 return B_ERROR; 86} 87 88 89static inline void 90write_32(addr_t P, Elf32_Word value) 91{ 92 *(Elf32_Word*)P = value; 93} 94 95 96static inline void 97write_16(addr_t P, Elf32_Word value) 98{ 99 // bits 16:29 100 *(Elf32_Half*)P = (Elf32_Half)value; 101} 102 103 104static inline bool 105write_16_check(addr_t P, Elf32_Word value) 106{ 107 // bits 15:0 108 if ((value & 0xffff0000) && (~value & 0xffff8000)) 109 return false; 110 *(Elf32_Half*)P = (Elf32_Half)value; 111 return true; 112} 113 114 115static inline bool 116write_8(addr_t P, Elf32_Word value) 117{ 118 // bits 7:0 119 *(uint8 *)P = (uint8)value; 120 return true; 121} 122 123 124static inline bool 125write_8_check(addr_t P, Elf32_Word value) 126{ 127 // bits 7:0 128 if ((value & 0xffffff00) && (~value & 0xffffff80)) 129 return false; 130 *(uint8 *)P = (uint8)value; 131 return true; 132} 133 134 135#ifdef _BOOT_MODE 136status_t 137boot_arch_elf_relocate_rela(struct preloaded_elf32_image *image, 138 struct Elf32_Rela *rel, int rel_len) 139#else 140int 141arch_elf_relocate_rela(struct elf_image_info *image, 142 struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len) 143#endif 144{ 145#warning IMPLEMENT arch_elf_relocate_rela 146 return B_ERROR; 147} 148 149