Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
On 10.11.2015 15:38, Daniel Kiper wrote: >>> - if (entry_specified) >>> > > + if (keep_bs && efi_entry_specified) >>> > > +grub_multiboot_payload_eip = efi_entry; >>> > > + else if (entry_specified) >>> > > grub_multiboot_payload_eip = entry; >>> > > >> > This seems redundant. > What is wrong here? I just mean that if we use a single structure this code could go away signature.asc Description: OpenPGP digital signature ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
On Mon, Nov 09, 2015 at 09:05:15PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko wrote: > On 20.07.2015 16:35, Daniel Kiper wrote: > > Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms > > when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. > > Relocator > > will set lower parts of %rax and %rbx accordingly to multiboot2 > > specification. > > On the other hand processor mode, just before jumping into loaded image, > > will > > be set accordingly to Unified Extensible Firmware Interface Specification, > > Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way > > loaded image will be able to use EFI boot services without any issues. > > > > If idea is accepted I will prepare grub_relocator32_efi relocator too. > > > > Signed-off-by: Daniel Kiper> > --- > > grub-core/Makefile.core.def |1 + > > grub-core/lib/i386/relocator.c | 53 +++ > > grub-core/lib/i386/relocator64_efi.S | 77 > > ++ > > grub-core/loader/multiboot.c | 29 +++-- > > grub-core/loader/multiboot_mbi2.c| 19 +++-- > > include/grub/i386/multiboot.h| 11 + > > include/grub/i386/relocator.h| 21 ++ > > include/multiboot2.h |9 > > 8 files changed, 213 insertions(+), 7 deletions(-) > > create mode 100644 grub-core/lib/i386/relocator64_efi.S > > > > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def > > index a6101de..d583549 100644 > > --- a/grub-core/Makefile.core.def > > +++ b/grub-core/Makefile.core.def > > @@ -1519,6 +1519,7 @@ module = { > >x86 = lib/i386/relocator_common_c.c; > >ieee1275 = lib/ieee1275/relocator.c; > >efi = lib/efi/relocator.c; > > + x86_64_efi = lib/i386/relocator64_efi.S; > >mips = lib/mips/relocator_asm.S; > >mips = lib/mips/relocator.c; > >powerpc = lib/powerpc/relocator_asm.S; > > diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c > > index 71dd4f0..459027e 100644 > > --- a/grub-core/lib/i386/relocator.c > > +++ b/grub-core/lib/i386/relocator.c > > @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi; > > extern grub_addr_t grub_relocator64_cr3; > > extern struct grub_i386_idt grub_relocator16_idt; > > > > +#ifdef GRUB_MACHINE_EFI > > +#ifdef __x86_64__ > > +extern grub_uint8_t grub_relocator64_efi_start; > > +extern grub_uint8_t grub_relocator64_efi_end; > > +extern grub_uint64_t grub_relocator64_efi_rax; > > +extern grub_uint64_t grub_relocator64_efi_rbx; > > +extern grub_uint64_t grub_relocator64_efi_rcx; > > +extern grub_uint64_t grub_relocator64_efi_rdx; > > +extern grub_uint64_t grub_relocator64_efi_rip; > > +extern grub_uint64_t grub_relocator64_efi_rsi; > > +#endif > > +#endif > > + > > #define RELOCATOR_SIZEOF(x)(_relocator##x##_end - > > _relocator##x##_start) > > > > grub_err_t > > @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel, > >/* Not reached. */ > >return GRUB_ERR_NONE; > > } > > + > > +#ifdef GRUB_MACHINE_EFI > > +#ifdef __x86_64__ > > +grub_err_t > > +grub_relocator64_efi_boot (struct grub_relocator *rel, > > + struct grub_relocator64_efi_state state) > > +{ > > + grub_err_t err; > > + void *relst; > > + grub_relocator_chunk_t ch; > > + > > + err = grub_relocator_alloc_chunk_align (rel, , 0, > > + 0x4000 - RELOCATOR_SIZEOF > > (64_efi), > > + RELOCATOR_SIZEOF (64_efi), 16, > > + GRUB_RELOCATOR_PREFERENCE_NONE, 1); > > + if (err) > > +return err; > > + > > + grub_relocator64_efi_rax = state.rax; > > + grub_relocator64_efi_rbx = state.rbx; > > + grub_relocator64_efi_rcx = state.rcx; > > + grub_relocator64_efi_rdx = state.rdx; > > + grub_relocator64_efi_rip = state.rip; > > + grub_relocator64_efi_rsi = state.rsi; > > + > > + grub_memmove (get_virtual_current_address (ch), > > _relocator64_efi_start, > > + RELOCATOR_SIZEOF (64_efi)); > > + > > + err = grub_relocator_prepare_relocs (rel, get_physical_target_address > > (ch), > > + , NULL); > > + if (err) > > +return err; > > + > > + ((void (*) (void)) relst) (); > > + > > + /* Not reached. */ > > + return GRUB_ERR_NONE; > > +} > > +#endif > > +#endif > > diff --git a/grub-core/lib/i386/relocator64_efi.S > > b/grub-core/lib/i386/relocator64_efi.S > > new file mode 100644 > > index 000..fcd1964 > > --- /dev/null > > +++ b/grub-core/lib/i386/relocator64_efi.S > > @@ -0,0 +1,77 @@ > > +/* > > + * GRUB -- GRand Unified Bootloader > > + * Copyright (C) 2009,2010 Free Software Foundation, Inc. > > + * Copyright (C) 2014,2015 Oracle Co. > > + * Author: Daniel Kiper > > + * > > + * GRUB is free software: you can redistribute it and/or modify > > + * it under the terms
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
On 20.07.2015 16:35, Daniel Kiper wrote: > Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms > when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator > will set lower parts of %rax and %rbx accordingly to multiboot2 specification. > On the other hand processor mode, just before jumping into loaded image, will > be set accordingly to Unified Extensible Firmware Interface Specification, > Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way > loaded image will be able to use EFI boot services without any issues. > > If idea is accepted I will prepare grub_relocator32_efi relocator too. > > Signed-off-by: Daniel Kiper> --- > grub-core/Makefile.core.def |1 + > grub-core/lib/i386/relocator.c | 53 +++ > grub-core/lib/i386/relocator64_efi.S | 77 > ++ > grub-core/loader/multiboot.c | 29 +++-- > grub-core/loader/multiboot_mbi2.c| 19 +++-- > include/grub/i386/multiboot.h| 11 + > include/grub/i386/relocator.h| 21 ++ > include/multiboot2.h |9 > 8 files changed, 213 insertions(+), 7 deletions(-) > create mode 100644 grub-core/lib/i386/relocator64_efi.S > > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def > index a6101de..d583549 100644 > --- a/grub-core/Makefile.core.def > +++ b/grub-core/Makefile.core.def > @@ -1519,6 +1519,7 @@ module = { >x86 = lib/i386/relocator_common_c.c; >ieee1275 = lib/ieee1275/relocator.c; >efi = lib/efi/relocator.c; > + x86_64_efi = lib/i386/relocator64_efi.S; >mips = lib/mips/relocator_asm.S; >mips = lib/mips/relocator.c; >powerpc = lib/powerpc/relocator_asm.S; > diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c > index 71dd4f0..459027e 100644 > --- a/grub-core/lib/i386/relocator.c > +++ b/grub-core/lib/i386/relocator.c > @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi; > extern grub_addr_t grub_relocator64_cr3; > extern struct grub_i386_idt grub_relocator16_idt; > > +#ifdef GRUB_MACHINE_EFI > +#ifdef __x86_64__ > +extern grub_uint8_t grub_relocator64_efi_start; > +extern grub_uint8_t grub_relocator64_efi_end; > +extern grub_uint64_t grub_relocator64_efi_rax; > +extern grub_uint64_t grub_relocator64_efi_rbx; > +extern grub_uint64_t grub_relocator64_efi_rcx; > +extern grub_uint64_t grub_relocator64_efi_rdx; > +extern grub_uint64_t grub_relocator64_efi_rip; > +extern grub_uint64_t grub_relocator64_efi_rsi; > +#endif > +#endif > + > #define RELOCATOR_SIZEOF(x) (_relocator##x##_end - > _relocator##x##_start) > > grub_err_t > @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel, >/* Not reached. */ >return GRUB_ERR_NONE; > } > + > +#ifdef GRUB_MACHINE_EFI > +#ifdef __x86_64__ > +grub_err_t > +grub_relocator64_efi_boot (struct grub_relocator *rel, > +struct grub_relocator64_efi_state state) > +{ > + grub_err_t err; > + void *relst; > + grub_relocator_chunk_t ch; > + > + err = grub_relocator_alloc_chunk_align (rel, , 0, > + 0x4000 - RELOCATOR_SIZEOF > (64_efi), > + RELOCATOR_SIZEOF (64_efi), 16, > + GRUB_RELOCATOR_PREFERENCE_NONE, 1); > + if (err) > +return err; > + > + grub_relocator64_efi_rax = state.rax; > + grub_relocator64_efi_rbx = state.rbx; > + grub_relocator64_efi_rcx = state.rcx; > + grub_relocator64_efi_rdx = state.rdx; > + grub_relocator64_efi_rip = state.rip; > + grub_relocator64_efi_rsi = state.rsi; > + > + grub_memmove (get_virtual_current_address (ch), > _relocator64_efi_start, > + RELOCATOR_SIZEOF (64_efi)); > + > + err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch), > +, NULL); > + if (err) > +return err; > + > + ((void (*) (void)) relst) (); > + > + /* Not reached. */ > + return GRUB_ERR_NONE; > +} > +#endif > +#endif > diff --git a/grub-core/lib/i386/relocator64_efi.S > b/grub-core/lib/i386/relocator64_efi.S > new file mode 100644 > index 000..fcd1964 > --- /dev/null > +++ b/grub-core/lib/i386/relocator64_efi.S > @@ -0,0 +1,77 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2009,2010 Free Software Foundation, Inc. > + * Copyright (C) 2014,2015 Oracle Co. > + * Author: Daniel Kiper > + * > + * 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
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
On Mon, Jul 20, 2015 at 04:35:51PM +0200, Daniel Kiper wrote: Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator will set lower parts of %rax and %rbx accordingly to multiboot2 specification. On the other hand processor mode, just before jumping into loaded image, will be set accordingly to Unified Extensible Firmware Interface Specification, Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way loaded image will be able to use EFI boot services without any issues. Andrei, Valdimir: ping? If idea is accepted I will prepare grub_relocator32_efi relocator too. Signed-off-by: Daniel Kiper daniel.ki...@oracle.com --- grub-core/Makefile.core.def |1 + grub-core/lib/i386/relocator.c | 53 +++ grub-core/lib/i386/relocator64_efi.S | 77 ++ grub-core/loader/multiboot.c | 29 +++-- grub-core/loader/multiboot_mbi2.c| 19 +++-- include/grub/i386/multiboot.h| 11 + include/grub/i386/relocator.h| 21 ++ include/multiboot2.h |9 8 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 grub-core/lib/i386/relocator64_efi.S diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index a6101de..d583549 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1519,6 +1519,7 @@ module = { x86 = lib/i386/relocator_common_c.c; ieee1275 = lib/ieee1275/relocator.c; efi = lib/efi/relocator.c; + x86_64_efi = lib/i386/relocator64_efi.S; mips = lib/mips/relocator_asm.S; mips = lib/mips/relocator.c; powerpc = lib/powerpc/relocator_asm.S; diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c index 71dd4f0..459027e 100644 --- a/grub-core/lib/i386/relocator.c +++ b/grub-core/lib/i386/relocator.c @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi; extern grub_addr_t grub_relocator64_cr3; extern struct grub_i386_idt grub_relocator16_idt; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +extern grub_uint8_t grub_relocator64_efi_start; +extern grub_uint8_t grub_relocator64_efi_end; +extern grub_uint64_t grub_relocator64_efi_rax; +extern grub_uint64_t grub_relocator64_efi_rbx; +extern grub_uint64_t grub_relocator64_efi_rcx; +extern grub_uint64_t grub_relocator64_efi_rdx; +extern grub_uint64_t grub_relocator64_efi_rip; +extern grub_uint64_t grub_relocator64_efi_rsi; +#endif +#endif + #define RELOCATOR_SIZEOF(x) (grub_relocator##x##_end - grub_relocator##x##_start) grub_err_t @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel, /* Not reached. */ return GRUB_ERR_NONE; } + +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +grub_err_t +grub_relocator64_efi_boot (struct grub_relocator *rel, +struct grub_relocator64_efi_state state) +{ + grub_err_t err; + void *relst; + grub_relocator_chunk_t ch; + + err = grub_relocator_alloc_chunk_align (rel, ch, 0, + 0x4000 - RELOCATOR_SIZEOF (64_efi), + RELOCATOR_SIZEOF (64_efi), 16, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) +return err; + + grub_relocator64_efi_rax = state.rax; + grub_relocator64_efi_rbx = state.rbx; + grub_relocator64_efi_rcx = state.rcx; + grub_relocator64_efi_rdx = state.rdx; + grub_relocator64_efi_rip = state.rip; + grub_relocator64_efi_rsi = state.rsi; + + grub_memmove (get_virtual_current_address (ch), grub_relocator64_efi_start, + RELOCATOR_SIZEOF (64_efi)); + + err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch), +relst, NULL); + if (err) +return err; + + ((void (*) (void)) relst) (); + + /* Not reached. */ + return GRUB_ERR_NONE; +} +#endif +#endif diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S new file mode 100644 index 000..fcd1964 --- /dev/null +++ b/grub-core/lib/i386/relocator64_efi.S @@ -0,0 +1,77 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009,2010 Free Software Foundation, Inc. + * Copyright (C) 2014,2015 Oracle Co. + * Author: Daniel Kiper + * + * 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
[PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
Add grub_relocator64_efi relocator. It will be used on EFI 64-bit platforms when multiboot2 compatible image requests MULTIBOOT_TAG_TYPE_EFI_BS. Relocator will set lower parts of %rax and %rbx accordingly to multiboot2 specification. On the other hand processor mode, just before jumping into loaded image, will be set accordingly to Unified Extensible Firmware Interface Specification, Version 2.4 Errata B, section 2.3.4, x64 Platforms, boot services. This way loaded image will be able to use EFI boot services without any issues. If idea is accepted I will prepare grub_relocator32_efi relocator too. Signed-off-by: Daniel Kiper daniel.ki...@oracle.com --- grub-core/Makefile.core.def |1 + grub-core/lib/i386/relocator.c | 53 +++ grub-core/lib/i386/relocator64_efi.S | 77 ++ grub-core/loader/multiboot.c | 29 +++-- grub-core/loader/multiboot_mbi2.c| 19 +++-- include/grub/i386/multiboot.h| 11 + include/grub/i386/relocator.h| 21 ++ include/multiboot2.h |9 8 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 grub-core/lib/i386/relocator64_efi.S diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index a6101de..d583549 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1519,6 +1519,7 @@ module = { x86 = lib/i386/relocator_common_c.c; ieee1275 = lib/ieee1275/relocator.c; efi = lib/efi/relocator.c; + x86_64_efi = lib/i386/relocator64_efi.S; mips = lib/mips/relocator_asm.S; mips = lib/mips/relocator.c; powerpc = lib/powerpc/relocator_asm.S; diff --git a/grub-core/lib/i386/relocator.c b/grub-core/lib/i386/relocator.c index 71dd4f0..459027e 100644 --- a/grub-core/lib/i386/relocator.c +++ b/grub-core/lib/i386/relocator.c @@ -69,6 +69,19 @@ extern grub_uint64_t grub_relocator64_rsi; extern grub_addr_t grub_relocator64_cr3; extern struct grub_i386_idt grub_relocator16_idt; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +extern grub_uint8_t grub_relocator64_efi_start; +extern grub_uint8_t grub_relocator64_efi_end; +extern grub_uint64_t grub_relocator64_efi_rax; +extern grub_uint64_t grub_relocator64_efi_rbx; +extern grub_uint64_t grub_relocator64_efi_rcx; +extern grub_uint64_t grub_relocator64_efi_rdx; +extern grub_uint64_t grub_relocator64_efi_rip; +extern grub_uint64_t grub_relocator64_efi_rsi; +#endif +#endif + #define RELOCATOR_SIZEOF(x)(grub_relocator##x##_end - grub_relocator##x##_start) grub_err_t @@ -214,3 +227,43 @@ grub_relocator64_boot (struct grub_relocator *rel, /* Not reached. */ return GRUB_ERR_NONE; } + +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +grub_err_t +grub_relocator64_efi_boot (struct grub_relocator *rel, + struct grub_relocator64_efi_state state) +{ + grub_err_t err; + void *relst; + grub_relocator_chunk_t ch; + + err = grub_relocator_alloc_chunk_align (rel, ch, 0, + 0x4000 - RELOCATOR_SIZEOF (64_efi), + RELOCATOR_SIZEOF (64_efi), 16, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) +return err; + + grub_relocator64_efi_rax = state.rax; + grub_relocator64_efi_rbx = state.rbx; + grub_relocator64_efi_rcx = state.rcx; + grub_relocator64_efi_rdx = state.rdx; + grub_relocator64_efi_rip = state.rip; + grub_relocator64_efi_rsi = state.rsi; + + grub_memmove (get_virtual_current_address (ch), grub_relocator64_efi_start, + RELOCATOR_SIZEOF (64_efi)); + + err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch), + relst, NULL); + if (err) +return err; + + ((void (*) (void)) relst) (); + + /* Not reached. */ + return GRUB_ERR_NONE; +} +#endif +#endif diff --git a/grub-core/lib/i386/relocator64_efi.S b/grub-core/lib/i386/relocator64_efi.S new file mode 100644 index 000..fcd1964 --- /dev/null +++ b/grub-core/lib/i386/relocator64_efi.S @@ -0,0 +1,77 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009,2010 Free Software Foundation, Inc. + * Copyright (C) 2014,2015 Oracle Co. + * Author: Daniel Kiper + * + * 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/. + */ + +#include relocator_common.S + +