Subject: Re: so what's happening...
To: Olaf Seibert <rhialto@polderland.nl>
From: Lars Brinkhoff <lars.spam@nocrew.org>
List: port-pdp10
Date: 07/06/2002 16:13:08
Olaf Seibert <rhialto@polderland.nl> writes:
> Yes - all pointers to structs must "smell the same" but need not be
> the same as other pointers.

They are word addresses in GCC (and KCC).

> (void *) must be essentially the same as (char *)

Both 9-bit byte pointers.

> Pointers to functions are different

Word addresses.

> [...] or pointers are based on chars of 9 bits (most likely) but
> then you have to be more careful about conversions. I presume that
> the compiler will do that, and if an object of size 4 is added to a
> word pointer, increase the pointer by 1 word.

Yes, on both accounts.

> But to make sure all this works ok, vaddr_t should probably be a
> (char *), and not an integer type

As the compiler guy, I really like that. :)

> or you'd have to do all this "by hand", if that is even possible
> given the format of a byte pointer.

Sure.  For example, (global) 9-bit byte pointers have a 6-bit code in
the most significant bits, and a 30-bit word address in the least
significant bits.  The code can be 070, 071, 072, or 073, which
indicates the first, second, third, or forth byte in the word,
respectively.  Here is code to do the conversion:

  /* Convert a 9-bit byte pointer to a linear byte address.  */
  unsigned char9p_to_unsigned (const char *p)
  {
    unsigned x = (unsigned)p;
    /* The "& 0777777" may seem unnecessary, but actually enables
       faster code to be generated.  */
    x = (x << 2) + (((x >> 30) - 070) & 0777777);
    return x & 07777777777;
  }

  /* Convert a linear byte address to a 9-bit byte pointer.  */
  char *unsigned_to_char9p (unsigned x)
  {
    unsigned tmp (x & 3) << 12;
  #if 0
    x = (x >> 2) | (tmp + 0700000) << 18;
  #else
    asm ("tlo %0,700000(%2)" : "=r" (x) : "0" (x >> 2). "r" (tmp));
  #endif
    return (char *)x;
  }

(Without the asm(), one or two more instructions will be generated.)

-- 
Lars Brinkhoff          http://lars.nocrew.org/     Linux, GCC, PDP-10,
Brinkhoff Consulting    http://www.brinkhoff.se/    HTTP programming