mirror of
https://github.com/xcat2/xNBA.git
synced 2025-04-15 17:49:26 +00:00
Remove osloader.c and replace with a prep_segment() that uses userptr_t
and get_memmap() in image/segment.c
This commit is contained in:
parent
ceca6b185c
commit
3634e705b7
@ -2,7 +2,6 @@
|
||||
#include "memsizes.h"
|
||||
#include "realmode.h"
|
||||
#include "gateA20.h"
|
||||
#include "osloader.h"
|
||||
#include "etherboot.h"
|
||||
#include "errno.h"
|
||||
|
||||
|
@ -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:
|
||||
*/
|
72
src/image/segment.c
Normal file
72
src/image/segment.c
Normal file
@ -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;
|
||||
}
|
15
src/include/gpxe/segment.h
Normal file
15
src/include/gpxe/segment.h
Normal file
@ -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 */
|
@ -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 */
|
Loading…
x
Reference in New Issue
Block a user