All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Millan <rmh@aybabtu.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] Centralizing understanding of far pointers
Date: Tue, 28 Jul 2009 20:11:03 +0200	[thread overview]
Message-ID: <20090728181103.GH32726@thorin> (raw)
In-Reply-To: <1248561149.4660.245.camel@accesodirecto.casa>

On Sun, Jul 26, 2009 at 12:32:28AM +0200, Javier Martín wrote:
> This patch modifies the machine-specific memory.h (currently, just the
> i386-specific file), adding a new type grub_machine_farptr and two
> functions to convert between such far pointers and normal C pointers.
> 
> The code performing the mapping between realmode and pmode addresses is
> simple, and thus is repeated in many source files like drivemap, vbe*,
> mmap, etc. However, as simple as it is, its ad-hoc application tends to
> be quite unwieldy, generating long code that is verges close to the tag
> of write-only code.
> 
> The i386 farptr type has been implemented as an union between the uint32
> that was used until now (.raw_bits) and a structure separating the
> uint16 segment and offset parts for easy access and debug printing.
> 
> This post has three attachments: the patch to memory.h itself, a patch
> to the i386 mmap.c and its helper asm file, to show the impact of this
> patch (I've also taken the liberty of adding an offset macro just like
> in drivemap, and make the changed code more elegant in my opinion), and
> another patch doing the same for drivemap.
> 
> NOTE: this patch depends on the PTR_TO_UINT macro added by another patch
> still on discussion, [1].

The idea seems interesting, and in general such cleanup is welcome.  I have
some comments, only on the first patch.

First of all, please don't call them far pointers.  They're an i8086 legacy
cruft, which have nothing to do with far or close really (although we seem to
have some code that makes this reference already).

What you're doing is basically the same as real2pm() function we already had.
It seems this function should move elsewhere so it can have the generic use
you intended (it can be reimplemented as well, if that makes it cleaner).

> +typedef union
> +{
> +  struct
> +  {
> +    /* Given that i386 is little-endian, this order matches the in-memory
> +       format of CPU realmode far pointers.  */
> +    grub_uint16_t offset;
> +    grub_uint16_t segment;
> +  } __attribute__ ((packed));
> +  grub_uint32_t raw_bits;

Is there a usefulness in this `raw_bits' member?  It doesn't have any
real meaning, as it doesn't correspond to an actual address.

> +} grub_machine_farptr;

I admit this is a bit confusing, but the `machine' namespace is for
things specific to a given firmware.  i8086 mode is part of the i386
architecture, so we'd put this in the `cpu' namespace instead.

-- 
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."



  reply	other threads:[~2009-07-28 21:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-25 22:32 [PATCH] Centralizing understanding of far pointers Javier Martín
2009-07-28 18:11 ` Robert Millan [this message]
2009-07-29  0:40   ` Javier Martín
2009-07-29 18:02     ` Vladimir 'phcoder' Serbinenko

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=20090728181103.GH32726@thorin \
    --to=rmh@aybabtu.com \
    --cc=grub-devel@gnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.