📄 main.c
字号:
#include <bios/types.h>#include <bios/config.h>#include <bios/bootdev.h>#include <bios/pci.h>#include <bios/isa.h>#include <bios/malloc.h>#include <bios/time.h>#include <bios/timer.h>#include <bios/stdio.h>#include <bios/stdioint.h>#include <bios/string.h>#include <bios/system.h>#include <bios/debug.h>#include <bios/cfg.h>#include <bios/vga.h>#include <bios/x86.h>typedef enum { ram_failure, ram_ok} ram_test_t;typedef enum { boot_failure, boot_single, boot_multiple} boot_test_t;char extra_args[80];char *cmdline = "";extern struct bootdev boot_net;extern struct bootdev boot_ide;extern struct bootdev boot_scsi;extern struct bootdev boot_serial;static struct bootdev *first;static struct bootdev * const bootdevs[] = {#ifdef CONFIG_BOOT_IDE &boot_ide,#endif#ifdef CONFIG_BOOT_SCSI &boot_scsi,#endif#ifdef CONFIG_BOOT_NET &boot_net,#endif &boot_serial, NULL};extern unsigned long quick_ramtest(unsigned long, unsigned long);unsigned int ram_size;static ram_test_t ram_test(void){ unsigned int ptr; ram_test_t ret = ram_ok; printf(" KB SDRAM OK"); for (ptr = 0; ptr < ram_size; ptr += 64) { if (quick_ramtest(ptr, 0x55aacc33) != 0x55aacc33) { printf("\nMemory error detected at address 0x%08X\n", ptr); ret = ram_failure; break; } if ((ptr & 8191) == 0) printf("\r%6d", ptr >> 10); } if (ret == ram_ok) printf("\r%6d\n", ram_size >> 10); return ret;}extern int check_chunk(unsigned long ptr, void *save, int size);static void indepth_ram_test(void){ const unsigned int chunk_size = 512*1024; unsigned int ptr, ret; unsigned char *save_chunk; save_chunk = malloc(chunk_size + 16); if (!save_chunk) { cli(); printf("unable to allocate chunk for test\n"); return; } printf("Checking chunk %p... ", save_chunk + 16); sti(); ret = check_chunk((unsigned int)save_chunk + 16, save_chunk, chunk_size); cli(); if (ret != -1) { printf("failed - result was: %08lx %08lx %08lx %08lx\n", *(unsigned long *)save_chunk, *(unsigned long *)(save_chunk + 4), *(unsigned long *)(save_chunk + 8), *(unsigned long *)(save_chunk + 12)); free(save_chunk); return; } printf("ok\n"); for (ptr = 0; ptr < ram_size - 1048576; ptr += chunk_size) { printf("\rChecking chunk %08x...", ptr); sti(); ret = check_chunk(ptr, save_chunk, chunk_size); cli(); if (ret != -1) { printf("failed - result was: %08lx %08lx %08lx %08lx\n", *(unsigned long *)save_chunk, *(unsigned long *)(save_chunk + 4), *(unsigned long *)(save_chunk + 8), *(unsigned long *)(save_chunk + 12)); break; } } free(save_chunk);}static void boot_init(void){ struct bootdev **prev; int i; first = NULL; prev = &first; printf("Initialising devices:\n"); for (i = 0; bootdevs[i]; i++) { if (bootdevs[i]->init() == 0) { *prev = bootdevs[i]; prev = &bootdevs[i]->next; } else printf(" %s: not available\n", bootdevs[i]->name); }}void panic(const char *s){ if (s) printf("%s", s); printf(" -- System Halted"); while(1);}int img_nr;u32 root_dev;static void boot(void){ printf("Now booting image...\n"); sti(); boot_kernel();}static int do_boot(struct bootdev *dev){ int ret; ret = dev->start(); if (ret) return ret; ret = dev->load(); dev->stop(); if (ret == 0) boot(); return ret;}static void auto_boot(void){ struct bootdev *dev; for (dev = first; dev; dev = dev->next) { printf("Trying %s...\n", dev->name); do_boot(dev); }}static void manual_boot(void){ struct bootdev *bd; int c; bd = first; while (1) { printf("\014EBSA285 manual boot\n"); printf("1 - Boot method : %-10s\n", bd->name); printf("2 - Image number: %d\n", img_nr); printf("3 - Root device : 0x%04X\n", root_dev); printf("4 - Arguments : %s\n", extra_args); printf("\n"); printf("d - Restore default parameters\n"); printf("s - Store parameters to CMOS\n"); printf("l - Load parameters from CMOS\n"); printf("m - In-depth memory test\n"); printf("p - Display PCI configuration\n"); printf("b - Boot\n"); printf("\ncfg> "); c = getc(); printf("%c\n", c); switch (c) { case '1': bd = bd->next; if (bd == NULL) bd = first; break; case '2': { char str[6]; printf("\nImage number: "); gets(str, sizeof(str)); if (str[0]) img_nr = atol(str); } break; case '3': { char str[6]; printf("\nRoot device: "); gets(str, sizeof(str)); if (str[0]) root_dev = atol(str); } break; case '4': printf("\nExtra arguments: "); gets(extra_args, sizeof(extra_args)); break; case 'd': img_nr = 0; root_dev = 0x301; extra_args[0] = '\0'; break; case 'l': cfg_read(); break; case 's': cfg_write(); break; case 'b': do_boot(bd); printf("\n\nPress any key"); getc(); break; case 'm': indepth_ram_test(); printf("\n\nPress any key"); getc(); break; case 'p': pci_print_config(); printf("\n\nPress any key"); getc(); break; } } boot();}/* * This is the main entry point for the BIOS. */void start_main(void){ int i; debug_init(); /* Initialise serial debug */ malloc_init(); /* Initialise malloc pool */ time_init(); /* Initialise timers */ cli(); /* * Wait a while until the PCI * devices have properly reset. */ wait_cs(40); pci_init(); /* Initialise PCI sub-system */ kbd_init(); /* Initialise keyboard */ x86_init(); /* Initialise the x86 emulator */ vga_init(); /* Initialise VGA adapter */ cfg_init(); /* Initialise configuration */ printf("EBSA285 Linux BIOS v"VERSION"\n\n"); wait_cs(40); isa_init(); /* Initialise ISA */ /* Check integrity of RAM */ if (ram_test() == ram_failure) panic("ram failure"); printf("\n"); boot_init(); /* Initialise & detect devices */ printf("\nHit 's' twice to abort autoboot..."); i = 0; while (i != 2) { int c; c = getc_timed(1000); if (c == -1) break; printf("%c", c); if (c == 's') i += 1; else i = 0; } printf("\n"); if (i == 2) manual_boot(); else { printf("Starting autoboot\n"); auto_boot(); } panic("Waving my legs in the air wondering what to do next!\n\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -