Helbig observed
> while wondering how unsigned integer division is implemented in C
> I found a bug in V7: a/b and a%b with b >= 2^15 does not give the expected
> results, if a and b are unsigned int's.
Does
http://www.cs.bell-labs.com/who/dmr/odd.html#muldiv
suffice to explain the behavior?
Dennis
Hi,
while wondering how unsigned integer division is implemented in C
I found a bug in V7: a/b and a%b with b >= 2^15 does not give the expected
results, if a and b are unsigned int's.
Was this bug ever noticed or even fixed?
Greetings,
Wolfgang
Here is a program showing the bug:
main()
{
unsigned int a, b;
a = 60000;
b = 40000;
printf("a/b: %u, a%%b: %u\n", a/b, a%b);
b = 25000;
printf("a/b: %u, a%%b: %u\n", a/b, a%b);
}
The above program prints
a/b: 65534, a%b: 8928
a/b: 2, a%b: 10000
The first line should be of course
a/b: 1, a%b: 20000
A belated rejoinder to:
This bug existed from (at least) the Fifth up until the Eighth
editions from 1127 (BTL research). The Ninth edition had much
rewrites in the kernel and the algorthim was changed at that point.
You're welcome. I can't remember, though, whether I fixed it on
purpose or as part of the many general cleanups and restructurings
I did at that point. And I didn't do enough of it; recently I
discovered a dumb problem that I probably introduced in the same
cleanups, wherein the i-node allocated for a file that couldn't be
created because the file system was full and the directory entry
couldn't be written was left allocated but nameless ...
Norman Wilson
Toronto ON
On Jan 6, 19:01, Wolfgang Helbig wrote:
> Richard L. Hamilton searches:
> >The files
> >
> >http://minnie.tuhs.org/UnixTree/V7/usr/sys/dev/rl.c
> >http://minnie.tuhs.org/UnixTree/V7/usr/sys/conf/mkconf.c
> >
> >don't seem to match - mkconf.c wants to generate references to
> >rlopen() and rlclose(), which don't exist in that version of rl.
> >What I'm really looking for is the right version of driver(s) etc.
>
> It seems that a version of the rl driver that matches
> mkconf, was never supplied by the bell labs.
>
> As a workaround delete the rl entry in cdevsw and the line
> "int rlopen,..." from c.c. This will give you a block device of the rl
disk,
> but no raw device.
Hmm... my 7th Edition distribution /usr/sys/dev/rl.c certainly *does*
have rlopen() and rlclose(). If you want them, I can send rl.c and the
matching mkconf.c to you, or to Warren, along with the rl1conf and rl2conf
(for RL01 and RL02 disks) from /usr/sys/conf/ and any other files needed
(if someone can tell me what might be required -- it's a long long time
since I looked at any of this. The distribution came for an 11/23 with 2
x RL02, and it also has some special source files for 11/23, 11/34, etc
("small machines") including tests for recovery from segmentation traps in
floating point (which isn't the same on all PDP-11 models), and an RK
driver from the Boston Children's Museum which handles overlapped seeks on
multiple drives.
I'll be away for a couple of days so don't expect a prompt reply, but the
source is online here so I can easily copy a few files when I get back.
--
Pete Peter Turnbull
Network Manager
University of York
Richard L. Hamilton searches:
>The files
>
>http://minnie.tuhs.org/UnixTree/V7/usr/sys/dev/rl.c
>http://minnie.tuhs.org/UnixTree/V7/usr/sys/conf/mkconf.c
>
>don't seem to match - mkconf.c wants to generate references to
>rlopen() and rlclose(), which don't exist in that version of rl.
>What I'm really looking for is the right version of driver(s) etc.
It seems that a version of the rl driver that matches
mkconf, was never supplied by the bell labs.
As a workaround delete the rl entry in cdevsw and the line
"int rlopen,..." from c.c. This will give you a block device of the rl disk,
but no raw device.
Greetings,
Wolfgang
The files
http://minnie.tuhs.org/UnixTree/V7/usr/sys/dev/rl.chttp://minnie.tuhs.org/UnixTree/V7/usr/sys/conf/mkconf.c
don't seem to match - mkconf.c wants to generate references to
rlopen() and rlclose(), which don't exist in that version of rl.c.
What I'm really looking for is the right version of driver(s) etc.
so that I can regenerate the rl2unix kernel in the V7 image
available for use with simh, so that I can add or tweak drivers, eventually
adding the dz driver so I can run multiple "terminals" with telnet access.
--
mailto:rlhamil@mindwarp.smart.net http://www.smart.net/~rlhamil
Hi,
tinkering at V6--now I need db(I). It works fine, but three features
that are described in its manual page seem to be missing:
- The names of the general registers (r0, ...) are not build in, at least
db only responds with `?' to `r0'. I can examine the registers
via the `$' command though.
- The '*' feature doesn't work, i.e. `*_main' gives me a `?'.
- I can't specify a number being relocatable, i.e. '10r' gives me a `?'.
Is this an exercise to the user? Did anyone solve the exercise. Or did I
just not understand the manual page?
Greetings,
Wolfgang
Michael Davidson distrusted:
>Note that this means that r4, r3 and r2 get restored to the values
>that they had at the time that the next stack frame was established
>(ie when the "next" function down was called from the original context)
>and that these are not necessarily the values that they had at the
>moment when the original call to setjnp returned. Hence the various
>caveats about not relying on the value of any register variables
>after returning via longjmp.
You can trust register variables when setjmp() returns the second time. Then
the registers are restored to the values they had when the "next" function was
called, that is the "values as of the time longjmp() was called" (quoted from
longjmp(3)'s man page. Thus any variable behaves the same, regardless of its
storage class.
By the way, this is not the case in V6. The register variables-- and only
the register variables-- are restored to the values as of the time setexit() was
called. (In V6 "setjmp()" is named "setexit()" and "longjmp()" is named "reset()").
Thus the value of a variable depends on its storage class. If it is register,
you get the value when setexit() was called, if it is not register, you get
the value when reset() was called. This might be considered a bug.
Greetings
Wolfgang
Looking thru the code for setjmp/longjmp (/usr/src/libc/gen/setjmp.s),
and have a question. Longjmp seems to make an attempt at restoring
register two through four, but setjmp doesn't save them. Where do
these register get saved from?
Brantley Coile
some hours ago I wrote:
>I ask this, because my system crashes ones in a while. But I changed it
>here and there, so it might be my fault.
It *was* my fault! So far, I have only found one bug in V6: The size
of swapmap and coremap are configured too small, so they might overflow.
The sizes don't take account of shared text segments, that produce
extra chunks of free memory. In V6 there are 19 pure executables, so their
minimal size should be (NPROC+19)*2, or better yet (NPROC+NTEXT)*2, where
NTEXT should be set to 20 instead of 40 as distributed in param.h .
I don't think this bug ever showed up. It is very unlikely. In V7 these
sizes are choosen to be even smaller than NPROC and even with its many pure
executables, I don't think V7 ever crashed because of this bug.
So, with the only exception reported by Brian S. Walden, there seem to be
no bugs in V6 that crash systems.
Greetings
Wolfgang