Explorar el Código

Remove osloader.c and replace with a prep_segment() that uses userptr_t

and get_memmap() in image/segment.c
tags/v0.9.3
Michael Brown hace 18 años
padre
commit
3634e705b7
Se han modificado 5 ficheros con 87 adiciones y 98 borrados
  1. 0
    1
      src/arch/i386/image/nbi.c
  2. 0
    91
      src/core/osloader.c
  3. 72
    0
      src/image/segment.c
  4. 15
    0
      src/include/gpxe/segment.h
  5. 0
    6
      src/include/osloader.h

+ 0
- 1
src/arch/i386/image/nbi.c Ver fichero

@@ -2,7 +2,6 @@
2 2
 #include "memsizes.h"
3 3
 #include "realmode.h"
4 4
 #include "gateA20.h"
5
-#include "osloader.h"
6 5
 #include "etherboot.h"
7 6
 #include "errno.h"
8 7
 

+ 0
- 91
src/core/osloader.c Ver fichero

@@ -1,91 +0,0 @@
1
-/**************************************************************************
2
-OS loader
3
-
4
-Author: Markus Gutschke (gutschk@math.uni-muenster.de)
5
-  Date: Sep/95
6
-Modifications: Ken Yap (for Etherboot/16)
7
-  Doug Ambrisko (ELF and a.out support)
8
-  Klaus Espenlaub (rewrote ELF and a.out (did it really work before?) support,
9
-      added ELF Multiboot images).  Someone should merge the ELF and a.out
10
-      loaders, as most of the code is now identical.  Maybe even NBI could be
11
-      rewritten and merged into the generic loading framework.  This should
12
-      save quite a few bytes of code if you have selected more than one format.
13
-  Ken Yap (Jan 2001)
14
-      Added support for linear entry addresses in tagged images,
15
-      which allows a more efficient protected mode call instead of
16
-      going to real mode and back. Also means entry addresses > 1 MB can
17
-      be called.  Conditional on the LINEAR_EXEC_ADDR bit.
18
-      Added support for Etherboot extension calls. Conditional on the
19
-      TAGGED_PROGRAM_RETURNS bit. Implies LINEAR_EXEC_ADDR.
20
-      Added support for non-MULTIBOOT ELF which also supports Etherboot
21
-      extension calls. Conditional on the ELF_PROGRAM_RETURNS bit.
22
-
23
-**************************************************************************/
24
-
25
-/*
26
- * This program is free software; you can redistribute it and/or
27
- * modify it under the terms of the GNU General Public License as
28
- * published by the Free Software Foundation; either version 2, or (at
29
- * your option) any later version.
30
- */
31
-
32
-#include "io.h"
33
-#include "memsizes.h"
34
-
35
-/* Linker symbols */
36
-extern char _text[];
37
-extern char _end[];
38
-
39
-int prep_segment ( physaddr_t start, physaddr_t mid, physaddr_t end ) {
40
-	unsigned fit, i;
41
-
42
-	DBG ( "OSLOADER preparing segment [%lX,%lX)\n", start, end );
43
-
44
-	if ( mid > end ) {
45
-		DBG ( "OSLOADER got filesz > memsz\n" );
46
-		return 0;
47
-	}
48
-
49
-	/* Check for overlap with Etherboot runtime image */
50
-	if ( ( end > virt_to_phys ( _text ) ) && 
51
-	     ( start < virt_to_phys ( _end ) ) ) {
52
-		DBG ( "OSLOADER got segment [%lX, %lX) "
53
-		      "overlapping etherboot [%lX, %lX)\n",
54
-		      start, end,
55
-		      virt_to_phys ( _text ), virt_to_phys ( _end ) );
56
-		return 0;
57
-	}
58
-
59
-	/* Check that block fits entirely inside a single memory region */
60
-	fit = 0;
61
-	for ( i = 0 ; i < meminfo.map_count ; i++ ) {
62
-		unsigned long long r_start, r_end;
63
-
64
-		if (meminfo.map[i].type != E820_RAM)
65
-			continue;
66
-
67
-		r_start = meminfo.map[i].addr;
68
-		r_end = r_start + meminfo.map[i].size;
69
-		if ( ( start >= r_start ) && ( end <= r_end ) ) {
70
-			fit = 1;
71
-			break;
72
-		}
73
-	}
74
-	if ( ! fit ) {
75
-		DBG ( "OSLOADER got segment [%lX,%lX) "
76
-		      "which does not fit in any memory region\n",
77
-			start, end );
78
-		return 0;
79
-	}
80
-
81
-	/* Zero the bss */
82
-	memset ( phys_to_virt ( mid ), 0, end - mid );
83
-
84
-	return 1;
85
-}
86
-
87
-/*
88
- * Local variables:
89
- *  c-basic-offset: 8
90
- * End:
91
- */

+ 72
- 0
src/image/segment.c Ver fichero

@@ -0,0 +1,72 @@
1
+/*
2
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+/**
20
+ * @file
21
+ *
22
+ * Executable image segments
23
+ *
24
+ */
25
+
26
+#include <errno.h>
27
+#include <gpxe/uaccess.h>
28
+#include <gpxe/memmap.h>
29
+#include <gpxe/segment.h>
30
+
31
+/**
32
+ * Prepare segment for loading
33
+ *
34
+ * @v segment		Segment start
35
+ * @v filesz		Size of the "allocated bytes" portion of the segment
36
+ * @v memsz		Size of the segment
37
+ * @ret rc		Return status code
38
+ */
39
+int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ) {
40
+	struct memory_map memmap;
41
+	physaddr_t start = user_to_phys ( segment, 0 );
42
+	physaddr_t mid = user_to_phys ( segment, filesz );
43
+	physaddr_t end = user_to_phys ( segment, memsz );
44
+	unsigned int i;
45
+
46
+	/* Sanity check */
47
+	if ( filesz > memsz ) {
48
+		DBG ( "Insane segment [%lx,%lx,%lx)\n", start, mid, end );
49
+		return -EINVAL;
50
+	}
51
+
52
+	/* Get a fresh memory map.  This allows us to automatically
53
+	 * avoid treading on any regions that Etherboot is currently
54
+	 * editing out of the memory map.
55
+	 */
56
+	get_memmap ( &memmap );
57
+
58
+	/* Look for a suitable memory region */
59
+	for ( i = 0 ; i < memmap.count ; i++ ) {
60
+		if ( ( start >= memmap.regions[i].start ) &&
61
+		     ( end <= memmap.regions[i].end ) ) {
62
+			/* Found valid region: zero bss and return */
63
+			memset_user ( segment, filesz, 0, ( memsz - filesz ) );
64
+			return 0;
65
+		}
66
+	}
67
+
68
+	/* No suitable memory region found */
69
+	DBG ( "Segment [%lx,%lx,%lx) does not fit into available memory\n",
70
+	      start, mid, end );
71
+	return -ERANGE;
72
+}

+ 15
- 0
src/include/gpxe/segment.h Ver fichero

@@ -0,0 +1,15 @@
1
+#ifndef _GPXE_SEGMENT_H
2
+#define _GPXE_SEGMENT_H
3
+
4
+/**
5
+ * @file
6
+ *
7
+ * Executable image segments
8
+ *
9
+ */
10
+
11
+#include <gpxe/uaccess.h>
12
+
13
+extern int prep_segment ( userptr_t segment, size_t filesz, size_t memsz );
14
+
15
+#endif /* _GPXE_SEGMENT_H */

+ 0
- 6
src/include/osloader.h Ver fichero

@@ -1,6 +0,0 @@
1
-#ifndef OSLOADER_H
2
-#define OSLOADER_H
3
-
4
-extern int prep_segment ( physaddr_t start, physaddr_t mid, physaddr_t end );
5
-
6
-#endif /* OSLOADER_H */

Loading…
Cancelar
Guardar