Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

fakee820.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. FILE_LICENCE ( GPL2_OR_LATER );
  18. #include <realmode.h>
  19. #include <biosint.h>
  20. /** Assembly routine in inline asm */
  21. extern void int15_fakee820();
  22. /** Original INT 15 handler */
  23. static struct segoff __text16 ( real_int15_vector );
  24. #define real_int15_vector __use_text16 ( real_int15_vector )
  25. /** An INT 15,e820 memory map entry */
  26. struct e820_entry {
  27. /** Start of region */
  28. uint64_t start;
  29. /** Length of region */
  30. uint64_t len;
  31. /** Type of region */
  32. uint32_t type;
  33. } __attribute__ (( packed ));
  34. #define E820_TYPE_RAM 1 /**< Normal memory */
  35. #define E820_TYPE_RSVD 2 /**< Reserved and unavailable */
  36. #define E820_TYPE_ACPI 3 /**< ACPI reclaim memory */
  37. #define E820_TYPE_NVS 4 /**< ACPI NVS memory */
  38. /** Fake e820 map */
  39. static struct e820_entry __text16_array ( e820map, [] ) __used = {
  40. { 0x00000000ULL, ( 0x000a0000ULL - 0x00000000ULL ), E820_TYPE_RAM },
  41. { 0x00100000ULL, ( 0xcfb50000ULL - 0x00100000ULL ), E820_TYPE_RAM },
  42. { 0xcfb50000ULL, ( 0xcfb64000ULL - 0xcfb50000ULL ), E820_TYPE_RSVD },
  43. { 0xcfb64000ULL, ( 0xcfb66000ULL - 0xcfb64000ULL ), E820_TYPE_RSVD },
  44. { 0xcfb66000ULL, ( 0xcfb85c00ULL - 0xcfb66000ULL ), E820_TYPE_ACPI },
  45. { 0xcfb85c00ULL, ( 0xd0000000ULL - 0xcfb85c00ULL ), E820_TYPE_RSVD },
  46. { 0xe0000000ULL, ( 0xf0000000ULL - 0xe0000000ULL ), E820_TYPE_RSVD },
  47. { 0xfe000000ULL, (0x100000000ULL - 0xfe000000ULL ), E820_TYPE_RSVD },
  48. {0x100000000ULL, (0x230000000ULL -0x100000000ULL ), E820_TYPE_RAM },
  49. };
  50. #define e820map __use_text16 ( e820map )
  51. void fake_e820 ( void ) {
  52. __asm__ __volatile__ (
  53. TEXT16_CODE ( "\nint15_fakee820:\n\t"
  54. "pushfw\n\t"
  55. "cmpl $0xe820, %%eax\n\t"
  56. "jne 99f\n\t"
  57. "cmpl $0x534d4150, %%edx\n\t"
  58. "jne 99f\n\t"
  59. "pushaw\n\t"
  60. "movw %%sp, %%bp\n\t"
  61. "andb $~0x01, 22(%%bp)\n\t" /* Clear return CF */
  62. "leaw e820map(%%bx), %%si\n\t"
  63. "cs rep movsb\n\t"
  64. "popaw\n\t"
  65. "movl %%edx, %%eax\n\t"
  66. "addl $20, %%ebx\n\t"
  67. "cmpl %0, %%ebx\n\t"
  68. "jne 1f\n\t"
  69. "xorl %%ebx,%%ebx\n\t"
  70. "\n1:\n\t"
  71. "popfw\n\t"
  72. "iret\n\t"
  73. "\n99:\n\t"
  74. "popfw\n\t"
  75. "ljmp *%%cs:real_int15_vector\n\t" )
  76. : : "i" ( sizeof ( e820map ) ) );
  77. hook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
  78. &real_int15_vector );
  79. }
  80. void unfake_e820 ( void ) {
  81. unhook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
  82. &real_int15_vector );
  83. }