The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Article on 'not meant to understand this'
@ 2017-01-16  1:44 Warren Toomey
  2017-01-16  3:15 ` Larry McVoy
  2017-01-16 11:19 ` Tony Finch
  0 siblings, 2 replies; 9+ messages in thread
From: Warren Toomey @ 2017-01-16  1:44 UTC (permalink / raw)


http://thenewstack.io/not-expected-understand-explainer/

in case you haven't seen it yet.

Cheers, Warren


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [TUHS] Article on 'not meant to understand this'
@ 2017-01-16 17:16 Noel Chiappa
  0 siblings, 0 replies; 9+ messages in thread
From: Noel Chiappa @ 2017-01-16 17:16 UTC (permalink / raw)


    > From: Angelo Papenhoff

    > The problem is that the function which did the savu was not necessarily
    > the same as the function that does the retu, so after retu the function
    > could have the call stack of a different function. As dmr explained,
    > this worked with the PDP-11 compiler but not with the interdata
    > compiler.

To put it slightly differently, in PDP-11 C all stack frames look identical,
but this is not true of other machines/compilers. So if routine A called
savu(), and routine B called aretu(), when the call to aretu() returned,
procedure B is still running, but on procedure A's stack frame. So on machines
where A's stack frame looks different from B's, hilarity ensues.

(Note that aretu() was significantly different from retu() - the latter
switched to a different process/stack, whereas aretu() did a 'non-local goto'
[technically, switched to a different stack frame on the current stack] in the
current process.)


    > Note that Lions doesn't explain this either, he assumed that the
    > difficulty was with with u_rsav and u_ssav .. (he probably wasn't that
    > wrong though, it really is confusing, but it's just not what the comment
    > refers to)

Right. There are actually _three_ sets of saved stack info:

	int	u_rsav[2];	/* save r5,r6 when exchanging stacks */
	int	u_qsav[2];	/* label variable for quits and interrupts */
	int	u_ssav[2];	/* label variable for swapping */

and it was the interaction among the three of them that I found very hard to
understand - hence my (incorrect) memory that the 'you are not' comment
actually referred to that, not the savu/aretu stuff!

Calls to retu(), the primitive to switch stacks/processes, _always_ use
rsav. The others are for 'non-local gotos' inside a process.

Think of qsav as a poor man's exception handler for process software
interrupts. When a process is sleeping on some event, when it is interrupted,
rather than the sleep() call returning, it wakes up returning from the
procedure that did the savu(qsav). (That last is because sleep() - which is
the procedure that's running when the call to aretu(qsav) returns - does a
return immediately after restoring the stack to the frame saved in qsav.)

And I've forgotten exactly how ssav worked - IIRC it was something to do with
how when a process is swapped out, since that can happen in a number of
ways/places, the stack can contains calls to various things like expand(),
etc; when it's swapped back in, the simplest thing to do is to just throw that
all away and have it go back to where it was just before it was decided to
swap it out.

       Noel


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [TUHS] Article on 'not meant to understand this'
@ 2017-01-16 19:10 Steve Johnson
  0 siblings, 0 replies; 9+ messages in thread
From: Steve Johnson @ 2017-01-16 19:10 UTC (permalink / raw)


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

I was well aware of the comment in V6, but had no idea what it
referred to.   When Dennis and I were porting what became V7 to the
Interdata 8/32, we spent about 10 frustrating days dealing with savu
and retu.  Dennis did his most productive work between 10pm and 4am,
while I kept more normal hours.  We would pore over the crash dumps
(in hex, then a new thing for us--PDP-ll was all octal, all the
time).  I'd tinker with the compiler, he'd tinker with the code and
we would get it to limp, flap its wings, and then crash.  The problem
was that the Interdata had many more registers than the PDP-11, so the
compiler only saved the register variables across a call, where the
PDP-11 saved all the registers.  This was just fine inside a process,
but between processes it was deadly.  After we had tried everything
we could think of, Dennis concluded that the fundamental architecture
was broken.  In a couple of days, he came up with the scheme that
ended up in V7.

It was only several years later when I saw a T-shirt with savu and
retu on it along with the famous comment that I realized what it had
referred to, and enjoyed the irony that we hadn't understood it
either...

Steve

----- Original Message -----
From: "Brantley Coile" <brantleycoile@me.com>
To:"Larry McVoy" <lm at mcvoy.com>
Cc:<tuhs at tuhs.org>
Sent:Mon, 16 Jan 2017 05:11:02 -0500
Subject:Re: [TUHS] Article on 'not meant to understand this'


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170116/a2320686/attachment.html>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-01-16 19:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-16  1:44 [TUHS] Article on 'not meant to understand this' Warren Toomey
2017-01-16  3:15 ` Larry McVoy
2017-01-16 10:11   ` Brantley Coile
2017-01-16 17:49     ` Marc Rochkind
2017-01-16 11:19 ` Tony Finch
2017-01-16 11:26   ` Angelo Papenhoff
2017-01-16 15:35     ` Random832
2017-01-16 17:16 Noel Chiappa
2017-01-16 19:10 Steve Johnson

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