summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/arch/i386/core/load_buffer.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/src/arch/i386/core/load_buffer.c b/src/arch/i386/core/load_buffer.c
index 1668b3c57..78cdb9afc 100644
--- a/src/arch/i386/core/load_buffer.c
+++ b/src/arch/i386/core/load_buffer.c
@@ -1,8 +1,6 @@
-#include "limits.h"
#include "io.h"
-#include "memsizes.h"
-#include "init.h"
-#include "buffer.h"
+#include "heap.h"
+#include "load_buffer.h"
/*
* Initialise a buffer in an unused portion of memory, to be used for
@@ -10,55 +8,58 @@
*
*/
-/* Under KEEP_IT_REAL, always use 07c0:0000 as the buffer. Otherwise,
- * use a reset_fn that finds the largest available block of RAM.
- */
-struct buffer load_buffer = {
- .start = 0x7c00,
- .end = 0xa0000,
-};
+#ifdef KEEP_IT_REAL
-#ifndef KEEP_IT_REAL
+/*
+ * Under KEEP_IT_REAL, always use 07c0:0000 as the load buffer.
+ *
+ */
-extern char _text[];
+int init_load_buffer ( struct buffer *buffer ) {
+ buffer->start = 0x7c00;
+ buffer->end = 0xa0000;
+ init_buffer ( buffer );
+ return 1;
+}
-static void init_load_buffer ( void ) {
- unsigned int i;
- unsigned long size = 0;
+void trim_load_buffer ( struct buffer *buffer ) {
+ /* Nothing to do */
+}
- load_buffer.start = 0;
- load_buffer.end = 0;
+void done_load_buffer ( struct buffer *buffer ) {
+ /* Nothing to do */
+}
- /* Find the largest usable segment in memory */
- for ( i = 0 ; i < meminfo.map_count ; i++ ) {
- unsigned long r_start, r_end;
+#else /* KEEP_IT_REAL */
- if ( meminfo.map[i].type != E820_RAM )
- continue;
+/*
+ * Without KEEP_IT_REAL, use all remaining heap space as the load buffer.
+ *
+ */
+int init_load_buffer ( struct buffer *buffer ) {
+ void *data;
+ size_t size;
+
+ data = emalloc_all ( &size );
+ if ( ! data )
+ return 0;
- if ( meminfo.map[i].addr + meminfo.map[i].size > ULONG_MAX )
- continue;
+ buffer->start = virt_to_phys ( data );
+ buffer->end = buffer->start + size;
+ init_buffer ( buffer );
+ return 1;
+}
- r_start = meminfo.map[i].addr;
- r_end = meminfo.map[i].size;
+void trim_load_buffer ( struct buffer *buffer ) {
+ void *new_start;
- /* Avoid overlap with Etherboot. Etherboot will be
- * located towards the top of a segment, so we need
- * only consider one-sided truncation.
- */
- if ( ( r_start <= virt_to_phys ( _text ) ) &&
- ( virt_to_phys ( _text ) < r_end ) ) {
- r_end = virt_to_phys ( _text );
- }
+ /* Shrink buffer */
+ new_start = erealloc ( phys_to_virt ( buffer->start ), buffer->fill );
+ buffer->start = virt_to_phys ( new_start );
+}
- if ( r_end - r_start > size ) {
- size = r_end - r_start;
- load_buffer.start = r_start;
- load_buffer.end = r_end;
- }
- }
+void done_load_buffer ( struct buffer *buffer ) {
+ efree ( phys_to_virt ( buffer->start ) );
}
-INIT_FN ( INIT_HEAP, init_load_buffer, init_load_buffer, NULL );
-
#endif