mirror of
https://github.com/xcat2/xNBA.git
synced 2024-12-23 19:51:46 +00:00
Moved find_segment into elf_loader.c
This commit is contained in:
parent
9a413cfea1
commit
9968c9513e
@ -32,6 +32,45 @@ struct elf_state
|
||||
|
||||
static struct elf_state estate;
|
||||
|
||||
static unsigned long find_segment(unsigned long size, unsigned long align)
|
||||
{
|
||||
unsigned i;
|
||||
/* Verify I have a power of 2 alignment */
|
||||
if (align & (align - 1)) {
|
||||
return ULONG_MAX;
|
||||
}
|
||||
for(i = 0; i < meminfo.map_count; i++) {
|
||||
unsigned long r_start, r_end;
|
||||
if (meminfo.map[i].type != E820_RAM)
|
||||
continue;
|
||||
if ((meminfo.map[i].addr + meminfo.map[i].size) > ULONG_MAX) {
|
||||
continue;
|
||||
}
|
||||
r_start = meminfo.map[i].addr;
|
||||
r_end = r_start + meminfo.map[i].size;
|
||||
/* Don't allow the segment to overlap etherboot */
|
||||
if ((r_end > virt_to_phys(_text)) && (r_start < virt_to_phys(_text))) {
|
||||
r_end = virt_to_phys(_text);
|
||||
}
|
||||
if ((r_start > virt_to_phys(_text)) && (r_start < virt_to_phys(_end))) {
|
||||
r_start = virt_to_phys(_end);
|
||||
}
|
||||
/* Don't allow the segment to overlap the heap */
|
||||
if ((r_end > heap_ptr) && (r_start < heap_ptr)) {
|
||||
r_end = heap_ptr;
|
||||
}
|
||||
if ((r_start > heap_ptr) && (r_start < heap_bot)) {
|
||||
r_start = heap_ptr;
|
||||
}
|
||||
r_start = (r_start + align - 1) & ~(align - 1);
|
||||
if ((r_end >= r_start) && ((r_end - r_start) >= size)) {
|
||||
return r_start;
|
||||
}
|
||||
}
|
||||
/* I did not find anything :( */
|
||||
return ULONG_MAX;
|
||||
}
|
||||
|
||||
static void elf_boot(unsigned long machine, unsigned long entry)
|
||||
{
|
||||
int result;
|
||||
|
Loading…
Reference in New Issue
Block a user