2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/machine/init.h>
20 #include <grub/machine/memory.h>
21 #include <grub/machine/boot.h>
22 #include <grub/types.h>
24 #include <grub/misc.h>
25 #include <grub/cmos.h>
27 #define QEMU_CMOS_MEMSIZE_HIGH 0x35
28 #define QEMU_CMOS_MEMSIZE_LOW 0x34
30 #define min(a,b) ((a) > (b) ? (b) : (a))
35 grub_size_t grub_lower_mem
, grub_upper_mem
;
36 grub_uint64_t mem_size
;
39 grub_machine_mmap_init ()
41 mem_size
= grub_cmos_read (QEMU_CMOS_MEMSIZE_HIGH
) << 24 | grub_cmos_read (QEMU_CMOS_MEMSIZE_LOW
) << 16;
44 mem_size
+= (16 * 1024 * 1024);
48 grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook
) (grub_uint64_t
, grub_uint64_t
, grub_uint32_t
))
52 GRUB_MACHINE_MEMORY_AVAILABLE
))
55 if (hook (GRUB_MEMORY_MACHINE_UPPER
,
56 0x100000 - GRUB_MEMORY_MACHINE_UPPER
,
57 GRUB_MACHINE_MEMORY_RESERVED
))
60 /* Protect boot.img, which contains the gdt. It is mapped at the top of memory
61 (it is also mapped below 0x100000, but we already reserved that area). */
62 if (hook ((grub_uint32_t
) -GRUB_BOOT_MACHINE_SIZE
,
63 GRUB_BOOT_MACHINE_SIZE
,
64 GRUB_MACHINE_MEMORY_RESERVED
))
67 /* Everything else is free. */
69 min (mem_size
, (grub_uint32_t
) -GRUB_BOOT_MACHINE_SIZE
) - 0x100000,
70 GRUB_MACHINE_MEMORY_AVAILABLE
))