FreeBSD/sys/boot/userboot/userboot/elf32_freebsd.c
/*
 * There is an ELF kernel and one or more ELF modules loaded.  
 * We wish to start executing the kernel image, so make such 
 * preparations as are required, and do so.
 */
There is an ELF kernel and one or more ELF modules loaded.
We wish to start executing the kernel image, so make such
preparations as are required, and do so.
There is an ELF kernel and one or more ELF modules loaded . We wish to start executing the kernel image so make such preparations as are required and do so .
static int
elf32_exec(struct preloaded_file *fp)
{
	struct file_metadata	*md;
	Elf_Ehdr 		*ehdr;
	vm_offset_t		entry, bootinfop, modulep, kernend;
	int			boothowto, err, bootdev;
	uint32_t		stack[1024], *sp;
	if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
		return(EFTYPE);
	ehdr = (Elf_Ehdr *)&(md->md_data);
	err = bi_load32(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend);
	if (err != 0)
		return(err);
	entry = ehdr->e_entry & 0xffffff;
#ifdef DEBUG
	printf("Start @ 0x%lx ...\n", entry);
#endif
	dev_cleanup();
	memset(stack, 0, sizeof(stack));
	sp = (uint32_t *)((char *)stack + sizeof(stack));
	*--sp = kernend;
	*--sp = modulep;
	*--sp = bootinfop;
	*--sp = 0;
	*--sp = 0;
	*--sp = 0;
	*--sp = bootdev;
	*--sp = boothowto;
	*--sp = 0xbeefface;
	CALLBACK(copyin, stack, GUEST_STACK, sizeof(stack));
	CALLBACK(setreg, 4, (char *)sp - (char *)stack + GUEST_STACK);
	CALLBACK(setgdt, GUEST_GDT, 8 * 4 - 1);
        CALLBACK(exec, entry);
	panic("exec returned");
}
static int elf32_exec ( struct preloaded_file * fp ) { struct file_metadata * md ; Elf_Ehdr * ehdr ; vm_offset_t entry , bootinfop , modulep , kernend ; int boothowto , err , bootdev ; uint32_t stack [ 1024 ] , * sp ; if ( ( md = file_findmetadata ( fp , MODINFOMD_ELFHDR ) ) == NULL ) return ( EFTYPE ) ; ehdr = ( Elf_Ehdr * ) & ( md -> md_data ) ; err = bi_load32 ( fp -> f_args , & boothowto , & bootdev , & bootinfop , & modulep , & kernend ) ; if ( err != 0 ) return ( err ) ; entry = ehdr -> e_entry & 0xffffff ; #ifdef DEBUG printf ( " \n " , entry ) ; #endif dev_cleanup ( ) ; memset ( stack , 0 , sizeof ( stack ) ) ; sp = ( uint32_t * ) ( ( char * ) stack + sizeof ( stack ) ) ; * -- sp = kernend ; * -- sp = modulep ; * -- sp = bootinfop ; * -- sp = 0 ; * -- sp = 0 ; * -- sp = 0 ; * -- sp = bootdev ; * -- sp = boothowto ; * -- sp = 0xbeefface ; CALLBACK ( copyin , stack , GUEST_STACK , sizeof ( stack ) ) ; CALLBACK ( setreg , 4 , ( char * ) sp - ( char * ) stack + GUEST_STACK ) ; CALLBACK ( setgdt , GUEST_GDT , 8 * 4 - 1 ) ; CALLBACK ( exec , entry ) ; panic ( " " ) ; }
There is an ELF kernel and one or more ELF modules loaded.
There is an ELF kernel and one or more ELF modules loaded .
/*
	 * Build a scratch stack at physical 0x1000
	 */ /*
	 * Fake return address to mimic "new" boot blocks.  For more
	 * details see recover_bootinfo in locore.S.
	 */