Exemplo n.º 1
0
void init_program(void)
{
	/* Get the value of load-base and use it to determine the correct loader
           to use */
	ucell addr;

	feval("load-base");
	addr = POP();

#ifdef CONFIG_LOADER_AOUT
	if (is_aout((struct exec *)cell2pointer(addr))) {
		aout_init_program();
		return;
	}
#endif

#ifdef CONFIG_LOADER_BOOTCODE
	if (is_bootcode((char *)cell2pointer(addr))) {
		bootcode_init_program();
		return;
	}
#endif

#ifdef CONFIG_LOADER_BOOTINFO
	if (is_bootinfo((char *)cell2pointer(addr))) {
		bootinfo_init_program();
		return;
	}
#endif

#ifdef CONFIG_LOADER_ELF
	if (is_elf((Elf_ehdr *)cell2pointer(addr))) {
		elf_init_program();
		return;
	}
#endif

#ifdef CONFIG_LOADER_FCODE
	if (is_fcode((unsigned char *)cell2pointer(addr))) {
		fcode_init_program();
		return;
	}
#endif

#ifdef CONFIG_LOADER_FORTH
	if (is_forth((char *)cell2pointer(addr))) {
		forth_init_program();
		return;
	}
#endif

#ifdef CONFIG_LOADER_XCOFF
	if (is_xcoff((COFF_filehdr_t *)cell2pointer(addr))) {
		xcoff_init_program();
		return;
	}
#endif

}
Exemplo n.º 2
0
int 
fcode_load(ihandle_t dev)
{
    int retval = -1;
    uint8_t fcode_header[8];
    unsigned long start, size;
    unsigned int offset;

    /* Mark the saved-program-state as invalid */
    feval("0 state-valid !");

    fd = open_ih(dev);
    if (fd == -1) {
        goto out;
    }

    for (offset = 0; offset < 16 * 512; offset += 512) {
        seek_io(fd, offset);
        if (read_io(fd, &fcode_header, sizeof(fcode_header))
            != sizeof(fcode_header)) {
            debug("Can't read FCode header from ihandle " FMT_ucellx "\n", dev);
            retval = LOADER_NOT_SUPPORT;
            goto out;
        }

	if (is_fcode(fcode_header))
            goto found;
    }

    debug("Not a bootable FCode image\n");
    retval = LOADER_NOT_SUPPORT;
    goto out;

 found:
    size = (fcode_header[4] << 24) | (fcode_header[5] << 16) |
        (fcode_header[6] << 8) | fcode_header[7];

    fword("load-base");
    start = POP();

    printf("\nLoading FCode image...\n");

    seek_io(fd, offset);

    if ((size_t)read_io(fd, (void *)start, size) != size) {
        printf("Can't read file (size 0x%lx)\n", size);
        goto out;
    }

    debug("Loaded %lu bytes\n", size);
    debug("entry point is %#lx\n", start);
    
    // Initialise load-state
    PUSH(size);
    feval("load-state >ls.file-size !");
    feval("fcode load-state >ls.file-type !");

out:
    close_io(fd);
    return retval;
}