fakee820.c

Go to the documentation of this file.
00001 /* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
00002  *
00003  * This program is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU General Public License as
00005  * published by the Free Software Foundation; either version 2 of the
00006  * License, or any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 FILE_LICENCE ( GPL2_OR_LATER );
00019 
00020 #include <realmode.h>
00021 #include <biosint.h>
00022 
00023 /** Assembly routine in inline asm */
00024 extern void int15_fakee820();
00025 
00026 /** Original INT 15 handler */
00027 static struct segoff __text16 ( real_int15_vector );
00028 #define real_int15_vector __use_text16 ( real_int15_vector )
00029 
00030 /** An INT 15,e820 memory map entry */
00031 struct e820_entry {
00032         /** Start of region */
00033         uint64_t start;
00034         /** Length of region */
00035         uint64_t len;
00036         /** Type of region */
00037         uint32_t type;
00038 } __attribute__ (( packed ));
00039 
00040 #define E820_TYPE_RAM           1 /**< Normal memory */
00041 #define E820_TYPE_RSVD          2 /**< Reserved and unavailable */
00042 #define E820_TYPE_ACPI          3 /**< ACPI reclaim memory */
00043 #define E820_TYPE_NVS           4 /**< ACPI NVS memory */
00044 
00045 /** Fake e820 map */
00046 static struct e820_entry __text16_array ( e820map, [] ) __used = {
00047         { 0x00000000ULL, ( 0x000a0000ULL - 0x00000000ULL ), E820_TYPE_RAM },
00048         { 0x00100000ULL, ( 0xcfb50000ULL - 0x00100000ULL ), E820_TYPE_RAM },
00049         { 0xcfb50000ULL, ( 0xcfb64000ULL - 0xcfb50000ULL ), E820_TYPE_RSVD },
00050         { 0xcfb64000ULL, ( 0xcfb66000ULL - 0xcfb64000ULL ), E820_TYPE_RSVD },
00051         { 0xcfb66000ULL, ( 0xcfb85c00ULL - 0xcfb66000ULL ), E820_TYPE_ACPI },
00052         { 0xcfb85c00ULL, ( 0xd0000000ULL - 0xcfb85c00ULL ), E820_TYPE_RSVD },
00053         { 0xe0000000ULL, ( 0xf0000000ULL - 0xe0000000ULL ), E820_TYPE_RSVD },
00054         { 0xfe000000ULL, (0x100000000ULL - 0xfe000000ULL ), E820_TYPE_RSVD },
00055         {0x100000000ULL, (0x230000000ULL -0x100000000ULL ), E820_TYPE_RAM },
00056 };
00057 #define e820map __use_text16 ( e820map )
00058 
00059 void fake_e820 ( void ) {
00060         __asm__ __volatile__ (
00061                 TEXT16_CODE ( "\nint15_fakee820:\n\t"
00062                               "pushfw\n\t"
00063                               "cmpl $0xe820, %%eax\n\t"
00064                               "jne 99f\n\t"
00065                               "cmpl $0x534d4150, %%edx\n\t"
00066                               "jne 99f\n\t"
00067                               "pushaw\n\t"
00068                               "movw %%sp, %%bp\n\t"
00069                               "andb $~0x01, 22(%%bp)\n\t" /* Clear return CF */
00070                               "leaw e820map(%%bx), %%si\n\t"
00071                               "cs rep movsb\n\t"
00072                               "popaw\n\t"
00073                               "movl %%edx, %%eax\n\t"
00074                               "addl $20, %%ebx\n\t"
00075                               "cmpl %0, %%ebx\n\t"
00076                               "jne 1f\n\t"
00077                               "xorl %%ebx,%%ebx\n\t"
00078                               "\n1:\n\t"
00079                               "popfw\n\t"
00080                               "iret\n\t"
00081                               "\n99:\n\t"
00082                               "popfw\n\t"
00083                               "ljmp *%%cs:real_int15_vector\n\t" )
00084                 : : "i" ( sizeof ( e820map ) ) );
00085 
00086         hook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
00087                               &real_int15_vector );
00088 }
00089 
00090 void unfake_e820 ( void ) {
00091         unhook_bios_interrupt ( 0x15, ( unsigned int ) int15_fakee820,
00092                                 &real_int15_vector );
00093 }

Generated on Tue Apr 6 20:00:49 2010 for gPXE by  doxygen 1.5.7.1