/*
* Copyright (c) 1998 Robert Nordier
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "endian.h"
#include "imgact_aout.h"
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "btx.h"
#include "elfh.h"
struct hdr {
};
static const char binfo[] =
"kernel: ver=%u.%02u size=%x load=%x entry=%x map=%uM "
"pgctl=%x:%x\n";
static const char cinfo[] =
"client: fmt=%s size=%x text=%x data=%x bss=%x entry=%x\n";
static const char oinfo[] =
"output: fmt=%s size=%x text=%x data=%x org=%x entry=%x\n";
static const char *lname =
static const char *bname =
static const char *oname =
"a.out"; /* Output filename */
static void cleanup(void);
static void btxld(const char *);
static unsigned int optfmt(const char *);
static int optpage(const char *, int);
static void Warn(const char *, const char *, ...);
static void usage(void);
extern void add_version(const char *, char *);
/*
* A link editor for BTX clients.
*/
int
{
int c;
switch (c) {
case 'q':
quiet = 1;
break;
case 'v':
verbose = 1;
break;
case 'b':
break;
case 'E':
Eflag = 1;
break;
case 'e':
break;
case 'f':
break;
case 'l':
break;
case 'o':
break;
case 'P':
break;
case 'V':
break;
case 'W':
break;
default:
usage();
}
if (argc != 1)
usage();
return 0;
}
/*
* Clean up after errors.
*/
static void
cleanup(void)
{
if (tname)
}
/*
* Read the input files; write the output file; display information.
*/
static void
{
ldr_size = 0;
switch (i) {
case I_LDR:
break;
case I_BTX:
break;
case I_CLNT:
"Client origin is 0x%x; expecting 0 or 0x%x",
}
}
cwr = 0;
if (wpage > 0)
else {
if (cwr > BTX_MAXCWR)
cwr = BTX_MAXCWR;
}
}
if (!cwr)
cwr++;
}
switch (i) {
case I_LDR:
break;
case I_BTX:
sizeof(btx));
break;
case I_CLNT:
}
}
if (verbose) {
}
}
/*
* Read BTX file header.
*/
static void
{
}
/*
* Get file size and read a.out or ELF header.
*/
static void
{
void *p;
unsigned int fmt, x, n, i;
return;
0)) == MAP_FAILED)
switch (fmt) {
case F_AOUT:
ex = p;
x = N_GETMAGIC(*ex);
if (x == NMAGIC)
}
}
break;
case F_ELF:
ee = p;
switch (n++) {
case 0:
break;
case 1:
break;
case 2:
"Ignoring extra %s PT_LOAD segments",
}
}
}
}
}
/*
* Write a.out or ELF header.
*/
static void
{
case F_AOUT:
break;
case F_ELF:
4096));
}
}
/*
* Safe copy from input file to output file.
*/
static void
{
size_t n;
while (nbyte) {
n = nbyte;
nbyte -= n;
offset = -1;
}
}
/*
* Safe read from input file.
*/
static size_t
{
ssize_t n;
return n;
}
/*
* Safe write to output file.
*/
static void
{
ssize_t n;
}
/*
* Safe seek in output file.
*/
static void
{
}
/*
* Convert an option argument to a format code.
*/
static unsigned int
{
unsigned int i;
if (i == F_CNT)
return i;
}
/*
* Convert an option argument to an address.
*/
static uint32_t
{
char *s;
unsigned long x;
errno = 0;
return x;
}
/*
* Convert an option argument to a page number.
*/
static int
{
char *s;
long x;
errno = 0;
return x;
}
/*
* Display a warning.
*/
static void
{
char *s;
if (!quiet) {
free(s);
}
}
/*
* Display usage information.
*/
static void
usage(void)
{
"usage: btxld [-qv] [-b file] [-E address] [-e address] [-f format]",
" [-l file] [-o filename] [-P page] [-W page] file");
exit(1);
}