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