source: grub-pc/trunk/fuentes/grub-core/mmap/i386/uppermem.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: 2.3 KB
Line 
1/* Compute amount of lower and upper memory till the first hole. */
2/*
3 *  GRUB  --  GRand Unified Bootloader
4 *  Copyright (C) 2009  Free Software Foundation, Inc.
5 *
6 *  GRUB is free software: you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation, either version 3 of the License, or
9 *  (at your option) any later version.
10 *
11 *  GRUB is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <grub/memory.h>
21#include <grub/i386/memory.h>
22#include <grub/mm.h>
23#include <grub/misc.h>
24
25/* Helper for grub_mmap_get_lower.  */
26static int
27lower_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
28            void *data)
29{
30  grub_uint64_t *lower = data;
31
32  if (type != GRUB_MEMORY_AVAILABLE)
33    return 0;
34  if (addr == 0)
35    *lower = size;
36  return 0;
37}
38
39grub_uint64_t
40grub_mmap_get_lower (void)
41{
42  grub_uint64_t lower = 0;
43
44  grub_mmap_iterate (lower_hook, &lower);
45  if (lower > 0x100000)
46    lower =  0x100000;
47  return lower;
48}
49
50/* Helper for grub_mmap_get_upper.  */
51static int
52upper_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
53            void *data)
54{
55  grub_uint64_t *upper = data;
56
57  if (type != GRUB_MEMORY_AVAILABLE)
58    return 0;
59  if (addr <= 0x100000 && addr + size > 0x100000)
60    *upper = addr + size - 0x100000;
61  return 0;
62}
63
64grub_uint64_t
65grub_mmap_get_upper (void)
66{
67  grub_uint64_t upper = 0;
68
69  grub_mmap_iterate (upper_hook, &upper);
70  return upper;
71}
72
73/* Helper for grub_mmap_get_post64.  */
74static int
75post64_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
76             void *data)
77{
78  grub_uint64_t *post64 = data;
79  if (type != GRUB_MEMORY_AVAILABLE)
80    return 0;
81  if (addr <= 0x4000000 && addr + size > 0x4000000)
82    *post64 = addr + size - 0x4000000;
83  return 0;
84}
85
86/* Count the continuous bytes after 64 MiB. */
87grub_uint64_t
88grub_mmap_get_post64 (void)
89{
90  grub_uint64_t post64 = 0;
91
92  grub_mmap_iterate (post64_hook, &post64);
93  return post64;
94}
Note: See TracBrowser for help on using the repository browser.