From: Robert Millan Date: Sun, 13 Dec 2009 18:37:44 +0000 (+0000) Subject: Merge relocator branch X-Git-Tag: 1.98~314 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b50b77b9a8d4cb117c8219dc1c7724351819efec;p=thirdparty%2Fgrub.git Merge relocator branch --- b50b77b9a8d4cb117c8219dc1c7724351819efec diff --cc ChangeLog index 5587f95f9,de12dd0da..026ff3e76 --- a/ChangeLog +++ b/ChangeLog @@@ -1,27 -1,3 +1,109 @@@ ++2009-12-13 Robert Millan ++ ++ * loader/i386/multiboot_elfxx.c ++ (CONCAT(grub_multiboot_load_elf, XX)): Fix `grub_multiboot_payload_eip' ++ initialization. ++ ++2009-12-13 Vladimir Serbinenko ++ ++ 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 + + * kern/i386/pc/startup.S (multiboot_entry): Setup stack before calling + anything. + +2009-12-13 Carles Pina i Estany + + * script/execute.c (grub_script_execute_cmdline): Set grub_errno to + GRUB_ERR_NONE before calling grub_env_set. + +2009-12-12 Robert Millan + + * 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 * THANKS: Add David Miller. diff --cc include/grub/i386/multiboot.h index b8cab9d24,2d990bf86..584955449 --- a/include/grub/i386/multiboot.h +++ b/include/grub/i386/multiboot.h @@@ -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 */ diff --cc lib/i386/relocator_asm.S index 000000000,c1be85c2b..d39732987 mode 000000,100644..100644 --- a/lib/i386/relocator_asm.S +++ b/lib/i386/relocator_asm.S @@@ -1,0 -1,248 +1,248 @@@ + /* + * 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 . + */ + + #include + #include + + #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. Thanks to David Miller for pointing this mistake out. */ ++ /* 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)