From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JFaB9-0007FW-VK for mharc-grub-devel@gnu.org; Thu, 17 Jan 2008 14:13:32 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JFaB9-0007EQ-A5 for grub-devel@gnu.org; Thu, 17 Jan 2008 14:13:31 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JFaB8-0007DN-Lf for grub-devel@gnu.org; Thu, 17 Jan 2008 14:13:31 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JFaB8-0007DB-IY for grub-devel@gnu.org; Thu, 17 Jan 2008 14:13:30 -0500 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JFaB8-0002CL-8r for grub-devel@gnu.org; Thu, 17 Jan 2008 14:13:30 -0500 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1JFaB5-0001vt-Gv for grub-devel@gnu.org; Thu, 17 Jan 2008 20:13:28 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1JFa9c-0004Cw-Tr for grub-devel@gnu.org; Thu, 17 Jan 2008 20:11:56 +0100 Date: Thu, 17 Jan 2008 20:11:56 +0100 From: Robert Millan To: The development of GRUB 2 Message-ID: <20080117191156.GA15371@thorin> References: <20080113191251.GA9050@thorin> <20080115200824.GA2881@thorin> <20080117025433.ez1grtxjdcc4ckgk@webmail.spamcop.net> <20080117121758.GA2399@thorin> <1200591019.6845.28.camel@dv> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="zYM0uCDKw75PZbzx" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1200591019.6845.28.camel@dv> 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: help with powerpc asm (moving grub_ieee1275_entry_fn initialization to crt0.S) 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, 17 Jan 2008 19:13:31 -0000 --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Thu, Jan 17, 2008 at 12:30:19PM -0500, Pavel Roskin wrote: > > Oh, I didn't realize that kern/powerpc/ieee1275/cmain.c is actually used > by the i386-ieee1275 build. That's misleading! Perhaps it should be > moved to kern/ieee1275/ Yes. I had this in mind, but I think it's better to wait untill the i386 port is complete before we start moving files. > Anyway, Sparc code doesn't use cmain() in any way. It starts > immediately with the function _start() written in C. So you shouldn't > worry about breaking Sparc. Ah, I see. I didn't expect this. > Please feel free to integrate the PowerPC part of my patch into your > patch, as it indeed needs to be committed at once. Ok. I'm attaching the complete patch. > > Another option would be to have just one param. This would be the cleanest > > on i386, since the call from OFW already uses -mregparm=1 for the callback > > address, but I don't know about powerpc. > > I would prefer that we don't choose global CFLAGS to adjust one > function. There is a "regparm" attribute that can be used on cmain() on > i386 architecture. The CFLAGS for i386-ieee1275 are already set to regparm. This makes it easier to interact with OFW in both ways, since call backs also use %eax as first (and only) parameter. In fact, our current code seems to assume that grub_ieee1275_entry_fn() always has the same calling conventions than GRUB. Because of this, I thought it'd be consistent to assume the same for our _start routine. However, powerpc and sparc64 seem to disagree with i386 on which is the parameter that ought to be used to initialize grub_ieee1275_entry_fn. I suppose it's better to move this out of cmain, then.. > But if you want to keep cmain() shared between architectures, then the > cleanest approach would be to take care of grub_ieee1275_entry_fn before > cmain() is called. It doesn't have to be in assembly. Sparc can still > use its _start function to set grub_ieee1275_entry_fn and then call > cmain(). Ok. That sounds good. > Arguments are transmitted in registers r3, r4 and r5. Nothing is passed > on the stack. r5 has the data we want to be in grub_ieee1275_entry_fn. > > The first instruction takes the high 16 bits of the > grub_ieee1275_entry_fn address and put is to register 9. Register 9 is > the favorite choice for memory operations, as it has no special purpose > and doesn't need to be preserved. > > The second instruction places the contents of register 5 into an address > pointed to by the register 9 plus the lower 16 bits of the > grub_ieee1275_entry_fn address. > > A 32-bit constant cannot be loaded in one operation, since all PowerPC > commands are 32-bit, and it simply won't fit one command. I see.. -- Robert Millan I know my rights; I want my phone call! What use is a phone call… if you are unable to speak? (as seen on /.) --zYM0uCDKw75PZbzx Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="cmain.diff" PowerPC changes provided by Pavel Roskin. * kern/powerpc/ieee1275/cmain.c (cmain): Don't take any arguments. * kern/powerpc/ieee1275/crt0.S: Store r5 in grub_ieee1275_entry_fn, don't rely on cmain() doing it. * kern/i386/ieee1275/startup.S (_start): Store %eax in grub_ieee1275_entry_fn, don't rely on cmain() doing it. diff -ur grub2/kern/i386/ieee1275/startup.S cmain/kern/i386/ieee1275/startup.S --- grub2/kern/i386/ieee1275/startup.S 2008-01-15 21:05:44.000000000 +0100 +++ cmain/kern/i386/ieee1275/startup.S 2008-01-17 20:05:51.000000000 +0100 @@ -34,5 +34,5 @@ start: _start: - movl %eax, %ecx + movl %eax, EXT_C(grub_ieee1275_entry_fn) jmp EXT_C(cmain) diff -ur grub2/kern/powerpc/ieee1275/cmain.c cmain/kern/powerpc/ieee1275/cmain.c --- grub2/kern/powerpc/ieee1275/cmain.c 2008-01-15 17:14:32.000000000 +0100 +++ cmain/kern/powerpc/ieee1275/cmain.c 2008-01-17 20:05:11.000000000 +0100 @@ -1,7 +1,7 @@ /* cmain.c - Startup code for the PowerPC. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2006,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2006,2007,2008 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 @@ -102,12 +102,10 @@ } } -void cmain (uint32_t r3, uint32_t r4, uint32_t r5); +void cmain (void); void -cmain (UNUSED uint32_t r3, UNUSED uint32_t r4, uint32_t r5) +cmain (void) { - grub_ieee1275_entry_fn = (int (*)(void *)) r5; - grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen); grub_ieee1275_find_options (); diff -ur grub2/kern/powerpc/ieee1275/crt0.S cmain/kern/powerpc/ieee1275/crt0.S --- grub2/kern/powerpc/ieee1275/crt0.S 2007-07-22 01:32:27.000000000 +0200 +++ cmain/kern/powerpc/ieee1275/crt0.S 2008-01-17 20:05:04.000000000 +0100 @@ -1,7 +1,7 @@ /* crt0.S - Startup code for the PowerPC. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003,2004,2005,2007 Free Software Foundation, Inc. + * Copyright (C) 2003,2004,2005,2007,2008 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 @@ -38,5 +38,9 @@ 2: stwu 2, 4(6) /* We know r2 is already 0 from above. */ bdnz 2b + /* Store r5 in grub_ieee1275_entry_fn. */ + lis 9, grub_ieee1275_entry_fn@ha + stw 5, grub_ieee1275_entry_fn@l(9) + bl cmain 1: b 1b --zYM0uCDKw75PZbzx--