1 /* Compute amount of lower and upper memory till the first hole. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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/>.
20 #include <grub/memory.h>
22 #include <grub/misc.h>
23 #include <grub/machine/memory.h>
26 grub_mmap_get_lower (void)
28 grub_uint64_t lower
= 0;
30 auto int NESTED_FUNC_ATTR
hook (grub_uint64_t
, grub_uint64_t
,
32 int NESTED_FUNC_ATTR
hook (grub_uint64_t addr
, grub_uint64_t size
,
33 grub_memory_type_t type
)
35 if (type
!= GRUB_MEMORY_AVAILABLE
)
42 grub_mmap_iterate (hook
);
43 if (lower
> GRUB_ARCH_LOWMEMMAXSIZE
)
44 lower
= GRUB_ARCH_LOWMEMMAXSIZE
;
49 grub_mmap_get_upper (void)
51 grub_uint64_t upper
= 0;
53 auto int NESTED_FUNC_ATTR
hook (grub_uint64_t
, grub_uint64_t
,
55 int NESTED_FUNC_ATTR
hook (grub_uint64_t addr
, grub_uint64_t size
,
56 grub_memory_type_t type
)
58 if (type
!= GRUB_MEMORY_AVAILABLE
)
60 if (addr
<= GRUB_ARCH_HIGHMEMPSTART
&& addr
+ size
61 > GRUB_ARCH_HIGHMEMPSTART
)
62 upper
= addr
+ size
- GRUB_ARCH_HIGHMEMPSTART
;
66 grub_mmap_iterate (hook
);