void __start(void) { int argc; char *ro_args, *args, **argv; /* Clear BSS */ memset(edata, 0, end - edata); /* Define heap. */ setheap(end, (void *)(HIMEM - 0x1000)); ro_args = os_get_env(NULL, NULL); args = alloc(strlen(ro_args)+10); /* some spare extra */ strcpy(args, ro_args); argc = splitargs(args, 0, NULL); argv = alloc(argc * sizeof(*argv)); if (argv == NULL) panic("alloc of argv failed"); argc = splitargs(args, 1, argv); /* start real main() */ os_exit(NULL, main(argc, argv)); }
int main(void) { char *h = malloc(HEAPSIZE); setheap(h, h + HEAPSIZE); return samain(); }
int main() { char *h = malloc(HEAPSIZE); setheap(h, h + HEAPSIZE); return (samain()); }
int main(int argc, char *argv[], char *envv[], struct bootinfo *bootinfop) { struct devsw **dp; /* NB: Must be sure to bzero() before using any globals. */ bzero(&__bss_start, (uintptr_t)&__bss_end - (uintptr_t)&__bss_start); boot2_argc = argc; boot2_argv = argv; boot2_envv = envv; boot2_bootinfo = *bootinfop; /* Copy rather than by reference. */ setheap((void *)&__heap_start, (void *)&__heap_end); /* * Pick up console settings from boot2; probe console. */ if (bootinfop->bi_boot2opts & RB_MULTIPLE) { if (bootinfop->bi_boot2opts & RB_SERIAL) setenv("console", "comconsole vidconsole", 1); else setenv("console", "vidconsole comconsole", 1); } else if (bootinfop->bi_boot2opts & RB_SERIAL) setenv("console", "comconsole", 1); else if (bootinfop->bi_boot2opts & RB_MUTE) setenv("console", "nullconsole", 1); cons_probe(); setenv("LINES", "24", 1); printf("%s(%d, %p, %p, %p (%p))\n", __func__, argc, argv, envv, bootinfop, (void *)bootinfop->bi_memsize); /* * Initialise devices. */ for (dp = devsw; *dp != NULL; dp++) { if ((*dp)->dv_init != NULL) (*dp)->dv_init(); } extract_currdev(bootinfop); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); #if 0 printf("bootpath=\"%s\"\n", bootpath); #endif interact(NULL); return (0); }
void mem_init(void) { uint32_t heap, size; size = MEMSIZE; /* XXX */ /* Start is always 0. */ heap = size - BOARD_HEAP_SIZE; printf(">> RAM 0x%x - 0x%x, heap at 0x%x\n", 0, size - 1, heap); setheap((void *)heap, (void *)(size - 1)); }
dupefile_t * dupe_open(uint8_t *data) { dupefile_t *f = (dupefile_t *)data; if (f->version > 3 || f->idx >= f->caplen) return NULL; if (f->caplen <= 0) return NULL; setheap(f->heaptype); return f; }
void mem_init(void) { uint32_t start, size, heap; start = S3C2410_SDRAM_START; size = SDRAM_SIZE; heap = (start + size) - HEAP_SIZE; printf(">> RAM 0x%x - 0x%x, heap at 0x%x\n", start, (start + size) - 1, heap); setheap((void *)heap, (void *)(heap + HEAP_SIZE - 1)); }
void init_heap(void) { void *base; ihandle_t stdout; if ((base = ofw_alloc_heap(HEAP_SIZE)) == (void *)0xffffffff) { OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)); OF_puts(stdout, "Heap memory claim failed!\n"); OF_enter(); } setheap(base, (void *)((int)base + HEAP_SIZE)); }
void mem_init(void) { uint32_t start, size, heap; start = RAM_START; size = RAM_SIZE; /* ROM monitor uses top of SDRAM for page table. */ #define ROMMONITOR_PAGETABLE (RAM_START+RAM_SIZE-0x8000) heap = ROMMONITOR_PAGETABLE - HEAP_SIZE; printf(">> RAM 0x%x - 0x%x, heap at 0x%x\n", start, (start + size) - 1, heap); setheap((void *)heap, (void *)(heap + HEAP_SIZE - 1)); }
int bootxx(void *readsector, void *disklabel, int autoboot) { static osdsc_t os_desc; extern char end[], edata[]; osdsc_t *od = &os_desc; bxxx_t bootxxx = (bxxx_t)(LOADADDR3); bzero(edata, end - edata); setheap(end, (void*)(LOADADDR3 - 4)); printf("\033v\nNetBSD/atari secondary bootloader" " ($Revision: 1.12 $)\n\n"); if (init_dskio(readsector, disklabel, -1)) return -1; for (;;) { od->rootfs = 0; /* partition a */ od->osname = "/netbsd"; od->ostype = &od->osname[1]; od->boothowto = (RB_RDONLY); if (!autoboot) { int pref; od->boothowto = (RB_RDONLY|RB_SINGLE); pref = usr_info(od); if (pref < 0) continue; if (pref > 0) return pref; } autoboot = 0; /* in case auto boot fails */ if (init_dskio(readsector, disklabel, od->rootfs)) continue; if (load_booter(od)) continue; (*bootxxx)(readsector, disklabel, od); } /* NOTREACHED */ }
void mem_init(void) { uint32_t cm_sdram; uint32_t heap, size; cm_sdram = INL(0x10000020); switch ((cm_sdram >> 2) & 0x7) { case 0: size = 16 * 1024 * 1024; break; case 1: size = 32 * 1024 * 1024; break; case 2: size = 64 * 1024 * 1024; break; case 3: size = 128 * 1024 * 1024; break; case 4: size = 256 * 1024 * 1024; break; default: printf("** CM_SDRAM retuns unknown value, using 16M\n"); size = 16 * 1024 * 1024; break; } /* Start is always 0. */ heap = size - HEAP_SIZE; printf(">> RAM 0x%x - 0x%x, heap at 0x%x\n", 0, size - 1, heap); setheap((void *)heap, (void *)(size - 1)); }
int bootxxx(void *readsector, void *disklabel, osdsc_t *od) { int fd; char *errmsg; extern char end[], edata[]; memset(edata, 0, end - edata); /* XXX: Limit should be 16MB */ setheap(end, (void*)0x1000000); printf("\033v\nNetBSD/Atari tertiary bootloader " "($Revision: 1.8 $)\n\n"); if (init_dskio(readsector, disklabel, od->rootfs)) return -1; sys_info(od); if (!(od->cputype & ATARI_ANYCPU)) { printf("Unknown CPU-type.\n"); return -2; } if ((fd = open(od->osname, 0)) < 0) { printf("Cannot open kernel '%s'\n", od->osname); return -3; } #ifndef __ELF__ /* a.out */ if (aout_load(fd, od, &errmsg, 1) != 0) #else if (elf_load(fd, od, &errmsg, 1) != 0) #endif return -4; boot_BSD(&od->kp); return -5; /* NOTREACHED */ }
int main(int argc, const char **argv) { void *heapbase; const size_t heapsize = 15*1024*1024; const char *bootdev = argv[1]; /* * Set the heap to one page after the end of the loader. */ heapbase = host_getmem(heapsize); setheap(heapbase, heapbase + heapsize); /* * Set up console. */ cons_probe(); printf("Boot device: %s\n", bootdev); archsw.arch_getdev = kboot_getdev; archsw.arch_copyin = kboot_copyin; archsw.arch_copyout = kboot_copyout; archsw.arch_readin = kboot_readin; archsw.arch_autoload = kboot_autoload; archsw.arch_loadaddr = kboot_loadaddr; printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); setenv("currdev", bootdev, 1); setenv("loaddev", bootdev, 1); setenv("LINES", "24", 1); interact(NULL); /* doesn't return */ return (0); }
int main(int (*openfirm)(void *)) { char bootpath[64]; struct devsw **dp; phandle_t chosenh; /* * Tell the OpenFirmware functions where they find the ofw gate. */ OF_init(openfirm); archsw.arch_getdev = ofw_getdev; archsw.arch_copyin = sparc64_copyin; archsw.arch_copyout = ofw_copyout; archsw.arch_readin = sparc64_readin; archsw.arch_autoload = sparc64_autoload; init_heap(); setheap((void *)heapva, (void *)(heapva + HEAPSZ)); /* * Probe for a console. */ cons_probe(); tlb_init(); bcache_init(32, 512); /* * Initialize devices. */ for (dp = devsw; *dp != 0; dp++) { if ((*dp)->dv_init != 0) (*dp)->dv_init(); } /* * Set up the current device. */ chosenh = OF_finddevice("/chosen"); OF_getprop(chosenh, "bootpath", bootpath, sizeof(bootpath)); /* * Sun compatible bootable CD-ROMs have a disk label placed * before the cd9660 data, with the actual filesystem being * in the first partition, while the other partitions contain * pseudo disk labels with embedded boot blocks for different * architectures, which may be followed by UFS filesystems. * The firmware will set the boot path to the partition it * boots from ('f' in the sun4u case), but we want the kernel * to be loaded from the cd9660 fs ('a'), so the boot path * needs to be altered. */ if (bootpath[strlen(bootpath) - 2] == ':' && bootpath[strlen(bootpath) - 1] == 'f') { bootpath[strlen(bootpath) - 1] = 'a'; printf("Boot path set to %s\n", bootpath); } env_setenv("currdev", EV_VOLATILE, bootpath, ofw_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset, env_nounset); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); printf("bootpath=\"%s\"\n", bootpath); /* Give control to the machine independent loader code. */ interact(); return 1; }
int main(void) { struct api_signature *sig = NULL; int load_type, load_unit, load_slice, load_partition; int i; const char * loaderdev; /* * If we can't find the magic signature and related info, exit with a * unique error code that U-Boot reports as "## Application terminated, * rc = 0xnnbadab1". Hopefully 'badab1' looks enough like "bad api" to * provide a clue. It's better than 0xffffffff anyway. */ if (!api_search_sig(&sig)) return (0x01badab1); syscall_ptr = sig->syscall; if (syscall_ptr == NULL) return (0x02badab1); if (sig->version > API_SIG_VERSION) return (0x03badab1); /* Clear BSS sections */ bzero(__sbss_start, __sbss_end - __sbss_start); bzero(__bss_start, _end - __bss_start); /* * Initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is safe. */ uboot_heap_start = round_page((uintptr_t)end); uboot_heap_end = uboot_heap_start + 512 * 1024; setheap((void *)uboot_heap_start, (void *)uboot_heap_end); /* * Set up console. */ cons_probe(); printf("Compatible U-Boot API signature found @%x\n", (uint32_t)sig); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); printf("\n"); dump_sig(sig); dump_addr_info(); meminfo(); /* * Enumerate U-Boot devices */ if ((devs_no = ub_dev_enum()) == 0) panic("no U-Boot devices found"); printf("Number of U-Boot devices: %d\n", devs_no); get_load_device(&load_type, &load_unit, &load_slice, &load_partition); /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; printf("Found U-Boot device: %s\n", devsw[i]->dv_name); currdev.d_dev = devsw[i]; currdev.d_type = currdev.d_dev->dv_type; currdev.d_unit = 0; if ((load_type == -1 || (load_type & DEV_TYP_STOR)) && strcmp(devsw[i]->dv_name, "disk") == 0) { if (probe_disks(i, load_type, load_unit, load_slice, load_partition) == 0) break; } if ((load_type == -1 || (load_type & DEV_TYP_NET)) && strcmp(devsw[i]->dv_name, "net") == 0) break; } /* * If we couldn't find a boot device, return an error to u-boot. * U-boot may be running a boot script that can try something different * so returning an error is better than forcing a reboot. */ if (devsw[i] == NULL) { printf("No boot device found!\n"); return (0xbadef1ce); } env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev), uboot_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ setenv("prompt", "loader>", 1); archsw.arch_loadaddr = uboot_loadaddr; archsw.arch_getdev = uboot_getdev; archsw.arch_copyin = uboot_copyin; archsw.arch_copyout = uboot_copyout; archsw.arch_readin = uboot_readin; archsw.arch_autoload = uboot_autoload; interact(); /* doesn't return */ return (0); }
void efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) { static EFI_GUID image_protocol = LOADED_IMAGE_PROTOCOL; EFI_LOADED_IMAGE *img; CHAR16 *argp, *args, **argv; EFI_STATUS status; int argc, addprog; IH = image_handle; ST = system_table; BS = ST->BootServices; RS = ST->RuntimeServices; heapsize = 512*1024; status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, EFI_SIZE_TO_PAGES(heapsize), &heap); if (status != EFI_SUCCESS) BS->Exit(IH, status, 0, NULL); setheap((void *)heap, (void *)(heap + heapsize)); /* Use exit() from here on... */ status = BS->HandleProtocol(IH, &image_protocol, (VOID**)&img); if (status != EFI_SUCCESS) exit(status); /* * Pre-process the (optional) load options. If the option string * is given as an ASCII string, we use a poor man's ASCII to * Unicode-16 translation. The size of the option string as given * to us includes the terminating null character. We assume the * string is an ASCII string if strlen() plus the terminating * '\0' is less than LoadOptionsSize. Even if all Unicode-16 * characters have the upper 8 bits non-zero, the terminating * null character will cause a one-off. * If the string is already in Unicode-16, we make a copy so that * we know we can always modify the string. */ if (img->LoadOptionsSize > 0 && img->LoadOptions != NULL) { if (img->LoadOptionsSize == strlen(img->LoadOptions) + 1) { args = malloc(img->LoadOptionsSize << 1); for (argc = 0; argc < img->LoadOptionsSize; argc++) args[argc] = ((char*)img->LoadOptions)[argc]; } else { args = malloc(img->LoadOptionsSize); memcpy(args, img->LoadOptions, img->LoadOptionsSize); } } else args = NULL; /* * Use a quick and dirty algorithm to build the argv vector. We * first count the number of words. Then, after allocating the * vector, we split the string up. We don't deal with quotes or * other more advanced shell features. * The EFI shell will pas the name of the image as the first * word in the argument list. This does not happen if we're * loaded by the boot manager. This is not so easy to figure * out though. The ParentHandle is not always NULL, because * there can be a function (=image) that will perform the task * for the boot manager. */ /* Part 1: Figure out if we need to add our program name. */ addprog = (args == NULL || img->ParentHandle == NULL || img->FilePath == NULL) ? 1 : 0; if (!addprog) { addprog = (DevicePathType(img->FilePath) != MEDIA_DEVICE_PATH || DevicePathSubType(img->FilePath) != MEDIA_FILEPATH_DP || DevicePathNodeLength(img->FilePath) <= sizeof(FILEPATH_DEVICE_PATH)) ? 1 : 0; if (!addprog) { /* XXX todo. */ } } /* Part 2: count words. */ argc = (addprog) ? 1 : 0; argp = args; while (argp != NULL && *argp != 0) { argp = arg_skipsep(argp); if (*argp == 0) break; argc++; argp = arg_skipword(argp); } /* Part 3: build vector. */ argv = malloc((argc + 1) * sizeof(CHAR16*)); argc = 0; if (addprog) argv[argc++] = L"loader.efi"; argp = args; while (argp != NULL && *argp != 0) { argp = arg_skipsep(argp); if (*argp == 0) break; argv[argc++] = argp; argp = arg_skipword(argp); /* Terminate the words. */ if (*argp != 0) *argp++ = 0; } argv[argc] = NULL; status = main(argc, argv); exit(status); }
int main(void) { uint64_t maxmem = 0; void *heapbase; int i, err; struct ps3_devdesc currdev; struct open_file f; lv1_get_physmem(&maxmem); ps3mmu_init(maxmem); /* * Set up console. */ cons_probe(); /* * Set the heap to one page after the end of the loader. */ heapbase = (void *)(maxmem - 0x80000); setheap(heapbase, maxmem); /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_init != NULL) { err = (devsw[i]->dv_init)(); if (err) { printf("\n%s: initialization failed err=%d\n", devsw[i]->dv_name, err); continue; } } currdev.d_dev = devsw[i]; currdev.d_type = currdev.d_dev->dv_type; if (strcmp(devsw[i]->dv_name, "cd") == 0) { f.f_devdata = &currdev; currdev.d_unit = 0; if (devsw[i]->dv_open(&f, &currdev) == 0) break; } if (strcmp(devsw[i]->dv_name, "disk") == 0) { f.f_devdata = &currdev; currdev.d_unit = 3; currdev.d_disk.pnum = 1; currdev.d_disk.ptype = PTYPE_GPT; if (devsw[i]->dv_open(&f, &currdev) == 0) break; } if (strcmp(devsw[i]->dv_name, "net") == 0) break; } if (devsw[i] == NULL) panic("No boot device found!"); else printf("Boot device: %s\n", devsw[i]->dv_name); /* * Get timebase at boot. */ basetb = mftb(); archsw.arch_getdev = ps3_getdev; archsw.arch_copyin = ps3_copyin; archsw.arch_copyout = ps3_copyout; archsw.arch_readin = ps3_readin; archsw.arch_autoload = ps3_autoload; printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); printf("Memory: %lldKB\n", maxmem / 1024); env_setenv("currdev", EV_VOLATILE, ps3_fmtdev(&currdev), ps3_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, ps3_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); setenv("hw.platform", "ps3", 1); interact(); /* doesn't return */ return (0); }
void loader_main(struct loader_callbacks *cb, void *arg, int version, int ndisks) { static char mallocbuf[MALLOCSZ]; const char *var; int i; if (version < USERBOOT_VERSION) abort(); callbacks = cb; callbacks_arg = arg; userboot_disk_maxunit = ndisks; /* * initialise the heap as early as possible. Once this is done, * alloc() is usable. */ setheap((void *)mallocbuf, (void *)(mallocbuf + sizeof(mallocbuf))); /* * Hook up the console */ cons_probe(); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); #if 0 printf("Memory: %ld k\n", memsize() / 1024); #endif setenv("LINES", "24", 1); /* optional */ /* * Set custom environment variables */ i = 0; while (1) { var = CALLBACK(getenv, i++); if (var == NULL) break; putenv(var); } archsw.arch_autoload = userboot_autoload; archsw.arch_getdev = userboot_getdev; archsw.arch_copyin = userboot_copyin; archsw.arch_copyout = userboot_copyout; archsw.arch_readin = userboot_readin; #if defined(USERBOOT_ZFS_SUPPORT) archsw.arch_zfs_probe = userboot_zfs_probe; #endif /* * Initialise the block cache. Set the upper limit. */ bcache_init(32768, 512); /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); extract_currdev(); if (setjmp(jb)) return; interact(NULL); /* doesn't return */ exit(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(); }
int main(void) { int i; /* Set machine type to PC98_SYSTEM_PARAMETER. */ set_machine_type(); /* Pick up arguments */ kargs = (void *)__args; initial_howto = kargs->howto; initial_bootdev = kargs->bootdev; initial_bootinfo = kargs->bootinfo ? (struct bootinfo *)PTOV(kargs->bootinfo) : NULL; /* Initialize the v86 register set to a known-good state. */ bzero(&v86, sizeof(v86)); v86.efl = PSL_RESERVED_DEFAULT | PSL_I; /* * Initialise the heap as early as possible. Once this is done, malloc() is usable. */ bios_getmem(); #if defined(LOADER_BZIP2_SUPPORT) if (high_heap_size > 0) { heap_top = PTOV(high_heap_base + high_heap_size); heap_bottom = PTOV(high_heap_base); if (high_heap_base < memtop_copyin) memtop_copyin = high_heap_base; } else #endif { heap_top = (void *)PTOV(bios_basemem); heap_bottom = (void *)end; } setheap(heap_bottom, heap_top); /* * XXX Chicken-and-egg problem; we want to have console output early, but some * console attributes may depend on reading from eg. the boot device, which we * can't do yet. * * We can use printf() etc. once this is done. * If the previous boot stage has requested a serial console, prefer that. */ bi_setboothowto(initial_howto); if (initial_howto & RB_MULTIPLE) { if (initial_howto & RB_SERIAL) setenv("console", "comconsole vidconsole", 1); else setenv("console", "vidconsole comconsole", 1); } else if (initial_howto & RB_SERIAL) setenv("console", "comconsole", 1); else if (initial_howto & RB_MUTE) setenv("console", "nullconsole", 1); cons_probe(); /* * Initialise the block cache */ bcache_init(32, 512); /* 16k cache XXX tune this */ /* * Special handling for PXE and CD booting. */ if (kargs->bootinfo == 0) { /* * We only want the PXE disk to try to init itself in the below * walk through devsw if we actually booted off of PXE. */ if (kargs->bootflags & KARGS_FLAGS_PXE) pxe_enable(kargs->pxeinfo ? PTOV(kargs->pxeinfo) : NULL); else if (kargs->bootflags & KARGS_FLAGS_CD) bc_add(initial_bootdev); } archsw.arch_autoload = i386_autoload; archsw.arch_getdev = i386_getdev; archsw.arch_copyin = i386_copyin; archsw.arch_copyout = i386_copyout; archsw.arch_readin = i386_readin; archsw.arch_isainb = isa_inb; archsw.arch_isaoutb = isa_outb; archsw.arch_loadaddr = pc98_loadaddr; /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024, bios_extmem / 1024); if (initial_bootinfo != NULL) { initial_bootinfo->bi_basemem = bios_basemem / 1024; initial_bootinfo->bi_extmem = bios_extmem / 1024; } printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); extract_currdev(); /* set $currdev and $loaddev */ setenv("LINES", "24", 1); /* optional */ interact(); /* doesn't return */ /* if we ever get here, it is an error */ return (1); }
int main(void) { char *memend; int i; WDEBUG_INIT(); WDEBUG('X'); /* Pick up arguments */ kargs = (void *)__args; initial_howto = kargs->howto; initial_bootdev = kargs->bootdev; initial_bootinfo = kargs->bootinfo ? (struct bootinfo *)PTOV(kargs->bootinfo) : NULL; #ifdef COMCONSOLE_DEBUG printf("args at %p initial_howto = %08x bootdev = %08x bootinfo = %p\n", kargs, initial_howto, initial_bootdev, initial_bootinfo); #endif /* Initialize the v86 register set to a known-good state. */ bzero(&v86, sizeof(v86)); v86.efl = PSL_RESERVED_DEFAULT | PSL_I; /* * Initialize the heap as early as possible. Once this is done, * malloc() is usable. * * Don't include our stack in the heap. If the stack is in low * user memory use {end,bios_basemem}. If the stack is in high * user memory but not extended memory then don't let the heap * overlap the stack. If the stack is in extended memory limit * the heap to bios_basemem. * * Be sure to use the virtual bios_basemem address rather then * the physical bios_basemem address or we may overwrite BIOS * data. */ bios_getmem(); memend = (char *)&memend - 0x8000; /* space for stack (16K) */ memend = (char *)((uintptr_t)memend & ~(uintptr_t)(0x1000 - 1)); /* * For day to day usage simple memend setup is more than engouh, * but bigger heap is a must for loading bzipp'ed kernel/modules * "bzf_read: BZ2_bzDecompress returned -3" */ #if defined(LOADER_BZIP2_SUPPORT) if (high_heap_size > 0) { heap_top = PTOV(high_heap_base + high_heap_size); heap_bottom = PTOV(high_heap_base); if (high_heap_base < memtop_copyin) memtop_copyin = high_heap_base; } else #endif if (memend < (char *)_end) { heap_top = PTOV(bios_basemem); heap_bottom = (void *)_end; } else { if (memend > (char *)PTOV(bios_basemem)) memend = (char *)PTOV(bios_basemem); heap_top = memend; heap_bottom = (void *)_end; } setheap(heap_bottom, heap_top); /* * XXX Chicken-and-egg problem; we want to have console output early, * but some console attributes may depend on reading from eg. the boot * device, which we can't do yet. * * We can use printf() etc. once this is done. The previous boot stage * might have requested a video or serial preference, in which case we * set it. */ bi_setboothowto(initial_howto); if (initial_howto & RB_MUTE) { setenv("console", "nullconsole", 1); } else if ((initial_howto & (RB_VIDEO|RB_SERIAL)) == (RB_VIDEO|RB_SERIAL)) { setenv("console", "vidconsole comconsole", 1); } else if (initial_howto & RB_VIDEO) { setenv("console", "vidconsole", 1); } else if (initial_howto & RB_SERIAL) { setenv("console", "comconsole", 1); } else { /* XXX leave to cons_probe() */ } cons_probe(); /* * Initialise the block cache */ bcache_init(32, 512); /* 16k cache XXX tune this */ /* * Special handling for PXE and CD booting. */ if (kargs->bootinfo == 0) { /* * We only want the PXE disk to try to init itself in the below * walk through devsw if we actually booted off of PXE. */ if (kargs->bootflags & KARGS_FLAGS_PXE) pxe_enable(kargs->pxeinfo ? PTOV(kargs->pxeinfo) : NULL); else if (kargs->bootflags & KARGS_FLAGS_CD) bc_add(initial_bootdev); } archsw.arch_autoload = i386_autoload; archsw.arch_getdev = i386_getdev; archsw.arch_copyin = i386_copyin; archsw.arch_copyout = i386_copyout; archsw.arch_readin = i386_readin; archsw.arch_isainb = isa_inb; archsw.arch_isaoutb = isa_outb; /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) { WDEBUG('M' + i); if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); WDEBUG('M' + i); } printf("BIOS %dkB/%dkB available memory\n", bios_basemem / 1024, bios_extmem / 1024); if (initial_bootinfo != NULL) { initial_bootinfo->bi_basemem = bios_basemem / 1024; initial_bootinfo->bi_extmem = bios_extmem / 1024; } /* detect ACPI for future reference */ biosacpi_detect(); /* detect SMBIOS for future reference */ smbios_detect(NULL); /* detect PCI BIOS for future reference */ biospci_detect(); /* enable EHCI */ setenv("ehci_load", "YES", 1); /* enable XHCI */ setenv("xhci_load", "YES", 1); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); extract_currdev(); /* set $currdev and $loaddev */ setenv("LINES", "24", 1); /* optional */ bios_getsmap(); interact(); /* doesn't return */ /* if we ever get here, it is an error */ return (1); }
void efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) { static EFI_GUID image_protocol = LOADED_IMAGE_PROTOCOL; static EFI_GUID console_control_protocol = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; EFI_CONSOLE_CONTROL_PROTOCOL *console_control = NULL; EFI_LOADED_IMAGE *img; CHAR16 *argp, *args, **argv; EFI_STATUS status; SIMPLE_TEXT_OUTPUT_INTERFACE *conout; UINTN i, max_dim, best_mode, cols, rows; int argc, addprog; IH = image_handle; ST = system_table; BS = ST->BootServices; RS = ST->RuntimeServices; status = BS->LocateProtocol(&console_control_protocol, NULL, (VOID **)&console_control); if (status == EFI_SUCCESS) (void)console_control->SetMode(console_control, EfiConsoleControlScreenText); conout = ST->ConOut; max_dim = best_mode = 0; for (i = 0; i <= conout->Mode->MaxMode ; i++) { status = conout->QueryMode(conout, i, &cols, &rows); if (EFI_ERROR(status)) continue; if (cols * rows > max_dim) { max_dim = cols * rows; best_mode = i; } } if (max_dim > 0) conout->SetMode(conout, best_mode); heapsize = 64 * 1024 * 1024; /* 4GB upper limit, try to leave some space from 1MB */ heap = 0x0000000100000000; status = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, EFI_SIZE_TO_PAGES(heapsize), &heap); if (status != EFI_SUCCESS) BS->Exit(IH, status, 0, NULL); setheap((void *)(uintptr_t)heap, (void *)(uintptr_t)(heap + heapsize)); status = conout->QueryMode(conout, best_mode, &cols, &rows); if (EFI_ERROR(status)) { setenv("LINES", "24", 1); setenv("COLUMNS", "80", 1); } else { char buf[8]; snprintf(buf, sizeof (buf), "%u", (unsigned)rows); setenv("LINES", buf, 1); snprintf(buf, sizeof (buf), "%u", (unsigned)cols); setenv("COLUMNS", buf, 1); } /* Use exit() from here on... */ status = BS->HandleProtocol(IH, &image_protocol, (VOID**)&img); if (status != EFI_SUCCESS) exit(status); /* * Pre-process the (optional) load options. If the option string * is given as an ASCII string, we use a poor man's ASCII to * Unicode-16 translation. The size of the option string as given * to us includes the terminating null character. We assume the * string is an ASCII string if strlen() plus the terminating * '\0' is less than LoadOptionsSize. Even if all Unicode-16 * characters have the upper 8 bits non-zero, the terminating * null character will cause a one-off. * If the string is already in Unicode-16, we make a copy so that * we know we can always modify the string. */ if (img->LoadOptionsSize > 0 && img->LoadOptions != NULL) { if (img->LoadOptionsSize == strlen(img->LoadOptions) + 1) { args = malloc(img->LoadOptionsSize << 1); for (argc = 0; argc < img->LoadOptionsSize; argc++) args[argc] = ((char*)img->LoadOptions)[argc]; } else { args = malloc(img->LoadOptionsSize); memcpy(args, img->LoadOptions, img->LoadOptionsSize); } } else args = NULL; /* * Use a quick and dirty algorithm to build the argv vector. We * first count the number of words. Then, after allocating the * vector, we split the string up. We don't deal with quotes or * other more advanced shell features. * The EFI shell will pass the name of the image as the first * word in the argument list. This does not happen if we're * loaded by the boot manager. This is not so easy to figure * out though. The ParentHandle is not always NULL, because * there can be a function (=image) that will perform the task * for the boot manager. */ /* Part 1: Figure out if we need to add our program name. */ addprog = (args == NULL || img->ParentHandle == NULL || img->FilePath == NULL) ? 1 : 0; if (!addprog) { addprog = (DevicePathType(img->FilePath) != MEDIA_DEVICE_PATH || DevicePathSubType(img->FilePath) != MEDIA_FILEPATH_DP || DevicePathNodeLength(img->FilePath) <= sizeof(FILEPATH_DEVICE_PATH)) ? 1 : 0; if (!addprog) { /* XXX todo. */ } } /* Part 2: count words. */ argc = (addprog) ? 1 : 0; argp = args; while (argp != NULL && *argp != 0) { argp = arg_skipsep(argp); if (*argp == 0) break; argc++; argp = arg_skipword(argp); } /* Part 3: build vector. */ argv = malloc((argc + 1) * sizeof(CHAR16*)); argc = 0; if (addprog) argv[argc++] = (CHAR16 *)L"loader.efi"; argp = args; while (argp != NULL && *argp != 0) { argp = arg_skipsep(argp); if (*argp == 0) break; argv[argc++] = argp; argp = arg_skipword(argp); /* Terminate the words. */ if (*argp != 0) *argp++ = 0; } argv[argc] = NULL; status = main(argc, argv); exit(status); }
void ski_main(void) { static char malloc[512*1024]; int i; /* * initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is * safe. */ setheap((void *)malloc, (void *)(malloc + 512*1024)); /* * XXX Chicken-and-egg problem; we want to have console output * early, but some console attributes may depend on reading from * eg. the boot device, which we can't do yet. We can use * printf() etc. once this is done. */ cons_probe(); /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) if (devsw[i]->dv_init != NULL) (devsw[i]->dv_init)(); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); #if 0 printf("Memory: %ld k\n", memsize() / 1024); #endif /* XXX presumes that biosdisk is first in devsw */ currdev.d_dev = devsw[0]; currdev.d_type = currdev.d_dev->dv_type; currdev.d_unit = 0; #if 0 /* Create arc-specific variables */ bootfile = GetEnvironmentVariable(ARCENV_BOOTFILE); if (bootfile) setenv("bootfile", bootfile, 1); #endif env_setenv("currdev", EV_VOLATILE, ia64_fmtdev(&currdev), ia64_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, ia64_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ archsw.arch_autoload = ia64_autoload; archsw.arch_copyin = ia64_copyin; archsw.arch_copyout = ia64_copyout; archsw.arch_getdev = ia64_getdev; archsw.arch_loadaddr = ia64_loadaddr; archsw.arch_loadseg = ia64_loadseg; archsw.arch_readin = ia64_readin; interact(); /* doesn't return */ exit(0); }
void ski_main(void) { static char malloc[512*1024]; int i; /* * initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is * safe. */ setheap((void *)malloc, (void *)(malloc + 512*1024)); /* * XXX Chicken-and-egg problem; we want to have console output * early, but some console attributes may depend on reading from * eg. the boot device, which we can't do yet. We can use * printf() etc. once this is done. */ cons_probe(); /* * Initialise the block cache XXX: Fixme: do we need the bcache ? */ /* bcache_init(32, 512); */ /* 16k XXX tune this */ /* Initialise skifs.c */ skifs_dev_init(); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); #if 0 printf("Memory: %ld k\n", memsize() / 1024); #endif /* XXX presumes that biosdisk is first in devsw */ currdev.d_dev = &devsw[0]; currdev.d_type = DEVT_DISK; currdev.d_kind.skidisk.unit = 0; /* XXX should be able to detect this, default to autoprobe */ currdev.d_kind.skidisk.slice = -1; /* default to 'a' */ currdev.d_kind.skidisk.partition = 0; #if 0 /* Create arc-specific variables */ bootfile = GetEnvironmentVariable(ARCENV_BOOTFILE); if (bootfile) setenv("bootfile", bootfile, 1); #endif env_setenv("currdev", EV_VOLATILE, ski_fmtdev(&currdev), (ev_sethook_t *) ski_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, ski_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ archsw.arch_autoload = ski_autoload; archsw.arch_getdev = ski_getdev; archsw.arch_copyin = ski_copyin; archsw.arch_copyout = ski_copyout; archsw.arch_readin = ski_readin; interact(); /* doesn't return */ exit(0); }
int main(void) { struct api_signature *sig = NULL; int diskdev, i, netdev, usedev; struct open_file f; const char * loaderdev; if (!api_search_sig(&sig)) return (-1); syscall_ptr = sig->syscall; if (syscall_ptr == NULL) return (-2); if (sig->version > API_SIG_VERSION) return (-3); /* Clear BSS sections */ bzero(__sbss_start, __sbss_end - __sbss_start); bzero(__bss_start, _end - __bss_start); /* * Set up console. */ cons_probe(); printf("Compatible API signature found @%x\n", (uint32_t)sig); dump_sig(sig); dump_addr_info(); /* * Initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is * safe. */ setheap((void *)end, (void *)(end + 512 * 1024)); /* * Enumerate U-Boot devices */ if ((devs_no = ub_dev_enum()) == 0) panic("no U-Boot devices found"); printf("Number of U-Boot devices: %d\n", devs_no); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); meminfo(); /* * March through the device switch probing for things -- sort of. * * The devsw array will have one or two items in it. If * LOADER_DISK_SUPPORT is defined the first item will be a disk (which * may not actually work if u-boot didn't supply one). If * LOADER_NET_SUPPORT is defined the next item will be a network * interface. Again it may not actually work at the u-boot level. * * The original logic was to always use a disk if it could be * successfully opened, otherwise use the network interface. Now that * logic is amended to first check whether the u-boot environment * contains a loaderdev variable which tells us which device to use. If * it does, we use it and skip the original (second) loop which "probes" * for a device. We still loop over the devsw just in case it ever gets * expanded to hold more than 2 devices (but then unit numbers, which * don't currently exist, may come into play). If the device named by * loaderdev isn't found, fall back using to the old "probe" loop. * * The original probe loop still effectively behaves as it always has: * the first usable disk device is choosen, and a network device is used * only if no disk device is found. The logic has been reworked so that * it examines (and thus lists) every potential device along the way * instead of breaking out of the loop when the first device is found. */ loaderdev = ub_env_get("loaderdev"); usedev = -1; if (loaderdev != NULL) { for (i = 0; devsw[i] != NULL; i++) { if (strcmp(loaderdev, devsw[i]->dv_name) == 0) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; usedev = i; goto have_device; } } printf("U-Boot env contains 'loaderdev=%s', " "device not found.\n", loaderdev); } printf("Probing for bootable devices...\n"); diskdev = -1; netdev = -1; for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; printf("Bootable device: %s\n", devsw[i]->dv_name); if (strncmp(devsw[i]->dv_name, "disk", strlen(devsw[i]->dv_name)) == 0) { f.f_devdata = &currdev; currdev.d_dev = devsw[i]; currdev.d_type = currdev.d_dev->dv_type; currdev.d_unit = 0; currdev.d_disk.slice = 0; if (devsw[i]->dv_open(&f, &currdev) == 0) { devsw[i]->dv_close(&f); if (diskdev == -1) diskdev = i; } } else if (strncmp(devsw[i]->dv_name, "net", strlen(devsw[i]->dv_name)) == 0) { if (netdev == -1) netdev = i; } } if (diskdev != -1) usedev = diskdev; else if (netdev != -1) usedev = netdev; else panic("No bootable devices found!\n"); have_device: currdev.d_dev = devsw[usedev]; currdev.d_type = devsw[usedev]->dv_type; currdev.d_unit = 0; if (currdev.d_type == DEV_TYP_STOR) currdev.d_disk.slice = 0; printf("Current device: %s\n", currdev.d_dev->dv_name); env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev), uboot_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ setenv("prompt", "loader>", 1); archsw.arch_getdev = uboot_getdev; archsw.arch_copyin = uboot_copyin; archsw.arch_copyout = uboot_copyout; archsw.arch_readin = uboot_readin; archsw.arch_autoload = uboot_autoload; interact(); /* doesn't return */ return (0); }
int main(void) { struct api_signature *sig = NULL; int i; struct open_file f; if (!api_search_sig(&sig)) return (-1); syscall_ptr = sig->syscall; if (syscall_ptr == NULL) return (-2); if (sig->version > API_SIG_VERSION) return (-3); /* Clear BSS sections */ bzero(__sbss_start, __sbss_end - __sbss_start); bzero(__bss_start, _end - __bss_start); /* * Set up console. */ cons_probe(); printf("Compatible API signature found @%x\n", (uint32_t)sig); dump_sig(sig); dump_addr_info(); /* * Initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is * safe. */ setheap((void *)end, (void *)(end + 512 * 1024)); /* * Enumerate U-Boot devices */ if ((devs_no = ub_dev_enum()) == 0) panic("no U-Boot devices found"); printf("Number of U-Boot devices: %d\n", devs_no); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); meminfo(); /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; printf("\nDevice: %s\n", devsw[i]->dv_name); currdev.d_dev = devsw[i]; currdev.d_type = currdev.d_dev->dv_type; currdev.d_unit = 0; if (strncmp(devsw[i]->dv_name, "disk", strlen(devsw[i]->dv_name)) == 0) { f.f_devdata = &currdev; currdev.d_disk.slice = 0; if (devsw[i]->dv_open(&f,&currdev) == 0) break; } if (strncmp(devsw[i]->dv_name, "net", strlen(devsw[i]->dv_name)) == 0) break; } if (devsw[i] == NULL) panic("No boot device found!"); env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev), uboot_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ setenv("prompt", "loader>", 1); archsw.arch_getdev = uboot_getdev; archsw.arch_copyin = uboot_copyin; archsw.arch_copyout = uboot_copyout; archsw.arch_readin = uboot_readin; archsw.arch_autoload = uboot_autoload; interact(); /* doesn't return */ return (0); }