Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
    int	error;
    char	*file;
    u_long	marks[MARK_MAX];
    extern char start[];		/* top of stack (see srt0.S) */
    vaddr_t	bstart_va;

    prom_init();
    mmu_init();

    printf(">> OpenBSD BOOT %s\n", version);

    /*
     * Find the physical memory area that's in use by the boot loader.
     * Our stack grows down from label `start'; assume we need no more
     * than 16K of stack space.
     * The top of the boot loader is the next 4MB boundary.
     */
    bstart_va = (vaddr_t)start - LOWSTACK;
    if (pmap_extract(bstart_va, &bstart) != 0)
        panic("can't figure out where we have been loaded");

    if (bstart != bstart_va)
        compat = 0;

    bend = roundup(bstart, FOURMB);
#ifdef DEBUG
    printf("bstart %p bend %p\n", bstart, bend);
#endif

    file = prom_bootfile;
    if (file == 0 || *file == 0)
        file = DEFAULT_KERNEL;

    for (;;) {
        if (prom_boothow & RB_ASKNAME) {
            printf("device[%s]: ", prom_bootdevice);
            gets(dbuf);
            if (dbuf[0])
                prom_bootdevice = dbuf;
            printf("boot: ");
            gets(fbuf);
            if (fbuf[0])
                file = fbuf;
        }

        printf("Booting %s\n", file);
        if ((error = loadk(file, marks)) == 0)
            break;

        printf("Cannot load %s: error=%d\n", file, error);
        prom_boothow |= RB_ASKNAME;
    }

    /* Note: args 2-4 not used due to conflicts with SunOS loaders */
    (*(entry_t)marks[MARK_ENTRY])(cputyp == CPU_SUN4 ?
                                  PROM_LOADADDR : (u_long)promvec, 0, 0, 0,
                                  marks[MARK_END], DDB_MAGIC1);

    _rtt();
}
Exemplo n.º 2
0
int
main(void)
{
	int	error, i;
	char	kernel[MAX_PROM_PATH];
	const char *k;
	u_long	marks[MARK_MAX], bootinfo;
	struct btinfo_symtab bi_sym;
	struct btinfo_boothowto bi_howto;
	void	*arg;

#ifdef HEAP_VARIABLE
	{
		extern char end[];
		setheap((void *)ALIGN(end), (void *)0xffffffff);
	}
#endif
	prom_init();
	mmu_init();

	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);

	/* massage machine prom */
	prom_patch();

	/*
	 * get default kernel.
	 */
	k = prom_getbootfile();
	if (k != NULL && *k != '\0') {
		i = -1;	/* not using the kernels */
		strcpy(kernel, k);
	} else {
		i = 0;
		strcpy(kernel, kernels[i]);
	}

	k = prom_getbootpath();
	if (k && *k)
		strcpy(prom_bootdevice, k);
	boothowto = bootoptions(prom_getbootargs());

	for (;;) {
		/*
		 * ask for a kernel first ..
		 */
		if (boothowto & RB_ASKNAME) {
			printf("device[%s] (\"halt\" to halt): ",
					prom_bootdevice);
			gets(dbuf);
			if (strcmp(dbuf, "halt") == 0)
				_rtt();
			if (dbuf[0])
				strcpy(prom_bootdevice, dbuf);
			printf("boot (press RETURN to try default list): ");
			gets(fbuf);
			if (fbuf[0])
				strcpy(kernel, fbuf);
			else {
				boothowto &= ~RB_ASKNAME;
				i = 0;
				strcpy(kernel, kernels[i]);
			}
		}

		printf("Booting %s\n", kernel);
		if ((error = loadk(kernel, marks)) == 0)
			break;

		if (error != ENOENT) {
			printf("Cannot load %s: error=%d\n", kernel, error);
			boothowto |= RB_ASKNAME;
		}

		/*
		 * if we have are not in askname mode, and we aren't using the
		 * prom bootfile, try the next one (if it exits).  otherwise,
		 * go into askname mode.
		 */
		if ((boothowto & RB_ASKNAME) == 0 &&
		    i != -1 && kernels[++i]) {
			strcpy(kernel, kernels[i]);
			printf(": trying %s...\n", kernel);
		} else {
			printf("\n");
			boothowto |= RB_ASKNAME;
		}
	}

	marks[MARK_END] = (((u_long)marks[MARK_END] + sizeof(u_long) - 1)) &
	    (-sizeof(u_long));
	arg = (prom_version() == PROM_OLDMON) ? (void *)PROM_LOADADDR : romp;

	/* Setup boot info structure at the end of the kernel image */
	bootinfo = bi_init(marks[MARK_END] & loadaddrmask);

	/* Add kernel symbols to bootinfo */
	bi_sym.nsym = marks[MARK_NSYM] & loadaddrmask;
	bi_sym.ssym = marks[MARK_SYM] & loadaddrmask;
	bi_sym.esym = marks[MARK_END] & loadaddrmask;
	bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));

	/* Add boothowto */
	bi_howto.boothowto = boothowto;
	bi_add(&bi_howto, BTINFO_BOOTHOWTO, sizeof(bi_howto));

	/* Add kernel path to bootinfo */
	i = sizeof(struct btinfo_common) + strlen(kernel) + 1;
	/* Impose limit (somewhat arbitrary) */
	if (i < BOOTINFO_SIZE / 2) {
		union {
			struct btinfo_kernelfile bi_file;
			char x[i];
		} U;
		strcpy(U.bi_file.name, kernel);
		bi_add(&U.bi_file, BTINFO_KERNELFILE, i);
	}

	(*(entry_t)marks[MARK_ENTRY])(arg, 0, 0, 0, bootinfo, DDB_MAGIC2);
	_rtt();
}