]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
intwrap grub_get_mmap_entry
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 10 Apr 2010 17:12:04 +0000 (19:12 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 10 Apr 2010 17:12:04 +0000 (19:12 +0200)
include/grub/i386/pc/init.h
kern/i386/pc/mmap.c
kern/i386/pc/startup.S

index 7dc8ee1f4a0ba24d310314ba0dfd475cd7111ff3..a6d2abf413460992a3cc008cea3c23a3cf31a7a7 100644 (file)
 #include <grub/symbol.h>
 #include <grub/machine/memory.h>
 
-/* Get a memory map entry. Return next continuation value. Zero means
-   the end.  */
-grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry,
-                                  grub_uint32_t cont);
-
 /* Turn on/off Gate A20.  */
 void grub_gate_a20 (int on);
 
index 2758d17f8b8c77bef33711b6491c88f14239d92e..25f8a739b7f672ca56338ae053df87289e1a1809 100644 (file)
@@ -61,6 +61,53 @@ grub_get_eisa_mmap (void)
   return (regs.eax & 0xffff) | (regs.ebx << 16);
 }
 
+/*
+ *
+ * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to
+ *             start), for the Query System Address Map BIOS call.
+ *
+ *  Sets the first 4-byte int value of "addr" to the size returned by
+ *  the call.  If the call fails, sets it to zero.
+ *
+ *     Returns:  new (non-zero) continuation value, 0 if done.
+ */
+/* Get a memory map entry. Return next continuation value. Zero means
+   the end.  */
+static grub_uint32_t
+grub_get_mmap_entry (struct grub_machine_mmap_entry *entry,
+                    grub_uint32_t cont)
+{
+  struct grub_bios_int_registers regs;
+
+  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
+
+  /* place address (+4) in ES:DI */
+  regs.es = ((grub_addr_t) &entry->addr) >> 4;
+  regs.edi = ((grub_addr_t) &entry->addr) & 0xf;
+       
+  /* set continuation value */
+  regs.ebx = cont;
+
+  /* set default maximum buffer size */
+  regs.ecx = sizeof (*entry) - sizeof (entry->size);
+
+  /* set EDX to 'SMAP' */
+  regs.edx = 0x534d4150;
+
+  regs.eax = 0xe820;
+  grub_bios_interrupt (0x15, &regs);
+
+  /* write length of buffer (zero if error) into ADDR */       
+  if ((regs.flags & GRUB_CPU_INT_FLAGS_CARRY) || regs.eax != 0x534d4150
+      || regs.ecx < 0x14 || regs.ecx > 0x400)
+    entry->size = 0;
+  else
+    entry->size = regs.ecx;
+
+  /* return the continuation value */
+  return regs.ebx;
+}
+
 grub_err_t
 grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
 {
index 3fa1b11e8a28a9ff0a94668c83aead2c53985b79..ee677fc15971d7f7bf871122a87f310cf12f9c5e 100644 (file)
@@ -505,94 +505,6 @@ FUNCTION(grub_chainloader_real_boot)
 
 #include "../loader.S"
 
-/*
- *
- * grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to
- *             start), for the Query System Address Map BIOS call.
- *
- *  Sets the first 4-byte int value of "addr" to the size returned by
- *  the call.  If the call fails, sets it to zero.
- *
- *     Returns:  new (non-zero) continuation value, 0 if done.
- */
-
-FUNCTION(grub_get_mmap_entry)
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %edi
-       pushl   %esi
-
-       /* push ADDR */
-       pushl   %eax
-
-       /* place address (+4) in ES:DI */
-       addl    $4, %eax
-       movl    %eax, %edi
-       andl    $0xf, %edi
-       shrl    $4, %eax
-       movl    %eax, %esi
-
-       /* set continuation value */
-       movl    %edx, %ebx
-
-       /* set default maximum buffer size */
-       movl    $0x14, %ecx
-
-       /* set EDX to 'SMAP' */
-       movl    $0x534d4150, %edx
-
-       call    prot_to_real    /* enter real mode */
-       .code16
-
-       movw    %si, %es
-       movl    $0xe820, %eax
-       int     $0x15
-
-       DATA32  jc      xnosmap
-
-       cmpl    $0x534d4150, %eax
-       jne     xnosmap
-
-       cmpl    $0x14, %ecx
-       jl      xnosmap
-
-       cmpl    $0x400, %ecx
-       jg      xnosmap
-
-       jmp     xsmap
-
-xnosmap:
-       xorl    %ecx, %ecx
-
-/*     Apple's cc jumps few bytes before the correct
-       label in this context. Hence nops. */
-#ifdef APPLE_CC
-       nop
-       nop
-       nop
-       nop
-       nop
-       nop
-#endif
-
-xsmap:
-       DATA32  call    real_to_prot
-       .code32
-
-       /* write length of buffer (zero if error) into ADDR */
-       popl    %eax
-       movl    %ecx, (%eax)
-
-       /* set return value to continuation */
-       movl    %ebx, %eax
-
-       popl    %esi
-       popl    %edi
-       popl    %ebx
-       popl    %ebp
-       ret
-
-
 /*
  * void grub_console_real_putchar (int c)
  *