source: grub-pc/trunk/fuentes/grub-core/kern/i386/qemu/mmap.c @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 3.0 KB
Line 
1/*
2 *  GRUB  --  GRand Unified Bootloader
3 *  Copyright (C) 2009  Free Software Foundation, Inc.
4 *
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.
9 *
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.
14 *
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/>.
17 */
18
19#include <grub/i386/memory.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>
26#include <grub/offsets.h>
27
28#define QEMU_CMOS_MEMSIZE_HIGH          0x35
29#define QEMU_CMOS_MEMSIZE_LOW           0x34
30
31#define QEMU_CMOS_MEMSIZE2_HIGH         0x31
32#define QEMU_CMOS_MEMSIZE2_LOW          0x30
33
34#define min(a,b)        ((a) > (b) ? (b) : (a))
35
36extern char _start[];
37extern char _end[];
38
39static grub_uint64_t mem_size, above_4g;
40
41void
42grub_machine_mmap_init (void)
43{
44  grub_uint8_t high, low, b, c, d;
45  grub_cmos_read (QEMU_CMOS_MEMSIZE_HIGH, &high);
46  grub_cmos_read (QEMU_CMOS_MEMSIZE_LOW, &low);
47  mem_size = ((grub_uint64_t) high) << 24
48    | ((grub_uint64_t) low) << 16;
49  if (mem_size > 0)
50    {
51      /* Don't ask... */
52      mem_size += (16 * 1024 * 1024);
53    }
54  else
55    {
56      grub_cmos_read (QEMU_CMOS_MEMSIZE2_HIGH, &high);
57      grub_cmos_read (QEMU_CMOS_MEMSIZE2_LOW, &low);
58      mem_size
59        = ((((grub_uint64_t) high) << 18) | (((grub_uint64_t) low) << 10))
60        + 1024 * 1024;
61    }
62
63  grub_cmos_read (0x5b, &b);
64  grub_cmos_read (0x5c, &c);
65  grub_cmos_read (0x5d, &d);
66  above_4g = (((grub_uint64_t) b) << 16)
67    | (((grub_uint64_t) c) << 24)
68    | (((grub_uint64_t) d) << 32);
69}
70
71grub_err_t
72grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
73{
74  if (hook (0x0,
75            (grub_addr_t) _start,
76            GRUB_MEMORY_AVAILABLE, hook_data))
77    return 1;
78
79  if (hook ((grub_addr_t) _end,
80           0xa0000 - (grub_addr_t) _end,
81           GRUB_MEMORY_AVAILABLE, hook_data))
82    return 1;
83
84  if (hook (GRUB_MEMORY_MACHINE_UPPER,
85            0x100000 - GRUB_MEMORY_MACHINE_UPPER,
86            GRUB_MEMORY_RESERVED, hook_data))
87    return 1;
88
89  /* Everything else is free.  */
90  if (hook (0x100000,
91            min (mem_size, (grub_uint32_t) -GRUB_BOOT_MACHINE_SIZE) - 0x100000,
92            GRUB_MEMORY_AVAILABLE, hook_data))
93    return 1;
94
95  /* Protect boot.img, which contains the gdt.  It is mapped at the top of memory
96     (it is also mapped below 0x100000, but we already reserved that area).  */
97  if (hook ((grub_uint32_t) -GRUB_BOOT_MACHINE_SIZE,
98            GRUB_BOOT_MACHINE_SIZE,
99            GRUB_MEMORY_RESERVED, hook_data))
100    return 1;
101
102  if (above_4g != 0 && hook (0x100000000ULL, above_4g,
103                             GRUB_MEMORY_AVAILABLE, hook_data))
104    return 1;
105
106  return 0;
107}
Note: See TracBrowser for help on using the repository browser.