/* bootinfo */ #define BOOTINFO_VERSION 1 #define NODEV (-1) /* non-existent device */ #define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ #define PAGE_SIZE (1<= estate.p.phdr32[j].p_offset) && ((shdr[i].sh_offset + shdr[i].sh_size) <= (estate.p.phdr32[j].p_offset + estate.p.phdr32[j].p_filesz))) { shdr[i].sh_offset=0; shdr[i].sh_size=0; break; } } } if ((shdr[i].sh_offset != 0) && (shdr[i].sh_size != 0)) { symtabindex = i; symstrindex = shdr[i].sh_link; } } } } /* Check if we have a symbol table index and have not loaded it */ if ((symtab_load == 0) && (symtabindex >= 0)) { /* No symbol table yet? Load it first... */ /* This happens to work out in a strange way. * If we are past the point in the file already, * we will skip a *large* number of bytes which * ends up bringing us to the end of the file and * an old (default) boot. Less code and lets * the state machine work in a cleaner way but this * is a nasty side-effect trick... */ estate.skip = shdr[symtabindex].sh_offset - (estate.loc + offset); /* And we need to read this many bytes... */ estate.toread = shdr[symtabindex].sh_size; if (estate.toread) { #if ELF_DEBUG printf("db sym, size %lX, curaddr %lX\n", estate.toread, estate.curaddr); #endif /* Save where we are loading this... */ symtab_load = estate.curaddr; *((long *)phys_to_virt(estate.curaddr)) = estate.toread; estate.curaddr += sizeof(long); /* Start to read... */ return 1; } } else if ((symstr_load == 0) && (symstrindex >= 0)) { /* We have already loaded the symbol table, so * now on to the symbol strings... */ /* Same nasty trick as above... */ estate.skip = shdr[symstrindex].sh_offset - (estate.loc + offset); /* And we need to read this many bytes... */ estate.toread = shdr[symstrindex].sh_size; if (estate.toread) { #if ELF_DEBUG printf("db str, size %lX, curaddr %lX\n", estate.toread, estate.curaddr); #endif /* Save where we are loading this... */ symstr_load = estate.curaddr; *((long *)phys_to_virt(estate.curaddr)) = estate.toread; estate.curaddr += sizeof(long); /* Start to read... */ return 1; } } } /* all done */ return 0; } static void elf_freebsd_boot(unsigned long entry) { if (image_type != Elf_FreeBSD) return; memset(&bsdinfo, 0, sizeof(bsdinfo)); bsdinfo.bi_basemem = meminfo.basememsize; bsdinfo.bi_extmem = meminfo.memsize; bsdinfo.bi_memsizes_valid = 1; bsdinfo.bi_version = BOOTINFO_VERSION; bsdinfo.bi_kernelname = virt_to_phys(KERNEL_BUF); bsdinfo.bi_nfs_diskless = NULL; bsdinfo.bi_size = sizeof(bsdinfo); #define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */ if(freebsd_kernel_env[0] != '\0'){ freebsd_howto |= RB_BOOTINFO; bsdinfo.bi_envp = (unsigned long)freebsd_kernel_env; } /* Check if we have symbols loaded, and if so, * made the meta_data needed to pass those to * the kernel. */ if ((symtab_load !=0) && (symstr_load != 0)) { unsigned long *t; bsdinfo.bi_symtab = symtab_load; /* End of symbols (long aligned...) */ /* Assumes size of long is a power of 2... */ bsdinfo.bi_esymtab = (symstr_load + sizeof(long) + *((long *)phys_to_virt(symstr_load)) + sizeof(long) - 1) & ~(sizeof(long) - 1); /* Where we will build the meta data... */ t = phys_to_virt(bsdinfo.bi_esymtab); #if ELF_DEBUG printf("Metadata at %lX\n",t); #endif /* Set up the pointer to the memory... */ bsdinfo.bi_modulep = virt_to_phys(t); /* The metadata structure is an array of 32-bit * words where we store some information about the * system. This is critical, as FreeBSD now looks * only for the metadata for the extended symbol * information rather than in the bootinfo. */ /* First, do the kernel name and the kernel type */ /* Note that this assumed x86 byte order... */ /* 'kernel\0\0' */ *t++=MODINFO_NAME; *t++= 7; *t++=0x6E72656B; *t++=0x00006C65; /* 'elf kernel\0\0' */ *t++=MODINFO_TYPE; *t++=11; *t++=0x20666C65; *t++=0x6E72656B; *t++ = 0x00006C65; /* Now the symbol start/end - note that they are * here in local/physical address - the Kernel * boot process will relocate the addresses. */ *t++=MODINFOMD_SSYM | MODINFO_METADATA; *t++=sizeof(*t); *t++=bsdinfo.bi_symtab; *t++=MODINFOMD_ESYM | MODINFO_METADATA; *t++=sizeof(*t); *t++=bsdinfo.bi_esymtab; *t++=MODINFO_END; *t++=0; /* end of metadata */ /* Since we have symbols we need to make * sure that the kernel knows its own end * of memory... It is not _end but after * the symbols and the metadata... */ bsdinfo.bi_kernend = virt_to_phys(t); /* Signal locore.s that we have a valid bootinfo * structure that was completely filled in. */ freebsd_howto |= 0x80000000; } xstart32(entry, freebsd_howto, NODEV, 0, 0, 0, virt_to_phys(&bsdinfo), 0, 0, 0); longjmp(restart_etherboot, -2); } #endif #ifdef AOUT_IMAGE static void aout_freebsd_probe(void) { image_type = Aout; if (((astate.head.a_midmag >> 16) & 0xffff) == 0) { /* Some other a.out variants have a different * value, and use other alignments (e.g. 1K), * not the 4K used by FreeBSD. */ image_type = Aout_FreeBSD; printf("/FreeBSD"); off = -(astate.head.a_entry & 0xff000000); astate.head.a_entry += off; } } static void aout_freebsd_boot(void) { if (image_type == Aout_FreeBSD) { memset(&bsdinfo, 0, sizeof(bsdinfo)); bsdinfo.bi_basemem = meminfo.basememsize; bsdinfo.bi_extmem = meminfo.memsize; bsdinfo.bi_memsizes_valid = 1; bsdinfo.bi_version = BOOTINFO_VERSION; bsdinfo.bi_kernelname = virt_to_phys(KERNEL_BUF); bsdinfo.bi_nfs_diskless = NULL; bsdinfo.bi_size = sizeof(bsdinfo); xstart32(astate.head.a_entry, freebsd_howto, NODEV, 0, 0, 0, virt_to_phys(&bsdinfo), 0, 0, 0); longjmp(restart_etherboot, -2); } } #endif