Added a framework for the elks/8086 format. Completely non-functional at the moment.

committer: mfx <mfx> 978092698 +0000
This commit is contained in:
Markus F.X.J. Oberhumer
2000-12-29 12:24:58 +00:00
parent 7d5042012b
commit 5a497e2dac
5 changed files with 228 additions and 3 deletions
+193
View File
@@ -0,0 +1,193 @@
/* p_elks.cpp --
This file is part of the UPX executable compressor.
Copyright (C) 1996-2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996-2000 Laszlo Molnar
All Rights Reserved.
UPX and the UCL library are free software; you can redistribute them
and/or modify them under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) 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; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Markus F.X.J. Oberhumer Laszlo Molnar
markus.oberhumer@jk.uni-linz.ac.at ml1050@cdata.tvnet.hu
*/
#include "conf.h"
#if 0
#include "file.h"
#include "filter.h"
#include "packer.h"
#include "p_vmlinz.h"
// FIXME
static const
#include "stub/l_vmlinz.h"
// from elks-0.0.83/Documentation/boot.txt
static const unsigned kernel_entry = 0x100000;
static const unsigned stack_during_uncompression = 0x90000;
static const unsigned zimage_offset = 0x1000;
/*************************************************************************
//
**************************************************************************/
int PackElks8086::getCompressionMethod() const
{
if (M_IS_NRV2B(opt->method))
return M_NRV2B_8;
if (M_IS_NRV2D(opt->method))
return M_NRV2D_8;
return opt->level > 1 ? M_NRV2D_8 : M_NRV2B_8;
}
const int *PackElks8086::getFilters() const
{
return NULL;
}
/*************************************************************************
// common util routines
**************************************************************************/
int PackElks8086::uncompressKernel()
{
// not used
return 0;
}
void PackElks8086::readKernel()
{
int klen = file_size - setup_size;
fi->seek(0, SEEK_SET);
setup_buf.alloc(setup_size);
fi->readx(setup_buf, setup_size);
ibuf.alloc(klen);
fi->readx(ibuf, klen);
obuf.allocForCompression(klen);
ph.u_len = klen;
ph.filter = 0;
}
/*************************************************************************
//
**************************************************************************/
int PackElks8086::buildLoader(const Filter *ft)
{
// prepare loader
initLoader(nrv_loader, sizeof(nrv_loader));
// FIXME
UNUSED(ft);
return getLoaderSize();
}
void PackElks8086::pack(OutputFile *fo)
{
readKernel();
// prepare filter
Filter ft(opt->level);
ft.buf_len = ph.u_len;
ft.addvalue = kernel_entry;
// prepare other settings
const unsigned overlap_range = 1 << 20;
unsigned overlapoh;
int strategy = -1; // try the first working filter
if (opt->filter >= 0 && isValidFilter(opt->filter))
// try opt->filter or 0 if that fails
strategy = -2;
else if (opt->all_filters)
// choose best from all available filters
strategy = 0;
compressWithFilters(&ft, &overlapoh, overlap_range, strategy);
const unsigned lsize = getLoaderSize();
MemBuffer loader(lsize);
memcpy(loader, getLoader(), lsize);
patchPackHeader(loader, lsize);
#if 0
// FIXME
patchFilter32(loader, lsize, &ft);
patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
patch_le32(loader, lsize, "KEIP", kernel_entry);
patch_le32(loader, lsize, "STAK", stack_during_uncompression);
#endif
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
bs->sys_size = ALIGN_UP(lsize + ph.c_len, 16) / 16;
fo->write(setup_buf, setup_buf.getSize());
fo->write(loader, lsize);
fo->write(obuf, ph.c_len);
#if 0
printf("%-13s: setup : %8ld bytes\n", getName(), (long) setup_buf.getSize());
printf("%-13s: loader : %8ld bytes\n", getName(), (long) lsize);
printf("%-13s: compressed : %8ld bytes\n", getName(), (long) ph.c_len);
#endif
// finally check the compression ratio
if (!checkFinalCompressionRatio(fo))
throwNotCompressible();
}
/*************************************************************************
// unpack
**************************************************************************/
int PackElks8086::canUnpack()
{
if (readFileHeader() != getFormat())
return false;
fi->seek(setup_size, SEEK_SET);
return readPackHeader(1024) ? 1 : -1;
}
void PackElks8086::unpack(OutputFile *)
{
// no uncompression support for this format yet
// FIXME: but we could write the uncompressed "Image" image
throwCantUnpack("build a new kernel instead :-)");
}
#endif /* if 0 */
/*
vi:ts=4:et
*/