]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Merge relocator branch
authorRobert Millan <rmh@aybabtu.com>
Sun, 13 Dec 2009 18:37:44 +0000 (18:37 +0000)
committerRobert Millan <rmh@aybabtu.com>
Sun, 13 Dec 2009 18:37:44 +0000 (18:37 +0000)
1  2 
ChangeLog
include/grub/i386/multiboot.h
lib/i386/relocator_asm.S

diff --cc ChangeLog
index 5587f95f999cb5db4a3fdc4bdf2201af8b6a050e,de12dd0daf1d33c62473d8e7877b66098e61e4de..026ff3e76d9be2e4106177e3d451807c5b2650b7
+++ b/ChangeLog
@@@ -1,27 -1,3 +1,109 @@@
++2009-12-13  Robert Millan  <rmh.grub@aybabtu.com>
++
++      * loader/i386/multiboot_elfxx.c
++      (CONCAT(grub_multiboot_load_elf, XX)): Fix `grub_multiboot_payload_eip'
++      initialization.
++
++2009-12-13  Vladimir Serbinenko  <phcoder@gmail.com>
++
++      Relocator framework
++
++      * loader/i386/xnu_helper.S: Removed. All users updated.
++      * conf/i386.rmk (pkglib_MODULES): Add relocator.mod.
++      (relocator_mod_SOURCES): New variable.
++      (relocator_mod_CFLAGS): Likewise.
++      (relocator_mod_LDFLAGS): Likewise.
++      (relocator_mod_ASFLAGS): Likewise.
++      * conf/x86_64.rmk: Likewise.
++      * include/grub/i386/multiboot.h (grub_multiboot_payload_orig): Removed.
++      (grub_multiboot_payload_entry_offset): Likewise.
++      (grub_multiboot_forward_relocator): Likewise.
++      (grub_multiboot_forward_relocator_end): Likewise.
++      (grub_multiboot_backward_relocator): Likewise.
++      (grub_multiboot_backward_relocator_end): Likewise.
++      (grub_multiboot_payload_eip): New variable.
++      (grub_multiboot_payload_orig): Likewise.
++      * include/grub/i386/pc/memory.h: Include grub/i386/memory.h.
++      (GRUB_MEMORY_MACHINE_CR0_PE_ON): Move from here ...
++      * include/grub/i386/memory.h
++      (GRUB_MEMORY_CPU_CR0_PE_ON): ... to here
++      (GRUB_MEMORY_CPU_CR4_PAE_ON): New definition.
++      (GRUB_MEMORY_CPU_CR0_PAGING_ON): Likewise.
++      (GRUB_MEMORY_CPU_AMD64_MSR): Likewise.
++      (GRUB_MEMORY_CPU_AMD64_MSR_ON): Likewise.
++      * include/grub/i386/relocator.h: New file.
++      * include/grub/x86_64/relocator.h: Likewise.
++      * include/grub/i386/xnu.h: Include grub/cpu/relocator.h.
++      (XNU_RELOCATOR): New macro.
++      (grub_xnu_launcher_start): Remove.
++      (grub_xnu_launcher_end): Likewise.
++      * include/grub/xnu.h (grub_xnu_boot_resume): New prototype.
++      (grub_xnu_heap_real_start): Remove.
++      (grub_xnu_heap_start): Change to void *. All users updated.
++      * kern/i386/realmode.S (real_to_prot): Use GRUB_MEMORY_CPU_CR0_PE_ON.
++      * lib/i386/relocator.c: New file.
++      * lib/i386/relocator_asm.S: Likewise.
++      * lib/i386/relocator_backward.S: Likewise.
++      * lib/mips/relocator.c: Likewise.
++      * lib/mips/relocator_asm.S: Likewise.
++      * lib/relocator.c: Likewise.
++      * loader/i386/multiboot.c: Include grub/i386/relocator.h.
++      (entry): Removed.
++      (playground): Likewise.
++      (grub_multiboot_payload_orig): New variable.
++      (grub_multiboot_payload_dest): Likewise.
++      (grub_multiboot_payload_size): Likewise.
++      (grub_multiboot_payload_eip): Likewise.
++      (grub_multiboot_payload_esp): Likewise.
++      (grub_multiboot_boot): Use grub_relocator32_boot.
++      (grub_multiboot_unload): Free relocators.
++      (grub_multiboot): Setup stack. Use relocators.
++      * loader/i386/multiboot_elfxx.c: Include grub/i386/relocator.h.
++      (grub_multiboot_load_elfXX): Use relocators.
++      * loader/i386/multiboot_helper.S (grub_multiboot_payload_orig): Removed.
++      (grub_multiboot_payload_size): Likewise.
++      (grub_multiboot_payload_dest): Likewise.
++      (grub_multiboot_payload_entry_offset): Likewise.
++      (grub_multiboot_forward_relocator): Likewise.
++      (grub_multiboot_backward_relocator): Likewise.
++      (grub_multiboot_real_boot): Likewise.
++      * loader/i386/xnu.c (grub_xnu_heap_will_be_at): New variable.
++      (grub_xnu_entry_point): Likewise.
++      (grub_xnu_arg1): Likewise.
++      (grub_xnu_stack): Likewise.
++      (grub_xnu_launch): Removed.
++      (grub_xnu_boot_resume): New function.
++      (grub_xnu_boot): Use relocators.
++      * loader/i386/xnu_helper.S: Removed.
++      * loader/xnu.c (grub_xnu_heap_start): New variable.
++      (grub_xnu_heap_size): Likewise.
++      (grub_xnu_heap_malloc): Use relocators.
++      * loader/xnu_resume.c (grub_xnu_resume): Use relocators.
++
 +2009-12-13  Vladimir Serbinenko  <phcoder@gmail.com>
 +
 +      * kern/i386/pc/startup.S (multiboot_entry): Setup stack before calling
 +      anything.
 +
 +2009-12-13  Carles Pina i Estany  <carles@pina.cat>
 +
 +      * script/execute.c (grub_script_execute_cmdline): Set grub_errno to
 +      GRUB_ERR_NONE before calling grub_env_set.
 +
 +2009-12-12  Robert Millan  <rmh@aybabtu.com>
 +
 +      * gendistlist.sh (EXTRA_DISTFILES): Add `genvideolist.sh'.
 +      * genmk.rb (video): New variable.
 +      (CLEANFILES, VIDEOFILES): Add #{video}.
 +      (#{video}): New target rule.
 +      * genvideolist.sh: New file.
 +      * Makefile.in (pkglib_DATA): Add video.lst.
 +      (video.lst): New target rule.
 +      * util/grub-mkconfig.in: Initialize ${GRUB_VIDEO_BACKEND} using
 +      `video.lst'.
 +      * util/grub.d/30_os-prober.in: Replace `vbe' with
 +      ${GRUB_VIDEO_BACKEND}.
 +
  2009-12-11  Robert Millan  <rmh.grub@aybabtu.com>
  
        * THANKS: Add David Miller.
index b8cab9d2412fa286d0a48562ff43916820a503d3,2d990bf866ca8d8089cec2de09d001b65ba9ce3e..584955449bb7ec4e733420c8c0cc60cbb6fcf657
@@@ -27,16 -27,11 +27,9 @@@ void grub_multiboot2_real_boot (grub_ad
                                struct multiboot_info *mbi)
       __attribute__ ((noreturn));
  
- extern grub_addr_t grub_multiboot_payload_orig;
+ extern grub_uint32_t grub_multiboot_payload_eip;
+ extern char *grub_multiboot_payload_orig;
  extern grub_addr_t grub_multiboot_payload_dest;
  extern grub_size_t grub_multiboot_payload_size;
- extern grub_uint32_t grub_multiboot_payload_entry_offset;
- extern grub_uint8_t grub_multiboot_forward_relocator;
- extern grub_uint8_t grub_multiboot_forward_relocator_end;
- extern grub_uint8_t grub_multiboot_backward_relocator;
- extern grub_uint8_t grub_multiboot_backward_relocator_end;
- #define RELOCATOR_SIZEOF(x)   (&grub_multiboot_##x##_relocator_end - &grub_multiboot_##x##_relocator)
  
 -#define GRUB_MULTIBOOT_STACK_SIZE 4096
 -
  #endif /* ! GRUB_MULTIBOOT_CPU_HEADER */
index 0000000000000000000000000000000000000000,c1be85c2b1a7084089c9dbe3a6239df1052ec092..d39732987e5f347e6213e5663205e228b984b6e6
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,248 +1,248 @@@
 -      /* Update %cs. Thanks to David Miller for pointing this mistake out. */
+ /*
+  *  GRUB  --  GRand Unified Bootloader
+  *  Copyright (C) 2009  Free Software Foundation, Inc.
+  *
+  *  GRUB is free software: you can redistribute it and/or modify
+  *  it under the terms of the GNU General Public License as published by
+  *  the Free Software Foundation, either version 3 of the License, or
+  *  (at your option) any later version.
+  *
+  *  GRUB is distributed in the hope that it will be useful,
+  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  *  GNU General Public License for more details.
+  *
+  *  You should have received a copy of the GNU General Public License
+  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+  */
+ #include <grub/symbol.h>
+ #include <grub/i386/memory.h>
+ #ifdef BACKWARD
+ #define RELOCATOR_VARIABLE(x) VARIABLE(grub_relocator32_backward_ ## x)
+ #else
+ #define RELOCATOR_VARIABLE(x) VARIABLE(grub_relocator32_forward_ ## x)
+ #endif
+ #ifdef __x86_64__
+ #define RAX %rax
+ #define RCX %rcx
+ #define RDI %rdi
+ #define RSI %rdi
+ #else
+ #define RAX %eax
+ #define RCX %ecx
+ #define RDI %edi      
+ #define RSI %esi      
+ #endif
+ /* The code segment of the protected mode.  */
+ #define CODE_SEGMENT  0x10
+ /* The data segment of the protected mode.  */
+ #define DATA_SEGMENT  0x18
+       
+       .p2align        4       /* force 16-byte alignment */
+ RELOCATOR_VARIABLE(start)
+ #ifdef BACKWARD
+ LOCAL(base):
+ #endif
+       cli
+ #ifndef __x86_64__
+       /* mov imm32, %eax */
+       .byte   0xb8
+ RELOCATOR_VARIABLE(dest)
+       .long   0
+       movl    %eax, %edi
+       /* mov imm32, %eax */
+       .byte   0xb8
+ RELOCATOR_VARIABLE(src)
+       .long   0
+       movl    %eax, %esi
+       /* mov imm32, %ecx */
+       .byte   0xb9
+ RELOCATOR_VARIABLE(size)
+       .long   0
+ #else
+       xorq    %rax, %rax
+       /* mov imm32, %eax */
+       .byte   0xb8
+ RELOCATOR_VARIABLE(dest)
+       .long   0
+       movq    %rax, %rdi
+       /* mov imm64, %rax */
+       .byte   0x48
+       .byte   0xb8
+ RELOCATOR_VARIABLE(src)
+       .long   0, 0
+       movq    %rax, %rsi
+       xorq    %rcx, %rcx
+       /* mov imm32, %ecx */
+       .byte   0xb9
+ RELOCATOR_VARIABLE(size)
+       .long   0
+ #endif
+       mov     RDI, RAX
+       
+ #ifdef BACKWARD
+       add     RCX, RSI
+       add     RCX, RDI
+ #endif
+ #ifndef BACKWARD
+       add     RCX, RAX
+ #endif
+       add     $0x3, RCX
+       shr     $2, RCX
+       
+ #ifdef BACKWARD
+       /* Backward movsl is implicitly off-by-four.  compensate that.  */
+       sub     $4,     RSI
+       sub     $4,     RDI
+       /* Backward copy.  */
+       std
+       rep
+       movsl
+ #else
+       /* Forward copy.  */
+       cld
+       rep
+       movsl
+ #endif
+       /* %rax contains now our new 'base'.  */
+       mov     RAX, RSI
+       add     $(LOCAL(cont0) - LOCAL(base)), RAX
+       jmp     *RAX
+ LOCAL(cont0):
+       lea     (LOCAL(cont1) - LOCAL(base)) (RSI, 1), RAX
+       movl    %eax, (LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
+       lea     (LOCAL(gdt) - LOCAL(base)) (RSI, 1), RAX
+       mov     RAX, (LOCAL(gdt_addr) - LOCAL(base)) (RSI, 1)
+       /* Switch to compatibility mode. */
+       lgdt    (LOCAL(gdtdesc) - LOCAL(base)) (RSI, 1)
++      /* Update %cs.  */
+       ljmp    *(LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
+ LOCAL(cont1):
+       .code32
+       /* Update other registers. */
+       movl    $DATA_SEGMENT, %eax
+       movl    %eax, %ds
+       movl    %eax, %es
+       movl    %eax, %fs
+       movl    %eax, %gs
+       movl    %eax, %ss
+       /* Disable paging. */
+       movl    %cr0, %eax
+       andl    $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax
+       movl    %eax, %cr0
+       /* Disable amd64. */
+       movl    $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
+       rdmsr
+       andl    $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
+       wrmsr
+       /* Turn off PAE. */
+       movl    %cr4, %eax
+       andl    $GRUB_MEMORY_CPU_CR4_PAE_ON, %eax
+       movl    %eax, %cr4
+       jmp     LOCAL(cont2)
+ LOCAL(cont2):
+       .code32
+       /* mov imm32, %eax */
+       .byte   0xb8
+ RELOCATOR_VARIABLE (esp)
+       .long   0
+       movl    %eax, %esp
+       /* mov imm32, %eax */
+       .byte   0xb8
+ RELOCATOR_VARIABLE (eax)
+       .long   0
+       /* mov imm32, %ebx */
+       .byte   0xbb
+ RELOCATOR_VARIABLE (ebx)
+       .long   0
+       /* mov imm32, %ecx */
+       .byte   0xb9
+ RELOCATOR_VARIABLE (ecx)
+       .long   0
+       /* mov imm32, %edx */
+       .byte   0xba
+ RELOCATOR_VARIABLE (edx)
+       .long   0
+       /* Cleared direction flag is of no problem with any current
+          payload and makes this implementation easier.  */
+       cld
+       .byte   0xea
+ RELOCATOR_VARIABLE (eip)
+       .long   0
+       .word   CODE_SEGMENT
+       /* GDT. Copied from loader/i386/linux.c. */
+       .p2align        4
+ LOCAL(gdt):
+       /* NULL.  */
+       .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       
+       /* Reserved.  */
+       .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       /* Code segment.  */
+       .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
+       /* Data segment.  */
+       .byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
+       .p2align        4
+ LOCAL(gdtdesc):
+       .word   0x27
+ LOCAL(gdt_addr):
+ #ifdef __x86_64__
+       /* Filled by the code. */
+       .quad   0
+ #else
+       /* Filled by the code. */
+       .long   0
+ #endif
+       
+       .p2align        4
+ LOCAL(jump_vector):
+       /* Jump location. Is filled by the code */
+       .long   0
+       .long   CODE_SEGMENT
+ #ifndef BACKWARD
+ LOCAL(base):
+ #endif
+ RELOCATOR_VARIABLE(end)