scroll mode for very long start menus
[reactos.git] / freeldr / freeldr / mm / mem.h
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program 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 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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 this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21 #ifndef __MEM_H
22 #define __MEM_H
23
24
25 #ifdef __i386__
26
27 #define MM_PAGE_SIZE 4096
28
29 #endif // defined __i386__
30
31 typedef struct
32 {
33 U32 PageAllocated; // Zero = free, non-zero = allocated
34 U32 PageAllocationLength; // Number of pages allocated (or zero if this isn't the first page in the chain)
35 } PACKED PAGE_LOOKUP_TABLE_ITEM, *PPAGE_LOOKUP_TABLE_ITEM;
36
37 //
38 // Define this to 1 if you want the entire contents
39 // of the memory allocation bitmap displayed
40 // when a chunk is allocated or freed
41 //
42 #define DUMP_MEM_MAP_ON_VERIFY 0
43
44
45
46 extern PVOID PageLookupTableAddress;
47 extern U32 TotalPagesInLookupTable;
48 extern U32 FreePagesInLookupTable;
49 extern U32 LastFreePageHint;
50
51 #ifdef DEBUG
52 PUCHAR MmGetSystemMemoryMapTypeString(U32 Type);
53 #endif
54
55 U32 MmGetPageNumberFromAddress(PVOID Address); // Returns the page number that contains a linear address
56 PVOID MmGetEndAddressOfAnyMemory(PBIOS_MEMORY_MAP BiosMemoryMap, U32 MapCount); // Returns the last address of memory from the memory map
57 U32 MmGetAddressablePageCountIncludingHoles(PBIOS_MEMORY_MAP BiosMemoryMap, U32 MapCount); // Returns the count of addressable pages from address zero including any memory holes and reserved memory regions
58 PVOID MmFindLocationForPageLookupTable(PBIOS_MEMORY_MAP BiosMemoryMap, U32 MapCount); // Returns the address for a memory chunk big enough to hold the page lookup table (starts search from end of memory)
59 VOID MmSortBiosMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, U32 MapCount); // Sorts the BIOS_MEMORY_MAP array so the first element corresponds to the first address in memory
60 VOID MmInitPageLookupTable(PVOID PageLookupTable, U32 TotalPageCount, PBIOS_MEMORY_MAP BiosMemoryMap, U32 MapCount); // Inits the page lookup table according to the memory types in the memory map
61 VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, U32 StartPage, U32 PageCount, U32 PageAllocated); // Marks the specified pages as allocated or free in the lookup table
62 VOID MmAllocatePagesInLookupTable(PVOID PageLookupTable, U32 StartPage, U32 PageCount); // Allocates the specified pages in the lookup table
63 U32 MmCountFreePagesInLookupTable(PVOID PageLookupTable, U32 TotalPageCount); // Returns the number of free pages in the lookup table
64 U32 MmFindAvailablePagesFromEnd(PVOID PageLookupTable, U32 TotalPageCount, U32 PagesNeeded); // Returns the page number of the first available page range from the end of memory
65 U32 MmFindAvailablePagesBeforePage(PVOID PageLookupTable, U32 TotalPageCount, U32 PagesNeeded, U32 LastPage); // Returns the page number of the first available page range before the specified page
66 VOID MmFixupSystemMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, U32* MapCount); // Removes entries in the memory map that describe memory above 4G
67 VOID MmUpdateLastFreePageHint(PVOID PageLookupTable, U32 TotalPageCount); // Sets the LastFreePageHint to the last usable page of memory
68 BOOL MmAreMemoryPagesAvailable(PVOID PageLookupTable, U32 TotalPageCount, PVOID PageAddress, U32 PageCount); // Returns TRUE if the specified pages of memory are available, otherwise FALSE
69
70 #endif // defined __MEM_H