summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2005-05-17 15:37:29 +0200
committerMichael Brown2005-05-17 15:37:29 +0200
commit9968c9513e1a503dcfa3ae11a85d80765f6a5b34 (patch)
tree4eadbda598cecc649624192e0eda955c3d2525bc /src/core
parentMoved os_regs into start32.S (diff)
downloadipxe-9968c9513e1a503dcfa3ae11a85d80765f6a5b34.tar.gz
ipxe-9968c9513e1a503dcfa3ae11a85d80765f6a5b34.tar.xz
ipxe-9968c9513e1a503dcfa3ae11a85d80765f6a5b34.zip
Moved find_segment into elf_loader.c
Diffstat (limited to 'src/core')
-rw-r--r--src/core/elf_loader.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/core/elf_loader.c b/src/core/elf_loader.c
index c1906d8a2..88a2975ef 100644
--- a/src/core/elf_loader.c
+++ b/src/core/elf_loader.c
@@ -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;