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.

hidemem.c 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2006 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. #include <realmode.h>
  18. #include <biosint.h>
  19. /**
  20. * A hidden region of Etherboot
  21. *
  22. * This represents a region that will be edited out of the system's
  23. * memory map.
  24. *
  25. * This structure is accessed by assembly code, so must not be
  26. * changed.
  27. */
  28. struct hidden_region {
  29. /* Physical start address */
  30. uint32_t start;
  31. /* Physical end address */
  32. uint32_t end;
  33. };
  34. /* Linker-defined symbols */
  35. extern char _text[];
  36. extern char _end[];
  37. /** Assembly routine in e820mangler.S */
  38. extern void int15();
  39. /** Vector for storing original INT 15 handler */
  40. extern struct segoff __text16 ( int15_vector );
  41. #define int15_vector __use_text16 ( int15_vector )
  42. /**
  43. * Unique IDs for hidden regions
  44. */
  45. enum {
  46. TEXT = 0,
  47. BASEMEM,
  48. };
  49. /**
  50. * List of hidden regions
  51. *
  52. * Must be terminated by a zero entry.
  53. */
  54. struct hidden_region __data16_array ( hidden_regions, [] ) = {
  55. [TEXT] = { 0, 0 },
  56. [BASEMEM] = { 0, ( 640 * 1024 ) },
  57. { 0, 0, } /* Terminator */
  58. };
  59. #define hidden_regions __use_data16 ( hidden_regions )
  60. /**
  61. * Hide Etherboot
  62. *
  63. * Installs an INT 15 handler to edit Etherboot out of the memory map
  64. * returned by the BIOS.
  65. */
  66. void hide_etherboot ( void ) {
  67. hidden_regions[TEXT].start = virt_to_phys ( _text );
  68. hidden_regions[TEXT].end = virt_to_phys ( _end );
  69. hidden_regions[BASEMEM].start = ( rm_cs << 4 );
  70. DBG ( "Hiding [%lx,%lx) and [%lx,%lx)\n",
  71. ( unsigned long ) hidden_regions[TEXT].start,
  72. ( unsigned long ) hidden_regions[TEXT].end,
  73. ( unsigned long ) hidden_regions[BASEMEM].start,
  74. ( unsigned long ) hidden_regions[BASEMEM].end );
  75. hook_bios_interrupt ( 0x15, ( unsigned int ) int15,
  76. &int15_vector );
  77. }
  78. /**
  79. * Unhide Etherboot
  80. *
  81. * Uninstalls the INT 15 handler installed by hide_etherboot(), if
  82. * possible.
  83. */
  84. void unhide_etherboot ( void ) {
  85. unhook_bios_interrupt ( 0x15, ( unsigned int ) int15,
  86. &int15_vector );
  87. }