zero-fill entry before asking BIOS for memory map
PATCH 1/1 zero-fill entry before asking BIOS for memory map
Hello. According to xen some BIOSes update only lower 32-bit in mmap entries. To workaround this and not get high values in memory map zero-fill before calling BIOS
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
ChangeLog +5 -0
@@ -1,3 +1,8 @@ +2009-07-23 Vladimir Serbinenko <[email protected]> + + * kern/i386/pc/mmap.c (grub_machine_mmap_iterate): Zero-fill entry + before calling BIOS + 2009-07-21 Vladimir Serbinenko <[email protected]> UUID support for UFS
kern/i386/pc/mmap.c +5 -0
@@ -20,6 +20,7 @@#include <grub/machine/memory.h> #include <grub/err.h> #include <grub/types.h> +#include <grub/misc.h> grub_err_t grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
@@ -28,6 +29,8 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uinstruct grub_machine_mmap_entry *entry = (struct grub_machine_mmap_entry *)GRUB_MEMORY_MACHINE_SCRATCH_ADDR ; +grub_memset (entry,0 ,sizeof (entry)); +/* Check if grub_get_mmap_entry works. */ cont =grub_get_mmap_entry (entry,0 );
@@ -43,6 +46,8 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uinif (! cont)break ; +grub_memset (entry,0 ,sizeof (entry)); + cont =grub_get_mmap_entry (entry, cont); }while (entry->size);
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
Hello. According to xen some BIOSes update only lower 32-bit in mmap entries. To workaround this and not get high values in memory map zero-fill before calling BIOS
I think the fix belongs to grub_get_mmap_entry(), not to all of its callers. Something like this:
kern/i386/pc/startup.S +8 -0
@@ -997,6 +997,14 @@ FUNCTION(grub_get_mmap_entry) /* push ADDR */ pushl %eax + /* clear the request area, buggy BIOSes may not clear it */ + xor %edi, %edi + movl %edi, 4(%eax) + movl %edi, 8(%eax) + movl %edi, 12(%eax) + movl %edi, 16(%eax) + movl %edi, 20(%eax) + /* place address (+4) in ES:DI */ addl $4, %eax movl %eax, %edi
I don't know whether it would interfere with the Apple CC workaround. It would be great if we get rid of it, perhaps by using labels starting with "L_".
Signature · 2 lines
Regards, Pavel Roskin
Quoted 7 lines · Pavel Roskin
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
Hello. According to xen some BIOSes update only lower 32-bit in mmap entries. To workaround this and not get high values in memory map zero-fill before calling BIOS
I think the fix belongs to
grub_get_mmap_entry(), not to all of its callers.
I'm ok with this too. The main reason for me to decide for one or another would be core.img size but I haven't checked yet which one is smaller. Actually asm part is kept to minimum and grub_machine_mmap_iterate is the C wrapper and I followed this idea. But as I said your solution is fine for me too.
Quoted 10 lines
Something like this:
kern/i386/pc/startup.S +0
-0@@ -997,6 +997,14 @@ FUNCTION(grub_get_mmap_entry) /* push ADDR */pushl %eax
Quoted 11 lines
+ /* clear the request area, buggy BIOSes may not clear it */
+ xor %edi, %edi
+ movl %edi, 4(%eax)
+ movl %edi, 8(%eax)
+ movl %edi, 12(%eax)
+ movl %edi, 16(%eax)
+ movl %edi, 20(%eax)
+
/* place address (+4) in ES:DI */
addl $4, %eax
movl %eax, %edi
For me this coode looks weird because of using edi as zero register and eax as pointer. Could we perhaps move this code down and use eax as 0 and edi as pointer?
Quoted 15 lines
I don't know whether it would interfere with the Apple CC workaround. It would be great if we get rid of it, perhaps by using labels starting with "L_".
--
Regards,
Pavel Roskin_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 13 lines · Pavel Roskin
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
Hello. According to xen some BIOSes update only lower 32-bit in mmap entries. To workaround this and not get high values in memory map zero-fill before calling BIOS
I think the fix belongs to
grub_get_mmap_entry(), not to all of its callers. Something like this:kern/i386/pc/startup.S +0
-0
kern/i386/pc/startup.S FUNCTION(grub_get_mmap_entry) · line 1006
Quoted 10 lines
kern/i386/pc/startup.S +7
-0@@ -997,6 +997,14 @@ FUNCTION(grub_get_mmap_entry) /* push ADDR */ pushl %eax + /* clear the request area, buggy BIOSes may not clear it */ + xor %edi, %edi + movl %edi, 4(%eax) + movl %edi, 8(%eax) + movl %edi, 12(%eax) + movl %edi, 16(%eax) + movl %edi, 20(%eax)
This effectively hardcodes sizeof(entry). Can we avoid it?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 9 lines
Quoted 7 lines
+ /* clear the request area, buggy BIOSes may not clear it */
+ xor %edi, %edi
+ movl %edi, 4(%eax)
+ movl %edi, 8(%eax)
+ movl %edi, 12(%eax)
+ movl %edi, 16(%eax)
+ movl %edi, 20(%eax)This effectively hardcodes sizeof(entry). Can we avoid it?
Can one or another version be merge for release?
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 10 lines · Vladimir 'phcoder' Serbinenko
Quoted 9 lines
Quoted 7 lines
+ /* clear the request area, buggy BIOSes may not clear it */
+ xor %edi, %edi
+ movl %edi, 4(%eax)
+ movl %edi, 8(%eax)
+ movl %edi, 12(%eax)
+ movl %edi, 16(%eax)
+ movl %edi, 20(%eax)This effectively hardcodes sizeof(entry). Can we avoid it?
Can one or another version be merge for release?
Pavel's point is right. I don't like hardcoding sizeof(entry), but the alternatives seem worse.
Please, could you at least add a comment to clarify that 20 aka sizeof(entry) is implicit here ?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."