Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KR2d5-0004u9-Fq for mharc-grub-devel@gnu.org; Thu, 07 Aug 2008 06:21:59 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KR2d2-0004sJ-1L for grub-devel@gnu.org; Thu, 07 Aug 2008 06:21:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KR2d0-0004rl-BI for grub-devel@gnu.org; Thu, 07 Aug 2008 06:21:54 -0400 Received: from [199.232.76.173] (port=49415 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KR2cx-0004r6-Qi for grub-devel@gnu.org; Thu, 07 Aug 2008 06:21:53 -0400 Received: from aybabtu.com ([69.60.117.155]:43411) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KR2cx-0007DB-I4 for grub-devel@gnu.org; Thu, 07 Aug 2008 06:21:51 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1KR2VT-0003OL-Hl for grub-devel@gnu.org; Thu, 07 Aug 2008 12:14:07 +0200 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1KR2bs-00069A-RG for grub-devel@gnu.org; Thu, 07 Aug 2008 12:20:44 +0200 Date: Thu, 7 Aug 2008 12:20:44 +0200 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20080807102044.GA23424@thorin> References: <20080806232753.GA14256@thorin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080806232753.GA14256@thorin> Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] fix multiboot/aout, cleanup relocators, etc 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: Thu, 07 Aug 2008 10:21:56 -0000 On Thu, Aug 07, 2008 at 01:27:53AM +0200, Robert Millan wrote: > > Hi, > > It seems when adding the relocators for ELF, I failed to notice both ELF and > a.out loaders share the same grub_multiboot_real_boot function, and hence my > code was trashing %eax. > > Since this functionality is useful for the a.out loader anyway, I decided to > implement it as well. In the process I did some cleanup, mostly to reduce > code duplication among both users of the relocators. > > So here's the patch. Please comment! I think I should ellaborate a bit on this: > if (header->flags & MULTIBOOT_AOUT_KLUDGE) > { > - int ofs; > + int offset = ((char *) header - buffer - > + (header->header_addr - header->load_addr)); > + int load_size = ((header->load_end_addr == 0) ? file->size - offset : > + header->load_end_addr - header->load_addr); > > - ofs = (char *) header - buffer - > - (header->header_addr - header->load_addr); > - if ((grub_aout_load (file, ofs, header->load_addr, > - ((header->load_end_addr == 0) ? 0 : > - header->load_end_addr - header->load_addr), > - header->bss_end_addr)) > - !=GRUB_ERR_NONE) > - goto fail; > + if (header->bss_end_addr) > + grub_multiboot_payload_size = (header->bss_end_addr - header->load_addr); > + else > + grub_multiboot_payload_size = load_size; > + grub_multiboot_payload_dest = header->load_addr; > > - entry = header->entry_addr; > + playground = grub_malloc (RELOCATOR_SIZEOF(forward) + grub_multiboot_payload_size + RELOCATOR_SIZEOF(backward)); > + if (! playground) > + goto fail; > + > + grub_multiboot_payload_orig = (long) playground + RELOCATOR_SIZEOF(forward); > + > + if ((grub_file_seek (file, offset)) == (grub_off_t) - 1) > + goto fail; > + > + grub_file_read (file, grub_multiboot_payload_orig, load_size); > + if (grub_errno) > + goto fail; > + > + if (header->bss_end_addr) > + grub_memset (grub_multiboot_payload_orig + load_size, 0, > + header->bss_end_addr - header->load_addr - load_size); > + > + grub_multiboot_payload_entry_offset = header->entry_addr - header->load_addr; > + > } The problem I had here is that grub_aout_load() was constrained to the api used by our BSD loaders, and the relocator approach requires to intermangle things, so I had to move it to multiboot.c and transform it. Splitting it to a separate function (like we do for multiboot/ELF) wouldn't be hard if this is seen as a good idea, but making it global wouldn't be so sound IMHO: it relies on the relocator variables, so one would have to implement relocators in each a.out loader, which doesn't sound like such a bad idea, but the relocator code itself is biased towards multiboot (written to preserve %eax and %ebx), and so it's not as generic as it looks, as other load protocols might have conflicting constraints. -- 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."