i386-qemu port
PATCH 1/1 i386-qemu port
Hi,
I ported GRUB to QEMU. It's mostly based on the coreboot port, with the main difference being that we include code to transition from i8086 mode, an i386 firmware entry point and produce raw code images instead of ELF.
The result is you can do e.g.
$ sudo grub-mkrawimage at_keyboard normal etc -o /usr/share/qemu/grub
and then:
$ qemu -bios grub -hda /dev/zero
grub-mkrawimage will automatically generate an image of arbitrary size, depending on the number of modules that were included (or the size of the memdisk). The only restriction imposed by qemu is that it must be 64k-aligned (zero-padding is used to archieve that).
This patch is incomplete, still includes a few hacks and needs general cleanup. I'll send a few cleanup patches separately so we can integrate this avoiding code duplication and ugly kludges.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
i386-qemu.rmk +2 -0
@@ -0,0 +1,2 @@ +# -*- makefile -*- +include $(srcdir)/conf/i386-coreboot.mk
i386-coreboot.rmk +54 -9
86 lines not on this page · raw message
i386/qemu/startup.S +113 -0
113 lines not on this page · raw message
i386/qemu/mmap.c +62 -0
62 lines not on this page · raw message
i386/realmode.S +1 -1
@@ -107,7 +107,7 @@ /* this is the GDT descriptor */ gdtdesc: .word 0x27 /* limit */ - .long gdt /* addr */ + .long (0xffe00 + gdt) /* addr */ /* * These next routine, "prot_to_real" is structured in a very
i386/coreboot/startup.S +0 -8
@@ -78,14 +78,6 @@ jmp EXT_C(grub_main) /* - * This call is special... it never returns... in fact it should simply - * hang at this point! - */ -FUNCTION(grub_stop) - hlt - jmp EXT_C(grub_stop) - -/* * prot_to_real and associated structures (but NOT real_to_prot, that is * only needed for BIOS gates). */
i386/coreboot/init.c +13 -1
@@ -50,6 +50,17 @@grub_fatal ("grub_get_rtc() is not implemented.\n" ); } +/* +* This call is special... it never returns... in fact it should simply +* hang at this point! +*/ +void +grub_stop () +{ +while (1 ) + __asm__ ("hlt" ); +} +/* Stop the floppy drive from spinning, so that other software is jumped to with a known state. */ void
@@ -144,5 +155,6 @@grub_addr_t grub_arch_modules_addr (void ) { -return ALIGN_UP ((grub_addr_t ) _end,GRUB_MOD_ALIGN ); +// return ALIGN_UP((grub_addr_t) _end, GRUB_MOD_ALIGN); +return _end; }
i386/qemu/boot.S +116 -0
116 lines not on this page · raw message
configure.ac +2 -1
@@ -85,6 +85,7 @@ i386-coreboot) ;; i386-linuxbios) platform=coreboot ;; i386-ieee1275) ;; + i386-qemu) ;; powerpc-ieee1275) ;; sparc64-ieee1275) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
@@ -414,7 +415,7 @@ # Check symbols provided by linker script. CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100" fi - if test "x$platform" = xpc && test "x$TARGET_APPLE_CC" != x1 ; then + if test "x$TARGET_APPLE_CC" != x1 ; then grub_CHECK_BSS_START_SYMBOL grub_CHECK_END_SYMBOL fi
grub/i386/qemu/time.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/time.h>
grub/i386/qemu/serial.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/serial.h>
grub/i386/qemu/kernel.h +51 -0
51 lines not on this page · raw message
grub/i386/qemu/console.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/console.h>
grub/i386/qemu/boot.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/boot.h>
grub/i386/qemu/init.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/init.h>
grub/i386/qemu/machine.h +24 -0
@@ -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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_MACHINE_MACHINE_HEADER +#define GRUB_MACHINE_MACHINE_HEADER 1 + +#define GRUB_MACHINE_QEMU 1 + +#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
grub/i386/qemu/loader.h +1 -0
@@ -0,0 +1 @@ +#include <grub/cpu/loader.h>
grub/i386/qemu/memory.h +45 -0
45 lines not on this page · raw message
grub/i386/coreboot/kernel.h +26 -3
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. +* 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
@@ -19,10 +19,33 @@#ifndef GRUB_KERNEL_MACHINE_HEADER #define GRUB_KERNEL_MACHINE_HEADER 1 +/* The offset of GRUB_TOTAL_MODULE_SIZE. */ +#define GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE 0x8 + +/* The offset of GRUB_KERNEL_IMAGE_SIZE. */ +#define GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE 0xc + +/* The offset of GRUB_PREFIX. */ +#define GRUB_KERNEL_MACHINE_PREFIX 0x10 + +/* End of the data section. */ +#define GRUB_KERNEL_MACHINE_DATA_END 0x50 + +#ifndef ASM_FILE +#include <grub/symbol.h> +#include <grub/types.h> -#ifndef ASM_FILE +/* The size of kernel image. */ +extern grub_int32_t grub_kernel_image_size; + +/* The total size of module images following the kernel. */ +extern grub_int32_t grub_total_module_size; + +/* The prefix which points to the directory where GRUB modules and its +configuration file are located. */ extern char grub_prefix[]; -#endif +#endif /* ! ASM_FILE */ +#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
i386/pc/grub-mkimage.c +49 -0
94 lines not on this page · raw message
does module area require alignment? (Re: [PATCH] i386-qemu port)
i386/coreboot/init.c line 160
Quoted 7 lines · Robert Millan
grub_addr_t
grub_arch_modules_addr(void)
{i386/coreboot/init.c +2
-1-return ALIGN_UP ((grub_addr_t ) _end,GRUB_MOD_ALIGN ); +// return ALIGN_UP((grub_addr_t) _end, GRUB_MOD_ALIGN); +return _end; }
Some comments on this one. It seems coreboot cares about alignment in modbase because all ELF targets do. This comes from elf/grub-mkimage.c:
/* Place modules just after grub segment. */
modbase = ALIGN_UP(grub_end + GRUB_MOD_GAP, GRUB_MOD_ALIGN);However, I don't see why this is necessary. The module area is unaligned on i386-pc and this works just fine there. Same for i386-qemu.
Does anyone know why do we align ELF targets? When I did the coreboot port, the ELF part was based on existing Ieee1275 code, so I guess I just mimicked it. Is there some issue with non-i386 CPUs or with some Ieee1275 implementations that makes this alignment a requirement?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
PATCH 1/1 move grub_stop() (Re: [PATCH] i386-qemu port)
In reply to Robert MillanMove grub_stop to init.c to ease code sharing with i386-qemu.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-21 Robert Millan <[email protected]>
* kern/i386/coreboot/startup.S (grub_stop): Move from here ...
* kern/i386/coreboot/init.c (grub_stop): ... to here.
i386/coreboot/startup.S +0 -8
@@ -78,14 +78,6 @@ codestart: jmp EXT_C(grub_main) /* - * This call is special... it never returns... in fact it should simply - * hang at this point! - */ -FUNCTION(grub_stop) - hlt - jmp EXT_C(grub_stop) - -/* * prot_to_real and associated structures (but NOT real_to_prot, that is * only needed for BIOS gates). */
i386/coreboot/init.c +11 -0
@@ -50,6 +50,17 @@ grub_get_rtc (void)grub_fatal ("grub_get_rtc() is not implemented.\n" ); } +/* +* This call is special... it never returns... in fact it should simply +* hang at this point! +*/ +void +grub_stop () +{ +while (1 ) +grub_cpu_idle (); +} +/* Stop the floppy drive from spinning, so that other software is jumped to with a known state. */ void
Quoted 5 lines · Robert Millan
Hi,
I ported GRUB to QEMU. It's mostly based on the coreboot port, with the main difference being that we include code to transition from i8086 mode, an i386 firmware entry point and produce raw code images instead of ELF.
That's great news! Eventually, it would be nice to have support for many other platforms supported by qemu, such as arm and mips. This way, it will be possible to emulate many platforms in qemu without having to implement the platform specific firmware.
Quoted 3 lines
The result is you can do e.g.
$ sudo grub-mkrawimage at_keyboard normal etc -o /usr/share/qemu/grub
Please consider if we can call it grub-mkimage unless grub-mkimage would make sense as a separate executable for that platform.
Quoted 3 lines
This patch is incomplete, still includes a few hacks and needs general cleanup. I'll send a few cleanup patches separately so we can integrate this avoiding code duplication and ugly kludges.
It should be one of our priorities to make the code easy to maintain and extend.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] move grub_stop() (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 1 line · Robert Millan
Move
grub_stoptoinit.cto ease code sharing with i386-qemu.
That's not quite a movement. grub_cpu_idle() does nothing.
I think we need to have several implementations of grub_stop: hard halt with interrupts disabled, exit from qemu, exit from other emulators if it's different, power off, exit to BIOS. Then different platforms should enable and try whatever is appropriate for them.
Signature · 2 lines
Regards, Pavel Roskin
Re: does module area require alignment? (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 4 lines · Robert Millan
Does anyone know why do we align ELF targets? When I did the coreboot port, the ELF part was based on existing Ieee1275 code, so I guess I just mimicked it. Is there some issue with non-i386 CPUs or with some Ieee1275 implementations that makes this alignment a requirement?
It was a hack for PowerPC openfirmware. I don't know why it was needed. I didn't have time and desire to debug openfirmware to find out what it wants.
Signature · 2 lines
Regards, Pavel Roskin
PATCH 1/1 rename kernel.elf to kernel.img (Re: [PATCH] i386-qemu port)
In reply to Robert MillanIf you check my earlier patch, you'll see i386-qemu.rmk is just a stub that includes i386-coreboot.rmk. This is to reduce code duplication (untill we have a more flexible build system).
This patch renames kernel.elf to kernel.img in ELF platforms, so that more variables / etc can be shared with non-ELF ones.
It has no user-visible effect.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-21 Robert Millan <[email protected]>
* conf/i386-ieee1275.rmk (pkglib_PROGRAMS): Replace kernel.elf' with kernel.img'.
(kernel_elf_SOURCES): Rename to ... (kernel_img_SOURCES): ... this. (kernel_elf_HEADERS): Rename to ... (kernel_img_HEADERS): ... this. Update all users. (kernel_elf_CFLAGS): Rename to ... (kernel_img_CFLAGS): ... this.
(kernel_elf_LDFLAGS): Rename to ... (kernel_img_LDFLAGS): ... this.
* conf/i386-coreboot.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* util/elf/grub-mkimage.c (add_segments): Replace "kernel.elf" with "kernel.img".
i386-ieee1275.rmk +8 -8
@@ -8,10 +8,10 @@ script/sh/lexer.c_DEPENDENCIES = grub_script.tab.h # Images. -pkglib_PROGRAMS = kernel.elf +pkglib_PROGRAMS = kernel.img -# For kernel.elf. -kernel_elf_SOURCES = kern/i386/ieee1275/startup.S kern/i386/ieee1275/init.c \ +# For kernel.img. +kernel_img_SOURCES = kern/i386/ieee1275/startup.S kern/i386/ieee1275/init.c \ kern/ieee1275/init.c \ kern/ieee1275/mmap.c \ kern/ieee1275/cmain.c kern/ieee1275/openfw.c \
@@ -27,21 +27,21 @@ term/ieee1275/ofconsole.c \ disk/ieee1275/ofdisk.c \ symlist.c -kernel_elf_HEADERS = cache.h device.h disk.h dl.h elf.h elfload.h \ +kernel_img_HEADERS = cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ partition.h pc_partition.h reader.h symbol.h term.h time.h types.h \ ieee1275/ieee1275.h machine/kernel.h machine/loader.h machine/memory.h \ list.h handler.h command.h -kernel_elf_CFLAGS = $(COMMON_CFLAGS) -kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic +kernel_img_CFLAGS = $(COMMON_CFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst -symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh +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_elf_HEADERS)) config.h genkernsyms.sh +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) # Utilities.
i386-coreboot.rmk +9 -9
@@ -8,10 +8,10 @@ script/sh/lexer.c_DEPENDENCIES = grub_script.tab.h # Images. -pkglib_PROGRAMS = kernel.elf +pkglib_PROGRAMS = kernel.img -# For kernel.elf. -kernel_elf_SOURCES = kern/i386/coreboot/startup.S \ +# For kernel.img. +kernel_img_SOURCES = kern/i386/coreboot/startup.S \ kern/i386/coreboot/init.c \ kern/i386/multiboot_mmap.c \ kern/main.c kern/device.c \
@@ -26,22 +26,22 @@ kern/env.c \ term/i386/pc/vga_text.c term/i386/vga_common.c \ symlist.c -kernel_elf_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ +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 loader.h misc.h mm.h net.h parser.h \ partition.h pc_partition.h reader.h symbol.h term.h time.h types.h \ machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h list.h handler.h command.h -kernel_elf_CFLAGS = $(COMMON_CFLAGS) -kernel_elf_ASFLAGS = $(COMMON_ASFLAGS) -kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x8200,-Bstatic +kernel_img_CFLAGS = $(COMMON_CFLAGS) +kernel_img_ASFLAGS = $(COMMON_ASFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x8200,-Bstatic MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst -symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh +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_elf_HEADERS)) config.h genkernsyms.sh +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) # Utilities.
powerpc-ieee1275.rmk +8 -8
@@ -13,20 +13,20 @@ MOSTLYCLEANFILES += symlist.c kernel_syms.lst DEFSYMFILES += kernel_syms.lst -kernel_elf_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ +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 powerpc/libgcc.h loader.h partition.h \ pc_partition.h ieee1275/ieee1275.h machine/kernel.h handler.h list.h \ command.h -symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh +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_elf_HEADERS)) config.h genkernsyms.sh +kernel_syms.lst: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h genkernsyms.sh /bin/sh genkernsyms.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1) # Programs -pkglib_PROGRAMS = kernel.elf +pkglib_PROGRAMS = kernel.img # Utilities. sbin_UTILITIES = grub-mkdevicemap
@@ -82,7 +82,7 @@ grub_emu_LDFLAGS = $(LIBCURSES) -kernel_elf_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \ +kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \ kern/ieee1275/ieee1275.c kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/err.c kern/file.c kern/fs.c \ kern/misc.c kern/mm.c kern/reader.c kern/term.c \
@@ -95,9 +95,9 @@ kern/parser.c kern/partition.c kern/env.c kern/powerpc/dl.c \ kern/generic/millisleep.c kern/time.c \ symlist.c kern/powerpc/cache.S -kernel_elf_CFLAGS = $(COMMON_CFLAGS) -kernel_elf_ASFLAGS = $(COMMON_ASFLAGS) -kernel_elf_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ +kernel_img_CFLAGS = $(COMMON_CFLAGS) +kernel_img_ASFLAGS = $(COMMON_ASFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) -static-libgcc -lgcc \ -Wl,-N,-S,-Ttext,0x200000,-Bstatic # Scripts.
elf/grub-mkimage.c +1 -1
@@ -193,7 +193,7 @@int i, phdr_size;/* Read ELF header. */ - kernel_path =grub_util_get_path (dir,"kernel.elf" ); + kernel_path =grub_util_get_path (dir,"kernel.img" ); in =fopen (kernel_path,"rb" );if (! in)grub_util_error ("cannot open %s" , kernel_path);
Re: [PATCH] move grub_stop() (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 4 lines · Pavel Roskin
Quoted 1 line · Robert Millan
Move
grub_stoptoinit.cto ease code sharing with i386-qemu.That's not quite a movement.
grub_cpu_idle()does nothing.
Well, the major problem with grub_cpu_idle() doing nothing on coreboot is CPU consumption during polls. grub_stop() is quite a corner case, only seen when you hit an error.
Quoted 4 lines
I think we need to have several implementations of
grub_stop: hard halt with interrupts disabled, exit from qemu, exit from other emulators if it's different, power off, exit to BIOS. Then different platforms should enable and try whatever is appropriate for them.
Note that we already have:
grub_stop: Just hang.
grub_exit: Exit to BIOS/whatever. On coreboot (and on i386-qemu) there's really no "proper" thing to do. Maybe fallback to grub_halt or grub_fatal.
grub_halt: Power off. Theoretically we can have it anywhere, although in some platforms like coreboot it's not easy; otherwise it can fallback to grub_stop.
I think grub_stop is intended to have this behaviour in all platforms. But I'm not sure how useful is it. Perhaps it could be ditched in favour of grub_exit?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 6 lines · Pavel Roskin
Quoted 3 lines
The result is you can do e.g.
$ sudo grub-mkrawimage at_keyboard normal etc -o /usr/share/qemu/grubPlease consider if we can call it grub-mkimage unless grub-mkimage would make sense as a separate executable for that platform.
Well, calling it grub-mkrawimage makes life a bit easier for packagers as it brings us closer to a situation in which two ports don't conflict with each other. In debian we already ship a single copy of grub-mkelfimage this way (grub-common package).
That said, in practice it isn't yet possible for two ports to coexist in the same system, so it doesn't bring much benefit in short term.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: does module area require alignment? (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 10 lines · Pavel Roskin
Quoted 4 lines · Robert Millan
Does anyone know why do we align ELF targets? When I did the coreboot port, the ELF part was based on existing Ieee1275 code, so I guess I just mimicked it. Is there some issue with non-i386 CPUs or with some Ieee1275 implementations that makes this alignment a requirement?
It was a hack for PowerPC openfirmware. I don't know why it was needed. I didn't have time and desire to debug openfirmware to find out what it wants.
Is the hack you're referring to GRUB_MOD_GAP, GRUB_MOD_ALIGN or both?
Btw, I suspect GRUB_MOD_GAP might be related to the modules overlapping with the BSS because of a firmware loader bug. Is there a correlation between the needed GRUB_MOD_GAP and the BSS size?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
PATCH 1/1 swap real_to_prot() and prot_to_real() (Re: [PATCH] i386-qemu port)
In reply to Robert MillanWhen doing the i386-coreboot port I made this choice completely backwards.
I thought real_to_prot() was only useful on i386-pc, because we needed it for returning from BIOS, and prot_to_real() was useful elsewhere, because the Linux loader would use it.
Turns out we need real_to_prot() on i386-qemu for the initial transition to i386 mode, AND we don't need prot_to_real() anywhere other than i386-pc, because OSes that expect to be loaded in i8086 mode are going to rely on BIOS calls.
So this patch swaps them. real_to_prot() goes to realmode.S and prot_to_real() back to startup.S.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-21 Robert Millan <[email protected]>
* kern/i386/pc/startup.S (real_to_prot): Move from here ...
* kern/i386/realmode.S (real_to_prot): ... to here.
* kern/i386/realmode.S (prot_to_real): Move from here ...
* kern/i386/pc/startup.S (prot_to_real): ... to here.
i386/pc/startup.S +47 -36
@@ -302,62 +302,73 @@ .p2align 2 /* force 4-byte alignment */ /* - * These next two routines, "real_to_prot" and "prot_to_real" are structured - * in a very specific way. Be very careful when changing them. + * This next routine, "prot_to_real" is structured in a very + * specific way. Be very careful when changing it. * - * NOTE: Use of either one messes up %eax and %ebp. + * NOTE: Use of it messes up %eax and %ebp. */ -real_to_prot: - .code16 - cli +prot_to_real: + /* just in case, set GDT */ + lgdt gdtdesc - /* load the GDT register */ -#ifdef APPLE_CC - mov %cs, %ax - mov %ax, %ds - DATA32 ADDR32 lgdt gdtdesc -#else - DATA32 ADDR32 lgdt %cs:gdtdesc -#endif + /* save the protected mode stack */ + movl %esp, %eax + movl %eax, protstack - /* turn on protected mode */ - movl %cr0, %eax - orl $GRUB_MEMORY_MACHINE_CR0_PE_ON, %eax - movl %eax, %cr0 + /* get the return address */ + movl (%esp), %eax + movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK - /* jump to relocation, flush prefetch queue, and reload %cs */ - DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg + /* set up new stack */ + movl $GRUB_MEMORY_MACHINE_REAL_STACK, %eax + movl %eax, %esp + movl %eax, %ebp - .code32 -protcseg: - /* reload other segment registers */ - movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax + /* set up segment limits */ + movw $GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax movw %ax, %ds movw %ax, %es movw %ax, %fs movw %ax, %gs movw %ax, %ss - /* put the return address in a known safe location */ - movl (%esp), %eax - movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK + /* this might be an extra step */ + /* jump to a 16 bit segment */ + ljmp $GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg - /* get protected mode stack */ - movl protstack, %eax - movl %eax, %esp - movl %eax, %ebp +tmpcseg: + .code16 - /* get return address onto the right stack */ - movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax - movl %eax, (%esp) + /* clear the PE bit of CR0 */ + movl %cr0, %eax + andl $(~GRUB_MEMORY_MACHINE_CR0_PE_ON), %eax + movl %eax, %cr0 + /* flush prefetch queue, reload %cs */ + DATA32 ljmp $0, $realcseg + +realcseg: + /* we are in real mode now + * set up the real mode segment registers : DS, SS, ES + */ /* zero %eax */ xorl %eax, %eax - /* return on the old (or initialized) stack! */ - ret + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + /* restore interrupts */ + sti + + /* return on new stack! */ + DATA32 ret + + .code32 + /* * grub_gate_a20(int on) *
i386/realmode.S +34 -44
103 lines not on this page · raw message
New patch, after a bunch of misc cleanup, turning hardcoded numbers into macros, improving comments, etc.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
i386-qemu.rmk +2 -0
@@ -0,0 +1,2 @@ +# -*- makefile -*- +include $(srcdir)/conf/i386-coreboot.mk
i386-coreboot.rmk +54 -9
86 lines not on this page · raw message
i386/qemu/startup.S +108 -0
108 lines not on this page · raw message
i386/qemu/mmap.c +71 -0
71 lines not on this page · raw message
i386/coreboot/startup.S +0 -8
@@ -78,14 +78,6 @@ jmp EXT_C(grub_main) /* - * This call is special... it never returns... in fact it should simply - * hang at this point! - */ -FUNCTION(grub_stop) - hlt - jmp EXT_C(grub_stop) - -/* * prot_to_real and associated structures (but NOT real_to_prot, that is * only needed for BIOS gates). */
i386/coreboot/init.c +13 -1
@@ -50,6 +50,17 @@grub_fatal ("grub_get_rtc() is not implemented.\n" ); } +/* +* This call is special... it never returns... in fact it should simply +* hang at this point! +*/ +void +grub_stop () +{ +while (1 ) + __asm__ ("hlt" ); +} +/* Stop the floppy drive from spinning, so that other software is jumped to with a known state. */ void
@@ -144,5 +155,6 @@grub_addr_t grub_arch_modules_addr (void ) { -return ALIGN_UP ((grub_addr_t ) _end,GRUB_MOD_ALIGN ); +// return ALIGN_UP((grub_addr_t) _end, GRUB_MOD_ALIGN); +return _end; }
i386/qemu/boot.S +113 -0
113 lines not on this page · raw message
configure.ac +1 -0
@@ -85,6 +85,7 @@ i386-coreboot) ;; i386-linuxbios) platform=coreboot ;; i386-ieee1275) ;; + i386-qemu) ;; powerpc-ieee1275) ;; sparc64-ieee1275) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
grub/i386/qemu/time.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/time.h>
grub/i386/qemu/serial.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/serial.h>
grub/i386/qemu/kernel.h +51 -0
51 lines not on this page · raw message
grub/i386/qemu/console.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/console.h>
grub/i386/qemu/boot.h +29 -0
@@ -0,0 +1,29 @@ +/* +* 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_BOOT_MACHINE_HEADER +#define GRUB_BOOT_MACHINE_HEADER 1 + +/* The size of boot.img. */ +#define GRUB_BOOT_MACHINE_SIZE 0x200 + +/* The offset of GRUB_CORE_ENTRY_ADDR. */ +#define GRUB_BOOT_MACHINE_CORE_ENTRY_ADDR 0x8 + + +#endif
grub/i386/qemu/init.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/init.h>
grub/i386/qemu/machine.h +24 -0
@@ -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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_MACHINE_MACHINE_HEADER +#define GRUB_MACHINE_MACHINE_HEADER 1 + +#define GRUB_MACHINE_QEMU 1 + +#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
grub/i386/qemu/loader.h +1 -0
@@ -0,0 +1 @@ +#include <grub/cpu/loader.h>
grub/i386/qemu/memory.h +45 -0
45 lines not on this page · raw message
grub/i386/coreboot/kernel.h +26 -3
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. +* 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
@@ -19,10 +19,33 @@#ifndef GRUB_KERNEL_MACHINE_HEADER #define GRUB_KERNEL_MACHINE_HEADER 1 +/* The offset of GRUB_TOTAL_MODULE_SIZE. */ +#define GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE 0x8 + +/* The offset of GRUB_KERNEL_IMAGE_SIZE. */ +#define GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE 0xc + +/* The offset of GRUB_PREFIX. */ +#define GRUB_KERNEL_MACHINE_PREFIX 0x10 + +/* End of the data section. */ +#define GRUB_KERNEL_MACHINE_DATA_END 0x50 + +#ifndef ASM_FILE +#include <grub/symbol.h> +#include <grub/types.h> -#ifndef ASM_FILE +/* The size of kernel image. */ +extern grub_int32_t grub_kernel_image_size; + +/* The total size of module images following the kernel. */ +extern grub_int32_t grub_total_module_size; + +/* The prefix which points to the directory where GRUB modules and its +configuration file are located. */ extern char grub_prefix[]; -#endif +#endif /* ! ASM_FILE */ +#endif /* ! GRUB_KERNEL_MACHINE_HEADER */
i386/pc/grub-mkimage.c +49 -0
80 lines not on this page · raw message
Quoted 9 lines · Pavel Roskin
Quoted 5 lines · Robert Millan
Hi,
I ported GRUB to QEMU. It's mostly based on the coreboot port, with the main difference being that we include code to transition from i8086 mode, an i386 firmware entry point and produce raw code images instead of ELF.
That's great news! Eventually, it would be nice to have support for many other platforms supported by qemu, such as arm and mips.
Sure! I hope it's going to be easier for arm and mips. For i386 GRUB had to jump between FOUR areas of code in memory before it can call grub_main()
(this is what happens after 30 years of backward compatibility kludges...)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 8 lines · Robert Millan
Quoted 4 lines · Pavel Roskin
Quoted 3 lines · Robert Millan
Hi,
I ported GRUB to QEMU. It's mostly based on the coreboot port, with
the
Quoted 1 line
Quoted 1 line
main difference being that we include code to transition from i8086
mode,
Quoted 9 lines
Quoted 1 line
Quoted 1 line
an i386 firmware entry point and produce raw code images instead of
ELF.
Quoted 3 lines
That's great news! Eventually, it would be nice to have support for many other platforms supported by qemu, such as arm and mips.
Sure! I hope it's going to be easier for arm and mips. For i386 GRUB had to jump between FOUR areas of code in memory before it can call
grub_main()
I'll try to do mips
Quoted 16 lines
(this is what happens after 30 years of backward compatibility kludges...)
--
Robert MillanThe DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
PATCH 1/1 access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Robert MillanIn this line of code in real_to_prot():
DATA32 ADDR32 lgdt %cs:gdtdesc
GAS generates an absolute address for `gdtdesc' (not relative to segment), and so for the code to work %cs must be zero. In current usage of real_to_prot(), %cs is always zero because we jump to 0x0:0x82xx early on.
However, in other situations this is not possible. On i386-qemu, before moving to i386 mode the code we're running is in the 0xf0000-0x100000 range, which is inaccessible from segment 0.
This patch changes this to access gdtdesc from segment 0 unconditionally.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-22 Robert Millan <[email protected]>
* kern/i386/pc/startup.S (real_to_prot): Access `gdtdesc' using segment 0x0 unconditionally, because the reference generated by GAS is an absolute address.
i386/pc/startup.S +4 -8
@@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,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
@@ -313,13 +313,9 @@ cli /* load the GDT register */ -#ifdef APPLE_CC - mov %cs, %ax - mov %ax, %ds - DATA32 ADDR32 lgdt gdtdesc -#else - DATA32 ADDR32 lgdt %cs:gdtdesc -#endif + xorw %ax, %ax + movw %ax, %ds + DATA32 ADDR32 lgdt %ds:gdtdesc /* turn on protected mode */ movl %cr0, %eax
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
Quoted 11 lines · Robert Millan
In this line of code in
real_to_prot():DATA32 ADDR32 lgdt %cs:gdtdesc
GAS generates an absolute address for `gdtdesc' (not relative to segment), and so for the code to work %cs must be zero. In current usage of
real_to_prot(), %cs is always zero because we jump to 0x0:0x82xx early on.However, in other situations this is not possible. On i386-qemu, before moving to i386 mode the code we're running is in the 0xf0000-0x100000 range, which is inaccessible from segment 0.
But gdtdesc should be next to the code we are running, since startup.S includes realmode.S where gdtdesc is defined, so they compile into one object file.
Since %cs is pointing to the code, it should be possible to point it to gdtdesc. They should be nearby.
Maybe you are trying to use a copy of gdtdesc in the beginning of memory? If GRUB serves as BIOS in i386-qemu, I'd rather use the "BIOS" value in the 0xF000 segment rather than the "RAM".
As for the APPLE_CC issue, I guess the Apple compiler doesn't understand the segment prefix at that position. The right fix would be to use ".byte" statements to create the same bytecode instead of introducing a different behavior to work around a compiler limitation.
Then I guess the Apple compiler won't accepted %ds: either, so if we want to use %ds, we should omit it.
Signature · 2 lines
Regards, Pavel Roskin
Quoted 2 lines · Robert Millan
New patch, after a bunch of misc cleanup, turning hardcoded numbers into macros, improving comments, etc.
kernel_img_FORMAT is defined but never used.
GRUB_MEMORY_MACHINE_LINK_ADDR doesn't need to be conditional, it's the same for coreboot and qemu.
Renaming kernel.elf to kernel.img could be done separately. Since it's a trivial patch, it can be committed without review provided that is compiles.
Please don't add trailing whitespace.
When compiling for coreboot, a warning appears:
/home/proski/src/grub2.git/kern/i386/coreboot/init.c: In function 'grub_arch_modules_addr':/home/proski/src/grub2.git/kern/i386/coreboot/init.c:159: warning:
return makes integer from pointer without a cast
Compilation for qemu fails when compiling in a separate directory:
/home/proski/src/grub2.git/boot/i386/qemu/boot.S:60:32: error:kern/i386/realmode.S: No such file or directory
The fix is to use relative path to include realmode.S:
#include "../../../kern/i386/realmode.S"
Here's my fix for compile warnings and errors. Please incorporate.
boot/i386/qemu/boot.S +1 -1
@@ -57,7 +57,7 @@ VARIABLE(grub_core_entry_addr) movl grub_core_entry_addr, %edx jmp *%edx -#include "kern/i386/realmode.S" +#include "../../../kern/i386/realmode.S" real_to_prot: .code16
kern/i386/coreboot/init.c +1 -1
@@ -156,5 +156,5 @@ grub_addr_tgrub_arch_modules_addr (void) {// return ALIGN_UP((grub_addr_t) _end, GRUB_MOD_ALIGN); -return _end; +return (grub_addr_t ) _end; }
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] swap real_to_prot() and prot_to_real() (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 6 lines · Robert Millan
When doing the i386-coreboot port I made this choice completely backwards.
I thought
real_to_prot()was only useful on i386-pc, because we needed it for returning from BIOS, andprot_to_real()was useful elsewhere, because the Linux loader would use it.
Quoted 7 lines
Turns out we need
real_to_prot()on i386-qemu for the initial transition to i386 mode, AND we don't needprot_to_real()anywhere other than i386-pc, because OSes that expect to be loaded in i8086 mode are going to rely on BIOS calls.So this patch swaps them.
real_to_prot()goes torealmode.Sandprot_to_real()back tostartup.S.
You have my approval as long as it compiles and doesn't introduce any warnings.
I'm attaching the script I'm using to test all platforms at once. The compiler path needs to be adjusted, as well as the target names, as they affect search for the target compiler. That's the version with qemu support. If every Log2make is empty, please go ahead.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] move grub_stop() (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 9 lines · Robert Millan
Quoted 4 lines · Pavel Roskin
Quoted 1 line · Robert Millan
Move
grub_stoptoinit.cto ease code sharing with i386-qemu.That's not quite a movement.
grub_cpu_idle()does nothing.Well, the major problem with
grub_cpu_idle()doing nothing on coreboot is CPU consumption during polls.grub_stop()is quite a corner case, only seen when you hit an error.
I think this should do the right thing if our goal is to stop:
cli
halt:
hlt
jmp halt
The last "jmp" is just in case for non-maskable interrupts.
Quoted 13 lines
Quoted 4 lines
I think we need to have several implementations of
grub_stop: hard halt with interrupts disabled, exit from qemu, exit from other emulators if it's different, power off, exit to BIOS. Then different platforms should enable and try whatever is appropriate for them.Note that we already have:
grub_stop: Just hang.
grub_exit: Exit to BIOS/whatever. On coreboot (and on i386-qemu) there's really no "proper" thing to do. Maybe fallback togrub_haltorgrub_fatal.
Quoted 7 lines
grub_halt: Power off. Theoretically we can have it anywhere, although in some platforms like coreboot it's not easy; otherwise it can fallback togrub_stop.I think
grub_stopis intended to have this behaviour in all platforms. But I'm not sure how useful is it. Perhaps it could be ditched in favour ofgrub_exit?
From the user's standpoint, I think three "stop-like" calls make sense:
Try to exit so that BIOS can try another media. Failing that, hang. That would be appropriate for installations on disks that may or may not be bootable. That's grub_exit().
Try for power down the system (that includes telling the emulator to stop). Failing that, hang. That would be appropriate for data centers where we don't want non-functioning systems to consume power. That's grub_halt().
Just stop. Appropriate if there is an important message on the screen that the user must see.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] rename kernel.elf to kernel.img (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 6 lines · Robert Millan
If you check my earlier patch, you'll see i386-qemu.rmk is just a stub that includes i386-coreboot.rmk. This is to reduce code duplication (untill we have a more flexible build system).
This patch renames kernel.elf to kernel.img in ELF platforms, so that more variables / etc can be shared with non-ELF ones.
No objections as long as it compiles without warnings. Sharing more code is a good thing.
By please note that I had to add kernel_elf_ASFLAGS in i386-ieee1275.rmk, or with would not compile on x86_64, as some compiler invocations would miss -m32. So you patch will need to be adjusted for that.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 13 lines · Pavel Roskin
Quoted 11 lines · Robert Millan
In this line of code in
real_to_prot():DATA32 ADDR32 lgdt %cs:gdtdesc
GAS generates an absolute address for `gdtdesc' (not relative to segment), and so for the code to work %cs must be zero. In current usage of
real_to_prot(), %cs is always zero because we jump to 0x0:0x82xx early on.However, in other situations this is not possible. On i386-qemu, before moving to i386 mode the code we're running is in the 0xf0000-0x100000 range, which is inaccessible from segment 0.
Quoted 6 lines
But gdtdesc should be next to the code we are running, since
startup.Sincludesrealmode.Swhere gdtdesc is defined, so they compile into one object file.Since %cs is pointing to the code, it should be possible to point it to gdtdesc. They should be nearby.
It is nearby, but the address reference for `gdtdesc' is absolute, NOT relative to %cs. Of course, when %cs is 0 that's no problem. But in my case I can't set %cs to 0 because my code is above 0x10000.
Quoted 7 lines
As for the
APPLE_CCissue, I guess the Apple compiler doesn't understand the segment prefix at that position. The right fix would be to use ".byte" statements to create the same bytecode instead of introducing a different behavior to work around a compiler limitation.Then I guess the Apple compiler won't accepted %ds: either, so if we want to use %ds, we should omit it.
Yes, this should work.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] move grub_stop() (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 11 lines · Pavel Roskin
Quoted 9 lines · Robert Millan
Quoted 4 lines · Pavel Roskin
Quoted 1 line · Robert Millan
Move
grub_stoptoinit.cto ease code sharing with i386-qemu.That's not quite a movement.
grub_cpu_idle()does nothing.Well, the major problem with
grub_cpu_idle()doing nothing on coreboot is CPU consumption during polls.grub_stop()is quite a corner case, only seen when you hit an error.
Quoted 8 lines
I think this should do the right thing if our goal is to stop:
cli
halt:
hlt
jmp haltThe last "jmp" is just in case for non-maskable interrupts.
My aim was to move this to C code so it can be shared between i386-qemu and i386-coreboot. However, this code will be the same on other i386 ports, but we don't yet have a generic .S file for i386 code.
How about kern/i386/misc.S ?
Quoted 20 lines
Quoted 10 lines
grub_stop: Just hang.
grub_exit: Exit to BIOS/whatever. On coreboot (and on i386-qemu) there's really no "proper" thing to do. Maybe fallback togrub_haltorgrub_fatal.
grub_halt: Power off. Theoretically we can have it anywhere, although in some platforms like coreboot it's not easy; otherwise it can fallback togrub_stop.Quoted 5 lines
I think
grub_stopis intended to have this behaviour in all platforms. But I'm not sure how useful is it. Perhaps it could be ditched in favour ofgrub_exit?From the user's standpoint, I think three "stop-like" calls make sense:
Try to exit so that BIOS can try another media. Failing that, hang. That would be appropriate for installations on disks that may or may not be bootable. That's
grub_exit().
Quoted 7 lines
Try for power down the system (that includes telling the emulator to stop). Failing that, hang. That would be appropriate for data centers where we don't want non-functioning systems to consume power. That's
grub_halt().Just stop. Appropriate if there is an important message on the screen that the user must see.
This seems to be the current behaviour, unless I missed something.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
about Apple compiler (Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port))
In reply to Pavel RoskinQuoted 3 lines · Pavel Roskin
Then I guess the Apple compiler won't accepted %ds: either, so if we want to use %ds, we should omit it.
Btw, it's Apple assembler that matters here. AFAIK their compiler is GCC.
I think those checks would need some adjustment, or it'll be a mess when we want to support GNU binutils on MacOS.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] rename kernel.elf to kernel.img (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 8 lines · Pavel Roskin
Quoted 6 lines · Robert Millan
If you check my earlier patch, you'll see i386-qemu.rmk is just a stub that includes i386-coreboot.rmk. This is to reduce code duplication (untill we have a more flexible build system).
This patch renames kernel.elf to kernel.img in ELF platforms, so that more variables / etc can be shared with non-ELF ones.
Quoted 7 lines
No objections as long as it compiles without warnings. Sharing more code is a good thing.
By please note that I had to add
kernel_elf_ASFLAGSin i386-ieee1275.rmk, or with would not compile onx86_64, as some compiler invocations would miss -m32. So you patch will need to be adjusted for that.
Updated, verified warning-free and committed.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] swap real_to_prot() and prot_to_real() (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 12 lines · Pavel Roskin
Quoted 11 lines · Robert Millan
When doing the i386-coreboot port I made this choice completely backwards.
I thought
real_to_prot()was only useful on i386-pc, because we needed it for returning from BIOS, andprot_to_real()was useful elsewhere, because the Linux loader would use it.Turns out we need
real_to_prot()on i386-qemu for the initial transition to i386 mode, AND we don't needprot_to_real()anywhere other than i386-pc, because OSes that expect to be loaded in i8086 mode are going to rely on BIOS calls.
Quoted 5 lines
Quoted 2 lines
So this patch swaps them.
real_to_prot()goes torealmode.Sandprot_to_real()back tostartup.S.You have my approval as long as it compiles and doesn't introduce any warnings.
Done, no warnings. I decided to keep prot_to_real() in its current place though. It's probably going to be useful when we support processing ROMs in i386-coreboot (e.g. for biosdisk or vbe).
Quoted 4 lines
I'm attaching the script I'm using to test all platforms at once. The compiler path needs to be adjusted, as well as the target names, as they affect search for the target compiler. That's the version with qemu support. If every Log2make is empty, please go ahead.
Thanks. Btw, maybe you find this useful:
-MAKE_JOBS=8
+MAKE_JOBS=getconf _NPROCESSORS_ONLN || echo 1
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Robert Millan
AppliedQuoted 5 lines · Pavel Roskin
Quoted 2 lines · Robert Millan
New patch, after a bunch of misc cleanup, turning hardcoded numbers into macros, improving comments, etc.
kernel_img_FORMATis defined but never used.
It's used by the build system, see:
genmk.rb: $(OBJCOPY) -O $(#{prefix}_FORMAT) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id $< $@
Quoted 2 lines
GRUB_MEMORY_MACHINE_LINK_ADDRdoesn't need to be conditional, it's the same for coreboot and qemu.
Ok.
Quoted 3 lines
Renaming kernel.elf to kernel.img could be done separately. Since it's a trivial patch, it can be committed without review provided that is compiles.
Committed already.
Quoted 1 line
Please don't add trailing whitespace.
Fixed.
Quoted 1 line
Here's my fix for compile warnings and errors. Please incorporate.
Merged, thanks.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
PATCH 1/1 define GRUB_MOD_ALIGN to 0 on non-ieee1275 (Re: does module area require alignment? (Re: [PATCH] i386-qemu port))
In reply to Robert MillanWell it seems that OLPC (i386-ieee1275) needs alignment, but coreboot doesn't. It must be some OFW-specific oddity.
This patch makes the alignment ieee1275-specific on i386.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
i386/coreboot/init.c +1 -1
@@ -144,5 +144,5 @@ grub_machine_fini (void)grub_addr_t grub_arch_modules_addr (void ) { -return ALIGN_UP ((grub_addr_t ) _end,GRUB_MOD_ALIGN ); +return (grub_addr_t ) _end; }
grub/i386/kernel.h +8 -2
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc. +* 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
@@ -19,7 +19,13 @@#ifndef GRUB_KERNEL_CPU_HEADER #define GRUB_KERNEL_CPU_HEADER 1 -#define GRUB_MOD_ALIGN 0x1000 +#include <grub/machine/machine.h> + +#ifdef GRUB_MACHINE_IEEE1275 +#define GRUB_MOD_ALIGN 0x1000 +#else +#define GRUB_MOD_ALIGN 0 +#endif /* Non-zero value is only needed for PowerMacs. */ #define GRUB_MOD_GAP 0x0
Quoted 8 lines · Robert Millan
Quoted 6 lines · Pavel Roskin
Quoted 3 lines
The result is you can do e.g.
$ sudo grub-mkrawimage at_keyboard normal etc -o /usr/share/qemu/grubPlease consider if we can call it grub-mkimage unless grub-mkimage would make sense as a separate executable for that platform.
Quoted 7 lines
Well, calling it grub-mkrawimage makes life a bit easier for packagers as it brings us closer to a situation in which two ports don't conflict with each other. In debian we already ship a single copy of grub-mkelfimage this way (grub-common package).
That said, in practice it isn't yet possible for two ports to coexist in the same system, so it doesn't bring much benefit in short term.
I'll just make it grub-mkimage for now. We can always discuss about a rename later on.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
PATCH 1/1 s/GRUB_MEMORY_MACHINE_LINK_ADDR/GRUB_KERNEL_MACHINE_LINK_ADDR/g (Re: [PATCH] i386-qemu port)
In reply to Robert MillanMy latest qemu patch removes the redundancy between boot.img link address and GRUB_BOOT_MACHINE_SIZE. This requires two macros for distinguishing between kernel & boot link addresses:
GRUB_BOOT_MACHINE_LINK_ADDR = 0xffe00
GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200
whereas the existing GRUB_MEMORY_MACHINE_LINK_ADDR becomes ambigous. This patch discards it in favour of GRUB_KERNEL_MACHINE_LINK_ADDR (the i386-pc bits need to be modified, since they share grub-mkimage code).
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-22 Robert Millan <[email protected]>
* conf/i386-pc.rmk (GRUB_MEMORY_MACHINE_LINK_ADDR): Rename to ... (GRUB_KERNEL_MACHINE_LINK_ADDR): ... this. Update all users.
i386-pc.rmk +3 -3
@@ -1,6 +1,6 @@ # -*- makefile -*- -GRUB_MEMORY_MACHINE_LINK_ADDR = 0x8200 +GRUB_KERNEL_MACHINE_LINK_ADDR = 0x8200 COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32
@@ -67,7 +67,7 @@ machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) -kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) +kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS) kernel_img_FORMAT = binary MOSTLYCLEANFILES += symlist.c kernel_syms.lst
@@ -95,7 +95,7 @@ grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \ util/resolve.c lib/LzmaEnc.c lib/LzFind.c endif -grub_mkimage_CFLAGS = -DGRUB_MEMORY_MACHINE_LINK_ADDR=$(GRUB_MEMORY_MACHINE_LINK_ADDR) +grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) util/i386/pc/grub-mkimage.c_DEPENDENCIES = Makefile # For grub-setup.
i386/pc/grub-mkimage.c +2 -2
@@ -270,9 +270,9 @@ = grub_cpu_to_le32 (-2); } -if (GRUB_MEMORY_MACHINE_LINK_ADDR + core_size >GRUB_MEMORY_MACHINE_UPPER ) +if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size >GRUB_MEMORY_MACHINE_UPPER )grub_util_error ("Core image is too big (%p > %p)\n" , -GRUB_MEMORY_MACHINE_LINK_ADDR + core_size,GRUB_MEMORY_MACHINE_UPPER ); +GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,GRUB_MEMORY_MACHINE_UPPER );grub_util_write_image (core_img, core_size, out);free (kernel_img);
Re: about Apple compiler (Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port))
In reply to Robert MillanQuoted 9 lines · Robert Millan
Quoted 3 lines · Pavel Roskin
Then I guess the Apple compiler won't accepted %ds: either, so if we want to use %ds, we should omit it.
Btw, it's Apple assembler that matters here. AFAIK their compiler is GCC.
I think those checks would need some adjustment, or it'll be a mess when we want to support GNU binutils on MacOS.
In most cases, we just want to leave the APPLE_CC version, as it's more portable. But we should verify that the same bytecode is generated, just to be safe.
In many cases, I'd like to see if there is a simpler workaround. Unfortunately, I don't have access to the Apple compiler.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] move grub_stop() (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 5 lines · Robert Millan
My aim was to move this to C code so it can be shared between i386-qemu and i386-coreboot. However, this code will be the same on other i386 ports, but we don't yet have a generic .S file for i386 code.
How about
kern/i386/misc.S?
Fine with me. We shouldn't switch to inferior C code just because we don't have a shared .S file.
Quoted 1 line
This seems to be the current behaviour, unless I missed something.
OK, never mind. I should have done that analysis before bringing up the issue.
Anyway, I think grub_halt() should be renamed to grub_poweroff() to be more explicit about its goal.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] move grub_stop() (Re: [PATCH] i386-qemu port)
Quoted 10 lines · Pavel Roskin
Quoted 5 lines · Robert Millan
My aim was to move this to C code so it can be shared between i386-qemu and i386-coreboot. However, this code will be the same on other i386 ports, but we don't yet have a generic .S file for i386 code.
How about
kern/i386/misc.S?Fine with me. We shouldn't switch to inferior C code just because we don't have a shared .S file.
Agreed. I just replaced the 3 instances we had of grub_stop() with a single one in kern/i386/misc.S.
Quoted 2 lines
Anyway, I think
grub_halt()should be renamed togrub_poweroff()to be more explicit about its goal.
Fine with me.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] s/GRUB_MEMORY_MACHINE_LINK_ADDR/GRUB_KERNEL_MACHINE_LINK_ADDR/g (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 10 lines · Robert Millan
My latest qemu patch removes the redundancy between boot.img link address and
GRUB_BOOT_MACHINE_SIZE. This requires two macros for distinguishing between kernel & boot link addresses:
GRUB_BOOT_MACHINE_LINK_ADDR=0xffe00
GRUB_KERNEL_MACHINE_LINK_ADDR=0x8200whereas the existing
GRUB_MEMORY_MACHINE_LINK_ADDRbecomes ambigous. This patch discards it in favour ofGRUB_KERNEL_MACHINE_LINK_ADDR(the i386-pc bits need to be modified, since they share grub-mkimage code).
Fine with me.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 6 lines · Robert Millan
Quoted 2 lines
Since %cs is pointing to the code, it should be possible to point it to gdtdesc. They should be nearby.
It is nearby, but the address reference for `gdtdesc' is absolute, NOT relative to %cs. Of course, when %cs is 0 that's no problem. But in my case I can't set %cs to 0 because my code is above
0x10000.
I think we can remove ADDR32 from the command. I tried that on i386-pc and it works in qemu and on real hardware. I don't see any need to use a 32-bit address in the lgdt command.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] define GRUB_MOD_ALIGN to 0 on non-ieee1275 (Re: does module area require alignment? (Re: [PATCH] i386-qemu port))
In reply to Robert MillanQuoted 4 lines · Robert Millan
Well it seems that OLPC (i386-ieee1275) needs alignment, but coreboot doesn't. It must be some OFW-specific oddity.
This patch makes the alignment ieee1275-specific on i386.
We can define GRUB_MOD_ALIGN to 1 for such architectures and keep using ALIGN_UP (or remove ALIGN_UP - it doesn't matter). The value of 0 for GRUB_MOD_ALIGN is meaningless, but the value of 1 has a meaning - align to a byte boundary.
Signature · 2 lines
Regards, Pavel Roskin
Re: does module area require alignment? (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 8 lines · Robert Millan
Quoted 7 lines · Pavel Roskin
Quoted 4 lines · Robert Millan
Does anyone know why do we align ELF targets? When I did the coreboot port, the ELF part was based on existing Ieee1275 code, so I guess I just mimicked it. Is there some issue with non-i386 CPUs or with some Ieee1275 implementations that makes this alignment a requirement?
Quoted 5 lines
Quoted 3 lines
It was a hack for PowerPC openfirmware. I don't know why it was needed. I didn't have time and desire to debug openfirmware to find out what it wants.
Is the hack you're referring to
GRUB_MOD_GAP,GRUB_MOD_ALIGNor both?
I'm referring to GRUB_MOD_GAP.
Quoted 3 lines
Btw, I suspect
GRUB_MOD_GAPmight be related to the modules overlapping with the BSS because of a firmware loader bug. Is there a correlation between the neededGRUB_MOD_GAPand the BSS size?
I don't see any correlation.
I made 3 images with the gap of 0x4000, 0x8000 and 0xc000. Then I added an uninitialized array to the kernel, 0x4000 bytes long, and made another 3 images with the same gap sizes. The images with the 0x4000 gap don't boot and the images with the gap sized 0x8000 and 0xc000 boot regardless of the array.
That's PowerMac G3 "Blue and White".
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] define GRUB_MOD_ALIGN to 0 on non-ieee1275 (Re: does module area require alignment? (Re: [PATCH] i386-qemu port))
In reply to Pavel RoskinQuoted 10 lines · Pavel Roskin
Quoted 4 lines · Robert Millan
Well it seems that OLPC (i386-ieee1275) needs alignment, but coreboot doesn't. It must be some OFW-specific oddity.
This patch makes the alignment ieee1275-specific on i386.
We can define
GRUB_MOD_ALIGNto 1 for such architectures and keep usingALIGN_UP(or removeALIGN_UP- it doesn't matter). The value of 0 forGRUB_MOD_ALIGNis meaningless, but the value of 1 has a meaning - align to a byte boundary.
Good idea, I just did that. I didn't remove ALIGN_UP, since it's harmless.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] define GRUB_MOD_ALIGN to 0 on non-ieee1275 (Re: does module area require alignment? (Re: [PATCH] i386-qemu port))
Quoted 5 lines · Robert Millan
Quoted 4 lines · Pavel Roskin
Quoted 3 lines · Robert Millan
Well it seems that OLPC (i386-ieee1275) needs alignment, but coreboot doesn't. It must be some OFW-specific oddity.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
This patch makes the alignment ieee1275-specific on i386.
We can define
GRUB_MOD_ALIGNto 1 for such architectures and keep usingALIGN_UP(or removeALIGN_UP- it doesn't matter). The value of 0 forGRUB_MOD_ALIGNis meaningless, but the value of 1 has a meaning - align to a byte boundary.Good idea, I just did that. I didn't remove
ALIGN_UP, since it's harmless.
By the way, it turns out that PowerPC needs alignment of 4 bytes. That would allow me to find the exact minimal gap and see if it's influenced by anything. The gap is between 0x8c50 and 0x8c60.
You may want to use 4 byte alignment too. It's a good thing to align 32-bit addresses in the ELF headers.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 11 lines · Pavel Roskin
Quoted 6 lines · Robert Millan
Quoted 2 lines
Since %cs is pointing to the code, it should be possible to point it to gdtdesc. They should be nearby.
It is nearby, but the address reference for `gdtdesc' is absolute, NOT relative to %cs. Of course, when %cs is 0 that's no problem. But in my case I can't set %cs to 0 because my code is above
0x10000.I think we can remove ADDR32 from the command. I tried that on i386-pc and it works in qemu and on real hardware. I don't see any need to use a 32-bit address in the lgdt command.
This won't build. I don't think it's possible to use relative addresses with this particular instruction. "DATA32 lgdt %cs:gdtdesc" results in:
boot_img-boot_i386_qemu_boot.o: In function `real_to_prot':
(.text+0x64): relocation truncated to fit: R_386_16 against `.text'
What's the problem with removing %cs? It's presence there is bogus. It *seems* to indicate gdtdesc is a segment-relative reference, but in fact it's not, and it just happens to work because %cs was set to 0.
Note: "ADDR32 lgdt %cs:gdtdesc" builds, but generates an absolute address too.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] define GRUB_MOD_ALIGN to 0 on non-ieee1275 (Re: does module area require alignment? (Re: [PATCH] i386-qemu port))
In reply to Pavel RoskinQuoted 3 lines · Pavel Roskin
You may want to use 4 byte alignment too. It's a good thing to align 32-bit addresses in the ELF headers.
Ok, but we aren't doing it on i386-pc, and this never caused trouble. The ELF headers in our modules are only loaded by GRUB itself, and if our loader can cope with unaligned addresses, why bother trying to align them?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 2 lines · Robert Millan
I don't think it's possible to use relative addresses with this particular instruction.
Uhm sorry, this was silly. Of course you can use addresses relative to a segment in lgdt, but this doesn't change the fact that GAS always gives you absolute ones.
Also, I'm not sure if it's possible to use a 16-bit field in this instruction, it could be that the field is always 32-bit, even if it's relative to a segment. This dump is from the i386-pc kernel.img:
836f: 2e 67 66 0f 01 15 68 addr32 lgdtl %cs:0x8368
8376: 83 00 00 a little-endian 0x00008368 is seen here, indicating the field is 32-bit.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 13 lines · Robert Millan
Quoted 11 lines · Pavel Roskin
Quoted 6 lines · Robert Millan
Quoted 2 lines
Since %cs is pointing to the code, it should be possible to point it to gdtdesc. They should be nearby.
It is nearby, but the address reference for `gdtdesc' is absolute, NOT relative to %cs. Of course, when %cs is 0 that's no problem. But in my case I can't set %cs to 0 because my code is above
0x10000.I think we can remove ADDR32 from the command. I tried that on i386-pc and it works in qemu and on real hardware. I don't see any need to use a 32-bit address in the lgdt command.
Quoted 5 lines
This won't build. I don't think it's possible to use relative addresses with this particular instruction. "DATA32 lgdt %cs:gdtdesc" results in:
boot_img-boot_i386_qemu_boot.o: In function `real_to_prot':
(.text+0x64): relocation truncated to fit:R_386_16against `.text'
My bad, I only checked it for i386-pc. I see this error for ieee1275-i386.
I believe it happens because we relocate the output too high in memory, so we cannot relocate a 16-bit address there.
Quoted 3 lines
What's the problem with removing %cs? It's presence there is bogus. It *seems* to indicate gdtdesc is a segment-relative reference, but in fact it's not, and it just happens to work because %cs was set to 0.
I just wanted to make sure we are not doing anything wrong. I have a feeling that somebody with a good knowledge of assembler tricks could write the code to use %cs and a 16-bit address, but I don't know how to do it.
Anyway, your code is correct and I have no objections. Please commit.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 8 lines · Robert Millan
Quoted 2 lines · Robert Millan
I don't think it's possible to use relative addresses with this particular instruction.
Uhm sorry, this was silly. Of course you can use addresses relative to a segment in lgdt, but this doesn't change the fact that GAS always gives you absolute ones.
Quoted 8 lines
Also, I'm not sure if it's possible to use a 16-bit field in this instruction, it could be that the field is always 32-bit, even if it's relative to a segment. This dump is from the i386-pc kernel.img:
836f: 2e 67 66 0f 01 15 68 addr32 lgdtl %cs:0x8368 8376: 83 00 00a little-endian
0x00008368is seen here, indicating the field is 32-bit.
But if I omit ADDR32, I get:
0000016e <real_to_prot>:
16e: fa cli 16f: 2e 66 0f 01 16 68 01 lgdtl %cs:0x168 176: 0f 20 c0 mov %cr0,%eax
The address is 16-bit.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] define GRUB_MOD_ALIGN to 0 on non-ieee1275 (Re: does module area require alignment? (Re: [PATCH] i386-qemu port))
In reply to Robert MillanQuoted 9 lines · Robert Millan
Quoted 3 lines · Pavel Roskin
You may want to use 4 byte alignment too. It's a good thing to align 32-bit addresses in the ELF headers.
Ok, but we aren't doing it on i386-pc, and this never caused trouble. The ELF headers in our modules are only loaded by GRUB itself, and if our loader can cope with unaligned addresses, why bother trying to align them?
Maybe to speed up things. But I don't really care.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] define GRUB_MOD_ALIGN to 0 on non-ieee1275 (Re: does module area require alignment? (Re: [PATCH] i386-qemu port))
Quoted 6 lines · Pavel Roskin
Quoted 5 lines · Robert Millan
Quoted 3 lines · Pavel Roskin
You may want to use 4 byte alignment too. It's a good thing to align 32-bit addresses in the ELF headers.
Quoted 6 lines
Quoted 4 lines
Ok, but we aren't doing it on i386-pc, and this never caused trouble. The ELF headers in our modules are only loaded by GRUB itself, and if our loader can cope with unaligned addresses, why bother trying to align them?
Maybe to speed up things. But I don't really care.
Well, if there's interest in doing this, I would suggest finding a platform-independant way. For example the modinfo structure could remain unaligned, with padding in-between its ELF modules or so.
If there's a speed improvement I'm fine with it. But I can sleep at night without alignment :-)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 18 lines · Pavel Roskin
Quoted 8 lines · Robert Millan
Quoted 2 lines · Robert Millan
I don't think it's possible to use relative addresses with this particular instruction.
Uhm sorry, this was silly. Of course you can use addresses relative to a segment in lgdt, but this doesn't change the fact that GAS always gives you absolute ones.
Quoted 8 lines
Also, I'm not sure if it's possible to use a 16-bit field in this instruction, it could be that the field is always 32-bit, even if it's relative to a segment. This dump is from the i386-pc kernel.img:
836f: 2e 67 66 0f 01 15 68 addr32 lgdtl %cs:0x8368 8376: 83 00 00a little-endian
0x00008368is seen here, indicating the field is 32-bit.
Quoted 8 lines
But if I omit ADDR32, I get:
0000016e<real_to_prot>:16e: fa cli 16f: 2e 66 0f 01 16 68 01 lgdtl %cs:0x168 176: 0f 20 c0 mov %cr0,%eaxThe address is 16-bit.
If I omit ADDR32 on i386-pc, I get:
836f: 2e 66 0f 01 16 68 83 lgdtl %cs:-0x7c98
"-0x7c98" being the signed version of 0x8368, which is also 16-bit. What is really odd is that you got 0x168 which is an offset to 0x8200, when in fact %cs is 0, so I don't think your binary would work (did you test it?).
Btw my binutils version is 2.18.0.20080103.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: does module area require alignment? (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 25 lines · Pavel Roskin
Quoted 4 lines · Robert Millan
Quoted 3 lines · Pavel Roskin
Quoted 1 line · Robert Millan
Does anyone know why do we align ELF targets? When I did the
coreboot port,
Quoted 1 line
Quoted 1 line
Quoted 1 line
the ELF part was based on existing Ieee1275 code, so I guess I just
mimicked
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
it. Is there some issue with non-i386 CPUs or with some Ieee1275 implementations that makes this alignment a requirement?
It was a hack for PowerPC openfirmware. I don't know why it was
needed.
Quoted 4 lines
Quoted 2 lines
I didn't have time and desire to debug openfirmware to find out what it wants.
Is the hack you're referring to
GRUB_MOD_GAP,GRUB_MOD_ALIGNor both?I'm referring to
GRUB_MOD_GAP.Quoted 1 line
Btw, I suspect
GRUB_MOD_GAPmight be related to the modules overlappingwith
Quoted 2 lines
the BSS because of a firmware loader bug. Is there a correlation between the needed
GRUB_MOD_GAPand the BSS size?
Quoted 7 lines
I don't see any correlation.
I made 3 images with the gap of
0x4000,0x8000and0xc000. Then I added an uninitialized array to the kernel,0x4000bytes long, and made another 3 images with the same gap sizes. The images with the0x4000gap don't boot and the images with the gap sized0x8000and0xc000boot regardless of the array.
Stupid question but have you ensured/checked that this array isn't optimized out?
Quoted 14 lines
That's PowerMac G3 "Blue and White".
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 8 lines · Pavel Roskin
Quoted 3 lines
What's the problem with removing %cs? It's presence there is bogus. It *seems* to indicate gdtdesc is a segment-relative reference, but in fact it's not, and it just happens to work because %cs was set to 0.
I just wanted to make sure we are not doing anything wrong. I have a feeling that somebody with a good knowledge of assembler tricks could write the code to use %cs and a 16-bit address, but I don't know how to do it.
We *could* convert the absolute reference generated by binutils into something relative to %cs with a combination of macros (so realmode.S knows what's the %cs value going to be), substract _start, bitshift, etc.
But in that case I really think the added complexity makes it unworthy.
Quoted 1 line
Anyway, your code is correct and I have no objections. Please commit.
Committed. Feel free to get rid of ADDR32 if you figure out a clean way to do it :-)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
clean patch for i386-qemu port (Re: [PATCH] i386-qemu port)
In reply to Robert MillanThis is my first "clean" (kludge-free) patch for the i386-qemu port. It doesn't depend on any other patch; I send it for some final review before checking it in.
Comments?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-23 Robert Millan <[email protected]>
* conf/i386-qemu.rmk: New file.
* kern/i386/qemu/startup.S: Likewise.
* kern/i386/qemu/mmap.c: Likewise.
* boot/i386/qemu/boot.S: Likewise.
* include/grub/i386/qemu/time.h: Likewise.
* include/grub/i386/qemu/serial.h: Likewise.
* include/grub/i386/qemu/kernel.h: Likewise.
* include/grub/i386/qemu/console.h: Likewise.
* include/grub/i386/qemu/boot.h: Likewise.
* include/grub/i386/qemu/init.h: Likewise.
* include/grub/i386/qemu/machine.h: Likewise.
* include/grub/i386/qemu/loader.h: Likewise.
* include/grub/i386/qemu/memory.h: Likewise.
* conf/i386-coreboot.rmk (GRUB_BOOT_MACHINE_LINK_ADDR) (GRUB_KERNEL_MACHINE_LINK_ADDR): New variables.
[qemu] (pkglib_IMAGES): Add `boot.img'.
[qemu] (boot_img_SOURCES, boot_img_ASFLAGS, boot_img_LDFLAGS) [qemu] (boot_img_FORMAT): New variables.
[qemu] (bin_UTILITIES): Add `grub-mkimage'.
[qemu] (grub_mkimage_SOURCES, grub_mkimage_CFLAGS): New variables. [qemu] (kernel_img_SOURCES, kernel_img_HEADERS, kernel_img_CFLAGS) [qemu] (kernel_img_ASFLAGS, kernel_img_LDFLAGS)
[qemu] (kernel_img_FORMAT): New variables.
* configure.ac: Recognise `i386-qemu'.
* util/i386/pc/grub-mkimage.c (compress_kernel): Add dummy variant (for no compression).
[GRUB_MACHINE_QEMU] (generate_image): Misc adjustments to produce a valid i386 ROM image. Make GRUB_KERNEL_MACHINE_COMPRESSED_SIZE', GRUB_KERNEL_MACHINE_INSTALL_DOS_PART' and `GRUB_KERNEL_MACHINE_INSTALL_BSD_PART' optional features (with ifdefs).
i386-qemu.rmk +2 -0
@@ -0,0 +1,2 @@ +# -*- makefile -*- +include $(srcdir)/conf/i386-coreboot.mk
i386-coreboot.rmk +49 -3
71 lines not on this page · raw message
i386/qemu/startup.S +108 -0
108 lines not on this page · raw message
i386/qemu/mmap.c +71 -0
71 lines not on this page · raw message
i386/qemu/boot.S +67 -0
67 lines not on this page · raw message
configure.ac +1 -0
@@ -85,6 +85,7 @@ i386-coreboot) ;; i386-linuxbios) platform=coreboot ;; i386-ieee1275) ;; + i386-qemu) ;; powerpc-ieee1275) ;; sparc64-ieee1275) ;; *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
grub/i386/qemu/time.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/time.h>
grub/i386/qemu/serial.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/serial.h>
grub/i386/qemu/kernel.h +51 -0
51 lines not on this page · raw message
grub/i386/qemu/console.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/console.h>
grub/i386/qemu/boot.h +28 -0
@@ -0,0 +1,28 @@ +/* +* 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_BOOT_MACHINE_HEADER +#define GRUB_BOOT_MACHINE_HEADER 1 + +/* The size of boot.img. */ +#define GRUB_BOOT_MACHINE_SIZE (0x100000 - GRUB_BOOT_MACHINE_LINK_ADDR) + +/* The offset of GRUB_CORE_ENTRY_ADDR. */ +#define GRUB_BOOT_MACHINE_CORE_ENTRY_ADDR 0x4 + +#endif
grub/i386/qemu/init.h +1 -0
@@ -0,0 +1 @@ +#include <grub/i386/coreboot/init.h>
grub/i386/qemu/machine.h +24 -0
@@ -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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_MACHINE_MACHINE_HEADER +#define GRUB_MACHINE_MACHINE_HEADER 1 + +#define GRUB_MACHINE_QEMU 1 + +#endif /* ! GRUB_MACHINE_MACHINE_HEADER */
grub/i386/qemu/loader.h +1 -0
@@ -0,0 +1 @@ +#include <grub/cpu/loader.h>
grub/i386/qemu/memory.h +45 -0
45 lines not on this page · raw message
i386/pc/grub-mkimage.c +50 -0
81 lines not on this page · raw message
Re: does module area require alignment? (Re: [PATCH] i386-qemu port)
In reply to Vladimir 'phcoder' SerbinenkoQuoted 11 lines · Vladimir 'phcoder' Serbinenko
I made 3 images with the gap of 0x4000, 0x8000 and 0xc000. Then I added an uninitialized array to the kernel, 0x4000 bytes long, and made another 3 images with the same gap sizes. The images with the 0x4000 gap don't boot and the images with the gap sized 0x8000 and 0xc000 boot regardless of the array.Stupid question but have you ensured/checked that this array isn't optimized out?
Yes, I checked that.
It turns out that small variables to to the .sbss section and reduce the minimal gap side (0x8c50 and 0x8c54 are OK). But larger arrays go to the .bss section and don't change the gap (0x8c50 is bad, 0x8c54 is OK).
Maybe OpenFirmware is confused by the .sbss section. I'll try a linker script to merge .sbss into the .bss section.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 7 lines · Robert Millan
If I omit ADDR32 on i386-pc, I get:
836f: 2e 66 0f 01 16 68 83 lgdtl %cs:-0x7c98"-0x7c98" being the signed version of
0x8368, which is also 16-bit. What is really odd is that you got0x168which is an offset to0x8200, when in fact %cs is 0, so I don't think your binary would work (did you test it?).
That's because you are disassembling the linked image after relocation and I'm disassembling the object file.
Signature · 2 lines
Regards, Pavel Roskin
Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port)
In reply to Robert MillanQuoted 3 lines · Robert Millan
This is my first "clean" (kludge-free) patch for the i386-qemu port. It doesn't depend on any other patch; I send it for some final review before checking it in.
In some cases, "2" appears on the command line. Perhaps the initial keyboard state is not cleared.
If I use all modules, the image is too big:
grub-mkimage: error: Core image is too big (0xa8200 > 0xa0000)
If I exclude lua.mod, I can build the image, but it fails in qemu with the message "no module name found". Removing udf.mod helps. Likewise, removing several other modules helps. I believe memory is corrupted if there are too many modules.
Also, if "no module name found" appears, it's followed by:
Aborted. Press any key to exit.grub_exit() is not implemented.
And it appears on the new line every time a key is pressed. I believe grub_exit() should call grub_halt() for i386-coreboot and i386-qemu.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] access gdtdesc on segment 0 unconditionally (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 4 lines · Pavel Roskin
Quoted 2 lines · Robert Millan
If I omit ADDR32 on i386-pc, I get:
Quoted 8 lines
Quoted 5 lines
836f: 2e 66 0f 01 16 68 83 lgdtl %cs:-0x7c98"-0x7c98" being the signed version of
0x8368, which is also 16-bit. What is really odd is that you got0x168which is an offset to0x8200, when in fact %cs is 0, so I don't think your binary would work (did you test it?).That's because you are disassembling the linked image after relocation and I'm disassembling the object file.
But it's the linked image that will be executed. The object file is only for ld consumption (and it doesn't contain any absolute addresses, even for instructions that require them, because link address has not yet been specified).
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port)
In reply to Pavel RoskinQuoted 7 lines · Pavel Roskin
Quoted 3 lines · Robert Millan
This is my first "clean" (kludge-free) patch for the i386-qemu port. It doesn't depend on any other patch; I send it for some final review before checking it in.
In some cases, "2" appears on the command line. Perhaps the initial keyboard state is not cleared.
I can't reproduce this, but we can flush the keyboard on startup. Do you mind if we discuss this after base qemu support is merged?
Quoted 2 lines
If I use all modules, the image is too big:
grub-mkimage: error: Core image is too big (0xa8200>0xa0000)
Strange, with all modules I get 0x88200. Anyway, GRUB_MEMORY_MACHINE_UPPER can be increased up to GRUB_BOOT_MACHINE_LINK_ADDR, this was just copied from the coreboot port.
With GRUB_BOOT_MACHINE_LINK_ADDR (0xffe00) you should be able to fit all of GRUB in.
Increasing it further would involve either compression or breaking the 0x100000 barrier (imposed by the Linux loader). I think compression for qemu is just silly, but fixing the Linux loader is not trivial (Vladimir's memory management proposal could help on this).
Quoted 4 lines
If I exclude lua.mod, I can build the image, but it fails in qemu with the message "no module name found". Removing udf.mod helps. Likewise, removing several other modules helps. I believe memory is corrupted if there are too many modules.
I get memory corruption too. I'll have a look.
Quoted 2 lines
And it appears on the new line every time a key is pressed. I believe
grub_exit()should callgrub_halt()for i386-coreboot and i386-qemu.
Is grub_halt() really what we want? grub_exit() callers expect that the user doesn't lose access to the machine when this function is invoked.
How about grub_reboot() instead?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port)
Quoted 7 lines · Robert Millan
Quoted 2 lines
If I use all modules, the image is too big:
grub-mkimage: error: Core image is too big (0xa8200>0xa0000)Strange, with all modules I get
0x88200. Anyway,GRUB_MEMORY_MACHINE_UPPERcan be increased up toGRUB_BOOT_MACHINE_LINK_ADDR, this was just copied from the coreboot port.
Quoted 7 lines
With
GRUB_BOOT_MACHINE_LINK_ADDR(0xffe00) you should be able to fit all of GRUB in.Increasing it further would involve either compression or breaking the
0x100000barrier (imposed by the Linux loader). I think compression for qemu is just silly, but fixing the Linux loader is not trivial (Vladimir's memory management proposal could help on this).
Actually, you can't step after 0xa0000 because there are I/O maps there (there's 0xb8000 and I think other VGA stuff).
I think I'll just change the link address to 0x100000. Then our limit is almost 2 GiB, which gives plenty of room for a big memdisk in case user wants that.
As for the Linux loader, I'll have to disable it on this port untill it doesn't require that we reserve a hardcoded address for it.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port)
Another solution is to just leave the modules where they are (I/O map at top of memory), and load them directly from that location. This allows us to put the kernel in low memory without size problems.
However, our module loader assumes the memory that contains the ELFs is writable (for example, grub_dl_resolve_symbols() modifies sym->st_value).
A possible solution to this could be to make grub_dl_load_core() create a copy of the module and work on the copy. This could even be ifdef'ed, but I doubt the performance hit would be significant.
Another possibility could be to copy them into the heap in grub_arch_modules_addr(), but this forces us to leak the memory that contains them.
Or grub_arch_modules_addr() could copy them to 0x100000, but then we'd have the beginning of the heap as limit.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
PATCH 1/1 fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 3 lines · Robert Millan
A possible solution to this could be to make
grub_dl_load_core()create a copy of the module and work on the copy. This could even be ifdef'ed, but I doubt the performance hit would be significant.
I found a better approach; instead of copiing the whole module, we just need to copy the symbol tab. A small adjustment to each of the functions that will access it (grub_dl_resolve_symbols and grub_arch_dl_relocate_symbols) will make them use the copy instead of the original.
Patch attached.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-25 Robert Millan <[email protected]>
* kern/dl.c (Elf_Word, Elf_Addr, Elf_Ehdr, Elf_Shdr, Elf_Sym): Remove typedefs.
(ELF_ST_BIND, ELF_ST_TYPE): Remove macros.
* include/grub/elf.h (Elf_Word, Elf_Addr, Elf_Ehdr, Elf_Shdr) (Elf_Sym, ELF_ST_BIND, ELF_ST_TYPE): New macros.
* efiemu/loadcore64.c: Include `<grub/elf.h>'. (Elf_Word, Elf_Ehdr, Elf_Shdr, Elf_Sym, ELF_ST_BIND) (ELF_ST_TYPE): Undefine macros for native word length so that they can be redefined afterwards.
* efiemu/loadcore32.c: Likewise.
* include/grub/dl.h: Include <grub/elf.h>'. (struct grub_dl): Add symtab' member.
* kern/dl.c (grub_dl_resolve_symbols): Copy symbol table to `mod->symtab', and use the copied structure for further writes rather than the original.
* kern/powerpc/dl.c (grub_arch_dl_relocate_symbols): Initialize symtab' using mod->symtab'.
* kern/sparc64/dl.c: Likewise.
* kern/i386/dl.c: Likewise.
* kern/x86_64/dl.c: Likewise.
powerpc/dl.c +1 -1
@@ -58,7 +58,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf32_Sym *) ((char *) e + s->sh_offset); + symtab = mod->symtab; entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
dl.c +4 -25
@@ -29,30 +29,6 @@#include <grub/env.h> #include <grub/cache.h> -#if GRUB_CPU_SIZEOF_VOID_P ==4 - -typedef Elf32_Word Elf_Word ; -typedef Elf32_Addr Elf_Addr ; -typedef Elf32_Ehdr Elf_Ehdr ; -typedef Elf32_Shdr Elf_Shdr ; -typedef Elf32_Sym Elf_Sym ; - -# define ELF_ST_BIND (val) ELF32_ST_BIND (val) -# define ELF_ST_TYPE (val) ELF32_ST_TYPE (val) - -#elif GRUB_CPU_SIZEOF_VOID_P ==8 - -typedef Elf64_Word Elf_Word ; -typedef Elf64_Addr Elf_Addr ; -typedef Elf64_Ehdr Elf_Ehdr ; -typedef Elf64_Shdr Elf_Shdr ; -typedef Elf64_Sym Elf_Sym ; - -# define ELF_ST_BIND (val) ELF64_ST_BIND (val) -# define ELF_ST_TYPE (val) ELF64_ST_TYPE (val) - -#endif -struct grub_dl_list
@@ -333,9 +309,11 @@ grub_dl_resolve_symbols (grub_dl_t mod,if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symbol table" ); - sym = (Elf_Sym *) ((char *) e + s->sh_offset); size = s->sh_size; entsize = s->sh_entsize; + mod->symtab =grub_malloc (size); +memcpy (mod->symtab, (char *) e + s->sh_offset, size); + sym = mod->symtab; s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shentsize * s->sh_link); str = (char *) e + s->sh_offset;
@@ -695,6 +673,7 @@ grub_dl_unload (grub_dl_t mod) }grub_free (mod->name); +grub_free (mod->symtab);grub_free (mod);return 1 ; }
sparc64/dl.c +1 -1
@@ -58,7 +58,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf64_Sym *) ((char *) e + s->sh_offset); + symtab = mod->symtab; entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
i386/dl.c +1 -1
@@ -57,7 +57,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf32_Sym *) ((char *) e + s->sh_offset); + symtab = mod->symtab; entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
x86_64/dl.c +1 -1
@@ -57,7 +57,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf64_Sym *) ((char *) e + s->sh_offset); + symtab = mod->symtab; entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
loadcore64.c +9 -0
@@ -18,6 +18,15 @@*/ #define SUFFIX (x) x ## 64 + +#include <grub/elf.h> +#undef Elf_Ehdr +#undef Elf_Shdr +#undef Elf_Sym +#undef Elf_Word +#undef ELF_ST_TYPE +#undef ELF_ST_BIND +#define Elf_Ehdr Elf64_Ehdr#define Elf_Shdr Elf64_Shdr#define Elf_Sym Elf64_Sym
loadcore32.c +10 -0
@@ -18,10 +18,20 @@*/ #define SUFFIX (x) x ## 32 + +#include <grub/elf.h> +#undef Elf_Ehdr +#undef Elf_Shdr +#undef Elf_Sym +#undef Elf_Word +#undef ELF_ST_TYPE +#undef ELF_ST_BIND +#define Elf_Ehdr Elf32_Ehdr#define Elf_Shdr Elf32_Shdr#define Elf_Sym Elf32_Sym#define Elf_Word Elf32_Word#define ELF_ST_TYPE ELF32_ST_TYPE#define ELF_ST_BIND ELF32_ST_BIND +#include "loadcore.c"
grub/elf.h +24 -0
@@ -2330,4 +2330,28 @@ typedef Elf32_Addr Elf32_Conflict;#define R_X86_64_NUM 24 +#if GRUB_CPU_SIZEOF_VOID_P ==4 + +#define Elf_Word Elf32_Word +#define Elf_Addr Elf32_Addr +#define Elf_Ehdr Elf32_Ehdr +#define Elf_Shdr Elf32_Shdr +#define Elf_Sym Elf32_Sym + +# define ELF_ST_BIND (val) ELF32_ST_BIND (val) +# define ELF_ST_TYPE (val) ELF32_ST_TYPE (val) + +#elif GRUB_CPU_SIZEOF_VOID_P ==8 + +#define Elf_Word Elf64_Word +#define Elf_Addr Elf64_Addr +#define Elf_Ehdr Elf64_Ehdr +#define Elf_Shdr Elf64_Shdr +#define Elf_Sym Elf64_Sym + +# define ELF_ST_BIND (val) ELF64_ST_BIND (val) +# define ELF_ST_TYPE (val) ELF64_ST_TYPE (val) + +#endif +#endif /* ! GRUB_ELF_H */
grub/dl.h +2 -0
@@ -23,6 +23,7 @@#include <grub/symbol.h> #include <grub/err.h> #include <grub/types.h> +#include <grub/elf.h> #define GRUB_MOD_INIT (name) \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
@@ -78,6 +79,7 @@ struct grub_dlint ref_count;grub_dl_dep_t dep;grub_dl_segment_t segment; +Elf_Sym *symtab;void (*init) (struct grub_dl *mod);void (*fini) (void ); };
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 10 lines · Robert Millan
Quoted 3 lines · Robert Millan
A possible solution to this could be to make
grub_dl_load_core()create a copy of the module and work on the copy. This could even be ifdef'ed, but I doubt the performance hit would be significant.I found a better approach; instead of copiing the whole module, we just need to copy the symbol tab. A small adjustment to each of the functions that will access it (
grub_dl_resolve_symbolsandgrub_arch_dl_relocate_symbols) will make them use the copy instead of the original.
Massive use of undef seems inelegant. Maybe it's better to use distinctive names instead, e.g. target_Elf_Ehdr v.s. host_Elf_Ehdr?
Also, I'm getting many warnings on i386-pc about redefined Elf_Ehdr when compiling on x86_64.
Generally, I like the idea for i386-qemu, but for other architectures, the only change is the increased memory consumption. I would be willing to accept this change if you could suggest some universal benefit for all platforms.
Otherwise, it would be better to use wrappers like get_header() and put_header() what would do grub_malloc() and grub_free() only if needed and return the original header otherwise.
I'm fine with adding the symtab field unconditionally, it doesn't cost much memory.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 6 lines · Pavel Roskin
Quoted 5 lines · Robert Millan
Quoted 3 lines · Robert Millan
A possible solution to this could be to make
grub_dl_load_core()create a copy of the module and work on the copy. This could even be ifdef'ed, but I doubt the performance hit would be significant.
Quoted 8 lines
Quoted 5 lines
I found a better approach; instead of copiing the whole module, we just need to copy the symbol tab. A small adjustment to each of the functions that will access it (
grub_dl_resolve_symbolsandgrub_arch_dl_relocate_symbols) will make them use the copy instead of the original.Massive use of undef seems inelegant. Maybe it's better to use distinctive names instead, e.g.
target_Elf_Ehdrv.s.host_Elf_Ehdr?
You mean for efiemu? Seems fine. But I wouldn't use "target/host" naming, since it doesn't match with existing usage of those names elsewhere, which makes it very confusing.
How about "native/cross"?
Quoted 2 lines
Also, I'm getting many warnings on i386-pc about redefined
Elf_Ehdrwhen compiling onx86_64.
I'll have a look.
Quoted 11 lines
Generally, I like the idea for i386-qemu, but for other architectures, the only change is the increased memory consumption. I would be willing to accept this change if you could suggest some universal benefit for all platforms.
Otherwise, it would be better to use wrappers like
get_header()andput_header()what would dogrub_malloc()andgrub_free()only if needed and return the original header otherwise.I'm fine with adding the symtab field unconditionally, it doesn't cost much memory.
I agree there's no point in making all architectures do this. However, note that we'll probably see more architectures with read-only modules in the future (other qemu ports, but also any port where GRUB runs standalone).
I was thinking that we could just #ifdef the symtab allocation (and the symtab field declaration as well). Since it's just a few lines, I think it'll look readable.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 5 lines · Robert Millan
You mean for efiemu? Seems fine. But I wouldn't use "target/host" naming, since it doesn't match with existing usage of those names elsewhere, which makes it very confusing.
How about "native/cross"?
Fine with me. Whatever is meaningful.
Quoted 8 lines
I agree there's no point in making all architectures do this. However, note that we'll probably see more architectures with read-only modules in the future (other qemu ports, but also any port where GRUB runs standalone).
I was thinking that we could just #ifdef the symtab allocation (and the symtab field declaration as well). Since it's just a few lines, I think it'll look readable.
I'd like to avoid preprocessor conditionals in kern/ARCH/dl.c files if possible. There is no harm in keeping mod->symtab and using it instead of the local "symtab" variables.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 3 lines · Pavel Roskin
I'd like to avoid preprocessor conditionals in
kern/ARCH/dl.cfiles if possible.
Alright, here's a new patch. It follows your earlier suggestion to use a wrapper to obtain the initialization address for symtab. This way we don't put any ifdefs in kern/ARCH/dl.c files.
I also avoid the #undefs in efiemu. This required many changes in loadcore.c, but they're just a sed search & replace run.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-06-26 Robert Millan <[email protected]>
* kern/dl.c (Elf_Word, Elf_Addr, Elf_Ehdr, Elf_Shdr, Elf_Sym): Remove typedefs.
(ELF_ST_BIND, ELF_ST_TYPE): Remove macros.
* include/grub/elf.h (Elf_Word, Elf_Addr, Elf_Ehdr, Elf_Shdr) (Elf_Sym, ELF_ST_BIND, ELF_ST_TYPE): New macros.
* efiemu/loadcore64.c: Include `<grub/elf.h>'. (Elf_Word, Elf_Ehdr, Elf_Shdr, Elf_Sym, ELF_ST_BIND) (ELF_ST_TYPE): Rename to ...
(ElfW_Word, ElfW_Ehdr, ElfW_Shdr, ElfW_Sym, ELFW_ST_BIND) (ELFW_ST_TYPE): ... this. Update all users.
* efiemu/loadcore32.c: Likewise.
* include/grub/dl.h: Include <grub/elf.h>' and <grub/machine/machine.h>'.
[GRUB_MACHINE_QEMU] (GRUB_MODULES_MACHINE_READONLY): New macro. [GRUB_MODULES_MACHINE_READONLY] (struct grub_dl): Add `symtab' member. (get_symtab): New macro.
* kern/dl.c [GRUB_MODULES_MACHINE_READONLY] (grub_dl_resolve_symbols): Copy symbol table to `mod->symtab', and use
the copied structure for further writes rather than the original.
* kern/powerpc/dl.c (grub_arch_dl_relocate_symbols): Initialize `symtab' using get_symtab().
* kern/sparc64/dl.c: Likewise.
* kern/i386/dl.c: Likewise.
* kern/x86_64/dl.c: Likewise.
powerpc/dl.c +1 -1
@@ -58,7 +58,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf32_Sym *) ((char *) e + s->sh_offset); + symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
dl.c +9 -26
@@ -1,7 +1,7 @@/* dl.c - loadable module support */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. +* Copyright (C) 2002,2003,2004,2005,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
@@ -29,30 +29,6 @@#include <grub/env.h> #include <grub/cache.h> -#if GRUB_CPU_SIZEOF_VOID_P ==4 - -typedef Elf32_Word Elf_Word ; -typedef Elf32_Addr Elf_Addr ; -typedef Elf32_Ehdr Elf_Ehdr ; -typedef Elf32_Shdr Elf_Shdr ; -typedef Elf32_Sym Elf_Sym ; - -# define ELF_ST_BIND (val) ELF32_ST_BIND (val) -# define ELF_ST_TYPE (val) ELF32_ST_TYPE (val) - -#elif GRUB_CPU_SIZEOF_VOID_P ==8 - -typedef Elf64_Word Elf_Word ; -typedef Elf64_Addr Elf_Addr ; -typedef Elf64_Ehdr Elf_Ehdr ; -typedef Elf64_Shdr Elf_Shdr ; -typedef Elf64_Sym Elf_Sym ; - -# define ELF_ST_BIND (val) ELF64_ST_BIND (val) -# define ELF_ST_TYPE (val) ELF64_ST_TYPE (val) - -#endif -struct grub_dl_list
@@ -333,9 +309,13 @@ grub_dl_resolve_symbols (grub_dl_t mod,if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symbol table" ); - sym = (Elf_Sym *) ((char *) e + s->sh_offset); size = s->sh_size; entsize = s->sh_entsize; +#ifdef GRUB_MODULES_MACHINE_READONLY + mod->symtab =grub_malloc (size); +memcpy (mod->symtab, (char *) e + s->sh_offset, size); +#endif + sym =get_symtab (); s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shentsize * s->sh_link); str = (char *) e + s->sh_offset;
@@ -695,6 +675,9 @@ grub_dl_unload (grub_dl_t mod) }grub_free (mod->name); +#ifdef GRUB_MODULES_MACHINE_READONLY +grub_free (mod->symtab); +#endif grub_free (mod);return 1 ; }
sparc64/dl.c +1 -1
@@ -58,7 +58,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf64_Sym *) ((char *) e + s->sh_offset); + symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
i386/dl.c +1 -1
@@ -57,7 +57,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf32_Sym *) ((char *) e + s->sh_offset); + symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
x86_64/dl.c +1 -1
@@ -57,7 +57,7 @@ grub_arch_dl_relocate_symbols (grub_dl_tif (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf64_Sym *) ((char *) e + s->sh_offset); + symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
loadcore64.c +10 -6
@@ -18,10 +18,14 @@*/ #define SUFFIX (x) x ## 64 -#define Elf_Ehdr Elf64_Ehdr -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Word Elf64_Word -#define ELF_ST_TYPE ELF64_ST_TYPE -#define ELF_ST_BIND ELF64_ST_BIND + +#include <grub/elf.h> + +#define ElfW_Ehdr Elf64_Ehdr +#define ElfW_Shdr Elf64_Shdr +#define ElfW_Sym Elf64_Sym +#define ElfW_Word Elf64_Word +#define ELFW_ST_TYPE ELF64_ST_TYPE +#define ELFW_ST_BIND ELF64_ST_BIND +#include "loadcore.c"
loadcore.c +31 -31
155 lines not on this page · raw message
loadcore32.c +10 -6
@@ -18,10 +18,14 @@*/ #define SUFFIX (x) x ## 32 -#define Elf_Ehdr Elf32_Ehdr -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Word Elf32_Word -#define ELF_ST_TYPE ELF32_ST_TYPE -#define ELF_ST_BIND ELF32_ST_BIND + +#include <grub/elf.h> + +#define ElfW_Ehdr Elf32_Ehdr +#define ElfW_Shdr Elf32_Shdr +#define ElfW_Sym Elf32_Sym +#define ElfW_Word Elf32_Word +#define ELFW_ST_TYPE ELF32_ST_TYPE +#define ELFW_ST_BIND ELF32_ST_BIND +#include "loadcore.c"
grub/elf.h +25 -1
@@ -1,5 +1,5 @@/* This file defines standard ELF types, structures, and macros. -Copyright (C) 1995-1999, 2000, 2001, 2002,2008 Free Software Foundation, Inc. +Copyright (C) 1995-1999,2000,2001,2002,2008,2009 Free Software Foundation, Inc. This file was part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or
@@ -2330,4 +2330,28 @@ typedef Elf32_Addr Elf32_Conflict;#define R_X86_64_NUM 24 +#if GRUB_CPU_SIZEOF_VOID_P ==4 + +#define Elf_Word Elf32_Word +#define Elf_Addr Elf32_Addr +#define Elf_Ehdr Elf32_Ehdr +#define Elf_Shdr Elf32_Shdr +#define Elf_Sym Elf32_Sym + +# define ELF_ST_BIND (val) ELF32_ST_BIND (val) +# define ELF_ST_TYPE (val) ELF32_ST_TYPE (val) + +#elif GRUB_CPU_SIZEOF_VOID_P ==8 + +#define Elf_Word Elf64_Word +#define Elf_Addr Elf64_Addr +#define Elf_Ehdr Elf64_Ehdr +#define Elf_Shdr Elf64_Shdr +#define Elf_Sym Elf64_Sym + +# define ELF_ST_BIND (val) ELF64_ST_BIND (val) +# define ELF_ST_TYPE (val) ELF64_ST_TYPE (val) + +#endif +#endif /* ! GRUB_ELF_H */
grub/dl.h +14 -1
@@ -1,7 +1,7 @@/* dl.h - types and prototypes for loadable module support */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2004,2005,2007,2008 Free Software Foundation, Inc. +* Copyright (C) 2002,2004,2005,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
@@ -23,6 +23,13 @@#include <grub/symbol.h> #include <grub/err.h> #include <grub/types.h> +#include <grub/elf.h> +#include <grub/machine/machine.h> + +/* Platforms where modules are in a readonly area of memory. */ +#if defined(GRUB_MACHINE_QEMU ) +#define GRUB_MODULES_MACHINE_READONLY +#endif #define GRUB_MOD_INIT (name) \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
@@ -78,6 +85,12 @@ struct grub_dlint ref_count;grub_dl_dep_t dep;grub_dl_segment_t segment; +#ifdef GRUB_MODULES_MACHINE_READONLY +Elf_Sym *symtab; +#define get_symtab () mod->symtab +#else +#define get_symtab () ((Elf_Sym *) ((char *) e + s->sh_offset)) +#endif void (*init) (struct grub_dl *mod);void (*fini) (void ); };
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 11 lines · Robert Millan
Quoted 3 lines · Pavel Roskin
I'd like to avoid preprocessor conditionals in
kern/ARCH/dl.cfiles if possible.Alright, here's a new patch. It follows your earlier suggestion to use a wrapper to obtain the initialization address for symtab. This way we don't put any ifdefs in
kern/ARCH/dl.cfiles.I also avoid the #undefs in efiemu. This required many changes in
loadcore.c, but they're just a sed search & replace run.
More redefinitions are needed to make all platforms compile. At this point I think maybe we should try something less intrusive. But anyway, 02-elf-renames.patch contains those renames.
03-simple-symtab.patch simplifies the logic in kern/ARCH/dl.c files.
Signature · 2 lines
Regards, Pavel Roskin
More elf definitions changed.
From: Pavel Roskin <[email protected]>
Use ElfT in grub-mkelfimage, ElfK in loaders.
---
loader/i386/bsd32.c | 6 - loader/i386/bsd64.c | 6 - loader/i386/bsdXX.c | 44 +++-- loader/i386/multiboot_elfxx.c | 18 +- util/i386/efi/grub-mkimage.c | 344 +++++++++++++++++++++-------------------- 5 files changed, 209 insertions(+), 209 deletions(-)
loader/i386/bsd32.c +3 -3
@@ -1,7 +1,7 @@#define SUFFIX (x) x ## 32 -#define Elf_Ehdr Elf32_Ehdr -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym +#define ElfK_Ehdr Elf32_Ehdr +#define ElfK_Shdr Elf32_Shdr +#define ElfK_Sym Elf32_Sym#define OBJSYM 0#include <grub/types.h> typedef grub_uint32_t grub_freebsd_addr_t ;
loader/i386/bsd64.c +3 -3
@@ -1,7 +1,7 @@#define SUFFIX (x) x ## 64 -#define Elf_Ehdr Elf64_Ehdr -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym +#define ElfK_Ehdr Elf64_Ehdr +#define ElfK_Shdr Elf64_Shdr +#define ElfK_Sym Elf64_Sym#define OBJSYM 1#include <grub/types.h> typedef grub_uint64_t grub_freebsd_addr_t ;
loader/i386/bsdXX.c +22 -22
108 lines not on this page · raw message
loader/i386/multiboot_elfxx.c +9 -9
@@ -20,14 +20,14 @@# define XX 32# define E_MACHINE EM_386# define ELFCLASSXX ELFCLASS32 -# define Elf_Ehdr Elf32_Ehdr -# define Elf_Phdr Elf32_Phdr +# define ElfK_Ehdr Elf32_Ehdr +# define ElfK_Phdr Elf32_Phdr#elif defined(MULTIBOOT_LOAD_ELF64 )# define XX 64# define E_MACHINE EM_X86_64# define ELFCLASSXX ELFCLASS64 -# define Elf_Ehdr Elf64_Ehdr -# define Elf_Phdr Elf64_Phdr +# define ElfK_Ehdr Elf64_Ehdr +# define ElfK_Phdr Elf64_Phdr#else #error "I'm confused"#endif
@@ -39,7 +39,7 @@static int CONCAT (grub_multiboot_is_elf ,XX ) (void *buffer) { -Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer; +ElfK_Ehdr *ehdr = (ElfK_Ehdr *) buffer;return ehdr->e_ident[EI_CLASS ] ==ELFCLASSXX ; }
@@ -47,7 +47,7 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer)static grub_err_t CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,void *buffer) { -Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer; +ElfK_Ehdr *ehdr = (ElfK_Ehdr *) buffer;char *phdr_base;int lowest_segment =-1 , highest_segment =-1 ;int i;
@@ -78,7 +78,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)#endif phdr_base = (char *) buffer + ehdr->e_phoff; -#define phdr (i) ((Elf_Phdr *) (phdr_base + (i) * ehdr->e_phentsize)) +#define phdr (i) ((ElfK_Phdr *) (phdr_base + (i) * ehdr->e_phentsize))for (i =0 ; i < ehdr->e_phnum; i++)if (phdr (i)->p_type ==PT_LOAD &&phdr (i)->p_filesz !=0 )
@@ -151,5 +151,5 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, void *buffer)#undef XX#undef E_MACHINE#undef ELFCLASSXX -#undef Elf_Ehdr -#undef Elf_Phdr +#undef ElfK_Ehdr +#undef ElfK_Phdr
util/i386/efi/grub-mkimage.c +172 -172
634 lines not on this page · raw message
Simplify symtab logic
From: Pavel Roskin <[email protected]>
---
include/grub/dl.h | 5 ----- kern/dl.c | 4 +++- kern/i386/dl.c | 4 +--- kern/powerpc/dl.c | 4 +--- kern/sparc64/dl.c | 4 +--- kern/x86_64/dl.c | 4 +--- 6 files changed, 7 insertions(+), 18 deletions(-)
include/grub/dl.h +0 -5
@@ -85,12 +85,7 @@ struct grub_dlint ref_count;grub_dl_dep_t dep;grub_dl_segment_t segment; -#ifdef GRUB_MODULES_MACHINE_READONLY Elf_Sym *symtab; -#define get_symtab () mod->symtab -#else -#define get_symtab () ((Elf_Sym *) ((char *) e + s->sh_offset)) -#endif void (*init) (struct grub_dl *mod);void (*fini) (void ); };
kern/dl.c +3 -1
@@ -314,8 +314,10 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)#ifdef GRUB_MODULES_MACHINE_READONLY mod->symtab =grub_malloc (size);memcpy (mod->symtab, (char *) e + s->sh_offset, size); +#else + mod->symtab = ((Elf_Sym *) ((char *) e + s->sh_offset));#endif - sym =get_symtab (); + sym = mod->symtab; s = (Elf_Shdr *) ((char *) e + e->e_shoff + e->e_shentsize * s->sh_link); str = (char *) e + s->sh_offset;
kern/i386/dl.c +1 -3
@@ -43,7 +43,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf32_Ehdr *e = ehdr;Elf32_Shdr *s; -Elf32_Sym *symtab;Elf32_Word entsize;unsigned i;
@@ -57,7 +56,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
@@ -89,7 +87,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) "reloc offset is out of the segment"); addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset); - sym = (Elf32_Sym *) ((char *) symtab + sym = (Elf32_Sym *) ((char *) mod->symtab + entsize *ELF32_R_SYM (rel->r_info)); switch (ELF32_R_TYPE (rel->r_info))
kern/powerpc/dl.c +1 -3
@@ -44,7 +44,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf32_Ehdr *e = ehdr;Elf32_Shdr *s; -Elf32_Sym *symtab;Elf32_Word entsize;unsigned i;
@@ -58,7 +57,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
@@ -91,7 +89,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) "reloc offset is out of the segment"); addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset); - sym = (Elf32_Sym *) ((char *) symtab + sym = (Elf32_Sym *) ((char *) mod->symtab + entsize *ELF32_R_SYM (rel->r_info));/* On the PPC the value does not have an explicit
kern/sparc64/dl.c +1 -3
@@ -44,7 +44,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf64_Ehdr *e = ehdr;Elf64_Shdr *s; -Elf64_Sym *symtab;Elf64_Word entsize;unsigned i;
@@ -58,7 +57,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
@@ -91,7 +89,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) "reloc offset is out of the segment"); addr = (Elf64_Word *) ((char *) seg->addr + rel->r_offset); - sym = (Elf64_Sym *) ((char *) symtab + sym = (Elf64_Sym *) ((char *) mod->symtab + entsize *ELF64_R_SYM (rel->r_info)); value = sym->st_value + rel->r_addend;
kern/x86_64/dl.c +1 -3
@@ -43,7 +43,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf64_Ehdr *e = ehdr;Elf64_Shdr *s; -Elf64_Sym *symtab;Elf64_Word entsize;unsigned i;
@@ -57,7 +56,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab =get_symtab (); entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
@@ -91,7 +89,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) addr32 = (Elf64_Word *) ((char *) seg->addr + rel->r_offset); addr64 = (Elf64_Xword *) addr32; - sym = (Elf64_Sym *) ((char *) symtab + sym = (Elf64_Sym *) ((char *) mod->symtab + entsize *ELF64_R_SYM (rel->r_info)); switch (ELF64_R_TYPE (rel->r_info))
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 10 lines · Pavel Roskin
Quoted 9 lines · Robert Millan
Quoted 3 lines · Pavel Roskin
I'd like to avoid preprocessor conditionals in
kern/ARCH/dl.cfiles if possible.Alright, here's a new patch. It follows your earlier suggestion to use a wrapper to obtain the initialization address for symtab. This way we don't put any ifdefs in
kern/ARCH/dl.cfiles.
Quoted 8 lines
Quoted 2 lines
I also avoid the #undefs in efiemu. This required many changes in
loadcore.c, but they're just a sed search & replace run.More redefinitions are needed to make all platforms compile. At this point I think maybe we should try something less intrusive. But anyway, 02-elf-renames.patch contains those renames.
03-simple-symtab.patch simplifies the logic in
kern/ARCH/dl.cfiles.
03-simple-symtab.patch looks nice, much cleaner than what I had.
But as for 02-elf-renames.patch we could try to make this more consistent. In efiemu I used 'W' (inspired by ElfW() macro in glibc), then in some places you use 'K' and in other places 'T'. Can we use the same everywhere? I don't care which letter, I'm not THAT much into bikeshed :-)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 1 line · Robert Millan
03-simple-symtab.patch looks nice, much cleaner than what I had.
Thanks!
Quoted 4 lines
But as for 02-elf-renames.patch we could try to make this more consistent. In efiemu I used 'W' (inspired by
ElfW()macro in glibc), then in some places you use 'K' and in other places 'T'. Can we use the same everywhere? I don't care which letter, I'm not THAT much into bikeshed :-)
"T" stands for "target" and "K" stands for "kernel". Yes, we can use ElfW everywhere. But I would try to avoid any mass renames. It's very easy to write Elf instead of ElfW somewhere in the code, and it would compile, but it won't work.
Maybe we could have two headers, elf32.h and elf64.h, and every file that needs Elf definitions would include one of them, dependent on which elf format it wants. Including both elf32.h and elf64.h from one source should be impossible. It could be a separate patch that would go in before the ROM modules support.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 9 lines · Pavel Roskin
Quoted 4 lines
But as for 02-elf-renames.patch we could try to make this more consistent. In efiemu I used 'W' (inspired by
ElfW()macro in glibc), then in some places you use 'K' and in other places 'T'. Can we use the same everywhere? I don't care which letter, I'm not THAT much into bikeshed :-)"T" stands for "target" and "K" stands for "kernel". Yes, we can use ElfW everywhere. But I would try to avoid any mass renames. It's very easy to write Elf instead of ElfW somewhere in the code, and it would compile, but it won't work.
Ok, I don't mind. Unless you have any objections, I'll merge your two patches with mine and commit that.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 2 lines · Robert Millan
Ok, I don't mind. Unless you have any objections, I'll merge your two patches with mine and commit that.
Please let me try to do it in a nicer way.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
In reply to Robert MillanQuoted 6 lines · Robert Millan
Quoted 5 lines · Pavel Roskin
Quoted 4 lines
But as for 02-elf-renames.patch we could try to make this more consistent. In efiemu I used 'W' (inspired by
ElfW()macro in glibc), then in some places you use 'K' and in other places 'T'. Can we use the same everywhere? I don't care which letter, I'm not THAT much into bikeshed :-)
Quoted 7 lines
Quoted 4 lines
"T" stands for "target" and "K" stands for "kernel". Yes, we can use ElfW everywhere. But I would try to avoid any mass renames. It's very easy to write Elf instead of ElfW somewhere in the code, and it would compile, but it won't work.
Ok, I don't mind. Unless you have any objections, I'll merge your two patches with mine and commit that.
Please consider following patches. They avoid the massive rename. ELF header reorganization is split from adding support for modules in ROM.
Signature · 2 lines
Regards, Pavel Roskin
Select default ELF format in include/grub/elf.h
From: Pavel Roskin <[email protected]>
ChangeLog:
* include/grub/elf.h: Define symbols for 32-bit or 64-bit ELF based on DEFAULT_ELF_BITS. Default to the target word size.
* efiemu/loadcore32.c: Use DEFAULT_ELF_BITS instead of own definitions.
* efiemu/loadcore64.c: Likewise.
* loader/i386/bsd32.c: Likewise.
* loader/i386/bsd64.c: Likewise.
* kern/dl.c: Remove ELF definitions.
* util/i386/efi/grub-mkimage.c: Likewise.
---
efiemu/loadcore32.c | 7 +------ efiemu/loadcore64.c | 7 +------ include/grub/elf.h | 44 ++++++++++++++++++++++++++++++++++++++++++ kern/dl.c | 24 ----------------------- loader/i386/bsd32.c | 4 +--- loader/i386/bsd64.c | 4 +--- util/i386/efi/grub-mkimage.c | 34 -------------------------------- 7 files changed, 48 insertions(+), 76 deletions(-)
efiemu/loadcore32.c +1 -6
@@ -18,10 +18,5 @@*/ #define SUFFIX (x) x ## 32 -#define Elf_Ehdr Elf32_Ehdr -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Word Elf32_Word -#define ELF_ST_TYPE ELF32_ST_TYPE -#define ELF_ST_BIND ELF32_ST_BIND +#define DEFAULT_ELF_BITS 32#include "loadcore.c"
efiemu/loadcore64.c +1 -6
@@ -18,10 +18,5 @@*/ #define SUFFIX (x) x ## 64 -#define Elf_Ehdr Elf64_Ehdr -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Word Elf64_Word -#define ELF_ST_TYPE ELF64_ST_TYPE -#define ELF_ST_BIND ELF64_ST_BIND +#define DEFAULT_ELF_BITS 64#include "loadcore.c"
include/grub/elf.h +44 -0
48 lines not on this page · raw message
kern/dl.c +0 -24
@@ -29,30 +29,6 @@#include <grub/env.h> #include <grub/cache.h> -#if GRUB_CPU_SIZEOF_VOID_P ==4 - -typedef Elf32_Word Elf_Word ; -typedef Elf32_Addr Elf_Addr ; -typedef Elf32_Ehdr Elf_Ehdr ; -typedef Elf32_Shdr Elf_Shdr ; -typedef Elf32_Sym Elf_Sym ; - -# define ELF_ST_BIND (val) ELF32_ST_BIND (val) -# define ELF_ST_TYPE (val) ELF32_ST_TYPE (val) - -#elif GRUB_CPU_SIZEOF_VOID_P ==8 - -typedef Elf64_Word Elf_Word ; -typedef Elf64_Addr Elf_Addr ; -typedef Elf64_Ehdr Elf_Ehdr ; -typedef Elf64_Shdr Elf_Shdr ; -typedef Elf64_Sym Elf_Sym ; - -# define ELF_ST_BIND (val) ELF64_ST_BIND (val) -# define ELF_ST_TYPE (val) ELF64_ST_TYPE (val) - -#endif -struct grub_dl_list
loader/i386/bsd32.c +1 -3
@@ -1,7 +1,5 @@#define SUFFIX (x) x ## 32 -#define Elf_Ehdr Elf32_Ehdr -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym +#define DEFAULT_ELF_BITS 32#define OBJSYM 0#include <grub/types.h> typedef grub_uint32_t grub_freebsd_addr_t ;
loader/i386/bsd64.c +1 -3
@@ -1,7 +1,5 @@#define SUFFIX (x) x ## 64 -#define Elf_Ehdr Elf64_Ehdr -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym +#define DEFAULT_ELF_BITS 64#define OBJSYM 1#include <grub/types.h> typedef grub_uint64_t grub_freebsd_addr_t ;
util/i386/efi/grub-mkimage.c +0 -34
@@ -32,43 +32,9 @@#include <grub/machine/kernel.h> #if GRUB_TARGET_SIZEOF_VOID_P ==4 - -typedef Elf32_Word Elf_Word ; -typedef Elf32_Addr Elf_Addr ; -typedef Elf32_Ehdr Elf_Ehdr ; -typedef Elf32_Shdr Elf_Shdr ; -typedef Elf32_Sym Elf_Sym ; -typedef Elf32_Half Elf_Half ; -typedef Elf32_Off Elf_Off ; -typedef Elf32_Section Elf_Section ; -typedef Elf32_Rel Elf_Rel ; -typedef Elf32_Rela Elf_Rela ; - -#define ELF_R_SYM ELF32_R_SYM -#define ELF_R_TYPE ELF32_R_TYPE -#define ELF_R_INFO ELF32_R_INFO -#define grub_le_to_cpu grub_le_to_cpu32 -#elif GRUB_TARGET_SIZEOF_VOID_P ==8 - -typedef Elf64_Word Elf_Word ; -typedef Elf64_Addr Elf_Addr ; -typedef Elf64_Ehdr Elf_Ehdr ; -typedef Elf64_Shdr Elf_Shdr ; -typedef Elf64_Sym Elf_Sym ; -typedef Elf64_Half Elf_Half ; -typedef Elf64_Off Elf_Off ; -typedef Elf64_Section Elf_Section ; -typedef Elf64_Rel Elf_Rel ; -typedef Elf64_Rela Elf_Rela ; - -#define ELF_R_SYM ELF64_R_SYM -#define ELF_R_TYPE ELF64_R_TYPE -#define ELF_R_INFO ELF64_R_INFO -#define grub_le_to_cpu grub_le_to_cpu64 -#endif static const grub_uint8_t stub[] =GRUB_PE32_MSDOS_STUB ;
Allow modules in ROM
From: Pavel Roskin <[email protected]>
ChangeLog:
* include/grub/dl.h: Include grub/elf.h.
(struct grub_dl): Add symtab field.
* kern/dl.c [GRUB_MACHINE_QEMU]: Define GRUB_MODULES_MACHINE_READONLY. (grub_dl_resolve_symbols): Populate mod->symtab, making a copy of the header for read-only modules. (grub_dl_unload): Free mod->symtab for read-only modules.
* kern/i386/dl.c: Use mod->symtab.
* kern/powerpc/dl.c: Likewise.
* kern/sparc64/dl.c: Likewise.
* kern/x86_64/dl.c: Likewise.
---
include/grub/dl.h | 4 +++- kern/dl.c | 19 +++++++++++++++++-- kern/i386/dl.c | 4 +--- kern/powerpc/dl.c | 4 +--- kern/sparc64/dl.c | 4 +--- kern/x86_64/dl.c | 4 +--- 6 files changed, 24 insertions(+), 15 deletions(-)
include/grub/dl.h +3 -1
@@ -1,7 +1,7 @@/* dl.h - types and prototypes for loadable module support */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2004,2005,2007,2008 Free Software Foundation, Inc. +* Copyright (C) 2002,2004,2005,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
@@ -23,6 +23,7 @@#include <grub/symbol.h> #include <grub/err.h> #include <grub/types.h> +#include <grub/elf.h> #define GRUB_MOD_INIT (name) \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
@@ -78,6 +79,7 @@ struct grub_dlint ref_count;grub_dl_dep_t dep;grub_dl_segment_t segment; +Elf_Sym *symtab;void (*init) (struct grub_dl *mod);void (*fini) (void ); };
kern/dl.c +17 -2
@@ -1,7 +1,7 @@/* dl.c - loadable module support */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2003,2004,2005,2007,2008 Free Software Foundation, Inc. +* Copyright (C) 2002,2003,2004,2005,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
@@ -28,6 +28,12 @@#include <grub/file.h> #include <grub/env.h> #include <grub/cache.h> +#include <grub/machine/machine.h> + +/* Platforms where modules are in a readonly area of memory. */ +#if defined(GRUB_MACHINE_QEMU ) +#define GRUB_MODULES_MACHINE_READONLY +#endif
@@ -309,7 +315,13 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symbol table" ); - sym = (Elf_Sym *) ((char *) e + s->sh_offset); +#ifdef GRUB_MODULES_MACHINE_READONLY + mod->symtab =grub_malloc (s->sh_size); +memcpy (mod->symtab, (char *) e + s->sh_offset, s->sh_size); +#else + mod->symtab = (Elf_Sym *) ((char *) e + s->sh_offset); +#endif + sym = mod->symtab; size = s->sh_size; entsize = s->sh_entsize;
@@ -671,6 +683,9 @@ grub_dl_unload (grub_dl_t mod) }grub_free (mod->name); +#ifdef GRUB_MODULES_MACHINE_READONLY +grub_free (mod->symtab); +#endif grub_free (mod);return 1 ; }
kern/i386/dl.c +1 -3
@@ -43,7 +43,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf32_Ehdr *e = ehdr;Elf32_Shdr *s; -Elf32_Sym *symtab;Elf32_Word entsize;unsigned i;
@@ -57,7 +56,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf32_Sym *) ((char *) e + s->sh_offset); entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
@@ -89,7 +87,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) "reloc offset is out of the segment"); addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset); - sym = (Elf32_Sym *) ((char *) symtab + sym = (Elf32_Sym *) ((char *) mod->symtab + entsize *ELF32_R_SYM (rel->r_info)); switch (ELF32_R_TYPE (rel->r_info))
kern/powerpc/dl.c +1 -3
@@ -44,7 +44,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf32_Ehdr *e = ehdr;Elf32_Shdr *s; -Elf32_Sym *symtab;Elf32_Word entsize;unsigned i;
@@ -58,7 +57,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf32_Sym *) ((char *) e + s->sh_offset); entsize = s->sh_entsize; for (i = 0, s = (Elf32_Shdr *) ((char *) e + e->e_shoff);
@@ -91,7 +89,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) "reloc offset is out of the segment"); addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset); - sym = (Elf32_Sym *) ((char *) symtab + sym = (Elf32_Sym *) ((char *) mod->symtab + entsize *ELF32_R_SYM (rel->r_info));/* On the PPC the value does not have an explicit
kern/sparc64/dl.c +1 -3
@@ -44,7 +44,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf64_Ehdr *e = ehdr;Elf64_Shdr *s; -Elf64_Sym *symtab;Elf64_Word entsize;unsigned i;
@@ -58,7 +57,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf64_Sym *) ((char *) e + s->sh_offset); entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
@@ -91,7 +89,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) "reloc offset is out of the segment"); addr = (Elf64_Word *) ((char *) seg->addr + rel->r_offset); - sym = (Elf64_Sym *) ((char *) symtab + sym = (Elf64_Sym *) ((char *) mod->symtab + entsize *ELF64_R_SYM (rel->r_info)); value = sym->st_value + rel->r_addend;
kern/x86_64/dl.c +1 -3
@@ -43,7 +43,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) {Elf64_Ehdr *e = ehdr;Elf64_Shdr *s; -Elf64_Sym *symtab;Elf64_Word entsize;unsigned i;
@@ -57,7 +56,6 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)if (i == e->e_shnum)return grub_error (GRUB_ERR_BAD_MODULE ,"no symtab found" ); - symtab = (Elf64_Sym *) ((char *) e + s->sh_offset); entsize = s->sh_entsize; for (i = 0, s = (Elf64_Shdr *) ((char *) e + e->e_shoff);
@@ -91,7 +89,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr) addr32 = (Elf64_Word *) ((char *) seg->addr + rel->r_offset); addr64 = (Elf64_Xword *) addr32; - sym = (Elf64_Sym *) ((char *) symtab + sym = (Elf64_Sym *) ((char *) mod->symtab + entsize *ELF64_R_SYM (rel->r_info)); switch (ELF64_R_TYPE (rel->r_info))
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
include/grub/elf.h typedef Elf32_Addr Elf32_Conflict; · line 2335
Quoted 9 lines · Pavel Roskin
include/grub/elf.h +3
-0@@ -2330,4 +2330,48 @@ typedef Elf32_Addr Elf32_Conflict;#define R_X86_64_NUM 24 +#ifndef DEFAULT_ELF_BITS +#define DEFAULT_ELF_BITS (8 * GRUB_TARGET_SIZEOF_VOID_P) +#endif
Nice trick. But it's not ELF-specific, so why not put it in the same header that defines GRUB_TARGET_SIZEOF_VOID_P ? (with a different name of course)
But either way, your patches look fine to me.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 7 lines · Robert Millan
Quoted 6 lines · Pavel Roskin
include/grub/elf.h +0
-0@@ -2330,4 +2330,48 @@ typedef Elf32_Addr Elf32_Conflict;#define R_X86_64_NUM 24
Quoted 7 lines
include/grub/elf.h typedef Elf32_Addr Elf32_Conflict; · line 2335
Quoted 3 lines
include/grub/elf.h +3
-0+#ifndef DEFAULT_ELF_BITS +#define DEFAULT_ELF_BITS (8 * GRUB_TARGET_SIZEOF_VOID_P) +#endif Nice trick. But it's not ELF-specific, so why not put it in the same header that defines
GRUB_TARGET_SIZEOF_VOID_P? (with a different name of course)
Good idea! Now it's GRUB_TARGET_WORDSIZE. The first patch has been committed. The second patch should probably go after the qemu patch.
Signature · 2 lines
Regards, Pavel Roskin
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 16 lines · Pavel Roskin
Quoted 7 lines · Robert Millan
Quoted 6 lines · Pavel Roskin
include/grub/elf.h +0
-0@@ -2330,4 +2330,48 @@ typedef Elf32_Addr Elf32_Conflict;#define R_X86_64_NUM 24Quoted 7 lines
include/grub/elf.h typedef Elf32_Addr Elf32_Conflict; · line 2335
Quoted 3 lines
include/grub/elf.h +3
-0+#ifndef DEFAULT_ELF_BITS +#define DEFAULT_ELF_BITS (8 * GRUB_TARGET_SIZEOF_VOID_P) +#endif Nice trick. But it's not ELF-specific, so why not put it in the same header that defines
GRUB_TARGET_SIZEOF_VOID_P? (with a different name of course)
Quoted 2 lines
Good idea! Now it's
GRUB_TARGET_WORDSIZE. The first patch has been committed.
Ok but note that word size == pointer size is not always true. In fact I'm working on a project where it isn't :-)
(if you're curious: https://savannah.gnu.org/task/?9437)
Quoted 1 line
The second patch should probably go after the qemu patch.
Actually, the qemu port won't work without the second patch. I just merged it with mine and made a joint commit (ROM + qemu).
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Re: [PATCH] fix for loading modules from read-only memory area (Re: clean patch for i386-qemu port (Re: [PATCH] i386-qemu port))
Quoted 4 lines · Robert Millan
Ok but note that word size == pointer size is not always true. In fact I'm working on a project where it isn't :-)
(if you're curious: https://savannah.gnu.org/task/?9437)
OK, when GRUB is changed to support that architecture, we'll make the necessary adjustments.
Quoted 4 lines
Quoted 1 line
The second patch should probably go after the qemu patch.
Actually, the qemu port won't work without the second patch. I just merged it with mine and made a joint commit (ROM + qemu).
Good. Thank you!
Signature · 2 lines
Regards, Pavel Roskin