david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Use the heap functions to allocate a load buffer.

This commit is contained in:
Michael Brown 2005-05-13 13:30:51 +00:00
parent c695c75b01
commit 301b2d40f0
1 changed files with 52 additions and 51 deletions

View File

@ -1,8 +1,6 @@
#include "limits.h"
#include "io.h" #include "io.h"
#include "memsizes.h" #include "heap.h"
#include "init.h" #include "load_buffer.h"
#include "buffer.h"
/* /*
* Initialise a buffer in an unused portion of memory, to be used for * 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, #ifdef KEEP_IT_REAL
* use a reset_fn that finds the largest available block of RAM.
/*
* Under KEEP_IT_REAL, always use 07c0:0000 as the load buffer.
*
*/ */
struct buffer load_buffer = {
.start = 0x7c00,
.end = 0xa0000,
};
#ifndef KEEP_IT_REAL int init_load_buffer ( struct buffer *buffer ) {
buffer->start = 0x7c00;
extern char _text[]; buffer->end = 0xa0000;
init_buffer ( buffer );
static void init_load_buffer ( void ) { return 1;
unsigned int i; }
unsigned long size = 0;
void trim_load_buffer ( struct buffer *buffer ) {
load_buffer.start = 0; /* Nothing to do */
load_buffer.end = 0; }
/* Find the largest usable segment in memory */ void done_load_buffer ( struct buffer *buffer ) {
for ( i = 0 ; i < meminfo.map_count ; i++ ) { /* Nothing to do */
unsigned long r_start, r_end; }
if ( meminfo.map[i].type != E820_RAM ) #else /* KEEP_IT_REAL */
continue;
/*
if ( meminfo.map[i].addr + meminfo.map[i].size > ULONG_MAX ) * Without KEEP_IT_REAL, use all remaining heap space as the load buffer.
continue; *
*/
r_start = meminfo.map[i].addr; int init_load_buffer ( struct buffer *buffer ) {
r_end = meminfo.map[i].size; void *data;
size_t size;
/* Avoid overlap with Etherboot. Etherboot will be
* located towards the top of a segment, so we need data = emalloc_all ( &size );
* only consider one-sided truncation. if ( ! data )
*/ return 0;
if ( ( r_start <= virt_to_phys ( _text ) ) &&
( virt_to_phys ( _text ) < r_end ) ) { buffer->start = virt_to_phys ( data );
r_end = virt_to_phys ( _text ); buffer->end = buffer->start + size;
} init_buffer ( buffer );
return 1;
if ( r_end - r_start > size ) { }
size = r_end - r_start;
load_buffer.start = r_start; void trim_load_buffer ( struct buffer *buffer ) {
load_buffer.end = r_end; void *new_start;
}
} /* Shrink buffer */
new_start = erealloc ( phys_to_virt ( buffer->start ), buffer->fill );
buffer->start = virt_to_phys ( new_start );
}
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 #endif