Make this work with the ELF tape bootloader.

This commit is contained in:
scw 2000-12-04 21:24:34 +00:00
parent 3de7a35dc2
commit 349445391c
2 changed files with 44 additions and 46 deletions

View File

@ -1,8 +1,15 @@
# $NetBSD: Makefile,v 1.4 2000/07/09 13:47:34 jdolecek Exp $
# $NetBSD: Makefile,v 1.5 2000/12/04 21:24:34 scw Exp $
S=${.CURDIR}/../../../../
PROG= wrtvid
MKMAN= no
LIBSA=${.CURDIR}/../../../../lib/libsa
COPTS+= -Wall -Wstrict-prototypes -Wmissing-prototypes
CPPFLAGS+= -I${LIBSA}
.PATH.c: ${LIBSA}
SRCS= wrtvid.c loadfile.c
# only needed during build
proginstall::

View File

@ -1,40 +1,51 @@
/* $NetBSD: wrtvid.c,v 1.1 1996/05/17 19:58:55 chuck Exp $ */
/* $NetBSD: wrtvid.c,v 1.2 2000/12/04 21:24:34 scw Exp $ */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define __DBINTERFACE_PRIVATE
#include <db.h>
#include <machine/disklabel.h>
main(argc, argv)
int argc;
char **argv;
#include "loadfile.h"
static void swabcfg(struct cpu_disklabel *);
static void swabvid(struct cpu_disklabel *);
int
main(int argc, char **argv)
{
struct cpu_disklabel *pcpul;
struct stat stat;
int exe_file;
int tape_vid;
int tape_exe;
unsigned int exe_addr;
unsigned short exe_addr_u;
unsigned short exe_addr_l;
int tape_vid, tape_exe, fd;
char *filename;
char *filebuff;
char fileext[256];
char filebase[256];
u_long marks[MARK_MAX];
size_t len;
if (argc == 0)
filename = "a.out";
else
filename = argv[1];
exe_file = open(filename, O_RDONLY,0444);
if (exe_file == -1) {
perror(filename);
exit(2);
}
marks[MARK_START] = 0;
if ((fd = loadfile(filename, marks, COUNT_TEXT|COUNT_DATA)) == -1)
return NULL;
(void)close(fd);
len = (((marks[MARK_END] - marks[MARK_START]) + 511) / 512) * 2;
len *= 256;
filebuff = malloc(len);
marks[MARK_START] = (u_long)(filebuff - marks[MARK_START]);
if ((fd = loadfile(filename, marks, LOAD_TEXT|LOAD_DATA)) == -1)
return NULL;
(void)close(fd);
sprintf(fileext, "%c%cboot", filename[4], filename[5]);
tape_vid = open(fileext, O_WRONLY|O_CREAT|O_TRUNC, 0644);
sprintf(fileext, "boot%c%c", filename[4], filename[5]);
@ -45,18 +56,12 @@ main(argc, argv)
strcpy(pcpul->vid_id, "NBSD");
fstat(exe_file, &stat);
/* size in 256 byte blocks round up after a.out header removed */
if (filename[5] == 't' ) {
pcpul->vid_oss = 1;
}else {
pcpul->vid_oss = 2;
}
pcpul->vid_osl = (((stat.st_size -0x20) +511) / 512) *2;
lseek(exe_file, 0x14, SEEK_SET);
read(exe_file, &exe_addr, 4);
pcpul->vid_osl = len / 256;
/* check this, it may not work in both endian. */
{
@ -67,7 +72,7 @@ main(argc, argv)
} s;
unsigned long l;
} a;
a.l = exe_addr;
a.l = marks[MARK_ENTRY];
pcpul->vid_osa_u = a.s.s1;
pcpul->vid_osa_l = a.s.s2;
@ -90,30 +95,15 @@ main(argc, argv)
free(pcpul);
copy_exe(exe_file, tape_exe);
close(exe_file);
write(tape_exe, filebuff, len);
free(filebuff);
close(tape_vid);
close(tape_exe);
return (0);
}
#define BUF_SIZ 512
copy_exe(exe_file, tape_exe)
int exe_file, tape_exe;
{
char *buf;
int cnt = 0;
buf = (char *)malloc(BUF_SIZ);
lseek (exe_file, 0x20, SEEK_SET);
while (BUF_SIZ == (cnt = read(exe_file, buf, BUF_SIZ))) {
write(tape_exe, buf, cnt);
}
bzero(&buf[cnt], BUF_SIZ-cnt);
write(tape_exe, buf, BUF_SIZ);
}
static void
swabvid(pcpul)
struct cpu_disklabel *pcpul;
{
@ -126,6 +116,7 @@ swabvid(pcpul)
M_32_SWAP(pcpul->vid_cas);
}
static void
swabcfg(pcpul)
struct cpu_disklabel *pcpul;
{