DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦4a1c22d05⟧ TextFile

    Length: 2006 (0x7d6)
    Types: TextFile
    Notes: UNIX file
    Names: »load.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »cmd/load.c« 

TextFile

/*
 * Load a driver.
 * #if I8086 will cause the pseudo load of a driver linked
 * with the system image.
 */
#include <stdio.h>
#include <canon.h>
#include <con.h>
#include <l.out.h>
#include <machine.h>

main(argc, argv)
char *argv[];
{
	register int n;
	register FILE *fp;
#if I8086
	register FILE *cfp;	/* CON file pointer */
#endif
	register size_t s;
	register size_t b;
	register int conflag;
	CON con;
	struct ldsym lds;
	struct ldheader ldh;
	extern int errno;
	extern char *sys_errlist[];

	if (argc < 2)
		panic("Usage: load <driver>");
	if ((fp=fopen(argv[1], "r")) == NULL)
		panic("Cannot open %s", argv[1]);
#if I8086
	if ((cfp=fopen("/dev/kmem", "r")) == NULL)
		panic("Cannot open /dev/kmem");
#endif
	if (fread(&ldh, sizeof(ldh), 1, fp) != 1)
		panic("Not an l.out");
	canint(ldh.l_magic);
	if (ldh.l_magic != L_MAGIC)
		panic("Not an l.out");
	for (n=0; n<NLSEG; n++)
		cansize(ldh.l_ssize[n]);
	b = sizeof(ldh);
	b += ldh.l_ssize[L_SHRI] + ldh.l_ssize[L_PRVI];
	b += ldh.l_ssize[L_SHRD] + ldh.l_ssize[L_PRVD];
	conflag = 0;
	fseek(fp, (long)b, 0);
	for (s=ldh.l_ssize[L_SYM]; s; s-=sizeof(lds)) {
		if (fread(&lds, sizeof(lds), 1, fp) != 1)
			panic("Bad l.out");
		canvaddr(lds.ls_addr);
		if (strcmp(&lds.ls_id[2], "con_") != 0)
			continue;
		conflag++;
#if I8086
		fseek(cfp, (long)lds.ls_addr, 0);
#else
		b = sizeof(ldh) + lds.ls_addr - (long)dvirt();
#if Z8001
		b = (unsigned)b;
#endif
		fseek(fp, b, 0);
#endif
#if I8086
		if (fread(&con, sizeof(con), 1, cfp) != 1)
#else
		if (fread(&con, sizeof(con), 1, fp) != 1)
#endif
			panic("Cannot read configuration");
#if ! I8086
		fseek(fp, (long)b+ldh.l_ssize[L_SYM]-s+sizeof(lds), 0);
#endif
		if (sload(con.c_mind, argv[1], lds.ls_addr) < 0)
			fprintf( stderr, "load: %.2s: %s\n", lds.ls_id,
				sys_errlist[errno]);
	}
	if (conflag == 0)
		panic("Configuration table not found");
	exit(0);
}

/*
 * Print out an error message and exit.
 */
panic(a1)
char *a1;
{
	fprintf(stderr, "%r", &a1);
	fprintf(stderr, "\n");
	exit(1);
}