/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #ifndef VAS_EBOOT_RELOCATOR_HEADER #define VAS_EBOOT_RELOCATOR_HEADER 1 #include #include #include #include struct VasEBoot_relocator; struct VasEBoot_relocator_chunk; typedef const struct VasEBoot_relocator_chunk *VasEBoot_relocator_chunk_t; struct VasEBoot_relocator *VasEBoot_relocator_new (void); VasEBoot_err_t VasEBoot_relocator_alloc_chunk_addr (struct VasEBoot_relocator *rel, VasEBoot_relocator_chunk_t *out, VasEBoot_phys_addr_t target, VasEBoot_size_t size); void * get_virtual_current_address (VasEBoot_relocator_chunk_t in); VasEBoot_phys_addr_t get_physical_target_address (VasEBoot_relocator_chunk_t in); VasEBoot_err_t VasEBoot_relocator_alloc_chunk_align (struct VasEBoot_relocator *rel, VasEBoot_relocator_chunk_t *out, VasEBoot_phys_addr_t min_addr, VasEBoot_phys_addr_t max_addr, VasEBoot_size_t size, VasEBoot_size_t align, int preference, int avoid_efi_boot_services); /* * Wrapper for VasEBoot_relocator_alloc_chunk_align() with purpose of * protecting against integer underflow. * * Compare to its callee, max_addr has different meaning here. * It covers entire chunk and not just start address of the chunk. */ static inline VasEBoot_err_t VasEBoot_relocator_alloc_chunk_align_safe (struct VasEBoot_relocator *rel, VasEBoot_relocator_chunk_t *out, VasEBoot_phys_addr_t min_addr, VasEBoot_phys_addr_t max_addr, VasEBoot_size_t size, VasEBoot_size_t align, int preference, int avoid_efi_boot_services) { /* Sanity check and ensure following equation (max_addr - size) is safe. */ if (max_addr < size || (max_addr - size) < min_addr) return VAS_EBOOT_ERR_OUT_OF_RANGE; return VasEBoot_relocator_alloc_chunk_align (rel, out, min_addr, max_addr - size, size, align, preference, avoid_efi_boot_services); } /* Top 32-bit address minus s bytes and plus 1 byte. */ #define UP_TO_TOP32(s) ((~(s) & 0xffffffff) + 1) #define VAS_EBOOT_RELOCATOR_PREFERENCE_NONE 0 #define VAS_EBOOT_RELOCATOR_PREFERENCE_LOW 1 #define VAS_EBOOT_RELOCATOR_PREFERENCE_HIGH 2 void VasEBoot_relocator_unload (struct VasEBoot_relocator *rel); #endif