2 * PROJECT: ReactOS Boot Loader (FreeLDR)
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: boot/freeldr/freeldr/arcemul/mm.c
5 * PURPOSE: Routines for ARC Memory Management
6 * PROGRAMMERS: Hervé Poussineau <hpoussin@reactos.org>
9 /* INCLUDES *******************************************************************/
15 /* FUNCTIONS ******************************************************************/
21 BOOLEAN GeneratedDescriptor
;
22 } MEMORY_DESCRIPTOR_INT
;
23 static const MEMORY_DESCRIPTOR_INT MemoryDescriptors
[] =
25 #if defined (__i386__) || defined (_M_AMD64)
26 { { MemoryFirmwarePermanent
, 0x00, 1 }, 0, }, // realmode int vectors
27 { { MemoryFirmwareTemporary
, 0x01, 7 }, 1, }, // freeldr stack + cmdline
28 { { MemoryLoadedProgram
, 0x08, 0x70 }, 2, }, // freeldr image (roughly max. 0x64 pages)
29 { { MemorySpecialMemory
, 0x78, 8 }, 3, }, // prot mode stack. BIOSCALLBUFFER
30 { { MemoryFirmwareTemporary
, 0x80, 0x10 }, 4, }, // File system read buffer. FILESYSBUFFER
31 { { MemoryFirmwareTemporary
, 0x90, 0x10 }, 5, }, // Disk read buffer for int 13h. DISKREADBUFFER
32 { { MemoryFirmwarePermanent
, 0xA0, 0x60 }, 6, }, // ROM / Video
33 #elif __arm__ // This needs to be done per-platform specific way
37 const MEMORY_DESCRIPTOR
*
38 ArcGetMemoryDescriptor(const MEMORY_DESCRIPTOR
* Current
)
40 MEMORY_DESCRIPTOR_INT
* CurrentDescriptor
;
41 BIOS_MEMORY_MAP BiosMemoryMap
[32];
42 static ULONG BiosMemoryMapEntryCount
;
43 static MEMORY_DESCRIPTOR_INT BiosMemoryDescriptors
[32];
44 static BOOLEAN MemoryMapInitialized
= FALSE
;
48 // Check if it is the first time we're called
50 if (!MemoryMapInitialized
)
53 // Get the machine generated memory map
55 RtlZeroMemory(BiosMemoryMap
, sizeof(BIOS_MEMORY_MAP
) * 32);
56 BiosMemoryMapEntryCount
= MachVtbl
.GetMemoryMap(BiosMemoryMap
,
57 sizeof(BiosMemoryMap
) /
58 sizeof(BIOS_MEMORY_MAP
));
61 // Copy the entries to our structure
63 for (i
= 0, j
= 0; i
< BiosMemoryMapEntryCount
; i
++)
66 // Is it suitable memory?
68 if (BiosMemoryMap
[i
].Type
!= BiosMemoryUsable
)
71 // No. Process next descriptor
77 // Copy this memory descriptor
79 BiosMemoryDescriptors
[j
].m
.MemoryType
= MemoryFree
;
80 BiosMemoryDescriptors
[j
].m
.BasePage
= (ULONG
)(BiosMemoryMap
[i
].BaseAddress
/ MM_PAGE_SIZE
);
81 BiosMemoryDescriptors
[j
].m
.PageCount
= (ULONG
)(BiosMemoryMap
[i
].Length
/ MM_PAGE_SIZE
);
82 BiosMemoryDescriptors
[j
].Index
= j
;
83 BiosMemoryDescriptors
[j
].GeneratedDescriptor
= TRUE
;
88 // Remember how much descriptors we found
90 BiosMemoryMapEntryCount
= j
;
93 // Mark memory map as already retrieved and initialized
95 MemoryMapInitialized
= TRUE
;
98 CurrentDescriptor
= CONTAINING_RECORD(Current
, MEMORY_DESCRIPTOR_INT
, m
);
103 // First descriptor requested
105 if (BiosMemoryMapEntryCount
> 0)
108 // Return first generated memory descriptor
110 return &BiosMemoryDescriptors
[0].m
;
112 else if (sizeof(MemoryDescriptors
) > 0)
115 // Return first fixed memory descriptor
117 return &MemoryDescriptors
[0].m
;
122 // Strange case, we have no memory descriptor
127 else if (CurrentDescriptor
->GeneratedDescriptor
)
130 // Current entry is a generated descriptor
132 if (CurrentDescriptor
->Index
+ 1 < BiosMemoryMapEntryCount
)
135 // Return next generated descriptor
137 return &BiosMemoryDescriptors
[CurrentDescriptor
->Index
+ 1].m
;
139 else if (sizeof(MemoryDescriptors
) > 0)
142 // Return first fixed memory descriptor
144 return &MemoryDescriptors
[0].m
;
149 // No fixed memory descriptor; end of memory map
157 // Current entry is a fixed descriptor
159 if (CurrentDescriptor
->Index
+ 1 < sizeof(MemoryDescriptors
) / sizeof(MemoryDescriptors
[0]))
162 // Return next fixed descriptor
164 return &MemoryDescriptors
[CurrentDescriptor
->Index
+ 1].m
;
169 // No more fixed memory descriptor; end of memory map