From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LiGuQ-0003W5-UI for mharc-grub-devel@gnu.org; Fri, 13 Mar 2009 19:35:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LiGuO-0003Ty-Mh for grub-devel@gnu.org; Fri, 13 Mar 2009 19:35:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LiGuJ-0003LB-Ip for grub-devel@gnu.org; Fri, 13 Mar 2009 19:35:20 -0400 Received: from [199.232.76.173] (port=58898 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LiGuJ-0003L8-Bc for grub-devel@gnu.org; Fri, 13 Mar 2009 19:35:15 -0400 Received: from mail-bw0-f172.google.com ([209.85.218.172]:59028) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LiGuI-00008o-Ff for grub-devel@gnu.org; Fri, 13 Mar 2009 19:35:15 -0400 Received: by bwz20 with SMTP id 20so2913026bwz.42 for ; Fri, 13 Mar 2009 16:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type; bh=3h5viM/PLYwA65H2VWXQ+rlwdXHIg3iMieFoAZqu94o=; b=fp1rH/bBT3jFLv5o93zy9BTVgyhgfRC5eLMHh9ZC+ozvd0h6+5Nj/Q4tK3GXfFgHu/ JNPyZmxqFQjaW0ch9Fsis31iMHcJUuGZqh9VfNmBAQiBylY5esgUWoK6k4ECGYteYwDM BA/ntJVvaRLHBY4t8ClbEw18eaiDLXlCm9n7s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; b=kZ1vLyVd73PiDCKmQqVcYE5LhU9OCE4Co/hG2nxUOnlBl8Bpg0RrQm0hxJN3oQ34Go cKnfMaHhXn53rksXsnwCJAvV7FXJHyKl4r3ZP8B4YudfK0HPH5HImHlsYouSxRynG3qO 5SObsQZFHFnNj30N+bHGQCdfaA+6C5E1E6sCM= Received: by 10.102.234.18 with SMTP id g18mr921274muh.102.1236987311704; Fri, 13 Mar 2009 16:35:11 -0700 (PDT) Received: from ?192.168.1.25? (7.86.202.62.cust.bluewin.ch [62.202.86.7]) by mx.google.com with ESMTPS id j6sm4745907mue.34.2009.03.13.16.35.10 (version=SSLv3 cipher=RC4-MD5); Fri, 13 Mar 2009 16:35:11 -0700 (PDT) Message-ID: <49BAEDAD.3030704@gmail.com> Date: Sat, 14 Mar 2009 00:35:09 +0100 From: phcoder User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: The development of GRUB 2 References: <4992ABA6.7040200@gmail.com> In-Reply-To: <4992ABA6.7040200@gmail.com> Content-Type: multipart/mixed; boundary="------------000705060702030508070101" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: [Patch] Move multiboot helpers out of the kernel X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2009 23:35:21 -0000 This is a multi-part message in MIME format. --------------000705060702030508070101 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Rediffed 2009-03-14 Vladimir Serbinenko Move multiboot helper out of kernel * conf/i386-pc.rmk: Add loader/i386/multiboot_helper.S to _multiboot.mod * conf/i386-coreboot.rmk: Likewise * conf/i386-ieee1275.rmk: Likewise * kern/i386/loader.S: Move multiboot helpers from here... * loader/i386/multiboot_helper.S: ...moved here * include/grub/i386/loader.h: Move declarations of multiboot helpers from here... * include/grub/i386/multiboot.h: ...moved here * loader/i386/multiboot.c: Added include of grub/cpu/multiboot.h phcoder wrote: > Hello. multiboot helpers have no real reason to stay in kernel. So here > is the proposition to move them out of it to _multiboot.mod. > Changelog: > 2009-02-11 Vladimir Serbinenko > > Move multiboot helper out of kernel > > * conf/i386-pc.rmk: Add loader/i386/multiboot.S to > _multiboot.mod > * conf/i386-coreboot.rmk: Likewise > * conf/i386-ieee1275.rmk: Likewise > * kern/i386/loader.S: Move multiboot helpers from here... > * loader/i386/multiboot.S: ...moved here > * include/grub/i386/loader.h: Move declarations of multiboot > helpers from here... > * include/grub/i386/multiboot.h: ...moved here > * loader/i386/pc/multiboot.c: Added include of > grub/cpu/multiboot.h > > Thanks > Vladimir 'phcoder' Serbinenko > -- Regards Vladimir 'phcoder' Serbinenko --------------000705060702030508070101 Content-Type: text/x-diff; name="mb.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mb.patch" Index: conf/i386-pc.rmk =================================================================== --- conf/i386-pc.rmk (revision 2030) +++ conf/i386-pc.rmk (working copy) @@ -238,11 +238,13 @@ # For _multiboot.mod. _multiboot_mod_SOURCES = loader/i386/multiboot.c \ + loader/i386/multiboot_helper.S \ loader/i386/pc/multiboot2.c \ loader/multiboot2.c \ loader/multiboot_loader.c _multiboot_mod_CFLAGS = $(COMMON_CFLAGS) _multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) +_multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) # For multiboot.mod. multiboot_mod_SOURCES = loader/multiboot_loader_normal.c Index: conf/i386-coreboot.rmk =================================================================== --- conf/i386-coreboot.rmk (revision 2030) +++ conf/i386-coreboot.rmk (working copy) @@ -151,10 +151,12 @@ # For _multiboot.mod. _multiboot_mod_SOURCES = loader/i386/multiboot.c \ loader/i386/pc/multiboot2.c \ + loader/i386/multiboot_helper.S \ loader/multiboot2.c \ loader/multiboot_loader.c _multiboot_mod_CFLAGS = $(COMMON_CFLAGS) _multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) +_multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) # For multiboot.mod. multiboot_mod_SOURCES = loader/multiboot_loader_normal.c Index: conf/i386-ieee1275.rmk =================================================================== --- conf/i386-ieee1275.rmk (revision 2030) +++ conf/i386-ieee1275.rmk (working copy) @@ -126,10 +126,12 @@ # For _multiboot.mod. _multiboot_mod_SOURCES = loader/ieee1275/multiboot2.c \ + loader/i386/multiboot_helper.S \ loader/multiboot2.c \ loader/multiboot_loader.c _multiboot_mod_CFLAGS = $(COMMON_CFLAGS) _multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) +_multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS) # For multiboot.mod. multiboot_mod_SOURCES = loader/multiboot_loader_normal.c Index: kern/i386/loader.S =================================================================== --- kern/i386/loader.S (revision 2030) +++ kern/i386/loader.S (working copy) @@ -118,107 +118,7 @@ .word 0 .code32 - /* - * This starts the multiboot kernel. - */ - -VARIABLE(grub_multiboot_payload_size) - .long 0 -VARIABLE(grub_multiboot_payload_orig) - .long 0 -VARIABLE(grub_multiboot_payload_dest) - .long 0 -VARIABLE(grub_multiboot_payload_entry_offset) - .long 0 - -/* - * The relocators below understand the following parameters: - * ecx: Size of the block to be copied. - * esi: Where to copy from (always lowest address, even if we're relocating - * backwards). - * edi: Where to copy to (likewise). - * edx: Offset of the entry point (relative to the beginning of the block). - */ -VARIABLE(grub_multiboot_forward_relocator) - /* Add entry offset. */ - addl %edi, %edx - - /* Forward copy. */ - cld - rep - movsb - - jmp *%edx -VARIABLE(grub_multiboot_forward_relocator_end) - -VARIABLE(grub_multiboot_backward_relocator) - /* Add entry offset (before %edi is mangled). */ - addl %edi, %edx - - /* Backward movsb is implicitly off-by-one. compensate that. */ - decl %esi - decl %edi - - /* Backward copy. */ - std - addl %ecx, %esi - addl %ecx, %edi - rep - movsb - - jmp *%edx -VARIABLE(grub_multiboot_backward_relocator_end) - -FUNCTION(grub_multiboot_real_boot) - /* Push the entry address on the stack. */ - pushl %eax - /* Move the address of the multiboot information structure to ebx. */ - movl %edx,%ebx - - /* Unload all modules and stop the floppy driver. */ - call EXT_C(grub_dl_unload_all) - call EXT_C(grub_stop_floppy) - - /* Interrupts should be disabled. */ - cli - - /* Where do we copy what from. */ - movl EXT_C(grub_multiboot_payload_size), %ecx - movl EXT_C(grub_multiboot_payload_orig), %esi - movl EXT_C(grub_multiboot_payload_dest), %edi - movl EXT_C(grub_multiboot_payload_entry_offset), %edx - - /* Move the magic value into eax. */ - movl $MULTIBOOT_MAGIC2, %eax - - /* Jump to the relocator. */ - popl %ebp - jmp *%ebp - -/* - * This starts the multiboot 2 kernel. - */ - -FUNCTION(grub_multiboot2_real_boot) - /* Push the entry address on the stack. */ - pushl %eax - /* Move the address of the multiboot information structure to ebx. */ - movl %edx,%ebx - - /* Unload all modules and stop the floppy driver. */ - call EXT_C(grub_dl_unload_all) - call EXT_C(grub_stop_floppy) - - /* Interrupts should be disabled. */ - cli - - /* Move the magic value into eax and jump to the kernel. */ - movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax - popl %ecx - jmp *%ecx - -/* * Use cdecl calling convention for *BSD kernels. */ Index: include/grub/i386/loader.h =================================================================== --- include/grub/i386/loader.h (revision 2030) +++ include/grub/i386/loader.h (working copy) @@ -22,7 +22,6 @@ #include #include #include -#include extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size); extern char *EXPORT_VAR(grub_linux_tmp_addr); @@ -33,31 +32,15 @@ grub_err_t EXPORT_FUNC(grub_linux_boot) (void); -/* The asm part of the multiboot loader. */ -void EXPORT_FUNC(grub_multiboot_real_boot) (grub_addr_t entry, - struct grub_multiboot_info *mbi) - __attribute__ ((noreturn)); -void EXPORT_FUNC(grub_multiboot2_real_boot) (grub_addr_t entry, - struct grub_multiboot_info *mbi) - __attribute__ ((noreturn)); void EXPORT_FUNC(grub_unix_real_boot) (grub_addr_t entry, ...) __attribute__ ((cdecl,noreturn)); -extern grub_addr_t EXPORT_VAR(grub_multiboot_payload_orig); -extern grub_addr_t EXPORT_VAR(grub_multiboot_payload_dest); -extern grub_size_t EXPORT_VAR(grub_multiboot_payload_size); -extern grub_uint32_t EXPORT_VAR(grub_multiboot_payload_entry_offset); - /* It is necessary to export these functions, because normal mode commands reuse rescue mode commands. */ void grub_rescue_cmd_linux (int argc, char *argv[]); void grub_rescue_cmd_initrd (int argc, char *argv[]); -extern grub_uint8_t EXPORT_VAR(grub_multiboot_forward_relocator); -extern grub_uint8_t EXPORT_VAR(grub_multiboot_forward_relocator_end); -extern grub_uint8_t EXPORT_VAR(grub_multiboot_backward_relocator); -extern grub_uint8_t EXPORT_VAR(grub_multiboot_backward_relocator_end); +void EXPORT_FUNC(grub_stop_floppy) (void); -#define RELOCATOR_SIZEOF(x) (&grub_multiboot_##x##_relocator_end - &grub_multiboot_##x##_relocator) #endif /* ! GRUB_LOADER_CPU_HEADER */ Index: include/grub/i386/multiboot.h =================================================================== --- include/grub/i386/multiboot.h (revision 0) +++ include/grub/i386/multiboot.h (revision 0) @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +#ifndef GRUB_MULTIBOOT_CPU_HEADER +#define GRUB_MULTIBOOT_CPU_HEADER 1 + +/* The asm part of the multiboot loader. */ +void grub_multiboot_real_boot (grub_addr_t entry, + struct grub_multiboot_info *mbi) + __attribute__ ((noreturn)); +void grub_multiboot2_real_boot (grub_addr_t entry, + struct grub_multiboot_info *mbi) + __attribute__ ((noreturn)); + +extern grub_addr_t 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) + +#endif /* ! GRUB_MULTIBOOT_CPU_HEADER */ Index: loader/i386/multiboot.c =================================================================== --- loader/i386/multiboot.c (revision 2030) +++ loader/i386/multiboot.c (working copy) @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,8 @@ static grub_err_t grub_multiboot_boot (void) { + grub_stop_floppy (); + grub_multiboot_real_boot (entry, mbi_dest); /* Not reached. */ Index: loader/i386/pc/multiboot2.c =================================================================== --- loader/i386/pc/multiboot2.c (revision 2030) +++ loader/i386/pc/multiboot2.c (working copy) @@ -73,6 +73,7 @@ void grub_mb2_arch_boot (grub_addr_t entry, void *tags) { + grub_stop_floppy (); grub_multiboot2_real_boot (entry, tags); } Index: loader/i386/multiboot_helper.S =================================================================== --- loader/i386/multiboot_helper.S (revision 0) +++ loader/i386/multiboot_helper.S (revision 0) @@ -0,0 +1,115 @@ +/* + * 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 +#include + + .p2align 2 /* force 4-byte alignment */ + +/* + * This starts the multiboot kernel. + */ + +VARIABLE(grub_multiboot_payload_size) + .long 0 +VARIABLE(grub_multiboot_payload_orig) + .long 0 +VARIABLE(grub_multiboot_payload_dest) + .long 0 +VARIABLE(grub_multiboot_payload_entry_offset) + .long 0 + +/* + * The relocators below understand the following parameters: + * ecx: Size of the block to be copied. + * esi: Where to copy from (always lowest address, even if we're relocating + * backwards). + * edi: Where to copy to (likewise). + * edx: Offset of the entry point (relative to the beginning of the block). + */ + +VARIABLE(grub_multiboot_forward_relocator) + /* Add entry offset. */ + addl %edi, %edx + + /* Forward copy. */ + cld + rep + movsb + + jmp *%edx +VARIABLE(grub_multiboot_forward_relocator_end) + +VARIABLE(grub_multiboot_backward_relocator) + /* Add entry offset (before %edi is mangled). */ + addl %edi, %edx + + /* Backward movsb is implicitly off-by-one. compensate that. */ + decl %esi + decl %edi + + /* Backward copy. */ + std + addl %ecx, %esi + addl %ecx, %edi + rep + movsb + + jmp *%edx +VARIABLE(grub_multiboot_backward_relocator_end) + +FUNCTION(grub_multiboot_real_boot) + /* Push the entry address on the stack. */ + pushl %eax + /* Move the address of the multiboot information structure to ebx. */ + movl %edx,%ebx + + /* Interrupts should be disabled. */ + cli + + /* Where do we copy what from. */ + movl EXT_C(grub_multiboot_payload_size), %ecx + movl EXT_C(grub_multiboot_payload_orig), %esi + movl EXT_C(grub_multiboot_payload_dest), %edi + movl EXT_C(grub_multiboot_payload_entry_offset), %edx + + /* Move the magic value into eax. */ + movl $MULTIBOOT_MAGIC2, %eax + + /* Jump to the relocator. */ + popl %ebp + jmp *%ebp + +/* + * This starts the multiboot 2 kernel. + */ + +FUNCTION(grub_multiboot2_real_boot) + /* Push the entry address on the stack. */ + pushl %eax + /* Move the address of the multiboot information structure to ebx. */ + movl %edx,%ebx + + /* Interrupts should be disabled. */ + cli + + /* Move the magic value into eax and jump to the kernel. */ + movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax + popl %ecx + jmp *%ecx --------------000705060702030508070101--