GRUB-1.98 changes
[grub2/jjazz.git] / kern / i386 / qemu / mmap.c
blobc7fc4f45e936bcadc7e18b08c494cdd8f4139bc3
1 /*
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>
23 #include <grub/err.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))
32 extern char _start[];
33 extern char _end[];
35 grub_size_t grub_lower_mem, grub_upper_mem;
36 grub_uint64_t mem_size;
38 void
39 grub_machine_mmap_init ()
41 mem_size = grub_cmos_read (QEMU_CMOS_MEMSIZE_HIGH) << 24 | grub_cmos_read (QEMU_CMOS_MEMSIZE_LOW) << 16;
43 /* Don't ask... */
44 mem_size += (16 * 1024 * 1024);
47 grub_err_t
48 grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
50 if (hook (0x0,
51 (grub_addr_t) _start,
52 GRUB_MACHINE_MEMORY_AVAILABLE))
53 return 1;
55 if (hook (GRUB_MEMORY_MACHINE_UPPER,
56 0x100000 - GRUB_MEMORY_MACHINE_UPPER,
57 GRUB_MACHINE_MEMORY_RESERVED))
58 return 1;
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))
65 return 1;
67 /* Everything else is free. */
68 if (hook (0x100000,
69 min (mem_size, (grub_uint32_t) -GRUB_BOOT_MACHINE_SIZE) - 0x100000,
70 GRUB_MACHINE_MEMORY_AVAILABLE))
71 return 1;
73 return 0;