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>
25 grub_mmap_get_lower (void)
27 grub_uint64_t lower
= 0;
29 auto int NESTED_FUNC_ATTR
hook (grub_uint64_t
, grub_uint64_t
, grub_uint32_t
);
30 int NESTED_FUNC_ATTR
hook (grub_uint64_t addr
, grub_uint64_t size
,
33 if (type
!= GRUB_MACHINE_MEMORY_AVAILABLE
)
40 grub_mmap_iterate (hook
);
47 grub_mmap_get_upper (void)
49 grub_uint64_t upper
= 0;
51 auto int NESTED_FUNC_ATTR
hook (grub_uint64_t
, grub_uint64_t
, grub_uint32_t
);
52 int NESTED_FUNC_ATTR
hook (grub_uint64_t addr
, grub_uint64_t size
,
55 if (type
!= GRUB_MACHINE_MEMORY_AVAILABLE
)
57 if (addr
<= 0x100000 && addr
+ size
> 0x100000)
58 upper
= addr
+ size
- 0x100000;
62 grub_mmap_iterate (hook
);
66 /* Count the continuous bytes after 64 MiB. */
68 grub_mmap_get_post64 (void)
70 grub_uint64_t post64
= 0;
72 auto int NESTED_FUNC_ATTR
hook (grub_uint64_t
, grub_uint64_t
, grub_uint32_t
);
73 int NESTED_FUNC_ATTR
hook (grub_uint64_t addr
, grub_uint64_t size
,
76 if (type
!= GRUB_MACHINE_MEMORY_AVAILABLE
)
78 if (addr
<= 0x4000000 && addr
+ size
> 0x4000000)
79 post64
= addr
+ size
- 0x4000000;
83 grub_mmap_iterate (hook
);