void boot2(int biosdev, u_int biossector) { extern char twiddle_toggle; twiddle_toggle = 1; /* no twiddling until we're ready */ printf("\f"); /* clear screen (hopefully) */ initio(boot_params.bp_consdev); #ifdef SUPPORT_PS2 biosmca(); #endif gateA20(); if (boot_params.bp_flags & X86_BP_FLAGS_RESET_VIDEO) biosvideomode(); twiddle_toggle = 0; printf("\n" ">> %s, Revision %s (from NetBSD %s)\n" ">> for Book:Lambda Ka Musume\n", bootprog_name, bootprog_rev, bootprog_kernrev); while (1) { step(); } }
/************************************************************************** MAIN - Kick off routine **************************************************************************/ main() { int c; extern char edata[], end[]; bzero(edata,end-edata); /* Zero BSS */ #ifdef ASK_BOOT while (1) { printf("\nBoot from Network (Y/N) ? "); c = getchar(); if ((c >= 'a') && (c <= 'z')) c &= 0x5F; if (c == '\r') break; putchar(c); if (c == 'N') exit(0); if (c == 'Y') break; printf(" - bad response\n"); } #endif /* get the bios's idea about the disks geometry */ #ifdef PC98 for(c = 0; c < 2; c ++) { if (*(unsigned char*)0xa155d & (1 << c)) { /* check DISK_EQUIP */ bootinfo.bi_bios_geom[c] = get_diskinfo(c + 0x80); } } #else /* IBM-PC */ for(c = 0; c < N_BIOS_GEOM; c ++) bootinfo.bi_bios_geom[c] = get_diskinfo(c + 0x80); #endif /* PC98 */ gateA20(); #ifdef PC98 /* set machine type to PC98_SYSTEM_PARAMETER */ machine_check(); #endif printf("\nBOOTP/TFTP/NFS bootstrap loader ESC for menu\n" "\nSearching for adapter..."); if (!eth_probe()) { printf("No adapter found.\n"); exit(0); } kernel = DEFAULT_BOOTFILE; while (1) { if (setjmp(jmp_bootmenu)) bootmenu(); else load(); } }
/* NORETURN */ void boot(int drive) { int ret; #ifdef PC98 int i; unsigned char disk_equips; #endif /* Pick up the story from the Bios on geometry of disks */ #ifdef PC98 for(ret = 0; ret < 2; ret ++) { if (*(unsigned char*)V(0xA155d) & (1 << ret)) { bootinfo.bi_bios_geom[ret] = get_diskinfo(ret + 0x80); } #else /* IBM-PC */ for(ret = 0; ret < N_BIOS_GEOM; ret ++) bootinfo.bi_bios_geom[ret] = get_diskinfo(ret + 0x80); #endif /* PC98 */ } bootinfo.bi_basemem = memsize(0); bootinfo.bi_extmem = memsize(1); bootinfo.bi_memsizes_valid = 1; gateA20(); #ifdef PC98 /* set machine type to PC98_SYSTEM_PARAMETER */ machine_check(); #endif /* PC98 */ /* * The default boot device is the first partition in the * compatibility slice on the boot drive. */ dosdev = drive; #ifdef PC98 maj = (drive&0x70) >> 3; /* a good first bet */ if (maj == 4) { /* sd */ disk_equips = *(unsigned char *)V(0xA1482); unit = 0; for (i=0; i<(drive&0x0f); i++) { unit += (disk_equips >> i) & 1; } } else {
/* This queries for BIOS information. */ void init_bios_info (void) { #ifndef STAGE1_5 unsigned long cont, memtmp, addr; int drive; #endif /* * Get information from BIOS on installed RAM. */ mbi.mem_lower = get_memsize (0); mbi.mem_upper = get_memsize (1); #ifndef STAGE1_5 /* * We need to call this somewhere before trying to put data * above 1 MB, since without calling it, address line 20 will be wired * to 0. Not too desirable. */ gateA20 (1); /* Store the size of extended memory in EXTENDED_MEMORY, in order to tell it to non-Multiboot OSes. */ extended_memory = mbi.mem_upper; /* * The "mbi.mem_upper" variable only recognizes upper memory in the * first memory region. If there are multiple memory regions, * the rest are reported to a Multiboot-compliant OS, but otherwise * unused by GRUB. */ addr = get_code_end (); mbi.mmap_addr = addr; mbi.mmap_length = 0; cont = 0; do { cont = get_mmap_entry ((void *) addr, cont); /* If the returned buffer's length is zero, quit. */ if (! *((unsigned long *) addr)) break; mbi.mmap_length += *((unsigned long *) addr) + 4; addr += *((unsigned long *) addr) + 4; } while (cont); if (mbi.mmap_length) { unsigned long long max_addr; unsigned long mem_lower = mmap_avail_at (0) >> 10; /* * This is to get the lower memory, and upper memory (up to the * first memory hole), into the "mbi.mem_{lower,upper}" * elements. This is for OS's that don't care about the memory * map, but might care about total RAM available. */ if (mem_lower < mbi.mem_lower) mbi.mem_lower = mem_lower; mbi.mem_upper = mmap_avail_at (0x100000) >> 10; /* Find the maximum available address. Ignore any memory holes. */ for (max_addr = 0, addr = mbi.mmap_addr; addr < mbi.mmap_addr + mbi.mmap_length; addr += *((unsigned long *) addr) + 4) { struct AddrRangeDesc *desc = (struct AddrRangeDesc *) addr; if (desc->Type == MB_ARD_MEMORY && desc->Length > 0 && desc->BaseAddr + desc->Length > max_addr) max_addr = desc->BaseAddr + desc->Length; } extended_memory = (max_addr - 0x100000) >> 10; }
void boot(int drive) { int addr; int top; int kern_entry; int boot_start; int boot_region_desc; int boot_thread_state; unsigned int size; int env_start; int env_size = 0; char *p; char *env = 0; char *defaults = 0; int defaults_size = 0; int i; int idt[2]; delayprompt = 10; /* default to 10s at the prompt */ switch(drive) { case BIOS_DEV_FLOPPY: dev = DEV_FLOPPY; break; case BIOS_FAKE_WD: dev = DEV_WD; break; case BIOS_DEV_WIN: default: dev = DEV_HD; break; } cnvmem = memsize(0); extmem = memsize(1); printf("\n>> Secondary Mach boot %s\n>> %d/%dk (? for help, ^C for intr)\n", VERSIONDATE, cnvmem, extmem); #ifdef DEBUG printf("end x%x data 0x%x\n",end,edata); #endif /* sanity check: */ if ((int)end > KALLOC_OFFSET || (int)end > (BOOTSTACK-0x300)) { printf("Size problem: 0x%x > 0x%x\n",end, ((int)end > KALLOC_OFFSET)?KALLOC_OFFSET:BOOTSTACK-0x300); } #if DEBUG if (debug) { printf("dev = %x\n", dev); printf("unit = %x\n", unit); printf("part = %x\n", part); } #endif #if 0 dev = DEV_HD; unit = 0; part = 0; #endif reset_pic(); /* Lilo breaks PIC, BIOS disk ints fail */ calibrate_delay(); /* adjust delay for i/o operation */ gateA20(); if (dev == DEV_FLOPPY && devfs()) { printf("No fd FS, using hd\n"); dev = DEV_HD; part = 0; } bcopy(MACH_KERNEL, kern_prog.name, sizeof(MACH_KERNEL)); bcopy(BOOTSTRAP, boot_prog.name, sizeof(BOOTSTRAP)); bcopy(MACH_BOOT_ENV, env_prog.name, sizeof(MACH_BOOT_ENV)); reload_env_file: if (openrd(env_prog.name, NULL) == 0 && fsize() != 0) { const char *value; /* * Read mach_boot environment file if exists */ printf("Reading defaults from %s:\n",env_prog.name); defaults_size = fsize()+1; if (defaults != (char *)0) free(defaults); defaults = (char *)malloc(defaults_size); read(defaults, defaults_size-1); *(defaults+defaults_size-1) = 0; printf("%s", defaults); for (p = defaults; p < defaults + defaults_size; p++) if (*p == '\n') *p = '\0'; value = get_env("CONSOLE", defaults, defaults_size); if (strcmp(value, "vga") == 0 || strcmp(value, "VGA") == 0) com_enabled = 0; /* WARNING: do not enable the remote console based * on the latter argument in an environment file, since * now, remote console enabling is decided by the primary * boot ONLY and passed along through secondary's. */ if (*get_env("PROMPT", defaults, defaults_size) == '1') prompt = 1; if (com_enabled && (value = get_env("COM1_SETUP", defaults, defaults_size))) com_setup(value); if (value = get_env("DELAYPROMPT", defaults, defaults_size)) { delayprompt = atoi(value); /* don't allow stupid values */ if (delayprompt < 3) delayprompt = 3; } } for (;;) { if ((!getbootline(kern_prog.name, boot_prog.name)) && defaults ) { /* * Get defaults from /mach_boot.env if any. */ const char *value; if (value = get_env("KERNEL_NAME", defaults, defaults_size)) { strcpy(kern_prog.name, (char *)value); strcpy(kern_prog.args, (char *)value); kern_prog.args_size = strlen(value)+1; } if (value = get_env("KERNEL_ARGS", defaults, defaults_size)) { char *args; args = kern_prog.args + kern_prog.args_size; while (*value) value = copyargs((char *)value, &args); kern_prog.args_size = args - kern_prog.args; } if (value = get_env("BOOTSTRAP_NAME", defaults, defaults_size)) { strcpy(boot_prog.name, (char *)value); strcpy(boot_prog.args, (char *)value); boot_prog.args_size = strlen(value)+1; } if (value = get_env("BOOTSTRAP_ARGS", defaults, defaults_size)) { char *args; args = boot_prog.args + boot_prog.args_size; while (*value) value = copyargs((char *)value, &args); boot_prog.args_size = args - boot_prog.args; } } if (cons_is_com) { printf("console is COM1\n"); /* check if we already enabled remote console? */ p = kern_prog.args + kern_prog.args_size; *p++ = '-'; *p++ = 'r'; *p++ = 0; kern_prog.args_size += 3; } addr = KERNEL_BOOT_ADDR; if (loadtext(&addr, &kern_prog)) { strcpy(env_prog.name, kern_prog.name); goto reload_env_file; } else if (loadprog(&addr, &kern_prog)) { printf("Can't load %s\n", kern_prog.name); usage(); continue; } kern_entry = entry; if (dev == DEV_WD) net_get_root_device(); env_start = addr; if (openrd("/mach_servers/environment", NULL) == 0 && fsize() != 0) { unsigned int total = fsize()+1; printf("Loading environment from /mach_servers/environment\n"); env = (char *)malloc(total); read(env, total-1); *(env+total-1) = 0; for (p = env; p < env + total; p++) if (*p == '\n') *p = '\0'; pcpy(env, (void *)addr, total); addr += total; env_size += total; free(env); } env = (char *)malloc(BOOT_LINE_LENGTH); #if BOOT_ENV_COMPAT /* should go away when all kernels are converted to use BOOT_DEVICE */ p = env; strcpy(p, "BOOTOFFSET="); p = itoa(p + strlen(p), boff) + 1; strcpy(p, "BOOTDEV=hd"); p += strlen(p)+1; *(p-3) = dev; strcpy(p, "BOOTUNIT="); p = itoa(p + strlen(p), unit) + 1; strcpy(p, "BOOTPART="); p = itoa(p + strlen(p), part) + 1; size = p - env; pcpy(env, (void *)addr, size); addr += size; env_size += size; #endif /* BOOT_ENV_COMPAT */ p = env; strcpy(p, "BOOT_DEVICE=hd"); p += strlen(p); *(p-2) = dev; p = itoa(p, unit); *p++ = 'a'+part; size = p - env; pcpy(env, (void *)addr, size); addr += size; env_size += size; free(env); if (strncmp("none",boot_prog.name,sizeof("none"))==0 ||strncmp("null",boot_prog.name,sizeof("null"))==0) { boot_start = 0; boot_region_desc = 0; boot_prog.sym_start = 0; boot_prog.sym_size = 0; boot_prog.args_start = 0; boot_prog.args_size = 0; region_count = 0; boot_thread_state = 0; top = page_align(addr); goto boot_kernel_only; } boot_start = addr = page_align(addr); if (loadprog(&addr, &boot_prog)) { printf("Can't load %s\n", boot_prog.name); usage(); continue; } boot_region_desc = addr; addr = boot_region_desc + (region_count * sizeof(regions[0])); pcpy(regions, (void *) boot_region_desc, addr - boot_region_desc); boot_thread_state = addr; addr += sizeof(thread_state); pcpy(&thread_state, (void *) boot_thread_state, addr - boot_thread_state); top = page_align(addr); boot_kernel_only: #ifdef DEBUG if (debug) { printf("startprog(\n"); printf(" entry 0x%x,\n", kern_entry); printf(" -1,\n"); printf(" extmem 0x%x,\n", extmem); printf(" cnvmem 0x%x,\n", cnvmem); printf(" kern_sym_start 0x%x,\n", kern_prog.sym_start); printf(" kern_sym_size 0x%x,\n", kern_prog.sym_size); printf(" kern_args_start 0x%x,\n", kern_prog.args_start); printf(" kern_args_size 0x%x,\n", kern_prog.args_size); for (p = kern_prog.args; p < &kern_prog.args[kern_prog.args_size]; p += strlen(p)+1) printf("<%s>", p); printf("\n"); printf(" boot_sym_start 0x%x,\n", boot_prog.sym_start); printf(" boot_sym_size 0x%x,\n", boot_prog.sym_size); printf(" boot_args_start 0x%x,\n", boot_prog.args_start); printf(" boot_args_size 0x%x,\n", boot_prog.args_size); for (p = boot_prog.args; p < &boot_prog.args[boot_prog.args_size]; p += strlen(p)+1) printf("<%s>", p); printf("\n"); printf(" boot_start 0x%x,\n", boot_start); printf(" boot_size 0x%x,\n", boot_prog.sym_start - boot_start); printf(" boot_region_desc 0x%x,\n", boot_region_desc); printf(" boot_region_count 0x%x,\n", region_count); printf(" boot_thread_state_flavor %d,\n", THREAD_SYSCALL_STATE); printf(" boot_thread_state 0x%x (eip 0x%x, esp 0x%x),\n", boot_thread_state, thread_state.eip, thread_state.esp); printf(" boot_thread_state_count %d,\n", (int) i386_THREAD_SYSCALL_STATE_COUNT); printf(" env_start 0x%x,\n", env_start); printf(" env_size 0x%x,\n", env_size); printf(" top 0x%x)\n", (int) top); getchar(); continue; } #endif /* DEBUG */ /* * New calling convention * * %esp -> -1 * size of extended memory (K) * size of conventional memory (K) * kern_sym_start * kern_sym_size * kern_args_start * kern_args_size * boot_sym_start * boot_sym_size * boot_args_start * boot_args_size * boot_start * boot_size * boot_region_desc * boot_region_count * boot_thread_state_flavor * boot_thread_state * boot_thread_state_count * env_start * env_size * top of loaded memory */ startprog( kern_entry, -1, extmem, cnvmem, kern_prog.sym_start, kern_prog.sym_size, kern_prog.args_start, kern_prog.args_size, boot_prog.sym_start, boot_prog.sym_size, boot_prog.args_start, boot_prog.args_size, boot_start, boot_prog.sym_start - boot_start, boot_region_desc, region_count, THREAD_SYSCALL_STATE, boot_thread_state, i386_THREAD_SYSCALL_STATE_COUNT, env_start, env_size, top); } }
int main(void) { extern char twiddle_toggle; char c; twiddle_toggle = 1; /* no twiddling until we're ready */ #ifdef SUPPORT_SERIAL initio(SUPPORT_SERIAL); #else initio(CONSDEV_PC); #endif gateA20(); boot_modules_enabled = !(boot_params.bp_flags & X86_BP_FLAGS_NOMODULES); #ifndef SMALL if (!(boot_params.bp_flags & X86_BP_FLAGS_NOBOOTCONF)) { parsebootconf(BOOTCONF); } else { bootconf.timeout = boot_params.bp_timeout; } /* * If console set in boot.cfg, switch to it. * This will print the banner, so we don't need to explicitly do it */ if (bootconf.consdev) command_consdev(bootconf.consdev); else print_banner(); /* Display the menu, if applicable */ twiddle_toggle = 0; if (bootconf.nummenu > 0) { /* Does not return */ doboottypemenu(); } #else twiddle_toggle = 0; print_banner(); #endif printf("Press return to boot now, any other key for boot menu\n"); printf("booting netbsd - starting in "); #ifdef SMALL c = awaitkey(boot_params.bp_timeout, 1); #else c = awaitkey((bootconf.timeout < 0) ? 0 : bootconf.timeout, 1); #endif if ((c != '\r') && (c != '\n') && (c != '\0') && ((boot_params.bp_flags & X86_BP_FLAGS_PASSWORD) == 0 || check_password((char *)boot_params.bp_password))) { printf("type \"?\" or \"help\" for help.\n"); bootmenu(); /* does not return */ } /* * The file name provided here is just a default. If the * DHCP server provides a file name, we'll use that instead. */ bootit("netbsd", 0); /* * If that fails, let the BIOS try the next boot device. */ return (1); }
/* * Called from the initial entry point boot_start in biosboot.S * * biosdev: BIOS drive number the system booted from * biossector: Sector number of the NetBSD partition */ void boot2(int biosdev, uint64_t biossector) { extern char twiddle_toggle; int currname; char c; twiddle_toggle = 1; /* no twiddling until we're ready */ initio(boot_params.bp_consdev); #ifdef SUPPORT_PS2 biosmca(); #endif gateA20(); boot_modules_enabled = !(boot_params.bp_flags & X86_BP_FLAGS_NOMODULES); if (boot_params.bp_flags & X86_BP_FLAGS_RESET_VIDEO) biosvideomode(); vbe_init(); /* need to remember these */ boot_biosdev = biosdev; boot_biossector = biossector; /* try to set default device to what BIOS tells us */ bios2dev(biosdev, biossector, &default_devname, &default_unit, &default_partition); /* if the user types "boot" without filename */ default_filename = DEFFILENAME; #ifndef SMALL if (!(boot_params.bp_flags & X86_BP_FLAGS_NOBOOTCONF)) { parsebootconf(BOOTCONF); } else { bootconf.timeout = boot_params.bp_timeout; } /* * If console set in boot.cfg, switch to it. * This will print the banner, so we don't need to explicitly do it */ if (bootconf.consdev) command_consdev(bootconf.consdev); else print_banner(); /* Display the menu, if applicable */ twiddle_toggle = 0; if (bootconf.nummenu > 0) { /* Does not return */ doboottypemenu(); } #else twiddle_toggle = 0; print_banner(); #endif printf("Press return to boot now, any other key for boot menu\n"); for (currname = 0; currname < NUMNAMES; currname++) { printf("booting %s - starting in ", sprint_bootsel(names[currname][0])); #ifdef SMALL c = awaitkey(boot_params.bp_timeout, 1); #else c = awaitkey((bootconf.timeout < 0) ? 0 : bootconf.timeout, 1); #endif if ((c != '\r') && (c != '\n') && (c != '\0')) { if ((boot_params.bp_flags & X86_BP_FLAGS_PASSWORD) == 0) { /* do NOT ask for password */ bootmenu(); /* does not return */ } else { /* DO ask for password */ if (check_password((char *)boot_params.bp_password)) { /* password ok */ printf("type \"?\" or \"help\" for help.\n"); bootmenu(); /* does not return */ } else { /* bad password */ printf("Wrong password.\n"); currname = 0; continue; } } } /* * try pairs of names[] entries, foo and foo.gz */ /* don't print "booting..." again */ bootit(names[currname][0], 0, 0); /* since it failed, try compressed bootfile. */ bootit(names[currname][1], 0, 1); } bootmenu(); /* does not return */ }