You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

osloader.c 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**************************************************************************
  2. OS loader
  3. Author: Markus Gutschke (gutschk@math.uni-muenster.de)
  4. Date: Sep/95
  5. Modifications: Ken Yap (for Etherboot/16)
  6. Doug Ambrisko (ELF and a.out support)
  7. Klaus Espenlaub (rewrote ELF and a.out (did it really work before?) support,
  8. added ELF Multiboot images). Someone should merge the ELF and a.out
  9. loaders, as most of the code is now identical. Maybe even NBI could be
  10. rewritten and merged into the generic loading framework. This should
  11. save quite a few bytes of code if you have selected more than one format.
  12. Ken Yap (Jan 2001)
  13. Added support for linear entry addresses in tagged images,
  14. which allows a more efficient protected mode call instead of
  15. going to real mode and back. Also means entry addresses > 1 MB can
  16. be called. Conditional on the LINEAR_EXEC_ADDR bit.
  17. Added support for Etherboot extension calls. Conditional on the
  18. TAGGED_PROGRAM_RETURNS bit. Implies LINEAR_EXEC_ADDR.
  19. Added support for non-MULTIBOOT ELF which also supports Etherboot
  20. extension calls. Conditional on the ELF_PROGRAM_RETURNS bit.
  21. **************************************************************************/
  22. /*
  23. * This program is free software; you can redistribute it and/or
  24. * modify it under the terms of the GNU General Public License as
  25. * published by the Free Software Foundation; either version 2, or (at
  26. * your option) any later version.
  27. */
  28. #include "io.h"
  29. #include "memsizes.h"
  30. /* Linker symbols */
  31. extern char _text[];
  32. extern char _end[];
  33. int prep_segment ( physaddr_t start, physaddr_t mid, physaddr_t end ) {
  34. unsigned fit, i;
  35. DBG ( "OSLOADER preparing segment [%lX,%lX)\n", start, end );
  36. if ( mid > end ) {
  37. DBG ( "OSLOADER got filesz > memsz\n" );
  38. return 0;
  39. }
  40. /* Check for overlap with Etherboot runtime image */
  41. if ( ( end > virt_to_phys ( _text ) ) &&
  42. ( start < virt_to_phys ( _end ) ) ) {
  43. DBG ( "OSLOADER got segment [%lX, %lX) "
  44. "overlapping etherboot [%lX, %lX)\n",
  45. start, end,
  46. virt_to_phys ( _text ), virt_to_phys ( _end ) );
  47. return 0;
  48. }
  49. /* Check that block fits entirely inside a single memory region */
  50. fit = 0;
  51. for ( i = 0 ; i < meminfo.map_count ; i++ ) {
  52. unsigned long long r_start, r_end;
  53. if (meminfo.map[i].type != E820_RAM)
  54. continue;
  55. r_start = meminfo.map[i].addr;
  56. r_end = r_start + meminfo.map[i].size;
  57. if ( ( start >= r_start ) && ( end <= r_end ) ) {
  58. fit = 1;
  59. break;
  60. }
  61. }
  62. if ( ! fit ) {
  63. DBG ( "OSLOADER got segment [%lX,%lX) "
  64. "which does not fit in any memory region\n",
  65. start, end );
  66. return 0;
  67. }
  68. /* Zero the bss */
  69. memset ( phys_to_virt ( mid ), 0, end - mid );
  70. return 1;
  71. }
  72. /*
  73. * Local variables:
  74. * c-basic-offset: 8
  75. * End:
  76. */