The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: jrvalverde@cnb.csic.es (Jose R. Valverde)
Subject: [TUHS] Introduction
Date: Tue, 1 Jul 2008 16:21:02 +0200	[thread overview]
Message-ID: <20080701162102.4812f3d6@veda.cnb.uam.es> (raw)
In-Reply-To: <20080630193450.b82063bb.lehmann@ans-netz.de>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3780 bytes --]

On Mon, 30 Jun 2008 19:34:50 +0200
Oliver Lehmann <lehmann at ans-netz.de> wrote:
> Jose R. Valverde wrote:
> 
> > But you would still be able to see what did generate the code (barring
> > register number).
> 
> my C code:
> 
>         register char *r2;
>         register long r4;
> 
> 	r2 = uap->linkname;
> 	r4 = (long) r2;
> 	r4 &= 0x7F00FFFF;
> 	u.u_dirp.l = (caddr_t) r4;
> 
> leads to:
> 
>         ldl     rr2,rr8(#4)			/* r2 = uap->linkname; */
>         ldl     |_stkseg+~L1|(fp),rr2		/* r2 = uap->linkname; */
>         ldl     |_stkseg+~L1+4|(fp),rr2		/* r4 = (long) r2;     */
>         ldl     rr4,rr2				/* r4 &= 0x7F00FFFF;   */
>         and     r4,#32512			/* r4 &= 0x7F00FFFF;   */
>         ldl     |_stkseg+~L1+4|(fp),rr4		/* r4 &= 0x7F00FFFF;   */
>         ldl     _u+78,rr4			/* u.u_dirp.l = (caddr_t) r4; */
> 
> looks not sooo bad - just the assigning into the stacked variables (no
> idea why no register bound is used here even if I told the compiler to
> make them register bound - but ,,register'' isn't that strong anyway)
>

So it means that you can reproduce (barring the stack assignments) the
behavior that you describe is puzzling you by using an auxiliary variable.
That is you exactly get

>         ldl     rr2,rr8(#4)			/* r2 = uap->linkname; */
>         ldl     rr4,rr2			/* r4 = (long) r2   */
>         and     r4,#32512			/* r4 &= 0x7F00FFFF;   */
>         ldl     _u+78,rr4			/* u.u_dirp.l = (caddr_t) r4; */

So the problem now is to figure out how the compiler came to use an
additional internal variable (maybe by playing with parenthesis) or
figure out if the original coder could have sensibly used an additional
variable actually.
> 
> but not with that code :/
> 
> u.u_dirp.l = (caddr_t) ((long) (((saddr_t) uap->linkname).l) & 0x7F00FFFF);
> "sys2_.c":50: operands of CAST have incompatible types 
> "sys2_.c":50: warning: struct/union or struct/union pointer required
> 
> Thats why I changed it the last time... to * and ->.
> 
This is starting to look nasty. My bet now is the compiler is getting confused
to parse the line. One thing: try with some additional parenthesis to 
disambiguate

	u.u_dirp.l = (caddr_t) ((long) (((saddr_t) (uap->linkname).l) & 0x7F00FFFF);

and see if that works or the same error repeats. Then, either one of two:
the original code did look that ugly, the author faced a difficult to parse
expression and broke it with an auxiliary variable,

	saddr_t aux;

	aux.l = (caddr_t) uap->linkname;
	u.u_dirp.l = (caddr_t) ((long) aux.l & 0x7F00FFFF);

or, now that I come to think of that, seeing the split example I just gave,
maybe it was all the way implicitly defined _the right way_: and instead of

	register struct a {
		char	*target;
		char	*linkname;
	} *uap;
	...
	u.u_dirp.l = (caddr_t)(((long)uap->linkname) & 0x7F00FFFF);	/* FIXME: this is not 100% compatible */

they actually had the original code

	register struct a {
		char	*target;
		saddr_t	*linkname;
	} *uap;
	...
	u.u_dirp.l = (caddr_t)(((long)uap->linkname.l & 0x7F00FFFF);

which would be absolutely clean, coherent with the way u_dirp is declared and
introduce a zero-offset union reference in the expression leading to the compiler
assigning an additional auxiliary variable to produce the expression.


					j
> 
> -- 
>  Oliver Lehmann
>   http://www.pofo.de/
>   http://wishlist.ans-netz.de/


-- 
	These opinions are mine and only mine. Hey man, I saw them first!

			    José R. Valverde

	De nada sirve la Inteligencia Artificial cuando falta la Natural
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20080701/f001c388/attachment.sig>


  reply	other threads:[~2008-07-01 14:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-04 11:57 Jose R. Valverde
2008-06-04 15:11 ` Oliver Lehmann
2008-06-04 15:16   ` Oliver Lehmann
2008-06-05 15:07 ` Jose R. Valverde
2008-06-05 17:59   ` Oliver Lehmann
2008-06-05 15:17 ` Jose R. Valverde
2008-06-05 17:45   ` Oliver Lehmann
2008-06-23 14:18   ` Jose R. Valverde
2008-06-23 16:11     ` Oliver Lehmann
2008-06-25  9:40       ` Jose R. Valverde
2008-06-25 10:25       ` Jose R. Valverde
2008-06-26 14:52         ` Oliver Lehmann
2008-06-27 12:24           ` Jose R. Valverde
2008-06-29  8:25             ` Oliver Lehmann
2008-06-30  9:30               ` Jose R. Valverde
2008-06-30 17:34                 ` Oliver Lehmann
2008-07-01 14:21                   ` Jose R. Valverde [this message]
2008-07-01 18:35                     ` Oliver Lehmann
2008-07-03 10:12                       ` Jose R. Valverde
2008-07-06 16:14                         ` Oliver Lehmann
2008-07-07  9:25                           ` [TUHS] SysIII/PDP-11 on SIMH (was Re: Introduction) Jose R. Valverde
2008-07-07  9:32                           ` [TUHS] Introduction Jose R. Valverde
2008-07-07 14:45                             ` Oliver Lehmann
2008-06-06  9:58 ` Jose R. Valverde
  -- strict thread matches above, loose matches on Subject: below --
2008-06-03  4:18 Oliver Lehmann

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=20080701162102.4812f3d6@veda.cnb.uam.es \
    --to=jrvalverde@cnb.csic.es \
    /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;
as well as URLs for NNTP newsgroup(s).