diff --git a/ChangeLog b/ChangeLog index 7b22a6aea..f814b940d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,331 @@ +2010-01-20 Vladimir Serbinenko + + Don't try to generate lists for kernel.img. + + * conf/i386-efi.rmk (pkglib_PROGRAMS): New variable. + (pkglib_MODULES): Remove kernel.img. + (kernel_img_EXPORTS): Removed. + (kernel_img_RELOCATABLE): New variable. + * conf/x86_64-efi.rmk: Likewise. + * genmk.rb: Remove *_EXPORTS support and add *_RELOCATABLE support. + +2010-01-20 Vladimir Serbinenko + + * include/grub/misc.h (grub_sprintf): Removed. All users switched to + grub_xasprintf or grub_snprintf. + (grub_vsprintf): Likewise. + (grub_snprintf): New proto. + (grub_vsnprintf): Likewise. + (grub_xasprintf): Likewise. + (grub_xvasprintf): Likewise. + * kern/misc.c (grub_vprintf): Use grub_vsnprintf_real. + (grub_sprintf): Removed. + (grub_vsnprintf): New function. + (grub_snprintf): Likewise. + (grub_xvasprintf): Likewise. + (grub_xasprintf): Likewise. + (grub_vsprintf): Renamed to ... + (grub_vsnprintf_real): ...this. New argument max_len. + +2010-01-20 BVK Chaitanya + + * include/grub/script_sh.h (sourcecode): Remove const qualifier to + fix grub-script-check warning. + +2010-01-20 Vladimir Serbinenko + + * include/grub/font.h (grub_font_load): Fix prototype. + +2010-01-20 Vladimir Serbinenko + + * conf/mips.rmk (kernel_img_HEADERS) [yeeloong]: Add pci.h. + +2010-01-20 Vladimir Serbinenko + + * include/grub/x86_64/at_keyboard.h: New file. + +2010-01-20 Vladimir Serbinenko + + * loader/mips/linux.c: Include missing grub/i18n.h. + +2009-12-20 Robert Millan + + * normal/menu.c (notify_execution_failure): Clarify error message. + +2009-12-20 Robert Millan + + * commands/loadenv.c (check_blocklists): Use `grub_err_t' as + return value (and revert all return statements). Update users. + +2010-01-20 Dan Merillat + + * kern/device.c (grub_device_iterate): Allocate new part_ent + structure based on sizeof (*p) rather than sizeof (p->next), to + account for structure padding. + + * util/grub-probe.c (probe_raid_level): Return -1 immediately if + disk is NULL, which might happen for LVM physical volumes with no + LVM signature. + +2009-12-20 Robert Millan + + * loader/mips/linux.c (grub_cmd_initrd) + (GRUB_MOD_INIT(linux)): Adjust and gettextize a few strings. + +2009-12-20 Robert Millan + + * kern/mips/yeeloong/init.c (grub_video_sm712_init) + (grub_video_video_init, grub_video_bitmap_init) + (grub_font_manager_init, grub_term_gfxterm_init) + (grub_at_keyboard_init): New extern declarations. + (grub_machine_init): Initialize gfxterm and at_keyboard. + + * kern/main.c (grub_main): Revert grub_printf delay kludge. + + * util/grub-install.in: Revert embed of `at_keyboard.mod' and + `gfxterm.mod' into core image. + + * conf/mips.rmk (pkglib_IMAGES, kernel_img_SOURCES) + (kernel_img_CFLAGS, kernel_img_ASFLAGS, kernel_img_LDFLAGS) + (kernel_img_FORMAT): Copy to ... + + * conf/mips-qemu-mips.rmk (pkglib_IMAGES, kernel_img_SOURCES) + (kernel_img_CFLAGS, kernel_img_ASFLAGS, kernel_img_LDFLAGS) + (kernel_img_FORMAT): ... here, and ... + + * conf/mips-yeeloong.rmk (pkglib_IMAGES, kernel_img_SOURCES) + (kernel_img_CFLAGS, kernel_img_ASFLAGS, kernel_img_LDFLAGS) + (kernel_img_FORMAT): ... here. + + (kernel_img_SOURCES): Add files necessary for output (gfxterm) + and input (at_keyboard) terminals in kernel. + (kernel_img_CFLAGS): Add `-DUSE_ASCII_FAILBACK'. + + (pkglib_MODULES): Remove `pci.mod'. + (pci_mod_SOURCES, pci_mod_CFLAGS, pci_mod_LDFLAGS) + (sm712_mod_SOURCES, sm712_mod_CFLAGS, sm712_mod_LDFLAGS) + (at_keyboard_mod_SOURCES, at_keyboard_mod_CFLAGS) + (at_keyboard_mod_LDFLAGS): Remove variables. + +2010-01-11 Felix Zielcke + + * po/POTFILES: Replace `term/i386/pc/serial.c' with `term/serial.c'. + +2009-12-10 Robert Millan + + * include/grub/mips/libgcc.h: Only export symbols for functions + that libgcc provides. + +2009-12-02 Vladimir Serbinenko + + MIPS support. + + * bus/bonito.c: New file. + * bus/pci.c (grub_pci_iterate): Use GRUB_PCI_NUM_BUS and + GRUB_PCI_NUM_DEVICES. + * term/i386/pc/serial.c: Move to ... + * term/serial.c: ... here. All users updated. + * util/i386/pc/grub-mkimage.c: Move to ... + * util/grub-mkrawimage.c: ... here. All users updated. + * term/i386/pc/at_keyboard.c: Move to ... + * term/at_keyboard.c: ... here. All users updated. + * conf/mips-qemu-mips.rmk: New file. + * conf/mips-yeeloong.rmk: Likewise. + * conf/mips.rmk: Likewise. + * configure.ac: New platforms mipsel-yeeloong, mips-qemu-mips and + mipsel-qemu-mips. + * disk/ata.c (grub_ata_device_initialize): Add GRUB_MACHINE_PCI_IO_BASE + to port addresses. + (grub_ata_pciinit): Support CS5536. + * font/font.c (grub_font_load): Use grub_file_t instead of filename. + * font/font_cmd.c (loadfont_command): Open file before passing it to + grub_font_load. + (pseudo_file_read): New function. + (pseudo_file_close): Likewise. + (pseudo_fs): New structure. + (load_font_module): New function. + (GRUB_MOD_INIT(font_manager)): Load embedded font. + * fs/cpio.c (grub_cpio_open): Handle partial matches correctly. + * genmk.rb: Strip .rel.dyn, .reginfo, .note and .comment. + * genmoddep.awk: Ignore __gnu_local_gp. It's defined by linker. + * include/grub/i386/at_keyboard.h: Split into ... + * include/grub/at_keyboard.h: ... this ... + * include/grub/i386/at_keyboard.h: ... and this. + * include/grub/dl.h (grub_arch_dl_init_linker) [_mips && !GRUB_UTIL]: + New prototype. + * include/grub/elfload.h (grub_elf32_size): New parameter. All users + updated. + (grub_elf64_size): Likewise. + * include/grub/font.h (grub_font_load): Use grub_file_t instead of + filename. + * include/grub/i386/io.h (grub_port_t): New type. All users updated. + * include/grub/i386/coreboot/serial.h: Rewritten. + * include/grub/i386/ieee1275/serial.h: Include + grub/i386/coreboot/serial.h instead of grub/i386/pc/serial.h. + * include/grub/i386/pc/serial.h: Moved from here ... + * include/grub/serial.h: ... to here. All users updated. + * include/grub/i386/pci.h (GRUB_MACHINE_PCI_IO_BASE): New definition. + (GRUB_PCI_NUM_BUS): Likewise. + (GRUB_PCI_NUM_DEVICES): Likewise. + (grub_pci_device_map_range): Add missing volatile keyword. + * include/grub/kernel.h (OBJ_TYPE_FONT): New enum value. + * include/grub/mips/at_keyboard.h: New file. + * include/grub/mips/cache.h: Likewise. + * include/grub/mips/io.h: Likewise. + * include/grub/mips/kernel.h: Likewise. + * include/grub/mips/libgcc.h: Likewise. + * include/grub/mips/pci.h: Likewise. + * include/grub/mips/qemu-mips/boot.h: Likewise. + * include/grub/mips/qemu-mips/kernel.h: Likewise. + * include/grub/mips/qemu-mips/loader.h: Likewise. + * include/grub/mips/qemu-mips/memory.h: Likewise. + * include/grub/mips/qemu-mips/serial.h: Likewise. + * include/grub/mips/qemu-mips/time.h: Likewise. + * include/grub/mips/relocator.h: Likewise. + * include/grub/mips/time.h: Likewise. + * include/grub/mips/types.h: Likewise. + * include/grub/mips/yeeloong/at_keyboard.h: Likewise. + * include/grub/mips/yeeloong/boot.h: Likewise. + * include/grub/mips/yeeloong/kernel.h: Likewise. + * include/grub/mips/yeeloong/loader.h: Likewise. + * include/grub/mips/yeeloong/memory.h: Likewise. + * include/grub/mips/yeeloong/pci.h: Likewise. + * include/grub/mips/yeeloong/serial.h: Likewise. + * include/grub/mips/yeeloong/time.h: Likewise. + * kern/dl.c (grub_dl_resolve_symbols): Handle STT_OBJECT correctly. + * kern/elf.c (grub_elf32_size): New parameter. All users + updated. + (grub_elf64_size): Likewise. + * kern/main.c (grub_main): Call grub_arch_dl_init_linker if necessary. + Load modules before saying "Welcome to GRUB!". + Call grub_refresh after saying "Welcome to GRUB!". + * kern/mips/cache.S: New file. + * kern/mips/cache_flush.S: Likewise. + * kern/mips/dl.c: Likewise. + * kern/mips/init.c: Likewise. + * kern/mips/qemu-mips/init.c: Likewise. + * kern/mips/startup.S: Likewise. + * kern/mips/yeeloong/init.c: Likewise. + * kern/term.c (grub_putcode): Handle NULL terminal. + (grub_getcharwidth): Likewise. + (grub_getkey): Likewise. + (grub_checkkey): Likewise. + (grub_getkeystatus): Likewise. + (grub_getxy): Likewise. + (grub_getwh): Likewise. + (grub_gotoxy): Likewise. + (grub_cls): Likewise. + (grub_setcolorstate): Likewise. + (grub_setcolor): Likewise. + (grub_getcolor): Likewise. + (grub_refresh): Likewise. + * lib/mips/relocator.c (JUMP_SIZEOF): Fix incorrect value. + (write_jump): Add hatch nop. + * lib/mips/relocator_asm.S: Use kern/mips/cache_flush.S. + * lib/mips/setjmp.S: New file. + * loader/mips/linux.c: Likewise. + * term/i386/pc/at_keyboard.c: Move from here ... + * term/at_keyboard.c: ... to here. + * term/i386/pc/serial.c: Moved from here ... + * term/serial.c: ... to here. All users updated. + (TEXT_HEIGHT): Set to 24 to fit linux terminal. + (serial_hw_io_addr): Use GRUB_MACHINE_SERIAL_PORTS. + (serial_translate_key_sequence): Avoid deadlock. + (grub_serial_getkey): Handle backspace. + (grub_serial_putchar): Fix newline handling. + * util/i386/pc/grub-mkimage.c: Move from here ... + * util/grub-mkrawimage.c: ... to here. All users updated. + (generate_image): New parameters 'font_path' and 'format'. + Support embedding font. + Use grub_host_to_target* instead of grub_cpu_to_le*. + (generate_image) [GRUB_MACHINE_MIPS]: Support ELF encapsulation. + (options) [GRUB_PLATFORM_IMAGE_DEFAULT]: New option "--format". + (options): New option "--font". + (usage): Likewise. + (main) [GRUB_PLATFORM_IMAGE_DEFAULT]: Handle "--format". + (main): Handle "--font". + * term/gfxterm.c (grub_virtual_screen): New member bg_color_display. + (grub_virtual_screen_setup): Set bg_color_display. + (redraw_screen_rect): Use bg_color_display instead of incorrect + bg_color. + (grub_gfxterm_cls): Likewise. + * util/elf/grub-mkimage.c (load_modules): New parameter 'config_path'. + Support embedding config file. + (add_segments): Likewise. + (options): New option "--config". + (main): Handle "--config". + * video/sm712.c: New file. + +2010-01-18 Robert Millan + + Fix parallel builds. + + * conf/common.rmk (font/font.c_DEPENDENCIES): New variable (makes + font.c depend on ascii.h). + +2010-01-12 Carles Pina i Estany + + * Makefile.in (DUSE_ASCII_FAILBACK): New macro. + +2010-01-11 Carles Pina i Estany + + * font/font.c (GENERATE_ASCII): Change the name to USE_ASCII_FAILBACK. + By default: disabled. + * Makefile.in (ascii.h): Remove the non-needed grub/bin2h size + parameter. + +2010-01-10 Carles Pina i Estany + + * font/font.c: Update copyright years. + * util/grub-mkfont.c (write_font_ascii_bitmap): Change comment format. + +2010-01-10 Carles Pina i Estany + + * font/font.c: Include `ascii.h'. + (ASCII_BITMAP_SIZE): New macro. + (ascii_font_glyph): Define. + (ascii_glyph_lookup): New function. + (grub_font_get_string_width): Change comment. If glyph not found, use + ascii_glyph_lookup. + (grub_font_get_glyph_with_fallback): If glyph not available returns + ascii_glyph_lookup. + * util/grub-mkfont.c (file_formats): New enum. + (options): Add `ascii-bitmaps' new option. + (usage): Add `asii-bitmaps' new option. + (write_font_ascii_bitmap): New function. + (write_font): Rename to ... + (write_font_p2): ... this. Remove print_glyphs call. + (main): Use file_format. Implement code for ranges if ascii-bitmaps is + used. Call print_glyphs. + * Makefile.in (pkgdata_DATA): Add `ascii.h'. + +2010-01-14 Robert Millan + + * conf/common.rmk (bin_UTILITIES): Add `grub-bin2h'. + (grub_bin2h_SOURCES): New variable. + * util/bin2h.c: New file. + +2010-01-20 Vladimir Serbinenko + + * include/multiboot.h: Resynced with spec. + * include/multiboot2.h: Likewise. + * loader/i386/multiboot_mbi.c (grub_fill_multiboot_mmap): Handle + GRUB_MACHINE_MEMORY_ACPI_RECLAIMABLE and GRUB_MACHINE_MEMORY_NVS. + +2010-01-18 Robert Millan + + * include/grub/term.h (grub_term_register_input, + grub_term_register_output): Check return of terminal init() + routines, and abort if errors are raised. + + * commands/terminal.c: Update copyright year. + +2010-01-18 Robert Millan + + * commands/terminal.c (grub_cmd_terminal_input) + (grub_cmd_terminal_output): Check return of terminal init() + routines, and abort if errors are raised. + 2010-01-18 Vladimir Serbinenko * include/grub/i386/bsd.h: Fix include pathes. diff --git a/Makefile.in b/Makefile.in index e1067b985..d0bbe3b25 100644 --- a/Makefile.in +++ b/Makefile.in @@ -236,7 +236,7 @@ else ifeq ($(enable_grub_mkfont),yes) -pkgdata_DATA += unicode.pf2 ascii.pf2 +pkgdata_DATA += unicode.pf2 ascii.pf2 ascii.h # Arrows and lines are needed to draw the menu, so we always include them UNICODE_ARROWS=0x2190-0x2193 @@ -247,6 +247,14 @@ unicode.pf2: $(FONT_SOURCE) grub-mkfont ascii.pf2: $(FONT_SOURCE) grub-mkfont $(builddir)/grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x7f,$(UNICODE_ARROWS),$(UNICODE_LINES) + +ascii.bitmaps: $(FONT_SOURCE) grub-mkfont + $(builddir)/grub-mkfont --ascii-bitmaps -o $@ $(FONT_SOURCE) + +ascii.h: ascii.bitmaps grub-bin2h + $(builddir)/grub-bin2h ascii_bitmaps < $< > $@ + +TARGET_CFLAGS += -DUSE_ASCII_FAILBACK=1 endif endif diff --git a/bus/bonito.c b/bus/bonito.c new file mode 100644 index 000000000..3f794c45a --- /dev/null +++ b/bus/bonito.c @@ -0,0 +1,90 @@ +/* bonito.c - PCI bonito interface. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include + +static grub_uint32_t base_win[GRUB_MACHINE_PCI_NUM_WIN]; +static const grub_size_t sizes_win[GRUB_MACHINE_PCI_NUM_WIN] = + {GRUB_MACHINE_PCI_WIN1_SIZE, GRUB_MACHINE_PCI_WIN_SIZE, + GRUB_MACHINE_PCI_WIN_SIZE}; +/* Usage counters. */ +static int usage_win[GRUB_MACHINE_PCI_NUM_WIN]; +static grub_addr_t addr_win[GRUB_MACHINE_PCI_NUM_WIN] = + {GRUB_MACHINE_PCI_WIN1_ADDR, GRUB_MACHINE_PCI_WIN2_ADDR, + GRUB_MACHINE_PCI_WIN3_ADDR}; + +static inline void +write_bases (void) +{ + int i; + grub_uint32_t reg = 0; + for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++) + reg |= (((base_win[i] >> GRUB_MACHINE_PCI_WIN_SHIFT) + & GRUB_MACHINE_PCI_WIN_MASK) + >> (i * GRUB_MACHINE_PCI_WIN_MASK_SIZE)); + GRUB_MACHINE_PCI_IO_CTRL_REG = reg; +} + +volatile void * +grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)), + grub_addr_t base, grub_size_t size) +{ + int i; + grub_addr_t newbase; + + /* First try already used registers. */ + for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++) + if (usage_win[i] && base_win[i] <= base + && base_win[i] + sizes_win[i] > base + size) + { + usage_win[i]++; + return (void *) + (addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK)); + } + /* Map new register. */ + newbase = base & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK; + for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++) + if (!usage_win[i] && newbase <= base + && newbase + sizes_win[i] > base + size) + { + usage_win[i]++; + base_win[i] = newbase; + write_bases (); + return (void *) + (addr_win[i] | (base & GRUB_MACHINE_PCI_WIN_OFFSET_MASK)); + } + grub_fatal ("Out of PCI windows."); +} + +void +grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)), + volatile void *mem __attribute__ ((unused)), + grub_size_t size __attribute__ ((unused))) +{ + int i; + for (i = 0; i < GRUB_MACHINE_PCI_NUM_WIN; i++) + if (usage_win[i] && addr_win[i] + == (((grub_addr_t) mem) & ~GRUB_MACHINE_PCI_WIN_OFFSET_MASK)) + { + usage_win[i]--; + return; + } + grub_fatal ("Tried to unmap not mapped region"); +} diff --git a/bus/pci.c b/bus/pci.c index 65d848a18..5f2dcce25 100644 --- a/bus/pci.c +++ b/bus/pci.c @@ -35,9 +35,9 @@ grub_pci_iterate (grub_pci_iteratefunc_t hook) grub_pci_id_t id; grub_uint32_t hdr; - for (dev.bus = 0; dev.bus < 256; dev.bus++) + for (dev.bus = 0; dev.bus < GRUB_PCI_NUM_BUS; dev.bus++) { - for (dev.device = 0; dev.device < 32; dev.device++) + for (dev.device = 0; dev.device < GRUB_PCI_NUM_DEVICES; dev.device++) { for (dev.function = 0; dev.function < 8; dev.function++) { diff --git a/commands/hashsum.c b/commands/hashsum.c index 60e17447b..a4e71b844 100644 --- a/commands/hashsum.c +++ b/commands/hashsum.c @@ -111,11 +111,9 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename, { char *filename; - filename = grub_malloc (grub_strlen (prefix) - + grub_strlen (p) + 2); + filename = grub_xasprintf ("%s/%s", prefix, p); if (!filename) return grub_errno; - grub_sprintf (filename, "%s/%s", prefix, p); file = grub_file_open (filename); grub_free (filename); } diff --git a/commands/help.c b/commands/help.c index 9234a3697..1181c3bfb 100644 --- a/commands/help.c +++ b/commands/help.c @@ -46,12 +46,10 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, char *command_help; grub_uint32_t *unicode_command_help; grub_uint32_t *unicode_last_position; - - command_help = grub_malloc (grub_strlen (cmd->name) + - sizeof (" ") - 1 + - grub_strlen (summary_translated)); - grub_sprintf(command_help, "%s %s", cmd->name, summary_translated); + command_help = grub_xasprintf ("%s %s", cmd->name, summary_translated); + if (!command_help) + return 1; grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help, &unicode_last_position); diff --git a/commands/loadenv.c b/commands/loadenv.c index 910392614..51b88cbc9 100644 --- a/commands/loadenv.c +++ b/commands/loadenv.c @@ -1,7 +1,7 @@ /* loadenv.c - command to load/save environment variable. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -196,7 +196,7 @@ free_blocklists (struct blocklist *p) } } -static int +static grub_err_t check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists, grub_file_t file) { @@ -219,8 +219,7 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists, { /* This might be actually valid, but it is unbelievable that any filesystem makes such a silly allocation. */ - grub_error (GRUB_ERR_BAD_FS, "malformed file"); - return 0; + return grub_error (GRUB_ERR_BAD_FS, "malformed file"); } } @@ -230,8 +229,7 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists, if (total_length != grub_file_size (file)) { /* Maybe sparse, unallocated sectors. No way in GRUB. */ - grub_error (GRUB_ERR_BAD_FILE_TYPE, "sparse file not allowed"); - return 0; + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "sparse file not allowed"); } /* One more sanity check. Re-read all sectors by blocklists, and compare @@ -249,16 +247,13 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists, if (grub_disk_read (disk, p->sector - part_start, p->offset, p->length, blockbuf)) - return 0; + return grub_errno; if (grub_memcmp (buf + index, blockbuf, p->length) != 0) - { - grub_error (GRUB_ERR_FILE_READ_ERROR, "invalid blocklist"); - return 0; - } + return grub_error (GRUB_ERR_FILE_READ_ERROR, "invalid blocklist"); } - return 1; + return GRUB_ERR_NONE; } static int @@ -347,7 +342,7 @@ grub_cmd_save_env (grub_extcmd_t cmd, int argc, char **args) if (! envblk) goto fail; - if (! check_blocklists (envblk, head, file)) + if (check_blocklists (envblk, head, file)) goto fail; while (argc) diff --git a/commands/ls.c b/commands/ls.c index 57409c4f6..8a8319ac8 100644 --- a/commands/ls.c +++ b/commands/ls.c @@ -87,7 +87,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) int print_files_long (const char *filename, const struct grub_dirhook_info *info) { - char pathname[grub_strlen (dirname) + grub_strlen (filename) + 1]; + char *pathname; if ((! all) && (filename[0] == '.')) return 0; @@ -97,9 +97,12 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) grub_file_t file; if (dirname[grub_strlen (dirname) - 1] == '/') - grub_sprintf (pathname, "%s%s", dirname, filename); + pathname = grub_xasprintf ("%s%s", dirname, filename); else - grub_sprintf (pathname, "%s/%s", dirname, filename); + pathname = grub_xasprintf ("%s/%s", dirname, filename); + + if (!pathname) + return 1; /* XXX: For ext2fs symlinks are detected as files while they should be reported as directories. */ @@ -131,8 +134,9 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human) grub_uint32_t whole, fraction; whole = grub_divmod64 (fsize, 100, &fraction); - grub_sprintf (buf, "%u.%02u%c", whole, fraction, - grub_human_sizes[units]); + grub_snprintf (buf, sizeof (buf), + "%u.%02u%c", whole, fraction, + grub_human_sizes[units]); grub_printf ("%-12s", buf); } else diff --git a/commands/memrw.c b/commands/memrw.c index d0908a237..6a4d43be2 100644 --- a/commands/memrw.c +++ b/commands/memrw.c @@ -62,7 +62,7 @@ grub_cmd_read (grub_extcmd_t cmd, int argc, char **argv) if (cmd->state[0].set) { - grub_sprintf (buf, "%x", value); + grub_snprintf (buf, sizeof (buf), "%x", value); grub_env_set (cmd->state[0].arg, buf); } else diff --git a/commands/parttool.c b/commands/parttool.c index 3f69d5525..5ad6133ca 100644 --- a/commands/parttool.c +++ b/commands/parttool.c @@ -183,12 +183,11 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), { char *filename; - filename = grub_malloc (grub_strlen (prefix) + sizeof ("/parttool.lst")); + filename = grub_xasprintf ("%s/parttool.lst", prefix); if (filename) { grub_file_t file; - grub_sprintf (filename, "%s/parttool.lst", prefix); file = grub_file_open (filename); if (file) { diff --git a/commands/search.c b/commands/search.c index ec736de3c..afb2e98e8 100644 --- a/commands/search.c +++ b/commands/search.c @@ -33,7 +33,6 @@ void FUNC_NAME (const char *key, const char *var, int no_floppy) { int count = 0; - char *buf = NULL; grub_fs_autoload_hook_t saved_autoload; auto int iterate_device (const char *name); @@ -48,24 +47,20 @@ FUNC_NAME (const char *key, const char *var, int no_floppy) #ifdef DO_SEARCH_FILE { - grub_size_t len; - char *p; + char *buf; grub_file_t file; - len = grub_strlen (name) + 2 + grub_strlen (key) + 1; - p = grub_realloc (buf, len); - if (! p) + buf = grub_xasprintf ("(%s)%s", name, key); + if (! buf) return 1; - buf = p; - grub_sprintf (buf, "(%s)%s", name, key); - file = grub_file_open (buf); if (file) { found = 1; grub_file_close (file); } + grub_free (buf); } #else { @@ -135,8 +130,6 @@ FUNC_NAME (const char *key, const char *var, int no_floppy) else grub_device_iterate (iterate_device); - grub_free (buf); - if (grub_errno == GRUB_ERR_NONE && count == 0) grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key); } diff --git a/commands/terminal.c b/commands/terminal.c index b30f43130..e725123b8 100644 --- a/commands/terminal.c +++ b/commands/terminal.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. + * Copyright (C) 2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -112,10 +112,11 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); } @@ -152,10 +153,11 @@ grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); } @@ -269,10 +271,11 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); } @@ -310,10 +313,11 @@ grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)), break; if (term) { + if (term->init && term->init () != GRUB_ERR_NONE) + return grub_errno; + grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)), GRUB_AS_LIST (term)); - if (term->init) - term->init (); grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), GRUB_AS_LIST (term)); } diff --git a/commands/xnu_uuid.c b/commands/xnu_uuid.c index b6f2b2604..382d3196b 100644 --- a/commands/xnu_uuid.c +++ b/commands/xnu_uuid.c @@ -61,7 +61,7 @@ grub_cmd_xnu_uuid (grub_command_t cmd __attribute__ ((unused)), GRUB_MD_MD5->final (&ctx); xnu_uuid = GRUB_MD_MD5->read (&ctx); - grub_sprintf (uuid_string, + grub_snprintf (uuid_string, sizeof (uuid_string), "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", (unsigned int) xnu_uuid[0], (unsigned int) xnu_uuid[1], (unsigned int) xnu_uuid[2], (unsigned int) xnu_uuid[3], diff --git a/conf/common.rmk b/conf/common.rmk index 0ded89a73..3e5b8f2dc 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -88,6 +88,9 @@ endif bin_UTILITIES += grub-mkrelpath grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c +bin_UTILITIES += grub-bin2h +grub_bin2h_SOURCES = gnulib/progname.c util/bin2h.c + # For grub-script-check. bin_UTILITIES += grub-script-check util/grub-script-check.c_DEPENDENCIES = grub_script_check_init.h @@ -597,7 +600,7 @@ sh_mod_LDFLAGS = $(COMMON_LDFLAGS) # Common Video Subsystem specific modules. pkglib_MODULES += video.mod videotest.mod bitmap.mod tga.mod jpeg.mod \ - png.mod font.mod gfxterm.mod video_fb.mod + png.mod gfxterm.mod video_fb.mod # For video.mod. video_mod_SOURCES = video/video.c @@ -634,7 +637,8 @@ png_mod_SOURCES = video/readers/png.c png_mod_CFLAGS = $(COMMON_CFLAGS) png_mod_LDFLAGS = $(COMMON_LDFLAGS) -# For font.mod. +pkglib_MODULES += font.mod +font/font.c_DEPENDENCIES = ascii.h font_mod_SOURCES = font/font_cmd.c font/font.c font_mod_CFLAGS = $(COMMON_CFLAGS) font_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-coreboot.rmk b/conf/i386-coreboot.rmk index 2e835e814..a4b132023 100644 --- a/conf/i386-coreboot.rmk +++ b/conf/i386-coreboot.rmk @@ -53,9 +53,11 @@ boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_BOOT_MACHINE_LI boot_img_FORMAT = binary bin_UTILITIES += grub-mkimage -grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \ +grub_mkimage_SOURCES = util/grub-mkrawimage.c util/misc.c \ util/resolve.c gnulib/progname.c grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) +util/grub-mkrawimage.c_DEPENDENCIES = Makefile + pkglib_IMAGES += kernel.img kernel_img_SOURCES = kern/i386/qemu/startup.S \ @@ -150,7 +152,7 @@ lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) # For datetime.mod -datetime_mod_SOURCES = lib/i386/datetime.c +datetime_mod_SOURCES = lib/cmos_datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-efi.rmk b/conf/i386-efi.rmk index 959cc2355..3170784be 100644 --- a/conf/i386-efi.rmk +++ b/conf/i386-efi.rmk @@ -30,13 +30,14 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. -pkglib_MODULES = kernel.img chain.mod appleldr.mod \ +pkglib_PROGRAMS = kernel.img +pkglib_MODULES = chain.mod appleldr.mod \ halt.mod reboot.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod # For kernel.img. -kernel_img_EXPORTS = no +kernel_img_RELOCATABLE = yes kernel_img_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/misc.c kern/mm.c kern/term.c \ diff --git a/conf/i386-ieee1275.rmk b/conf/i386-ieee1275.rmk index 4d652a504..7750fef97 100644 --- a/conf/i386-ieee1275.rmk +++ b/conf/i386-ieee1275.rmk @@ -86,7 +86,7 @@ halt_mod_CFLAGS = $(COMMON_CFLAGS) halt_mod_LDFLAGS = $(COMMON_LDFLAGS) # For serial.mod. -serial_mod_SOURCES = term/i386/pc/serial.c +serial_mod_SOURCES = term/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) @@ -111,7 +111,7 @@ lspci_mod_CFLAGS = $(COMMON_CFLAGS) lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) # For datetime.mod -datetime_mod_SOURCES = lib/i386/datetime.c +datetime_mod_SOURCES = lib/cmos_datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 92aff127a..dd15979d4 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -84,10 +84,10 @@ bin_UTILITIES = grub-mkimage sbin_UTILITIES = grub-setup # For grub-mkimage. -grub_mkimage_SOURCES = gnulib/progname.c util/i386/pc/grub-mkimage.c util/misc.c \ +grub_mkimage_SOURCES = gnulib/progname.c util/grub-mkrawimage.c util/misc.c \ util/resolve.c lib/LzmaEnc.c lib/LzFind.c grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) -util/i386/pc/grub-mkimage.c_DEPENDENCIES = Makefile +util/grub-mkrawimage.c_DEPENDENCIES = Makefile # For grub-setup. util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h @@ -272,7 +272,7 @@ pxecmd_mod_CFLAGS = $(COMMON_CFLAGS) pxecmd_mod_LDFLAGS = $(COMMON_LDFLAGS) # For datetime.mod -datetime_mod_SOURCES = lib/i386/datetime.c +datetime_mod_SOURCES = lib/cmos_datetime.c datetime_mod_CFLAGS = $(COMMON_CFLAGS) datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/i386.rmk b/conf/i386.rmk index 690194261..aa2ec21df 100644 --- a/conf/i386.rmk +++ b/conf/i386.rmk @@ -6,7 +6,7 @@ cpuid_mod_CFLAGS = $(COMMON_CFLAGS) cpuid_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += at_keyboard.mod -at_keyboard_mod_SOURCES = term/i386/pc/at_keyboard.c +at_keyboard_mod_SOURCES = term/at_keyboard.c at_keyboard_mod_CFLAGS = $(COMMON_CFLAGS) at_keyboard_mod_LDFLAGS = $(COMMON_LDFLAGS) @@ -65,7 +65,7 @@ multiboot2_mod_ASFLAGS = $(COMMON_ASFLAGS) # For serial.mod. pkglib_MODULES += serial.mod -serial_mod_SOURCES = term/i386/pc/serial.c +serial_mod_SOURCES = term/serial.c serial_mod_CFLAGS = $(COMMON_CFLAGS) serial_mod_LDFLAGS = $(COMMON_LDFLAGS) diff --git a/conf/mips-qemu-mips.rmk b/conf/mips-qemu-mips.rmk new file mode 100644 index 000000000..e06370122 --- /dev/null +++ b/conf/mips-qemu-mips.rmk @@ -0,0 +1,23 @@ +# -*- makefile -*- +LINK_BASE = 0x80010000 +target_machine=qemu-mips +COMMON_CFLAGS += -march=mips3 +COMMON_ASFLAGS += -march=mips3 +include $(srcdir)/conf/mips.mk + +pkglib_IMAGES = kernel.img +kernel_img_SOURCES = kern/$(target_cpu)/startup.S \ + kern/main.c kern/device.c kern/$(target_cpu)/init.c \ + kern/$(target_cpu)/$(target_machine)/init.c \ + kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \ + kern/misc.c kern/mm.c kern/term.c \ + kern/rescue_parser.c kern/rescue_reader.c \ + kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ + kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \ + kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c kern/time.c \ + symlist.c kern/$(target_cpu)/cache.S +kernel_img_CFLAGS = $(COMMON_CFLAGS) +kernel_img_ASFLAGS = $(COMMON_ASFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ + -Wl,-N,-S,-Ttext,$(LINK_BASE),-Bstatic +kernel_img_FORMAT = binary diff --git a/conf/mips-yeeloong.rmk b/conf/mips-yeeloong.rmk new file mode 100644 index 000000000..964f29384 --- /dev/null +++ b/conf/mips-yeeloong.rmk @@ -0,0 +1,79 @@ +# -*- makefile -*- +LINK_BASE = 0x80200000 +target_machine=yeeloong +COMMON_CFLAGS += -march=mips3 +COMMON_ASFLAGS += -march=mips3 +include $(srcdir)/conf/mips.mk + +pkglib_IMAGES = kernel.img +kernel_img_SOURCES = kern/$(target_cpu)/startup.S \ + kern/main.c kern/device.c kern/$(target_cpu)/init.c \ + kern/$(target_cpu)/$(target_machine)/init.c \ + kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \ + kern/misc.c kern/mm.c kern/term.c \ + kern/rescue_parser.c kern/rescue_reader.c \ + kern/list.c kern/handler.c kern/command.c kern/corecmd.c \ + kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \ + kern/generic/millisleep.c kern/generic/rtc_get_time_ms.c kern/time.c \ + kern/$(target_cpu)/cache.S \ + \ + term/at_keyboard.c \ + font/font_cmd.c font/font.c io/bufio.c \ + video/video.c video/fb/video_fb.c video/fb/fbblit.c \ + video/fb/fbfill.c video/fb/fbutil.c video/bitmap.c \ + video/sm712.c bus/pci.c bus/bonito.c \ + term/gfxterm.c commands/extcmd.c lib/arg.c \ + symlist.c +kernel_img_CFLAGS = $(COMMON_CFLAGS) -DUSE_ASCII_FAILBACK +kernel_img_ASFLAGS = $(COMMON_ASFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ + -Wl,-N,-S,-Ttext,$(LINK_BASE),-Bstatic +kernel_img_FORMAT = binary + +# For ata.mod. +pkglib_MODULES += ata.mod +ata_mod_SOURCES = disk/ata.c +ata_mod_CFLAGS = $(COMMON_CFLAGS) +ata_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For lspci.mod +pkglib_MODULES += lspci.mod +lspci_mod_SOURCES = commands/lspci.c +lspci_mod_CFLAGS = $(COMMON_CFLAGS) +lspci_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For ata_pthru.mod. +pkglib_MODULES += ata_pthru.mod +ata_pthru_mod_SOURCES = disk/ata_pthru.c +ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS) +ata_pthru_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For mmap.mod. +pkglib_MODULES += mmap.mod +mmap_mod_SOURCES = mmap/mmap.c mmap/mips/yeeloong/uppermem.c +mmap_mod_CFLAGS = $(COMMON_CFLAGS) +mmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +mmap_mod_ASFLAGS = $(COMMON_ASFLAGS) + +# For datetime.mod +pkglib_MODULES += datetime.mod +datetime_mod_SOURCES = lib/cmos_datetime.c +datetime_mod_CFLAGS = $(COMMON_CFLAGS) +datetime_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For date.mod +pkglib_MODULES += date.mod +date_mod_SOURCES = commands/date.c +date_mod_CFLAGS = $(COMMON_CFLAGS) +date_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For datehook.mod +pkglib_MODULES += datehook.mod +datehook_mod_SOURCES = hook/datehook.c +datehook_mod_CFLAGS = $(COMMON_CFLAGS) +datehook_mod_LDFLAGS = $(COMMON_LDFLAGS) + + +sbin_SCRIPTS += grub-install +grub_install_SOURCES = util/grub-install.in + diff --git a/conf/mips.rmk b/conf/mips.rmk new file mode 100644 index 000000000..d0b1c484c --- /dev/null +++ b/conf/mips.rmk @@ -0,0 +1,82 @@ + +# -*- makefile -*- + +COMMON_ASFLAGS += -nostdinc +COMMON_CFLAGS += -ffreestanding -mexplicit-relocs -mflush-func=grub_cpu_flush_cache +COMMON_LDFLAGS += -nostdlib + +# Used by various components. These rules need to precede them. +script/lexer.c_DEPENDENCIES = grub_script.tab.h + +# Images. + +MOSTLYCLEANFILES += symlist.c kernel_syms.lst +DEFSYMFILES += kernel_syms.lst + +kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ + env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h reader.h \ + symbol.h term.h time.h types.h loader.h partition.h \ + msdos_partition.h machine/kernel.h handler.h list.h \ + command.h machine/memory.h cpu/libgcc.h cpu/cache.h i18n.h + +ifeq ($(platform), yeeloong) +kernel_img_HEADERS += pci.h +endif + +symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh + /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh + /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) + +# Scripts. +sbin_SCRIPTS = +bin_SCRIPTS = + +# For grub-mkimage. +bin_UTILITIES += grub-mkimage +grub_mkimage_SOURCES = gnulib/progname.c util/grub-mkrawimage.c util/misc.c \ + util/resolve.c lib/LzmaEnc.c lib/LzFind.c +grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(LINK_BASE) +util/grub-mkrawimage.c_DEPENDENCIES = Makefile + +# Modules. +pkglib_MODULES = memdisk.mod \ + lsmmap.mod + +# For boot.mod. +pkglib_MODULES += boot.mod +boot_mod_SOURCES = commands/boot.c lib/i386/pc/biosnum.c +boot_mod_CFLAGS = $(COMMON_CFLAGS) +boot_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For memdisk.mod. +memdisk_mod_SOURCES = disk/memdisk.c +memdisk_mod_CFLAGS = $(COMMON_CFLAGS) +memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For lsmmap.mod +lsmmap_mod_SOURCES = commands/lsmmap.c +lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) +lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For serial.mod. +pkglib_MODULES += serial.mod +serial_mod_SOURCES = term/serial.c +serial_mod_CFLAGS = $(COMMON_CFLAGS) +serial_mod_LDFLAGS = $(COMMON_LDFLAGS) + +# For relocator.mod. +pkglib_MODULES += relocator.mod +relocator_mod_SOURCES = lib/$(target_cpu)/relocator.c lib/$(target_cpu)/relocator_asm.S +relocator_mod_CFLAGS = $(COMMON_CFLAGS) +relocator_mod_ASFLAGS = $(COMMON_ASFLAGS) +relocator_mod_LDFLAGS = $(COMMON_LDFLAGS) + +pkglib_MODULES += linux.mod +linux_mod_SOURCES = loader/$(target_cpu)/linux.c +linux_mod_CFLAGS = $(COMMON_CFLAGS) +linux_mod_ASFLAGS = $(COMMON_ASFLAGS) +linux_mod_LDFLAGS = $(COMMON_LDFLAGS) + +include $(srcdir)/conf/common.mk diff --git a/conf/x86_64-efi.rmk b/conf/x86_64-efi.rmk index b73773dbb..a4d1970aa 100644 --- a/conf/x86_64-efi.rmk +++ b/conf/x86_64-efi.rmk @@ -29,13 +29,14 @@ sbin_SCRIPTS = grub-install grub_install_SOURCES = util/i386/efi/grub-install.in # Modules. -pkglib_MODULES = kernel.img chain.mod appleldr.mod \ +pkglib_PROGRAMS = kernel.img +pkglib_MODULES = chain.mod appleldr.mod \ halt.mod reboot.mod pci.mod lspci.mod \ datetime.mod date.mod datehook.mod loadbios.mod \ fixvideo.mod mmap.mod acpi.mod # For kernel.img. -kernel_img_EXPORTS = no +kernel_img_RELOCATABLE = yes kernel_img_SOURCES = kern/x86_64/efi/startup.S kern/x86_64/efi/callwrap.S \ kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ diff --git a/configure.ac b/configure.ac index 4b5b5dd5a..a8e137b90 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,16 @@ fi case "$target_cpu" in i[[3456]]86) target_cpu=i386 ;; sparc) target_cpu=sparc64 ;; + mipsel|mips64el) + target_cpu=mips; + TARGET_CFLAGS="$TARGET_CFLAGS -DGRUB_CPU_MIPSEL=1"; + CFLAGS="$CFLAGS -DGRUB_CPU_MIPSEL=1"; + ;; + mips|mips64) + target_cpu=mips; + TARGET_CFLAGS="$TARGET_CFLAGS -DGRUB_CPU_MIPS=1"; + CFLAGS="$CFLAGS -DGRUB_CPU_MIPS=1"; + ;; esac # Specify the platform (such as firmware). @@ -69,6 +79,7 @@ if test "x$with_platform" = x; then powerpc-*) platform=ieee1275 ;; powerpc64-*) platform=ieee1275 ;; sparc64-*) platform=ieee1275 ;; + mips-*) platform=yeeloong ;; *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;; esac else @@ -95,6 +106,8 @@ case "$target_cpu"-"$platform" in i386-qemu) ;; powerpc-ieee1275) ;; sparc64-ieee1275) ;; + mips-qemu-mips) ;; + mips-yeeloong) ;; *-emu) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;; esac @@ -125,6 +138,8 @@ case "$platform" in qemu) machine_CFLAGS="-DGRUB_MACHINE_QEMU=1" ;; pc) machine_CFLAGS="-DGRUB_MACHINE_PCBIOS=1" ;; emu) machine_CFLAGS="-DGRUB_MACHINE_EMU=1" ;; + yeeloong) machine_CFLAGS="-DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; + qemu-mips) machine_CFLAGS="-DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;; esac CFLAGS="$CFLAGS $machine_CFLAGS" TARGET_ASFLAGS="$TARGET_ASFLAGS $machine_CFLAGS" diff --git a/disk/ata.c b/disk/ata.c index 864ae9488..833ccb976 100644 --- a/disk/ata.c +++ b/disk/ata.c @@ -26,8 +26,8 @@ #include /* At the moment, only two IDE ports are supported. */ -static const int grub_ata_ioaddress[] = { 0x1f0, 0x170 }; -static const int grub_ata_ioaddress2[] = { 0x3f6, 0x376 }; +static const grub_port_t grub_ata_ioaddress[] = { 0x1f0, 0x170 }; +static const grub_port_t grub_ata_ioaddress2[] = { 0x3f6, 0x376 }; static struct grub_ata_device *grub_ata_devices; @@ -347,8 +347,8 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2) /* Setup the device information. */ dev->port = port; dev->device = device; - dev->ioaddress = addr; - dev->ioaddress2 = addr2; + dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE; + dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE; dev->next = NULL; grub_ata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4); @@ -389,7 +389,7 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2) static int NESTED_FUNC_ATTR grub_ata_pciinit (grub_pci_device_t dev, - grub_pci_id_t pciid __attribute__((unused))) + grub_pci_id_t pciid) { static int compat_use[2] = { 0 }; grub_pci_address_t addr; @@ -400,19 +400,34 @@ grub_ata_pciinit (grub_pci_device_t dev, int regb; int i; static int controller = 0; + int cs5536 = 0; + int nports = 2; /* Read class. */ addr = grub_pci_make_address (dev, 2); class = grub_pci_read (addr); + /* AMD CS5536 Southbridge. */ + if (pciid == 0x208f1022) + { + cs5536 = 1; + nports = 1; + } + /* Check if this class ID matches that of a PCI IDE Controller. */ - if (class >> 16 != 0x0101) + if (!cs5536 && (class >> 16 != 0x0101)) return 0; - for (i = 0; i < 2; i++) + for (i = 0; i < nports; i++) { /* Set to 0 when the channel operated in compatibility mode. */ - int compat = (class >> (8 + 2 * i)) & 1; + int compat; + + /* We don't support non-compatibility mode for CS5536. */ + if (cs5536) + compat = 0; + else + compat = (class >> (8 + 2 * i)) & 1; rega = 0; regb = 0; @@ -485,7 +500,6 @@ grub_ata_initialize (void) return 0; } - static void grub_ata_setlba (struct grub_ata_device *dev, grub_disk_addr_t sector, grub_size_t size) @@ -648,12 +662,14 @@ grub_ata_iterate (int (*hook) (const char *name)) for (dev = grub_ata_devices; dev; dev = dev->next) { - char devname[5]; - grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device); + char devname[10]; if (dev->atapi) continue; + grub_snprintf (devname, sizeof (devname), + "ata%d", dev->port * 2 + dev->device); + if (hook (devname)) return 1; } @@ -668,8 +684,9 @@ grub_ata_open (const char *name, grub_disk_t disk) for (dev = grub_ata_devices; dev; dev = dev->next) { - char devname[5]; - grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device); + char devname[10]; + grub_snprintf (devname, sizeof (devname), + "ata%d", dev->port * 2 + dev->device); if (grub_strcmp (name, devname) == 0) break; } @@ -735,8 +752,9 @@ grub_atapi_iterate (int (*hook) (const char *name, int luns)) for (dev = grub_ata_devices; dev; dev = dev->next) { - char devname[7]; - grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device); + char devname[10]; + grub_snprintf (devname, sizeof (devname), + "ata%d", dev->port * 2 + dev->device); if (! dev->atapi) continue; @@ -808,8 +826,9 @@ grub_atapi_open (const char *name, struct grub_scsi *scsi) for (dev = grub_ata_devices; dev; dev = dev->next) { - char devname[7]; - grub_sprintf (devname, "ata%d", dev->port * 2 + dev->device); + char devname[10]; + grub_snprintf (devname, sizeof (devname), + "ata%d", dev->port * 2 + dev->device); if (!grub_strcmp (devname, name)) { diff --git a/disk/efi/efidisk.c b/disk/efi/efidisk.c index de848594a..58300a0d2 100644 --- a/disk/efi/efidisk.c +++ b/disk/efi/efidisk.c @@ -440,7 +440,7 @@ grub_efidisk_iterate (int (*hook) (const char *name)) for (d = fd_devices, count = 0; d; d = d->next, count++) { - grub_sprintf (buf, "fd%d", count); + grub_snprintf (buf, sizeof (buf), "fd%d", count); grub_dprintf ("efidisk", "iterating %s\n", buf); if (hook (buf)) return 1; @@ -448,7 +448,7 @@ grub_efidisk_iterate (int (*hook) (const char *name)) for (d = hd_devices, count = 0; d; d = d->next, count++) { - grub_sprintf (buf, "hd%d", count); + grub_snprintf (buf, sizeof (buf), "hd%d", count); grub_dprintf ("efidisk", "iterating %s\n", buf); if (hook (buf)) return 1; @@ -456,7 +456,7 @@ grub_efidisk_iterate (int (*hook) (const char *name)) for (d = cd_devices, count = 0; d; d = d->next, count++) { - grub_sprintf (buf, "cd%d", count); + grub_snprintf (buf, sizeof (buf), "cd%d", count); grub_dprintf ("efidisk", "iterating %s\n", buf); if (hook (buf)) return 1; @@ -805,18 +805,10 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle) return 0; } - device_name = grub_malloc (grub_strlen (parent->name) + 1 - + grub_strlen (partition_name) + 1); - if (! device_name) - { - grub_free (partition_name); - grub_disk_close (parent); - return 0; - } - - grub_sprintf (device_name, "%s,%s", parent->name, partition_name); + device_name = grub_xasprintf ("%s,%s", parent->name, partition_name); grub_free (partition_name); grub_disk_close (parent); + return device_name; } else diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c index 5f04ecc1e..682474b1a 100644 --- a/disk/i386/pc/biosdisk.c +++ b/disk/i386/pc/biosdisk.c @@ -56,7 +56,8 @@ grub_biosdisk_call_hook (int (*hook) (const char *name), int drive) { char name[10]; - grub_sprintf (name, (drive & 0x80) ? "hd%d" : "fd%d", drive & (~0x80)); + grub_snprintf (name, sizeof (name), + (drive & 0x80) ? "hd%d" : "fd%d", drive & (~0x80)); return hook (name); } diff --git a/disk/raid.c b/disk/raid.c index 5d2793a07..2d544afdc 100644 --- a/disk/raid.c +++ b/disk/raid.c @@ -556,7 +556,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, } } - array->name = grub_malloc (13); + array->name = grub_xasprintf ("md%d", array->number); if (! array->name) { grub_free (array->uuid); @@ -565,8 +565,6 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array, return grub_errno; } - grub_sprintf (array->name, "md%d", array->number); - grub_dprintf ("raid", "Found array %s (%s)\n", array->name, scanner_name); diff --git a/disk/scsi.c b/disk/scsi.c index 2a5e934f0..6f3233b29 100644 --- a/disk/scsi.c +++ b/disk/scsi.c @@ -197,7 +197,6 @@ grub_scsi_iterate (int (*hook) (const char *name)) int scsi_iterate (const char *name, int luns) { - char sname[40]; int i; /* In case of a single LUN, just return `usbX'. */ @@ -208,9 +207,13 @@ grub_scsi_iterate (int (*hook) (const char *name)) distinguish it. */ for (i = 0; i < luns; i++) { - grub_sprintf (sname, "%s%c", name, 'a' + i); + char *sname; + sname = grub_xasprintf ("%s%c", name, 'a' + i); + if (!sname) + return 1; if (hook (sname)) return 1; + grub_free (sname); } return 0; } diff --git a/disk/usbms.c b/disk/usbms.c index 51e886520..8554b224f 100644 --- a/disk/usbms.c +++ b/disk/usbms.c @@ -200,11 +200,15 @@ grub_usbms_iterate (int (*hook) (const char *name, int luns)) for (p = grub_usbms_dev_list; p; p = p->next) { - char devname[20]; - grub_sprintf (devname, "usb%d", cnt); + char *devname; + devname = grub_xasprintf ("usb%d", cnt); if (hook (devname, p->luns)) - return 1; + { + grub_free (devname); + return 1; + } + grub_free (devname); cnt++; } diff --git a/efiemu/main.c b/efiemu/main.c index a3cfdb5b5..9480bfc4d 100644 --- a/efiemu/main.c +++ b/efiemu/main.c @@ -255,12 +255,11 @@ grub_efiemu_autocore (void) suffix = grub_efiemu_get_default_core_name (); - filename = grub_malloc (grub_strlen (prefix) + grub_strlen (suffix) + 2); + filename = grub_xasprintf ("%s/%s", prefix, suffix); if (! filename) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate temporary space"); - grub_sprintf (filename, "%s/%s", prefix, suffix); err = grub_efiemu_load_file (filename); grub_free (filename); diff --git a/font/font.c b/font/font.c index 44827a9a1..9f8e0f5c6 100644 --- a/font/font.c +++ b/font/font.c @@ -1,7 +1,7 @@ /* font.c - Font API and font file loader. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,10 @@ #include #include +#ifdef USE_ASCII_FAILBACK +#include "ascii.h" +#endif + #ifndef FONT_DEBUG #define FONT_DEBUG 0 #endif @@ -43,6 +47,7 @@ struct char_index_entry #define FONT_WEIGHT_NORMAL 100 #define FONT_WEIGHT_BOLD 200 +#define ASCII_BITMAP_SIZE 16 struct grub_font { @@ -129,6 +134,48 @@ static struct grub_font null_font; /* Flag to ensure module is initialized only once. */ static grub_uint8_t font_loader_initialized; +#ifdef USE_ASCII_FAILBACK +static struct grub_font_glyph *ascii_font_glyph[0x80]; +#endif + +static struct grub_font_glyph * +ascii_glyph_lookup (grub_uint32_t code) +{ +#ifdef USE_ASCII_FAILBACK + static int ascii_failback_initialized = 0; + + if (code >= 0x80) + return unknown_glyph; + + if (ascii_failback_initialized == 0) + { + int current; + for (current = 0; current < 0x80; current++) + { + ascii_font_glyph[current] = grub_malloc(sizeof(struct grub_font_glyph) + + ASCII_BITMAP_SIZE); + + ascii_font_glyph[current]->width = 8; + ascii_font_glyph[current]->height = 16; + ascii_font_glyph[current]->offset_x = 0; + ascii_font_glyph[current]->offset_y = -2; + ascii_font_glyph[current]->device_width = 8; + + grub_memcpy (ascii_font_glyph[current]->bitmap, + &ascii_bitmaps[(0x7f - current) * ASCII_BITMAP_SIZE], + ASCII_BITMAP_SIZE); + } + + ascii_failback_initialized = 1; + } + + return ascii_font_glyph[code]; +#else + (void) code; + return unknown_glyph; +#endif +} + void grub_font_loader_init (void) { @@ -865,15 +912,17 @@ grub_font_get_string_width (grub_font_t font, const char *str) } /* Get the glyph for FONT corresponding to the Unicode code point CODE. - Returns a pointer to an glyph indicating there is no glyph available - if CODE does not exist in the font. The glyphs are cached once loaded. */ + Returns the ASCII glyph for the code if no other fonts are available. + The glyphs are cached once loaded. */ struct grub_font_glyph * grub_font_get_glyph (grub_font_t font, grub_uint32_t code) { struct grub_font_glyph *glyph; glyph = grub_font_get_glyph_internal (font, code); if (glyph == 0) - glyph = unknown_glyph; + { + glyph = ascii_glyph_lookup (code); + } return glyph; } @@ -968,8 +1017,8 @@ grub_font_get_glyph_with_fallback (grub_font_t font, grub_uint32_t code) if (best_glyph) return best_glyph; else - /* Glyph not available in any font. Return unknown glyph. */ - return unknown_glyph; + /* Glyph not available in any font. Return ASCII failback. */ + return ascii_glyph_lookup (code); } diff --git a/fs/cpio.c b/fs/cpio.c index 17c37975d..c087b4f90 100644 --- a/fs/cpio.c +++ b/fs/cpio.c @@ -280,8 +280,10 @@ grub_cpio_open (grub_file_t file, const char *name) /* Compare NAME and FN by hand in order to cope with duplicate slashes. */ - i = 1; + i = 0; j = 0; + while (name[i] == '/') + i++; while (1) { if (name[i] != fn[j]) @@ -290,13 +292,16 @@ grub_cpio_open (grub_file_t file, const char *name) if (name[i] == '\0') break; - if (name[i] == '/' && name[i+1] == '/') + while (name[i] == '/' && name[i+1] == '/') i++; i++; j++; } + if (name[i] != fn[j]) + goto no_match; + file->data = data; file->size = data->size; grub_free (fn); diff --git a/fs/ext2.c b/fs/ext2.c index 58be3e6fc..ac36b329b 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -875,12 +875,15 @@ grub_ext2_uuid (grub_device_t device, char **uuid) data = grub_ext2_mount (disk); if (data) { - *uuid = grub_malloc (40 + sizeof ('\0')); - grub_sprintf (*uuid, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", - grub_be_to_cpu16 (data->sblock.uuid[0]), grub_be_to_cpu16 (data->sblock.uuid[1]), - grub_be_to_cpu16 (data->sblock.uuid[2]), grub_be_to_cpu16 (data->sblock.uuid[3]), - grub_be_to_cpu16 (data->sblock.uuid[4]), grub_be_to_cpu16 (data->sblock.uuid[5]), - grub_be_to_cpu16 (data->sblock.uuid[6]), grub_be_to_cpu16 (data->sblock.uuid[7])); + *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", + grub_be_to_cpu16 (data->sblock.uuid[0]), + grub_be_to_cpu16 (data->sblock.uuid[1]), + grub_be_to_cpu16 (data->sblock.uuid[2]), + grub_be_to_cpu16 (data->sblock.uuid[3]), + grub_be_to_cpu16 (data->sblock.uuid[4]), + grub_be_to_cpu16 (data->sblock.uuid[5]), + grub_be_to_cpu16 (data->sblock.uuid[6]), + grub_be_to_cpu16 (data->sblock.uuid[7])); } else *uuid = NULL; diff --git a/fs/fat.c b/fs/fat.c index 8a0fc0292..d008dc10d 100644 --- a/fs/fat.c +++ b/fs/fat.c @@ -833,9 +833,9 @@ grub_fat_uuid (grub_device_t device, char **uuid) data = grub_fat_mount (disk); if (data) { - *uuid = grub_malloc (sizeof ("xxxx-xxxx")); - grub_sprintf (*uuid, "%04x-%04x", (grub_uint16_t) (data->uuid >> 16), - (grub_uint16_t) data->uuid); + *uuid = grub_xasprintf ("%04x-%04x", + (grub_uint16_t) (data->uuid >> 16), + (grub_uint16_t) data->uuid); } else *uuid = NULL; diff --git a/fs/hfs.c b/fs/hfs.c index f7dc2484f..cef856326 100644 --- a/fs/hfs.c +++ b/fs/hfs.c @@ -1082,10 +1082,9 @@ grub_hfs_uuid (grub_device_t device, char **uuid) data = grub_hfs_mount (device->disk); if (data && data->sblock.num_serial != 0) { - *uuid = grub_malloc (16 + sizeof ('\0')); - grub_sprintf (*uuid, "%016llx", - (unsigned long long) - grub_be_to_cpu64 (data->sblock.num_serial)); + *uuid = grub_xasprintf ("%016llx", + (unsigned long long) + grub_be_to_cpu64 (data->sblock.num_serial)); } else *uuid = NULL; diff --git a/fs/hfsplus.c b/fs/hfsplus.c index 9310b6502..bcb8e9584 100644 --- a/fs/hfsplus.c +++ b/fs/hfsplus.c @@ -995,10 +995,9 @@ grub_hfsplus_uuid (grub_device_t device, char **uuid) data = grub_hfsplus_mount (disk); if (data) { - *uuid = grub_malloc (16 + sizeof ('\0')); - grub_sprintf (*uuid, "%016llx", - (unsigned long long) - grub_be_to_cpu64 (data->volheader.num_serial)); + *uuid = grub_xasprintf ("%016llx", + (unsigned long long) + grub_be_to_cpu64 (data->volheader.num_serial)); } else *uuid = NULL; diff --git a/fs/i386/pc/pxe.c b/fs/i386/pc/pxe.c index 03385b3e3..8bfe17594 100644 --- a/fs/i386/pc/pxe.c +++ b/fs/i386/pc/pxe.c @@ -356,7 +356,8 @@ set_mac_env (grub_uint8_t *mac_addr, grub_size_t mac_len) for (i = 0; i < mac_len; i++) { - grub_sprintf (ptr, "%02x:", mac_addr[i] & 0xff); + grub_snprintf (ptr, sizeof (buf) - (ptr - buf), + "%02x:", mac_addr[i] & 0xff); ptr += (sizeof ("XX:") - 1); } if (mac_len) @@ -483,8 +484,8 @@ set_ip_env (char *varname, grub_uint32_t ip) { char buf[sizeof ("XXX.XXX.XXX.XXX")]; - grub_sprintf (buf, "%d.%d.%d.%d", (ip & 0xff), - (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff); + grub_snprintf (buf, sizeof (buf), "%d.%d.%d.%d", (ip & 0xff), + (ip >> 8) & 0xff, (ip >> 16) & 0xff, (ip >> 24) & 0xff); grub_env_set (varname, buf); } @@ -500,15 +501,13 @@ write_ip_env (grub_uint32_t *ip, const char *val) return 0; /* Normalize the IP. */ - buf = grub_malloc (sizeof ("XXX.XXX.XXX.XXX")); + buf = grub_xasprintf ("%d.%d.%d.%d", (newip & 0xff), (newip >> 8) & 0xff, + (newip >> 16) & 0xff, (newip >> 24) & 0xff); if (!buf) return 0; *ip = newip; - grub_sprintf (buf, "%d.%d.%d.%d", (newip & 0xff), (newip >> 8) & 0xff, - (newip >> 16) & 0xff, (newip >> 24) & 0xff); - return buf; } @@ -544,11 +543,10 @@ grub_env_write_pxe_blocksize (struct grub_env_var *var __attribute__ ((unused)), else if (size > GRUB_PXE_MAX_BLKSIZE) size = GRUB_PXE_MAX_BLKSIZE; - buf = grub_malloc (sizeof ("XXXXXX XXXXXX")); + buf = grub_xasprintf ("%d", size); if (!buf) return 0; - grub_sprintf (buf, "%d", size); grub_pxe_blksize = size; return buf; @@ -562,12 +560,10 @@ GRUB_MOD_INIT(pxe) { char *buf; - buf = grub_malloc (sizeof ("XXXXXX XXXXXX")); + buf = grub_xasprintf ("%d", grub_pxe_blksize); if (buf) - { - grub_sprintf (buf, "%d", grub_pxe_blksize); - grub_env_set ("net_pxe_blksize", buf); - } + grub_env_set ("net_pxe_blksize", buf); + grub_free (buf); set_ip_env ("pxe_default_server", grub_pxe_default_server_ip); set_ip_env ("pxe_default_gateway", grub_pxe_default_gateway_ip); diff --git a/fs/iso9660.c b/fs/iso9660.c index 1ab98be3f..a8a310f50 100644 --- a/fs/iso9660.c +++ b/fs/iso9660.c @@ -840,16 +840,23 @@ grub_iso9660_uuid (grub_device_t device, char **uuid) } else { - *uuid = grub_malloc (sizeof ("YYYY-MM-DD-HH-mm-ss-hh")); - grub_sprintf (*uuid, "%c%c%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c", - data->voldesc.modified.year[0], data->voldesc.modified.year[1], - data->voldesc.modified.year[2], data->voldesc.modified.year[3], - data->voldesc.modified.month[0], data->voldesc.modified.month[1], - data->voldesc.modified.day[0], data->voldesc.modified.day[1], - data->voldesc.modified.hour[0], data->voldesc.modified.hour[1], - data->voldesc.modified.minute[0], data->voldesc.modified.minute[1], - data->voldesc.modified.second[0], data->voldesc.modified.second[1], - data->voldesc.modified.hundredth[0], data->voldesc.modified.hundredth[1]); + *uuid = grub_xasprintf ("%c%c%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c", + data->voldesc.modified.year[0], + data->voldesc.modified.year[1], + data->voldesc.modified.year[2], + data->voldesc.modified.year[3], + data->voldesc.modified.month[0], + data->voldesc.modified.month[1], + data->voldesc.modified.day[0], + data->voldesc.modified.day[1], + data->voldesc.modified.hour[0], + data->voldesc.modified.hour[1], + data->voldesc.modified.minute[0], + data->voldesc.modified.minute[1], + data->voldesc.modified.second[0], + data->voldesc.modified.second[1], + data->voldesc.modified.hundredth[0], + data->voldesc.modified.hundredth[1]); } } else diff --git a/fs/jfs.c b/fs/jfs.c index dc5eaed67..c9839a22f 100644 --- a/fs/jfs.c +++ b/fs/jfs.c @@ -842,17 +842,16 @@ grub_jfs_uuid (grub_device_t device, char **uuid) data = grub_jfs_mount (disk); if (data) { - *uuid = grub_malloc (40 + sizeof ('\0')); - - grub_sprintf (*uuid, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - data->sblock.uuid[0], data->sblock.uuid[1], - data->sblock.uuid[2], data->sblock.uuid[3], - data->sblock.uuid[4], data->sblock.uuid[5], - data->sblock.uuid[6], data->sblock.uuid[7], - data->sblock.uuid[8], data->sblock.uuid[9], - data->sblock.uuid[10], data->sblock.uuid[11], - data->sblock.uuid[12], data->sblock.uuid[13], - data->sblock.uuid[14], data->sblock.uuid[15]); + *uuid = grub_xasprintf ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x", + data->sblock.uuid[0], data->sblock.uuid[1], + data->sblock.uuid[2], data->sblock.uuid[3], + data->sblock.uuid[4], data->sblock.uuid[5], + data->sblock.uuid[6], data->sblock.uuid[7], + data->sblock.uuid[8], data->sblock.uuid[9], + data->sblock.uuid[10], data->sblock.uuid[11], + data->sblock.uuid[12], data->sblock.uuid[13], + data->sblock.uuid[14], data->sblock.uuid[15]); } else *uuid = NULL; diff --git a/fs/ntfs.c b/fs/ntfs.c index c1b4b2fe1..dd041e23a 100644 --- a/fs/ntfs.c +++ b/fs/ntfs.c @@ -1072,8 +1072,7 @@ grub_ntfs_uuid (grub_device_t device, char **uuid) data = grub_ntfs_mount (disk); if (data) { - *uuid = grub_malloc (16 + sizeof ('\0')); - grub_sprintf (*uuid, "%016llx", (unsigned long long) data->uuid); + *uuid = grub_xasprintf ("%016llx", (unsigned long long) data->uuid); } else *uuid = NULL; diff --git a/fs/reiserfs.c b/fs/reiserfs.c index a8ba75910..444bf3120 100644 --- a/fs/reiserfs.c +++ b/fs/reiserfs.c @@ -1335,12 +1335,15 @@ grub_reiserfs_uuid (grub_device_t device, char **uuid) data = grub_reiserfs_mount (disk); if (data) { - *uuid = grub_malloc (sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")); - grub_sprintf (*uuid, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", - grub_be_to_cpu16 (data->superblock.uuid[0]), grub_be_to_cpu16 (data->superblock.uuid[1]), - grub_be_to_cpu16 (data->superblock.uuid[2]), grub_be_to_cpu16 (data->superblock.uuid[3]), - grub_be_to_cpu16 (data->superblock.uuid[4]), grub_be_to_cpu16 (data->superblock.uuid[5]), - grub_be_to_cpu16 (data->superblock.uuid[6]), grub_be_to_cpu16 (data->superblock.uuid[7])); + *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", + grub_be_to_cpu16 (data->superblock.uuid[0]), + grub_be_to_cpu16 (data->superblock.uuid[1]), + grub_be_to_cpu16 (data->superblock.uuid[2]), + grub_be_to_cpu16 (data->superblock.uuid[3]), + grub_be_to_cpu16 (data->superblock.uuid[4]), + grub_be_to_cpu16 (data->superblock.uuid[5]), + grub_be_to_cpu16 (data->superblock.uuid[6]), + grub_be_to_cpu16 (data->superblock.uuid[7])); } else *uuid = NULL; diff --git a/fs/ufs.c b/fs/ufs.c index 9f3743d8b..40cf068e6 100644 --- a/fs/ufs.c +++ b/fs/ufs.c @@ -732,12 +732,9 @@ grub_ufs_uuid (grub_device_t device, char **uuid) data = grub_ufs_mount (disk); if (data && (data->sblock.uuidhi != 0 || data->sblock.uuidlow != 0)) - { - *uuid = grub_malloc (16 + sizeof ('\0')); - grub_sprintf (*uuid, "%08x%08x", - (unsigned) grub_le_to_cpu32 (data->sblock.uuidhi), - (unsigned) grub_le_to_cpu32 (data->sblock.uuidlow)); - } + *uuid = grub_xasprintf ("%08x%08x", + (unsigned) grub_le_to_cpu32 (data->sblock.uuidhi), + (unsigned) grub_le_to_cpu32 (data->sblock.uuidlow)); else *uuid = NULL; diff --git a/fs/xfs.c b/fs/xfs.c index 8b512de37..9dffe31d1 100644 --- a/fs/xfs.c +++ b/fs/xfs.c @@ -777,12 +777,15 @@ grub_xfs_uuid (grub_device_t device, char **uuid) data = grub_xfs_mount (disk); if (data) { - *uuid = grub_malloc (sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")); - grub_sprintf (*uuid, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", - grub_be_to_cpu16 (data->sblock.uuid[0]), grub_be_to_cpu16 (data->sblock.uuid[1]), - grub_be_to_cpu16 (data->sblock.uuid[2]), grub_be_to_cpu16 (data->sblock.uuid[3]), - grub_be_to_cpu16 (data->sblock.uuid[4]), grub_be_to_cpu16 (data->sblock.uuid[5]), - grub_be_to_cpu16 (data->sblock.uuid[6]), grub_be_to_cpu16 (data->sblock.uuid[7])); + *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", + grub_be_to_cpu16 (data->sblock.uuid[0]), + grub_be_to_cpu16 (data->sblock.uuid[1]), + grub_be_to_cpu16 (data->sblock.uuid[2]), + grub_be_to_cpu16 (data->sblock.uuid[3]), + grub_be_to_cpu16 (data->sblock.uuid[4]), + grub_be_to_cpu16 (data->sblock.uuid[5]), + grub_be_to_cpu16 (data->sblock.uuid[6]), + grub_be_to_cpu16 (data->sblock.uuid[7])); } else *uuid = NULL; diff --git a/genmk.rb b/genmk.rb index afd1582aa..df03e1dfe 100644 --- a/genmk.rb +++ b/genmk.rb @@ -68,7 +68,7 @@ MOSTLYCLEAN_IMAGE_TARGETS += mostlyclean-image-#{@name}.#{@rule_count} ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{exe} - $(OBJCOPY) -O $(#{prefix}_FORMAT) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id $< $@ + $(OBJCOPY) -O $(#{prefix}_FORMAT) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn $< $@ else ifneq (#{exe},kernel.exec) #{@name}: #{exe} ./grub-macho2img @@ -132,13 +132,11 @@ clean-module-#{@name}.#{@rule_count}: CLEAN_MODULE_TARGETS += clean-module-#{@name}.#{@rule_count} -ifneq ($(#{prefix}_EXPORTS),no) clean-module-#{@name}-symbol.#{@rule_count}: rm -f #{defsym} CLEAN_MODULE_TARGETS += clean-module-#{@name}-symbol.#{@rule_count} DEFSYMFILES += #{defsym} -endif mostlyclean-module-#{@name}.#{@rule_count}: rm -f #{deps_str} @@ -170,7 +168,6 @@ endif #{mod_src}: $(builddir)/moddep.lst $(srcdir)/genmodsrc.sh sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1) -ifneq ($(#{prefix}_EXPORTS),no) ifneq ($(TARGET_APPLE_CC),1) #{defsym}: #{pre_obj} $(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ @@ -178,7 +175,6 @@ else #{defsym}: #{pre_obj} $(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@ endif -endif #{undsym}: #{pre_obj} echo '#{mod_name}' > $@ @@ -331,8 +327,15 @@ class Program "CLEANFILES += #{@name} #{objs_str} MOSTLYCLEANFILES += #{deps_str} +ifeq ($(#{prefix}_RELOCATABLE),yes) +#{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str} + $(TARGET_CC) -Wl,-r,-d -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS) + $(STRIP) --strip-unneeded -K start -R .note -R .comment $@ +else #{@name}: $(#{prefix}_DEPENDENCIES) #{objs_str} $(TARGET_CC) -o $@ #{objs_str} $(TARGET_LDFLAGS) $(#{prefix}_LDFLAGS) + $(STRIP) -R .rel.dyn -R .reginfo -R .note -R .comment $@ +endif " + objs.collect_with_index do |obj, i| src = sources[i] @@ -344,6 +347,7 @@ MOSTLYCLEANFILES += #{deps_str} "#{obj}: #{src} $(#{src}_DEPENDENCIES) $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $< + -include #{dep} " diff --git a/genmoddep.awk b/genmoddep.awk index f7f085e99..19ac80c71 100644 --- a/genmoddep.awk +++ b/genmoddep.awk @@ -29,7 +29,7 @@ FNR == 1 { if ($1 in symtab) { modtab[module] = modtab[module] " " symtab[$1]; } - else { + else if ($1 != "__gnu_local_gp") { printf "%s in %s is not defined\n", $1, module >"/dev/stderr"; error++; exit; diff --git a/gettext/gettext.c b/gettext/gettext.c index 83497b7f6..9a1756be7 100644 --- a/gettext/gettext.c +++ b/gettext/gettext.c @@ -286,14 +286,19 @@ grub_gettext_init_ext (const char *lang) /* Warning: if changing some paths in the below line, change the grub_malloc contents below. */ - grub_sprintf (mo_file, "%s/%s.mo", locale_dir, lang); + mo_file = grub_xasprintf ("%s/%s.mo", locale_dir, lang); + if (!mo_file) + return; fd_mo = grub_mofile_open (mo_file); /* Will try adding .gz as well. */ if (fd_mo == NULL) { - grub_sprintf (mo_file, "%s.gz", mo_file); + grub_free (mo_file); + mo_file = grub_xasprintf ("%s.gz", mo_file); + if (!mo_file) + return; fd_mo = grub_mofile_open (mo_file); } diff --git a/hook/datehook.c b/hook/datehook.c index b7663cc21..4876e1198 100644 --- a/hook/datehook.c +++ b/hook/datehook.c @@ -76,7 +76,7 @@ grub_read_hook_datetime (struct grub_env_var *var, return grub_get_weekday_name (&datetime); } - grub_sprintf (buf, "%d", n); + grub_snprintf (buf, sizeof (buf), "%d", n); break; } } diff --git a/include/grub/at_keyboard.h b/include/grub/at_keyboard.h new file mode 100644 index 000000000..10421540a --- /dev/null +++ b/include/grub/at_keyboard.h @@ -0,0 +1,54 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_AT_KEYBOARD_HEADER +#define GRUB_AT_KEYBOARD_HEADER 1 + +#define SHIFT_L 0x2a +#define SHIFT_R 0x36 +#define CTRL 0x1d +#define ALT 0x38 +#define CAPS_LOCK 0x3a +#define NUM_LOCK 0x45 +#define SCROLL_LOCK 0x46 + +/* Used for sending commands to the controller. */ +#define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02) +#define KEYBOARD_COMMAND_READ 0x20 +#define KEYBOARD_COMMAND_WRITE 0x60 +#define KEYBOARD_COMMAND_REBOOT 0xfe + +#define KEYBOARD_SCANCODE_SET1 0x40 + +#define KEYBOARD_ISMAKE(x) !((x) & 0x80) +#define KEYBOARD_ISREADY(x) ((x) & 0x01) +#define KEYBOARD_SCANCODE(x) ((x) & 0x7f) + +#ifdef GRUB_MACHINE_IEEE1275 +#define OLPC_UP GRUB_TERM_UP +#define OLPC_DOWN GRUB_TERM_DOWN +#define OLPC_LEFT GRUB_TERM_LEFT +#define OLPC_RIGHT GRUB_TERM_RIGHT +#else +#define OLPC_UP '\0' +#define OLPC_DOWN '\0' +#define OLPC_LEFT '\0' +#define OLPC_RIGHT '\0' +#endif + +#endif diff --git a/include/grub/ata.h b/include/grub/ata.h index aaa2e147a..940e67102 100644 --- a/include/grub/ata.h +++ b/include/grub/ata.h @@ -98,8 +98,8 @@ struct grub_ata_device /* IO addresses on which the registers for this device can be found. */ - int ioaddress; - int ioaddress2; + grub_port_t ioaddress; + grub_port_t ioaddress2; /* Two devices can be connected to a single cable. Use this field to select device 0 (commonly known as "master") or device 1 diff --git a/include/grub/cmos.h b/include/grub/cmos.h new file mode 100644 index 000000000..f508e3bf6 --- /dev/null +++ b/include/grub/cmos.h @@ -0,0 +1,72 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008, 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_CMOS_H +#define GRUB_CMOS_H 1 + +#include +#include +#include + +#define GRUB_CMOS_INDEX_SECOND 0 +#define GRUB_CMOS_INDEX_SECOND_ALARM 1 +#define GRUB_CMOS_INDEX_MINUTE 2 +#define GRUB_CMOS_INDEX_MINUTE_ALARM 3 +#define GRUB_CMOS_INDEX_HOUR 4 +#define GRUB_CMOS_INDEX_HOUR_ALARM 5 +#define GRUB_CMOS_INDEX_DAY_OF_WEEK 6 +#define GRUB_CMOS_INDEX_DAY_OF_MONTH 7 +#define GRUB_CMOS_INDEX_MONTH 8 +#define GRUB_CMOS_INDEX_YEAR 9 + +#define GRUB_CMOS_INDEX_STATUS_A 0xA +#define GRUB_CMOS_INDEX_STATUS_B 0xB +#define GRUB_CMOS_INDEX_STATUS_C 0xC +#define GRUB_CMOS_INDEX_STATUS_D 0xD + +#define GRUB_CMOS_STATUS_B_DAYLIGHT 1 +#define GRUB_CMOS_STATUS_B_24HOUR 2 +#define GRUB_CMOS_STATUS_B_BINARY 4 + +static inline grub_uint8_t +grub_bcd_to_num (grub_uint8_t a) +{ + return ((a >> 4) * 10 + (a & 0xF)); +} + +static inline grub_uint8_t +grub_num_to_bcd (grub_uint8_t a) +{ + return (((a / 10) << 4) + (a % 10)); +} + +static inline grub_uint8_t +grub_cmos_read (grub_uint8_t index) +{ + grub_outb (index, GRUB_CMOS_ADDR_REG); + return grub_inb (GRUB_CMOS_DATA_REG); +} + +static inline void +grub_cmos_write (grub_uint8_t index, grub_uint8_t value) +{ + grub_outb (index, GRUB_CMOS_ADDR_REG); + grub_outb (value, GRUB_CMOS_DATA_REG); +} + +#endif /* GRUB_CMOS_H */ diff --git a/include/grub/dl.h b/include/grub/dl.h index 3f8b328da..9340b6ce4 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -116,4 +116,9 @@ grub_err_t EXPORT_FUNC(grub_dl_register_symbol) (const char *name, void *addr, grub_err_t grub_arch_dl_check_header (void *ehdr); grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr); +#if defined (_mips) && ! defined (GRUB_UTIL) +#define GRUB_LINKER_HAVE_INIT 1 +void grub_arch_dl_init_linker (void); +#endif + #endif /* ! GRUB_DL_H */ diff --git a/include/grub/elfload.h b/include/grub/elfload.h index 1e640c198..83fb9128a 100644 --- a/include/grub/elfload.h +++ b/include/grub/elfload.h @@ -46,12 +46,12 @@ grub_elf_t grub_elf_file (grub_file_t); grub_err_t grub_elf_close (grub_elf_t); int grub_elf_is_elf32 (grub_elf_t); -grub_size_t grub_elf32_size (grub_elf_t); +grub_size_t grub_elf32_size (grub_elf_t, Elf32_Addr *); grub_err_t grub_elf32_load (grub_elf_t, grub_elf32_load_hook_t, grub_addr_t *, grub_size_t *); int grub_elf_is_elf64 (grub_elf_t); -grub_size_t grub_elf64_size (grub_elf_t); +grub_size_t grub_elf64_size (grub_elf_t, Elf64_Addr *); grub_err_t grub_elf64_load (grub_elf_t, grub_elf64_load_hook_t, grub_addr_t *, grub_size_t *); grub_err_t diff --git a/include/grub/font.h b/include/grub/font.h index 8a5f3ac7d..1816e3570 100644 --- a/include/grub/font.h +++ b/include/grub/font.h @@ -21,6 +21,7 @@ #include #include +#include /* Forward declaration of opaque structure grub_font. Users only pass struct grub_font pointers to the font module functions, diff --git a/include/grub/i386/at_keyboard.h b/include/grub/i386/at_keyboard.h index e6ee60d28..da4e80654 100644 --- a/include/grub/i386/at_keyboard.h +++ b/include/grub/i386/at_keyboard.h @@ -19,40 +19,7 @@ #ifndef GRUB_CPU_AT_KEYBOARD_HEADER #define GRUB_CPU_AT_KEYBOARD_HEADER 1 - -#define SHIFT_L 0x2a -#define SHIFT_R 0x36 -#define CTRL 0x1d -#define ALT 0x38 -#define CAPS_LOCK 0x3a -#define NUM_LOCK 0x45 -#define SCROLL_LOCK 0x46 - #define KEYBOARD_REG_DATA 0x60 #define KEYBOARD_REG_STATUS 0x64 -/* Used for sending commands to the controller. */ -#define KEYBOARD_COMMAND_ISREADY(x) !((x) & 0x02) -#define KEYBOARD_COMMAND_READ 0x20 -#define KEYBOARD_COMMAND_WRITE 0x60 -#define KEYBOARD_COMMAND_REBOOT 0xfe - -#define KEYBOARD_SCANCODE_SET1 0x40 - -#define KEYBOARD_ISMAKE(x) !((x) & 0x80) -#define KEYBOARD_ISREADY(x) ((x) & 0x01) -#define KEYBOARD_SCANCODE(x) ((x) & 0x7f) - -#ifdef GRUB_MACHINE_IEEE1275 -#define OLPC_UP GRUB_TERM_UP -#define OLPC_DOWN GRUB_TERM_DOWN -#define OLPC_LEFT GRUB_TERM_LEFT -#define OLPC_RIGHT GRUB_TERM_RIGHT -#else -#define OLPC_UP '\0' -#define OLPC_DOWN '\0' -#define OLPC_LEFT '\0' -#define OLPC_RIGHT '\0' -#endif - #endif diff --git a/include/grub/i386/cmos.h b/include/grub/i386/cmos.h index 1c0530dba..8b1fa3586 100644 --- a/include/grub/i386/cmos.h +++ b/include/grub/i386/cmos.h @@ -20,55 +20,9 @@ #define GRUB_CPU_CMOS_H 1 #include -#include +#include #define GRUB_CMOS_ADDR_REG 0x70 #define GRUB_CMOS_DATA_REG 0x71 -#define GRUB_CMOS_INDEX_SECOND 0 -#define GRUB_CMOS_INDEX_SECOND_ALARM 1 -#define GRUB_CMOS_INDEX_MINUTE 2 -#define GRUB_CMOS_INDEX_MINUTE_ALARM 3 -#define GRUB_CMOS_INDEX_HOUR 4 -#define GRUB_CMOS_INDEX_HOUR_ALARM 5 -#define GRUB_CMOS_INDEX_DAY_OF_WEEK 6 -#define GRUB_CMOS_INDEX_DAY_OF_MONTH 7 -#define GRUB_CMOS_INDEX_MONTH 8 -#define GRUB_CMOS_INDEX_YEAR 9 - -#define GRUB_CMOS_INDEX_STATUS_A 0xA -#define GRUB_CMOS_INDEX_STATUS_B 0xB -#define GRUB_CMOS_INDEX_STATUS_C 0xC -#define GRUB_CMOS_INDEX_STATUS_D 0xD - -#define GRUB_CMOS_STATUS_B_DAYLIGHT 1 -#define GRUB_CMOS_STATUS_B_24HOUR 2 -#define GRUB_CMOS_STATUS_B_BINARY 4 - -static inline grub_uint8_t -grub_bcd_to_num (grub_uint8_t a) -{ - return ((a >> 4) * 10 + (a & 0xF)); -} - -static inline grub_uint8_t -grub_num_to_bcd (grub_uint8_t a) -{ - return (((a / 10) << 4) + (a % 10)); -} - -static inline grub_uint8_t -grub_cmos_read (grub_uint8_t index) -{ - grub_outb (index, GRUB_CMOS_ADDR_REG); - return grub_inb (GRUB_CMOS_DATA_REG); -} - -static inline void -grub_cmos_write (grub_uint8_t index, grub_uint8_t value) -{ - grub_outb (index, GRUB_CMOS_ADDR_REG); - grub_outb (value, GRUB_CMOS_DATA_REG); -} - #endif /* GRUB_CPU_CMOS_H */ diff --git a/include/grub/i386/coreboot/serial.h b/include/grub/i386/coreboot/serial.h index 2c527f626..b6819d587 100644 --- a/include/grub/i386/coreboot/serial.h +++ b/include/grub/i386/coreboot/serial.h @@ -1 +1,24 @@ -#include +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MACHINE_SERIAL_HEADER +#define GRUB_MACHINE_SERIAL_HEADER 1 + +#define GRUB_MACHINE_SERIAL_PORTS { 0x3f8, 0x2f8, 0x3e8, 0x2e8 } + +#endif diff --git a/include/grub/i386/efi/serial.h b/include/grub/i386/efi/serial.h new file mode 100644 index 000000000..2d8563414 --- /dev/null +++ b/include/grub/i386/efi/serial.h @@ -0,0 +1 @@ +#include diff --git a/include/grub/i386/ieee1275/serial.h b/include/grub/i386/ieee1275/serial.h index 2c527f626..2d8563414 100644 --- a/include/grub/i386/ieee1275/serial.h +++ b/include/grub/i386/ieee1275/serial.h @@ -1 +1 @@ -#include +#include diff --git a/include/grub/i386/io.h b/include/grub/i386/io.h index 0e567766b..ae12a3e3d 100644 --- a/include/grub/i386/io.h +++ b/include/grub/i386/io.h @@ -21,6 +21,8 @@ #ifndef GRUB_IO_H #define GRUB_IO_H 1 +typedef unsigned short int grub_port_t; + static __inline unsigned char grub_inb (unsigned short int port) { diff --git a/include/grub/i386/pci.h b/include/grub/i386/pci.h index 31217d5f5..bab42adb6 100644 --- a/include/grub/i386/pci.h +++ b/include/grub/i386/pci.h @@ -22,8 +22,11 @@ #include #include +#define GRUB_MACHINE_PCI_IO_BASE 0 #define GRUB_PCI_ADDR_REG 0xcf8 #define GRUB_PCI_DATA_REG 0xcfc +#define GRUB_PCI_NUM_BUS 256 +#define GRUB_PCI_NUM_DEVICES 32 static inline grub_uint32_t grub_pci_read (grub_pci_address_t addr) @@ -67,12 +70,12 @@ grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data) grub_outb (data, GRUB_PCI_DATA_REG + (addr & 3)); } -static inline void * +static inline volatile void * grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)), grub_addr_t base, grub_size_t size __attribute__ ((unused))) { - return (void *) base; + return (volatile void *) base; } static inline void diff --git a/include/grub/kernel.h b/include/grub/kernel.h index 75ec77c2a..9586a90b9 100644 --- a/include/grub/kernel.h +++ b/include/grub/kernel.h @@ -26,7 +26,8 @@ enum { OBJ_TYPE_ELF, OBJ_TYPE_MEMDISK, - OBJ_TYPE_CONFIG + OBJ_TYPE_CONFIG, + OBJ_TYPE_FONT }; /* The module header. */ diff --git a/include/grub/mips/at_keyboard.h b/include/grub/mips/at_keyboard.h new file mode 100644 index 000000000..0c307537d --- /dev/null +++ b/include/grub/mips/at_keyboard.h @@ -0,0 +1 @@ +#include diff --git a/include/grub/mips/cache.h b/include/grub/mips/cache.h new file mode 100644 index 000000000..c3470571e --- /dev/null +++ b/include/grub/mips/cache.h @@ -0,0 +1,27 @@ +/* cache.h - Flush the processor's cache. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2007 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_CPU_CACHE_H +#define GRUB_CPU_CACHE_H 1 + +#include +#include + +void EXPORT_FUNC(grub_cpu_flush_cache) (void *start, grub_size_t size, int type); +#endif diff --git a/include/grub/mips/cmos.h b/include/grub/mips/cmos.h new file mode 100644 index 000000000..79a7a4c1b --- /dev/null +++ b/include/grub/mips/cmos.h @@ -0,0 +1 @@ +#include diff --git a/include/grub/mips/io.h b/include/grub/mips/io.h new file mode 100644 index 000000000..dee76bde5 --- /dev/null +++ b/include/grub/mips/io.h @@ -0,0 +1,62 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_IO_H +#define GRUB_IO_H 1 + +#include + +typedef grub_addr_t grub_port_t; + +static __inline unsigned char +grub_inb (grub_port_t port) +{ + return *(volatile grub_uint8_t *) port; +} + +static __inline unsigned short int +grub_inw (grub_port_t port) +{ + return *(volatile grub_uint16_t *) port; +} + +static __inline unsigned int +grub_inl (grub_port_t port) +{ + return *(volatile grub_uint32_t *) port; +} + +static __inline void +grub_outb (unsigned char value, grub_port_t port) +{ + *(volatile grub_uint8_t *) port = value; +} + +static __inline void +grub_outw (unsigned short int value, grub_port_t port) +{ + *(volatile grub_uint16_t *) port = value; +} + +static __inline void +grub_outl (unsigned int value, grub_port_t port) +{ + *(volatile grub_uint32_t *) port = value; +} + +#endif /* _SYS_IO_H */ diff --git a/include/grub/mips/kernel.h b/include/grub/mips/kernel.h new file mode 100644 index 000000000..8b68f7b6b --- /dev/null +++ b/include/grub/mips/kernel.h @@ -0,0 +1,65 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_KERNEL_CPU_HEADER +#define GRUB_KERNEL_CPU_HEADER 1 + +#define GRUB_MOD_ALIGN 0x1 +/* Non-zero value is only needed for PowerMacs. */ +#define GRUB_MOD_GAP 0x0 + +#define GRUB_KERNEL_MACHINE_LINK_ALIGN 32 + +#define GRUB_KERNEL_CPU_RAW_SIZE 0x200 +#define GRUB_KERNEL_CPU_COMPRESSED_SIZE 0x8 +#define GRUB_KERNEL_CPU_TOTAL_MODULE_SIZE 0xc +#define GRUB_KERNEL_CPU_KERNEL_IMAGE_SIZE 0x10 + +#define GRUB_KERNEL_CPU_PREFIX GRUB_KERNEL_CPU_RAW_SIZE +#define GRUB_KERNEL_CPU_DATA_END GRUB_KERNEL_CPU_RAW_SIZE + 0x48 + +#define GRUB_KERNEL_MACHINE_RAW_SIZE GRUB_KERNEL_CPU_RAW_SIZE + +#define GRUB_KERNEL_MACHINE_PREFIX GRUB_KERNEL_CPU_PREFIX +#define GRUB_KERNEL_MACHINE_DATA_END GRUB_KERNEL_CPU_DATA_END +#define GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE GRUB_KERNEL_CPU_KERNEL_IMAGE_SIZE +#define GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE GRUB_KERNEL_CPU_TOTAL_MODULE_SIZE +#define GRUB_KERNEL_MACHINE_COMPRESSED_SIZE GRUB_KERNEL_CPU_COMPRESSED_SIZE + +#define GRUB_PLATFORM_IMAGE_FORMATS "raw, elf" +#define GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT "raw" + +#define GRUB_PLATFORM_IMAGE_DEFAULT GRUB_PLATFORM_IMAGE_RAW + +#ifndef ASM_FILE + +typedef enum { + GRUB_PLATFORM_IMAGE_RAW, + GRUB_PLATFORM_IMAGE_ELF +} + grub_platform_image_format_t; +#define GRUB_PLATFORM_IMAGE_RAW GRUB_PLATFORM_IMAGE_RAW +#define GRUB_PLATFORM_IMAGE_ELF GRUB_PLATFORM_IMAGE_ELF + +/* The prefix which points to the directory where GRUB modules and its + configuration file are located. */ +extern char grub_prefix[]; + +#endif + +#endif diff --git a/include/grub/mips/libgcc.h b/include/grub/mips/libgcc.h new file mode 100644 index 000000000..f06ea1c1c --- /dev/null +++ b/include/grub/mips/libgcc.h @@ -0,0 +1,38 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2007,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include + +#ifdef HAVE___ASHLDI3 +void EXPORT_FUNC (__ashldi3) (void); +#endif +#ifdef HAVE___ASHRDI3 +void EXPORT_FUNC (__ashrdi3) (void); +#endif +#ifdef HAVE___LSHRDI3 +void EXPORT_FUNC (__lshrdi3) (void); +#endif +#ifdef HAVE___UCMPDI2 +void EXPORT_FUNC (__ucmpdi2) (void); +#endif +#ifdef HAVE___BSWAPSI2 +void EXPORT_FUNC (__bswapsi2) (void); +#endif +#ifdef HAVE___BSWAPDI2 +void EXPORT_FUNC (__bswapdi2) (void); +#endif diff --git a/include/grub/mips/pci.h b/include/grub/mips/pci.h new file mode 100644 index 000000000..8b49d8479 --- /dev/null +++ b/include/grub/mips/pci.h @@ -0,0 +1 @@ +#include diff --git a/include/grub/mips/qemu-mips/boot.h b/include/grub/mips/qemu-mips/boot.h new file mode 100644 index 000000000..e69de29bb diff --git a/include/grub/mips/qemu-mips/kernel.h b/include/grub/mips/qemu-mips/kernel.h new file mode 100644 index 000000000..dbf74c1b2 --- /dev/null +++ b/include/grub/mips/qemu-mips/kernel.h @@ -0,0 +1,36 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_KERNEL_MACHINE_HEADER +#define GRUB_KERNEL_MACHINE_HEADER 1 + +#include +#include + +#ifndef ASM_FILE + +void EXPORT_FUNC (grub_reboot) (void); +void EXPORT_FUNC (grub_halt) (void); + +/* The prefix which points to the directory where GRUB modules and its + configuration file are located. */ +extern char grub_prefix[]; + +#endif + +#endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/mips/qemu-mips/loader.h b/include/grub/mips/qemu-mips/loader.h new file mode 100644 index 000000000..e69de29bb diff --git a/include/grub/mips/qemu-mips/memory.h b/include/grub/mips/qemu-mips/memory.h new file mode 100644 index 000000000..87e68674e --- /dev/null +++ b/include/grub/mips/qemu-mips/memory.h @@ -0,0 +1,54 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MEMORY_MACHINE_HEADER +#define GRUB_MEMORY_MACHINE_HEADER 1 + +#ifndef ASM_FILE +#include +#include +#include +#endif + +#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x80f00000 +#define GRUB_MACHINE_MEMORY_USABLE 0x81000000 + +#define GRUB_MACHINE_MEMORY_AVAILABLE 1 + +#ifndef ASM_FILE +grub_err_t EXPORT_FUNC (grub_machine_mmap_iterate) +(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); +grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) + (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); + +static inline grub_err_t +grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), + grub_uint64_t size __attribute__ ((unused)), + int type __attribute__ ((unused)), + int handle __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} +static inline grub_err_t +grub_machine_mmap_unregister (int handle __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} +#endif + +#endif diff --git a/include/grub/mips/qemu-mips/serial.h b/include/grub/mips/qemu-mips/serial.h new file mode 100644 index 000000000..1f8ce0804 --- /dev/null +++ b/include/grub/mips/qemu-mips/serial.h @@ -0,0 +1,24 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MACHINE_SERIAL_HEADER +#define GRUB_MACHINE_SERIAL_HEADER 1 + +#define GRUB_MACHINE_SERIAL_PORTS { 0x140003f8 } + +#endif diff --git a/include/grub/mips/qemu-mips/time.h b/include/grub/mips/qemu-mips/time.h new file mode 100644 index 000000000..a73f64dea --- /dev/null +++ b/include/grub/mips/qemu-mips/time.h @@ -0,0 +1,34 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1 + +#include + +#define GRUB_TICKS_PER_SECOND 1000 + +/* Return the real time in ticks. */ +grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void); + +static inline void +grub_cpu_idle(void) +{ +} + +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff --git a/include/grub/mips/relocator.h b/include/grub/mips/relocator.h new file mode 100644 index 000000000..838ef832f --- /dev/null +++ b/include/grub/mips/relocator.h @@ -0,0 +1,39 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_RELOCATOR_CPU_HEADER +#define GRUB_RELOCATOR_CPU_HEADER 1 + +#include +#include + +struct grub_relocator32_state +{ + /* gpr[0] is ignored since it's hardwired to 0. */ + grub_uint32_t gpr[32]; + /* Register holding target $pc. */ + int jumpreg; +}; + +void *grub_relocator32_alloc (grub_size_t size); +grub_err_t grub_relocator32_boot (void *relocator, grub_uint32_t dest, + struct grub_relocator32_state state); +void *grub_relocator32_realloc (void *relocator, grub_size_t size); +void grub_relocator32_free (void *relocator); + +#endif /* ! GRUB_RELOCATOR_CPU_HEADER */ diff --git a/include/grub/mips/setjmp.h b/include/grub/mips/setjmp.h new file mode 100644 index 000000000..5e5985586 --- /dev/null +++ b/include/grub/mips/setjmp.h @@ -0,0 +1,27 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2004,2006,2007,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_SETJMP_CPU_HEADER +#define GRUB_SETJMP_CPU_HEADER 1 + +typedef unsigned long grub_jmp_buf[11]; + +int grub_setjmp (grub_jmp_buf env) __attribute__ ((returns_twice)); +void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); + +#endif /* ! GRUB_SETJMP_CPU_HEADER */ diff --git a/include/grub/mips/time.h b/include/grub/mips/time.h new file mode 100644 index 000000000..e69de29bb diff --git a/include/grub/mips/types.h b/include/grub/mips/types.h new file mode 100644 index 000000000..fe09afa3e --- /dev/null +++ b/include/grub/mips/types.h @@ -0,0 +1,38 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2006,2007,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_TYPES_CPU_HEADER +#define GRUB_TYPES_CPU_HEADER 1 + +/* The size of void *. */ +#define GRUB_TARGET_SIZEOF_VOID_P 4 + +/* The size of long. */ +#define GRUB_TARGET_SIZEOF_LONG 4 + +#ifdef GRUB_CPU_MIPSEL +/* mipsEL is little-endian. */ +#undef GRUB_TARGET_WORDS_BIGENDIAN +#elif defined (GRUB_CPU_MIPS) +/* mips is big-endian. */ +#define GRUB_TARGET_WORDS_BIGENDIAN +#elif !defined (GRUB_SYMBOL_GENERATOR) +#error Neither GRUB_CPU_MIPS nor GRUB_CPU_MIPSEL is defined +#endif + +#endif /* ! GRUB_TYPES_CPU_HEADER */ diff --git a/include/grub/mips/yeeloong/at_keyboard.h b/include/grub/mips/yeeloong/at_keyboard.h new file mode 100644 index 000000000..f279ac86d --- /dev/null +++ b/include/grub/mips/yeeloong/at_keyboard.h @@ -0,0 +1,25 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MACHINE_AT_KEYBOARD_HEADER +#define GRUB_MACHINE_AT_KEYBOARD_HEADER 1 + +#define KEYBOARD_REG_DATA 0xbfd00060 +#define KEYBOARD_REG_STATUS 0xbfd00064 + +#endif diff --git a/include/grub/mips/yeeloong/boot.h b/include/grub/mips/yeeloong/boot.h new file mode 100644 index 000000000..e69de29bb diff --git a/include/grub/mips/yeeloong/cmos.h b/include/grub/mips/yeeloong/cmos.h new file mode 100644 index 000000000..f2a32d736 --- /dev/null +++ b/include/grub/mips/yeeloong/cmos.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_CPU_CMOS_H +#define GRUB_CPU_CMOS_H 1 + +#include +#include + +#define GRUB_CMOS_ADDR_REG 0xbfd00070 +#define GRUB_CMOS_DATA_REG 0xbfd00071 + +#endif /* GRUB_CPU_CMOS_H */ diff --git a/include/grub/mips/yeeloong/kernel.h b/include/grub/mips/yeeloong/kernel.h new file mode 100644 index 000000000..230455dbf --- /dev/null +++ b/include/grub/mips/yeeloong/kernel.h @@ -0,0 +1,32 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_KERNEL_MACHINE_HEADER +#define GRUB_KERNEL_MACHINE_HEADER 1 + +#include +#include + +#ifndef ASM_FILE + +void EXPORT_FUNC (grub_reboot) (void); +void EXPORT_FUNC (grub_halt) (void); + +#endif + +#endif /* ! GRUB_KERNEL_MACHINE_HEADER */ diff --git a/include/grub/mips/yeeloong/loader.h b/include/grub/mips/yeeloong/loader.h new file mode 100644 index 000000000..e69de29bb diff --git a/include/grub/mips/yeeloong/memory.h b/include/grub/mips/yeeloong/memory.h new file mode 100644 index 000000000..922db2404 --- /dev/null +++ b/include/grub/mips/yeeloong/memory.h @@ -0,0 +1,68 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MEMORY_MACHINE_HEADER +#define GRUB_MEMORY_MACHINE_HEADER 1 + +#ifndef ASM_FILE +#include +#include +#include +#endif + +#define GRUB_MACHINE_MEMORY_STACK_HIGH 0x801ffff0 +#define GRUB_ARCH_LOWMEMVSTART 0x80000000 +#define GRUB_ARCH_LOWMEMPSTART 0x00000000 +#define GRUB_ARCH_LOWMEMMAXSIZE 0x10000000 +#define GRUB_ARCH_HIGHMEMPSTART 0x10000000 + + +#define GRUB_MACHINE_MEMORY_AVAILABLE 1 +#define GRUB_MACHINE_MEMORY_MAX_TYPE 1 + /* This one is special: it's used internally but is never reported + by firmware. */ +#define GRUB_MACHINE_MEMORY_HOLE 2 +#define GRUB_MACHINE_MEMORY_RESERVED GRUB_MACHINE_MEMORY_HOLE + +#ifndef ASM_FILE +grub_err_t EXPORT_FUNC (grub_machine_mmap_iterate) +(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); + +static inline grub_err_t +grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), + grub_uint64_t size __attribute__ ((unused)), + int type __attribute__ ((unused)), + int handle __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} +static inline grub_err_t +grub_machine_mmap_unregister (int handle __attribute__ ((unused))) +{ + return GRUB_ERR_NONE; +} + +grub_uint64_t grub_mmap_get_lower (void); +grub_uint64_t grub_mmap_get_upper (void); + +extern grub_uint32_t EXPORT_VAR (grub_arch_memsize); +extern grub_uint32_t EXPORT_VAR (grub_arch_highmemsize); + +#endif + +#endif diff --git a/include/grub/mips/yeeloong/pci.h b/include/grub/mips/yeeloong/pci.h new file mode 100644 index 000000000..c7bd31d4f --- /dev/null +++ b/include/grub/mips/yeeloong/pci.h @@ -0,0 +1,105 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2008 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MACHINE_PCI_H +#define GRUB_MACHINE_PCI_H 1 + +#include +#include + +#define GRUB_PCI_NUM_BUS 1 +#define GRUB_PCI_NUM_DEVICES 16 + +#define GRUB_MACHINE_PCI_IO_BASE 0xbfd00000 +#define GRUB_MACHINE_PCI_CONFSPACE 0xbfe80000 +#define GRUB_MACHINE_PCI_CONF_CTRL_REG (*(volatile grub_uint32_t *) 0xbfe00118) +#define GRUB_MACHINE_PCI_IO_CTRL_REG (*(volatile grub_uint32_t *) 0xbfe00110) +#define GRUB_MACHINE_PCI_WIN_MASK_SIZE 6 +#define GRUB_MACHINE_PCI_WIN_MASK ((1 << GRUB_MACHINE_PCI_WIN_MASK_SIZE) - 1) + +/* We have 3 PCI windows. */ +#define GRUB_MACHINE_PCI_NUM_WIN 3 +/* Each window is 64MiB. */ +#define GRUB_MACHINE_PCI_WIN_SHIFT 26 +#define GRUB_MACHINE_PCI_WIN_OFFSET_MASK ((1 << GRUB_MACHINE_PCI_WIN_SHIFT) - 1) + +#define GRUB_MACHINE_PCI_WIN_SIZE 0x04000000 +/* Graphical acceleration takes 1 MiB away. */ +#define GRUB_MACHINE_PCI_WIN1_SIZE 0x03f00000 + +#define GRUB_MACHINE_PCI_WIN1_ADDR 0xb0000000 +#define GRUB_MACHINE_PCI_WIN2_ADDR 0xb4000000 +#define GRUB_MACHINE_PCI_WIN3_ADDR 0xb8000000 + +static inline grub_uint32_t +grub_pci_read (grub_pci_address_t addr) +{ + GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); + return *(volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONFSPACE + | (addr & 0x03ff)); +} + +static inline grub_uint16_t +grub_pci_read_word (grub_pci_address_t addr) +{ + GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); + return *(volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONFSPACE + | (addr & 0x03ff)); +} + +static inline grub_uint8_t +grub_pci_read_byte (grub_pci_address_t addr) +{ + GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); + return *(volatile grub_uint8_t *) (GRUB_MACHINE_PCI_CONFSPACE + | (addr & 0x03ff)); +} + +static inline void +grub_pci_write (grub_pci_address_t addr, grub_uint32_t data) +{ + GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); + *(volatile grub_uint32_t *) (GRUB_MACHINE_PCI_CONFSPACE + | (addr & 0x03ff)) = data; +} + +static inline void +grub_pci_write_word (grub_pci_address_t addr, grub_uint16_t data) +{ + GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); + *(volatile grub_uint16_t *) (GRUB_MACHINE_PCI_CONFSPACE + | (addr & 0x03ff)) = data; +} + +static inline void +grub_pci_write_byte (grub_pci_address_t addr, grub_uint8_t data) +{ + GRUB_MACHINE_PCI_CONF_CTRL_REG = 1 << ((addr >> 11) & 0xf); + *(volatile grub_uint8_t *) (GRUB_MACHINE_PCI_CONFSPACE + | (addr & 0x03ff)) = data; +} + +volatile void * +grub_pci_device_map_range (grub_pci_device_t dev __attribute__ ((unused)), + grub_addr_t base, grub_size_t size); +void +grub_pci_device_unmap_range (grub_pci_device_t dev __attribute__ ((unused)), + volatile void *mem, + grub_size_t size __attribute__ ((unused))); + +#endif /* GRUB_MACHINE_PCI_H */ diff --git a/include/grub/mips/yeeloong/serial.h b/include/grub/mips/yeeloong/serial.h new file mode 100644 index 000000000..9390ea18a --- /dev/null +++ b/include/grub/mips/yeeloong/serial.h @@ -0,0 +1,24 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_MACHINE_SERIAL_HEADER +#define GRUB_MACHINE_SERIAL_HEADER 1 + +#define GRUB_MACHINE_SERIAL_PORTS { 0xbff003f8 } + +#endif diff --git a/include/grub/mips/yeeloong/time.h b/include/grub/mips/yeeloong/time.h new file mode 100644 index 000000000..7f468bf12 --- /dev/null +++ b/include/grub/mips/yeeloong/time.h @@ -0,0 +1,37 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1 + +#include + +#define GRUB_TICKS_PER_SECOND (grub_arch_cpuclock / 2) + +/* Return the real time in ticks. */ +grub_uint64_t EXPORT_FUNC (grub_get_rtc) (void); + +extern grub_uint32_t EXPORT_VAR (grub_arch_busclock); +extern grub_uint32_t EXPORT_VAR (grub_arch_cpuclock); + +static inline void +grub_cpu_idle(void) +{ +} + +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff --git a/include/grub/misc.h b/include/grub/misc.h index e7324fe10..4830c4fe3 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -197,8 +197,13 @@ void EXPORT_FUNC(grub_real_dprintf) (const char *file, const char *condition, const char *fmt, ...) __attribute__ ((format (printf, 4, 5))); int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args); -int EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); -int EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args); +int EXPORT_FUNC(grub_snprintf) (char *str, grub_size_t n, const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))); +int EXPORT_FUNC(grub_vsnprintf) (char *str, grub_size_t n, const char *fmt, + va_list args); +char *EXPORT_FUNC(grub_xasprintf) (const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); +char *EXPORT_FUNC(grub_xvasprintf) (const char *fmt, va_list args); void EXPORT_FUNC(grub_exit) (void) __attribute__ ((noreturn)); void EXPORT_FUNC(grub_abort) (void) __attribute__ ((noreturn)); grub_size_t EXPORT_FUNC(grub_utf8_to_ucs4) (grub_uint32_t *dest, diff --git a/include/grub/script_sh.h b/include/grub/script_sh.h index f6177b02a..0bd14abcd 100644 --- a/include/grub/script_sh.h +++ b/include/grub/script_sh.h @@ -112,7 +112,7 @@ struct grub_script_cmd_menuentry struct grub_script_arglist *arglist; /* The sourcecode the entry will be generated from. */ - const char *sourcecode; + char *sourcecode; /* Options. XXX: Not used yet. */ int options; diff --git a/include/grub/i386/pc/serial.h b/include/grub/serial.h similarity index 95% rename from include/grub/i386/pc/serial.h rename to include/grub/serial.h index 4038f50fb..30daeb6ae 100644 --- a/include/grub/i386/pc/serial.h +++ b/include/grub/serial.h @@ -17,8 +17,8 @@ * along with GRUB. If not, see . */ -#ifndef GRUB_SERIAL_MACHINE_HEADER -#define GRUB_SERIAL_MACHINE_HEADER 1 +#ifndef GRUB_SERIAL_HEADER +#define GRUB_SERIAL_HEADER 1 /* Macros. */ @@ -64,7 +64,9 @@ /* Turn on DTR, RTS, and OUT2. */ #define UART_ENABLE_MODEM 0x0B -unsigned short +#include + +grub_port_t grub_serial_hw_get_port (const unsigned int unit); #endif /* ! GRUB_SERIAL_MACHINE_HEADER */ diff --git a/include/grub/term.h b/include/grub/term.h index 3d644b848..143aabe1e 100644 --- a/include/grub/term.h +++ b/include/grub/term.h @@ -208,9 +208,8 @@ grub_term_register_input (const char *name __attribute__ ((unused)), else { /* If this is the first terminal, enable automatically. */ - if (term->init) - term->init (); - grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); + if (! term->init || term->init () == GRUB_ERR_NONE) + grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs), GRUB_AS_LIST (term)); } } @@ -224,10 +223,9 @@ grub_term_register_output (const char *name __attribute__ ((unused)), else { /* If this is the first terminal, enable automatically. */ - if (term->init) - term->init (); - grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), - GRUB_AS_LIST (term)); + if (! term->init || term->init () == GRUB_ERR_NONE) + grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs), + GRUB_AS_LIST (term)); } } diff --git a/include/grub/time.h b/include/grub/time.h index 115fbd95e..5aafdc9ed 100644 --- a/include/grub/time.h +++ b/include/grub/time.h @@ -23,7 +23,7 @@ #include #include -#ifdef GRUB_MACHINE_EMU +#if defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL) #define GRUB_TICKS_PER_SECOND 100000 #else #include diff --git a/include/grub/x86_64/at_keyboard.h b/include/grub/x86_64/at_keyboard.h new file mode 100644 index 000000000..c632aa85c --- /dev/null +++ b/include/grub/x86_64/at_keyboard.h @@ -0,0 +1 @@ +#include diff --git a/include/grub/x86_64/efi/serial.h b/include/grub/x86_64/efi/serial.h new file mode 100644 index 000000000..2d8563414 --- /dev/null +++ b/include/grub/x86_64/efi/serial.h @@ -0,0 +1 @@ +#include diff --git a/include/multiboot.h b/include/multiboot.h index 57c154c98..c529c5c5f 100644 --- a/include/multiboot.h +++ b/include/multiboot.h @@ -233,6 +233,8 @@ struct multiboot_mmap_entry multiboot_uint64_t len; #define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_RESERVED 2 +#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 +#define MULTIBOOT_MEMORY_NVS 4 multiboot_uint32_t type; } __attribute__((packed)); typedef struct multiboot_mmap_entry multiboot_memory_map_t; diff --git a/include/multiboot2.h b/include/multiboot2.h index a241a70ad..1b649d514 100644 --- a/include/multiboot2.h +++ b/include/multiboot2.h @@ -233,6 +233,8 @@ struct multiboot_mmap_entry multiboot_uint64_t len; #define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_RESERVED 2 +#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 +#define MULTIBOOT_MEMORY_NVS 4 multiboot_uint32_t type; } __attribute__((packed)); typedef struct multiboot_mmap_entry multiboot_memory_map_t; diff --git a/kern/device.c b/kern/device.c index f519c63b2..5cfd190f3 100644 --- a/kern/device.c +++ b/kern/device.c @@ -86,7 +86,7 @@ grub_device_iterate (int (*hook) (const char *name)) struct part_ent { struct part_ent *next; - char name[0]; + char *name; } *ents; int iterate_disk (const char *disk_name) @@ -118,6 +118,7 @@ grub_device_iterate (int (*hook) (const char *name)) if (!ret) ret = hook (p->name); + grub_free (p->name); grub_free (p); p = next; } @@ -138,15 +139,20 @@ grub_device_iterate (int (*hook) (const char *name)) if (! partition_name) return 1; - p = grub_malloc (sizeof (p->next) + grub_strlen (disk->name) + 1 + - grub_strlen (partition_name) + 1); + p = grub_malloc (sizeof (*p)); if (!p) { grub_free (partition_name); return 1; } - grub_sprintf (p->name, "%s,%s", disk->name, partition_name); + p->name = grub_xasprintf ("%s,%s", disk->name, partition_name); + if (!p->name) + { + grub_free (partition_name); + grub_free (p); + return 1; + } grub_free (partition_name); p->next = ents; diff --git a/kern/dl.c b/kern/dl.c index 20ab1c5c2..4735a004a 100644 --- a/kern/dl.c +++ b/kern/dl.c @@ -341,6 +341,7 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) switch (type) { case STT_NOTYPE: + case STT_OBJECT: /* Resolve a global symbol. */ if (sym->st_name != 0 && sym->st_shndx == 0) { @@ -350,15 +351,13 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e) "the symbol `%s' not found", name); } else - sym->st_value = 0; - break; - - case STT_OBJECT: - sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod, - sym->st_shndx); - if (bind != STB_LOCAL) - if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) - return grub_errno; + { + sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod, + sym->st_shndx); + if (bind != STB_LOCAL) + if (grub_dl_register_symbol (name, (void *) sym->st_value, mod)) + return grub_errno; + } break; case STT_FUNC: @@ -628,12 +627,10 @@ grub_dl_load (const char *name) return 0; } - filename = (char *) grub_malloc (grub_strlen (grub_dl_dir) + 1 - + grub_strlen (name) + 4 + 1); + filename = grub_xasprintf ("%s/%s.mod", grub_dl_dir, name); if (! filename) return 0; - grub_sprintf (filename, "%s/%s.mod", grub_dl_dir, name); mod = grub_dl_load_file (filename); grub_free (filename); diff --git a/kern/efi/init.c b/kern/efi/init.c index 8862eb2f9..a0b4ff779 100644 --- a/kern/efi/init.c +++ b/kern/efi/init.c @@ -63,11 +63,10 @@ grub_efi_set_prefix (void) if (p) *p = '\0'; - prefix = grub_malloc (1 + grub_strlen (device) + 1 - + grub_strlen (file) + 1); + prefix = grub_xasprintf ("(%s)%s", device, file); if (prefix) { - grub_sprintf (prefix, "(%s)%s", device, file); + grub_env_set ("prefix", prefix); grub_free (prefix); } diff --git a/kern/elf.c b/kern/elf.c index c70071d6e..875a855ea 100644 --- a/kern/elf.c +++ b/kern/elf.c @@ -172,7 +172,7 @@ grub_elf32_phdr_iterate (grub_elf_t elf, /* Calculate the amount of memory spanned by the segments. */ grub_size_t -grub_elf32_size (grub_elf_t elf) +grub_elf32_size (grub_elf_t elf, Elf32_Addr *base) { Elf32_Addr segments_start = (Elf32_Addr) -1; Elf32_Addr segments_end = 0; @@ -198,6 +198,9 @@ grub_elf32_size (grub_elf_t elf) grub_elf32_phdr_iterate (elf, calcsize, 0); + if (base) + *base = 0; + if (nr_phdrs == 0) { grub_error (GRUB_ERR_BAD_OS, "no program headers present"); @@ -211,10 +214,12 @@ grub_elf32_size (grub_elf_t elf) return 0; } + if (base) + *base = segments_start; + return segments_end - segments_start; } - /* Load every loadable segment into memory specified by `_load_hook'. */ grub_err_t grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook, @@ -353,7 +358,7 @@ grub_elf64_phdr_iterate (grub_elf_t elf, /* Calculate the amount of memory spanned by the segments. */ grub_size_t -grub_elf64_size (grub_elf_t elf) +grub_elf64_size (grub_elf_t elf, Elf64_Addr *base) { Elf64_Addr segments_start = (Elf64_Addr) -1; Elf64_Addr segments_end = 0; @@ -379,6 +384,9 @@ grub_elf64_size (grub_elf_t elf) grub_elf64_phdr_iterate (elf, calcsize, 0); + if (base) + *base = 0; + if (nr_phdrs == 0) { grub_error (GRUB_ERR_BAD_OS, "no program headers present"); @@ -392,6 +400,9 @@ grub_elf64_size (grub_elf_t elf) return 0; } + if (base) + *base = segments_start; + return segments_end - segments_start; } diff --git a/kern/env.c b/kern/env.c index 8f94e891e..cebb4eeff 100644 --- a/kern/env.c +++ b/kern/env.c @@ -357,14 +357,7 @@ grub_register_variable_hook (const char *name, static char * mangle_data_slot_name (const char *name) { - char *mangled_name; - - mangled_name = grub_malloc (grub_strlen (name) + 2); - if (! mangled_name) - return 0; - - grub_sprintf (mangled_name, "\e%s", name); - return mangled_name; + return grub_xasprintf ("\e%s", name); } grub_err_t diff --git a/kern/err.c b/kern/err.c index 1a881db25..8272467f5 100644 --- a/kern/err.c +++ b/kern/err.c @@ -45,7 +45,7 @@ grub_error (grub_err_t n, const char *fmt, ...) grub_errno = n; va_start (ap, fmt); - grub_vsprintf (grub_errmsg, _(fmt), ap); + grub_vsnprintf (grub_errmsg, sizeof (grub_errmsg), _(fmt), ap); va_end (ap); return n; diff --git a/kern/i386/pc/init.c b/kern/i386/pc/init.c index 382e097e4..e48a52322 100644 --- a/kern/i386/pc/init.c +++ b/kern/i386/pc/init.c @@ -53,22 +53,30 @@ static char * make_install_device (void) { /* XXX: This should be enough. */ - char dev[100]; + char dev[100], *ptr = dev; if (grub_prefix[0] != '(') { /* No hardcoded root partition - make it from the boot drive and the partition number encoded at the install time. */ - grub_sprintf (dev, "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f', + grub_snprintf (dev, sizeof (dev), + "(%cd%u", (grub_boot_drive & 0x80) ? 'h' : 'f', grub_boot_drive & 0x7f); + ptr += grub_strlen (ptr); if (grub_install_dos_part >= 0) - grub_sprintf (dev + grub_strlen (dev), ",%u", grub_install_dos_part + 1); + grub_snprintf (ptr, sizeof (dev) - (ptr - dev), + ",%u", grub_install_dos_part + 1); + + ptr += grub_strlen (ptr); if (grub_install_bsd_part >= 0) - grub_sprintf (dev + grub_strlen (dev), ",%c", grub_install_bsd_part + 'a'); + grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ",%c", + grub_install_bsd_part + 'a'); - grub_sprintf (dev + grub_strlen (dev), ")%s", grub_prefix); + ptr += grub_strlen (ptr); + + grub_snprintf (ptr, sizeof (dev) - (ptr - dev), ")%s", grub_prefix); grub_strcpy (grub_prefix, dev); } diff --git a/kern/i386/qemu/mmap.c b/kern/i386/qemu/mmap.c index 4ccae023a..c7fc4f45e 100644 --- a/kern/i386/qemu/mmap.c +++ b/kern/i386/qemu/mmap.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #define QEMU_CMOS_MEMSIZE_HIGH 0x35 #define QEMU_CMOS_MEMSIZE_LOW 0x34 diff --git a/kern/ieee1275/init.c b/kern/ieee1275/init.c index 3e11d2369..04e4e2dca 100644 --- a/kern/ieee1275/init.c +++ b/kern/ieee1275/init.c @@ -111,11 +111,12 @@ grub_machine_set_prefix (void) *lastslash = '\0'; grub_translate_ieee1275_path (filename); - newprefix = grub_malloc (grub_strlen (prefix) - + grub_strlen (filename)); - grub_sprintf (newprefix, "%s%s", prefix, filename); - grub_free (prefix); - prefix = newprefix; + newprefix = grub_xasprintf ("%s%s", prefix, filename); + if (newprefix) + { + grub_free (prefix); + prefix = newprefix; + } } } diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index c38eb450f..5f0aad119 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -38,7 +38,7 @@ grub_children_iterate (char *devpath, grub_ieee1275_phandle_t dev; grub_ieee1275_phandle_t child; char *childtype, *childpath; - char *childname, *fullname; + char *childname; int ret = 0; if (grub_ieee1275_finddevice (devpath, &dev)) @@ -63,19 +63,12 @@ grub_children_iterate (char *devpath, grub_free (childtype); return 0; } - fullname = grub_malloc (IEEE1275_MAX_PATH_LEN); - if (!fullname) - { - grub_free (childname); - grub_free (childpath); - grub_free (childtype); - return 0; - } do { struct grub_ieee1275_devalias alias; grub_ssize_t actual; + char *fullname; if (grub_ieee1275_get_property (child, "device_type", childtype, IEEE1275_MAX_PROP_LEN, &actual)) @@ -89,18 +82,25 @@ grub_children_iterate (char *devpath, IEEE1275_MAX_PROP_LEN, &actual)) continue; - grub_sprintf (fullname, "%s/%s", devpath, childname); + fullname = grub_xasprintf ("%s/%s", devpath, childname); + if (!fullname) + { + grub_free (childname); + grub_free (childpath); + grub_free (childtype); + return 0; + } alias.type = childtype; alias.path = childpath; alias.name = fullname; ret = hook (&alias); + grub_free (fullname); if (ret) break; } while (grub_ieee1275_peer (child, &child)); - grub_free (fullname); grub_free (childname); grub_free (childpath); grub_free (childtype); @@ -330,12 +330,11 @@ grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype) { char *filepath = comma + 1; - ret = grub_malloc (grub_strlen (filepath) + 1); /* Make sure filepath has leading backslash. */ if (filepath[0] != '\\') - grub_sprintf (ret, "\\%s", filepath); + ret = grub_xasprintf ("\\%s", filepath); else - grub_strcpy (ret, filepath); + ret = grub_strdup (filepath); } } else if (ptype == GRUB_PARSE_PARTITION) @@ -383,15 +382,10 @@ grub_ieee1275_encode_devname (const char *path) /* GRUB partition 1 is OF partition 0. */ partno++; - /* Assume partno will require less than five bytes to encode. */ - encoding = grub_malloc (grub_strlen (device) + 3 + 5); - grub_sprintf (encoding, "(%s,%d)", device, partno); + encoding = grub_xasprintf ("(%s,%d)", device, partno); } else - { - encoding = grub_malloc (grub_strlen (device) + 2); - grub_sprintf (encoding, "(%s)", device); - } + encoding = grub_xasprintf ("(%s)", device); grub_free (partition); grub_free (device); diff --git a/kern/main.c b/kern/main.c index 7250c73e0..2e1ef6400 100644 --- a/kern/main.c +++ b/kern/main.c @@ -159,6 +159,9 @@ grub_main (void) /* Load pre-loaded modules and free the space. */ grub_register_exported_symbols (); +#ifdef GRUB_LINKER_HAVE_INIT + grub_arch_dl_init_linker (); +#endif grub_load_modules (); /* It is better to set the root device as soon as possible, diff --git a/kern/mips/cache.S b/kern/mips/cache.S new file mode 100644 index 000000000..2c35b6da2 --- /dev/null +++ b/kern/mips/cache.S @@ -0,0 +1,7 @@ + +#include + +FUNCTION (grub_cpu_flush_cache) +FUNCTION (grub_arch_sync_caches) +#include "cache_flush.S" + j $ra diff --git a/kern/mips/cache_flush.S b/kern/mips/cache_flush.S new file mode 100644 index 000000000..5667ee7b4 --- /dev/null +++ b/kern/mips/cache_flush.S @@ -0,0 +1,23 @@ + move $t2, $a0 + addu $t3, $a0, $a1 + srl $t2, $t2, 5 + sll $t2, $t2, 5 + addu $t3, $t3, 0x1f + srl $t3, $t3, 5 + sll $t3, $t3, 5 + move $t0, $t2 + subu $t1, $t3, $t2 +1: + cache 1, 0($t0) + addiu $t0, $t0, 0x1 + addiu $t1, $t1, 0xffff + bne $t1, $zero, 1b + sync + move $t0, $t2 + subu $t1, $t3, $t2 +2: + cache 0, 0($t0) + addiu $t0, $t0, 0x1 + addiu $t1, $t1, 0xffff + bne $t1, $zero, 2b + sync diff --git a/kern/mips/dl.c b/kern/mips/dl.c new file mode 100644 index 000000000..485955e7f --- /dev/null +++ b/kern/mips/dl.c @@ -0,0 +1,237 @@ +/* dl-386.c - arch-dependent part of loadable module support */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2002,2005,2007,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +/* Dummy __gnu_local_gp. Resolved by linker. */ +static char __gnu_local_gp_dummy; + +/* Check if EHDR is a valid ELF header. */ +grub_err_t +grub_arch_dl_check_header (void *ehdr) +{ + Elf_Ehdr *e = ehdr; + + /* Check the magic numbers. */ +#ifdef WORDS_BIGENDIAN + if (e->e_ident[EI_CLASS] != ELFCLASS32 + || e->e_ident[EI_DATA] != ELFDATA2MSB + || e->e_machine != EM_MIPS) +#else + if (e->e_ident[EI_CLASS] != ELFCLASS32 + || e->e_ident[EI_DATA] != ELFDATA2LSB + || e->e_machine != EM_MIPS) +#endif + return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic"); + + return GRUB_ERR_NONE; +} + +/* Relocate symbols. */ +grub_err_t +grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) +{ + Elf_Ehdr *e = ehdr; + Elf_Shdr *s; + Elf_Word entsize; + unsigned i; + grub_size_t gp_size = 0; + /* FIXME: suboptimal. */ + grub_uint32_t *gp, *gpptr; + grub_uint32_t gp0; + + /* Find a symbol table. */ + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_SYMTAB) + break; + + if (i == e->e_shnum) + return grub_error (GRUB_ERR_BAD_MODULE, "no symtab found"); + + entsize = s->sh_entsize; + + /* Find reginfo. */ + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_MIPS_REGINFO) + break; + + if (i == e->e_shnum) + return grub_error (GRUB_ERR_BAD_MODULE, "no reginfo found"); + + gp0 = ((grub_uint32_t *)((char *) e + s->sh_offset))[5]; + + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_REL) + { + grub_dl_segment_t seg; + + /* Find the target segment. */ + for (seg = mod->segment; seg; seg = seg->next) + if (seg->section == s->sh_info) + break; + + if (seg) + { + Elf_Rel *rel, *max; + + for (rel = (Elf_Rel *) ((char *) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; + rel++) + switch (ELF_R_TYPE (rel->r_info)) + { + case R_MIPS_GOT16: + case R_MIPS_CALL16: + case R_MIPS_GPREL32: + gp_size += 4; + break; + } + } + } + + if (gp_size > 0x08000) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "__gnu_local_gp is too big\n"); + + gpptr = gp = grub_malloc (gp_size); + if (!gp) + return grub_errno; + + for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); + i < e->e_shnum; + i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize)) + if (s->sh_type == SHT_REL) + { + grub_dl_segment_t seg; + + /* Find the target segment. */ + for (seg = mod->segment; seg; seg = seg->next) + if (seg->section == s->sh_info) + break; + + if (seg) + { + Elf_Rel *rel, *max; + + for (rel = (Elf_Rel *) ((char *) e + s->sh_offset), + max = rel + s->sh_size / s->sh_entsize; + rel < max; + rel++) + { + Elf_Word *addr; + Elf_Sym *sym; + + if (seg->size < rel->r_offset) + return grub_error (GRUB_ERR_BAD_MODULE, + "reloc offset is out of the segment"); + + addr = (Elf_Word *) ((char *) seg->addr + rel->r_offset); + sym = (Elf_Sym *) ((char *) mod->symtab + + entsize * ELF_R_SYM (rel->r_info)); + if (sym->st_value == (grub_addr_t) &__gnu_local_gp_dummy) + sym->st_value = (grub_addr_t) gp; + + switch (ELF_R_TYPE (rel->r_info)) + { + case R_MIPS_HI16: + { + grub_uint32_t value; + Elf_Rel *rel2; + + /* Handle partner lo16 relocation. Lower part is + treated as signed. Hence add 0x8000 to compensate. + */ + value = (*(grub_uint16_t *) addr << 16) + + sym->st_value + 0x8000; + for (rel2 = rel + 1; rel2 < max; rel2++) + if (ELF_R_SYM (rel2->r_info) + == ELF_R_SYM (rel->r_info) + && ELF_R_TYPE (rel2->r_info) == R_MIPS_LO16) + { + value += *(grub_int16_t *) + ((char *) seg->addr + rel2->r_offset); + break; + } + *(grub_uint16_t *) addr = (value >> 16) & 0xffff; + } + break; + case R_MIPS_LO16: + *(grub_uint16_t *) addr += (sym->st_value) & 0xffff; + break; + case R_MIPS_32: + *(grub_uint32_t *) addr += sym->st_value; + break; + case R_MIPS_GPREL32: + *(grub_uint32_t *) addr = sym->st_value + + *(grub_uint32_t *) addr + gp0 - (grub_uint32_t)gp; + break; + + case R_MIPS_26: + { + grub_uint32_t value; + grub_uint32_t raw; + raw = (*(grub_uint32_t *) addr) & 0x3ffffff; + value = raw << 2; + value += sym->st_value; + raw = (value >> 2) & 0x3ffffff; + + *(grub_uint32_t *) addr = + raw | ((*(grub_uint32_t *) addr) & 0xfc000000); + } + break; + case R_MIPS_GOT16: + case R_MIPS_CALL16: + /* FIXME: reuse*/ + *gpptr = sym->st_value + *(grub_uint16_t *) addr; + *(grub_uint16_t *) addr + = sizeof (grub_uint32_t) * (gpptr - gp); + gpptr++; + break; + default: + { + grub_free (gp); + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "Unknown relocation type %d\n", + ELF_R_TYPE (rel->r_info)); + } + break; + } + } + } + } + + return GRUB_ERR_NONE; +} + +void +grub_arch_dl_init_linker (void) +{ + grub_dl_register_symbol ("__gnu_local_gp", &__gnu_local_gp_dummy, 0); +} + diff --git a/kern/mips/init.c b/kern/mips/init.c new file mode 100644 index 000000000..5adcedcbb --- /dev/null +++ b/kern/mips/init.c @@ -0,0 +1,35 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include + +void +grub_machine_set_prefix (void) +{ + grub_env_set ("prefix", grub_prefix); +} + +extern char _end[]; + +grub_addr_t +grub_arch_modules_addr (void) +{ + return (grub_addr_t) _end; +} diff --git a/kern/mips/qemu-mips/init.c b/kern/mips/qemu-mips/init.c new file mode 100644 index 000000000..866c7a82a --- /dev/null +++ b/kern/mips/qemu-mips/init.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RAMSIZE (*(grub_uint32_t *) ((16 << 20) - 264)) + +grub_uint32_t +grub_get_rtc (void) +{ + static int calln = 0; + return calln++; +} + +void +grub_machine_init (void) +{ + grub_mm_init_region ((void *) GRUB_MACHINE_MEMORY_USABLE, + RAMSIZE - (GRUB_MACHINE_MEMORY_USABLE & 0x7fffffff)); + grub_install_get_time_ms (grub_rtc_get_time_ms); +} + +void +grub_machine_fini (void) +{ +} + +void +grub_exit (void) +{ + while (1); +} + +void +grub_halt (void) +{ + while (1); +} + +void +grub_reboot (void) +{ + while (1); +} + +grub_err_t +grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, + grub_uint64_t, + grub_uint32_t)) +{ + hook (0, RAMSIZE, + GRUB_MACHINE_MEMORY_AVAILABLE); + return GRUB_ERR_NONE; +} diff --git a/kern/mips/startup.S b/kern/mips/startup.S new file mode 100644 index 000000000..5e3fb7ad5 --- /dev/null +++ b/kern/mips/startup.S @@ -0,0 +1,218 @@ +/* startup.S - Startup code for the MIPS. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include + +#define BASE_ADDR 8 + +.extern __bss_start +.extern _end + + .globl __start, _start, start +__start: +_start: +start: + bal codestart +base: + . = _start + GRUB_KERNEL_CPU_COMPRESSED_SIZE +compressed_size: + .long 0 + . = _start + GRUB_KERNEL_CPU_TOTAL_MODULE_SIZE +total_module_size: + .long 0 + . = _start + GRUB_KERNEL_CPU_KERNEL_IMAGE_SIZE +kernel_image_size: + .long 0 +codestart: + /* Save our base. */ + move $s0, $ra + + /* Parse arguments. Has to be done before relocation. + So need to do it in asm. */ +#ifdef GRUB_MACHINE_MIPS_YEELOONG + /* $a2 has the environment. */ + move $t0, $a2 +argcont: + lw $t1, 0($t0) + beq $t1, $zero, argdone +#define DO_PARSE(str, reg) \ + addiu $t2, $s0, (str-base);\ + bal parsestr;\ + beq $v0, $zero, 1f;\ + move reg, $v0;\ + b 2f;\ +1: + DO_PARSE (busclockstr, $s2) + DO_PARSE (cpuclockstr, $s3) + DO_PARSE (memsizestr, $s4) + DO_PARSE (highmemsizestr, $s5) +2: + addiu $t0, $t0, 4 + b argcont +parsestr: + move $v0, $zero + move $t3, $t1 +3: + lb $t4, 0($t2) + lb $t5, 0($t3) + addiu $t2, $t2, 1 + addiu $t3, $t3, 1 + beq $t5, $zero, 1f + beq $t5, $t4, 3b + bne $t4, $zero, 1f + + addiu $t3, $t3, 0xffff +digcont: + lb $t5, 0($t3) + /* Substract '0' from digit. */ + addiu $t5, $t5, 0xffd0 + bltz $t5, 1f + addiu $t4, $t5, 0xfff7 + bgtz $t4, 1f + /* Multiply $v0 by 10 with bitshifts. */ + sll $v0, $v0, 1 + sll $t4, $v0, 2 + addu $v0, $v0, $t4 + addu $v0, $v0, $t5 + addiu $t3, $t3, 1 + b digcont +1: + jr $ra +busclockstr: .asciiz "busclock=" +cpuclockstr: .asciiz "cpuclock=" +memsizestr: .asciiz "memsize=" +highmemsizestr: .asciiz "highmemsize=" + .p2align 2 +argdone: +#endif + + /* Decompress the payload. */ + addiu $a0, $s0, GRUB_KERNEL_CPU_RAW_SIZE - BASE_ADDR + lui $a1, %hi(compressed) + addiu $a1, %lo(compressed) + lw $a2, (GRUB_KERNEL_CPU_COMPRESSED_SIZE - BASE_ADDR)($s0) + move $s1, $a1 + + /* $a0 contains source compressed address, $a1 is destination, + $a2 is compressed size. FIXME: put LZMA here. Don't clober $s0, + $s1, $s2, $s3, $s4 and $s5. + On return $v0 contains uncompressed size. + */ + move $v0, $a2 +reloccont: + lb $t4, 0($a0) + sb $t4, 0($a1) + addiu $a1,$a1,1 + addiu $a0,$a0,1 + addiu $a2, 0xffff + bne $a2, $0, reloccont + + move $a0, $s1 + move $a1, $v0 + +#include "cache_flush.S" + + lui $t1, %hi(cont) + addiu $t1, %lo(cont) + + jr $t1 + . = _start + GRUB_KERNEL_CPU_RAW_SIZE +compressed: + . = _start + GRUB_KERNEL_CPU_PREFIX + +VARIABLE(grub_prefix) + + /* to be filled by grub-mkelfimage */ + + /* + * Leave some breathing room for the prefix. + */ + + . = _start + GRUB_KERNEL_CPU_DATA_END +#ifdef GRUB_MACHINE_MIPS_YEELOONG +VARIABLE (grub_arch_busclock) + .long 0 +VARIABLE (grub_arch_cpuclock) + .long 0 +VARIABLE (grub_arch_memsize) + .long 0 +VARIABLE (grub_arch_highmemsize) + .long 0 +#endif +cont: + +#ifdef GRUB_MACHINE_MIPS_YEELOONG + lui $t1, %hi(grub_arch_busclock) + addiu $t1, %lo(grub_arch_busclock) + sw $s2, 0($t1) + sw $s3, 4($t1) + sw $s4, 8($t1) + sw $s5, 12($t1) +#endif + + /* Move the modules out of BSS. */ + lui $t1, %hi(_start) + addiu $t1, %lo(_start) + lw $t2, (GRUB_KERNEL_CPU_KERNEL_IMAGE_SIZE - BASE_ADDR)($s0) + addu $t2, $t1, $t2 + + lui $t1, %hi(_end) + addiu $t1, %lo(_end) + addiu $t1, (GRUB_MOD_ALIGN-1) + li $t3, (GRUB_MOD_ALIGN-1) + nor $t3, $t3, $0 + and $t1, $t1, $t3 + + lw $t3, (GRUB_KERNEL_CPU_TOTAL_MODULE_SIZE - BASE_ADDR)($s0) + + /* Backward copy. */ + add $t1, $t1, $t3 + add $t2, $t2, $t3 + addiu $t1, $t1, 0xffff + addiu $t2, $t2, 0xffff + + /* $t2 is source. $t1 is destination. $t3 is size. */ +modulesmovcont: + lb $t4, 0($t2) + sb $t4, 0($t1) + addiu $t1,$t1,0xffff + addiu $t2,$t2,0xffff + addiu $t3, 0xffff + bne $t3, $0, modulesmovcont + + /* Clean BSS. */ + + lui $t1, %hi(__bss_start) + addiu $t1, %lo(__bss_start) + lui $t2, %hi(_end) + addiu $t2, %lo(_end) +bsscont: + sb $0,0($t1) + addiu $t1,$t1,1 + sltu $t3,$t1,$t2 + bne $t3, $0, bsscont + + li $sp, GRUB_MACHINE_MEMORY_STACK_HIGH + lui $t1, %hi(grub_main) + addiu $t1, %lo(grub_main) + + jr $t1 + diff --git a/kern/mips/yeeloong/init.c b/kern/mips/yeeloong/init.c new file mode 100644 index 000000000..14e8a39a2 --- /dev/null +++ b/kern/mips/yeeloong/init.c @@ -0,0 +1,131 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009,2010 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern void grub_video_sm712_init (void); +extern void grub_video_video_init (void); +extern void grub_video_bitmap_init (void); +extern void grub_font_manager_init (void); +extern void grub_term_gfxterm_init (void); +extern void grub_at_keyboard_init (void); + +/* FIXME: use interrupt to count high. */ +grub_uint64_t +grub_get_rtc (void) +{ + static grub_uint32_t high = 0; + static grub_uint32_t last = 0; + grub_uint32_t low; + + asm volatile ("mfc0 %0, $9": "=r" (low)); + if (low < last) + high++; + last = low; + + return (((grub_uint64_t) high) << 32) | low; +} + +grub_err_t +grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, + grub_uint64_t, + grub_uint32_t)) +{ + hook (GRUB_ARCH_LOWMEMPSTART, grub_arch_memsize << 20, + GRUB_MACHINE_MEMORY_AVAILABLE); + hook (GRUB_ARCH_HIGHMEMPSTART, grub_arch_highmemsize << 20, + GRUB_MACHINE_MEMORY_AVAILABLE); + return GRUB_ERR_NONE; +} + + +static void * +get_modules_end (void) +{ + struct grub_module_info *modinfo; + struct grub_module_header *header; + grub_addr_t modbase; + + modbase = grub_arch_modules_addr (); + modinfo = (struct grub_module_info *) modbase; + + /* Check if there are any modules. */ + if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC) + return modinfo; + + for (header = (struct grub_module_header *) (modbase + modinfo->offset); + header < (struct grub_module_header *) (modbase + modinfo->size); + header = (struct grub_module_header *) ((char *) header + header->size)); + + return header; +} + +void +grub_machine_init (void) +{ + void *modend; + modend = get_modules_end (); + grub_mm_init_region (modend, (grub_arch_memsize << 20) + - (((grub_addr_t) modend) - GRUB_ARCH_LOWMEMVSTART)); + /* FIXME: use upper memory as well. */ + grub_install_get_time_ms (grub_rtc_get_time_ms); + + /* Initialize output terminal (can't be done earlier, as gfxterm + relies on a working heap. */ + grub_video_sm712_init (); + grub_video_video_init (); + grub_video_bitmap_init (); + grub_font_manager_init (); + grub_term_gfxterm_init (); + + grub_at_keyboard_init (); +} + +void +grub_machine_fini (void) +{ +} + +void +grub_exit (void) +{ + while (1); +} + +void +grub_halt (void) +{ + while (1); +} + +void +grub_reboot (void) +{ + while (1); +} + diff --git a/kern/misc.c b/kern/misc.c index 3a2cf9ed9..ba31d24bb 100644 --- a/kern/misc.c +++ b/kern/misc.c @@ -25,6 +25,9 @@ #include #include +static int +grub_vsnprintf_real (char *str, grub_size_t n, const char *fmt, va_list args); + static int grub_iswordseparator (int c) { @@ -202,7 +205,7 @@ grub_vprintf (const char *fmt, va_list args) { int ret; - ret = grub_vsprintf (0, fmt, args); + ret = grub_vsnprintf_real (0, 0, fmt, args); grub_refresh (); return ret; } @@ -636,11 +639,11 @@ grub_lltoa (char *str, int c, unsigned long long n) return p; } -int -grub_vsprintf (char *str, const char *fmt, va_list args) +static int +grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt, va_list args) { char c; - int count = 0; + grub_size_t count = 0; auto void write_char (unsigned char ch); auto void write_str (const char *s); auto void write_fill (const char ch, int n); @@ -648,7 +651,10 @@ grub_vsprintf (char *str, const char *fmt, va_list args) void write_char (unsigned char ch) { if (str) - *str++ = ch; + { + if (count < max_len) + *str++ = ch; + } else grub_putchar (ch); @@ -877,13 +883,64 @@ grub_vsprintf (char *str, const char *fmt, va_list args) } int -grub_sprintf (char *str, const char *fmt, ...) +grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list ap) +{ + grub_size_t ret; + + if (!n) + return 0; + + n--; + + ret = grub_vsnprintf_real (str, n, fmt, ap); + + return ret < n ? ret : n; +} + +int +grub_snprintf (char *str, grub_size_t n, const char *fmt, ...) { va_list ap; int ret; va_start (ap, fmt); - ret = grub_vsprintf (str, fmt, ap); + ret = grub_vsnprintf (str, n, fmt, ap); + va_end (ap); + + return ret; +} + +#define PREALLOC_SIZE 255 + +char * +grub_xvasprintf (const char *fmt, va_list ap) +{ + grub_size_t s, as = PREALLOC_SIZE; + char *ret; + + while (1) + { + ret = grub_malloc (as + 1); + if (!ret) + return NULL; + + s = grub_vsnprintf_real (ret, as, fmt, ap); + if (s <= as) + return ret; + + grub_free (ret); + as = s; + } +} + +char * +grub_xasprintf (const char *fmt, ...) +{ + va_list ap; + char *ret; + + va_start (ap, fmt); + ret = grub_xvasprintf (fmt, ap); va_end (ap); return ret; diff --git a/kern/sparc64/ieee1275/init.c b/kern/sparc64/ieee1275/init.c index 699f9631b..115328f40 100644 --- a/kern/sparc64/ieee1275/init.c +++ b/kern/sparc64/ieee1275/init.c @@ -90,10 +90,7 @@ grub_machine_set_prefix (void) } prefix = grub_ieee1275_encode_devname (bootpath); - path = grub_malloc (grub_strlen (grub_prefix) - + grub_strlen (prefix) - + 2); - grub_sprintf(path, "%s%s", prefix, grub_prefix); + path = grub_xasprintf("%s%s", prefix, grub_prefix); grub_strcpy (grub_prefix, path); diff --git a/lib/i386/datetime.c b/lib/cmos_datetime.c similarity index 95% rename from lib/i386/datetime.c rename to lib/cmos_datetime.c index 63858ed03..8db60b48c 100644 --- a/lib/i386/datetime.c +++ b/lib/cmos_datetime.c @@ -1,7 +1,7 @@ -/* kern/i386/datetime.c - x86 CMOS datetime function. +/* kern/cmos_datetime.c - CMOS datetime function. * * GRUB -- GRand Unified Bootloader - * Copyright (C) 2008 Free Software Foundation, Inc. + * Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ */ #include -#include +#include grub_err_t grub_get_datetime (struct grub_datetime *datetime) diff --git a/lib/hexdump.c b/lib/hexdump.c index 800beb2ba..317635a2b 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -31,21 +31,22 @@ hexdump (unsigned long bse, char *buf, int len) { int cnt, i; - pos = grub_sprintf (line, "%08lx ", bse); + pos = grub_snprintf (line, sizeof (line), "%08lx ", bse); cnt = 16; if (cnt > len) cnt = len; for (i = 0; i < cnt; i++) { - pos += grub_sprintf (&line[pos], "%02x ", (unsigned char) buf[i]); + pos += grub_snprintf (&line[pos], sizeof (line) - pos, + "%02x ", (unsigned char) buf[i]); if ((i & 7) == 7) line[pos++] = ' '; } for (; i < 16; i++) { - pos += grub_sprintf (&line[pos], " "); + pos += grub_snprintf (&line[pos], sizeof (line) - pos, " "); if ((i & 7) == 7) line[pos++] = ' '; } diff --git a/lib/mips/relocator.c b/lib/mips/relocator.c index 796473bf7..118ddbd6f 100644 --- a/lib/mips/relocator.c +++ b/lib/mips/relocator.c @@ -36,7 +36,7 @@ extern grub_uint8_t grub_relocator32_backward_start; extern grub_uint8_t grub_relocator32_backward_end; #define REGW_SIZEOF (2 * sizeof (grub_uint32_t)) -#define JUMP_SIZEOF (sizeof (grub_uint32_t)) +#define JUMP_SIZEOF (2 * sizeof (grub_uint32_t)) #define RELOCATOR_SRC_SIZEOF(x) (&grub_relocator32_##x##_end \ - &grub_relocator32_##x##_start) @@ -64,6 +64,9 @@ write_jump (int regn, void **target) /* j $r. */ *(grub_uint32_t *) *target = (regn<<21) | 0x8; *target = ((grub_uint32_t *) *target) + 1; + /* nop. */ + *(grub_uint32_t *) *target = 0; + *target = ((grub_uint32_t *) *target) + 1; } static void diff --git a/lib/mips/relocator_asm.S b/lib/mips/relocator_asm.S index 9daf0d32f..ff4fa31e0 100644 --- a/lib/mips/relocator_asm.S +++ b/lib/mips/relocator_asm.S @@ -21,8 +21,8 @@ .p2align 4 /* force 16-byte alignment */ VARIABLE (grub_relocator32_forward_start) - move $12, $9 - move $13, $10 + move $a0, $9 + move $a1, $10 copycont1: lb $11,0($8) @@ -32,31 +32,13 @@ copycont1: addiu $10, $10, 0xffff bne $10, $0, copycont1 - move $9, $12 - move $10, $13 -cachecont1a: - cache 1,0($12) - addiu $12, $12, 0x1 - addiu $13, $13, 0xffff - bne $13, $0, cachecont1a - - sync - - move $12, $9 - move $13, $10 -cachecont1b: - cache 0,0($12) - addiu $12, $12, 0x1 - addiu $13, $13, 0xffff - bne $13, $0, cachecont1b - - sync +#include "../../kern/mips/cache_flush.S" VARIABLE (grub_relocator32_forward_end) VARIABLE (grub_relocator32_backward_start) - move $12, $9 - move $13, $10 + move $a0, $9 + move $a1, $10 addu $9, $9, $10 addu $8, $8, $10 @@ -71,23 +53,6 @@ copycont2: addiu $10, 0xffff bne $10, $0, copycont2 - move $9, $12 - move $10, $13 -cachecont2a: - cache 1,0($12) - addiu $12, $12, 0x1 - addiu $13, $13, 0xffff - bne $13, $0, cachecont2a +#include "../../kern/mips/cache_flush.S" - sync - - move $12, $9 - move $13, $10 -cachecont2b: - cache 0,0($12) - addiu $12, $12, 0x1 - addiu $13, $13, 0xffff - bne $13, $0, cachecont2b - - sync VARIABLE (grub_relocator32_backward_end) diff --git a/lib/mips/setjmp.S b/lib/mips/setjmp.S new file mode 100644 index 000000000..8ab6222c4 --- /dev/null +++ b/lib/mips/setjmp.S @@ -0,0 +1,65 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2007,2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include + + .file "setjmp.S" + + .text + +/* + * int grub_setjmp (grub_jmp_buf env) + */ +FUNCTION(grub_setjmp) + sw $s0, 0($a0) + sw $s1, 4($a0) + sw $s2, 8($a0) + sw $s3, 12($a0) + sw $s4, 16($a0) + sw $s5, 20($a0) + sw $s6, 24($a0) + sw $s7, 28($a0) + sw $s8, 32($a0) + sw $gp, 36($a0) + sw $sp, 40($a0) + sw $ra, 44($a0) + move $v0, $zero + move $v1, $zero + jr $ra +/* + * int grub_longjmp (grub_jmp_buf env, int val) + */ +FUNCTION(grub_longjmp) + lw $s0, 0($a0) + lw $s1, 4($a0) + lw $s2, 8($a0) + lw $s3, 12($a0) + lw $s4, 16($a0) + lw $s5, 20($a0) + lw $s6, 24($a0) + lw $s7, 28($a0) + lw $s8, 32($a0) + lw $gp, 36($a0) + lw $sp, 40($a0) + lw $ra, 44($a0) + move $v0, $a1 + bne $v0, $zero, 1f + addiu $v0, $v0, 1 +1: + move $v1, $zero + jr $ra diff --git a/loader/i386/bsd.c b/loader/i386/bsd.c index 7a8ddb89a..9e222244e 100644 --- a/loader/i386/bsd.c +++ b/loader/i386/bsd.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #ifdef GRUB_MACHINE_PCBIOS @@ -849,11 +849,9 @@ grub_netbsd_setup_video (void) if (modevar && *modevar != 0) { char *tmp; - tmp = grub_malloc (grub_strlen (modevar) - + sizeof (";" NETBSD_DEFAULT_VIDEO_MODE)); + tmp = grub_xasprintf ("%s;" NETBSD_DEFAULT_VIDEO_MODE, modevar); if (! tmp) return grub_errno; - grub_sprintf (tmp, "%s;" NETBSD_DEFAULT_VIDEO_MODE, modevar); err = grub_video_set_mode (tmp, 0, 0); grub_free (tmp); } @@ -1634,14 +1632,20 @@ grub_cmd_freebsd_loadenv (grub_command_t cmd __attribute__ ((unused)), if (*curr) { - char name[grub_strlen (curr) + sizeof("kFreeBSD.")]; + char *name; if (*p == '"') p++; - grub_sprintf (name, "kFreeBSD.%s", curr); - if (grub_env_set (name, p)) + name = grub_xasprintf ("kFreeBSD.%s", curr); + if (!name) goto fail; + if (grub_env_set (name, p)) + { + grub_free (name); + goto fail; + } + grub_free (name); } } diff --git a/loader/i386/linux.c b/loader/i386/linux.c index af3b37ac4..bfee316e3 100644 --- a/loader/i386/linux.c +++ b/loader/i386/linux.c @@ -612,11 +612,9 @@ grub_linux_boot (void) May change in future if we have modes without framebuffer. */ if (modevar && *modevar != 0) { - tmp = grub_malloc (grub_strlen (modevar) - + sizeof (";" DEFAULT_VIDEO_MODE)); + tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); if (! tmp) return grub_errno; - grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); err = grub_video_set_mode (tmp, 0, 0); grub_free (tmp); } @@ -941,19 +939,18 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), break; } - buf = grub_malloc (sizeof ("WWWWxHHHHxDD;WWWWxHHHH")); - if (! buf) - goto fail; - linux_mode = &linux_vesafb_modes[vid_mode - GRUB_LINUX_VID_MODE_VESA_START]; - grub_sprintf (buf, "%ux%ux%u,%ux%u", - linux_vesafb_res[linux_mode->res_index].width, - linux_vesafb_res[linux_mode->res_index].height, - linux_mode->depth, - linux_vesafb_res[linux_mode->res_index].width, - linux_vesafb_res[linux_mode->res_index].height); + buf = grub_xasprintf ("%ux%ux%u,%ux%u", + linux_vesafb_res[linux_mode->res_index].width, + linux_vesafb_res[linux_mode->res_index].height, + linux_mode->depth, + linux_vesafb_res[linux_mode->res_index].width, + linux_vesafb_res[linux_mode->res_index].height); + if (! buf) + goto fail; + grub_printf ("%s is deprecated. " "Use set gfxpayload=%s before " "linux command instead.\n", diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c index 3c743c85f..58e945f61 100644 --- a/loader/i386/multiboot.c +++ b/loader/i386/multiboot.c @@ -231,17 +231,20 @@ grub_multiboot (int argc, char *argv[]) case 0: { - char buf[sizeof ("XXXXXXXXXXxXXXXXXXXXXxXXXXXXXXXX,XXXXXXXXXXxXXXXXXXXXX,auto")]; + char *buf; if (header->depth && header->width && header->height) - grub_sprintf (buf, "%dx%dx%d,%dx%d,auto", header->width, - header->height, header->depth, header->width, - header->height); + buf = grub_xasprintf ("%dx%dx%d,%dx%d,auto", header->width, + header->height, header->depth, header->width, + header->height); else if (header->width && header->height) - grub_sprintf (buf, "%dx%d,auto", header->width, header->height); + buf = grub_xasprintf ("%dx%d,auto", header->width, header->height); else - grub_sprintf (buf, "auto"); + buf = grub_strdup ("auto"); + if (!buf) + goto fail; grub_env_set ("gfxpayload", buf); + grub_free (buf); break; } } diff --git a/loader/i386/multiboot_mbi.c b/loader/i386/multiboot_mbi.c index 3324be514..e4a77911b 100644 --- a/loader/i386/multiboot_mbi.c +++ b/loader/i386/multiboot_mbi.c @@ -114,6 +114,18 @@ grub_fill_multiboot_mmap (struct multiboot_mmap_entry *first_entry) case GRUB_MACHINE_MEMORY_AVAILABLE: mmap_entry->type = MULTIBOOT_MEMORY_AVAILABLE; break; + +#ifdef GRUB_MACHINE_MEMORY_ACPI_RECLAIMABLE + case GRUB_MACHINE_MEMORY_ACPI_RECLAIMABLE: + mmap_entry->type = MULTIBOOT_MEMORY_ACPI_RECLAIMABLE; + break; +#endif + +#ifdef GRUB_MACHINE_MEMORY_NVS + case GRUB_MACHINE_MEMORY_NVS: + mmap_entry->type = MULTIBOOT_MEMORY_NVS; + break; +#endif default: mmap_entry->type = MULTIBOOT_MEMORY_RESERVED; @@ -142,11 +154,9 @@ set_video_mode (void) else { char *tmp; - tmp = grub_malloc (grub_strlen (modevar) - + sizeof (DEFAULT_VIDEO_MODE) + 1); + tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); if (! tmp) return grub_errno; - grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); err = grub_video_set_mode (tmp, 0, 0); grub_free (tmp); } diff --git a/loader/i386/xnu.c b/loader/i386/xnu.c index a39f2bc7d..8040e65e3 100644 --- a/loader/i386/xnu.c +++ b/loader/i386/xnu.c @@ -753,11 +753,13 @@ grub_cpu_xnu_fill_devicetree (void) #endif /* The name of key for new table. */ - grub_sprintf (guidbuf, "%08x-%04x-%04x-%02x%02x-", - guid.data1, guid.data2, guid.data3, guid.data4[0], - guid.data4[1]); + grub_snprintf (guidbuf, sizeof (guidbuf), "%08x-%04x-%04x-%02x%02x-", + guid.data1, guid.data2, guid.data3, guid.data4[0], + guid.data4[1]); for (j = 2; j < 8; j++) - grub_sprintf (guidbuf + grub_strlen (guidbuf), "%02x", guid.data4[j]); + grub_snprintf (guidbuf + grub_strlen (guidbuf), + sizeof (guidbuf) - grub_strlen (guidbuf), + "%02x", guid.data4[j]); /* For some reason GUID has to be in uppercase. */ for (j = 0; guidbuf[j] ; j++) if (guidbuf[j] >= 'a' && guidbuf[j] <= 'f') @@ -858,12 +860,10 @@ grub_xnu_set_video (struct grub_xnu_boot_params *params) 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); else { - tmp = grub_malloc (grub_strlen (modevar) - + sizeof (DEFAULT_VIDEO_MODE) + 1); + tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); if (! tmp) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate temporary storag"); - grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, diff --git a/loader/mips/linux.c b/loader/mips/linux.c new file mode 100644 index 000000000..51060c4fb --- /dev/null +++ b/loader/mips/linux.c @@ -0,0 +1,398 @@ +/* linux.c - boot Linux */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2004,2005,2007,2009,2010 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* For frequencies. */ +#include +#include + +#define ELF32_LOADMASK (0x00000000UL) +#define ELF64_LOADMASK (0x0000000000000000ULL) + +static grub_dl_t my_mod; + +static int loaded; + +static grub_size_t linux_size; + +static grub_uint8_t *playground; +static grub_addr_t target_addr, entry_addr; +static int linux_argc; +static grub_off_t argv_off, envp_off; +static grub_off_t rd_addr_arg_off, rd_size_arg_off; +static int initrd_loaded = 0; + +static grub_err_t +grub_linux_boot (void) +{ + struct grub_relocator32_state state; + + /* Boot the kernel. */ + state.gpr[1] = entry_addr; + state.gpr[4] = linux_argc; + state.gpr[5] = target_addr + argv_off; + state.gpr[6] = target_addr + envp_off; + state.jumpreg = 1; + grub_relocator32_boot (playground, target_addr, state); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_linux_release_mem (void) +{ + grub_relocator32_free (playground); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_linux_unload (void) +{ + grub_err_t err; + + err = grub_linux_release_mem (); + grub_dl_unref (my_mod); + + loaded = 0; + + return err; +} + +static grub_err_t +grub_linux_load32 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size) +{ + Elf32_Addr base; + int extraoff; + + /* Linux's entry point incorrectly contains a virtual address. */ + entry_addr = elf->ehdr.ehdr32.e_entry & ~ELF32_LOADMASK; + + linux_size = grub_elf32_size (elf, &base); + if (linux_size == 0) + return grub_errno; + target_addr = base; + /* Pad it; the kernel scribbles over memory beyond its load address. */ + linux_size += 0x100000; + linux_size = ALIGN_UP (base + linux_size, 4) - base; + extraoff = linux_size; + linux_size += extra_size; + + playground = grub_relocator32_alloc (linux_size); + if (!playground) + return grub_errno; + + *extra_mem = playground + extraoff; + + /* Now load the segments into the area we claimed. */ + auto grub_err_t offset_phdr (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load); + grub_err_t offset_phdr (Elf32_Phdr *phdr, grub_addr_t *addr, int *do_load) + { + if (phdr->p_type != PT_LOAD) + { + *do_load = 0; + return 0; + } + *do_load = 1; + + /* Linux's program headers incorrectly contain virtual addresses. + * Translate those to physical, and offset to the area we claimed. */ + *addr = (grub_addr_t) (phdr->p_paddr - base + playground); + return 0; + } + return grub_elf32_load (elf, offset_phdr, 0, 0); +} + +static grub_err_t +grub_linux_load64 (grub_elf_t elf, void **extra_mem, grub_size_t extra_size) +{ + Elf64_Addr base; + int extraoff; + + /* Linux's entry point incorrectly contains a virtual address. */ + entry_addr = elf->ehdr.ehdr64.e_entry & ~ELF64_LOADMASK; + + linux_size = grub_elf64_size (elf, &base); + if (linux_size == 0) + return grub_errno; + target_addr = base; + /* Pad it; the kernel scribbles over memory beyond its load address. */ + linux_size += 0x100000; + linux_size = ALIGN_UP (base + linux_size, 4) - base; + extraoff = linux_size; + linux_size += extra_size; + + playground = grub_relocator32_alloc (linux_size); + if (!playground) + return grub_errno; + + *extra_mem = playground + extraoff; + + /* Now load the segments into the area we claimed. */ + auto grub_err_t offset_phdr (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load); + grub_err_t offset_phdr (Elf64_Phdr *phdr, grub_addr_t *addr, int *do_load) + { + if (phdr->p_type != PT_LOAD) + { + *do_load = 0; + return 0; + } + *do_load = 1; + /* Linux's program headers incorrectly contain virtual addresses. + * Translate those to physical, and offset to the area we claimed. */ + *addr = (grub_addr_t) (phdr->p_paddr - base + playground); + return 0; + } + return grub_elf64_load (elf, offset_phdr, 0, 0); +} + +static grub_err_t +grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_elf_t elf = 0; + int i; + int size; + void *extra = NULL; + grub_uint32_t *linux_argv, *linux_envp; + char *linux_args, *linux_envs; + grub_err_t err; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "no kernel specified"); + + elf = grub_elf_open (argv[0]); + if (! elf) + return grub_errno; + + if (elf->ehdr.ehdr32.e_type != ET_EXEC) + { + grub_elf_close (elf); + return grub_error (GRUB_ERR_UNKNOWN_OS, + "This ELF file is not of the right type\n"); + } + + /* Release the previously used memory. */ + grub_loader_unset (); + loaded = 0; + + /* For arguments. */ + linux_argc = argc; + /* Main arguments. */ + size = (linux_argc) * sizeof (grub_uint32_t); + /* Initrd address and size. */ + size += 2 * sizeof (grub_uint32_t); + /* NULL terminator. */ + size += sizeof (grub_uint32_t); + + /* First argument is always "a0". */ + size += ALIGN_UP (sizeof ("a0"), 4); + /* Normal arguments. */ + for (i = 1; i < argc; i++) + size += ALIGN_UP (grub_strlen (argv[i]) + 1, 4); + + /* rd arguments. */ + size += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4); + size += ALIGN_UP (sizeof ("rd_size=0xXXXXXXXXXXXXXXXX"), 4); + + /* For the environment. */ + size += sizeof (grub_uint32_t); + size += 4 * sizeof (grub_uint32_t); + size += ALIGN_UP (sizeof ("memsize=XXXXXXXXXXXXXXXXXXXX"), 4) + + ALIGN_UP (sizeof ("highmemsize=XXXXXXXXXXXXXXXXXXXX"), 4) + + ALIGN_UP (sizeof ("busclock=XXXXXXXXXX"), 4) + + ALIGN_UP (sizeof ("cpuclock=XXXXXXXXXX"), 4); + + if (grub_elf_is_elf32 (elf)) + err = grub_linux_load32 (elf, &extra, size); + else + if (grub_elf_is_elf64 (elf)) + err = grub_linux_load64 (elf, &extra, size); + else + err = grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unknown ELF class"); + + grub_elf_close (elf); + + if (err) + return err; + + linux_argv = extra; + argv_off = (grub_uint8_t *) linux_argv - (grub_uint8_t *) playground; + extra = linux_argv + (linux_argc + 1 + 2); + linux_args = extra; + + grub_memcpy (linux_args, "a0", sizeof ("a0")); + *linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground + + target_addr; + linux_argv++; + linux_args += ALIGN_UP (sizeof ("a0"), 4); + + for (i = 1; i < argc; i++) + { + grub_memcpy (linux_args, argv[i], grub_strlen (argv[i]) + 1); + *linux_argv = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground + + target_addr; + linux_argv++; + linux_args += ALIGN_UP (grub_strlen (argv[i]) + 1, 4); + } + + /* Reserve space for rd arguments. */ + rd_addr_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground; + linux_args += ALIGN_UP (sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), 4); + *linux_argv = 0; + linux_argv++; + + rd_size_arg_off = (grub_uint8_t *) linux_args - (grub_uint8_t *) playground; + linux_args += ALIGN_UP (sizeof ("rd_size=0xXXXXXXXXXXXXXXXX"), 4); + *linux_argv = 0; + linux_argv++; + + *linux_argv = 0; + + extra = linux_args; + + linux_envp = extra; + envp_off = (grub_uint8_t *) linux_envp - (grub_uint8_t *) playground; + linux_envs = (char *) (linux_envp + 5); + grub_snprintf (linux_envs, sizeof ("memsize=XXXXXXXXXXXXXXXXXXXX"), + "memsize=%lld", + (unsigned long long) grub_mmap_get_lower () >> 20); + linux_envp[0] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground + + target_addr; + linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4); + grub_snprintf (linux_envs, sizeof ("highmemsize=XXXXXXXXXXXXXXXXXXXX"), + "highmemsize=%lld", + (unsigned long long) grub_mmap_get_upper () >> 20); + linux_envp[1] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground + + target_addr; + linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4); + + grub_snprintf (linux_envs, sizeof ("busclock=XXXXXXXXXX"), + "busclock=%d", grub_arch_busclock); + linux_envp[2] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground + + target_addr; + linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4); + grub_snprintf (linux_envs, sizeof ("cpuclock=XXXXXXXXXX"), + "cpuclock=%d", grub_arch_cpuclock); + linux_envp[3] = (grub_uint8_t *) linux_envs - (grub_uint8_t *) playground + + target_addr; + linux_envs += ALIGN_UP (grub_strlen (linux_envs) + 1, 4); + + + linux_envp[4] = 0; + + grub_loader_set (grub_linux_boot, grub_linux_unload, 1); + initrd_loaded = 0; + loaded = 1; + grub_dl_ref (my_mod); + + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + int argc, char *argv[]) +{ + grub_file_t file = 0; + grub_ssize_t size; + grub_size_t overhead; + + if (argc == 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "No initrd specified"); + + if (!loaded) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "You need to load Linux first."); + + if (initrd_loaded) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Only one initrd can be loaded."); + + file = grub_file_open (argv[0]); + if (! file) + return grub_errno; + + size = grub_file_size (file); + + overhead = ALIGN_UP (target_addr + linux_size + 0x10000, 0x10000) + - (target_addr + linux_size); + + playground = grub_relocator32_realloc (playground, + linux_size + overhead + size); + + if (!playground) + { + grub_file_close (file); + return grub_errno; + } + + if (grub_file_read (file, playground + linux_size + overhead, size) != size) + { + grub_error (GRUB_ERR_FILE_READ_ERROR, "Couldn't read file"); + grub_file_close (file); + + return grub_errno; + } + + grub_snprintf ((char *) playground + rd_addr_arg_off, + sizeof ("rd_start=0xXXXXXXXXXXXXXXXX"), "rd_start=0x%llx", + (unsigned long long) target_addr + linux_size + overhead); + ((grub_uint32_t *) (playground + argv_off))[linux_argc] + = target_addr + rd_addr_arg_off; + linux_argc++; + + grub_snprintf ((char *) playground + rd_size_arg_off, + sizeof ("rd_size=0xXXXXXXXXXXXXXXXXX"), "rd_size=0x%llx", + (unsigned long long) size); + ((grub_uint32_t *) (playground + argv_off))[linux_argc] + = target_addr + rd_size_arg_off; + linux_argc++; + + initrd_loaded = 1; + + grub_file_close (file); + + return GRUB_ERR_NONE; +} + +static grub_command_t cmd_linux, cmd_initrd; + +GRUB_MOD_INIT(linux) +{ + cmd_linux = grub_register_command ("linux", grub_cmd_linux, + 0, N_("Load Linux.")); + cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, + 0, N_("Load initrd.")); + my_mod = mod; +} + +GRUB_MOD_FINI(linux) +{ + grub_unregister_command (cmd_linux); + grub_unregister_command (cmd_initrd); +} diff --git a/loader/powerpc/ieee1275/linux.c b/loader/powerpc/ieee1275/linux.c index 39ba2ad0a..930c0cb41 100644 --- a/loader/powerpc/ieee1275/linux.c +++ b/loader/powerpc/ieee1275/linux.c @@ -111,7 +111,7 @@ grub_linux_load32 (grub_elf_t elf) if (entry == 0) entry = 0x01400000; - linux_size = grub_elf32_size (elf); + linux_size = grub_elf32_size (elf, 0); if (linux_size == 0) return grub_errno; /* Pad it; the kernel scribbles over memory beyond its load address. */ @@ -161,7 +161,7 @@ grub_linux_load64 (grub_elf_t elf) if (entry == 0) entry = 0x01400000; - linux_size = grub_elf64_size (elf); + linux_size = grub_elf64_size (elf, 0); if (linux_size == 0) return grub_errno; /* Pad it; the kernel scribbles over memory beyond its load address. */ diff --git a/loader/sparc64/ieee1275/linux.c b/loader/sparc64/ieee1275/linux.c index 4d5723c19..42bae6bb8 100644 --- a/loader/sparc64/ieee1275/linux.c +++ b/loader/sparc64/ieee1275/linux.c @@ -247,7 +247,7 @@ grub_linux_load64 (grub_elf_t elf) linux_entry = elf->ehdr.ehdr64.e_entry; linux_addr = 0x40004000; off = 0x4000; - linux_size = grub_elf64_size (elf); + linux_size = grub_elf64_size (elf, 0); if (linux_size == 0) return grub_errno; diff --git a/loader/xnu.c b/loader/xnu.c index 07a0b726e..7b478c604 100644 --- a/loader/xnu.c +++ b/loader/xnu.c @@ -561,10 +561,9 @@ grub_xnu_register_memory (char *prefix, int *suffix, return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register memory"); if (suffix) { - driverkey->name = grub_malloc (grub_strlen (prefix) + 10); + driverkey->name = grub_xasprintf ("%s%d", prefix, (*suffix)++); if (!driverkey->name) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register memory"); - grub_sprintf (driverkey->name, "%s%d", prefix, (*suffix)++); } else driverkey->name = grub_strdup (prefix); diff --git a/mmap/mips/yeeloong/uppermem.c b/mmap/mips/yeeloong/uppermem.c new file mode 100644 index 000000000..3c5f814de --- /dev/null +++ b/mmap/mips/yeeloong/uppermem.c @@ -0,0 +1,66 @@ +/* Compute amount of lower and upper memory till the first hole. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +grub_uint64_t +grub_mmap_get_lower (void) +{ + grub_uint64_t lower = 0; + + auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); + int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, + grub_uint32_t type) + { + if (type != GRUB_MACHINE_MEMORY_AVAILABLE) + return 0; + if (addr == 0) + lower = size; + return 0; + } + + grub_mmap_iterate (hook); + if (lower > GRUB_ARCH_LOWMEMMAXSIZE) + lower = GRUB_ARCH_LOWMEMMAXSIZE; + return lower; +} + +grub_uint64_t +grub_mmap_get_upper (void) +{ + grub_uint64_t upper = 0; + + auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); + int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, + grub_uint32_t type) + { + if (type != GRUB_MACHINE_MEMORY_AVAILABLE) + return 0; + if (addr <= GRUB_ARCH_HIGHMEMPSTART && addr + size + > GRUB_ARCH_HIGHMEMPSTART) + upper = addr + size - GRUB_ARCH_HIGHMEMPSTART; + return 0; + } + + grub_mmap_iterate (hook); + return upper; +} diff --git a/mmap/mmap.c b/mmap/mmap.c index 874a238b2..c22be0a56 100644 --- a/mmap/mmap.c +++ b/mmap/mmap.c @@ -52,7 +52,7 @@ grub_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, #ifdef GRUB_MACHINE_MEMORY_AVAILABLE [GRUB_MACHINE_MEMORY_AVAILABLE] = 1, #endif -#ifdef GRUB_MACHINE_MEMORY_RESERVED +#if defined (GRUB_MACHINE_MEMORY_RESERVED) && GRUB_MACHINE_MEMORY_RESERVED != GRUB_MACHINE_MEMORY_HOLE [GRUB_MACHINE_MEMORY_RESERVED] = 3, #endif #ifdef GRUB_MACHINE_MEMORY_ACPI diff --git a/normal/autofs.c b/normal/autofs.c index d1ef761fb..57e43fdf4 100644 --- a/normal/autofs.c +++ b/normal/autofs.c @@ -57,14 +57,12 @@ read_fs_list (void) { char *filename; - filename = grub_malloc (grub_strlen (prefix) + sizeof ("/fs.lst")); + filename = grub_xasprintf ("%s/fs.lst", prefix); if (filename) { grub_file_t file; grub_fs_autoload_hook_t tmp_autoload_hook; - grub_sprintf (filename, "%s/fs.lst", prefix); - /* This rules out the possibility that read_fs_list() is invoked recursively when we call grub_file_open() below. */ tmp_autoload_hook = grub_fs_autoload_hook; diff --git a/normal/completion.c b/normal/completion.c index f9d8307e8..13e8f7a6b 100644 --- a/normal/completion.c +++ b/normal/completion.c @@ -107,17 +107,12 @@ iterate_partition (grub_disk_t disk, const grub_partition_t p) if (! partition_name) return 1; - name = grub_malloc (grub_strlen (disk_name) + 1 - + grub_strlen (partition_name) + 1); - if (! name) - { - grub_free (partition_name); - return 1; - } - - grub_sprintf (name, "%s,%s", disk_name, partition_name); + name = grub_xasprintf ("%s,%s", disk_name, partition_name); grub_free (partition_name); + if (! name) + return 1; + ret = add_completion (name, ")", GRUB_COMPLETION_TYPE_PARTITION); grub_free (name); return ret; @@ -141,11 +136,15 @@ iterate_dir (const char *filename, const struct grub_dirhook_info *info) } else if (grub_strcmp (filename, ".") && grub_strcmp (filename, "..")) { - char fname[grub_strlen (filename) + 2]; + char *fname; - grub_sprintf (fname, "%s/", filename); + fname = grub_xasprintf ("%s/", filename); if (add_completion (fname, "", GRUB_COMPLETION_TYPE_FILE)) - return 1; + { + grub_free (fname); + return 1; + } + grub_free (fname); } return 0; @@ -360,8 +359,9 @@ complete_arguments (char *command) if (!option->longarg) continue; - longarg = grub_malloc (grub_strlen (option->longarg)); - grub_sprintf (longarg, "--%s", option->longarg); + longarg = grub_xasprintf ("--%s", option->longarg); + if (!longarg) + return 1; if (add_completion (longarg, " ", GRUB_COMPLETION_TYPE_ARGUMENT)) { diff --git a/normal/crypto.c b/normal/crypto.c index 67330272a..932f26f97 100644 --- a/normal/crypto.c +++ b/normal/crypto.c @@ -80,14 +80,13 @@ read_crypto_list (void) return; } - filename = grub_malloc (grub_strlen (prefix) + sizeof ("/crypto.lst")); + filename = grub_xasprintf ("%s/crypto.lst", prefix); if (!filename) { grub_errno = GRUB_ERR_NONE; return; } - grub_sprintf (filename, "%s/crypto.lst", prefix); file = grub_file_open (filename); if (!file) { diff --git a/normal/dyncmd.c b/normal/dyncmd.c index e797d574f..ca9a82289 100644 --- a/normal/dyncmd.c +++ b/normal/dyncmd.c @@ -69,12 +69,11 @@ read_command_list (void) { char *filename; - filename = grub_malloc (grub_strlen (prefix) + sizeof ("/command.lst")); + filename = grub_xasprintf ("%s/command.lst", prefix); if (filename) { grub_file_t file; - grub_sprintf (filename, "%s/command.lst", prefix); file = grub_file_open (filename); if (file) { diff --git a/normal/handler.c b/normal/handler.c index b44dc7a68..686626929 100644 --- a/normal/handler.c +++ b/normal/handler.c @@ -172,12 +172,11 @@ read_handler_list (void) { char *filename; - filename = grub_malloc (grub_strlen (prefix) + sizeof ("/handler.lst")); + filename = grub_xasprintf ("%s/handler.lst", prefix); if (filename) { grub_file_t file; - grub_sprintf (filename, "%s/handler.lst", prefix); file = grub_file_open (filename); if (file) { diff --git a/normal/main.c b/normal/main.c index 7a5e3ee8e..6e3518a59 100644 --- a/normal/main.c +++ b/normal/main.c @@ -406,15 +406,15 @@ grub_normal_init_page (struct grub_term_output *term) int msg_len; int posx; const char *msg = _("GNU GRUB version %s"); - - char *msg_formatted = grub_malloc (grub_strlen(msg) + - grub_strlen(PACKAGE_VERSION)); + char *msg_formatted; grub_uint32_t *unicode_msg; grub_uint32_t *last_position; grub_term_cls (term); - grub_sprintf (msg_formatted, msg, PACKAGE_VERSION); + msg_formatted = grub_xasprintf (msg, PACKAGE_VERSION); + if (!msg_formatted) + return; msg_len = grub_utf8_to_ucs4_alloc (msg_formatted, &unicode_msg, &last_position); @@ -502,11 +502,10 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), prefix = grub_env_get ("prefix"); if (prefix) { - config = grub_malloc (grub_strlen (prefix) + sizeof ("/grub.cfg")); + config = grub_xasprintf ("%s/grub.cfg", prefix); if (! config) goto quit; - grub_sprintf (config, "%s/grub.cfg", prefix); grub_enter_normal_mode (config); grub_free (config); } @@ -540,10 +539,11 @@ grub_normal_reader_init (int nested) "the first word, TAB lists possible command completions. Anywhere " "else TAB lists possible device or file completions. %s"); const char *msg_esc = _("ESC at any time exits."); - char *msg_formatted = grub_malloc (sizeof (char) * (grub_strlen (msg) + - grub_strlen(msg_esc) + 1)); + char *msg_formatted; - grub_sprintf (msg_formatted, msg, nested ? msg_esc : ""); + msg_formatted = grub_xasprintf (msg, nested ? msg_esc : ""); + if (!msg_formatted) + return grub_errno; FOR_ACTIVE_TERM_OUTPUTS(term) { @@ -563,12 +563,15 @@ static grub_err_t grub_normal_read_line_real (char **line, int cont, int nested) { grub_parser_t parser = grub_parser_get_current (); - char prompt[sizeof(">") + grub_strlen (parser->name)]; + char *prompt; if (cont) - grub_sprintf (prompt, ">"); + prompt = grub_xasprintf (">"); else - grub_sprintf (prompt, "%s>", parser->name); + prompt = grub_xasprintf ("%s>", parser->name); + + if (!prompt) + return grub_errno; while (1) { diff --git a/normal/menu.c b/normal/menu.c index 17730eff3..585c10304 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -1,7 +1,7 @@ /* menu.c - General supporting functionality for menus. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -98,7 +98,7 @@ grub_menu_set_timeout (int timeout) { char buf[16]; - grub_sprintf (buf, "%d", timeout); + grub_snprintf (buf, sizeof (buf), "%d", timeout); grub_env_set ("timeout", buf); } } @@ -519,7 +519,7 @@ notify_execution_failure (void *userdata __attribute__((unused))) grub_errno = GRUB_ERR_NONE; } grub_printf ("\n "); - grub_printf_ (N_("Failed to boot default entries.\n")); + grub_printf_ (N_("Failed to boot both default and fallback entries.\n")); grub_wait_after_message (); } diff --git a/normal/menu_text.c b/normal/menu_text.c index cab1d22f8..b39f57512 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -183,13 +183,14 @@ command-line or ESC to return menu."), STANDARD_MARGIN, STANDARD_MARGIN, } else { - const char *msg = _("Use the %C and %C keys to select which \ -entry is highlighted.\n"); - char *msg_translated = - grub_malloc (sizeof (char) * grub_strlen (msg) + 1); + const char *msg = _("Use the %C and %C keys to select which " + "entry is highlighted.\n"); + char *msg_translated; - grub_sprintf (msg_translated, msg, (grub_uint32_t) GRUB_TERM_DISP_UP, - (grub_uint32_t) GRUB_TERM_DISP_DOWN); + msg_translated = grub_xasprintf (msg, (grub_uint32_t) GRUB_TERM_DISP_UP, + (grub_uint32_t) GRUB_TERM_DISP_DOWN); + if (!msg_translated) + return; grub_putchar ('\n'); grub_print_message_indented (msg_translated, STANDARD_MARGIN, STANDARD_MARGIN, term); @@ -366,7 +367,7 @@ menu_text_print_timeout (int timeout, void *dataptr) grub_term_gotoxy (data->term, 0, grub_term_height (data->term) - 3); - msg_translated = grub_malloc (sizeof (char) * grub_strlen (msg) + 5); + msg_translated = grub_xasprintf (msg, timeout); if (!msg_translated) { grub_print_error (); @@ -374,7 +375,6 @@ menu_text_print_timeout (int timeout, void *dataptr) return; } - grub_sprintf (msg_translated, msg, timeout); grub_print_message_indented (msg_translated, 3, 0, data->term); posx = grub_term_getxy (data->term) >> 8; diff --git a/normal/term.c b/normal/term.c index 667d27ee9..42201fbb3 100644 --- a/normal/term.c +++ b/normal/term.c @@ -167,14 +167,13 @@ read_terminal_list (void) return; } - filename = grub_malloc (grub_strlen (prefix) + sizeof ("/terminal.lst")); + filename = grub_xasprintf ("%s/terminal.lst", prefix); if (!filename) { grub_errno = GRUB_ERR_NONE; return; } - grub_sprintf (filename, "%s/terminal.lst", prefix); file = grub_file_open (filename); if (!file) { diff --git a/partmap/acorn.c b/partmap/acorn.c index 076d998f8..081b6ee94 100644 --- a/partmap/acorn.c +++ b/partmap/acorn.c @@ -175,14 +175,7 @@ fail: static char * acorn_partition_map_get_name (const grub_partition_t p) { - char *name; - - name = grub_malloc (13); - if (! name) - return 0; - - grub_sprintf (name, "%d", p->index + 1); - return name; + return grub_xasprintf ("%d", p->index + 1); } diff --git a/partmap/amiga.c b/partmap/amiga.c index e8ba9181c..f832db354 100644 --- a/partmap/amiga.c +++ b/partmap/amiga.c @@ -184,14 +184,7 @@ amiga_partition_map_probe (grub_disk_t disk, const char *str) static char * amiga_partition_map_get_name (const grub_partition_t p) { - char *name; - - name = grub_malloc (13); - if (! name) - return 0; - - grub_sprintf (name, "%d", p->index + 1); - return name; + return grub_xasprintf ("%d", p->index + 1); } diff --git a/partmap/apple.c b/partmap/apple.c index 7934c90fd..a1a645acf 100644 --- a/partmap/apple.c +++ b/partmap/apple.c @@ -227,14 +227,7 @@ apple_partition_map_probe (grub_disk_t disk, const char *str) static char * apple_partition_map_get_name (const grub_partition_t p) { - char *name; - - name = grub_malloc (13); - if (! name) - return 0; - - grub_sprintf (name, "%d", p->index + 1); - return name; + return grub_xasprintf ("%d", p->index + 1); } diff --git a/partmap/gpt.c b/partmap/gpt.c index 4a4957437..cb1229bee 100644 --- a/partmap/gpt.c +++ b/partmap/gpt.c @@ -162,14 +162,7 @@ gpt_partition_map_probe (grub_disk_t disk, const char *str) static char * gpt_partition_map_get_name (const grub_partition_t p) { - char *name; - - name = grub_malloc (13); - if (! name) - return 0; - - grub_sprintf (name, "%d", p->index + 1); - return name; + return grub_xasprintf ("%d", p->index + 1); } diff --git a/partmap/msdos.c b/partmap/msdos.c index 6ba7fb927..1c3861cc7 100644 --- a/partmap/msdos.c +++ b/partmap/msdos.c @@ -300,21 +300,15 @@ pc_partition_map_probe (grub_disk_t disk, const char *str) static char * pc_partition_map_get_name (const grub_partition_t p) { - char *name; struct grub_msdos_partition *pcdata = p->data; - name = grub_malloc (13); - if (! name) - return 0; - if (pcdata->bsd_part < 0) - grub_sprintf (name, "%d", pcdata->dos_part + 1); + return grub_xasprintf ("%d", pcdata->dos_part + 1); else if (pcdata->dos_part < 0) - grub_sprintf (name, "%c", pcdata->bsd_part + 'a'); + return grub_xasprintf ("%c", pcdata->bsd_part + 'a'); else - grub_sprintf (name, "%d,%c", pcdata->dos_part + 1, pcdata->bsd_part + 'a'); - - return name; + return grub_xasprintf ("%d,%c", pcdata->dos_part + 1, + pcdata->bsd_part + 'a'); } diff --git a/partmap/sun.c b/partmap/sun.c index e816ec17a..42cf0d598 100644 --- a/partmap/sun.c +++ b/partmap/sun.c @@ -184,13 +184,7 @@ sun_partition_map_probe (grub_disk_t disk, const char *str) static char * sun_partition_map_get_name (const grub_partition_t p) { - char *name; - - name = grub_malloc (13); - if (name) - grub_sprintf (name, "%d", p->index + 1); - - return name; + return grub_xasprintf ("%d", p->index + 1); } /* Partition map type. */ diff --git a/po/POTFILES b/po/POTFILES index 32927256c..04a3516fa 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -75,9 +75,9 @@ normal/menu_entry.c normal/menu_text.c normal/misc.c -term/i386/pc/serial.c +term/serial.c -util/i386/pc/grub-mkimage.c +util/grub-mkrawimage.c util/i386/pc/grub-setup.c util/mkisofs/eltorito.c diff --git a/script/execute.c b/script/execute.c index 08224fc7d..ee7e099bc 100644 --- a/script/execute.c +++ b/script/execute.c @@ -92,7 +92,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grub_err_t ret = 0; int argcount = 0; grub_script_function_t func = 0; - char errnobuf[6]; + char errnobuf[18]; char *cmdname; /* Lookup the command. */ @@ -123,7 +123,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) } grub_free (assign); - grub_sprintf (errnobuf, "%d", grub_errno); + grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno); grub_env_set ("?", errnobuf); return 0; @@ -156,7 +156,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd) grub_free (args[i]); grub_free (args); - grub_sprintf (errnobuf, "%d", ret); + grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret); grub_env_set ("?", errnobuf); return ret; diff --git a/term/i386/pc/at_keyboard.c b/term/at_keyboard.c similarity index 94% rename from term/i386/pc/at_keyboard.c rename to term/at_keyboard.c index 6382c954a..1f84ae71a 100644 --- a/term/i386/pc/at_keyboard.c +++ b/term/at_keyboard.c @@ -17,13 +17,14 @@ */ #include -#include -#include -#include +#include +#include +#include #include #include static short at_keyboard_status = 0; +static int pending_key = -1; #define KEYBOARD_STATUS_SHIFT_L (1 << 0) #define KEYBOARD_STATUS_SHIFT_R (1 << 1) @@ -237,14 +238,27 @@ grub_at_keyboard_getkey_noblock (void) static int grub_at_keyboard_checkkey (void) { - /* FIXME: this will be triggered by BREAK events. */ - return KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)) ? 1 : -1; + if (pending_key != -1) + return 1; + + pending_key = grub_at_keyboard_getkey_noblock (); + + if (pending_key != -1) + return 1; + + return -1; } static int grub_at_keyboard_getkey (void) { int key; + if (pending_key != -1) + { + key = pending_key; + pending_key = -1; + return key; + } do { key = grub_at_keyboard_getkey_noblock (); @@ -255,6 +269,8 @@ grub_at_keyboard_getkey (void) static grub_err_t grub_keyboard_controller_init (void) { + pending_key = -1; + at_keyboard_status = 0; grub_keyboard_controller_orig = grub_keyboard_controller_read (); grub_keyboard_controller_write (grub_keyboard_controller_orig | KEYBOARD_SCANCODE_SET1); return GRUB_ERR_NONE; diff --git a/term/gfxterm.c b/term/gfxterm.c index f493f882c..a8aca7820 100644 --- a/term/gfxterm.c +++ b/term/gfxterm.c @@ -27,7 +27,7 @@ #include #include -#define DEFAULT_VIDEO_MODE "auto" +#define DEFAULT_VIDEO_MODE "auto" #define DEFAULT_BORDER_WIDTH 10 #define DEFAULT_STANDARD_COLOR 0x07 @@ -95,6 +95,7 @@ struct grub_virtual_screen /* Color settings. */ grub_video_color_t fg_color; grub_video_color_t bg_color; + grub_video_color_t bg_color_display; /* Text buffer for virtual screen. Contains (columns * rows) number of entries. */ @@ -237,6 +238,8 @@ grub_virtual_screen_setup (unsigned int x, unsigned int y, grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); + virtual_screen.bg_color_display = grub_video_map_rgba(0, 0, 0, 0); + /* Clear out text buffer. */ for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++) clear_char (&(virtual_screen.text_buffer[i])); @@ -267,11 +270,10 @@ grub_gfxterm_init (void) GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); else { - tmp = grub_malloc (grub_strlen (modevar) - + sizeof (DEFAULT_VIDEO_MODE) + 1); - grub_sprintf (tmp, "%s;" DEFAULT_VIDEO_MODE, modevar); - err = grub_video_set_mode (tmp, - GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); + tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); + if (!tmp) + return grub_errno; + err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); grub_free (tmp); } @@ -341,7 +343,7 @@ redraw_screen_rect (unsigned int x, unsigned int y, /* If bitmap is smaller than requested blit area, use background color. */ - color = virtual_screen.bg_color; + color = virtual_screen.bg_color_display; /* Fill right side of the bitmap if needed. */ if ((x + width >= bitmap_width) && (y < bitmap_height)) @@ -388,7 +390,7 @@ redraw_screen_rect (unsigned int x, unsigned int y, else { /* Render background layer. */ - color = virtual_screen.bg_color; + color = virtual_screen.bg_color_display; grub_video_fill_rect (color, x, y, width, height); /* Render text layer as replaced (to get texts background color). */ @@ -810,7 +812,8 @@ grub_gfxterm_cls (void) /* Clear text layer. */ grub_video_set_active_render_target (text_layer); color = virtual_screen.bg_color; - grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); + grub_video_fill_rect (color, 0, 0, virtual_screen.width, + virtual_screen.height); grub_video_set_active_render_target (GRUB_VIDEO_RENDER_TARGET_DISPLAY); /* Mark virtual screen to be redrawn. */ diff --git a/term/ieee1275/ofconsole.c b/term/ieee1275/ofconsole.c index a9834e23e..dd4270eff 100644 --- a/term/ieee1275/ofconsole.c +++ b/term/ieee1275/ofconsole.c @@ -109,7 +109,7 @@ grub_ofconsole_getcharwidth (grub_uint32_t c __attribute__((unused))) static void grub_ofconsole_setcolorstate (grub_term_color_state state) { - char setcol[20]; + char *setcol; int fg; int bg; @@ -128,8 +128,10 @@ grub_ofconsole_setcolorstate (grub_term_color_state state) return; } - grub_sprintf (setcol, "\e[3%dm\e[4%dm", fg, bg); - grub_ofconsole_writeesc (setcol); + setcol = grub_xasprintf ("\e[3%dm\e[4%dm", fg, bg); + if (setcol) + grub_ofconsole_writeesc (setcol); + grub_free (setcol); } static void @@ -293,15 +295,16 @@ grub_ofconsole_getwh (void) static void grub_ofconsole_gotoxy (grub_uint8_t x, grub_uint8_t y) { - char s[11]; /* 5 + 3 + 3. */ - if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_ANSI)) { + char *s; grub_curr_x = x; grub_curr_y = y; - grub_sprintf (s, "\e[%d;%dH", y + 1, x + 1); - grub_ofconsole_writeesc (s); + s = grub_xasprintf ("\e[%d;%dH", y + 1, x + 1); + if (s) + grub_ofconsole_writeesc (s); + grub_free (s); } else { diff --git a/term/i386/pc/serial.c b/term/serial.c similarity index 96% rename from term/i386/pc/serial.c rename to term/serial.c index 135bb6cc5..9a195f0e7 100644 --- a/term/i386/pc/serial.c +++ b/term/serial.c @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include @@ -28,9 +28,8 @@ #include #define TEXT_WIDTH 80 -#define TEXT_HEIGHT 25 +#define TEXT_HEIGHT 24 -static struct grub_term_output grub_serial_term_output; static unsigned int xpos, ypos; static unsigned int keep_track = 1; static unsigned int registered = 0; @@ -39,6 +38,8 @@ static unsigned int registered = 0; static char input_buf[8]; static unsigned int npending = 0; +static struct grub_term_output grub_serial_term_output; + /* Argument options. */ static const struct grub_arg_option options[] = { @@ -54,7 +55,7 @@ static const struct grub_arg_option options[] = /* Serial port settings. */ struct serial_port { - unsigned short port; + grub_port_t port; unsigned short divisor; unsigned short word_len; unsigned int parity; @@ -68,12 +69,13 @@ static struct serial_port serial_settings; static const unsigned short *serial_hw_io_addr = (const unsigned short *) GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR; #define GRUB_SERIAL_PORT_NUM 4 #else -static const unsigned short serial_hw_io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; +#include +static const grub_port_t serial_hw_io_addr[] = GRUB_MACHINE_SERIAL_PORTS; #define GRUB_SERIAL_PORT_NUM (ARRAY_SIZE(serial_hw_io_addr)) #endif /* Return the port number for the UNITth serial device. */ -unsigned short +grub_port_t grub_serial_hw_get_port (const unsigned int unit) { if (unit < GRUB_SERIAL_PORT_NUM) @@ -149,7 +151,7 @@ serial_translate_key_sequence (void) if (input_buf[0] != '\e' || input_buf[1] != '[') return; - for (i = 0; ARRAY_SIZE (three_code_table); i++) + for (i = 0; i < ARRAY_SIZE (three_code_table); i++) if (three_code_table[i].key == input_buf[2]) { input_buf[0] = three_code_table[i].ascii; @@ -254,6 +256,9 @@ grub_serial_getkey (void) ; c = input_buf[0]; + if (c == 0x7f) + c = GRUB_TERM_BACKSPACE; + grub_memmove (input_buf, input_buf + 1, --npending); return c; @@ -364,7 +369,7 @@ grub_serial_putchar (grub_uint32_t c) break; case '\n': - if (ypos < TEXT_HEIGHT) + if (ypos < TEXT_HEIGHT - 1) ypos++; break; @@ -503,7 +508,7 @@ grub_cmd_serial (grub_extcmd_t cmd, } if (state[1].set) - serial_settings.port = (unsigned short) grub_strtoul (state[1].arg, 0, 0); + serial_settings.port = (grub_port_t) grub_strtoul (state[1].arg, 0, 0); if (state[2].set) { @@ -603,8 +608,8 @@ GRUB_MOD_INIT(serial) { cmd = grub_register_extcmd ("serial", grub_cmd_serial, GRUB_COMMAND_FLAG_BOTH, - N_("[OPTIONS...]"), - N_("Configure serial port."), options); + "serial [OPTIONS...]", + "Configure serial port.", options); /* Set default settings. */ serial_settings.port = grub_serial_hw_get_port (0); diff --git a/term/tparm.c b/term/tparm.c index fa25bd32c..adf0b3a7c 100644 --- a/term/tparm.c +++ b/term/tparm.c @@ -167,7 +167,7 @@ save_text(const char *fmt, const char *s, int len) get_space(s_len + 1); - (void) grub_sprintf(out_buff + out_used, fmt, s); + (void) grub_snprintf(out_buff + out_used, s_len + 1, fmt, s); out_used += grub_strlen(out_buff + out_used); } @@ -179,7 +179,7 @@ save_number(const char *fmt, int number, int len) get_space((unsigned) len + 1); - (void) grub_sprintf(out_buff + out_used, fmt, number); + (void) grub_snprintf(out_buff + out_used, len + 1, fmt, number); out_used += grub_strlen(out_buff + out_used); } diff --git a/tests/lib/test.c b/tests/lib/test.c index cd0799f56..b5c054370 100644 --- a/tests/lib/test.c +++ b/tests/lib/test.c @@ -47,19 +47,16 @@ add_failure (const char *file, const char *funp, grub_uint32_t line, const char *fmt, va_list args) { - char buf[1024]; grub_test_failure_t failure; failure = (grub_test_failure_t) grub_malloc (sizeof (*failure)); if (!failure) return; - grub_vsprintf (buf, fmt, args); - failure->file = grub_strdup (file ? : ""); failure->funp = grub_strdup (funp ? : ""); failure->line = line; - failure->message = grub_strdup (buf); + failure->message = grub_xvasprintf (fmt, args); grub_list_push (GRUB_AS_LIST_P (&failure_list), GRUB_AS_LIST (failure)); } diff --git a/util/bin2h.c b/util/bin2h.c new file mode 100644 index 000000000..5ce47f086 --- /dev/null +++ b/util/bin2h.c @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2008,2010 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include + +#define _GNU_SOURCE 1 +#include + +#include "progname.h" + +static struct option options[] = + { + {"help", no_argument, 0, 'h' }, + {"version", no_argument, 0, 'V' }, + {0, 0, 0, 0 } + }; + +static void +usage (int status) +{ + if (status) + fprintf (stderr, + "Try ``%s --help'' for more information.\n", program_name); + else + printf ("\ +Usage: %s [OPTIONS] SYMBOL-NAME\n\ +\n\ + -h, --help display this message and exit\n\ + -V, --version print version information and exit\n\ +\n\ +Report bugs to <%s>.\n\ +", program_name, PACKAGE_BUGREPORT); + + exit (status); +} + +int +main (int argc, char *argv[]) +{ + int b, i; + char *sym; + + set_program_name (argv[0]); + + /* Check for options. */ + while (1) + { + int c = getopt_long (argc, argv, "snm:r:hVv", options, 0); + + if (c == -1) + break; + else + switch (c) + { + case 'h': + usage (0); + break; + + case 'V': + printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); + return 0; + + default: + usage (1); + break; + } + } + + if (optind >= argc) + usage (1); + + if (optind + 1 != argc) + usage (1); + + sym = argv[optind]; + + b = getchar (); + if (b == EOF) + goto abort; + + printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALY GENERATED */\n" + "unsigned char %s[] =\n{\n", sym); + + while (1) + { + printf ("0x%02x", b); + + b = getchar (); + if (b == EOF) + goto end; + + for (i = 0; i < 16 - 1; i++) + { + printf (", 0x%02x", b); + + b = getchar (); + if (b == EOF) + goto end; + } + + printf (",\n"); + } + +end: + printf ("\n};\n"); + +abort: + exit (0); +} diff --git a/util/elf/grub-mkimage.c b/util/elf/grub-mkimage.c index c0736b83f..04a19bc4e 100644 --- a/util/elf/grub-mkimage.c +++ b/util/elf/grub-mkimage.c @@ -100,7 +100,7 @@ load_note (Elf32_Phdr *phdr, FILE *out) void load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir, - char *mods[], FILE *out, char *memdisk_path) + char *mods[], FILE *out, char *memdisk_path, char *config_path) { char *module_img; struct grub_util_path_list *path_list; @@ -109,6 +109,7 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir, size_t offset; size_t total_module_size; size_t memdisk_size = 0; + size_t config_size = 0; path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods); @@ -122,6 +123,13 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir, total_module_size += memdisk_size + sizeof (struct grub_module_header); } + if (config_path) + { + config_size = ALIGN_UP(grub_util_get_image_size (config_path), 512); + grub_util_info ("the size of memory disk is 0x%x", config_size); + total_module_size += config_size + sizeof (struct grub_module_header); + } + for (p = path_list; p; p = p->next) { total_module_size += (grub_util_get_image_size (p->name) @@ -168,6 +176,19 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir, offset += memdisk_size; } + if (config_path) + { + struct grub_module_header *header; + + header = (struct grub_module_header *) (module_img + offset); + header->type = OBJ_TYPE_CONFIG; + header->size = grub_host_to_target32 (config_size + sizeof (*header)); + offset += sizeof (*header); + + grub_util_load_image (config_path, module_img + offset); + offset += config_size; + } + /* Write the module data to the new segment. */ grub_util_write_image_at (module_img, total_module_size, @@ -184,7 +205,7 @@ load_modules (grub_addr_t modbase, Elf32_Phdr *phdr, const char *dir, } void -add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *memdisk_path) +add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char *memdisk_path, char *config_path) { Elf32_Ehdr ehdr; Elf32_Phdr *phdrs = NULL; @@ -273,7 +294,7 @@ add_segments (char *dir, char *prefix, FILE *out, int chrp, char *mods[], char * phdr->p_offset = grub_host_to_target32 (ALIGN_UP (grub_util_get_fp_size (out), GRUB_TARGET_SIZEOF_LONG)); - load_modules (modbase, phdr, dir, mods, out, memdisk_path); + load_modules (modbase, phdr, dir, mods, out, memdisk_path, config_path); } if (chrp) @@ -316,6 +337,7 @@ static struct option options[] = {"directory", required_argument, 0, 'd'}, {"prefix", required_argument, 0, 'p'}, {"memdisk", required_argument, 0, 'm'}, + {"config", required_argument, 0, 'c'}, {"output", required_argument, 0, 'o'}, {"help", no_argument, 0, 'h'}, {"note", no_argument, 0, 'n'}, @@ -338,6 +360,7 @@ Make a bootable image of GRUB.\n\ -d, --directory=DIR use images and modules under DIR [default=%s]\n\ -p, --prefix=DIR set grub_prefix directory\n\ -m, --memdisk=FILE embed FILE as a memdisk image\n\ + -c, --config=FILE embed FILE as boot config\n\ -o, --output=FILE output a generated image to FILE\n\ -h, --help display this message and exit\n\ -n, --note add NOTE segment for CHRP Open Firmware\n\ @@ -358,6 +381,7 @@ main (int argc, char *argv[]) char *dir = NULL; char *prefix = NULL; char *memdisk = NULL; + char *config = NULL; int chrp = 0; set_program_name (argv[0]); @@ -366,7 +390,7 @@ main (int argc, char *argv[]) while (1) { - int c = getopt_long (argc, argv, "d:p:m:o:hVvn", options, 0); + int c = getopt_long (argc, argv, "d:p:m:c:o:hVvn", options, 0); if (c == -1) break; @@ -392,6 +416,13 @@ main (int argc, char *argv[]) prefix = xstrdup ("(memdisk)/boot/grub"); break; + case 'c': + if (config) + free (config); + config = xstrdup (optarg); + + break; + case 'h': usage (0); break; @@ -422,7 +453,8 @@ main (int argc, char *argv[]) if (! fp) grub_util_error ("cannot open %s", output); - add_segments (dir ? : GRUB_LIBDIR, prefix, fp, chrp, argv + optind, memdisk); + add_segments (dir ? : GRUB_LIBDIR, prefix, fp, chrp, argv + optind, memdisk, + config); fclose (fp); diff --git a/util/grub-fstest.c b/util/grub-fstest.c index 4470cbfa5..bf30286a4 100644 --- a/util/grub-fstest.c +++ b/util/grub-fstest.c @@ -278,18 +278,26 @@ cmd_crc (char *pathname) static void fstest (char **images, int num_disks, int cmd, int n, char **args) { - char host_file[128]; - char loop_name[8]; - char *argv[3] = { "-p", loop_name, host_file}; + char *host_file; + char *loop_name; + char *argv[3] = { "-p" }; int i; for (i = 0; i < num_disks; i++) { - if (grub_strlen (images[i]) + 7 > sizeof (host_file)) - grub_util_error ("pathname %s too long", images[i]); + loop_name = grub_xasprintf ("loop%d", i); + host_file = grub_xasprintf ("(host)%s", images[i]); - grub_sprintf (loop_name, "loop%d", i); - grub_sprintf (host_file, "(host)%s", images[i]); + if (!loop_name || !host_file) + { + grub_free (loop_name); + grub_free (host_file); + grub_util_error (grub_errmsg); + return; + } + + argv[1] = loop_name; + argv[2] = host_file; if (execute_command ("loopback", 3, argv)) grub_util_error ("loopback command fails"); @@ -328,9 +336,19 @@ fstest (char **images, int num_disks, int cmd, int n, char **args) for (i = 0; i < num_disks; i++) { - grub_sprintf (loop_name, "loop%d", i); + grub_free (loop_name); + loop_name = grub_xasprintf ("loop%d", i); + if (!loop_name) + { + grub_free (host_file); + grub_util_error (grub_errmsg); + return; + } execute_command ("loopback", 2, argv); } + + grub_free (loop_name); + grub_free (host_file); } static struct option options[] = { diff --git a/util/grub-install.in b/util/grub-install.in index 4d814b085..bb323d706 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -30,10 +30,11 @@ PACKAGE_VERSION=@PACKAGE_VERSION@ target_cpu=@target_cpu@ platform=@platform@ host_os=@host_os@ +font=@datadir@/@PACKAGE_TARNAME@/ascii.pf2 pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` grub_setup=${sbindir}/`echo grub-setup | sed ${transform}` -if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] ; then +if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" = "sparc64-ieee1275" ] || [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` else grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}` @@ -83,6 +84,11 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then cat <&2 usage exit 1 @@ -297,15 +305,17 @@ prefix_drive= config_opt= if [ "x${devabstraction_module}" = "x" ] ; then - if echo "${install_device}" | grep -qx "(.*)" ; then - install_drive="${install_device}" - else - install_drive="`$grub_probe --target=drive --device ${install_device}`" + if [ x"${install_device}" != x ]; then + if echo "${install_device}" | grep -qx "(.*)" ; then + install_drive="${install_device}" + else + install_drive="`$grub_probe --target=drive --device ${install_device}`" + fi + install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`" fi grub_drive="`$grub_probe --target=drive --device ${grub_device}`" # Strip partition number - install_drive="`echo ${install_drive} | sed -e s/,[0-9]*[a-z]*//g`" grub_drive="`echo ${grub_drive} | sed -e s/,[0-9]*[a-z]*//g`" if [ "$disk_module" = ata ] ; then # generic method (used on coreboot and ata mod) @@ -339,6 +349,8 @@ if [ "${target_cpu}-${platform}" = "i386-pc" ] || [ "${target_cpu}-${platform}" # Now perform the installation. $grub_setup ${setup_verbose} ${setup_force} --directory=${grubdir} --device-map=${device_map} \ ${install_device} || exit 1 +elif [ "${target_cpu}-${platform}" = "mips-yeeloong" ] ; then + $grub_mkimage ${config_opt} -f ${font} -d ${pkglibdir} -O elf --output=/boot/grub.elf --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 else $grub_mkimage ${config_opt} -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1 fi diff --git a/util/grub-mkfont.c b/util/grub-mkfont.c index fcd35afd4..38906a70e 100644 --- a/util/grub-mkfont.c +++ b/util/grub-mkfont.c @@ -49,6 +49,12 @@ struct grub_glyph_info grub_uint8_t bitmap[0]; }; +enum file_formats +{ + PF2, + ASCII_BITMAPS +}; + #define GRUB_FONT_FLAG_BOLD 1 #define GRUB_FONT_FLAG_NOBITMAP 2 #define GRUB_FONT_FLAG_NOHINTING 4 @@ -87,6 +93,7 @@ static struct option options[] = {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, + {"ascii-bitmaps", no_argument, 0, 0x102}, {0, 0, 0, 0} }; @@ -102,6 +109,7 @@ usage (int status) Usage: %s [OPTIONS] FONT_FILES\n\ \nOptions:\n\ -o, --output=FILE_NAME set output file name\n\ + --ascii-bitmaps save only the ASCII bitmaps\n\ -i, --index=N set face index\n\ -r, --range=A-B[,C-D] set font range\n\ -n, --name=S set font family name\n\ @@ -337,7 +345,39 @@ print_glyphs (struct grub_font_info *font_info) } void -write_font (struct grub_font_info *font_info, char *output_file) +write_font_ascii_bitmap (struct grub_font_info *font_info, char *output_file) +{ + FILE *file; + struct grub_glyph_info *glyph; + int num; + + file = fopen (output_file, "wb"); + if (! file) + grub_util_error ("Can\'t write to file %s.", output_file); + + int correct_size; + for (glyph = font_info->glyph, num = 0; glyph; glyph = glyph->next, num++) + { + correct_size = 1; + if (glyph->width != 8 || glyph->height != 16) + { + /* printf ("Width or height from glyph U+%04x not supported, skipping.\n", glyph->char_code); */ + correct_size = 0; + } + int row; + for (row = 0; row < glyph->height; row++) + { + if (correct_size) + fwrite (&glyph->bitmap[row], sizeof(glyph->bitmap[row]), 1, file); + else + fwrite (&correct_size, 1, 1, file); + } + } + fclose (file); +} + +void +write_font_pf2 (struct grub_font_info *font_info, char *output_file) { FILE *file; grub_uint32_t leng, data; @@ -473,9 +513,6 @@ write_font (struct grub_font_info *font_info, char *output_file) grub_util_write_image ((char *) &cur->bitmap[0], cur->bitmap_size, file); } - if (font_verbosity > 1) - print_glyphs (font_info); - fclose (file); } @@ -487,6 +524,7 @@ main (int argc, char *argv[]) int font_index = 0; int font_size = 0; char *output_file = NULL; + enum file_formats file_format = PF2; memset (&font_info, 0, sizeof (font_info)); @@ -552,7 +590,7 @@ main (int argc, char *argv[]) font_info.ranges = xrealloc (font_info.ranges, (font_info.num_range + GRUB_FONT_RANGE_BLOCK) * - sizeof (int) * 2); + sizeof (grub_uint32_t) * 2); font_info.ranges[font_info.num_range * 2] = a; font_info.ranges[font_info.num_range * 2 + 1] = b; @@ -591,12 +629,33 @@ main (int argc, char *argv[]) font_verbosity++; break; + case 0x102: + file_format = ASCII_BITMAPS; + break; + default: usage (1); break; } } + if (file_format == ASCII_BITMAPS && font_info.num_range > 0) + { + grub_util_error ("Option --ascii-bitmaps doesn't accept ranges (use ASCII)."); + return 1; + } + + else if (file_format == ASCII_BITMAPS) + { + font_info.ranges = xrealloc (font_info.ranges, + GRUB_FONT_RANGE_BLOCK * + sizeof (grub_uint32_t) * 2); + + font_info.ranges[0] = (grub_uint32_t) 0x00; + font_info.ranges[1] = (grub_uint32_t) 0x7f; + font_info.num_range = 1; + } + if (! output_file) grub_util_error ("no output file is specified"); @@ -638,7 +697,13 @@ main (int argc, char *argv[]) FT_Done_FreeType (ft_lib); - write_font (&font_info, output_file); + if (file_format == PF2) + write_font_pf2 (&font_info, output_file); + else if (file_format == ASCII_BITMAPS) + write_font_ascii_bitmap (&font_info, output_file); + + if (font_verbosity > 1) + print_glyphs (&font_info); return 0; } diff --git a/util/grub-mkpasswd-pbkdf2.c b/util/grub-mkpasswd-pbkdf2.c index 82437fdca..a00b1e990 100644 --- a/util/grub-mkpasswd-pbkdf2.c +++ b/util/grub-mkpasswd-pbkdf2.c @@ -50,9 +50,9 @@ grub_vprintf (const char *fmt, va_list args) } int -grub_vsprintf (char *str, const char *fmt, va_list args) +grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list args) { - return vsprintf (str, fmt, args); + return vsnprintf (str, n, fmt, args); } void diff --git a/util/i386/pc/grub-mkimage.c b/util/grub-mkrawimage.c similarity index 66% rename from util/i386/pc/grub-mkimage.c rename to util/grub-mkrawimage.c index 16b2c6619..2316479e9 100644 --- a/util/i386/pc/grub-mkimage.c +++ b/util/grub-mkrawimage.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -95,12 +96,19 @@ compress_kernel (char *kernel_img, size_t kernel_size, static void generate_image (const char *dir, char *prefix, FILE *out, char *mods[], - char *memdisk_path, char *config_path) + char *memdisk_path, char *font_path, char *config_path, +#ifdef GRUB_PLATFORM_IMAGE_DEFAULT + grub_platform_image_format_t format +#else + int dummy __attribute__ ((unused)) +#endif + +) { - char *kernel_img, *boot_img, *core_img; - size_t kernel_size, boot_size, total_module_size, core_size; - size_t memdisk_size = 0, config_size = 0; - char *kernel_path, *boot_path; + char *kernel_img, *core_img; + size_t kernel_size, total_module_size, core_size; + size_t memdisk_size = 0, font_size = 0, config_size = 0, config_size_pure = 0; + char *kernel_path; size_t offset; struct grub_util_path_list *path_list, *p, *next; struct grub_module_info *modinfo; @@ -119,9 +127,16 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], total_module_size += memdisk_size + sizeof (struct grub_module_header); } + if (font_path) + { + font_size = ALIGN_UP(grub_util_get_image_size (font_path), 4); + total_module_size += font_size + sizeof (struct grub_module_header); + } + if (config_path) { - config_size = grub_util_get_image_size (config_path) + 1; + config_size_pure = grub_util_get_image_size (config_path) + 1; + config_size = ALIGN_UP(config_size_pure, 4); grub_util_info ("the size of config file is 0x%x", config_size); total_module_size += config_size + sizeof (struct grub_module_header); } @@ -150,15 +165,17 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], for (p = path_list; p; p = p->next) { struct grub_module_header *header; - size_t mod_size; + size_t mod_size, orig_size; - mod_size = grub_util_get_image_size (p->name); + orig_size = grub_util_get_image_size (p->name); + mod_size = ALIGN_UP(orig_size, 4); header = (struct grub_module_header *) (kernel_img + offset); memset (header, 0, sizeof (struct grub_module_header)); header->type = OBJ_TYPE_ELF; header->size = grub_host_to_target32 (mod_size + sizeof (*header)); offset += sizeof (*header); + memset (kernel_img + offset + orig_size, 0, mod_size - orig_size); grub_util_load_image (p->name, kernel_img + offset); offset += mod_size; @@ -178,6 +195,20 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], offset += memdisk_size; } + if (font_path) + { + struct grub_module_header *header; + + header = (struct grub_module_header *) (kernel_img + offset); + memset (header, 0, sizeof (struct grub_module_header)); + header->type = OBJ_TYPE_FONT; + header->size = grub_host_to_target32 (font_size + sizeof (*header)); + offset += sizeof (*header); + + grub_util_load_image (font_path, kernel_img + offset); + offset += font_size; + } + if (config_path) { struct grub_module_header *header; @@ -189,8 +220,8 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], offset += sizeof (*header); grub_util_load_image (config_path, kernel_img + offset); + *(kernel_img + offset + config_size_pure - 1) = 0; offset += config_size; - *(kernel_img + offset - 1) = 0; } grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size); @@ -202,29 +233,33 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], #if defined(GRUB_MACHINE_PCBIOS) { unsigned num; + char *boot_path, *boot_img; + size_t boot_size; num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS); if (num > 0xffff) grub_util_error (_("the core image is too big")); - + boot_path = grub_util_get_path (dir, "diskboot.img"); boot_size = grub_util_get_image_size (boot_path); if (boot_size != GRUB_DISK_SECTOR_SIZE) - grub_util_error (_("diskboot.img size must be %u bytes"), GRUB_DISK_SECTOR_SIZE); - + grub_util_error (_("diskboot.img size must be %u bytes"), + GRUB_DISK_SECTOR_SIZE); + boot_img = grub_util_read_image (boot_path); - + { struct grub_boot_blocklist *block; block = (struct grub_boot_blocklist *) (boot_img - + GRUB_DISK_SECTOR_SIZE - - sizeof (*block)); + + GRUB_DISK_SECTOR_SIZE + - sizeof (*block)); block->len = grub_host_to_target16 (num); /* This is filled elsewhere. Verify it just in case. */ - assert (block->segment == grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG - + (GRUB_DISK_SECTOR_SIZE >> 4))); + assert (block->segment + == grub_host_to_target16 (GRUB_BOOT_MACHINE_KERNEL_SEG + + (GRUB_DISK_SECTOR_SIZE >> 4))); } - + grub_util_write_image (boot_img, boot_size, out); free (boot_img); free (boot_path); @@ -233,6 +268,8 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], { char *rom_img; size_t rom_size; + char *boot_path, *boot_img; + size_t boot_size; boot_path = grub_util_get_path (dir, "boot.img"); boot_size = grub_util_get_image_size (boot_path); @@ -245,12 +282,12 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], memset (rom_img, 0, rom_size); *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_CORE_ENTRY_ADDR)) - = grub_cpu_to_le32 ((grub_uint32_t) -rom_size); + = grub_host_to_target32 ((grub_uint32_t) -rom_size); memcpy (rom_img, core_img, core_size); *((grub_int32_t *) (boot_img + GRUB_BOOT_MACHINE_CORE_ENTRY_ADDR)) - = grub_cpu_to_le32 ((grub_uint32_t) -rom_size); + = grub_host_to_target32 ((grub_uint32_t) -rom_size); memcpy (rom_img + rom_size - boot_size, boot_img, boot_size); @@ -261,18 +298,17 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], free (boot_img); free (boot_path); } - #endif #ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE)) - = grub_cpu_to_le32 (total_module_size); + = grub_host_to_target32 (total_module_size); #endif *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE)) - = grub_cpu_to_le32 (kernel_size); + = grub_host_to_target32 (kernel_size); #ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE *((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE)) - = grub_cpu_to_le32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE); + = grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE); #endif #if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART) @@ -281,16 +317,79 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[], if (prefix[0] == '(') { *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART)) - = grub_cpu_to_le32 (-2); + = grub_host_to_target32 (-2); *((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)) - = grub_cpu_to_le32 (-2); + = grub_host_to_target32 (-2); } #endif #ifdef GRUB_MACHINE_PCBIOS if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER) grub_util_error (_("core image is too big (%p > %p)"), - GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, GRUB_MEMORY_MACHINE_UPPER); + GRUB_KERNEL_MACHINE_LINK_ADDR + core_size, + GRUB_MEMORY_MACHINE_UPPER); +#endif + +#if defined(GRUB_MACHINE_MIPS) + if (format == GRUB_PLATFORM_IMAGE_ELF) + { + char *elf_img; + size_t program_size; + Elf32_Ehdr *ehdr; + Elf32_Phdr *phdr; + grub_uint32_t target_addr; + + program_size = ALIGN_UP (core_size, 4); + + elf_img = xmalloc (program_size + sizeof (*ehdr) + sizeof (*phdr)); + memset (elf_img, 0, program_size + sizeof (*ehdr) + sizeof (*phdr)); + memcpy (elf_img + sizeof (*ehdr) + sizeof (*phdr), core_img, core_size); + ehdr = (void *) elf_img; + phdr = (void *) (elf_img + sizeof (*ehdr)); + memcpy (ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] = ELFCLASS32; +#ifdef GRUB_CPU_MIPSEL + ehdr->e_ident[EI_DATA] = ELFDATA2LSB; +#else + ehdr->e_ident[EI_DATA] = ELFDATA2MSB; +#endif + ehdr->e_ident[EI_VERSION] = EV_CURRENT; + ehdr->e_ident[EI_OSABI] = ELFOSABI_NONE; + ehdr->e_type = grub_host_to_target16 (ET_EXEC); + ehdr->e_machine = grub_host_to_target16 (EM_MIPS); + ehdr->e_version = grub_host_to_target32 (EV_CURRENT); + + ehdr->e_phoff = grub_host_to_target32 ((char *) phdr - (char *) ehdr); + ehdr->e_phentsize = grub_host_to_target16 (sizeof (*phdr)); + ehdr->e_phnum = grub_host_to_target16 (1); + + /* No section headers. */ + ehdr->e_shoff = grub_host_to_target32 (0); + ehdr->e_shentsize = grub_host_to_target16 (0); + ehdr->e_shnum = grub_host_to_target16 (0); + ehdr->e_shstrndx = grub_host_to_target16 (0); + + ehdr->e_ehsize = grub_host_to_target16 (sizeof (*ehdr)); + + phdr->p_type = grub_host_to_target32 (PT_LOAD); + phdr->p_offset = grub_host_to_target32 (sizeof (*ehdr) + sizeof (*phdr)); + phdr->p_flags = grub_host_to_target32 (PF_R | PF_W | PF_X); + + target_addr = ALIGN_UP (GRUB_KERNEL_MACHINE_LINK_ADDR + + kernel_size + total_module_size, 32); + ehdr->e_entry = grub_host_to_target32 (target_addr); + phdr->p_vaddr = grub_host_to_target32 (target_addr); + phdr->p_paddr = grub_host_to_target32 (target_addr); + phdr->p_align = grub_host_to_target32 (GRUB_KERNEL_MACHINE_LINK_ALIGN); + ehdr->e_flags = grub_host_to_target32 (0x1000 | EF_MIPS_NOREORDER + | EF_MIPS_PIC | EF_MIPS_CPIC); + phdr->p_filesz = grub_host_to_target32 (core_size); + phdr->p_memsz = grub_host_to_target32 (core_size); + + free (core_img); + core_img = elf_img; + core_size = program_size + sizeof (*ehdr) + sizeof (*phdr); + } #endif grub_util_write_image (core_img, core_size, out); @@ -314,8 +413,12 @@ static struct option options[] = {"directory", required_argument, 0, 'd'}, {"prefix", required_argument, 0, 'p'}, {"memdisk", required_argument, 0, 'm'}, + {"font", required_argument, 0, 'f'}, {"config", required_argument, 0, 'c'}, {"output", required_argument, 0, 'o'}, +#ifdef GRUB_PLATFORM_IMAGE_DEFAULT + {"format", required_argument, 0, 'O'}, +#endif {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, @@ -336,8 +439,17 @@ Make a bootable image of GRUB.\n\ -d, --directory=DIR use images and modules under DIR [default=%s]\n\ -p, --prefix=DIR set grub_prefix directory [default=%s]\n\ -m, --memdisk=FILE embed FILE as a memdisk image\n\ + -f, --font=FILE embed FILE as a boot font\n\ -c, --config=FILE embed FILE as boot config\n\ - -o, --output=FILE output a generated image to FILE [default=stdout]\n\ + -o, --output=FILE output a generated image to FILE [default=stdout]\n" +#ifdef GRUB_PLATFORM_IMAGE_DEFAULT + "\ + -O, --format=FORMAT generate an image in format [default=" + GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT "]\n \ + available formats: " + GRUB_PLATFORM_IMAGE_FORMATS "\n" +#endif + "\ -h, --help display this message and exit\n\ -V, --version print version information and exit\n\ -v, --verbose print verbose messages\n\ @@ -355,16 +467,18 @@ main (int argc, char *argv[]) char *dir = NULL; char *prefix = NULL; char *memdisk = NULL; + char *font = NULL; char *config = NULL; FILE *fp = stdout; - - set_program_name (argv[0]); +#ifdef GRUB_PLATFORM_IMAGE_DEFAULT + grub_platform_image_format_t format = GRUB_PLATFORM_IMAGE_DEFAULT; +#endif grub_util_init_nls (); while (1) { - int c = getopt_long (argc, argv, "d:p:m:c:o:hVv", options, 0); + int c = getopt_long (argc, argv, "d:p:m:c:o:O:f:hVv", options, 0); if (c == -1) break; @@ -378,6 +492,22 @@ main (int argc, char *argv[]) output = xstrdup (optarg); break; +#ifdef GRUB_PLATFORM_IMAGE_DEFAULT + case 'O': +#ifdef GRUB_PLATFORM_IMAGE_RAW + if (strcmp (optarg, "raw") == 0) + format = GRUB_PLATFORM_IMAGE_RAW; + else +#endif +#ifdef GRUB_PLATFORM_IMAGE_ELF + if (strcmp (optarg, "elf") == 0) + format = GRUB_PLATFORM_IMAGE_ELF; + else +#endif + usage (1); + break; +#endif + case 'd': if (dir) free (dir); @@ -397,6 +527,13 @@ main (int argc, char *argv[]) prefix = xstrdup ("(memdisk)/boot/grub"); break; + case 'f': + if (font) + free (font); + + font = xstrdup (optarg); + break; + case 'c': if (config) free (config); @@ -438,7 +575,13 @@ main (int argc, char *argv[]) } generate_image (dir ? : GRUB_LIBDIR, prefix ? : DEFAULT_DIRECTORY, fp, - argv + optind, memdisk, config); + argv + optind, memdisk, font, config, +#ifdef GRUB_PLATFORM_IMAGE_DEFAULT + format +#else + 0 +#endif + ); fclose (fp); diff --git a/util/grub-probe.c b/util/grub-probe.c index 879098542..ba2fe4c35 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -94,6 +94,11 @@ probe_partmap (grub_disk_t disk) static int probe_raid_level (grub_disk_t disk) { + /* disk might be NULL in the case of a LVM physical volume with no LVM + signature. Ignore such cases here. */ + if (!disk) + return -1; + if (disk->dev->id != GRUB_DISK_DEVICE_RAID_ID) return -1; diff --git a/video/sm712.c b/video/sm712.c new file mode 100644 index 000000000..1e0f59b9d --- /dev/null +++ b/video/sm712.c @@ -0,0 +1,229 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. + * + * GRUB 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 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#define grub_video_render_target grub_video_fbrender_target + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct +{ + struct grub_video_mode_info mode_info; + struct grub_video_render_target *render_target; + + unsigned int bytes_per_scan_line; + unsigned int bytes_per_pixel; + grub_uint8_t *ptr; + int index_color_mode; + int mapped; + grub_uint32_t base; + grub_pci_device_t dev; +} framebuffer; + +static grub_err_t +grub_video_sm712_video_init (void) +{ + /* Reset frame buffer. */ + grub_memset (&framebuffer, 0, sizeof(framebuffer)); + + return grub_video_fb_init (); +} + +static grub_err_t +grub_video_sm712_video_fini (void) +{ + if (framebuffer.mapped) + grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr, + 1024 * 600 * 2); + + return grub_video_fb_fini (); +} + +static grub_err_t +grub_video_sm712_setup (unsigned int width, unsigned int height, + unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused))) +{ + int depth; + grub_err_t err; + int found = 0; + + auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused))); + int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused))) + { + grub_pci_address_t addr; + grub_uint32_t class; + + addr = grub_pci_make_address (dev, 2); + class = grub_pci_read (addr); + + if (((class >> 16) & 0xffff) != 0x0300 || pciid != 0x0712126f) + return 0; + + found = 1; + + addr = grub_pci_make_address (dev, 4); + framebuffer.base = grub_pci_read (addr); + framebuffer.dev = dev; + + return 1; + } + + /* Decode depth from mode_type. If it is zero, then autodetect. */ + depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) + >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS; + + if ((width != 1024 && width != 0) || (height != 600 && height != 0) + || (depth != 16 && depth != 0)) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "Only 1024x600x16 is supported"); + + grub_pci_iterate (find_card); + if (!found) + return grub_error (GRUB_ERR_IO, "Couldn't find graphics card"); + + if (found && framebuffer.base == 0) + { + /* FIXME: change framebuffer base */ + } + + /* Fill mode info details. */ + framebuffer.mode_info.width = 1024; + framebuffer.mode_info.height = 600; + framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB; + framebuffer.mode_info.bpp = 16; + framebuffer.mode_info.bytes_per_pixel = 2; + framebuffer.mode_info.pitch = 1024 * 2; + framebuffer.mode_info.number_of_colors = 256; + framebuffer.mode_info.red_mask_size = 5; + framebuffer.mode_info.red_field_pos = 11; + framebuffer.mode_info.green_mask_size = 6; + framebuffer.mode_info.green_field_pos = 5; + framebuffer.mode_info.blue_mask_size = 5; + framebuffer.mode_info.blue_field_pos = 0; + framebuffer.mode_info.reserved_mask_size = 0; + framebuffer.mode_info.reserved_field_pos = 0; + framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); + /* We can safely discard volatile attribute. */ + framebuffer.ptr = (void *) grub_pci_device_map_range (framebuffer.dev, + framebuffer.base, + 1024 * 600 * 2); + framebuffer.mapped = 1; + + err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr); + + if (err) + return err; + + err = grub_video_fb_set_active_render_target (framebuffer.render_target); + + if (err) + return err; + + /* Copy default palette to initialize emulated palette. */ + err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, + grub_video_fbstd_colors); + return err; +} + +static grub_err_t +grub_video_sm712_set_palette (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data) +{ + if (framebuffer.index_color_mode) + { + /* TODO: Implement setting indexed color mode palette to hardware. */ + } + + /* Then set color to emulated palette. */ + return grub_video_fb_set_palette (start, count, palette_data); +} + +static grub_err_t +grub_video_sm712_swap_buffers (void) +{ + /* TODO: Implement buffer swapping. */ + return GRUB_ERR_NONE; +} + +static grub_err_t +grub_video_sm712_set_active_render_target (struct grub_video_render_target *target) +{ + if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY) + target = framebuffer.render_target; + + return grub_video_fb_set_active_render_target (target); +} + +static grub_err_t +grub_video_sm712_get_info_and_fini (struct grub_video_mode_info *mode_info, + void **framebuf) +{ + grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info)); + *framebuf = (char *) framebuffer.ptr; + + grub_video_fb_fini (); + + return GRUB_ERR_NONE; +} + + +static struct grub_video_adapter grub_video_sm712_adapter = + { + .name = "SM712 Video Driver", + + .init = grub_video_sm712_video_init, + .fini = grub_video_sm712_video_fini, + .setup = grub_video_sm712_setup, + .get_info = grub_video_fb_get_info, + .get_info_and_fini = grub_video_sm712_get_info_and_fini, + .set_palette = grub_video_sm712_set_palette, + .get_palette = grub_video_fb_get_palette, + .set_viewport = grub_video_fb_set_viewport, + .get_viewport = grub_video_fb_get_viewport, + .map_color = grub_video_fb_map_color, + .map_rgb = grub_video_fb_map_rgb, + .map_rgba = grub_video_fb_map_rgba, + .unmap_color = grub_video_fb_unmap_color, + .fill_rect = grub_video_fb_fill_rect, + .blit_bitmap = grub_video_fb_blit_bitmap, + .blit_render_target = grub_video_fb_blit_render_target, + .scroll = grub_video_fb_scroll, + .swap_buffers = grub_video_sm712_swap_buffers, + .create_render_target = grub_video_fb_create_render_target, + .delete_render_target = grub_video_fb_delete_render_target, + .set_active_render_target = grub_video_sm712_set_active_render_target, + .get_active_render_target = grub_video_fb_get_active_render_target, + + .next = 0 + }; + +GRUB_MOD_INIT(video_sm712) +{ + grub_video_register (&grub_video_sm712_adapter); +} + +GRUB_MOD_FINI(video_sm712) +{ + grub_video_unregister (&grub_video_sm712_adapter); +}