remove all trailing whitespace
[grub2/phcoder/solaris.git] / mmap / i386 / uppermem.c
blobcd1a452393ccb21c7c34e525110eba9f574c22b5
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.
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>
21 #include <grub/mm.h>
22 #include <grub/misc.h>
24 grub_uint64_t
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,
31 grub_uint32_t type)
33 if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
34 return 0;
35 if (addr == 0)
36 lower = size;
37 return 0;
40 grub_mmap_iterate (hook);
41 if (lower > 0x100000)
42 lower = 0x100000;
43 return lower;
46 grub_uint64_t
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,
53 grub_uint32_t type)
55 if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
56 return 0;
57 if (addr <= 0x100000 && addr + size > 0x100000)
58 upper = addr + size - 0x100000;
59 return 0;
62 grub_mmap_iterate (hook);
63 return upper;
66 /* Count the continuous bytes after 64 MiB. */
67 grub_uint64_t
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,
74 grub_uint32_t type)
76 if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
77 return 0;
78 if (addr <= 0x4000000 && addr + size > 0x4000000)
79 post64 = addr + size - 0x4000000;
80 return 0;
83 grub_mmap_iterate (hook);
84 return post64;