Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

elf.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "etherboot.h"
  2. #include "elf.h"
  3. #define NAME "Etherboot"
  4. #if defined(PCBIOS)
  5. #define FIRMWARE "PCBIOS"
  6. #endif
  7. #if defined(LINUXBIOS)
  8. #define FIRMWARE "LinuxBIOS"
  9. #endif
  10. #if !defined(FIRMWARE)
  11. #error "No BIOS selected"
  12. #endif
  13. #define SZ(X) ((sizeof(X)+3) & ~3)
  14. #define CP(D,S) (memcpy(&(D), &(S), sizeof(S)))
  15. struct elf_notes {
  16. /* The note header */
  17. struct Elf_Bhdr hdr;
  18. /* First the Fixed sized entries that must be well aligned */
  19. /* Pointer to bootp data */
  20. Elf_Nhdr nf1;
  21. char nf1_name[SZ(EB_PARAM_NOTE)];
  22. uint32_t nf1_bootp_data;
  23. /* Pointer to ELF header */
  24. Elf_Nhdr nf2;
  25. char nf2_name[SZ(EB_PARAM_NOTE)];
  26. uint32_t nf2_header;
  27. /* A copy of the i386 memory map */
  28. Elf_Nhdr nf3;
  29. char nf3_name[SZ(EB_PARAM_NOTE)];
  30. struct meminfo nf3_meminfo;
  31. /* Then the variable sized data string data where alignment does not matter */
  32. /* The bootloader name */
  33. Elf_Nhdr nv1;
  34. char nv1_desc[SZ(NAME)];
  35. /* The bootloader version */
  36. Elf_Nhdr nv2;
  37. char nv2_desc[SZ(VERSION)];
  38. /* The firmware type */
  39. Elf_Nhdr nv3;
  40. char nv3_desc[SZ(FIRMWARE)];
  41. /* Name of the loaded image */
  42. Elf_Nhdr nv4;
  43. char nv4_loaded_image[128];
  44. /* An empty command line */
  45. Elf_Nhdr nv5;
  46. char nv5_cmdline[SZ("")];
  47. };
  48. #define ELF_NOTE_COUNT (3 + 5)
  49. static struct elf_notes notes;
  50. struct Elf_Bhdr *prepare_boot_params(void *header)
  51. {
  52. memset(&notes, 0, sizeof(notes));
  53. notes.hdr.b_signature = ELF_BHDR_MAGIC;
  54. notes.hdr.b_size = sizeof(notes);
  55. notes.hdr.b_checksum = 0;
  56. notes.hdr.b_records = ELF_NOTE_COUNT;
  57. /* Initialize the fixed length entries. */
  58. notes.nf1.n_namesz = sizeof(EB_PARAM_NOTE);
  59. notes.nf1.n_descsz = sizeof(notes.nf1_bootp_data);
  60. notes.nf1.n_type = EB_BOOTP_DATA;
  61. CP(notes.nf1_name, EB_PARAM_NOTE);
  62. notes.nf1_bootp_data = virt_to_phys(BOOTP_DATA_ADDR);
  63. notes.nf2.n_namesz = sizeof(EB_PARAM_NOTE);
  64. notes.nf2.n_descsz = sizeof(notes.nf2_header);
  65. notes.nf2.n_type = EB_HEADER;
  66. CP(notes.nf2_name, EB_PARAM_NOTE);
  67. notes.nf2_header = virt_to_phys(header);
  68. notes.nf3.n_namesz = sizeof(EB_PARAM_NOTE);
  69. notes.nf3.n_descsz = sizeof(notes.nf3_meminfo);
  70. notes.nf3.n_type = EB_I386_MEMMAP;
  71. CP(notes.nf3_name, EB_PARAM_NOTE);
  72. memcpy(&notes.nf3_meminfo, &meminfo, sizeof(meminfo));
  73. /* Initialize the variable length entries */
  74. notes.nv1.n_namesz = 0;
  75. notes.nv1.n_descsz = sizeof(NAME);
  76. notes.nv1.n_type = EBN_BOOTLOADER_NAME;
  77. CP(notes.nv1_desc, NAME);
  78. notes.nv2.n_namesz = 0;
  79. notes.nv2.n_descsz = sizeof(VERSION);
  80. notes.nv2.n_type = EBN_BOOTLOADER_VERSION;
  81. CP(notes.nv2_desc, VERSION);
  82. notes.nv3.n_namesz = 0;
  83. notes.nv3.n_descsz = sizeof(FIRMWARE);
  84. notes.nv3.n_type = EBN_FIRMWARE_TYPE;
  85. CP(notes.nv3_desc, FIRMWARE);
  86. /* Attempt to pass the name of the loaded image */
  87. notes.nv4.n_namesz = 0;
  88. notes.nv4.n_descsz = sizeof(notes.nv4_loaded_image);
  89. notes.nv4.n_type = EBN_LOADED_IMAGE;
  90. memcpy(&notes.nv4_loaded_image, KERNEL_BUF, sizeof(notes.nv4_loaded_image));
  91. /* Pass an empty command line for now */
  92. notes.nv5.n_namesz = 0;
  93. notes.nv5.n_descsz = sizeof("");
  94. notes.nv5.n_type = EBN_COMMAND_LINE;
  95. CP(notes.nv5_cmdline, "");
  96. notes.hdr.b_checksum = ipchksum(&notes, sizeof(notes));
  97. /* Like UDP invert a 0 checksum to show that a checksum is present */
  98. if (notes.hdr.b_checksum == 0) {
  99. notes.hdr.b_checksum = 0xffff;
  100. }
  101. return &notes.hdr;
  102. }
  103. int elf_start(unsigned long machine __unused_i386, unsigned long entry, unsigned long params)
  104. {
  105. #if defined(CONFIG_X86_64)
  106. if (machine == EM_X86_64) {
  107. return xstart_lm(entry, params);
  108. }
  109. #endif
  110. return xstart32(entry, params);
  111. }