

Unix-jun72: Restoration of 1st Edition UNIX kernel sources - vinutheraj
http://code.google.com/p/unix-jun72/

======
tedunangst
Wow, for an operating system written in C, that's a lot of assembly!
(Apparently, unix was actually _re_ written in C a little later.)

Interesting to see the implementation of something like printf though:
[http://code.google.com/p/unix-
jun72/source/browse/trunk/src/...](http://code.google.com/p/unix-
jun72/source/browse/trunk/src/lib/printf.c)

~~~
philwelch
Interesting. They were explicitly addressing the stack to iterate through
arguments, yet the prototype lists nine arguments in addition to the fmt
string. Is that function actually variadic? If so, why explicitly list x1
through x9 as arguments?

~~~
enf
I think what's going on here is that the local variables in a function are
directly adjacent in memory to the arguments, so if it wasn't declared to have
that many arguments, the local variables would start at the same location in
memory as the first undeclared argument and the undeclared arguments would get
clobbered.

~~~
philwelch
As it is now, you push all your function arguments to the stack before you
push your locals. If you call printf(a1, a2, ... , an), it pushes n arguments,
then the instruction pointer, then your locals. No clobbering necessary.

Maybe 1972-era C pushed arguments to the stack according to the signature
defined in the function definition rather than the function call? (i.e. printf
would have 10 pushes no matter how many arguments you actually passed to it).
If it pushed according to the function signature, you'd waste memory and have
a hard limit to how many arguments you could pass. And you'd waste push
instructions. So I don't know why it's written the way it is, but corrupting
your locals doesn't seem like a likely explanation. Maybe they're trying to
mollify the compiler?

~~~
abecedarius
I think the x2,...x9 were declared just as "documentation". Really early C
didn't have any types that would get passed as anything but a single word on
the stack, IIRC.

(as I was going to add before getting noprocrast-blocked)

~~~
philwelch
Ha, so it doesn't matter how the function is defined! You can call any
function with any arguments you want, just shove 'em on the stack and see what
happens. And people say ANSI C is too unsafe ;)

------
vinutheraj
_"The software retains the copyright of the original authors and is currently
licensed under the Caldera ancient UNIX license."_ \- as mentioned in the
homepage, yet the code license information on the right side says GNU General
Public License v2. Is this because google only allows a limited number of
licenses on code.google.com ?

~~~
cmelbye
That's probably an accurate assumption. Happens a lot on Google Code hosting
projects due to a lack of available licenses to choose from.

