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.

fakee820.c 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  2. *
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU General Public License as
  5. * published by the Free Software Foundation; either version 2 of the
  6. * License, or any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <realmode.h>
  20. #include <biosint.h>
  21. /** Assembly routine in inline asm */
  22. extern void int15_fakee820();
  23. /** Original INT 15 handler */
  24. static struct segoff __text16 ( real_int15_vector );
  25. #define real_int15_vector __use_text16 ( real_int15_vector )
  26. /** An INT 15,e820 memory map entry */
  27. struct e820_entry {
  28. /** Start of region */
  29. uint64_t start;
  30. /** Length of region */
  31. uint64_t len;
  32. /** Type of region */
  33. uint32_t type;
  34. } __attribute__ (( packed ));
  35. #define E820_TYPE_RAM 1 /**< Normal memory */
  36. #define E820_TYPE_RSVD 2 /**< Reserved and unavailable */
  37. #define E820_TYPE_ACPI 3 /**< ACPI reclaim memory */
  38. #define E820_TYPE_NVS 4 /**< ACPI NVS memory */
  39. /** Fake e820 map */
  40. static struct e820_entry __text16_array ( e820map, [] ) __used = {
  41. { 0x00000000ULL, ( 0x000a0000ULL - 0x00000000ULL ), E820_TYPE_RAM },
  42. { 0x00100000ULL, ( 0xcfb50000ULL - 0x00100000ULL ), E820_TYPE_RAM },
  43. { 0xcfb50000ULL, ( 0xcfb64000ULL - 0xcfb50000ULL ), E820_TYPE_RSVD },
  44. { 0xcfb64000ULL, ( 0xcfb66000ULL - 0xcfb64000ULL ), E820_TYPE_RSVD },
  45. { 0xcfb66000ULL, ( 0xcfb85c00ULL - 0xcfb66000ULL ), E820_TYPE_ACPI },
  46. { 0xcfb85c00ULL, ( 0xd0000000ULL - 0xcfb85c00ULL ), E820_TYPE_RSVD },
  47. { 0xe0000000ULL, ( 0xf0000000ULL - 0xe0000000ULL ), E820_TYPE_RSVD },
  48. { 0xfe000000ULL, (0x100000000ULL - 0xfe000000ULL ), E820_TYPE_RSVD },
  49. {0x100000000ULL, (0x230000000ULL -0x100000000ULL ), E820_TYPE_RAM },
  50. };
  51. #define e820map __use_text16 ( e820map )
  52. void fake_e820 ( void ) {
  53. __asm__ __volatile__ (
  54. TEXT16_CODE ( "\nint15_fakee820:\n\t"
  55. "pushfw\n\t"
  56. "cmpl $0xe820, %%eax\n\t"
  57. "jne 99f\n\t"
  58. "cmpl $0x534d4150, %%edx\n\t"
  59. "jne 99f\n\t"
  60. "pushaw\n\t"
  61. "movw %%sp, %%bp\n\t"
  62. "andb $~0x01, 22(%%bp)\n\t" /* Clear return CF */
  63. "leaw e820map(%%bx), %%si\n\t"
  64. "cs rep movsb\n\t"
  65. "popaw\n\t"
  66. "movl %%edx, %%eax\n\t"
  67. "addl $20, %%ebx\n\t"
  68. "cmpl %0, %%ebx\n\t"
  69. "jne 1f\n\t"
  70. "xorl %%ebx,%%ebx\n\t"
  71. "\n1:\n\t"
  72. "popfw\n\t"
  73. "iret\n\t"
  74. "\n99:\n\t"
  75. "popfw\n\t"
  76. "ljmp *%%cs:real_int15_vector\n\t" )
  77. : : "i" ( sizeof ( e820map ) ) );
  78. hook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
  79. &real_int15_vector );
  80. }
  81. void unfake_e820 ( void ) {
  82. unhook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
  83. &real_int15_vector );
  84. }