Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /**
  19. * @file
  20. *
  21. * Executable image segments
  22. *
  23. */
  24. #include <errno.h>
  25. #include <gpxe/uaccess.h>
  26. #include <gpxe/memmap.h>
  27. #include <gpxe/segment.h>
  28. /**
  29. * Prepare segment for loading
  30. *
  31. * @v segment Segment start
  32. * @v filesz Size of the "allocated bytes" portion of the segment
  33. * @v memsz Size of the segment
  34. * @ret rc Return status code
  35. */
  36. int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ) {
  37. struct memory_map memmap;
  38. physaddr_t start = user_to_phys ( segment, 0 );
  39. physaddr_t mid = user_to_phys ( segment, filesz );
  40. physaddr_t end = user_to_phys ( segment, memsz );
  41. unsigned int i;
  42. /* Sanity check */
  43. if ( filesz > memsz ) {
  44. DBG ( "Insane segment [%lx,%lx,%lx)\n", start, mid, end );
  45. return -EINVAL;
  46. }
  47. /* Get a fresh memory map. This allows us to automatically
  48. * avoid treading on any regions that Etherboot is currently
  49. * editing out of the memory map.
  50. */
  51. get_memmap ( &memmap );
  52. /* Look for a suitable memory region */
  53. for ( i = 0 ; i < memmap.count ; i++ ) {
  54. if ( ( start >= memmap.regions[i].start ) &&
  55. ( end <= memmap.regions[i].end ) ) {
  56. /* Found valid region: zero bss and return */
  57. memset_user ( segment, filesz, 0, ( memsz - filesz ) );
  58. return 0;
  59. }
  60. }
  61. /* No suitable memory region found */
  62. DBG ( "Segment [%lx,%lx,%lx) does not fit into available memory\n",
  63. start, mid, end );
  64. return -ERANGE;
  65. }