public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Graeme Russ <graeme.russ@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] RFC: Aligning arch initialisation sequences
Date: Sun, 14 Nov 2010 16:10:06 +1100	[thread overview]
Message-ID: <4CDF6F2E.9040900@gmail.com> (raw)
In-Reply-To: <4CDE741C.1020507@gmail.com>

On 13/11/10 22:18, Graeme Russ wrote:
> On 13/11/10 19:20, Albert ARIBAUD wrote:
>> Le 13/11/2010 05:16, Graeme Russ a ?crit :
>>
>>> I essence, the gd pointer is a unique global variable available prior to
>>> relocation. On all other arches, this is achieved by using a reserved
>>> register which I do not have the luxury of on x86 :(
>>
>> Dusting off ooooold knowledge of x86 and without even a glance at x86 
>> u-boot... Since GD is the only global used pre-reloc, can you not ensure 
>> it always ends up first in the data segment, and then manage two values 
>> for the DS segment reg, one pre-reloc where only gd can be used, and one 
>> post-reloc where gd and all the other globals can be accessed?
> 
> I had though of something similar to that by using GS (which is not
> generally used by u-boot) but it is very messy
> 
> All segments are currently setup to be full 4GB with the initial descriptor
> table hard-coded in flash and then reloaded after relocation (it needs to
> be reloaded so it does not get clobbered when erasing flash or relocating
> from RAM). I did have a dynamic GTD calculated in asm using self modifying
> code but changed that out to use the same 'C' methodology as Linux. I would
> prefer not to go back there...
> 
> So yes, it is possible, but quite frankly, I would rather leave the init
> functions post relocation than mess around with the GTS pre-relocation
> 

OK, I've had a good hard look at this, and setting aside a segment is the
only way that I can think of. I'll need to revisit the self-modifying code
I threw out, but I can live with that small ugliness to bring x86
board_init_f() in line with the other (relocating) arches.

For some bizarre reason, the BIOS emulation layer *yuck* uses GS *double
yuck*. FS is available though

So, I can set aside FS to store the global data pointer, but this
introduces a new problem. To get the pointer, I cannot simply use gd->, I
will need to write a function to retrieve the pointer, so I need gd()->

So I'm thinking of a #define GLOBAL_DATA which all existing arches can
define simply as gd and x86 can define as get_gd_ptr() and I write the
get_gd_ptr() function to extract the pointer using FS


static inline void *get_gd_ptr(void)
{
	void *gd_ptr;

	asm volatile("gs mov 0, %0\n" : "=r" (gd_ptr));
	return gd_ptr;
}

Now I hope the compiler will optimise this down very well. For example,
accessing gd results in the following asm:

	/* gd->baudrate =  CONFIG_BAUDRATE; */
	mov    0x602917c,%eax
 	movl   $0x2580,0x8(%eax)

I would expect using FS to result in something like:

	/* gd->baudrate =  CONFIG_BAUDRATE; */
	mov    fs:0x00000000,%eax
 	movl   $0x2580,0x8(%eax)

So no speed or size penalty :)

Does this sound like a plan?

Regards,

Graeme

  reply	other threads:[~2010-11-14  5:10 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-07 10:06 [U-Boot] RFC: Aligning arch initialisation sequences Graeme Russ
2010-11-09 23:35 ` Mike Frysinger
2010-11-13  4:16   ` Graeme Russ
2010-11-13  4:58     ` Mike Frysinger
2010-11-13  6:31     ` Reinhard Meyer
2010-11-13  6:38       ` Reinhard Meyer
2010-11-13  9:51         ` Graeme Russ
2010-11-13  8:17       ` Wolfgang Denk
2010-11-13 21:35         ` Reinhard Meyer
2010-11-13 21:53           ` Wolfgang Denk
2010-11-13 22:38             ` Reinhard Meyer
2010-11-13 22:45               ` Wolfgang Denk
2010-11-13 22:48                 ` Reinhard Meyer
2010-11-14  0:07                   ` Wolfgang Denk
2010-11-14  0:25                     ` Graeme Russ
2010-11-14  0:35                       ` Wolfgang Denk
2010-11-14  1:09                         ` Graeme Russ
2010-11-14  9:04                           ` Wolfgang Denk
2010-11-14 10:21                             ` Graeme Russ
2010-11-14 19:43                               ` Graeme Russ
2010-11-14  4:07                         ` Reinhard Meyer
2010-11-14  9:07                           ` Wolfgang Denk
2010-11-14 13:46                           ` Reinhard Meyer
2010-11-14 19:36                             ` Graeme Russ
2010-11-14 20:16                               ` Reinhard Meyer
2010-11-14 21:01                                 ` Graeme Russ
2010-11-13  8:20     ` Albert ARIBAUD
2010-11-13 11:18       ` Graeme Russ
2010-11-14  5:10         ` Graeme Russ [this message]
2010-11-14  5:48           ` Graeme Russ
2010-11-14  9:16             ` Albert ARIBAUD
2010-11-14 10:30               ` Wolfgang Denk
2010-11-14 12:10                 ` Albert ARIBAUD
2010-11-14 15:01                   ` Wolfgang Denk
2010-11-14 17:53                     ` Albert ARIBAUD
2010-11-14 19:06                       ` Wolfgang Denk
2010-11-14 19:29                         ` Albert ARIBAUD
2010-11-14 19:55                           ` Wolfgang Denk
2010-11-14 20:10                             ` Albert ARIBAUD
2010-11-14 20:42                               ` Wolfgang Denk
2010-11-14 19:23                       ` Wolfgang Denk
2010-11-14 19:34                         ` Graeme Russ
2010-11-14 20:05                           ` Albert ARIBAUD
2010-11-14 21:27                             ` Graeme Russ
2010-11-15 11:08                             ` Graeme Russ
2010-11-14 21:51   ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CDF6F2E.9040900@gmail.com \
    --to=graeme.russ@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox