3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
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.
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.
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.
28 BiosMemoryAcpiReclaim
,
35 ULONGLONG BaseAddress
;
39 } BIOS_MEMORY_MAP
, *PBIOS_MEMORY_MAP
;
42 #if defined(__i386__) || defined(_PPC_) || defined(_MIPS_) || defined(_ARM_)
44 #define MM_PAGE_SIZE 4096
45 #define MM_PAGE_MASK 0xFFF
46 #define MM_PAGE_SHIFT 12
48 #define MM_SIZE_TO_PAGES(a) \
49 ( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
51 #endif // defined __i386__ or _PPC_ or _MIPS_
55 #define MM_PAGE_SIZE 4096
56 #define MM_PAGE_MASK 0xFFF
57 #define MM_PAGE_SHIFT 12
59 #define MM_SIZE_TO_PAGES(a) \
60 ( ((a) >> MM_PAGE_SHIFT) + ((a) & MM_PAGE_MASK ? 1 : 0) )
64 // HEAP and STACK size
65 #define HEAP_PAGES 0x400
66 #define STACK_PAGES 0x00
71 TYPE_OF_MEMORY PageAllocated
; // Type of allocated memory (LoaderFree if this memory is free)
72 ULONG PageAllocationLength
; // Number of pages allocated (or zero if this isn't the first page in the chain)
73 } PAGE_LOOKUP_TABLE_ITEM
, *PPAGE_LOOKUP_TABLE_ITEM
;
77 // Define this to 1 if you want the entire contents
78 // of the memory allocation bitmap displayed
79 // when a chunk is allocated or freed
81 #define DUMP_MEM_MAP_ON_VERIFY 0
85 extern PVOID PageLookupTableAddress
;
86 extern ULONG TotalPagesInLookupTable
;
87 extern ULONG FreePagesInLookupTable
;
88 extern ULONG LastFreePageHint
;
91 PCSTR
MmGetSystemMemoryMapTypeString(MEMORY_TYPE Type
);
94 ULONG
MmGetPageNumberFromAddress(PVOID Address
); // Returns the page number that contains a linear address
95 ULONG
MmGetAddressablePageCountIncludingHoles(VOID
); // Returns the count of addressable pages from address zero including any memory holes and reserved memory regions
96 PVOID
MmFindLocationForPageLookupTable(ULONG TotalPageCount
); // Returns the address for a memory chunk big enough to hold the page lookup table (starts search from end of memory)
97 VOID
MmInitPageLookupTable(PVOID PageLookupTable
, ULONG TotalPageCount
); // Inits the page lookup table according to the memory types in the memory map
98 VOID
MmMarkPagesInLookupTable(PVOID PageLookupTable
, ULONG StartPage
, ULONG PageCount
, TYPE_OF_MEMORY PageAllocated
); // Marks the specified pages as allocated or free in the lookup table
99 VOID
MmAllocatePagesInLookupTable(PVOID PageLookupTable
, ULONG StartPage
, ULONG PageCount
, TYPE_OF_MEMORY MemoryType
); // Allocates the specified pages in the lookup table
100 ULONG
MmCountFreePagesInLookupTable(PVOID PageLookupTable
, ULONG TotalPageCount
); // Returns the number of free pages in the lookup table
101 ULONG
MmFindAvailablePages(PVOID PageLookupTable
, ULONG TotalPageCount
, ULONG PagesNeeded
, BOOLEAN FromEnd
); // Returns the page number of the first available page range from the beginning or end of memory
102 ULONG
MmFindAvailablePagesBeforePage(PVOID PageLookupTable
, ULONG TotalPageCount
, ULONG PagesNeeded
, ULONG LastPage
); // Returns the page number of the first available page range before the specified page
103 VOID
MmUpdateLastFreePageHint(PVOID PageLookupTable
, ULONG TotalPageCount
); // Sets the LastFreePageHint to the last usable page of memory
104 BOOLEAN
MmAreMemoryPagesAvailable(PVOID PageLookupTable
, ULONG TotalPageCount
, PVOID PageAddress
, ULONG PageCount
); // Returns TRUE if the specified pages of memory are available, otherwise FALSE
105 VOID
MmSetMemoryType(PVOID MemoryAddress
, ULONG MemorySize
, TYPE_OF_MEMORY NewType
); // Use with EXTREME caution!
107 ULONG
GetSystemMemorySize(VOID
); // Returns the amount of total memory in the system
108 PPAGE_LOOKUP_TABLE_ITEM
MmGetMemoryMap(ULONG
*NoEntries
); // Returns a pointer to the memory mapping table and a number of entries in it
111 //BOOLEAN MmInitializeMemoryManager(ULONG LowMemoryStart, ULONG LowMemoryLength);
112 BOOLEAN
MmInitializeMemoryManager(VOID
);
113 VOID
MmInitializeHeap(PVOID PageLookupTable
);
114 PVOID
MmAllocateMemory(ULONG MemorySize
);
115 PVOID
MmAllocateMemoryWithType(ULONG MemorySize
, TYPE_OF_MEMORY MemoryType
);
116 VOID
MmFreeMemory(PVOID MemoryPointer
);
117 PVOID
MmAllocateMemoryAtAddress(ULONG MemorySize
, PVOID DesiredAddress
, TYPE_OF_MEMORY MemoryType
);
118 PVOID
MmAllocateHighestMemoryBelowAddress(ULONG MemorySize
, PVOID DesiredAddress
, TYPE_OF_MEMORY MemoryType
);
120 PVOID
MmHeapAlloc(ULONG MemorySize
);
121 VOID
MmHeapFree(PVOID MemoryPointer
);
123 #endif // defined __MEMORY_H