multiboot2: Add two extensions and fix some issues
v2 cover multiboot2: Add two extensions and fix some issues
Hi,
This patch series:
- enables EFI boot services usage in loaded images by multiboot2 protocol,
- add support for multiboot2 protocol compatible relocatable images,
- fixes two minor issues.
Daniel
.gitignore | 3 ++ grub-core/Makefile.core.def | 1 + grub-core/lib/i386/relocator.c | 53 +++++++++++++++++++++ grub-core/lib/i386/relocator64_efi.S | 77 ++++++++++++++++++++++++++++++ grub-core/lib/relocator.c | 2 +- grub-core/loader/i386/multiboot_mbi.c | 6 ++- grub-core/loader/multiboot.c | 41 +++++++++++++--- grub-core/loader/multiboot_elfxx.c | 28 ++++++++--- grub-core/loader/multiboot_mbi2.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- include/grub/i386/multiboot.h | 11 +++++ include/grub/i386/relocator.h | 21 +++++++++ include/grub/multiboot.h | 4 +- include/multiboot2.h | 49 +++++++++++++++++++ 13 files changed, 423 insertions(+), 72 deletions(-)
Daniel Kiper (6):
gitignore: Ignore *.orig, *.rej and *.swp files
relocator: Do not use memory region if its starta is smaller than size i386/relocator: Add grub_relocator64_efi relocator
multiboot2: Add tags used to pass ImageHandle to loaded image
multiboot2: Add support for relocatable images
multiboot2: Do not pass memory maps to image if EFI boot services are enabled
PATCH v2 1/6 gitignore: Ignore *.orig, *.rej and *.swp files
--- .gitignore | 3 +++ 1 file changed, 3 insertions(+)
.gitignore +3 -0
@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test
@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test +*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.c
Signature · 1 line
1.7.10.4
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
but really - this is quite easy to review :-)
Quoted 31 lines
--- .gitignore | 3 +++ 1 file changed, 3 insertions(+).gitignore +3
-0@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test +*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.cSignature · 1 line
1.7.10.4
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Daniel KiperQuoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
but really - this is quite easy to review :-)
Quoted 31 lines
--- .gitignore | 3 +++ 1 file changed, 3 insertions(+).gitignore +3
-0@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test +*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.cSignature · 1 line
1.7.10.4
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Daniel Kiper(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be useful please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent about *.orig.
Quoted 28 lines
--- .gitignore | 3 +++ 1 file changed, 3 insertions(+).gitignore +3
-0@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test +*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.c
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Daniel Kiper(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be useful please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent about *.orig.
Quoted 28 lines
--- .gitignore | 3 +++ 1 file changed, 3 insertions(+).gitignore +3
-0@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test +*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.c
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 7 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
Quoted 7 lines
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Quoted 20 lines
Quoted 20 lines
--- .gitignore | 3 +++ 1 file changed, 3 insertions(+).gitignore +1
-0@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test
Quoted 8 lines
.gitignore po/stamp-po · line 171
Quoted 8 lines
.gitignore +2
-0+*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.c
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Ian CampbellQuoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 7 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
Quoted 7 lines
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Quoted 28 lines
Quoted 28 lines
--- .gitignore | 3 +++ 1 file changed, 3 insertions(+).gitignore +3
-0@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test +*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.c
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
Quoted 16 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 10 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
Quoted 8 lines
Quoted 4 lines
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
Daniel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Vladimir 'phcoder' SerbinenkoQuoted 16 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 10 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
Quoted 8 lines
Quoted 4 lines
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
Daniel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
Quoted 21 lines · Daniel Kiper
Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 14 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
Quoted 9 lines
Quoted 4 lines
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
I will go through them today
Quoted 2 lines
Daniel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
Quoted 25 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 24 lines · Daniel Kiper
Quoted 23 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 7 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>Quoted 7 lines
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
I will go through them today
Thanks a lot!
Daniel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
Quoted 28 lines · Daniel Kiper
Quoted 27 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 26 lines · Daniel Kiper
Quoted 24 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 7 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>Quoted 7 lines
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
I will go through them today
Thanks a lot!
All reviewed. Some of them already good but they have dependencies. Feel free to either fix concerns with dependencies or rebase in a way to get the good ones committed first in a meaningful way
Quoted 2 lines
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Daniel KiperQuoted 28 lines · Daniel Kiper
Quoted 27 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 26 lines · Daniel Kiper
Quoted 24 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 7 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>Quoted 7 lines
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
I will go through them today
Thanks a lot!
All reviewed. Some of them already good but they have dependencies. Feel free to either fix concerns with dependencies or rebase in a way to get the good ones committed first in a meaningful way
Quoted 2 lines
Daniel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Vladimir 'φ-coder/phcoder' SerbinenkoQuoted 25 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 24 lines · Daniel Kiper
Quoted 23 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 7 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>Quoted 7 lines
At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
about
Quoted 2 lines
*.orig.
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
I will go through them today
Thanks a lot!
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 1/6] gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Daniel KiperQuoted 21 lines · Daniel Kiper
Quoted 20 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Ian Campbell
(Having written the below I see too late that this is a grub patch not a Xen one, a tag in the subject for such cross posted patches would be
useful
Quoted 14 lines
please. Anyway, my opinion counts for very little in this context but I leave it below since already I wrote it. I notice that xen.git#.gitignore _does_ list *.rej, which I think is wrong...)
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>At least *.rej and perhaps *.orig are indicative of a failed patch application, I think I want them to appear in "git status".
By way of comparison Linux's .gitignore includes *.orig but not *.rej and Qemu's includes neither.
So nack to the addition of *.rej from me. I'm more or less ambivalent
Quoted 9 lines
Quoted 4 lines
about
Quoted 2 lines
*.orig.
I have to agree. You should clean up *.rej *.orig after fixing conflicts
Thanks for comment on this. Could you review rest of this patchset? I am working on v3 and it will be nice to take your (and others if possible) comments into it.
I will go through them today
Quoted 2 lines
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 1/6 gitignore: Ignore *.orig, *.rej and *.swp files
In reply to Daniel Kiper--- .gitignore | 3 +++ 1 file changed, 3 insertions(+)
.gitignore +3 -0
@@ -147,6 +147,7 @@ mod-*.c missing netboot_test *.o +*.orig *.a ohci_test partmap_test
@@ -160,9 +161,11 @@ po/stamp-po printf_test priority_queue_unit_test pseries_test +*.rej stamp-h stamp-h1 stamp-h.in +*.swp symlist.c symlist.h trigtables.c
Signature · 1 line
1.7.10.4
PATCH v2 2/6 relocator: Do not use memory region if its starta is smaller than size
In reply to Daniel Kipermalloc_in_range() should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000 lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000 lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000 lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000 lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000 lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000 lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/lib/relocator.c +1 -1
@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size) { target = starta - size;if (target > end - size)
Signature · 1 line
1.7.10.4
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
Quoted 22 lines · Daniel Kiper
malloc_in_range()should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000lib/relocator.c:1241:min_addr=0x0,max_addr=0xffffffffffffffff, target =0x800000lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000Signed-off-by Daniel Kiper <[email protected]>--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)grub-core/lib/relocator.c +0
-0
grub-core/lib/relocator.c malloc_in_range (struct grub_relocator *rel, · line 751
Quoted 5 lines
grub-core/lib/relocator.c +1
-1@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
That's too late, we need to check end of region on previous iteration. Consider region of 128 bytes, requested size 129 and alignment 256. Than starta still ends up high in memory.
Quoted 11 lines
grub-core/lib/relocator.c +0
-1{ target = starta - size;if (target > end - size) --1.7.10.4
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
In reply to Daniel KiperQuoted 22 lines · Daniel Kiper
malloc_in_range()should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000lib/relocator.c:1241:min_addr=0x0,max_addr=0xffffffffffffffff, target =0x800000lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000Signed-off-by Daniel Kiper <[email protected]>--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)grub-core/lib/relocator.c +0
-0
grub-core/lib/relocator.c malloc_in_range (struct grub_relocator *rel, · line 751
Quoted 5 lines
grub-core/lib/relocator.c +1
-1@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)
That's too late, we need to check end of region on previous iteration. Consider region of 128 bytes, requested size 129 and alignment 256. Than starta still ends up high in memory.
Quoted 11 lines
grub-core/lib/relocator.c +0
-1{ target = starta - size;if (target > end - size) --1.7.10.4
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
Quoted 18 lines · Andrei Borzenkov
Quoted 17 lines · Daniel Kiper
malloc_in_range()should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000lib/relocator.c:1241:min_addr=0x0,max_addr=0xffffffffffffffff, target =0x800000lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000Signed-off-by Daniel Kiper <[email protected]>--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
grub-core/lib/relocator.c malloc_in_range (struct grub_relocator *rel, · line 751
Quoted 10 lines
grub-core/lib/relocator.c +1
-1@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)That's too late, we need to check end of region on previous iteration. Consider region of 128 bytes, requested size 129 and alignment 256. Than starta still ends up high in memory.
Agreed, we need a check earlier. It makes sense to split this block with an if (from_low_priv) as both flows are completely separate and splitting them will make it more readable
Quoted 7 lines
Quoted 7 lines
grub-core/lib/relocator.c +0
-1{ target = starta - size;if (target > end - size) --1.7.10.4
Quoted 5 lines
Quoted 4 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
In reply to Andrei BorzenkovQuoted 18 lines · Andrei Borzenkov
Quoted 17 lines · Daniel Kiper
malloc_in_range()should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000lib/relocator.c:1241:min_addr=0x0,max_addr=0xffffffffffffffff, target =0x800000lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000Signed-off-by Daniel Kiper <[email protected]>--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
grub-core/lib/relocator.c malloc_in_range (struct grub_relocator *rel, · line 751
Quoted 10 lines
grub-core/lib/relocator.c +1
-1@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size)That's too late, we need to check end of region on previous iteration. Consider region of 128 bytes, requested size 129 and alignment 256. Than starta still ends up high in memory.
Agreed, we need a check earlier. It makes sense to split this block with an if (from_low_priv) as both flows are completely separate and splitting them will make it more readable
Quoted 12 lines
Quoted 11 lines
grub-core/lib/relocator.c +0
-1{ target = starta - size;if (target > end - size) --1.7.10.4
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
In reply to Daniel KiperApplied, thanks
Quoted 23 lines · Daniel Kiper
malloc_in_range()should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000lib/relocator.c:1241:min_addr=0x0,max_addr=0xffffffffffffffff, target =0x800000lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000Signed-off-by Daniel Kiper <[email protected]>--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)grub-core/lib/relocator.c +0
-0
grub-core/lib/relocator.c malloc_in_range (struct grub_relocator *rel, · line 754
Quoted 8 lines
grub-core/lib/relocator.c +1
-1@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size) { target = starta - size;if (target > end - size)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
In reply to Daniel KiperApplied, thanks
Quoted 31 lines · Daniel Kiper
malloc_in_range()should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000lib/relocator.c:1241:min_addr=0x0,max_addr=0xffffffffffffffff, target =0x800000lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned0x1size0x3f800000lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned0x1size0x3f800000lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000Signed-off-by Daniel Kiper <[email protected]>--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)grub-core/lib/relocator.c +1
-1@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size) { target = starta - size;if (target > end - size)
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko
Applied, thanks
Thanks but here http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
In reply to Vladimir 'φ-coder/phcoder' SerbinenkoQuoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko
Applied, thanks
Thanks but here http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?
Daniel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
Le ven. 12 févr. 2016 20:01, Daniel Kiper <[email protected]> a écrit :
Quoted 12 lines
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko
Applied, thanks
Thanks but here
http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here
http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?
Quoted 2 lines
Daniel
Yes, I changed your patch before committing
Quoted 1 line
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
In reply to Daniel KiperLe ven. 12 févr. 2016 20:01, Daniel Kiper <[email protected]> a écrit :
Quoted 12 lines
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko
Applied, thanks
Thanks but here
http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here
http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?
Quoted 2 lines
Daniel
Yes, I changed your patch before committing
Quoted 1 line
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
Quoted 15 lines · Vladimir 'phcoder' Serbinenko
Le ven. 12 févr. 2016 20:01, Daniel Kiper <[email protected]> a écrit :
Quoted 12 lines
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko
Applied, thanks
Thanks but here
http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here
http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?
Quoted 3 lines
Quoted 2 lines
Daniel
Yes, I changed your patch before committing
Great! Thanks a lot!
Daniel
Re: [PATCH v2 2/6] relocator: Do not use memory region if its starta is smaller than size
In reply to Vladimir 'phcoder' SerbinenkoQuoted 15 lines · Vladimir 'phcoder' Serbinenko
Le ven. 12 févr. 2016 20:01, Daniel Kiper <[email protected]> a écrit :
Quoted 12 lines
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko
Applied, thanks
Thanks but here
http://lists.gnu.org/archive/html/grub-devel/2015-07/msg00100.html
Andrei and later here
http://lists.gnu.org/archive/html/grub-devel/2015-11/msg00110.html
you expressed concerns that patch is wrong and it should be fixed. Does anything have changed?
Quoted 3 lines
Quoted 2 lines
Daniel
Yes, I changed your patch before committing
Great! Thanks a lot!
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 2/6 relocator: Do not use memory region if its starta is smaller than size
In reply to Daniel Kipermalloc_in_range() should not use memory region if its starta is smaller than size. Otherwise target wraps around and points to region which is usually not a RAM, e.g.:
loader/multiboot.c:93: segment 0: paddr=0x800000, memsz=0x3f800000, vaddr=0x800000 lib/relocator.c:1241: min_addr = 0x0, max_addr = 0xffffffffffffffff, target = 0x800000 lib/relocator.c:434: trying to allocate in 0x800000-0xffffffffffffffff aligned 0x1 size 0x3f800000 lib/relocator.c:434: trying to allocate in 0x0-0x800000 aligned 0x1 size 0x3f800000 lib/relocator.c:434: trying to allocate in 0x0-0xffffffffffffffff aligned 0x1 size 0x3f800000 lib/relocator.c:1188: allocated: 0xffffffffc07fffff+0x3f800000 lib/relocator.c:1277: allocated 0xffffffffc07fffff/0x800000
--- grub-core/lib/relocator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/lib/relocator.c +1 -1
@@ -748,7 +748,7 @@ malloc_in_range (struct grub_relocator *rel,/* Found an usable address. */ goto found; } -if (isinsidebefore && !isinsideafter && !from_low_priv) +if (isinsidebefore && !isinsideafter && !from_low_priv && starta >= size) { target = starta - size;if (target > end - size)
Signature · 1 line
1.7.10.4
PATCH v2 3/6 i386/relocator: Add grub_relocator64_efi relocator
In reply to Daniel KiperAdd 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.
--- 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
grub-core/Makefile.core.def +1 -0
@@ -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;
grub-core/lib/i386/relocator.c +53 -0
62 lines not on this page · raw message
grub-core/lib/i386/relocator64_efi.S new file +77 -0
77 lines not on this page · raw message
grub-core/loader/multiboot.c +26 -3
@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)return err; } +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define grub_relocator_efi_boot grub_relocator64_efi_boot +#endif +#endif +static grub_err_t grub_multiboot_boot (void ) {grub_err_t err; +grub_uint32_t target;struct grub_relocator32_state state =MULTIBOOT_INITIAL_STATE ; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state state_efi =MULTIBOOT_EFI_INITIAL_STATE ; +#endif +#endif - state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; - - err =grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER); + err =grub_multiboot_make_mbi (&target);if (err)return err; + state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; + state.MULTIBOOT_MBI_REGISTER = target; +#if defined (__i386__) || defined (__x86_64__) +#ifdef GRUB_MACHINE_EFI + state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip; + state_efi.MULTIBOOT_EFI_MBI_REGISTER = target; + +if (grub_efi_is_finished) +grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +else +grub_relocator_efi_boot (grub_multiboot_relocator, state_efi); +#else grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +#endif #else grub_relocator32_boot (grub_multiboot_relocator, state);#endif
grub-core/loader/multiboot_mbi2.c +15 -4
@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 ; -grub_addr_t entry =0 ; +int entry_specified =0 , efi_entry_specified =0 ; +grub_addr_t entry =0 , efi_entry =0 ;grub_uint32_t console_required =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ;
@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename) entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;break ; +case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 : +#if defined (GRUB_MACHINE_EFI ) && defined (__x86_64__) + efi_entry_specified =1 ; + efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr; +#endif +break ; +case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS :if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags &MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED ))
@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ;case MULTIBOOT_HEADER_TAG_EFI_BS : +#ifdef GRUB_MACHINE_EFI keep_bs =1 ; +#endif break ;default :
@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ; } -if (addr_tag && !entry_specified) +if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified)) {grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS,
@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) } } -if (entry_specified) +if (keep_bs && efi_entry_specified) + grub_multiboot_payload_eip = efi_entry; +else if (entry_specified) grub_multiboot_payload_eip = entry;if (fbtag)
include/grub/i386/multiboot.h +11 -0
@@ -30,6 +30,17 @@#define MULTIBOOT_MBI_REGISTER ebx#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386 +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define MULTIBOOT_EFI_INITIAL_STATE { .rax = MULTIBOOT_BOOTLOADER_MAGIC, \ + .rcx = 0, \ + .rdx = 0, \ + } +#define MULTIBOOT_EFI_ENTRY_REGISTER rip +#define MULTIBOOT_EFI_MBI_REGISTER rbx +#endif +#endif +#define MULTIBOOT_ELF32_MACHINE EM_386#define MULTIBOOT_ELF64_MACHINE EM_X86_64
include/grub/i386/relocator.h +21 -0
@@ -65,6 +65,20 @@ struct grub_relocator64_stategrub_addr_t cr3; }; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state +{ +grub_uint64_t rax; +grub_uint64_t rbx; +grub_uint64_t rcx; +grub_uint64_t rdx; +grub_uint64_t rip; +grub_uint64_t rsi; +}; +#endif +#endif +grub_err_t grub_relocator16_boot (struct grub_relocator *rel,struct grub_relocator16_state state);
@@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,struct grub_relocator64_state state, grub_addr_t min_addr, grub_addr_t max_addr); +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel, +struct grub_relocator64_efi_state state); +#endif +#endif +#endif /* ! GRUB_RELOCATOR_CPU_HEADER */
include/multiboot2.h +9 -0
@@ -69,6 +69,7 @@#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7 +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4
@@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_addressmultiboot_uint32_t entry_addr; }; +struct multiboot_header_tag_entry_address_efi64 +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t entry_addr; +}; +struct multiboot_header_tag_console_flags {multiboot_uint16_t type;
Signature · 1 line
1.7.10.4
PATCH v2 3/6 i386/relocator: Add grub_relocator64_efi relocator
In reply to Daniel KiperAdd 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.
--- 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
grub-core/Makefile.core.def +1 -0
@@ -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;
grub-core/lib/i386/relocator.c +53 -0
62 lines not on this page · raw message
grub-core/lib/i386/relocator64_efi.S new file +77 -0
77 lines not on this page · raw message
grub-core/loader/multiboot.c +26 -3
@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)return err; } +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define grub_relocator_efi_boot grub_relocator64_efi_boot +#endif +#endif +static grub_err_t grub_multiboot_boot (void ) {grub_err_t err; +grub_uint32_t target;struct grub_relocator32_state state =MULTIBOOT_INITIAL_STATE ; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state state_efi =MULTIBOOT_EFI_INITIAL_STATE ; +#endif +#endif - state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; - - err =grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER); + err =grub_multiboot_make_mbi (&target);if (err)return err; + state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; + state.MULTIBOOT_MBI_REGISTER = target; +#if defined (__i386__) || defined (__x86_64__) +#ifdef GRUB_MACHINE_EFI + state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip; + state_efi.MULTIBOOT_EFI_MBI_REGISTER = target; + +if (grub_efi_is_finished) +grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +else +grub_relocator_efi_boot (grub_multiboot_relocator, state_efi); +#else grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +#endif #else grub_relocator32_boot (grub_multiboot_relocator, state);#endif
grub-core/loader/multiboot_mbi2.c +15 -4
@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 ; -grub_addr_t entry =0 ; +int entry_specified =0 , efi_entry_specified =0 ; +grub_addr_t entry =0 , efi_entry =0 ;grub_uint32_t console_required =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ;
@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename) entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;break ; +case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 : +#if defined (GRUB_MACHINE_EFI ) && defined (__x86_64__) + efi_entry_specified =1 ; + efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr; +#endif +break ; +case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS :if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags &MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED ))
@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ;case MULTIBOOT_HEADER_TAG_EFI_BS : +#ifdef GRUB_MACHINE_EFI keep_bs =1 ; +#endif break ;default :
@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ; } -if (addr_tag && !entry_specified) +if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified)) {grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS,
@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) } } -if (entry_specified) +if (keep_bs && efi_entry_specified) + grub_multiboot_payload_eip = efi_entry; +else if (entry_specified) grub_multiboot_payload_eip = entry;if (fbtag)
include/grub/i386/multiboot.h +11 -0
@@ -30,6 +30,17 @@#define MULTIBOOT_MBI_REGISTER ebx#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386 +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define MULTIBOOT_EFI_INITIAL_STATE { .rax = MULTIBOOT_BOOTLOADER_MAGIC, \ + .rcx = 0, \ + .rdx = 0, \ + } +#define MULTIBOOT_EFI_ENTRY_REGISTER rip +#define MULTIBOOT_EFI_MBI_REGISTER rbx +#endif +#endif +#define MULTIBOOT_ELF32_MACHINE EM_386#define MULTIBOOT_ELF64_MACHINE EM_X86_64
include/grub/i386/relocator.h +21 -0
@@ -65,6 +65,20 @@ struct grub_relocator64_stategrub_addr_t cr3; }; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state +{ +grub_uint64_t rax; +grub_uint64_t rbx; +grub_uint64_t rcx; +grub_uint64_t rdx; +grub_uint64_t rip; +grub_uint64_t rsi; +}; +#endif +#endif +grub_err_t grub_relocator16_boot (struct grub_relocator *rel,struct grub_relocator16_state state);
@@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,struct grub_relocator64_state state, grub_addr_t min_addr, grub_addr_t max_addr); +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel, +struct grub_relocator64_efi_state state); +#endif +#endif +#endif /* ! GRUB_RELOCATOR_CPU_HEADER */
include/multiboot2.h +9 -0
@@ -69,6 +69,7 @@#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7 +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4
@@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_addressmultiboot_uint32_t entry_addr; }; +struct multiboot_header_tag_entry_address_efi64 +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t entry_addr; +}; +struct multiboot_header_tag_console_flags {multiboot_uint16_t type;
Signature · 1 line
1.7.10.4
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
Quoted 7 lines · Daniel Kiper
Add
grub_relocator64_efirelocator. It will be used on EFI 64-bit platforms when multiboot2 compatible image requestsMULTIBOOT_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?
Quoted 379 lines
If idea is accepted I will prepare
grub_relocator32_efirelocator too.Signed-off-by Daniel Kiper <[email protected]>--- 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.Sgrub-core/Makefile.core.def +1
-0@@ -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;grub-core/lib/i386/relocator.c +53
-0@@ -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 , + 0x40000000 - 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 grub-core/lib/i386/relocator64_efi.S new file +77
-0@@ -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" + + .p2align 4 /* force 16-byte alignment */ + +VARIABLE(grub_relocator64_efi_start) + PREAMBLE + + .code64 + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rsi) + .quad 0 + + movq %rax, %rsi + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rax) + .quad 0 + + /* mov imm64, %rbx */ + .byte 0x48 + .byte 0xbb +VARIABLE(grub_relocator64_efi_rbx) + .quad 0 + + /* mov imm64, %rcx */ + .byte 0x48 + .byte 0xb9 +VARIABLE(grub_relocator64_efi_rcx) + .quad 0 + + /* mov imm64, %rdx */ + .byte 0x48 + .byte 0xba +VARIABLE(grub_relocator64_efi_rdx) + .quad 0 + + /* Cleared direction flag is of no problem with any current + payload and makes this implementation easier. */ + cld + +#ifdef __APPLE__ + .byte 0xff, 0x25 + .quad 0 +#else + jmp *LOCAL(jump_addr) (%rip) +#endif + +LOCAL(jump_addr): +VARIABLE(grub_relocator64_efi_rip) + .quad 0 + +VARIABLE(grub_relocator64_efi_end)grub-core/loader/multiboot.c +26
-3@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)return err; } +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define grub_relocator_efi_boot grub_relocator64_efi_boot +#endif +#endif +static grub_err_t grub_multiboot_boot (void ) {grub_err_t err; +grub_uint32_t target;struct grub_relocator32_state state =MULTIBOOT_INITIAL_STATE ; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state state_efi =MULTIBOOT_EFI_INITIAL_STATE ; +#endif +#endif - state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; - - err =grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER); + err =grub_multiboot_make_mbi (&target);if (err)return err; + state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; + state.MULTIBOOT_MBI_REGISTER = target; +#if defined (__i386__) || defined (__x86_64__) +#ifdef GRUB_MACHINE_EFI + state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip; + state_efi.MULTIBOOT_EFI_MBI_REGISTER = target; + +if (grub_efi_is_finished) +grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +else +grub_relocator_efi_boot (grub_multiboot_relocator, state_efi); +#else grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +#endif #else grub_relocator32_boot (grub_multiboot_relocator, state);#endif grub-core/loader/multiboot_mbi2.c +15
-4@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 ; -grub_addr_t entry =0 ; +int entry_specified =0 , efi_entry_specified =0 ; +grub_addr_t entry =0 , efi_entry =0 ;grub_uint32_t console_required =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ;@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename) entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;break ; +case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 : +#if defined (GRUB_MACHINE_EFI ) && defined (__x86_64__) + efi_entry_specified =1 ; + efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr; +#endif +break ; +case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS :if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags &MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED ))@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ;case MULTIBOOT_HEADER_TAG_EFI_BS : +#ifdef GRUB_MACHINE_EFI keep_bs =1 ; +#endif break ;default :@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ; } -if (addr_tag && !entry_specified) +if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified)) {grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS,@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) } } -if (entry_specified) +if (keep_bs && efi_entry_specified) + grub_multiboot_payload_eip = efi_entry; +else if (entry_specified) grub_multiboot_payload_eip = entry;if (fbtag)include/grub/i386/multiboot.h +11
-0@@ -30,6 +30,17 @@#define MULTIBOOT_MBI_REGISTER ebx#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386 +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define MULTIBOOT_EFI_INITIAL_STATE { .rax = MULTIBOOT_BOOTLOADER_MAGIC, \ + .rcx = 0, \ + .rdx = 0, \ + } +#define MULTIBOOT_EFI_ENTRY_REGISTER rip +#define MULTIBOOT_EFI_MBI_REGISTER rbx +#endif +#endif +#define MULTIBOOT_ELF32_MACHINE EM_386#define MULTIBOOT_ELF64_MACHINE EM_X86_64include/grub/i386/relocator.h +21
-0@@ -65,6 +65,20 @@ struct grub_relocator64_stategrub_addr_t cr3; }; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state +{ +grub_uint64_t rax; +grub_uint64_t rbx; +grub_uint64_t rcx; +grub_uint64_t rdx; +grub_uint64_t rip; +grub_uint64_t rsi; +}; +#endif +#endif +grub_err_t grub_relocator16_boot (struct grub_relocator *rel,struct grub_relocator16_state state);@@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,struct grub_relocator64_state state, grub_addr_t min_addr, grub_addr_t max_addr); +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel, +struct grub_relocator64_efi_state state); +#endif +#endif +#endif /* ! GRUB_RELOCATOR_CPU_HEADER */ include/multiboot2.h +9
-0@@ -69,6 +69,7 @@#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7 +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4@@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_addressmultiboot_uint32_t entry_addr; }; +struct multiboot_header_tag_entry_address_efi64 +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t entry_addr; +}; +struct multiboot_header_tag_console_flags {multiboot_uint16_t type;Signature · 1 line
1.7.10.4
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
In reply to Daniel KiperQuoted 175 lines · Daniel Kiper
Add
grub_relocator64_efirelocator. It will be used on EFI 64-bit platforms when multiboot2 compatible image requestsMULTIBOOT_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_efirelocator too.Signed-off-by Daniel Kiper <[email protected]>--- 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.Sgrub-core/Makefile.core.def +1
-0@@ -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;grub-core/lib/i386/relocator.c +53
-0@@ -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 , + 0x40000000 - 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 grub-core/lib/i386/relocator64_efi.S new file +66
-0@@ -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" + + .p2align 4 /* force 16-byte alignment */ + +VARIABLE(grub_relocator64_efi_start) + PREAMBLE + + .code64 + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rsi) + .quad 0 + + movq %rax, %rsi + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rax) + .quad 0 + + /* mov imm64, %rbx */ + .byte 0x48 + .byte 0xbb +VARIABLE(grub_relocator64_efi_rbx) + .quad 0 + + /* mov imm64, %rcx */ + .byte 0x48 + .byte 0xb9 +VARIABLE(grub_relocator64_efi_rcx) + .quad 0 + + /* mov imm64, %rdx */ + .byte 0x48 + .byte 0xba +VARIABLE(grub_relocator64_efi_rdx) + .quad 0 + + /* Cleared direction flag is of no problem with any current + payload and makes this implementation easier. */ + cld + +#ifdef __APPLE__
grub-core/lib/i386/relocator64_efi.S line 76
Quoted 10 lines
grub-core/lib/i386/relocator64_efi.S new file +10
-0+ .byte 0xff, 0x25 + .quad 0 +#else + jmp *LOCAL(jump_addr) (%rip) +#endif + +LOCAL(jump_addr): +VARIABLE(grub_relocator64_efi_rip) + .quad 0 +
This repeats relocator64 almost exactly. Can we avoid code duplication? It's fine to compile it twice but code duplication is bad.
Quoted 43 lines
grub-core/lib/i386/relocator64_efi.S new file +1
-0+VARIABLE(grub_relocator64_efi_end)grub-core/loader/multiboot.c +20
-3@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)return err; } +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define grub_relocator_efi_boot grub_relocator64_efi_boot +#endif +#endif +static grub_err_t grub_multiboot_boot (void ) {grub_err_t err; +grub_uint32_t target;struct grub_relocator32_state state =MULTIBOOT_INITIAL_STATE ; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state state_efi =MULTIBOOT_EFI_INITIAL_STATE ; +#endif +#endif - state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; - - err =grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER); + err =grub_multiboot_make_mbi (&target);if (err)return err; + state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; + state.MULTIBOOT_MBI_REGISTER = target; +#if defined (__i386__) || defined (__x86_64__) +#ifdef GRUB_MACHINE_EFI + state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip; + state_efi.MULTIBOOT_EFI_MBI_REGISTER = target; +
grub-core/loader/multiboot.c grub_multiboot_set_video_mode (void) · line 161
Quoted 10 lines
grub-core/loader/multiboot.c +6
-0+if (grub_efi_is_finished) +grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +else +grub_relocator_efi_boot (grub_multiboot_relocator, state_efi); +#else grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +#endif #else grub_relocator32_boot (grub_multiboot_relocator, state);#endif
This becomes hairy. I think it's time to split it into platform-specific functions and/or use tricks like
#ifndef GRUB_MACHINE_EFI
#define grub_efi_is_finished 0
#endif
Quoted 16 lines
grub-core/loader/multiboot_mbi2.c +2
-2@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 ; -grub_addr_t entry =0 ; +int entry_specified =0 , efi_entry_specified =0 ; +grub_addr_t entry =0 , efi_entry =0 ;grub_uint32_t console_required =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ;
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 201
Quoted 10 lines
grub-core/loader/multiboot_mbi2.c +7
-0@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename) entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;break ; +case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 : +#if defined (GRUB_MACHINE_EFI ) && defined (__x86_64__) + efi_entry_specified =1 ; + efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr; +#endif +break ; +
Why do we need separate handling of EFI entry point? Why can't we use the same structure?
Quoted 23 lines
grub-core/loader/multiboot_mbi2.c +3
-1case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS :if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags &MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED ))@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ;case MULTIBOOT_HEADER_TAG_EFI_BS : +#ifdef GRUB_MACHINE_EFI keep_bs =1 ; +#endif break ;default :@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ; } -if (addr_tag && !entry_specified) +if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified)) {grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS,
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 303
Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3
-1@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) } } -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.
Quoted 74 lines
grub-core/loader/multiboot_mbi2.c +0
-0if (fbtag)include/grub/i386/multiboot.h +11
-0@@ -30,6 +30,17 @@#define MULTIBOOT_MBI_REGISTER ebx#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386 +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define MULTIBOOT_EFI_INITIAL_STATE { .rax = MULTIBOOT_BOOTLOADER_MAGIC, \ + .rcx = 0, \ + .rdx = 0, \ + } +#define MULTIBOOT_EFI_ENTRY_REGISTER rip +#define MULTIBOOT_EFI_MBI_REGISTER rbx +#endif +#endif +#define MULTIBOOT_ELF32_MACHINE EM_386#define MULTIBOOT_ELF64_MACHINE EM_X86_64include/grub/i386/relocator.h +21
-0@@ -65,6 +65,20 @@ struct grub_relocator64_stategrub_addr_t cr3; }; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state +{ +grub_uint64_t rax; +grub_uint64_t rbx; +grub_uint64_t rcx; +grub_uint64_t rdx; +grub_uint64_t rip; +grub_uint64_t rsi; +}; +#endif +#endif +grub_err_t grub_relocator16_boot (struct grub_relocator *rel,struct grub_relocator16_state state);@@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,struct grub_relocator64_state state, grub_addr_t min_addr, grub_addr_t max_addr); +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel, +struct grub_relocator64_efi_state state); +#endif +#endif +#endif /* ! GRUB_RELOCATOR_CPU_HEADER */ include/multiboot2.h +1
-0@@ -69,6 +69,7 @@#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7 +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4@@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_addressmultiboot_uint32_t entry_addr;
include/multiboot2.h struct multiboot_header_tag_entry_address · line 144
Quoted 10 lines
include/multiboot2.h +8
-0}; +struct multiboot_header_tag_entry_address_efi64 +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t entry_addr; +}; +
Ditto
include/multiboot2.h struct multiboot_header_tag_entry_address · line 147
Quoted 4 lines
include/multiboot2.h +0
-0struct multiboot_header_tag_console_flags {multiboot_uint16_t type;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
In reply to Daniel KiperQuoted 175 lines · Daniel Kiper
Add
grub_relocator64_efirelocator. It will be used on EFI 64-bit platforms when multiboot2 compatible image requestsMULTIBOOT_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_efirelocator too.Signed-off-by Daniel Kiper <[email protected]>--- 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.Sgrub-core/Makefile.core.def +1
-0@@ -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;grub-core/lib/i386/relocator.c +53
-0@@ -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 , + 0x40000000 - 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 grub-core/lib/i386/relocator64_efi.S new file +66
-0@@ -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" + + .p2align 4 /* force 16-byte alignment */ + +VARIABLE(grub_relocator64_efi_start) + PREAMBLE + + .code64 + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rsi) + .quad 0 + + movq %rax, %rsi + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rax) + .quad 0 + + /* mov imm64, %rbx */ + .byte 0x48 + .byte 0xbb +VARIABLE(grub_relocator64_efi_rbx) + .quad 0 + + /* mov imm64, %rcx */ + .byte 0x48 + .byte 0xb9 +VARIABLE(grub_relocator64_efi_rcx) + .quad 0 + + /* mov imm64, %rdx */ + .byte 0x48 + .byte 0xba +VARIABLE(grub_relocator64_efi_rdx) + .quad 0 + + /* Cleared direction flag is of no problem with any current + payload and makes this implementation easier. */ + cld + +#ifdef __APPLE__
grub-core/lib/i386/relocator64_efi.S line 76
Quoted 10 lines
grub-core/lib/i386/relocator64_efi.S new file +10
-0+ .byte 0xff, 0x25 + .quad 0 +#else + jmp *LOCAL(jump_addr) (%rip) +#endif + +LOCAL(jump_addr): +VARIABLE(grub_relocator64_efi_rip) + .quad 0 +
This repeats relocator64 almost exactly. Can we avoid code duplication? It's fine to compile it twice but code duplication is bad.
Quoted 43 lines
grub-core/lib/i386/relocator64_efi.S new file +1
-0+VARIABLE(grub_relocator64_efi_end)grub-core/loader/multiboot.c +20
-3@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)return err; } +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define grub_relocator_efi_boot grub_relocator64_efi_boot +#endif +#endif +static grub_err_t grub_multiboot_boot (void ) {grub_err_t err; +grub_uint32_t target;struct grub_relocator32_state state =MULTIBOOT_INITIAL_STATE ; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state state_efi =MULTIBOOT_EFI_INITIAL_STATE ; +#endif +#endif - state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; - - err =grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER); + err =grub_multiboot_make_mbi (&target);if (err)return err; + state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; + state.MULTIBOOT_MBI_REGISTER = target; +#if defined (__i386__) || defined (__x86_64__) +#ifdef GRUB_MACHINE_EFI + state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip; + state_efi.MULTIBOOT_EFI_MBI_REGISTER = target; +
grub-core/loader/multiboot.c grub_multiboot_set_video_mode (void) · line 161
Quoted 10 lines
grub-core/loader/multiboot.c +6
-0+if (grub_efi_is_finished) +grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +else +grub_relocator_efi_boot (grub_multiboot_relocator, state_efi); +#else grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +#endif #else grub_relocator32_boot (grub_multiboot_relocator, state);#endif
This becomes hairy. I think it's time to split it into platform-specific functions and/or use tricks like
#ifndef GRUB_MACHINE_EFI
#define grub_efi_is_finished 0
#endif
Quoted 16 lines
grub-core/loader/multiboot_mbi2.c +2
-2@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 ; -grub_addr_t entry =0 ; +int entry_specified =0 , efi_entry_specified =0 ; +grub_addr_t entry =0 , efi_entry =0 ;grub_uint32_t console_required =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ;
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 201
Quoted 10 lines
grub-core/loader/multiboot_mbi2.c +7
-0@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename) entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;break ; +case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 : +#if defined (GRUB_MACHINE_EFI ) && defined (__x86_64__) + efi_entry_specified =1 ; + efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr; +#endif +break ; +
Why do we need separate handling of EFI entry point? Why can't we use the same structure?
Quoted 23 lines
grub-core/loader/multiboot_mbi2.c +3
-1case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS :if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags &MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED ))@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ;case MULTIBOOT_HEADER_TAG_EFI_BS : +#ifdef GRUB_MACHINE_EFI keep_bs =1 ; +#endif break ;default :@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ; } -if (addr_tag && !entry_specified) +if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified)) {grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS,
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 303
Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +3
-1@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) } } -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.
Quoted 74 lines
grub-core/loader/multiboot_mbi2.c +0
-0if (fbtag)include/grub/i386/multiboot.h +11
-0@@ -30,6 +30,17 @@#define MULTIBOOT_MBI_REGISTER ebx#define MULTIBOOT_ARCHITECTURE_CURRENT MULTIBOOT_ARCHITECTURE_I386 +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define MULTIBOOT_EFI_INITIAL_STATE { .rax = MULTIBOOT_BOOTLOADER_MAGIC, \ + .rcx = 0, \ + .rdx = 0, \ + } +#define MULTIBOOT_EFI_ENTRY_REGISTER rip +#define MULTIBOOT_EFI_MBI_REGISTER rbx +#endif +#endif +#define MULTIBOOT_ELF32_MACHINE EM_386#define MULTIBOOT_ELF64_MACHINE EM_X86_64include/grub/i386/relocator.h +21
-0@@ -65,6 +65,20 @@ struct grub_relocator64_stategrub_addr_t cr3; }; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state +{ +grub_uint64_t rax; +grub_uint64_t rbx; +grub_uint64_t rcx; +grub_uint64_t rdx; +grub_uint64_t rip; +grub_uint64_t rsi; +}; +#endif +#endif +grub_err_t grub_relocator16_boot (struct grub_relocator *rel,struct grub_relocator16_state state);@@ -76,4 +90,11 @@ grub_err_t grub_relocator64_boot (struct grub_relocator *rel,struct grub_relocator64_state state, grub_addr_t min_addr, grub_addr_t max_addr); +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +grub_err_t grub_relocator64_efi_boot (struct grub_relocator *rel, +struct grub_relocator64_efi_state state); +#endif +#endif +#endif /* ! GRUB_RELOCATOR_CPU_HEADER */ include/multiboot2.h +1
-0@@ -69,6 +69,7 @@#define MULTIBOOT_HEADER_TAG_FRAMEBUFFER 5#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7 +#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4@@ -133,6 +134,14 @@ struct multiboot_header_tag_entry_addressmultiboot_uint32_t entry_addr;
include/multiboot2.h struct multiboot_header_tag_entry_address · line 144
Quoted 10 lines
include/multiboot2.h +8
-0}; +struct multiboot_header_tag_entry_address_efi64 +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t entry_addr; +}; +
Ditto
Quoted 4 lines
include/multiboot2.h +0
-0struct multiboot_header_tag_console_flags {multiboot_uint16_t type;
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
Quoted 180 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 179 lines · Daniel Kiper
Add
grub_relocator64_efirelocator. It will be used on EFI 64-bit platforms when multiboot2 compatible image requestsMULTIBOOT_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_efirelocator too.Signed-off-by Daniel Kiper <[email protected]>--- 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.Sgrub-core/Makefile.core.def +1
-0@@ -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;grub-core/lib/i386/relocator.c +53
-0@@ -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 , + 0x40000000 - 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 grub-core/lib/i386/relocator64_efi.S new file +70
-0@@ -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" + + .p2align 4 /* force 16-byte alignment */ + +VARIABLE(grub_relocator64_efi_start) + PREAMBLE + + .code64 + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rsi) + .quad 0 + + movq %rax, %rsi + + /* mov imm64, %rax */ + .byte 0x48 + .byte 0xb8 +VARIABLE(grub_relocator64_efi_rax) + .quad 0 + + /* mov imm64, %rbx */ + .byte 0x48 + .byte 0xbb +VARIABLE(grub_relocator64_efi_rbx) + .quad 0 + + /* mov imm64, %rcx */ + .byte 0x48 + .byte 0xb9 +VARIABLE(grub_relocator64_efi_rcx) + .quad 0 + + /* mov imm64, %rdx */ + .byte 0x48 + .byte 0xba +VARIABLE(grub_relocator64_efi_rdx) + .quad 0 + + /* Cleared direction flag is of no problem with any current + payload and makes this implementation easier. */ + cld + +#ifdef __APPLE__ + .byte 0xff, 0x25 + .quad 0 +#else + jmp *LOCAL(jump_addr) (%rip)
Quoted 8 lines
grub-core/lib/i386/relocator64_efi.S line 76
Quoted 6 lines
grub-core/lib/i386/relocator64_efi.S new file +6
-0+#endif + +LOCAL(jump_addr): +VARIABLE(grub_relocator64_efi_rip) + .quad 0 +This repeats relocator64 almost exactly. Can we avoid code duplication? It's fine to compile it twice but code duplication is bad.
I will try to do that.
Quoted 50 lines
Quoted 50 lines
grub-core/lib/i386/relocator64_efi.S new file +1
-0+VARIABLE(grub_relocator64_efi_end)grub-core/loader/multiboot.c +26
-3@@ -118,21 +118,44 @@ grub_multiboot_set_video_mode (void)return err; } +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +#define grub_relocator_efi_boot grub_relocator64_efi_boot +#endif +#endif +static grub_err_t grub_multiboot_boot (void ) {grub_err_t err; +grub_uint32_t target;struct grub_relocator32_state state =MULTIBOOT_INITIAL_STATE ; +#ifdef GRUB_MACHINE_EFI +#ifdef __x86_64__ +struct grub_relocator64_efi_state state_efi =MULTIBOOT_EFI_INITIAL_STATE ; +#endif +#endif - state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; - - err =grub_multiboot_make_mbi (&state.MULTIBOOT_MBI_REGISTER); + err =grub_multiboot_make_mbi (&target);if (err)return err; + state.MULTIBOOT_ENTRY_REGISTER = grub_multiboot_payload_eip; + state.MULTIBOOT_MBI_REGISTER = target; +#if defined (__i386__) || defined (__x86_64__) +#ifdef GRUB_MACHINE_EFI + state_efi.MULTIBOOT_EFI_ENTRY_REGISTER = grub_multiboot_payload_eip; + state_efi.MULTIBOOT_EFI_MBI_REGISTER = target; + +if (grub_efi_is_finished) +grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +else +grub_relocator_efi_boot (grub_multiboot_relocator, state_efi); +#else grub_relocator32_boot (grub_multiboot_relocator, state,0 ); +#endif
Quoted 8 lines
grub-core/loader/multiboot.c grub_multiboot_set_video_mode (void) · line 161
Quoted 3 lines
grub-core/loader/multiboot.c +0
-0#else grub_relocator32_boot (grub_multiboot_relocator, state);#endif This becomes hairy. I think it's time to split it into platform-specific functions and/or use tricks like
#ifndefGRUB_MACHINE_EFI
#definegrub_efi_is_finished0
#endif
OK.
Quoted 19 lines
Quoted 19 lines
grub-core/loader/multiboot_mbi2.c +2
-2@@ -107,8 +107,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 ; -grub_addr_t entry =0 ; +int entry_specified =0 , efi_entry_specified =0 ; +grub_addr_t entry =0 , efi_entry =0 ;grub_uint32_t console_required =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ;@@ -192,6 +192,13 @@ grub_multiboot_load (grub_file_t file, const char *filename) entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;break ;
Quoted 9 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 201
Quoted 7 lines
grub-core/loader/multiboot_mbi2.c +7
-0+case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 : +#if defined (GRUB_MACHINE_EFI ) && defined (__x86_64__) + efi_entry_specified =1 ; + efi_entry = ((struct multiboot_header_tag_entry_address_efi64 *) tag)->entry_addr; +#endif +break ; +Why do we need separate handling of EFI entry point? Why can't we use the same structure?
Make sense.
Quoted 26 lines
Quoted 26 lines
grub-core/loader/multiboot_mbi2.c +3
-1case MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS :if (!(((struct multiboot_header_tag_console_flags *) tag)->console_flags &MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED ))@@ -211,7 +218,9 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ;case MULTIBOOT_HEADER_TAG_EFI_BS : +#ifdef GRUB_MACHINE_EFI keep_bs =1 ; +#endif break ;default :@@ -224,7 +233,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)break ; } -if (addr_tag && !entry_specified) +if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified)) {grub_free (buffer); return grub_error (GRUB_ERR_UNKNOWN_OS,@@ -287,7 +296,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) } }
Quoted 7 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 303
Quoted 6 lines
grub-core/loader/multiboot_mbi2.c +3
-1-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?
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
Quoted 8 lines · Daniel Kiper
Quoted 7 lines
Quoted 7 lines
- if (
entry_specified)Quoted 5 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 302
Quoted 5 lines
grub-core/loader/multiboot_mbi2.c +3
-0+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
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 3/6] i386/relocator: Add grub_relocator64_efi relocator
In reply to Daniel KiperQuoted 8 lines · Daniel Kiper
Quoted 7 lines
Quoted 7 lines
- if (
entry_specified)Quoted 5 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 302
Quoted 5 lines
grub-core/loader/multiboot_mbi2.c +3
-0+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
PATCH v2 4/6 multiboot2: Add tags used to pass ImageHandle to loaded image
In reply to Daniel KiperAdd tags used to pass ImageHandle to loaded image. It is used by at least ExitBootServices() function.
--- grub-core/loader/multiboot_mbi2.c | 46 +++++++++++++++++++++++++++++-------- include/multiboot2.h | 16 +++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-)
grub-core/loader/multiboot_mbi2.c +37 -9
@@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_NETWORK :case MULTIBOOT_TAG_TYPE_EFI_MMAP :case MULTIBOOT_TAG_TYPE_EFI_BS : +case MULTIBOOT_TAG_TYPE_EFI32_IH : +case MULTIBOOT_TAG_TYPE_EFI64_IH :break ;default :
@@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN) +#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) + + efi_mmap_size, MULTIBOOT_TAG_ALIGN) +#endif +ALIGN_UP (sizeof (struct multiboot_tag_old_acpi ) +sizeof (struct grub_acpi_rsdp_v10 ),MULTIBOOT_TAG_ALIGN ) +acpiv2_size () +net_size () -#ifdef GRUB_MACHINE_EFI - +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) - + efi_mmap_size, MULTIBOOT_TAG_ALIGN) -#endif +sizeof (struct multiboot_tag_vbe ) +MULTIBOOT_TAG_ALIGN -1 +sizeof (struct multiboot_tag_apm ) +MULTIBOOT_TAG_ALIGN -1 ; }
@@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)if (keep_bs) { -struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ; - tag->size =sizeof (struct multiboot_tag ); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); + { +struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ; + tag->size =sizeof (struct multiboot_tag ); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + +#ifdef __x86_64__ + { +struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI64_IH ; + tag->size =sizeof (*tag); + tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif + +#ifdef __i386__ + { +struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI32_IH ; + tag->size =sizeof (*tag); + tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif }#endif
include/multiboot2.h +16 -0
@@ -60,6 +60,8 @@#define MULTIBOOT_TAG_TYPE_NETWORK 16#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17#define MULTIBOOT_TAG_TYPE_EFI_BS 18 +#define MULTIBOOT_TAG_TYPE_EFI32_IH 19 +#define MULTIBOOT_TAG_TYPE_EFI64_IH 20#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
@@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmapmultiboot_uint8_t efi_mmap[0 ]; }; +struct multiboot_tag_efi32_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t pointer; +}; + +struct multiboot_tag_efi64_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint64_t pointer; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */
Signature · 1 line
1.7.10.4
PATCH v2 4/6 multiboot2: Add tags used to pass ImageHandle to loaded image
In reply to Daniel KiperAdd tags used to pass ImageHandle to loaded image. It is used by at least ExitBootServices() function.
--- grub-core/loader/multiboot_mbi2.c | 46 +++++++++++++++++++++++++++++-------- include/multiboot2.h | 16 +++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-)
grub-core/loader/multiboot_mbi2.c +37 -9
@@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_NETWORK :case MULTIBOOT_TAG_TYPE_EFI_MMAP :case MULTIBOOT_TAG_TYPE_EFI_BS : +case MULTIBOOT_TAG_TYPE_EFI32_IH : +case MULTIBOOT_TAG_TYPE_EFI64_IH :break ;default :
@@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN) +#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) + + efi_mmap_size, MULTIBOOT_TAG_ALIGN) +#endif +ALIGN_UP (sizeof (struct multiboot_tag_old_acpi ) +sizeof (struct grub_acpi_rsdp_v10 ),MULTIBOOT_TAG_ALIGN ) +acpiv2_size () +net_size () -#ifdef GRUB_MACHINE_EFI - +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) - + efi_mmap_size, MULTIBOOT_TAG_ALIGN) -#endif +sizeof (struct multiboot_tag_vbe ) +MULTIBOOT_TAG_ALIGN -1 +sizeof (struct multiboot_tag_apm ) +MULTIBOOT_TAG_ALIGN -1 ; }
@@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)if (keep_bs) { -struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ; - tag->size =sizeof (struct multiboot_tag ); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); + { +struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ; + tag->size =sizeof (struct multiboot_tag ); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + +#ifdef __x86_64__ + { +struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI64_IH ; + tag->size =sizeof (*tag); + tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif + +#ifdef __i386__ + { +struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI32_IH ; + tag->size =sizeof (*tag); + tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif }#endif
include/multiboot2.h +16 -0
@@ -60,6 +60,8 @@#define MULTIBOOT_TAG_TYPE_NETWORK 16#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17#define MULTIBOOT_TAG_TYPE_EFI_BS 18 +#define MULTIBOOT_TAG_TYPE_EFI32_IH 19 +#define MULTIBOOT_TAG_TYPE_EFI64_IH 20#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
@@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmapmultiboot_uint8_t efi_mmap[0 ]; }; +struct multiboot_tag_efi32_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t pointer; +}; + +struct multiboot_tag_efi64_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint64_t pointer; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */
Signature · 1 line
1.7.10.4
Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
Quoted 1 line · Daniel Kiper
Add tags used to pass ImageHandle to loaded image. It is used
s/loaded image/loaded image if requested./
Quoted 22 lines
by at least
ExitBootServices()function.Signed-off-by Daniel Kiper <[email protected]>--- grub-core/loader/multiboot_mbi2.c | 46 +++++++++++++++++++++++++++++-------- include/multiboot2.h | 16 +++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-)grub-core/loader/multiboot_mbi2.c +2
-0@@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_NETWORK :case MULTIBOOT_TAG_TYPE_EFI_MMAP :case MULTIBOOT_TAG_TYPE_EFI_BS : +case MULTIBOOT_TAG_TYPE_EFI32_IH : +case MULTIBOOT_TAG_TYPE_EFI64_IH :break ;default :
grub-core/loader/multiboot_mbi2.c grub_multiboot_get_mbi_size (void) · line 415
Quoted 7 lines
grub-core/loader/multiboot_mbi2.c +2
-0@@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN) +#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih ),MULTIBOOT_TAG_ALIGN )
Shouldn't they be wrapped with #ifdef __x86_64__ (for efi64_ih) and #ifdef __i386__ for the other?
Or two functions (in the header?) wrapped with proper #ifdef machinery?
Quoted 27 lines
grub-core/loader/multiboot_mbi2.c +7
-9+ +ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) + + efi_mmap_size, MULTIBOOT_TAG_ALIGN) +#endif +ALIGN_UP (sizeof (struct multiboot_tag_old_acpi ) +sizeof (struct grub_acpi_rsdp_v10 ),MULTIBOOT_TAG_ALIGN ) +acpiv2_size () +net_size () -#ifdef GRUB_MACHINE_EFI - +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) - + efi_mmap_size, MULTIBOOT_TAG_ALIGN) -#endif +sizeof (struct multiboot_tag_vbe ) +MULTIBOOT_TAG_ALIGN -1 +sizeof (struct multiboot_tag_apm ) +MULTIBOOT_TAG_ALIGN -1 ; }@@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)if (keep_bs) { -struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ; - tag->size =sizeof (struct multiboot_tag ); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); + { +struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ;
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 925
Quoted 10 lines
grub-core/loader/multiboot_mbi2.c +10
-0+ tag->size =sizeof (struct multiboot_tag ); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + +#ifdef __x86_64__ + { +struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI64_IH ; + tag->size =sizeof (*tag);
The other places where sizeof is used ends up using the full structure so it :
sizeof (struct multiboot_tag_efi64_ih)
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 936
Quoted 11 lines
grub-core/loader/multiboot_mbi2.c +11
-0+ tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif + +#ifdef __i386__ + { +struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI32_IH ; + tag->size =sizeof (*tag);
Ditto.
Quoted 45 lines
grub-core/loader/multiboot_mbi2.c +5
-0+ tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif }#endif include/multiboot2.h +16
-0@@ -60,6 +60,8 @@#define MULTIBOOT_TAG_TYPE_NETWORK 16#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17#define MULTIBOOT_TAG_TYPE_EFI_BS 18 +#define MULTIBOOT_TAG_TYPE_EFI32_IH 19 +#define MULTIBOOT_TAG_TYPE_EFI64_IH 20#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1@@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmapmultiboot_uint8_t efi_mmap[0 ]; }; +struct multiboot_tag_efi32_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t pointer; +}; + +struct multiboot_tag_efi64_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint64_t pointer; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ Signature · 1 line
1.7.10.4
A message that is not in the archive (sent off-list or not yet received): CAEaD8JOPxLVECcUqjj2-x5AeXjbQ9Cd7bOaoe8UPU2t7wdoxpA@mail.gmail.com
Fwd: Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
---------- Message transféré ----------
De : "Vladimir 'phcoder' Serbinenko" <[email protected]>
Date : 9 nov. 2015 8:12 PM
Objet : Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
À : "Konrad Rzeszutek Wilk" <[email protected]>
Cc :
Le 11 août 2015 8:38 PM, "Konrad Rzeszutek Wilk" <[email protected]> a écrit :
Quoted 10 lines · Daniel Kiper
Quoted 1 line
Add tags used to pass ImageHandle to loaded image. It is used
s/loaded image/loaded image if requested./
Quoted 5 lines
by at least
ExitBootServices()function.Signed-off-by Daniel Kiper <[email protected]>--- grub-core/loader/multiboot_mbi2.c | 46
+++++++++++++++++++++++++++++--------
Quoted 4 lines
Review
Quoted 4 lines
include/multiboot2.h | 16 +++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-)(quoted diff) +0
-0
b/grub-core/loader/multiboot_mbi2.c
Quoted 4 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char
Quoted 4 lines
index 8d66e3f..dc9c709 100644
grub-core/loader/multiboot_mbi2.c +0
-0@@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char
*filename)
Quoted 11 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_get_mbi_size (void) · line 410
Quoted 11 lines
grub-core/loader/multiboot_mbi2.c +2
-0case MULTIBOOT_TAG_TYPE_NETWORK :case MULTIBOOT_TAG_TYPE_EFI_MMAP :case MULTIBOOT_TAG_TYPE_EFI_BS : +case MULTIBOOT_TAG_TYPE_EFI32_IH : +case MULTIBOOT_TAG_TYPE_EFI64_IH :break ;default :@@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void) +grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)),
MULTIBOOT_TAG_ALIGN)
Quoted 1 line
grub-core/loader/multiboot_mbi2.c grub_multiboot_get_mbi_size (void) · line 411
Quoted 1 line
grub-core/loader/multiboot_mbi2.c +0
-0+ ALIGN_UP (sizeof (struct multiboot_tag_framebuffer),
MULTIBOOT_TAG_ALIGN)
Quoted 2 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_get_mbi_size (void) · line 413
Quoted 2 lines
grub-core/loader/multiboot_mbi2.c +1
-0+#ifdef GRUB_MACHINE_EFI + ALIGN_UP (sizeof (struct multiboot_tag_efi32),
MULTIBOOT_TAG_ALIGN)
Quoted 1 line
grub-core/loader/multiboot_mbi2.c grub_multiboot_get_mbi_size (void) · line 414
Quoted 1 line
grub-core/loader/multiboot_mbi2.c +0
-0+ ALIGN_UP (sizeof (struct multiboot_tag_efi64),
MULTIBOOT_TAG_ALIGN)
Quoted 1 line
grub-core/loader/multiboot_mbi2.c grub_multiboot_get_mbi_size (void) · line 415
Quoted 1 line
grub-core/loader/multiboot_mbi2.c +1
-0+ + ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih),
MULTIBOOT_TAG_ALIGN)
Quoted 2 lines
Shouldn't they be wrapped with #ifdef
__x86_64__(forefi64_ih) and
#ifdef __i386__
Quoted 2 lines
for the other?
No need. It's just few bytes but not adding ifdef makes it more readable
Quoted 3 lines
Or two functions (in the header?) wrapped with proper #ifdef machinery?
Quoted 1 line
grub-core/loader/multiboot_mbi2.c +1
-0+ + ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih),
MULTIBOOT_TAG_ALIGN)
Quoted 26 lines
Quoted 26 lines
grub-core/loader/multiboot_mbi2.c +6
-9+ +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) + + efi_mmap_size, MULTIBOOT_TAG_ALIGN) +#endif +ALIGN_UP (sizeof (struct multiboot_tag_old_acpi ) +sizeof (struct grub_acpi_rsdp_v10 ),MULTIBOOT_TAG_ALIGN ) +acpiv2_size () +net_size () -#ifdef GRUB_MACHINE_EFI - +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) - + efi_mmap_size, MULTIBOOT_TAG_ALIGN) -#endif +sizeof (struct multiboot_tag_vbe ) +MULTIBOOT_TAG_ALIGN -1 +sizeof (struct multiboot_tag_apm ) +MULTIBOOT_TAG_ALIGN -1 ; }@@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)if (keep_bs) { -struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ; - tag->size =sizeof (struct multiboot_tag ); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); + { +struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ;
Quoted 8 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target)
Quoted 8 lines
grub-core/loader/multiboot_mbi2.c +8
-0+ tag->size =sizeof (struct multiboot_tag ); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + +#ifdef __x86_64__ + { + struct multiboot_tag_efi64_ih *tag = (struct
multiboot_tag_efi64_ih *) ptrorig;
Quoted 4 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 925
Quoted 2 lines
grub-core/loader/multiboot_mbi2.c +2
-0+ tag->type =MULTIBOOT_TAG_TYPE_EFI64_IH ; + tag->size =sizeof (*tag);The other places where sizeof is used ends up using the full structure so
it :
Quoted 3 lines
sizeof (struct
multiboot_tag_efi64_ih)
sizeof (*tag) is fine and is actually better
Quoted 9 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target)
Quoted 9 lines
grub-core/loader/multiboot_mbi2.c +9
-0+ tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif + +#ifdef __i386__ + { + struct multiboot_tag_efi32_ih *tag = (struct
multiboot_tag_efi32_ih *) ptrorig;
Quoted 49 lines
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 936
Quoted 2 lines
grub-core/loader/multiboot_mbi2.c +2
-0+ tag->type =MULTIBOOT_TAG_TYPE_EFI32_IH ; + tag->size =sizeof (*tag);Ditto.
Quoted 45 lines
grub-core/loader/multiboot_mbi2.c +5
-0+ tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif }#endif include/multiboot2.h +16
-1@@ -60,6 +60,8 @@#define MULTIBOOT_TAG_TYPE_NETWORK 16#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17#define MULTIBOOT_TAG_TYPE_EFI_BS 18 +#define MULTIBOOT_TAG_TYPE_EFI32_IH 19 +#define MULTIBOOT_TAG_TYPE_EFI64_IH 20#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1@@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmapmultiboot_uint8_t efi_mmap[0 ]; }; +struct multiboot_tag_efi32_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t pointer; +}; + +struct multiboot_tag_efi64_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint64_t pointer; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ --1.7.10.4
Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
In reply to Daniel KiperQuoted 1 line · Daniel Kiper
Add tags used to pass ImageHandle to loaded image. It is used
s/loaded image/loaded image if requested./
Quoted 22 lines
by at least
ExitBootServices()function.Signed-off-by Daniel Kiper <[email protected]>--- grub-core/loader/multiboot_mbi2.c | 46 +++++++++++++++++++++++++++++-------- include/multiboot2.h | 16 +++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-)grub-core/loader/multiboot_mbi2.c +2
-0@@ -172,6 +172,8 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_NETWORK :case MULTIBOOT_TAG_TYPE_EFI_MMAP :case MULTIBOOT_TAG_TYPE_EFI_BS : +case MULTIBOOT_TAG_TYPE_EFI32_IH : +case MULTIBOOT_TAG_TYPE_EFI64_IH :break ;default :
grub-core/loader/multiboot_mbi2.c grub_multiboot_get_mbi_size (void) · line 415
Quoted 7 lines
grub-core/loader/multiboot_mbi2.c +2
-0@@ -407,16 +409,18 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) + ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN) +#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi32_ih ),MULTIBOOT_TAG_ALIGN )
Shouldn't they be wrapped with #ifdef __x86_64__ (for efi64_ih) and #ifdef __i386__ for the other?
Or two functions (in the header?) wrapped with proper #ifdef machinery?
Quoted 27 lines
grub-core/loader/multiboot_mbi2.c +7
-9+ +ALIGN_UP (sizeof (struct multiboot_tag_efi64_ih ),MULTIBOOT_TAG_ALIGN ) + +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) + + efi_mmap_size, MULTIBOOT_TAG_ALIGN) +#endif +ALIGN_UP (sizeof (struct multiboot_tag_old_acpi ) +sizeof (struct grub_acpi_rsdp_v10 ),MULTIBOOT_TAG_ALIGN ) +acpiv2_size () +net_size () -#ifdef GRUB_MACHINE_EFI - +ALIGN_UP (sizeof (struct multiboot_tag_efi_mmap ) - + efi_mmap_size, MULTIBOOT_TAG_ALIGN) -#endif +sizeof (struct multiboot_tag_vbe ) +MULTIBOOT_TAG_ALIGN -1 +sizeof (struct multiboot_tag_apm ) +MULTIBOOT_TAG_ALIGN -1 ; }@@ -906,11 +910,35 @@ grub_multiboot_make_mbi (grub_uint32_t *target)if (keep_bs) { -struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ; - tag->size =sizeof (struct multiboot_tag ); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); + { +struct multiboot_tag *tag = (struct multiboot_tag *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI_BS ;
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 925
Quoted 10 lines
grub-core/loader/multiboot_mbi2.c +10
-0+ tag->size =sizeof (struct multiboot_tag ); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + +#ifdef __x86_64__ + { +struct multiboot_tag_efi64_ih *tag = (struct multiboot_tag_efi64_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI64_IH ; + tag->size =sizeof (*tag);
The other places where sizeof is used ends up using the full structure so it :
sizeof (struct multiboot_tag_efi64_ih)
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 936
Quoted 11 lines
grub-core/loader/multiboot_mbi2.c +11
-0+ tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif + +#ifdef __i386__ + { +struct multiboot_tag_efi32_ih *tag = (struct multiboot_tag_efi32_ih *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_EFI32_IH ; + tag->size =sizeof (*tag);
Ditto.
Quoted 45 lines
grub-core/loader/multiboot_mbi2.c +5
-0+ tag->pointer = (grub_addr_t ) grub_efi_image_handle; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } +#endif }#endif include/multiboot2.h +16
-0@@ -60,6 +60,8 @@#define MULTIBOOT_TAG_TYPE_NETWORK 16#define MULTIBOOT_TAG_TYPE_EFI_MMAP 17#define MULTIBOOT_TAG_TYPE_EFI_BS 18 +#define MULTIBOOT_TAG_TYPE_EFI32_IH 19 +#define MULTIBOOT_TAG_TYPE_EFI64_IH 20#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1@@ -379,6 +381,20 @@ struct multiboot_tag_efi_mmapmultiboot_uint8_t efi_mmap[0 ]; }; +struct multiboot_tag_efi32_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t pointer; +}; + +struct multiboot_tag_efi64_ih +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint64_t pointer; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ Signature · 1 line
1.7.10.4
A message that is not in the archive (sent off-list or not yet received): CAEaD8JOaS=J22k+Sq=8Ou77pO6yvtgxSLiwuMjAoirSipJhW6g@mail.gmail.com
Re: [PATCH v2 4/6] multiboot2: Add tags used to pass ImageHandle to loaded image
Quoted 141 lines · Vladimir 'phcoder' Serbinenko
Lgtm
Le 20 juil. 2015 4:36 PM, "Daniel Kiper" <[email protected] <mailto:[email protected]>> a écrit :
Add tags used to pass ImageHandle to loaded image. It is used by at least
ExitBootServices()function.Signed-off-by Daniel Kiper <[email protected]<mailto:[email protected]>>
---
grub-core/loader/multiboot_mbi2.c| 46
+++++++++++++++++++++++++++++--------
include/multiboot2.h| 16 +++++++++++++
2 files changed, 53 insertions(+), 9 deletions(-)diff --git
a/grub-core/loader/multiboot_mbi2.cb/grub-core/loader/multiboot_mbi2.c
index 8d66e3f..dc9c709 100644
---a/grub-core/loader/multiboot_mbi2.c
+++b/grub-core/loader/multiboot_mbi2.c
@@ -172,6 +172,8 @@grub_multiboot_load(grub_file_tfile, const char *filename)
caseMULTIBOOT_TAG_TYPE_NETWORK:
caseMULTIBOOT_TAG_TYPE_EFI_MMAP:
caseMULTIBOOT_TAG_TYPE_EFI_BS:
+ caseMULTIBOOT_TAG_TYPE_EFI32_IH:
+ caseMULTIBOOT_TAG_TYPE_EFI64_IH:
break;default:
@@ -407,16 +409,18 @@grub_multiboot_get_mbi_size(void)
+grub_get_multiboot_mmap_count()
* sizeof (structmultiboot_mmap_entry)),
MULTIBOOT_TAG_ALIGN)
+ALIGN_UP(sizeof (structmultiboot_tag_framebuffer),
MULTIBOOT_TAG_ALIGN)
+#ifdefGRUB_MACHINE_EFI
+ALIGN_UP(sizeof (structmultiboot_tag_efi32),
MULTIBOOT_TAG_ALIGN)
+ALIGN_UP(sizeof (structmultiboot_tag_efi64),
MULTIBOOT_TAG_ALIGN)
+ +ALIGN_UP(sizeof (structmultiboot_tag_efi32_ih),
MULTIBOOT_TAG_ALIGN)
+ +ALIGN_UP(sizeof (structmultiboot_tag_efi64_ih),
MULTIBOOT_TAG_ALIGN)
+ +ALIGN_UP(sizeof (structmultiboot_tag_efi_mmap)
+ +efi_mmap_size,MULTIBOOT_TAG_ALIGN)
+#endif
+ALIGN_UP(sizeof (structmultiboot_tag_old_acpi)
+ sizeof (structgrub_acpi_rsdp_v10),
MULTIBOOT_TAG_ALIGN)
+acpiv2_size()
+net_size()
-#ifdefGRUB_MACHINE_EFI
- +ALIGN_UP(sizeof (structmultiboot_tag_efi_mmap)
- +efi_mmap_size,MULTIBOOT_TAG_ALIGN)
-#endif
+ sizeof (structmultiboot_tag_vbe) +MULTIBOOT_TAG_ALIGN- 1
+ sizeof (structmultiboot_tag_apm) +MULTIBOOT_TAG_ALIGN- 1;
}
@@ -906,11 +910,35 @@grub_multiboot_make_mbi(grub_uint32_t*target)if (
keep_bs)
{
- structmultiboot_tag*tag = (structmultiboot_tag*) ptrorig;
-tag->type=MULTIBOOT_TAG_TYPE_EFI_BS;
-tag->size= sizeof (structmultiboot_tag);
- ptrorig +=ALIGN_UP(tag->size,MULTIBOOT_TAG_ALIGN)
- / sizeof (grub_properly_aligned_t);
+ {
+ structmultiboot_tag*tag = (structmultiboot_tag*) ptrorig;
+tag->type=MULTIBOOT_TAG_TYPE_EFI_BS;
+tag->size= sizeof (structmultiboot_tag);
+ ptrorig +=ALIGN_UP(tag->size,MULTIBOOT_TAG_ALIGN)
+ / sizeof (grub_properly_aligned_t);
+ }
+
+#ifdef__x86_64__
+ {
+ structmultiboot_tag_efi64_ih*tag = (struct
multiboot_tag_efi64_ih*) ptrorig;
+tag->type=MULTIBOOT_TAG_TYPE_EFI64_IH;
+tag->size= sizeof (*tag);
+tag->pointer= (grub_addr_t)grub_efi_image_handle;
+ ptrorig +=ALIGN_UP(tag->size,MULTIBOOT_TAG_ALIGN)
+ / sizeof (grub_properly_aligned_t);
+ }
+#endif
+
+#ifdef__i386__
+ {
+ structmultiboot_tag_efi32_ih*tag = (struct
multiboot_tag_efi32_ih*) ptrorig;
+tag->type=MULTIBOOT_TAG_TYPE_EFI32_IH;
+tag->size= sizeof (*tag);
+tag->pointer= (grub_addr_t)grub_efi_image_handle;
+ ptrorig +=ALIGN_UP(tag->size,MULTIBOOT_TAG_ALIGN)
+ / sizeof (grub_properly_aligned_t);
+ }
+#endif
}
#endifdiff --git
a/include/multiboot2.hb/include/multiboot2.hindex b3977e3..9f97ddc 100644
---a/include/multiboot2.h
+++b/include/multiboot2.h
@@ -60,6 +60,8 @@
#defineMULTIBOOT_TAG_TYPE_NETWORK16
#defineMULTIBOOT_TAG_TYPE_EFI_MMAP17
#defineMULTIBOOT_TAG_TYPE_EFI_BS18
+#defineMULTIBOOT_TAG_TYPE_EFI32_IH19
+#defineMULTIBOOT_TAG_TYPE_EFI64_IH20#define
MULTIBOOT_HEADER_TAG_END0 #defineMULTIBOOT_HEADER_TAG_INFORMATION_REQUEST1
@@ -379,6 +381,20 @@ structmultiboot_tag_efi_mmap
multiboot_uint8_tefi_mmap[0];
};+struct
multiboot_tag_efi32_ih
+{
+multiboot_uint32_ttype;
+multiboot_uint32_tsize;
+multiboot_uint32_tpointer;
+};
+
+structmultiboot_tag_efi64_ih
+{
+multiboot_uint32_ttype;
+multiboot_uint32_tsize;
+multiboot_uint64_tpointer;
+};
+
#endif /* !ASM_FILE*/#endif /* !
MULTIBOOT_HEADER*/
--
1.7.10.4
PATCH v2 5/6 multiboot2: Add support for relocatable images
In reply to Daniel Kiper--- grub-core/loader/i386/multiboot_mbi.c | 6 ++-- grub-core/loader/multiboot.c | 12 +++++-- grub-core/loader/multiboot_elfxx.c | 28 +++++++++++---- grub-core/loader/multiboot_mbi2.c | 63 +++++++++++++++++++++++++++++---- include/grub/multiboot.h | 4 ++- include/multiboot2.h | 24 +++++++++++++ 6 files changed, 118 insertions(+), 19 deletions(-)
grub-core/loader/i386/multiboot_mbi.c +4 -2
@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,grub_err_t err;if (grub_multiboot_quirks &GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE ) { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );if (err ==GRUB_ERR_UNKNOWN_OS && (header->flags &MULTIBOOT_AOUT_KLUDGE )) grub_errno = err =GRUB_ERR_NONE ; }
@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,return GRUB_ERR_NONE ; } -return grub_multiboot_load_elf (file, filename, buffer); +return grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 ); } static struct multiboot_header *
grub-core/loader/multiboot.c +9 -3
@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer) +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {if (grub_multiboot_is_elf32 (buffer)) -return grub_multiboot_load_elf32 (file, filename, buffer); +return grub_multiboot_load_elf32 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);else if (grub_multiboot_is_elf64 (buffer)) -return grub_multiboot_load_elf64 (file, filename, buffer); +return grub_multiboot_load_elf64 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);return grub_error (GRUB_ERR_UNKNOWN_OS ,N_ ("invalid arch-dependent ELF magic" )); }
grub-core/loader/multiboot_elfxx.c +21 -7
@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer) }static grub_err_t -CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename,void *buffer) +CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename, +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;char *phdr_base;
@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voiif (phdr (i)->p_paddr +phdr (i)->p_memsz > highest_load) highest_load =phdr (i)->p_paddr +phdr (i)->p_memsz; -grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n" , - i, (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr); +grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx," +"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n" , i, + (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr, + (long ) align, relocatable, avoid_efi_boot_services); {grub_relocator_chunk_t ch; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch,phdr (i)->p_paddr, -phdr (i)->p_memsz); + +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr -phdr (i)->p_memsz, +phdr (i)->p_memsz, align ? align :1 , + preference, avoid_efi_boot_services); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch,phdr (i)->p_paddr, +phdr (i)->p_memsz);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading phdr %d\n" , i);return err; } +if (base_addr) + *base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch); }
@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi +1 , sh->sh_size, sh->sh_addralign,GRUB_RELOCATOR_PREFERENCE_NONE , - 0); + avoid_efi_boot_services);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading shdr %d\n" , i);
grub-core/loader/multiboot_mbi2.c +57 -6
126 lines not on this page · raw message
include/grub/multiboot.h +3 -1
@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer); +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services);extern grub_size_t grub_multiboot_pure_size;extern grub_size_t grub_multiboot_alloc_mbi;extern grub_uint32_t grub_multiboot_payload_eip;
include/multiboot2.h +24 -0
@@ -62,6 +62,7 @@#define MULTIBOOT_TAG_TYPE_EFI_BS 18#define MULTIBOOT_TAG_TYPE_EFI32_IH 19#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT_TAG_TYPE_BASE_ADDR 21#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
@@ -72,11 +73,16 @@#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4#define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_alignmultiboot_uint32_t size; }; +struct multiboot_header_tag_relocatable +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t min_addr; +multiboot_uint32_t max_addr; +multiboot_uint32_t align; +multiboot_uint32_t preference; +}; +struct multiboot_color {multiboot_uint8_t red;
@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ihmultiboot_uint64_t pointer; }; +struct multiboot_tag_base_addr +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t base_addr; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */
Signature · 1 line
1.7.10.4
PATCH v2 5/6 multiboot2: Add support for relocatable images
In reply to Daniel Kiper--- grub-core/loader/i386/multiboot_mbi.c | 6 ++-- grub-core/loader/multiboot.c | 12 +++++-- grub-core/loader/multiboot_elfxx.c | 28 +++++++++++---- grub-core/loader/multiboot_mbi2.c | 63 +++++++++++++++++++++++++++++---- include/grub/multiboot.h | 4 ++- include/multiboot2.h | 24 +++++++++++++ 6 files changed, 118 insertions(+), 19 deletions(-)
grub-core/loader/i386/multiboot_mbi.c +4 -2
@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,grub_err_t err;if (grub_multiboot_quirks &GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE ) { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );if (err ==GRUB_ERR_UNKNOWN_OS && (header->flags &MULTIBOOT_AOUT_KLUDGE )) grub_errno = err =GRUB_ERR_NONE ; }
@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,return GRUB_ERR_NONE ; } -return grub_multiboot_load_elf (file, filename, buffer); +return grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 ); } static struct multiboot_header *
grub-core/loader/multiboot.c +9 -3
@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer) +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {if (grub_multiboot_is_elf32 (buffer)) -return grub_multiboot_load_elf32 (file, filename, buffer); +return grub_multiboot_load_elf32 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);else if (grub_multiboot_is_elf64 (buffer)) -return grub_multiboot_load_elf64 (file, filename, buffer); +return grub_multiboot_load_elf64 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);return grub_error (GRUB_ERR_UNKNOWN_OS ,N_ ("invalid arch-dependent ELF magic" )); }
grub-core/loader/multiboot_elfxx.c +21 -7
@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer) }static grub_err_t -CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename,void *buffer) +CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename, +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;char *phdr_base;
@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voiif (phdr (i)->p_paddr +phdr (i)->p_memsz > highest_load) highest_load =phdr (i)->p_paddr +phdr (i)->p_memsz; -grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n" , - i, (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr); +grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx," +"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n" , i, + (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr, + (long ) align, relocatable, avoid_efi_boot_services); {grub_relocator_chunk_t ch; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch,phdr (i)->p_paddr, -phdr (i)->p_memsz); + +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr -phdr (i)->p_memsz, +phdr (i)->p_memsz, align ? align :1 , + preference, avoid_efi_boot_services); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch,phdr (i)->p_paddr, +phdr (i)->p_memsz);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading phdr %d\n" , i);return err; } +if (base_addr) + *base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch); }
@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi +1 , sh->sh_size, sh->sh_addralign,GRUB_RELOCATOR_PREFERENCE_NONE , - 0); + avoid_efi_boot_services);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading shdr %d\n" , i);
grub-core/loader/multiboot_mbi2.c +57 -6
126 lines not on this page · raw message
include/grub/multiboot.h +3 -1
@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer); +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services);extern grub_size_t grub_multiboot_pure_size;extern grub_size_t grub_multiboot_alloc_mbi;extern grub_uint32_t grub_multiboot_payload_eip;
include/multiboot2.h +24 -0
@@ -62,6 +62,7 @@#define MULTIBOOT_TAG_TYPE_EFI_BS 18#define MULTIBOOT_TAG_TYPE_EFI32_IH 19#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT_TAG_TYPE_BASE_ADDR 21#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1
@@ -72,11 +73,16 @@#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4#define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_alignmultiboot_uint32_t size; }; +struct multiboot_header_tag_relocatable +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t min_addr; +multiboot_uint32_t max_addr; +multiboot_uint32_t align; +multiboot_uint32_t preference; +}; +struct multiboot_color {multiboot_uint8_t red;
@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ihmultiboot_uint64_t pointer; }; +struct multiboot_tag_base_addr +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t base_addr; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */
Signature · 1 line
1.7.10.4
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
On Mon, Jul 20, 2015 at 04:35:53PM +0200, Daniel Kiper wrote:
This parts needs a bit of details I think.
As in why can't the ELF note that is present in the binary be satisfied. Or under what conditions would the existing code not work?
Quoted 25 lines
Signed-off-by Daniel Kiper <[email protected]>--- grub-core/loader/i386/multiboot_mbi.c | 6 ++-- grub-core/loader/multiboot.c | 12 +++++-- grub-core/loader/multiboot_elfxx.c | 28 +++++++++++---- grub-core/loader/multiboot_mbi2.c | 63 +++++++++++++++++++++++++++++---- include/grub/multiboot.h | 4 ++- include/multiboot2.h | 24 +++++++++++++ 6 files changed, 118 insertions(+), 19 deletions(-)grub-core/loader/i386/multiboot_mbi.c +2
-1@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,grub_err_t err;if (grub_multiboot_quirks &GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE ) { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );if (err ==GRUB_ERR_UNKNOWN_OS && (header->flags &MULTIBOOT_AOUT_KLUDGE )) grub_errno = err =GRUB_ERR_NONE ; }
grub-core/loader/i386/multiboot_mbi.c load_kernel (grub_file_t file, const char *filename, · line 123
Quoted 6 lines
grub-core/loader/i386/multiboot_mbi.c +2
-1@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,return GRUB_ERR_NONE ; } -return grub_multiboot_load_elf (file, filename, buffer); +return grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );
Oh boy. That is a bit hard to read. Perhaps another function could be introduced?
grub_multiboot_load_elf_ignore_reloc ? which would just pass the three parameters and set the rest to the 0 options?
Quoted 8 lines
grub-core/loader/i386/multiboot_mbi.c +0
-0} static struct multiboot_header *grub-core/loader/multiboot.c +0
-0
grub-core/loader/multiboot.c static grub_uint64_t highest_load; · line 195
Quoted 7 lines
grub-core/loader/multiboot.c +3
-1@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer) +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services)
s/int/bool/ ?
Quoted 31 lines
grub-core/loader/multiboot.c +6
-2{if (grub_multiboot_is_elf32 (buffer)) -return grub_multiboot_load_elf32 (file, filename, buffer); +return grub_multiboot_load_elf32 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);else if (grub_multiboot_is_elf64 (buffer)) -return grub_multiboot_load_elf64 (file, filename, buffer); +return grub_multiboot_load_elf64 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);return grub_error (GRUB_ERR_UNKNOWN_OS ,N_ ("invalid arch-dependent ELF magic" )); }grub-core/loader/multiboot_elfxx.c +4
-1@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer) }static grub_err_t -CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename,void *buffer) +CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename, +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;char *phdr_base;
grub-core/loader/multiboot_elfxx.c CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi · line 96
Quoted 7 lines
grub-core/loader/multiboot_elfxx.c +2
-2@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voiif (phdr (i)->p_paddr +phdr (i)->p_memsz > highest_load) highest_load =phdr (i)->p_paddr +phdr (i)->p_memsz; -grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n" , - i, (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr); + grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx," + "align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,
%d to %s
grub-core/loader/multiboot_elfxx.c CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi · line 98
Quoted 2 lines
grub-core/loader/multiboot_elfxx.c +2
-0+ (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr, + (long) align, relocatable, avoid_efi_boot_services);
and then
avoid_efi_boot_services ? "yes" : "no"
Quoted 72 lines
grub-core/loader/multiboot_elfxx.c +13
-4{grub_relocator_chunk_t ch; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch,phdr (i)->p_paddr, -phdr (i)->p_memsz); + +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr -phdr (i)->p_memsz, +phdr (i)->p_memsz, align ? align :1 , + preference, avoid_efi_boot_services); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch,phdr (i)->p_paddr, +phdr (i)->p_memsz);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading phdr %d\n" , i);return err; } +if (base_addr) + *base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch); }@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi +1 , sh->sh_size, sh->sh_addralign,GRUB_RELOCATOR_PREFERENCE_NONE , - 0); + avoid_efi_boot_services);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading shdr %d\n" , i);grub-core/loader/multiboot_mbi2.c +6
-2@@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;static unsigned elf_sec_shstrndx;static void *elf_sections;static int keep_bs =0 ; +static grub_uint32_t base_addr =0 ; void grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,@@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 , efi_entry_specified =0 ; +int entry_specified =0 , efi_entry_specified =0 , relocatable =0 ;grub_addr_t entry =0 , efi_entry =0 ; -grub_uint32_t console_required =0 ; +grub_uint32_t console_required =0 , min_addr =0 ; +grub_uint32_t max_addr =0 , preference =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ; +grub_size_t align =0 ; buffer =grub_malloc (MULTIBOOT_SEARCH );if (!buffer)@@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_EFI_BS :case MULTIBOOT_TAG_TYPE_EFI32_IH :case MULTIBOOT_TAG_TYPE_EFI64_IH : +case MULTIBOOT_TAG_TYPE_BASE_ADDR :break ;default :
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 223
Quoted 5 lines
grub-core/loader/multiboot_mbi2.c +2
-0@@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename) accepted_consoles |=GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER ;break ; +case MULTIBOOT_HEADER_TAG_RELOCATABLE : + relocatable =1 ;
How about:
struct multiboot_header_tag_relocatable *_tag = (struct multiboot_header_tag_relocatable *)tag;
and then you don't have to use the casting?
Quoted 82 lines
grub-core/loader/multiboot_mbi2.c +40
-4+ min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr; + max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr; + align = ((struct multiboot_header_tag_relocatable *) tag)->align; +switch (((struct multiboot_header_tag_relocatable *) tag)->preference) + { +case MULTIBOOT_LOAD_PREFERENCE_LOW : + preference =GRUB_RELOCATOR_PREFERENCE_LOW ; +break ; + +case MULTIBOOT_LOAD_PREFERENCE_HIGH : + preference =GRUB_RELOCATOR_PREFERENCE_HIGH ; +break ; + +default : + preference =GRUB_RELOCATOR_PREFERENCE_NONE ; + } +break ; +/* GRUB always page-aligns modules. */ case MULTIBOOT_HEADER_TAG_MODULE_ALIGN :break ;@@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)else code_size = load_size; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch, load_addr, - code_size); +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr - code_size, + code_size, align ? align :1 , + preference, keep_bs); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch, load_addr, + code_size);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading aout kludge\n" );grub_free (buffer);return err; } + base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch);if ((grub_file_seek (file, offset)) == (grub_off_t) -1 )@@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) }else { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer, + relocatable, min_addr, max_addr, + align, preference, &base_addr, keep_bs);if (err) {grub_free (buffer);@@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)else if (entry_specified) grub_multiboot_payload_eip = entry; +if (relocatable) + { +if (base_addr > min_addr) + grub_multiboot_payload_eip += base_addr - min_addr; +else + grub_multiboot_payload_eip -= min_addr - base_addr; + } +if (fbtag) err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER, accepted_consoles,@@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) +ALIGN_UP (sizeof (struct multiboot_tag_framebuffer ),MULTIBOOT_TAG_ALIGN ) + + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN )
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 740
Quoted 6 lines
grub-core/loader/multiboot_mbi2.c +3
-0@@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target) ptrorig += (2 *sizeof (grub_uint32_t)) /sizeof (grub_properly_aligned_t); { +struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASE_ADDR ; + tag->size =sizeof (struct multiboot_tag_base_addr );
You have an extra space at the end.
Quoted 88 lines
grub-core/loader/multiboot_mbi2.c +6
-0+ tag->base_addr = base_addr; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + + {struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig; tag->type =MULTIBOOT_TAG_TYPE_CMDLINE ; tag->size =sizeof (struct multiboot_tag_string ) + cmdline_size;include/grub/multiboot.h +3
-1@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer); +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services);extern grub_size_t grub_multiboot_pure_size;extern grub_size_t grub_multiboot_alloc_mbi;extern grub_uint32_t grub_multiboot_payload_eip;include/multiboot2.h +24
-0@@ -62,6 +62,7 @@#define MULTIBOOT_TAG_TYPE_EFI_BS 18#define MULTIBOOT_TAG_TYPE_EFI32_IH 19#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT_TAG_TYPE_BASE_ADDR 21#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1@@ -72,11 +73,16 @@#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4#define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_alignmultiboot_uint32_t size; }; +struct multiboot_header_tag_relocatable +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t min_addr; +multiboot_uint32_t max_addr; +multiboot_uint32_t align; +multiboot_uint32_t preference; +}; +struct multiboot_color {multiboot_uint8_t red;@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ihmultiboot_uint64_t pointer; }; +struct multiboot_tag_base_addr +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t base_addr; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ Signature · 1 line
1.7.10.4
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
In reply to Daniel KiperOn Mon, Jul 20, 2015 at 04:35:53PM +0200, Daniel Kiper wrote:
This parts needs a bit of details I think.
As in why can't the ELF note that is present in the binary be satisfied. Or under what conditions would the existing code not work?
Quoted 25 lines
Signed-off-by Daniel Kiper <[email protected]>--- grub-core/loader/i386/multiboot_mbi.c | 6 ++-- grub-core/loader/multiboot.c | 12 +++++-- grub-core/loader/multiboot_elfxx.c | 28 +++++++++++---- grub-core/loader/multiboot_mbi2.c | 63 +++++++++++++++++++++++++++++---- include/grub/multiboot.h | 4 ++- include/multiboot2.h | 24 +++++++++++++ 6 files changed, 118 insertions(+), 19 deletions(-)grub-core/loader/i386/multiboot_mbi.c +2
-1@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,grub_err_t err;if (grub_multiboot_quirks &GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE ) { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );if (err ==GRUB_ERR_UNKNOWN_OS && (header->flags &MULTIBOOT_AOUT_KLUDGE )) grub_errno = err =GRUB_ERR_NONE ; }
grub-core/loader/i386/multiboot_mbi.c load_kernel (grub_file_t file, const char *filename, · line 123
Quoted 6 lines
grub-core/loader/i386/multiboot_mbi.c +2
-1@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,return GRUB_ERR_NONE ; } -return grub_multiboot_load_elf (file, filename, buffer); +return grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );
Oh boy. That is a bit hard to read. Perhaps another function could be introduced?
grub_multiboot_load_elf_ignore_reloc ? which would just pass the three parameters and set the rest to the 0 options?
Quoted 8 lines
grub-core/loader/i386/multiboot_mbi.c +0
-0} static struct multiboot_header *grub-core/loader/multiboot.c +0
-0
grub-core/loader/multiboot.c static grub_uint64_t highest_load; · line 195
Quoted 7 lines
grub-core/loader/multiboot.c +3
-1@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer) +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services)
s/int/bool/ ?
Quoted 31 lines
grub-core/loader/multiboot.c +6
-2{if (grub_multiboot_is_elf32 (buffer)) -return grub_multiboot_load_elf32 (file, filename, buffer); +return grub_multiboot_load_elf32 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);else if (grub_multiboot_is_elf64 (buffer)) -return grub_multiboot_load_elf64 (file, filename, buffer); +return grub_multiboot_load_elf64 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);return grub_error (GRUB_ERR_UNKNOWN_OS ,N_ ("invalid arch-dependent ELF magic" )); }grub-core/loader/multiboot_elfxx.c +4
-1@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer) }static grub_err_t -CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename,void *buffer) +CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename, +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;char *phdr_base;
grub-core/loader/multiboot_elfxx.c CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi · line 96
Quoted 7 lines
grub-core/loader/multiboot_elfxx.c +2
-2@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voiif (phdr (i)->p_paddr +phdr (i)->p_memsz > highest_load) highest_load =phdr (i)->p_paddr +phdr (i)->p_memsz; -grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n" , - i, (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr); + grub_dprintf ("multiboot_loader", "segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx," + "align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n", i,
%d to %s
grub-core/loader/multiboot_elfxx.c CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi · line 98
Quoted 2 lines
grub-core/loader/multiboot_elfxx.c +2
-0+ (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr, + (long) align, relocatable, avoid_efi_boot_services);
and then
avoid_efi_boot_services ? "yes" : "no"
Quoted 72 lines
grub-core/loader/multiboot_elfxx.c +13
-4{grub_relocator_chunk_t ch; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch,phdr (i)->p_paddr, -phdr (i)->p_memsz); + +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr -phdr (i)->p_memsz, +phdr (i)->p_memsz, align ? align :1 , + preference, avoid_efi_boot_services); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch,phdr (i)->p_paddr, +phdr (i)->p_memsz);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading phdr %d\n" , i);return err; } +if (base_addr) + *base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch); }@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi +1 , sh->sh_size, sh->sh_addralign,GRUB_RELOCATOR_PREFERENCE_NONE , - 0); + avoid_efi_boot_services);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading shdr %d\n" , i);grub-core/loader/multiboot_mbi2.c +6
-2@@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;static unsigned elf_sec_shstrndx;static void *elf_sections;static int keep_bs =0 ; +static grub_uint32_t base_addr =0 ; void grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,@@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 , efi_entry_specified =0 ; +int entry_specified =0 , efi_entry_specified =0 , relocatable =0 ;grub_addr_t entry =0 , efi_entry =0 ; -grub_uint32_t console_required =0 ; +grub_uint32_t console_required =0 , min_addr =0 ; +grub_uint32_t max_addr =0 , preference =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ; +grub_size_t align =0 ; buffer =grub_malloc (MULTIBOOT_SEARCH );if (!buffer)@@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_EFI_BS :case MULTIBOOT_TAG_TYPE_EFI32_IH :case MULTIBOOT_TAG_TYPE_EFI64_IH : +case MULTIBOOT_TAG_TYPE_BASE_ADDR :break ;default :
grub-core/loader/multiboot_mbi2.c grub_multiboot_load (grub_file_t file, const char *filename) · line 223
Quoted 5 lines
grub-core/loader/multiboot_mbi2.c +2
-0@@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename) accepted_consoles |=GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER ;break ; +case MULTIBOOT_HEADER_TAG_RELOCATABLE : + relocatable =1 ;
How about:
struct multiboot_header_tag_relocatable *_tag = (struct multiboot_header_tag_relocatable *)tag;
and then you don't have to use the casting?
Quoted 82 lines
grub-core/loader/multiboot_mbi2.c +40
-4+ min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr; + max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr; + align = ((struct multiboot_header_tag_relocatable *) tag)->align; +switch (((struct multiboot_header_tag_relocatable *) tag)->preference) + { +case MULTIBOOT_LOAD_PREFERENCE_LOW : + preference =GRUB_RELOCATOR_PREFERENCE_LOW ; +break ; + +case MULTIBOOT_LOAD_PREFERENCE_HIGH : + preference =GRUB_RELOCATOR_PREFERENCE_HIGH ; +break ; + +default : + preference =GRUB_RELOCATOR_PREFERENCE_NONE ; + } +break ; +/* GRUB always page-aligns modules. */ case MULTIBOOT_HEADER_TAG_MODULE_ALIGN :break ;@@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)else code_size = load_size; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch, load_addr, - code_size); +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr - code_size, + code_size, align ? align :1 , + preference, keep_bs); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch, load_addr, + code_size);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading aout kludge\n" );grub_free (buffer);return err; } + base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch);if ((grub_file_seek (file, offset)) == (grub_off_t) -1 )@@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) }else { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer, + relocatable, min_addr, max_addr, + align, preference, &base_addr, keep_bs);if (err) {grub_free (buffer);@@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)else if (entry_specified) grub_multiboot_payload_eip = entry; +if (relocatable) + { +if (base_addr > min_addr) + grub_multiboot_payload_eip += base_addr - min_addr; +else + grub_multiboot_payload_eip -= min_addr - base_addr; + } +if (fbtag) err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER, accepted_consoles,@@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) +ALIGN_UP (sizeof (struct multiboot_tag_framebuffer ),MULTIBOOT_TAG_ALIGN ) + + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN )
grub-core/loader/multiboot_mbi2.c grub_multiboot_make_mbi (grub_uint32_t *target) · line 740
Quoted 6 lines
grub-core/loader/multiboot_mbi2.c +3
-0@@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target) ptrorig += (2 *sizeof (grub_uint32_t)) /sizeof (grub_properly_aligned_t); { +struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASE_ADDR ; + tag->size =sizeof (struct multiboot_tag_base_addr );
You have an extra space at the end.
Quoted 88 lines
grub-core/loader/multiboot_mbi2.c +6
-0+ tag->base_addr = base_addr; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + + {struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig; tag->type =MULTIBOOT_TAG_TYPE_CMDLINE ; tag->size =sizeof (struct multiboot_tag_string ) + cmdline_size;include/grub/multiboot.h +3
-1@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer); +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services);extern grub_size_t grub_multiboot_pure_size;extern grub_size_t grub_multiboot_alloc_mbi;extern grub_uint32_t grub_multiboot_payload_eip;include/multiboot2.h +24
-0@@ -62,6 +62,7 @@#define MULTIBOOT_TAG_TYPE_EFI_BS 18#define MULTIBOOT_TAG_TYPE_EFI32_IH 19#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT_TAG_TYPE_BASE_ADDR 21#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1@@ -72,11 +73,16 @@#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4#define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_alignmultiboot_uint32_t size; }; +struct multiboot_header_tag_relocatable +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t min_addr; +multiboot_uint32_t max_addr; +multiboot_uint32_t align; +multiboot_uint32_t preference; +}; +struct multiboot_color {multiboot_uint8_t red;@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ihmultiboot_uint64_t pointer; }; +struct multiboot_tag_base_addr +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t base_addr; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */ Signature · 1 line
1.7.10.4
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
In reply to Daniel KiperQuoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
What is handling the actual relocation? Why doesn't this patch include support for ELF relocations?
Quoted 326 lines
--- grub-core/loader/i386/multiboot_mbi.c | 6 ++-- grub-core/loader/multiboot.c | 12 +++++-- grub-core/loader/multiboot_elfxx.c | 28 +++++++++++---- grub-core/loader/multiboot_mbi2.c | 63 +++++++++++++++++++++++++++++---- include/grub/multiboot.h | 4 ++- include/multiboot2.h | 24 +++++++++++++ 6 files changed, 118 insertions(+), 19 deletions(-)grub-core/loader/i386/multiboot_mbi.c +4
-2@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,grub_err_t err;if (grub_multiboot_quirks &GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE ) { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );if (err ==GRUB_ERR_UNKNOWN_OS && (header->flags &MULTIBOOT_AOUT_KLUDGE )) grub_errno = err =GRUB_ERR_NONE ; }@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,return GRUB_ERR_NONE ; } -return grub_multiboot_load_elf (file, filename, buffer); +return grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 ); } static struct multiboot_header *grub-core/loader/multiboot.c +9
-3@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer) +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {if (grub_multiboot_is_elf32 (buffer)) -return grub_multiboot_load_elf32 (file, filename, buffer); +return grub_multiboot_load_elf32 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);else if (grub_multiboot_is_elf64 (buffer)) -return grub_multiboot_load_elf64 (file, filename, buffer); +return grub_multiboot_load_elf64 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);return grub_error (GRUB_ERR_UNKNOWN_OS ,N_ ("invalid arch-dependent ELF magic" )); }grub-core/loader/multiboot_elfxx.c +21
-7@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer) }static grub_err_t -CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename,void *buffer) +CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename, +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;char *phdr_base;@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voiif (phdr (i)->p_paddr +phdr (i)->p_memsz > highest_load) highest_load =phdr (i)->p_paddr +phdr (i)->p_memsz; -grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n" , - i, (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr); +grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx," +"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n" , i, + (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr, + (long ) align, relocatable, avoid_efi_boot_services); {grub_relocator_chunk_t ch; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch,phdr (i)->p_paddr, -phdr (i)->p_memsz); + +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr -phdr (i)->p_memsz, +phdr (i)->p_memsz, align ? align :1 , + preference, avoid_efi_boot_services); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch,phdr (i)->p_paddr, +phdr (i)->p_memsz);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading phdr %d\n" , i);return err; } +if (base_addr) + *base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch); }@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi +1 , sh->sh_size, sh->sh_addralign,GRUB_RELOCATOR_PREFERENCE_NONE , - 0); + avoid_efi_boot_services);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading shdr %d\n" , i);grub-core/loader/multiboot_mbi2.c +57
-6@@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;static unsigned elf_sec_shstrndx;static void *elf_sections;static int keep_bs =0 ; +static grub_uint32_t base_addr =0 ; void grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,@@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 , efi_entry_specified =0 ; +int entry_specified =0 , efi_entry_specified =0 , relocatable =0 ;grub_addr_t entry =0 , efi_entry =0 ; -grub_uint32_t console_required =0 ; +grub_uint32_t console_required =0 , min_addr =0 ; +grub_uint32_t max_addr =0 , preference =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ; +grub_size_t align =0 ; buffer =grub_malloc (MULTIBOOT_SEARCH );if (!buffer)@@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_EFI_BS :case MULTIBOOT_TAG_TYPE_EFI32_IH :case MULTIBOOT_TAG_TYPE_EFI64_IH : +case MULTIBOOT_TAG_TYPE_BASE_ADDR :break ;default :@@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename) accepted_consoles |=GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER ;break ; +case MULTIBOOT_HEADER_TAG_RELOCATABLE : + relocatable =1 ; + min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr; + max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr; + align = ((struct multiboot_header_tag_relocatable *) tag)->align; +switch (((struct multiboot_header_tag_relocatable *) tag)->preference) + { +case MULTIBOOT_LOAD_PREFERENCE_LOW : + preference =GRUB_RELOCATOR_PREFERENCE_LOW ; +break ; + +case MULTIBOOT_LOAD_PREFERENCE_HIGH : + preference =GRUB_RELOCATOR_PREFERENCE_HIGH ; +break ; + +default : + preference =GRUB_RELOCATOR_PREFERENCE_NONE ; + } +break ; +/* GRUB always page-aligns modules. */ case MULTIBOOT_HEADER_TAG_MODULE_ALIGN :break ;@@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)else code_size = load_size; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch, load_addr, - code_size); +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr - code_size, + code_size, align ? align :1 , + preference, keep_bs); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch, load_addr, + code_size);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading aout kludge\n" );grub_free (buffer);return err; } + base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch);if ((grub_file_seek (file, offset)) == (grub_off_t) -1 )@@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) }else { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer, + relocatable, min_addr, max_addr, + align, preference, &base_addr, keep_bs);if (err) {grub_free (buffer);@@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)else if (entry_specified) grub_multiboot_payload_eip = entry; +if (relocatable) + { +if (base_addr > min_addr) + grub_multiboot_payload_eip += base_addr - min_addr; +else + grub_multiboot_payload_eip -= min_addr - base_addr; + } +if (fbtag) err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER, accepted_consoles,@@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) +ALIGN_UP (sizeof (struct multiboot_tag_framebuffer ),MULTIBOOT_TAG_ALIGN ) + + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN )@@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target) ptrorig += (2 *sizeof (grub_uint32_t)) /sizeof (grub_properly_aligned_t); { +struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASE_ADDR ; + tag->size =sizeof (struct multiboot_tag_base_addr ); + tag->base_addr = base_addr; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + + {struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig; tag->type =MULTIBOOT_TAG_TYPE_CMDLINE ; tag->size =sizeof (struct multiboot_tag_string ) + cmdline_size;include/grub/multiboot.h +3
-1@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer); +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services);extern grub_size_t grub_multiboot_pure_size;extern grub_size_t grub_multiboot_alloc_mbi;extern grub_uint32_t grub_multiboot_payload_eip;include/multiboot2.h +17
-0@@ -62,6 +62,7 @@#define MULTIBOOT_TAG_TYPE_EFI_BS 18#define MULTIBOOT_TAG_TYPE_EFI32_IH 19#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT_TAG_TYPE_BASE_ADDR 21#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1@@ -72,11 +73,16 @@#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4#define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_alignmultiboot_uint32_t size; }; +struct multiboot_header_tag_relocatable +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t min_addr; +multiboot_uint32_t max_addr; +multiboot_uint32_t align; +multiboot_uint32_t preference; +}; +struct multiboot_color {multiboot_uint8_t red;@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ihmultiboot_uint64_t pointer; };
include/multiboot2.h struct multiboot_tag_efi64_ih · line 424
Quoted 10 lines
include/multiboot2.h +7
-0+struct multiboot_tag_base_addr +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t base_addr; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
In reply to Daniel KiperQuoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>
What is handling the actual relocation? Why doesn't this patch include support for ELF relocations?
Quoted 336 lines
--- grub-core/loader/i386/multiboot_mbi.c | 6 ++-- grub-core/loader/multiboot.c | 12 +++++-- grub-core/loader/multiboot_elfxx.c | 28 +++++++++++---- grub-core/loader/multiboot_mbi2.c | 63 +++++++++++++++++++++++++++++---- include/grub/multiboot.h | 4 ++- include/multiboot2.h | 24 +++++++++++++ 6 files changed, 118 insertions(+), 19 deletions(-)grub-core/loader/i386/multiboot_mbi.c +4
-2@@ -72,7 +72,8 @@ load_kernel (grub_file_t file, const char *filename,grub_err_t err;if (grub_multiboot_quirks &GRUB_MULTIBOOT_QUIRK_BAD_KLUDGE ) { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 );if (err ==GRUB_ERR_UNKNOWN_OS && (header->flags &MULTIBOOT_AOUT_KLUDGE )) grub_errno = err =GRUB_ERR_NONE ; }@@ -118,7 +119,8 @@ load_kernel (grub_file_t file, const char *filename,return GRUB_ERR_NONE ; } -return grub_multiboot_load_elf (file, filename, buffer); +return grub_multiboot_load_elf (file, filename, buffer,0 ,0 ,0 ,0 , +GRUB_RELOCATOR_PREFERENCE_NONE ,NULL ,0 ); } static struct multiboot_header *grub-core/loader/multiboot.c +9
-3@@ -190,12 +190,18 @@ static grub_uint64_t highest_load;/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer) +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {if (grub_multiboot_is_elf32 (buffer)) -return grub_multiboot_load_elf32 (file, filename, buffer); +return grub_multiboot_load_elf32 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);else if (grub_multiboot_is_elf64 (buffer)) -return grub_multiboot_load_elf64 (file, filename, buffer); +return grub_multiboot_load_elf64 (file, filename, buffer, relocatable, + min_addr, max_addr, align, preference, + base_addr, avoid_efi_boot_services);return grub_error (GRUB_ERR_UNKNOWN_OS ,N_ ("invalid arch-dependent ELF magic" )); }grub-core/loader/multiboot_elfxx.c +21
-7@@ -51,7 +51,10 @@ CONCAT(grub_multiboot_is_elf, XX) (void *buffer) }static grub_err_t -CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename,void *buffer) +CONCAT (grub_multiboot_load_elf ,XX ) (grub_file_t file,const char *filename, +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services) {Elf_Ehdr *ehdr = (Elf_Ehdr *) buffer;char *phdr_base;@@ -89,19 +92,30 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voiif (phdr (i)->p_paddr +phdr (i)->p_memsz > highest_load) highest_load =phdr (i)->p_paddr +phdr (i)->p_memsz; -grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx\n" , - i, (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr); +grub_dprintf ("multiboot_loader" ,"segment %d: paddr=0x%lx, memsz=0x%lx, vaddr=0x%lx," +"align=0x%lx, relocatable=%d, avoid_efi_boot_services=%d\n" , i, + (long )phdr (i)->p_paddr, (long )phdr (i)->p_memsz, (long )phdr (i)->p_vaddr, + (long ) align, relocatable, avoid_efi_boot_services); {grub_relocator_chunk_t ch; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch,phdr (i)->p_paddr, -phdr (i)->p_memsz); + +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr -phdr (i)->p_memsz, +phdr (i)->p_memsz, align ? align :1 , + preference, avoid_efi_boot_services); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch,phdr (i)->p_paddr, +phdr (i)->p_memsz);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading phdr %d\n" , i);return err; } +if (base_addr) + *base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch); }@@ -208,7 +222,7 @@ CONCAT(grub_multiboot_load_elf, XX) (grub_file_t file, const char *filename, voi +1 , sh->sh_size, sh->sh_addralign,GRUB_RELOCATOR_PREFERENCE_NONE , - 0); + avoid_efi_boot_services);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading shdr %d\n" , i);grub-core/loader/multiboot_mbi2.c +57
-6@@ -68,6 +68,7 @@ static grub_size_t elf_sec_num, elf_sec_entsize;static unsigned elf_sec_shstrndx;static void *elf_sections;static int keep_bs =0 ; +static grub_uint32_t base_addr =0 ; void grub_multiboot_add_elfsyms (grub_size_t num, grub_size_t entsize,@@ -107,11 +108,13 @@ grub_multiboot_load (grub_file_t file, const char *filename)grub_err_t err;struct multiboot_header_tag *tag;struct multiboot_header_tag_address *addr_tag =NULL ; -int entry_specified =0 , efi_entry_specified =0 ; +int entry_specified =0 , efi_entry_specified =0 , relocatable =0 ;grub_addr_t entry =0 , efi_entry =0 ; -grub_uint32_t console_required =0 ; +grub_uint32_t console_required =0 , min_addr =0 ; +grub_uint32_t max_addr =0 , preference =0 ;struct multiboot_header_tag_framebuffer *fbtag =NULL ;int accepted_consoles =GRUB_MULTIBOOT_CONSOLE_EGA_TEXT ; +grub_size_t align =0 ; buffer =grub_malloc (MULTIBOOT_SEARCH );if (!buffer)@@ -174,6 +177,7 @@ grub_multiboot_load (grub_file_t file, const char *filename)case MULTIBOOT_TAG_TYPE_EFI_BS :case MULTIBOOT_TAG_TYPE_EFI32_IH :case MULTIBOOT_TAG_TYPE_EFI64_IH : +case MULTIBOOT_TAG_TYPE_BASE_ADDR :break ;default :@@ -215,6 +219,26 @@ grub_multiboot_load (grub_file_t file, const char *filename) accepted_consoles |=GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER ;break ; +case MULTIBOOT_HEADER_TAG_RELOCATABLE : + relocatable =1 ; + min_addr = ((struct multiboot_header_tag_relocatable *) tag)->min_addr; + max_addr = ((struct multiboot_header_tag_relocatable *) tag)->max_addr; + align = ((struct multiboot_header_tag_relocatable *) tag)->align; +switch (((struct multiboot_header_tag_relocatable *) tag)->preference) + { +case MULTIBOOT_LOAD_PREFERENCE_LOW : + preference =GRUB_RELOCATOR_PREFERENCE_LOW ; +break ; + +case MULTIBOOT_LOAD_PREFERENCE_HIGH : + preference =GRUB_RELOCATOR_PREFERENCE_HIGH ; +break ; + +default : + preference =GRUB_RELOCATOR_PREFERENCE_NONE ; + } +break ; +/* GRUB always page-aligns modules. */ case MULTIBOOT_HEADER_TAG_MODULE_ALIGN :break ;@@ -260,15 +284,22 @@ grub_multiboot_load (grub_file_t file, const char *filename)else code_size = load_size; - err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, - &ch, load_addr, - code_size); +if (relocatable) + err =grub_relocator_alloc_chunk_align (grub_multiboot_relocator, &ch, + min_addr, max_addr - code_size, + code_size, align ? align :1 , + preference, keep_bs); +else + err =grub_relocator_alloc_chunk_addr (grub_multiboot_relocator, + &ch, load_addr, + code_size);if (err) {grub_dprintf ("multiboot_loader" ,"Error loading aout kludge\n" );grub_free (buffer);return err; } + base_addr =get_physical_target_address (ch); source =get_virtual_current_address (ch);if ((grub_file_seek (file, offset)) == (grub_off_t) -1 )@@ -290,7 +321,9 @@ grub_multiboot_load (grub_file_t file, const char *filename) }else { - err =grub_multiboot_load_elf (file, filename, buffer); + err =grub_multiboot_load_elf (file, filename, buffer, + relocatable, min_addr, max_addr, + align, preference, &base_addr, keep_bs);if (err) {grub_free (buffer);@@ -303,6 +336,14 @@ grub_multiboot_load (grub_file_t file, const char *filename)else if (entry_specified) grub_multiboot_payload_eip = entry; +if (relocatable) + { +if (base_addr > min_addr) + grub_multiboot_payload_eip += base_addr - min_addr; +else + grub_multiboot_payload_eip -= min_addr - base_addr; + } +if (fbtag) err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER, accepted_consoles,@@ -409,6 +450,7 @@ grub_multiboot_get_mbi_size (void) + grub_get_multiboot_mmap_count () * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) +ALIGN_UP (sizeof (struct multiboot_tag_framebuffer ),MULTIBOOT_TAG_ALIGN ) + + ALIGN_UP (sizeof (struct multiboot_tag_base_addr), MULTIBOOT_TAG_ALIGN)#ifdef GRUB_MACHINE_EFI +ALIGN_UP (sizeof (struct multiboot_tag_efi32 ),MULTIBOOT_TAG_ALIGN ) +ALIGN_UP (sizeof (struct multiboot_tag_efi64 ),MULTIBOOT_TAG_ALIGN )@@ -693,6 +735,15 @@ grub_multiboot_make_mbi (grub_uint32_t *target) ptrorig += (2 *sizeof (grub_uint32_t)) /sizeof (grub_properly_aligned_t); { +struct multiboot_tag_base_addr *tag = (struct multiboot_tag_base_addr *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASE_ADDR ; + tag->size =sizeof (struct multiboot_tag_base_addr ); + tag->base_addr = base_addr; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } + + {struct multiboot_tag_string *tag = (struct multiboot_tag_string *) ptrorig; tag->type =MULTIBOOT_TAG_TYPE_CMDLINE ; tag->size =sizeof (struct multiboot_tag_string ) + cmdline_size;include/grub/multiboot.h +3
-1@@ -94,7 +94,9 @@ grub_multiboot_load (grub_file_t file, const char *filename);/* Load ELF32 or ELF64. */ grub_err_t grub_multiboot_load_elf (grub_file_t file,const char *filename, -void *buffer); +void *buffer,int relocatable,grub_uint32_t min_addr, +grub_uint32_t max_addr,grub_size_t align,grub_uint32_t preference, +grub_uint32_t *base_addr,int avoid_efi_boot_services);extern grub_size_t grub_multiboot_pure_size;extern grub_size_t grub_multiboot_alloc_mbi;extern grub_uint32_t grub_multiboot_payload_eip;include/multiboot2.h +24
-0@@ -62,6 +62,7 @@#define MULTIBOOT_TAG_TYPE_EFI_BS 18#define MULTIBOOT_TAG_TYPE_EFI32_IH 19#define MULTIBOOT_TAG_TYPE_EFI64_IH 20 +#define MULTIBOOT_TAG_TYPE_BASE_ADDR 21#define MULTIBOOT_HEADER_TAG_END 0#define MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST 1@@ -72,11 +73,16 @@#define MULTIBOOT_HEADER_TAG_MODULE_ALIGN 6#define MULTIBOOT_HEADER_TAG_EFI_BS 7#define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT_HEADER_TAG_RELOCATABLE 10#define MULTIBOOT_ARCHITECTURE_I386 0#define MULTIBOOT_ARCHITECTURE_MIPS32 4#define MULTIBOOT_HEADER_TAG_OPTIONAL 1 +#define MULTIBOOT_LOAD_PREFERENCE_NONE 0 +#define MULTIBOOT_LOAD_PREFERENCE_LOW 1 +#define MULTIBOOT_LOAD_PREFERENCE_HIGH 2 +#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2@@ -169,6 +175,17 @@ struct multiboot_header_tag_module_alignmultiboot_uint32_t size; }; +struct multiboot_header_tag_relocatable +{ +multiboot_uint16_t type; +multiboot_uint16_t flags; +multiboot_uint32_t size; +multiboot_uint32_t min_addr; +multiboot_uint32_t max_addr; +multiboot_uint32_t align; +multiboot_uint32_t preference; +}; +struct multiboot_color {multiboot_uint8_t red;@@ -395,6 +412,13 @@ struct multiboot_tag_efi64_ihmultiboot_uint64_t pointer; }; +struct multiboot_tag_base_addr +{ +multiboot_uint32_t type; +multiboot_uint32_t size; +multiboot_uint32_t base_addr; +}; +#endif /* ! ASM_FILE */ #endif /* ! MULTIBOOT_HEADER */
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
Quoted 3 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 1 line · Daniel Kiper
Signed-off-by Daniel Kiper <[email protected]>What is handling the actual relocation?
In Xen we get image offset from GRUB2 and using this value we calculate relative addresses. We are using %fs for it.
Quoted 1 line
Why doesn't this patch include support for ELF relocations?
This is another option. We considered it too. However, in our case relative addressing looks simpler then ELF relocations. However, if you wish I can add this functionality when this patch series is included in upstream GRUB2. Is it OK for you?
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): CAEaD8JMUUnSd7MMTANouZ1oQvYA00c49V8ENgUGUY+K8HcE_+Q@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
Quoted 19 lines · Daniel Kiper
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 1 line · Daniel Kiper
On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
Quoted 4 lines · Serbinenko
Quoted 3 lines · Daniel Kiper
Quoted 1 line
Signed-off-by Daniel Kiper <[email protected]>What is handling the actual relocation?
Quoted 8 lines
Quoted 7 lines
In Xen we get image offset from GRUB2 and using this value we calculate relative addresses. We are using %fs for it.
Quoted 1 line
Why doesn't this patch include support for ELF relocations?
This is another option. We considered it too. However, in our case relative addressing looks simpler then ELF relocations.
How is it simpler than to have a fully relocated binary when you start?
Xen ELF file does not have relocations.
Quoted 8 lines
Quoted 1 line
How do you pass the offset?
Via
MULTIBOOT_TAG_TYPE_BASE_ADDRtag.Quoted 1 line
Does xen have any relocation entries?
No.
Can we then settle on using your interface but saying that bootloader has to execute all ELF relocations? Since you don't have them, you wouldn't be affected by the change but it would allow easy creation of relocatable binaries. Feel free in the first patch just to have a check for absence of relocation entries. x86-64 has only about 5 relocations we care about so should be easy to implement. We can reuse code in dl.c.
Quoted 11 lines
Quoted 2 lines
Was such xen already released? Just looking for how it should be in perspective and how to get there
We agreed (in Xen community) that we would like to have multiboot2 protocol with additional features set in stone at first. So, this patch series just propose some changes which are required by Xen but they are not used by any Xen release yet. Additionally, we want that these extensions are quite generic and could be used by other projects if they need them too.
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
In reply to a message not in the archiveQuoted 19 lines · Daniel Kiper
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 1 line · Daniel Kiper
On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
Quoted 4 lines · Serbinenko
Quoted 3 lines · Daniel Kiper
Quoted 1 line
Signed-off-by Daniel Kiper <[email protected]>What is handling the actual relocation?
Quoted 8 lines
Quoted 7 lines
In Xen we get image offset from GRUB2 and using this value we calculate relative addresses. We are using %fs for it.
Quoted 1 line
Why doesn't this patch include support for ELF relocations?
This is another option. We considered it too. However, in our case relative addressing looks simpler then ELF relocations.
How is it simpler than to have a fully relocated binary when you start?
Xen ELF file does not have relocations.
Quoted 8 lines
Quoted 1 line
How do you pass the offset?
Via
MULTIBOOT_TAG_TYPE_BASE_ADDRtag.Quoted 1 line
Does xen have any relocation entries?
No.
Can we then settle on using your interface but saying that bootloader has to execute all ELF relocations? Since you don't have them, you wouldn't be affected by the change but it would allow easy creation of relocatable binaries. Feel free in the first patch just to have a check for absence of relocation entries. x86-64 has only about 5 relocations we care about so should be easy to implement. We can reuse code in dl.c.
Quoted 11 lines
Quoted 2 lines
Was such xen already released? Just looking for how it should be in perspective and how to get there
We agreed (in Xen community) that we would like to have multiboot2 protocol with additional features set in stone at first. So, this patch series just propose some changes which are required by Xen but they are not used by any Xen release yet. Additionally, we want that these extensions are quite generic and could be used by other projects if they need them too.
Daniel
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
Quoted 26 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 25 lines · Daniel Kiper
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 1 line · Daniel Kiper
On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
Quoted 4 lines · Serbinenko
Quoted 3 lines · Daniel Kiper
Quoted 1 line
Signed-off-by Daniel Kiper <[email protected]>What is handling the actual relocation?
Quoted 8 lines
Quoted 7 lines
In Xen we get image offset from GRUB2 and using this value we calculate relative addresses. We are using %fs for it.
Quoted 1 line
Why doesn't this patch include support for ELF relocations?
This is another option. We considered it too. However, in our case relative addressing looks simpler then ELF relocations.
How is it simpler than to have a fully relocated binary when you start?
Xen ELF file does not have relocations.
Quoted 1 line
How do you pass the offset?
Via
MULTIBOOT_TAG_TYPE_BASE_ADDRtag.Quoted 1 line
Does xen have any relocation entries?
Quoted 8 lines
Quoted 2 lines
No.
Can we then settle on using your interface but saying that bootloader has to execute all ELF relocations? Since you don't have them, you wouldn't be affected by the change but it would allow easy creation of relocatable binaries. Feel free in the first patch just to have a check for absence of relocation entries. x86-64 has only about 5 relocations we care about so should be easy to implement. We can reuse code in
dl.c.
Granted!
Daniel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 5/6] multiboot2: Add support for relocatable images
In reply to Vladimir 'φ-coder/phcoder' SerbinenkoQuoted 26 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 25 lines · Daniel Kiper
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 1 line · Daniel Kiper
On Mon, Nov 09, 2015 at 09:08:35PM +0100, Vladimir 'φ-coder/phcoder'
Quoted 4 lines · Serbinenko
Quoted 3 lines · Daniel Kiper
Quoted 1 line
Signed-off-by Daniel Kiper <[email protected]>What is handling the actual relocation?
Quoted 8 lines
Quoted 7 lines
In Xen we get image offset from GRUB2 and using this value we calculate relative addresses. We are using %fs for it.
Quoted 1 line
Why doesn't this patch include support for ELF relocations?
This is another option. We considered it too. However, in our case relative addressing looks simpler then ELF relocations.
How is it simpler than to have a fully relocated binary when you start?
Xen ELF file does not have relocations.
Quoted 1 line
How do you pass the offset?
Via
MULTIBOOT_TAG_TYPE_BASE_ADDRtag.Quoted 1 line
Does xen have any relocation entries?
Quoted 8 lines
Quoted 2 lines
No.
Can we then settle on using your interface but saying that bootloader has to execute all ELF relocations? Since you don't have them, you wouldn't be affected by the change but it would allow easy creation of relocatable binaries. Feel free in the first patch just to have a check for absence of relocation entries. x86-64 has only about 5 relocations we care about so should be easy to implement. We can reuse code in
dl.c.
Granted!
Daniel
PATCH v2 6/6 multiboot2: Do not pass memory maps to image if EFI boot services are enabled
In reply to Daniel KiperDo not pass memory maps to image if it asked for EFI boot services. Maps are usually invalid in that case and they can confuse potential user. Image should get memory map itself just before ExitBootServices() call.
--- grub-core/loader/multiboot_mbi2.c | 71 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +35 -36
@@ -431,7 +431,7 @@ static grub_size_tgrub_multiboot_get_mbi_size (void) {#ifdef GRUB_MACHINE_EFI -if (!efi_mmap_size) +if (!keep_bs && !efi_mmap_size)find_efi_mmap_size ();#endif return 2 *sizeof (grub_uint32_t) +sizeof (struct multiboot_tag )
@@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target) } } - { -struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; -grub_fill_multiboot_mmap (tag); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +if (!keep_bs) + { +struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; +grub_fill_multiboot_mmap (tag); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct multiboot_tag_elf_sections *tag
@@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target) / sizeof (grub_properly_aligned_t); } - { -struct multiboot_tag_basic_meminfo *tag - = (struct multiboot_tag_basic_meminfo *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; - tag->size =sizeof (struct multiboot_tag_basic_meminfo ); +if (!keep_bs) + { +struct multiboot_tag_basic_meminfo *tag + = (struct multiboot_tag_basic_meminfo *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; + tag->size =sizeof (struct multiboot_tag_basic_meminfo ); -/* Convert from bytes to kilobytes. */ - tag->mem_lower =grub_mmap_get_lower () /1024 ; - tag->mem_upper =grub_mmap_get_upper () /1024 ; - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +/* Convert from bytes to kilobytes. */ + tag->mem_lower =grub_mmap_get_lower () /1024 ; + tag->mem_upper =grub_mmap_get_upper () /1024 ; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct grub_net_network_level_interface *net;
@@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)grub_efi_uintn_t efi_desc_size;grub_efi_uint32_t efi_desc_version; - tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; - tag->size =sizeof (*tag) + efi_mmap_size; -if (!keep_bs) - err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , - &efi_desc_size, &efi_desc_version); -else { -if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap, -NULL , - &efi_desc_size, &efi_desc_version) <=0 ) - err =grub_error (GRUB_ERR_IO ,"couldn't retrieve memory map" ); + tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; + tag->size =sizeof (*tag) + efi_mmap_size; + + err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , + &efi_desc_size, &efi_desc_version); + +if (err) +return err; + + tag->descr_size = efi_desc_size; + tag->descr_vers = efi_desc_version; + tag->size =sizeof (*tag) + efi_mmap_size; + + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); } -if (err) -return err; - tag->descr_size = efi_desc_size; - tag->descr_vers = efi_desc_version; - tag->size =sizeof (*tag) + efi_mmap_size; - - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); }if (keep_bs)
Signature · 1 line
1.7.10.4
Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
Quoted 3 lines · Daniel Kiper
Do not pass memory maps to image if it asked for EFI boot services. Maps are usually invalid in that case and they can confuse potential user. Image should get memory map itself just before
ExitBootServices()call.
Can we point to some commits in Linux or Xen in which these situations arose?
Wait, I think there even was one commit in grub.
Aha:
ommit e75fdee420a7ad95e9a465c9699adc2e2e970440
Author: Vladimir 'phcoder' Serbinenko <[email protected]> Date: Tue Mar 26 11:34:56 2013 +0100
* grub-core/kern/efi/mm.c (grub_efi_finish_boot_services):
Try terminating EFI services several times due to quirks in some implementations.
Otherwise:
Quoted 116 lines
Signed-off-by Daniel Kiper <[email protected]>--- grub-core/loader/multiboot_mbi2.c | 71 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-)grub-core/loader/multiboot_mbi2.c +35
-36@@ -431,7 +431,7 @@ static grub_size_tgrub_multiboot_get_mbi_size (void) {#ifdef GRUB_MACHINE_EFI -if (!efi_mmap_size) +if (!keep_bs && !efi_mmap_size)find_efi_mmap_size ();#endif return 2 *sizeof (grub_uint32_t) +sizeof (struct multiboot_tag )@@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target) } } - { -struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; -grub_fill_multiboot_mmap (tag); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +if (!keep_bs) + { +struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; +grub_fill_multiboot_mmap (tag); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct multiboot_tag_elf_sections *tag@@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target) / sizeof (grub_properly_aligned_t); } - { -struct multiboot_tag_basic_meminfo *tag - = (struct multiboot_tag_basic_meminfo *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; - tag->size =sizeof (struct multiboot_tag_basic_meminfo ); +if (!keep_bs) + { +struct multiboot_tag_basic_meminfo *tag + = (struct multiboot_tag_basic_meminfo *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; + tag->size =sizeof (struct multiboot_tag_basic_meminfo ); -/* Convert from bytes to kilobytes. */ - tag->mem_lower =grub_mmap_get_lower () /1024 ; - tag->mem_upper =grub_mmap_get_upper () /1024 ; - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +/* Convert from bytes to kilobytes. */ + tag->mem_lower =grub_mmap_get_lower () /1024 ; + tag->mem_upper =grub_mmap_get_upper () /1024 ; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct grub_net_network_level_interface *net;@@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)grub_efi_uintn_t efi_desc_size;grub_efi_uint32_t efi_desc_version; - tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; - tag->size =sizeof (*tag) + efi_mmap_size; -if (!keep_bs) - err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , - &efi_desc_size, &efi_desc_version); -else { -if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap, -NULL , - &efi_desc_size, &efi_desc_version) <=0 ) - err =grub_error (GRUB_ERR_IO ,"couldn't retrieve memory map" ); + tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; + tag->size =sizeof (*tag) + efi_mmap_size; + + err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , + &efi_desc_size, &efi_desc_version); + +if (err) +return err; + + tag->descr_size = efi_desc_size; + tag->descr_vers = efi_desc_version; + tag->size =sizeof (*tag) + efi_mmap_size; + + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); } -if (err) -return err; - tag->descr_size = efi_desc_size; - tag->descr_vers = efi_desc_version; - tag->size =sizeof (*tag) + efi_mmap_size; - - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); }if (keep_bs)Signature · 1 line
1.7.10.4
Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
Quoted 16 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Daniel Kiper
Do not pass memory maps to image if it asked for EFI boot services. Maps are usually invalid in that case and they can confuse potential user. Image should get memory map itself just before
ExitBootServices()call.Can we point to some commits in Linux or Xen in which these situations arose?
Wait, I think there even was one commit in grub.
Aha:
ommit
e75fdee420a7ad95e9a465c9699adc2e2e970440Author: Vladimir 'phcoder' Serbinenko <[email protected]> Date: Tue Mar 26 11:34:56 2013 +0100
Quoted 7 lines
*
grub-core/kern/efi/mm.c(grub_efi_finish_boot_services):
Try terminating EFI services several times due to quirks in some implementations.Otherwise:
Reviewed-by Konrad Rzeszutek Wilk <[email protected]>
Nope, this is a bit different problem. In general GRUB2 assumes that EFI boot services memory regions are free and specify them as such in relevant maps. However, this is not true if you jump into loaded image with EFI boot services enabled. So, we should not expose this maps to the user when he/she asked for access to EFI boot services. This is not very big issue for him/her because he/she can get memory map from EFI just before ExitBootServices() call. This way they will have latest valid memory map.
Daniel
Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
In reply to Konrad Rzeszutek WilkQuoted 16 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Daniel Kiper
Do not pass memory maps to image if it asked for EFI boot services. Maps are usually invalid in that case and they can confuse potential user. Image should get memory map itself just before
ExitBootServices()call.Can we point to some commits in Linux or Xen in which these situations arose?
Wait, I think there even was one commit in grub.
Aha:
ommit
e75fdee420a7ad95e9a465c9699adc2e2e970440Author: Vladimir 'phcoder' Serbinenko <[email protected]> Date: Tue Mar 26 11:34:56 2013 +0100
Quoted 7 lines
*
grub-core/kern/efi/mm.c(grub_efi_finish_boot_services):
Try terminating EFI services several times due to quirks in some implementations.Otherwise:
Reviewed-by Konrad Rzeszutek Wilk <[email protected]>
Nope, this is a bit different problem. In general GRUB2 assumes that EFI boot services memory regions are free and specify them as such in relevant maps. However, this is not true if you jump into loaded image with EFI boot services enabled. So, we should not expose this maps to the user when he/she asked for access to EFI boot services. This is not very big issue for him/her because he/she can get memory map from EFI just before ExitBootServices() call. This way they will have latest valid memory map.
Daniel
Re: [PATCH v2 6/6] multiboot2: Do not pass memory maps to image if EFI boot services are enabled
In reply to Daniel KiperQuoted 3 lines · Daniel Kiper
Do not pass memory maps to image if it asked for EFI boot services. Maps are usually invalid in that case and they can confuse potential user. Image should get memory map itself just before
ExitBootServices()call.
Can we point to some commits in Linux or Xen in which these situations arose?
Wait, I think there even was one commit in grub.
Aha:
ommit e75fdee420a7ad95e9a465c9699adc2e2e970440
Author: Vladimir 'phcoder' Serbinenko <[email protected]> Date: Tue Mar 26 11:34:56 2013 +0100
* grub-core/kern/efi/mm.c (grub_efi_finish_boot_services):
Try terminating EFI services several times due to quirks in some implementations.
Otherwise:
Quoted 116 lines
Signed-off-by Daniel Kiper <[email protected]>--- grub-core/loader/multiboot_mbi2.c | 71 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-)grub-core/loader/multiboot_mbi2.c +35
-36@@ -431,7 +431,7 @@ static grub_size_tgrub_multiboot_get_mbi_size (void) {#ifdef GRUB_MACHINE_EFI -if (!efi_mmap_size) +if (!keep_bs && !efi_mmap_size)find_efi_mmap_size ();#endif return 2 *sizeof (grub_uint32_t) +sizeof (struct multiboot_tag )@@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target) } } - { -struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; -grub_fill_multiboot_mmap (tag); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +if (!keep_bs) + { +struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; +grub_fill_multiboot_mmap (tag); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct multiboot_tag_elf_sections *tag@@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target) / sizeof (grub_properly_aligned_t); } - { -struct multiboot_tag_basic_meminfo *tag - = (struct multiboot_tag_basic_meminfo *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; - tag->size =sizeof (struct multiboot_tag_basic_meminfo ); +if (!keep_bs) + { +struct multiboot_tag_basic_meminfo *tag + = (struct multiboot_tag_basic_meminfo *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; + tag->size =sizeof (struct multiboot_tag_basic_meminfo ); -/* Convert from bytes to kilobytes. */ - tag->mem_lower =grub_mmap_get_lower () /1024 ; - tag->mem_upper =grub_mmap_get_upper () /1024 ; - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +/* Convert from bytes to kilobytes. */ + tag->mem_lower =grub_mmap_get_lower () /1024 ; + tag->mem_upper =grub_mmap_get_upper () /1024 ; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct grub_net_network_level_interface *net;@@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)grub_efi_uintn_t efi_desc_size;grub_efi_uint32_t efi_desc_version; - tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; - tag->size =sizeof (*tag) + efi_mmap_size; -if (!keep_bs) - err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , - &efi_desc_size, &efi_desc_version); -else { -if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap, -NULL , - &efi_desc_size, &efi_desc_version) <=0 ) - err =grub_error (GRUB_ERR_IO ,"couldn't retrieve memory map" ); + tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; + tag->size =sizeof (*tag) + efi_mmap_size; + + err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , + &efi_desc_size, &efi_desc_version); + +if (err) +return err; + + tag->descr_size = efi_desc_size; + tag->descr_vers = efi_desc_version; + tag->size =sizeof (*tag) + efi_mmap_size; + + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); } -if (err) -return err; - tag->descr_size = efi_desc_size; - tag->descr_vers = efi_desc_version; - tag->size =sizeof (*tag) + efi_mmap_size; - - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); }if (keep_bs)Signature · 1 line
1.7.10.4
PATCH v2 6/6 multiboot2: Do not pass memory maps to image if EFI boot services are enabled
In reply to Daniel KiperDo not pass memory maps to image if it asked for EFI boot services. Maps are usually invalid in that case and they can confuse potential user. Image should get memory map itself just before ExitBootServices() call.
--- grub-core/loader/multiboot_mbi2.c | 71 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-)
grub-core/loader/multiboot_mbi2.c +35 -36
@@ -431,7 +431,7 @@ static grub_size_tgrub_multiboot_get_mbi_size (void) {#ifdef GRUB_MACHINE_EFI -if (!efi_mmap_size) +if (!keep_bs && !efi_mmap_size)find_efi_mmap_size ();#endif return 2 *sizeof (grub_uint32_t) +sizeof (struct multiboot_tag )
@@ -805,12 +805,13 @@ grub_multiboot_make_mbi (grub_uint32_t *target) } } - { -struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; -grub_fill_multiboot_mmap (tag); - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +if (!keep_bs) + { +struct multiboot_tag_mmap *tag = (struct multiboot_tag_mmap *) ptrorig; +grub_fill_multiboot_mmap (tag); + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct multiboot_tag_elf_sections *tag
@@ -826,18 +827,19 @@ grub_multiboot_make_mbi (grub_uint32_t *target) / sizeof (grub_properly_aligned_t); } - { -struct multiboot_tag_basic_meminfo *tag - = (struct multiboot_tag_basic_meminfo *) ptrorig; - tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; - tag->size =sizeof (struct multiboot_tag_basic_meminfo ); +if (!keep_bs) + { +struct multiboot_tag_basic_meminfo *tag + = (struct multiboot_tag_basic_meminfo *) ptrorig; + tag->type =MULTIBOOT_TAG_TYPE_BASIC_MEMINFO ; + tag->size =sizeof (struct multiboot_tag_basic_meminfo ); -/* Convert from bytes to kilobytes. */ - tag->mem_lower =grub_mmap_get_lower () /1024 ; - tag->mem_upper =grub_mmap_get_upper () /1024 ; - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); - } +/* Convert from bytes to kilobytes. */ + tag->mem_lower =grub_mmap_get_lower () /1024 ; + tag->mem_upper =grub_mmap_get_upper () /1024 ; + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); + } {struct grub_net_network_level_interface *net;
@@ -936,27 +938,24 @@ grub_multiboot_make_mbi (grub_uint32_t *target)grub_efi_uintn_t efi_desc_size;grub_efi_uint32_t efi_desc_version; - tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; - tag->size =sizeof (*tag) + efi_mmap_size; -if (!keep_bs) - err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , - &efi_desc_size, &efi_desc_version); -else { -if (grub_efi_get_memory_map (&efi_mmap_size, (void *) tag->efi_mmap, -NULL , - &efi_desc_size, &efi_desc_version) <=0 ) - err =grub_error (GRUB_ERR_IO ,"couldn't retrieve memory map" ); + tag->type =MULTIBOOT_TAG_TYPE_EFI_MMAP ; + tag->size =sizeof (*tag) + efi_mmap_size; + + err =grub_efi_finish_boot_services (&efi_mmap_size, tag->efi_mmap,NULL , + &efi_desc_size, &efi_desc_version); + +if (err) +return err; + + tag->descr_size = efi_desc_size; + tag->descr_vers = efi_desc_version; + tag->size =sizeof (*tag) + efi_mmap_size; + + ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) + /sizeof (grub_properly_aligned_t); } -if (err) -return err; - tag->descr_size = efi_desc_size; - tag->descr_vers = efi_desc_version; - tag->size =sizeof (*tag) + efi_mmap_size; - - ptrorig +=ALIGN_UP (tag->size,MULTIBOOT_TAG_ALIGN ) - /sizeof (grub_properly_aligned_t); }if (keep_bs)
Signature · 1 line
1.7.10.4
Guys, especially GRUB2 maintainers,
Quoted 8 lines · Daniel Kiper
Hi,
This patch series:
- enables EFI boot services usage in loaded images by multiboot2 protocol,
- add support for multiboot2 protocol compatible relocatable images,
- fixes two minor issues.
Is it possible to get your comments to this patch series (I would like to thank you Andrei and Konrad for review)? We need this functionality as Xen community and as Oracle. Hence, it will be nice to know that we go in good direction. So, if you think that we should change something please drop me a line.
I know that you are busy but please, at least, tell us when you take a look at it.
Daniel
Guys, especially GRUB2 maintainers,
Quoted 8 lines · Daniel Kiper
Hi,
This patch series:
- enables EFI boot services usage in loaded images by multiboot2 protocol,
- add support for multiboot2 protocol compatible relocatable images,
- fixes two minor issues.
Is it possible to get your comments to this patch series (I would like to thank you Andrei and Konrad for review)? We need this functionality as Xen community and as Oracle. Hence, it will be nice to know that we go in good direction. So, if you think that we should change something please drop me a line.
I know that you are busy but please, at least, tell us when you take a look at it.
Daniel