iPXE
fakee820.c
Go to the documentation of this file.
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  * You can also choose to distribute this program under the terms of
19  * the Unmodified Binary Distribution Licence (as given in the file
20  * COPYING.UBDL), provided that you have satisfied its requirements.
21  */
22 
23 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
24 
25 #include <realmode.h>
26 #include <biosint.h>
27 
28 /** Assembly routine in inline asm */
29 extern void int15_fakee820();
30 
31 /** Original INT 15 handler */
32 static struct segoff __text16 ( real_int15_vector );
33 #define real_int15_vector __use_text16 ( real_int15_vector )
34 
35 /** An INT 15,e820 memory map entry */
36 struct e820_entry {
37  /** Start of region */
39  /** Length of region */
41  /** Type of region */
43 } __attribute__ (( packed ));
44 
45 #define E820_TYPE_RAM 1 /**< Normal memory */
46 #define E820_TYPE_RSVD 2 /**< Reserved and unavailable */
47 #define E820_TYPE_ACPI 3 /**< ACPI reclaim memory */
48 #define E820_TYPE_NVS 4 /**< ACPI NVS memory */
49 
50 /** Fake e820 map */
51 static struct e820_entry __text16_array ( e820map, [] ) __used = {
52  { 0x00000000ULL, ( 0x000a0000ULL - 0x00000000ULL ), E820_TYPE_RAM },
53  { 0x00100000ULL, ( 0xcfb50000ULL - 0x00100000ULL ), E820_TYPE_RAM },
54  { 0xcfb50000ULL, ( 0xcfb64000ULL - 0xcfb50000ULL ), E820_TYPE_RSVD },
55  { 0xcfb64000ULL, ( 0xcfb66000ULL - 0xcfb64000ULL ), E820_TYPE_RSVD },
56  { 0xcfb66000ULL, ( 0xcfb85c00ULL - 0xcfb66000ULL ), E820_TYPE_ACPI },
57  { 0xcfb85c00ULL, ( 0xd0000000ULL - 0xcfb85c00ULL ), E820_TYPE_RSVD },
58  { 0xe0000000ULL, ( 0xf0000000ULL - 0xe0000000ULL ), E820_TYPE_RSVD },
59  { 0xfe000000ULL, (0x100000000ULL - 0xfe000000ULL ), E820_TYPE_RSVD },
60  {0x100000000ULL, (0x230000000ULL -0x100000000ULL ), E820_TYPE_RAM },
61 };
62 #define e820map __use_text16 ( e820map )
63 
64 void fake_e820 ( void ) {
66  TEXT16_CODE ( "\nint15_fakee820:\n\t"
67  "pushfw\n\t"
68  "cmpl $0xe820, %%eax\n\t"
69  "jne 99f\n\t"
70  "cmpl $0x534d4150, %%edx\n\t"
71  "jne 99f\n\t"
72  "pushaw\n\t"
73  "movw %%sp, %%bp\n\t"
74  "andb $~0x01, 22(%%bp)\n\t" /* Clear return CF */
75  "leaw e820map(%%bx), %%si\n\t"
76  "cs rep movsb\n\t"
77  "popaw\n\t"
78  "movl %%edx, %%eax\n\t"
79  "addl $20, %%ebx\n\t"
80  "cmpl %0, %%ebx\n\t"
81  "jne 1f\n\t"
82  "xorl %%ebx,%%ebx\n\t"
83  "\n1:\n\t"
84  "popfw\n\t"
85  "iret\n\t"
86  "\n99:\n\t"
87  "popfw\n\t"
88  "ljmp *%%cs:real_int15_vector\n\t" )
89  : : "i" ( sizeof ( e820map ) ) );
90 
93 }
94 
95 void unfake_e820 ( void ) {
98 }
#define E820_TYPE_ACPI
ACPI reclaim memory.
Definition: fakee820.c:47
#define e820map
Definition: fakee820.c:62
unsigned long long uint64_t
Definition: stdint.h:13
unsigned long intptr_t
Definition: stdint.h:21
static struct segoff __text16(real_int15_vector)
Original INT 15 handler.
#define real_int15_vector
Definition: fakee820.c:33
void hook_bios_interrupt(unsigned int interrupt, unsigned int handler, struct segoff *chain_vector)
Hook INT vector.
Definition: biosint.c:24
int unhook_bios_interrupt(unsigned int interrupt, unsigned int handler, struct segoff *chain_vector)
Unhook INT vector.
Definition: biosint.c:69
uint64_t start
Start of region.
Definition: fakee820.c:38
#define __used
Declare a function as used.
Definition: compiler.h:605
An INT 15,e820 memory map entry.
Definition: fakee820.c:36
uint64_t len
Length of region.
Definition: fakee820.c:40
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void int15_fakee820()
Assembly routine in inline asm.
unsigned int uint32_t
Definition: stdint.h:12
void fake_e820(void)
Definition: fakee820.c:64
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
static struct e820_entry __text16_array(e820map)
Fake e820 map.
Definition: fakee820.c:51
uint32_t type
Type of region.
Definition: fakee820.c:42
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
void unfake_e820(void)
Definition: fakee820.c:95
#define E820_TYPE_RAM
Normal memory.
Definition: fakee820.c:45
#define E820_TYPE_RSVD
Reserved and unavailable.
Definition: fakee820.c:46
struct e820_entry __attribute__((packed))
#define TEXT16_CODE(asm_code_str)
Definition: libkir.h:217