Browse Source

Merge branch 'master' of /pub/scm/gpxe

tags/v0.9.3
Marty Connor 17 years ago
parent
commit
74a1c77820
4 changed files with 75 additions and 14 deletions
  1. 2
    3
      contrib/bochs/README.qemu
  2. 1
    1
      src/Makefile
  3. 7
    0
      src/arch/i386/Makefile
  4. 65
    10
      src/arch/i386/core/umalloc.c

+ 2
- 3
contrib/bochs/README.qemu View File

54
 
54
 
55
 8.  Build Etherboot floppy disk images and pad to 1.44MB
55
 8.  Build Etherboot floppy disk images and pad to 1.44MB
56
       pushd ../../src
56
       pushd ../../src
57
-      make bin/rtl8139.dsk
58
-      ./util/dskpad.pl bin/rtl8139.dsk
57
+      make bin/rtl8139.pdsk
59
       popd
58
       popd
60
 
59
 
61
 9.  Start qemu
60
 9.  Start qemu
62
       export SDL_VIDEO_X11_DGAMOUSE=0
61
       export SDL_VIDEO_X11_DGAMOUSE=0
63
       ./qemu/i386-softmmu/qemu -L qemu/pc-bios \
62
       ./qemu/i386-softmmu/qemu -L qemu/pc-bios \
64
 			       -net nic,model=rtl8139 -net tap,ifname=tap0 \
63
 			       -net nic,model=rtl8139 -net tap,ifname=tap0 \
65
-			       -boot a -fda ../../src/bin/rtl8139.dsk 
64
+			       -boot a -fda ../../src/bin/rtl8139.pdsk 
66
 
65
 
67
 You should see qemu start up, load up Etherboot and attempt to boot
66
 You should see qemu start up, load up Etherboot and attempt to boot
68
 from the network.
67
 from the network.

+ 1
- 1
src/Makefile View File

162
 # "-p 0x1234,0x5678" string to set the PCI IDs.
162
 # "-p 0x1234,0x5678" string to set the PCI IDs.
163
 #
163
 #
164
 FINALISE_rom	= $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
164
 FINALISE_rom	= $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
165
-		  -i$(IDENT) $@
165
+		  -i$(IDENT) -s 0 $@
166
 
166
 
167
 # Some ROMs require specific flags to be passed to makerom.pl
167
 # Some ROMs require specific flags to be passed to makerom.pl
168
 #
168
 #

+ 7
- 0
src/arch/i386/Makefile View File

111
 	dd if=$< bs=512 conv=sync of=/dev/fd0
111
 	dd if=$< bs=512 conv=sync of=/dev/fd0
112
 	sync
112
 	sync
113
 
113
 
114
+# rule to create padded disk images
115
+NON_AUTO_MEDIA		+= pdsk
116
+%pdsk : %dsk
117
+	cp $< $@
118
+	$(PERL) ./util/dskpad.pl $@
119
+
114
 # rule to make a non-emulation ISO boot image
120
 # rule to make a non-emulation ISO boot image
115
 NON_AUTO_MEDIA		+= iso
121
 NON_AUTO_MEDIA		+= iso
116
 %iso:	%lkrn util/geniso
122
 %iso:	%lkrn util/geniso
125
 $(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
131
 $(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
126
 	$(OBJCOPY) -O binary $< $@
132
 	$(OBJCOPY) -O binary $< $@
127
 
133
 
134
+NON_AUTO_MEDIA		+= usb
128
 %usb: $(BIN)/usbdisk.bin %hd
135
 %usb: $(BIN)/usbdisk.bin %hd
129
 	cat $^ > $@
136
 	cat $^ > $@
130
 
137
 

+ 65
- 10
src/arch/i386/core/umalloc.c View File

23
  *
23
  *
24
  */
24
  */
25
 
25
 
26
+#include <limits.h>
27
+#include <errno.h>
26
 #include <gpxe/uaccess.h>
28
 #include <gpxe/uaccess.h>
27
 #include <gpxe/hidemem.h>
29
 #include <gpxe/hidemem.h>
30
+#include <gpxe/memmap.h>
28
 #include <gpxe/umalloc.h>
31
 #include <gpxe/umalloc.h>
29
 
32
 
30
 /** Alignment of external allocated memory */
33
 /** Alignment of external allocated memory */
36
 /** Start of Etherboot text, as defined by the linker */
39
 /** Start of Etherboot text, as defined by the linker */
37
 extern char _text[];
40
 extern char _text[];
38
 
41
 
39
-/** Top of allocatable memory */
40
-#define TOP ( virt_to_user ( _text ) )
41
-
42
 /** An external memory block */
42
 /** An external memory block */
43
 struct external_memory {
43
 struct external_memory {
44
 	/** Size of this memory block (excluding this header) */
44
 	/** Size of this memory block (excluding this header) */
47
 	int used;
47
 	int used;
48
 };
48
 };
49
 
49
 
50
-/** Current lowest allocated block
50
+/** Top of heap */
51
+static userptr_t top = UNULL;
52
+
53
+/** Bottom of heap (current lowest allocated block) */
54
+static userptr_t bottom = UNULL;
55
+
56
+/**
57
+ * Initialise external heap
51
  *
58
  *
52
- * A value of UNULL indicates that no blocks are currently allocated.
59
+ * @ret rc		Return status code
53
  */
60
  */
54
-userptr_t bottom = UNULL;
61
+static int init_eheap ( void ) {
62
+	struct memory_map memmap;
63
+	unsigned long heap_size = 0;
64
+	unsigned int i;
65
+
66
+	DBG ( "Allocating external heap\n" );
67
+
68
+	get_memmap ( &memmap );
69
+	for ( i = 0 ; i < memmap.count ; i++ ) {
70
+		struct memory_region *region = &memmap.regions[i];
71
+		unsigned long r_start, r_end;
72
+		unsigned long r_size;
73
+
74
+		DBG ( "Considering [%llx,%llx)\n", region->start, region->end);
75
+
76
+		/* Truncate block to 4GB */
77
+		if ( region->start > UINT_MAX ) {
78
+			DBG ( "...starts after 4GB\n" );
79
+			continue;
80
+		}
81
+		r_start = region->start;
82
+		if ( region->end > UINT_MAX ) {
83
+			DBG ( "...end truncated to 4GB\n" );
84
+			r_end = 0; /* =4GB, given the wraparound */
85
+		} else {
86
+			r_end = region->end;
87
+		}
88
+
89
+		/* Use largest block */
90
+		r_size = ( r_end - r_start );
91
+		if ( r_size > heap_size ) {
92
+			DBG ( "...new best block found\n" );
93
+			top = bottom = phys_to_user ( r_end );
94
+			heap_size = r_size;
95
+		}
96
+	}
97
+
98
+	if ( ! top ) {
99
+		DBG ( "No external heap available\n" );
100
+		return -ENOMEM;
101
+	}
102
+
103
+	DBG ( "External heap grows downwards from %lx\n",
104
+	      user_to_phys ( top, 0 ) );
105
+	return 0;
106
+}
55
 
107
 
56
 /**
108
 /**
57
  * Collect free blocks
109
  * Collect free blocks
61
 	struct external_memory extmem;
113
 	struct external_memory extmem;
62
 
114
 
63
 	/* Walk the free list and collect empty blocks */
115
 	/* Walk the free list and collect empty blocks */
64
-	while ( bottom != TOP ) {
116
+	while ( bottom != top ) {
65
 		copy_from_user ( &extmem, bottom, -sizeof ( extmem ),
117
 		copy_from_user ( &extmem, bottom, -sizeof ( extmem ),
66
 				 sizeof ( extmem ) );
118
 				 sizeof ( extmem ) );
67
 		if ( extmem.used )
119
 		if ( extmem.used )
87
 	struct external_memory extmem;
139
 	struct external_memory extmem;
88
 	userptr_t new = ptr;
140
 	userptr_t new = ptr;
89
 	size_t align;
141
 	size_t align;
142
+	int rc;
90
 
143
 
91
 	/* Initialise external memory allocator if necessary */
144
 	/* Initialise external memory allocator if necessary */
92
-	if ( ! bottom  )
93
-		bottom = TOP;
145
+	if ( ! top  ) {
146
+		if ( ( rc = init_eheap() ) != 0 )
147
+			return rc;
148
+	}
94
 
149
 
95
 	/* Get block properties into extmem */
150
 	/* Get block properties into extmem */
96
 	if ( ptr && ( ptr != UNOWHERE ) ) {
151
 	if ( ptr && ( ptr != UNOWHERE ) ) {
140
 	/* Collect any free blocks and update hidden memory region */
195
 	/* Collect any free blocks and update hidden memory region */
141
 	ecollect_free();
196
 	ecollect_free();
142
 	hide_region ( EXTMEM, user_to_phys ( bottom, -sizeof ( extmem ) ),
197
 	hide_region ( EXTMEM, user_to_phys ( bottom, -sizeof ( extmem ) ),
143
-		      user_to_phys ( TOP, 0 ) );
198
+		      user_to_phys ( top, 0 ) );
144
 
199
 
145
 	return ( new_size ? new : UNOWHERE );
200
 	return ( new_size ? new : UNOWHERE );
146
 }
201
 }

Loading…
Cancel
Save