aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown <mcb30@etherboot.org>2007-01-11 14:32:26 +0000
committerMichael Brown <mcb30@etherboot.org>2007-01-11 14:32:26 +0000
commit3634e705b700ce6cbc307c5e940f85fc46b2e327 (patch)
tree4b66b83deb1de2870c8594ce22c9c5e87fc3a6c9
parentceca6b185c9f21d1063c069021d7ea2f40c5af00 (diff)
downloadipxe-3634e705b700ce6cbc307c5e940f85fc46b2e327.tar.gz
Remove osloader.c and replace with a prep_segment() that uses userptr_t
and get_memmap() in image/segment.c
-rw-r--r--src/arch/i386/image/nbi.c1
-rw-r--r--src/core/osloader.c91
-rw-r--r--src/image/segment.c72
-rw-r--r--src/include/gpxe/segment.h15
-rw-r--r--src/include/osloader.h6
5 files changed, 87 insertions, 98 deletions
diff --git a/src/arch/i386/image/nbi.c b/src/arch/i386/image/nbi.c
index c50a78c3..edaaedc9 100644
--- a/src/arch/i386/image/nbi.c
+++ b/src/arch/i386/image/nbi.c
@@ -2,7 +2,6 @@
#include "memsizes.h"
#include "realmode.h"
#include "gateA20.h"
-#include "osloader.h"
#include "etherboot.h"
#include "errno.h"
diff --git a/src/core/osloader.c b/src/core/osloader.c
deleted file mode 100644
index ddbe68a3..00000000
--- a/src/core/osloader.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/**************************************************************************
-OS loader
-
-Author: Markus Gutschke (gutschk@math.uni-muenster.de)
- Date: Sep/95
-Modifications: Ken Yap (for Etherboot/16)
- Doug Ambrisko (ELF and a.out support)
- Klaus Espenlaub (rewrote ELF and a.out (did it really work before?) support,
- added ELF Multiboot images). Someone should merge the ELF and a.out
- loaders, as most of the code is now identical. Maybe even NBI could be
- rewritten and merged into the generic loading framework. This should
- save quite a few bytes of code if you have selected more than one format.
- Ken Yap (Jan 2001)
- Added support for linear entry addresses in tagged images,
- which allows a more efficient protected mode call instead of
- going to real mode and back. Also means entry addresses > 1 MB can
- be called. Conditional on the LINEAR_EXEC_ADDR bit.
- Added support for Etherboot extension calls. Conditional on the
- TAGGED_PROGRAM_RETURNS bit. Implies LINEAR_EXEC_ADDR.
- Added support for non-MULTIBOOT ELF which also supports Etherboot
- extension calls. Conditional on the ELF_PROGRAM_RETURNS bit.
-
-**************************************************************************/
-
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2, or (at
- * your option) any later version.
- */
-
-#include "io.h"
-#include "memsizes.h"
-
-/* Linker symbols */
-extern char _text[];
-extern char _end[];
-
-int prep_segment ( physaddr_t start, physaddr_t mid, physaddr_t end ) {
- unsigned fit, i;
-
- DBG ( "OSLOADER preparing segment [%lX,%lX)\n", start, end );
-
- if ( mid > end ) {
- DBG ( "OSLOADER got filesz > memsz\n" );
- return 0;
- }
-
- /* Check for overlap with Etherboot runtime image */
- if ( ( end > virt_to_phys ( _text ) ) &&
- ( start < virt_to_phys ( _end ) ) ) {
- DBG ( "OSLOADER got segment [%lX, %lX) "
- "overlapping etherboot [%lX, %lX)\n",
- start, end,
- virt_to_phys ( _text ), virt_to_phys ( _end ) );
- return 0;
- }
-
- /* Check that block fits entirely inside a single memory region */
- fit = 0;
- for ( i = 0 ; i < meminfo.map_count ; i++ ) {
- unsigned long long r_start, r_end;
-
- if (meminfo.map[i].type != E820_RAM)
- continue;
-
- r_start = meminfo.map[i].addr;
- r_end = r_start + meminfo.map[i].size;
- if ( ( start >= r_start ) && ( end <= r_end ) ) {
- fit = 1;
- break;
- }
- }
- if ( ! fit ) {
- DBG ( "OSLOADER got segment [%lX,%lX) "
- "which does not fit in any memory region\n",
- start, end );
- return 0;
- }
-
- /* Zero the bss */
- memset ( phys_to_virt ( mid ), 0, end - mid );
-
- return 1;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
diff --git a/src/image/segment.c b/src/image/segment.c
new file mode 100644
index 00000000..8deaef79
--- /dev/null
+++ b/src/image/segment.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/**
+ * @file
+ *
+ * Executable image segments
+ *
+ */
+
+#include <errno.h>
+#include <gpxe/uaccess.h>
+#include <gpxe/memmap.h>
+#include <gpxe/segment.h>
+
+/**
+ * Prepare segment for loading
+ *
+ * @v segment Segment start
+ * @v filesz Size of the "allocated bytes" portion of the segment
+ * @v memsz Size of the segment
+ * @ret rc Return status code
+ */
+int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ) {
+ struct memory_map memmap;
+ physaddr_t start = user_to_phys ( segment, 0 );
+ physaddr_t mid = user_to_phys ( segment, filesz );
+ physaddr_t end = user_to_phys ( segment, memsz );
+ unsigned int i;
+
+ /* Sanity check */
+ if ( filesz > memsz ) {
+ DBG ( "Insane segment [%lx,%lx,%lx)\n", start, mid, end );
+ return -EINVAL;
+ }
+
+ /* Get a fresh memory map. This allows us to automatically
+ * avoid treading on any regions that Etherboot is currently
+ * editing out of the memory map.
+ */
+ get_memmap ( &memmap );
+
+ /* Look for a suitable memory region */
+ for ( i = 0 ; i < memmap.count ; i++ ) {
+ if ( ( start >= memmap.regions[i].start ) &&
+ ( end <= memmap.regions[i].end ) ) {
+ /* Found valid region: zero bss and return */
+ memset_user ( segment, filesz, 0, ( memsz - filesz ) );
+ return 0;
+ }
+ }
+
+ /* No suitable memory region found */
+ DBG ( "Segment [%lx,%lx,%lx) does not fit into available memory\n",
+ start, mid, end );
+ return -ERANGE;
+}
diff --git a/src/include/gpxe/segment.h b/src/include/gpxe/segment.h
new file mode 100644
index 00000000..5ab91699
--- /dev/null
+++ b/src/include/gpxe/segment.h
@@ -0,0 +1,15 @@
+#ifndef _GPXE_SEGMENT_H
+#define _GPXE_SEGMENT_H
+
+/**
+ * @file
+ *
+ * Executable image segments
+ *
+ */
+
+#include <gpxe/uaccess.h>
+
+extern int prep_segment ( userptr_t segment, size_t filesz, size_t memsz );
+
+#endif /* _GPXE_SEGMENT_H */
diff --git a/src/include/osloader.h b/src/include/osloader.h
deleted file mode 100644
index 12439568..00000000
--- a/src/include/osloader.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef OSLOADER_H
-#define OSLOADER_H
-
-extern int prep_segment ( physaddr_t start, physaddr_t mid, physaddr_t end );
-
-#endif /* OSLOADER_H */