diff options
| author | Michael Brown | 2006-03-17 15:09:45 +0100 |
|---|---|---|
| committer | Michael Brown | 2006-03-17 15:09:45 +0100 |
| commit | a2b15fd1febc77aecfc99b9d366b13f0bc17bebd (patch) | |
| tree | 47cef6e48756f1d39f6404af8de70023a72c10bb /src/filo/main | |
| parent | Prefix semantics have changed (diff) | |
| download | ipxe-a2b15fd1febc77aecfc99b9d366b13f0bc17bebd.tar.gz ipxe-a2b15fd1febc77aecfc99b9d366b13f0bc17bebd.tar.xz ipxe-a2b15fd1febc77aecfc99b9d366b13f0bc17bebd.zip | |
GPXE code cleanup and purge.
Diffstat (limited to 'src/filo/main')
| -rw-r--r-- | src/filo/main/console_x.c | 74 | ||||
| -rw-r--r-- | src/filo/main/elfload.c | 398 | ||||
| -rw-r--r-- | src/filo/main/elfnote.c | 153 | ||||
| -rw-r--r-- | src/filo/main/filo_x.c | 129 | ||||
| -rw-r--r-- | src/filo/main/lib.c | 56 | ||||
| -rw-r--r-- | src/filo/main/linuxbios_x.c | 124 | ||||
| -rw-r--r-- | src/filo/main/malloc_x.c | 45 | ||||
| -rw-r--r-- | src/filo/main/pci_x.c | 124 | ||||
| -rw-r--r-- | src/filo/main/printf_x.c | 400 |
9 files changed, 0 insertions, 1503 deletions
diff --git a/src/filo/main/console_x.c b/src/filo/main/console_x.c deleted file mode 100644 index fd04a9392..000000000 --- a/src/filo/main/console_x.c +++ /dev/null @@ -1,74 +0,0 @@ - -#include "etherboot.h" - -#include <lib.h> - -int getline(char *buf, int max) -{ - int cur, ch, nonspace_seen; - - cur = 0; - while (buf[cur]) { - putchar(buf[cur]); - cur++; - } - for (;;) { - ch = getchar(); - switch (ch) { - /* end of line */ - case '\r': - case '\n': - putchar('\n'); - goto out; - /* backspace */ - case '\b': - case '\x7f': - if (cur > 0) { - cur--; - putchar('\b'); - putchar(' '); - putchar('\b'); - } - break; - /* word erase */ - case 'W' & 0x1f: /* ^W */ - nonspace_seen = 0; - while (cur) { - if (buf[cur-1] != ' ') - nonspace_seen = 1; - putchar('\b'); - putchar(' '); - putchar('\b'); - cur--; - if (nonspace_seen && cur < max-1 && cur > 0 && buf[cur-1]==' ') - break; - } - break; - /* line erase */ - case 'U' & 0x1f: /* ^U */ - while (cur) { - putchar('\b'); - putchar(' '); - putchar('\b'); - cur--; - } - cur = 0; - break; - default: - if (ch < 0x20) - break; /* ignore control char */ - if (ch >= 0x7f) - break; - if (cur + 1 < max) { - putchar(ch); /* echo back */ - buf[cur] = ch; - cur++; - } - } - } -out: - if (cur >= max) - cur = max - 1; - buf[cur] = '\0'; - return cur; -} diff --git a/src/filo/main/elfload.c b/src/filo/main/elfload.c deleted file mode 100644 index 53114ffb7..000000000 --- a/src/filo/main/elfload.c +++ /dev/null @@ -1,398 +0,0 @@ -/* ELF Boot loader - * As we have seek, this implementation can be straightforward. - * 2003-07 by SONE Takeshi - */ -#include <etherboot.h> -#include <elf.h> -#include <bits/elf_x.h> -#include <elf_boot.h> -#include <lib.h> -#include <sys_info.h> - -#include <fs.h> -#define DEBUG_THIS DEBUG_ELFBOOT -#include <debug.h> - -#if 1 -//Use that in Etherboot -extern int elf_start(unsigned long __unused_i386, unsigned long entry, unsigned long param); -#define start_elf(x,y) elf_start(0, x, y) -#else -// original in filo -extern unsigned int start_elf(unsigned long entry_point, unsigned long param); -#endif - -extern char _virt_start[], _end[]; - -static char *image_name, *image_version; - -static int check_mem_ranges(struct sys_info *info, - Elf_phdr *phdr, int phnum) -{ - int i, j; - unsigned long start, end; - unsigned long prog_start, prog_end; -#if 0 - struct memrange *mem; -#else - struct e820entry *mem; -#endif - - prog_start = virt_to_phys(&_virt_start); - prog_end = virt_to_phys(&_end); - - for (i = 0; i < phnum; i++) { - if (phdr[i].p_type != PT_LOAD) - continue; - start = phdr[i].p_paddr; - end = start + phdr[i].p_memsz; - if (start < prog_start && end > prog_start) - goto conflict; - if (start < prog_end && end > prog_end) - goto conflict; -#if 0 - for (j = 0; j < info->n_memranges; j++) { - mem = &info->memrange[j]; - if (mem->base <= start && mem->base + mem->size >= end) - break; - } - if (j >= info->n_memranges) - goto badseg; -#else -#define LB_MEM_RAM 1 - for (j = 0; j < meminfo.map_count; j++) { - mem = &meminfo.map[j]; - if (mem->type!=LB_MEM_RAM) continue; - if (mem->addr <= start && mem->addr + mem->size >= end) - break; - } - if (j >= meminfo.map_count) - goto badseg; -#endif - } - return 1; - -conflict: - printf("%s occupies [%#lx-%#lx]\n", program_name, prog_start, prog_end); - -badseg: - printf("Segment %d [%#lx-%#lx] doesn't fit into memory\n", i, start, end-1); - return 0; -} - -static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, - unsigned short *sum_ptr) -{ - int i; - char *buf = NULL; - int retval = 0; - unsigned long addr, end; - Elf_Nhdr *nhdr; - const char *name; - void *desc; - - for (i = 0; i < phnum; i++) { - if (phdr[i].p_type != PT_NOTE) - continue; - buf = allot(phdr[i].p_filesz); - file_seek(phdr[i].p_offset); - if (file_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) { - printf("Can't read note segment\n"); - goto out; - } - addr = (unsigned long) buf; - end = addr + phdr[i].p_filesz; - while (addr < end) { - nhdr = (Elf_Nhdr *) addr; - addr += sizeof(Elf_Nhdr); - name = (const char *) addr; - addr += (nhdr->n_namesz+3) & ~3; - desc = (void *) addr; - addr += (nhdr->n_descsz+3) & ~3; - - if (nhdr->n_namesz==sizeof(ELF_NOTE_BOOT) - && memcmp(name, ELF_NOTE_BOOT, sizeof(ELF_NOTE_BOOT))==0) { - if (nhdr->n_type == EIN_PROGRAM_NAME) { - image_name = calloc(1, nhdr->n_descsz + 1); - memcpy(image_name, desc, nhdr->n_descsz); - } - if (nhdr->n_type == EIN_PROGRAM_VERSION) { - image_version = calloc(1, nhdr->n_descsz + 1); - memcpy(image_version, desc, nhdr->n_descsz); - } - if (nhdr->n_type == EIN_PROGRAM_CHECKSUM) { - *sum_ptr = *(unsigned short *) desc; - debug("Image checksum: %04x\n", *sum_ptr); - /* Where in the file */ - retval = phdr[i].p_offset - + (unsigned long) desc - (unsigned long) buf; - } - } - } - } -out: - if (buf) - forget(buf); - return retval; -} - -static int load_segments(Elf_phdr *phdr, int phnum, - unsigned long checksum_offset) -{ - unsigned long bytes; - unsigned int start_time, time; - int i; - int j; - - bytes = 0; - start_time = currticks(); -#if 0 - for (j = 0; j < phnum; j++) { - if (phdr[j].p_type != PT_LOAD) - continue; - debug("0 segment %d addr:%#x file:%#x mem:%#x, phdr%#x\n", - j, phdr[j].p_paddr, phdr[j].p_filesz, phdr[j].p_memsz, virt_to_phys(&phdr[j])); - } -#endif - - for (i = 0; i < phnum; i++) { - if (phdr[i].p_type != PT_LOAD) - continue; - debug("segment %d addr:%#x file:%#x mem:%#x phdr:%#x ", - i, phdr[i].p_paddr, phdr[i].p_filesz, phdr[i].p_memsz, virt_to_phys(&phdr[i])); - file_seek(phdr[i].p_offset); - debug("loading... "); - if (file_read(phys_to_virt(phdr[i].p_paddr), phdr[i].p_filesz) - != phdr[i].p_filesz) { - printf("Can't read program segment %d\n", i); - return 0; - } - bytes += phdr[i].p_filesz; - debug("clearing... "); - memset(phys_to_virt(phdr[i].p_paddr + phdr[i].p_filesz), 0, - phdr[i].p_memsz - phdr[i].p_filesz); - if (phdr[i].p_offset <= checksum_offset - && phdr[i].p_offset + phdr[i].p_filesz >= checksum_offset+2) { - debug("clearing checksum... "); - memset(phys_to_virt(phdr[i].p_paddr + checksum_offset - - phdr[i].p_offset), 0, 2); - } - debug("ok\n"); - - } - time = (currticks() - start_time)*1000/18; - printf("Loaded %d bytes in %dms (%dKB/s)\n", bytes, time, - time? bytes/time : 0); - return 1; -} - -static int verify_image(Elf_ehdr *ehdr, Elf_phdr *phdr, int phnum, - unsigned short image_sum) -{ - unsigned short sum, part_sum; - unsigned long offset; - int i; - - sum = 0; - offset = 0; - - part_sum = ipchksum(ehdr, sizeof *ehdr); - sum = add_ipchksums(offset, sum, part_sum); - offset += sizeof *ehdr; - - part_sum = ipchksum(phdr, phnum * sizeof(*phdr)); - sum = add_ipchksums(offset, sum, part_sum); - offset += phnum * sizeof(*phdr); - - for (i = 0; i < phnum; i++) { - if (phdr[i].p_type != PT_LOAD) - continue; - part_sum = ipchksum(phys_to_virt(phdr[i].p_paddr), phdr[i].p_memsz); - sum = add_ipchksums(offset, sum, part_sum); - offset += phdr[i].p_memsz; - } - - if (sum != image_sum) { - printf("Verify FAILED (image:%04x vs computed:%04x)\n", - image_sum, sum); - return 0; - } - return 1; -} - -static inline unsigned const padded(unsigned s) -{ - return (s + 3) & ~3; -} - -static Elf_Bhdr *add_boot_note(Elf_Bhdr *bhdr, const char *name, - unsigned type, const char *desc, unsigned descsz) -{ - Elf_Nhdr nhdr; - unsigned ent_size, new_size, pad; - char *addr; - - if (!bhdr) - return NULL; - - nhdr.n_namesz = name? strlen(name)+1 : 0; - nhdr.n_descsz = descsz; - nhdr.n_type = type; - ent_size = sizeof(nhdr) + padded(nhdr.n_namesz) + padded(nhdr.n_descsz); - if (bhdr->b_size + ent_size > 0xffff) { - printf("Boot notes too big\n"); - forget(bhdr); - return NULL; - } - if (bhdr->b_size + ent_size > bhdr->b_checksum) { - do { - new_size = bhdr->b_checksum * 2; - } while (new_size < bhdr->b_size + ent_size); - if (new_size > 0xffff) - new_size = 0xffff; - debug("expanding boot note size to %u\n", new_size); - bhdr = realloc(bhdr, new_size); - bhdr->b_checksum = new_size; - } - - addr = (char *) bhdr; - addr += bhdr->b_size; - memcpy(addr, &nhdr, sizeof(nhdr)); - addr += sizeof(nhdr); - - memcpy(addr, name, nhdr.n_namesz); - addr += nhdr.n_namesz; - pad = padded(nhdr.n_namesz) - nhdr.n_namesz; - memset(addr, 0, pad); - addr += pad; - - memcpy(addr, desc, nhdr.n_descsz); - addr += nhdr.n_descsz; - pad = padded(nhdr.n_descsz) - nhdr.n_descsz; - memset(addr, 0, pad); - addr += pad; - - bhdr->b_size += ent_size; - bhdr->b_records++; - return bhdr; -} - -static inline Elf_Bhdr *add_note_string(Elf_Bhdr *bhdr, const char *name, - unsigned type, const char *desc) -{ - return add_boot_note(bhdr, name, type, desc, strlen(desc) + 1); -} - -static Elf_Bhdr *build_boot_notes(struct sys_info *info, const char *cmdline) -{ - Elf_Bhdr *bhdr; - - bhdr = allot(256); - bhdr->b_signature = ELF_BHDR_MAGIC; - bhdr->b_size = sizeof *bhdr; - bhdr->b_checksum = 256; /* XXX cache the current buffer size here */ - bhdr->b_records = 0; - - if (info->firmware) - bhdr = add_note_string(bhdr, NULL, EBN_FIRMWARE_TYPE, info->firmware); - bhdr = add_note_string(bhdr, NULL, EBN_BOOTLOADER_NAME, program_name); - bhdr = add_note_string(bhdr, NULL, EBN_BOOTLOADER_VERSION, program_version); - if (cmdline) - bhdr = add_note_string(bhdr, NULL, EBN_COMMAND_LINE, cmdline); - if (!bhdr) - return bhdr; - bhdr->b_checksum = 0; - bhdr->b_checksum = ipchksum(bhdr, bhdr->b_size); - return bhdr; -} - -int elf_load(struct sys_info *info, const char *filename, const char *cmdline) -{ - Elf_ehdr ehdr; - Elf_phdr *phdr = NULL; - unsigned long phdr_size; - unsigned long checksum_offset; - unsigned short checksum; - Elf_Bhdr *boot_notes = NULL; - int retval = -1; - int image_retval; - - image_name = image_version = 0; - - if (!file_open(filename)) - goto out; - - if (file_read(&ehdr, sizeof ehdr) != sizeof ehdr) { - debug("Can't read ELF header\n"); - retval = LOADER_NOT_SUPPORT; - goto out; - } - - if (ehdr.e_ident[EI_MAG0] != ELFMAG0 - || ehdr.e_ident[EI_MAG1] != ELFMAG1 - || ehdr.e_ident[EI_MAG2] != ELFMAG2 - || ehdr.e_ident[EI_MAG3] != ELFMAG3 - || ehdr.e_ident[EI_CLASS] != ARCH_ELF_CLASS - || ehdr.e_ident[EI_DATA] != ARCH_ELF_DATA - || ehdr.e_ident[EI_VERSION] != EV_CURRENT - || ehdr.e_type != ET_EXEC - || !ARCH_ELF_MACHINE_OK(ehdr.e_machine) - || ehdr.e_version != EV_CURRENT - || ehdr.e_phentsize != sizeof(Elf_phdr)) { - debug("Not a bootable ELF image\n"); - retval = LOADER_NOT_SUPPORT; - goto out; - } - - phdr_size = ehdr.e_phnum * sizeof *phdr; - phdr = allot(phdr_size);//hack LYH otherwise some one clear the last entry - file_seek(ehdr.e_phoff); - if (file_read(phdr, phdr_size) != phdr_size) { - printf("Can't read program header\n"); - goto out; - } - - if (!check_mem_ranges(info, phdr, ehdr.e_phnum)) - goto out; - - checksum_offset = process_image_notes(phdr, ehdr.e_phnum, &checksum); - - printf("Loading %s", image_name ? image_name : "image"); - if (image_version) - printf(" version %s", image_version); - printf("...\n"); - - if (!load_segments(phdr, ehdr.e_phnum, checksum_offset)) - goto out; - - if (checksum_offset) { - if (!verify_image(&ehdr, phdr, ehdr.e_phnum, checksum)) - goto out; - } - - boot_notes = build_boot_notes(info, cmdline); - - debug("current time: %x\n", currticks()); - - debug("entry point is %#x\n", ehdr.e_entry); - printf("Jumping to entry point...\n"); - - image_retval = start_elf(ehdr.e_entry, virt_to_phys(boot_notes)); -#if 0 - console_init(); -#endif - - printf("Image returned with return value %#x\n", image_retval); - retval = 0; - -out: - if (phdr) - forget(phdr); - if (boot_notes) - forget(boot_notes); - if (image_name) - forget(image_name); - if (image_version) - forget(image_version); - return retval; -} diff --git a/src/filo/main/elfnote.c b/src/filo/main/elfnote.c deleted file mode 100644 index 2100ec956..000000000 --- a/src/filo/main/elfnote.c +++ /dev/null @@ -1,153 +0,0 @@ -/* Support for ELF Boot Proposal as a boot image */ - -#include <etherboot.h> -#include <elf_boot.h> -#include <sys_info.h> -#include <lib.h> - -#include "version.h" -#define DEBUG_THIS DEBUG_ELFNOTE -#include <debug.h> - -/* ELF image notes provide information to the loader who boots us */ - -/* This compiles and generates correct PT_NOTE segment for me. - * If it doesn't, use assembly version below. */ - -struct elf_image_note { - Elf_Nhdr hdr0; - char name0[sizeof(ELF_NOTE_BOOT)]; - char prog_name[sizeof(PROGRAM_NAME)]; - - Elf_Nhdr hdr1; - char name1[sizeof(ELF_NOTE_BOOT)]; - char version[sizeof(PROGRAM_VERSION)]; - - Elf_Nhdr hdr2; - char name2[sizeof(ELF_NOTE_BOOT)]; - unsigned short checksum; -}; - -const struct elf_image_note elf_image_notes - __attribute__ ((section (".note.ELFBoot"))) = -{ - .hdr0 = { - .n_namesz = sizeof(ELF_NOTE_BOOT), - .n_descsz = sizeof(PROGRAM_NAME), - .n_type = EIN_PROGRAM_NAME, - }, - .name0 = ELF_NOTE_BOOT, - .prog_name = PROGRAM_NAME, - - .hdr1 = { - .n_namesz = sizeof(ELF_NOTE_BOOT), - .n_descsz = sizeof(PROGRAM_VERSION), - .n_type = EIN_PROGRAM_VERSION, - }, - .name1 = ELF_NOTE_BOOT, - .version = PROGRAM_VERSION, - - .hdr2 = { - .n_namesz = sizeof(ELF_NOTE_BOOT), - .n_descsz = sizeof(unsigned short), - .n_type = EIN_PROGRAM_CHECKSUM, - }, - .name2 = ELF_NOTE_BOOT, - .checksum = 0, /* to be computed by external tool */ -}; - -/* This is refered by other files */ -const char *program_name = elf_image_notes.prog_name; -const char *program_version = elf_image_notes.version; - -#if 0 - - /* This tells the linker to make a PT_NOTE segment. - * If the section is named just ".note", it will be - * mixed up with useless .version notes generated by GCC. - */ - .section ".note.ELFBoot", "a" - - .align 4 - .int 2f - 1f - .int 4f - 3f - .int EIN_PROGRAM_NAME -1: .asciz "ELFBoot" -2: .align 4 -3: .asciz PROGRAM_NAME -4: - - .align 4 - .int 2f - 1f - .int 4f - 3f - .int EIN_PROGRAM_VERSION -1: .asciz "ELFBoot" -2: .align 4 -3: .asciz PROGRAM_VERSION -4: - - .align 4 - .int 2f - 1f - .int 4f - 3f - .int EIN_PROGRAM_CHECKSUM -1: .asciz "ELFBoot" -2: .align 4 -3: .short 0 -4: -#endif - -/* Collect information from the ELF bootloader - * Note that we have to copy them to our own memory, - * otherwise they might be overwritten afterward. */ -void collect_elfboot_info(struct sys_info *info) -{ - Elf_Bhdr *hdr = 0; - char *addr, *end; - Elf_Nhdr *nhdr; - char *name, *desc; - - if (info->boot_type == ELF_BHDR_MAGIC) - hdr = phys_to_virt(info->boot_data); - else - hdr = phys_to_virt(info->boot_arg); - - if (hdr->b_signature != ELF_BHDR_MAGIC) - return; - - if (ipchksum(hdr, hdr->b_size) != 0) { - printf("Broken ELF boot notes\n"); - return; - } - - addr = (char *) (hdr + 1); - end = addr + hdr->b_size; - while (addr < end) { - nhdr = (Elf_Nhdr *) addr; - addr += sizeof(Elf_Nhdr); - name = addr; - addr += (nhdr->n_namesz + 3) & ~3; - desc = addr; - addr += (nhdr->n_descsz + 3) & ~3; - - if (nhdr->n_namesz == 0) { - /* Standard notes */ - switch (nhdr->n_type) { - case EBN_FIRMWARE_TYPE: - info->firmware = strdup(desc); - break; - case EBN_BOOTLOADER_NAME: - debug("Bootloader: %s\n", desc); - break; - case EBN_BOOTLOADER_VERSION: - debug("Version: %s\n", desc); - break; - case EBN_COMMAND_LINE: - info->command_line = strdup(desc); - break; - case EBN_LOADED_IMAGE: - debug("Image name: %s\n", desc); - break; - } - } - } -} diff --git a/src/filo/main/filo_x.c b/src/filo/main/filo_x.c deleted file mode 100644 index 6569c4136..000000000 --- a/src/filo/main/filo_x.c +++ /dev/null @@ -1,129 +0,0 @@ -#include <etherboot.h> - -#include <fs.h> -#include <lib.h> -#include <sys_info.h> - -#define ENTER '\r' -#define ESCAPE '\x1b' - -#ifndef AUTOBOOT_FILE -#define autoboot() ((void) 0) /* nop */ -#endif - -#ifndef AUTOBOOT_DELAY -#define autoboot_delay() 0 /* success */ -#endif - -struct sys_info sys_info; - -static void init(void) -{ - collect_sys_info(&sys_info); - - printf("%s version %s\n", program_name, program_version); - -} - -static void boot(const char *line) -{ - char file[256], *param; - - /* Split filename and parameter */ - memcpy(file, line,256); -// file = strdup(line); - param = strchr(file, ' '); - if (param) { - *param = '\0'; - param++; - } - if (elf_load(&sys_info, file, param) == LOADER_NOT_SUPPORT){ - if (linux_load(&sys_info, file, param) == LOADER_NOT_SUPPORT) - printf("Unsupported image format\n"); - } -// free(file); -} - -#ifdef AUTOBOOT_FILE -#if AUTOBOOT_DELAY - -static inline int autoboot_delay(void) -{ - unsigned int timeout; - int sec, tmp; - int key; - - key = 0; - - printf("Press <Enter> for default boot, or <Esc> for boot prompt... "); - for (sec = AUTOBOOT_DELAY; sec>0 && key==0; sec--) { - printf("%d", sec); - timeout = currticks() + TICKS_PER_SEC; - while (currticks() < timeout) { - if (iskey()) { - key = getchar(); - if (key==ENTER || key==ESCAPE) - break; - } - } - for (tmp = sec; tmp; tmp /= 10) - printf("\b \b"); - } - if (key == 0) { - printf("timed out\n"); - return 0; /* success */ - } else { - putchar('\n'); - if (key == ESCAPE) - return -1; /* canceled */ - else - return 0; /* default accepted */ - } -} -#endif /* AUTOBOOT_DELAY */ - -static void autoboot(void) -{ - /* If Escape key is pressed already, skip autoboot */ - if (iskey() && getchar()==ESCAPE) - return; - - if (autoboot_delay()==0) { - printf("boot: %s\n", AUTOBOOT_FILE); - boot(AUTOBOOT_FILE); - } -} -#endif /* AUTOBOOT_FILE */ - -/* The main routine */ -int filo(void) -{ - char line[256]; - - /* Initialize */ - - init(); - - /* Try default image */ - autoboot(); - - /* The above didn't work, ask user */ - while (iskey()) - getchar(); -#ifdef AUTOBOOT_FILE - strncpy(line, AUTOBOOT_FILE, sizeof(line)-1); - line[sizeof(line)-1] = '\0'; -#else - line[0] = '\0'; -#endif - for (;;) { - printf("boot: "); - getline(line, sizeof line); -// BY LYH add "quit" to exit filo - if (strcmp(line,"quit")==0) break; -// if (memcmp(line,"quit",4)==0) break; - if (line[0]) - boot(line); - } - return 0; -} diff --git a/src/filo/main/lib.c b/src/filo/main/lib.c deleted file mode 100644 index 6e5020c7e..000000000 --- a/src/filo/main/lib.c +++ /dev/null @@ -1,56 +0,0 @@ - -#include <etherboot.h> -#include <lib.h> - -char *strdup(const char *s) -{ - size_t sz = strlen(s) + 1; - char *d = allot(sz); - memcpy(d, s, sz); - return d; -} - -int isspace(int c) -{ - switch (c) { - case ' ': case '\f': case '\n': - case '\r': case '\t': case '\v': - return 1; - default: - return 0; - } -} - -unsigned int get_le32(const unsigned char *p) -{ - return ((unsigned int) p[0] << 0) - | ((unsigned int) p[1] << 8) - | ((unsigned int) p[2] << 16) - | ((unsigned int) p[3] << 24); -} - -unsigned int get_le16(const unsigned char *p) -{ - return ((unsigned int) p[0] << 0) - | ((unsigned int) p[1] << 8); -} -#if (DEBUG_ALL || DEBUG_ELFBOOT || DEBUG_ELFNOTE || DEBUG_LINUXBIOS || \ - DEBUG_MALLOC || DEBUG_MULTIBOOT || DEBUG_SEGMENT || DEBUG_SYS_INFO ||\ - DEBUG_TIMER || DEBUG_BLOCKDEV || DEBUG_PCI || DEBUG_LINUXLOAD ||\ - DEBUG_IDE || DEBUG_ELTORITO) - -// It is needed by debug for filo -void hexdump(const void *p, unsigned int len) -{ - int i; - const unsigned char *q = p; - - for (i = 0; i < len; i++) { - if (i%16==0) - printf("%04x: ", i); - printf("%02x%c", q[i], i%16==15 ? '\n' : i%8==7 ? '-' : ' '); - } - if (i%16 != 0) - putchar('\n'); -} -#endif diff --git a/src/filo/main/linuxbios_x.c b/src/filo/main/linuxbios_x.c deleted file mode 100644 index 37f9e3f13..000000000 --- a/src/filo/main/linuxbios_x.c +++ /dev/null @@ -1,124 +0,0 @@ -/* Adapted from Etherboot 5.1.8 */ -#include <sys_info.h> -#define DEBUG_THIS DEBUG_LINUXBIOS -#include <debug.h> - -#if 0 - -#define for_each_lbrec(head, rec) \ - for(rec = (struct lb_record *)(((char *)head) + sizeof(*head)); \ - (((char *)rec) < (((char *)head) + sizeof(*head) + head->table_bytes)) && \ - (rec->size >= 1) && \ - ((((char *)rec) + rec->size) <= (((char *)head) + sizeof(*head) + head->table_bytes)); \ - rec = (struct lb_record *)(((char *)rec) + rec->size)) - -static void convert_memmap(struct lb_memory *lbmem, struct sys_info *info) -{ - int lbcount; - int i; - - lbcount = lbmem->size / sizeof(struct lb_memory_range); - info->memrange = malloc(lbcount * sizeof(struct memrange)); - info->n_memranges = 0; - for (i = 0; i < lbcount; i++) { - debug("%#016Lx %#016Lx %d\n", - lbmem->map[i].start, lbmem->map[i].size, - (int) lbmem->map[i].type); - if (lbmem->map[i].type != LB_MEM_RAM) - continue; - info->memrange[info->n_memranges].base = lbmem->map[i].start; - info->memrange[info->n_memranges].size = lbmem->map[i].size; - info->n_memranges++; - } -} -static int read_lbtable(struct lb_header *head, struct sys_info *info) -{ - int retval = 0; - - /* Read linuxbios tables... */ - struct lb_record *rec; - - for_each_lbrec(head, rec) { - switch(rec->tag) { - case LB_TAG_MEMORY: - convert_memmap((struct lb_memory *) rec, info); - retval = 1; - break; - }; - } - return retval; -} -#endif -#if 0 -//Use func in Etherboot -static unsigned long count_lb_records(void *start, unsigned long length) -{ - struct lb_record *rec; - void *end; - unsigned long count; - count = 0; - end = ((char *)start) + length; - for(rec = start; ((void *)rec < end) && - ((signed long)rec->size <= (end - (void *)rec)); - rec = (void *)(((char *)rec) + rec->size)) { - count++; - } - return count; -} -static int find_lb_table(void *start, void *end, struct lb_header **result) -{ - unsigned char *ptr; - /* For now be stupid.... */ - for(ptr = start; (void *)ptr < end; ptr += 16) { - struct lb_header *head = (struct lb_header *)ptr; - if ( (head->signature[0] != 'L') || - (head->signature[1] != 'B') || - (head->signature[2] != 'I') || - (head->signature[3] != 'O')) { - continue; - } - if (head->header_bytes != sizeof(*head)) - continue; - debug("Found canidate at: %p\n", head); - if (ipchksum((uint16_t *)head, sizeof(*head)) != 0) - continue; - debug("header checksum o.k.\n"); - if (ipchksum((uint16_t *)(ptr + sizeof(*head)), head->table_bytes) != - head->table_checksum) { - continue; - } - debug("table checksum o.k.\n"); - if (count_lb_records(ptr + sizeof(*head), head->table_bytes) != - head->table_entries) { - continue; - } - debug("record count o.k.\n"); - *result = head; - return 1; - }; - return 0; -} -#endif -void collect_linuxbios_info(struct sys_info *info) -{ -#if 0 - struct lb_header *lb_table; - int found; - debug("Searching for LinuxBIOS tables...\n"); - found = 0; - if (!found) { - found = find_lb_table(phys_to_virt(0x00000), phys_to_virt(0x01000), &lb_table); - } - if (!found) { - found = find_lb_table(phys_to_virt(0xf0000), phys_to_virt(0x100000), &lb_table); - } - if (!found) - return; - - debug("Found LinuxBIOS table at: %p\n", lb_table); -#endif - info->firmware = "LinuxBIOS"; -#if 0 - read_lbtable(lb_table, info); -#endif -} diff --git a/src/filo/main/malloc_x.c b/src/filo/main/malloc_x.c deleted file mode 100644 index 99b309aa7..000000000 --- a/src/filo/main/malloc_x.c +++ /dev/null @@ -1,45 +0,0 @@ -#include <etherboot.h> - -#include <lib.h> - -void *calloc(size_t nmemb, size_t size) -{ - size_t alloc_size = nmemb * size; - void *mem; - - if (alloc_size < nmemb || alloc_size < size) { - printf("calloc overflow: %u, %u\n", nmemb, size); - return 0; - } - - mem = allot(alloc_size); - memset(mem, 0, alloc_size); - - return mem; -} - -void *realloc(void *mem, size_t size) -{ - size_t copy_size; - void *new_mem; - size_t *mark, addr; - - if (mem == 0) - return allot(size); - if (size == 0) { - forget(mem); - return 0; - } - - addr = virt_to_phys(mem); - mark = phys_to_virt(addr - sizeof(size_t)); - copy_size = *mark; - - if (size < copy_size) - copy_size = size; - /* XXX should optimze this */ - new_mem = allot(size); - memcpy(new_mem, mem, copy_size); - forget(mem); - return new_mem; -} diff --git a/src/filo/main/pci_x.c b/src/filo/main/pci_x.c deleted file mode 100644 index 0c88dff70..000000000 --- a/src/filo/main/pci_x.c +++ /dev/null @@ -1,124 +0,0 @@ -#ifdef CONFIG_PCI - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2, or (at - * your option) any later version. - */ - -#include <etherboot.h> -#include <pci.h> -#include <lib.h> - -#define DEBUG_THIS DEBUG_PCI - -#include <debug.h> - -struct pci_device *dev_list; -int n_devs; - -static void pci_scan_bus(void) -{ - - unsigned int first_bus, first_devfn; - unsigned int devfn, bus, buses; - - uint32_t class; - uint16_t vendor, dev_id; - uint8_t hdr_type; - - - first_bus = 0; - first_devfn = 0; - - buses=256; - for (bus = first_bus; bus < buses; ++bus) { - for (devfn = first_devfn; devfn < 0xff; ++devfn) { - -#if 1 - if (PCI_FUNC(devfn) == 0) - pcibios_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type); - else if (!(hdr_type & 0x80)) /* not a multi-function device */ - continue; -#endif - - pcibios_read_config_word(bus,devfn, PCI_VENDOR_ID, &vendor); - if (vendor==0xffff || vendor==0) - continue; - - if (dev_list) { - dev_list[n_devs].bus = bus; - dev_list[n_devs].devfn = devfn; - dev_list[n_devs].vendor = vendor; - - pcibios_read_config_word(bus,devfn, PCI_DEVICE_ID, &dev_id); - dev_list[n_devs].dev_id = dev_id; - - pcibios_read_config_dword(bus,devfn, PCI_CLASS_REVISION, &class); - dev_list[n_devs].class = class; - - } - n_devs++; - } - first_devfn = 0; - } - first_bus = 0; - -} -#define DEBUG 0 - -void pci_init(void) -{ - /* Count devices */ - dev_list = 0; - n_devs = 0; - debug("Scanning PCI: "); - pci_scan_bus(); - debug("found %d devices\n", n_devs); - - /* Make the list */ - dev_list = allot(n_devs * sizeof(struct pci_device)); - n_devs = 0; - pci_scan_bus(); -#if DEBUG - { - int i; - for (i = 0; i < n_devs; i++) { - printf("%02x:%02x.%x %04x:%04x %04x %02x\n", - dev_list[i].bus, - PCI_SLOT(dev_list[i].devfn), - PCI_FUNC(dev_list[i].devfn), - dev_list[i].vendor, - dev_list[i].dev_id,((dev_list[i].class)>>16), - ((dev_list[i].class)>>8 & 0xff)); - } - } -#endif -} - -struct pci_device *pci_find_device_2(int vendor, int device, int devclass, int devclass2, int prog_if, int index) -{ - int i; - - for (i=0; i<n_devs; i++) { - if (vendor < 0 || vendor==dev_list[i].vendor) - if (device < 0 || device==dev_list[i].dev_id) - if (devclass < 0 || devclass==((dev_list[i].class)>>16) || devclass2==((dev_list[i].class)>>16)) - if (prog_if < 0 || prog_if==((dev_list[i].class)>>8 & 0xff)) { - if (index == 0) - return &dev_list[i]; - index--; - } - } - - return NULL; -} - - -struct pci_device *pci_find_device(int vendor, int device, int devclass, int prog_if, int index) -{ - return pci_find_device_2(vendor, device, devclass, devclass, prog_if, index); -} - -#endif diff --git a/src/filo/main/printf_x.c b/src/filo/main/printf_x.c deleted file mode 100644 index 517e2dd25..000000000 --- a/src/filo/main/printf_x.c +++ /dev/null @@ -1,400 +0,0 @@ -/* Adapted from LinuxBIOS */ - -/* - * - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - * - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -#include "etherboot.h" -#include <stdarg.h> -#include <lib.h> - -/* haha, don't need ctype.c */ -#define isdigit(c) ((c) >= '0' && (c) <= '9') -#define is_digit isdigit -#define isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) -#define islower(c) ((c) >= 'a' && (c) <= 'z') -#define toupper(c) __toupper(c) - -static inline unsigned char __toupper(unsigned char c) -{ - if (islower(c)) - c -= 'a'-'A'; - return c; -} - - -unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base) -{ - unsigned long long result = 0,value; - - if (!base) { - base = 10; - if (*cp == '0') { - base = 8; - cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { - cp++; - base = 16; - } - } - } - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; - cp++; - } - if (endp) - *endp = (char *)cp; - return result; -} - -long long simple_strtoll(const char *cp,char **endp,unsigned int base) -{ - if(*cp=='-') - return -simple_strtoull(cp+1,endp,base); - return simple_strtoull(cp,endp,base); -} - -unsigned long long strtoull_with_suffix(const char *cp,char **endp,unsigned int base) -{ - unsigned long long result; - - if (!endp) { - printf("%s must be called with endp\n", __FUNCTION__); - return 0; - } - result = simple_strtoull(cp, endp, base); - switch (toupper(**endp)) { - case 'K': - result <<= 10; - ++*endp; - break; - case 'M': - result <<= 20; - ++*endp; - break; - case 'G': - result <<= 30; - ++*endp; - break; - } - return result; -} - -#if 0 -// it can be used to substitute the vsprintf.c in etherboot. And it has better -// support in numeric output suppot -//When you want to debug filo, you need to enable it and disable vsprintf.c -// to get output from filo -// BY LYH - -static int skip_atoi(const char **s) -{ - int i=0; - - while (is_digit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed long */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ - -#define do_div(n,base) ({ \ -int __res; \ -__res = ((unsigned long) n) % (unsigned) base; \ -n = ((unsigned long) n) / (unsigned) base; \ -__res; }) - -static int number(int (*tx_byte)(int byte), long num, int base, int size, int precision - ,int type) -{ - char c,sign,tmp[66]; - const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; - int i; - int count = 0; - - if (type & LARGE) - digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = '-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - if (type & SPECIAL) { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - i = 0; - if (num == 0) - tmp[i++]='0'; - else while (num != 0) - tmp[i++] = digits[do_div(num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) - while(size-->0) - tx_byte(' '), count++; - if (sign) - tx_byte(sign), count++; - if (type & SPECIAL) { - if (base==8) - tx_byte('0'), count++; - else if (base==16) { - tx_byte('0'), count++; - tx_byte(digits[33]), count++; - } - } - if (!(type & LEFT)) - while (size-- > 0) - tx_byte(c), count++; - while (i < precision--) - tx_byte('0'), count++; - while (i-- > 0) - tx_byte(tmp[i]), count++; - while (size-- > 0) - tx_byte(' '), count++; - return count; -} - - -int vtxprintf(int (*tx_byte)(int byte), const char *fmt, va_list args) -{ - int len; - unsigned long num; - int i, base; - const char *s; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - - int count; - - for (count=0; *fmt ; ++fmt) { - if (*fmt != '%') { - tx_byte(*fmt), count++; - continue; - } - - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (is_digit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == '.') { - ++fmt; - if (is_digit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { - qualifier = *fmt; - ++fmt; - } - - /* default base */ - base = 10; - - switch (*fmt) { - case 'c': - if (!(flags & LEFT)) - while (--field_width > 0) - tx_byte(' '), count++; - tx_byte((unsigned char) va_arg(args, int)), count++; - while (--field_width > 0) - tx_byte(' '), count++; - continue; - - case 's': - s = va_arg(args, char *); - if (!s) - s = "<NULL>"; - - len = strnlen(s, precision); - - if (!(flags & LEFT)) - while (len < field_width--) - tx_byte(' '), count++; - for (i = 0; i < len; ++i) - tx_byte(*s++), count++; - while (len < field_width--) - tx_byte(' '), count++; - continue; - - case 'p': - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - count += number(tx_byte, - (unsigned long) va_arg(args, void *), 16, - field_width, precision, flags); - continue; - - - case 'n': - if (qualifier == 'l') { - long * ip = va_arg(args, long *); - *ip = count; - } else { - int * ip = va_arg(args, int *); - *ip = count; - } - continue; - - case '%': - tx_byte('%'), count++; - continue; - - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; - - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; - - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; - - default: - tx_byte('%'), count++; - if (*fmt) - tx_byte(*fmt), count++; - else - --fmt; - continue; - } - if (qualifier == 'L') - num = va_arg(args, unsigned long long); - else if (qualifier == 'l') - num = va_arg(args, unsigned long); - else if (qualifier == 'h') { - num = (unsigned short) va_arg(args, int); - if (flags & SIGN) - num = (short) num; - } else if (flags & SIGN) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - count += number(tx_byte, num, base, field_width, precision, flags); - } - return count; -} - -/* FIXME this global makes vsprintf non-reentrant - */ -static char *str_buf; -static int str_tx_byte(int byte) -{ - *str_buf = byte; - str_buf++; - return byte; -} - -int vsprintf(char * buf, const char *fmt, va_list args) -{ - int i; - str_buf = buf; - i = vtxprintf(str_tx_byte, fmt, args); - /* maeder/Ispiri -- The null termination was missing a deference */ - /* and was just zeroing out the pointer instead */ - *str_buf = '\0'; - return i; -} - -int sprintf(char * buf, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=vsprintf(buf,fmt,args); - va_end(args); - return i; -} - -void printf(const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i = vtxprintf(putchar, fmt, args); - va_end(args); - return i; -} -#endif |
