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 QEMU_CMOS_MEMSIZE2_HIGH 0x31
31
#define QEMU_CMOS_MEMSIZE2_LOW 0x30
33
#define min(a,b) ((a) > (b) ? (b) : (a))
38
static grub_uint64_t mem_size, above_4g;
41
grub_machine_mmap_init ()
43
mem_size = ((grub_uint64_t) grub_cmos_read (QEMU_CMOS_MEMSIZE_HIGH)) << 24
44
| ((grub_uint64_t) grub_cmos_read (QEMU_CMOS_MEMSIZE_LOW)) << 16;
48
mem_size += (16 * 1024 * 1024);
53
= ((((grub_uint64_t) grub_cmos_read (QEMU_CMOS_MEMSIZE2_HIGH)) << 18)
54
| ((grub_uint64_t) (grub_cmos_read (QEMU_CMOS_MEMSIZE2_LOW)) << 10))
58
above_4g = (((grub_uint64_t) grub_cmos_read (0x5b)) << 16)
59
| (((grub_uint64_t) grub_cmos_read (0x5c)) << 24)
60
| (((grub_uint64_t) grub_cmos_read (0x5d)) << 32);
64
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
68
GRUB_MACHINE_MEMORY_AVAILABLE))
71
if (hook (GRUB_MEMORY_MACHINE_UPPER,
72
0x100000 - GRUB_MEMORY_MACHINE_UPPER,
73
GRUB_MACHINE_MEMORY_RESERVED))
76
/* Everything else is free. */
78
min (mem_size, (grub_uint32_t) -GRUB_BOOT_MACHINE_SIZE) - 0x100000,
79
GRUB_MACHINE_MEMORY_AVAILABLE))
82
/* Protect boot.img, which contains the gdt. It is mapped at the top of memory
83
(it is also mapped below 0x100000, but we already reserved that area). */
84
if (hook ((grub_uint32_t) -GRUB_BOOT_MACHINE_SIZE,
85
GRUB_BOOT_MACHINE_SIZE,
86
GRUB_MACHINE_MEMORY_RESERVED))
89
if (above_4g != 0 && hook (0x100000000ULL, above_4g,
90
GRUB_MACHINE_MEMORY_AVAILABLE))