
Unix v6 Ported to ANSI C - octopus
http://os-blog.com/xv6-unix-v6-ported-to-ansi-c-x86/
======
ssp
There is a bug in the memmove() function from ulib.c:

    
    
        void*
        memmove(void *vdst, void *vsrc, int n)
        {
          char *dst, *src;
      
          dst = vdst;
          src = vsrc;
          while(n-- > 0)
            *dst++ = *src++;
          return vdst;
        }
    

If the two blocks overlap, and the address of dst is greater than the address
of src, then parts of the source will be overwritten before it can be copied.

~~~
antihero
I'm not massively great at C but would this be a fix?

    
    
        void*
        memmove(void *vdst, void *vsrc, int n)
        {
            char *dst, *src;
    
            dst = vdst;
            src = vsrc;
            if(*vdst > *vsrc) {
                *vdst += n;
                *vsrc += n;
                while(n-- > 0)
                    *dst-- = *src--;
            }
            else if(*vdst < *vsrc)
                while(n-- > 0)
                    *dst++ == *src++;
            return vdst;
        }

~~~
antihero
Ok, updated version:

    
    
        void*
        memmove(void *vdst, void *vsrc, int n)
        {
            char *dst, *src;
    
            dst = vdst;
            src = vsrc;
            if(vdst > vsrc) {
                dst = vdst + n;
                src = vsrc + n;
                while(n-- > 0)
                    *--dst = *--src;
            }
            else if(vdst < vsrc)
                while(n-- > 0)
                    *dst++ == *src++;
            return vdst;
        }
    
    

Does this solve the bugs?

~~~
abecedarius
There's an == for an =. Also vdst+n is an error, I believe, because sizeof
*vdst has no meaning.

------
supersillyus
I'm starting to suspect that Russ Cox is actually a team of people, all
contributing under one name.

~~~
mahmud
He is really just one very productive man, and his real name is Nicholas
Bourbaki.

~~~
ahpeeyem
"Nicolas Bourbaki is the collective pseudonym under which a group of (mainly
French) 20th-century mathematicians wrote a series of books presenting an
exposition of modern advanced mathematics, beginning in 1935. With the goal of
founding all of mathematics on set theory, the group strove for rigour and
generality. Their work led to the discovery of several concepts and
terminologies still discussed."

<http://en.wikipedia.org/wiki/Nicolas_Bourbaki>

------
mdwrigh2
I pulled the repository and all of the code is very well documented, and easy
to read. Really a great resource for learning OS internals.

~~~
agumonkey
it's small enough to fit in one `ls` screen, really inciting to be read, kinda
like plan9 source code.

~~~
cpeterso
If anyone is interested:

<http://plan9.bell-labs.com/sources/plan9/sys/src/>

------
RexRollman
I was under the impression that Minix was created and used for this kind of
thing. Is there something about Minix that makes it unsuitable today's
classrooms?

~~~
derleth
Minix is a microkernel design, so it's of limited use in understanding how
modern OSes work.

~~~
rbanffy
It would be fair to say _current_ operating systems.

~~~
derleth
Microkernels have been the wave of the future for longer than some of the most
popular OSes have been around, namely Windows NT (not just Windows 7, but the
whole NT design), Mac OS X (NeXTStep too, for that matter), and Linux (but,
admittedly, not Unix).

If I may prognosticate, stripped-down monolithic OSes running on hypervisors
are the wave of the future. Look at VM/CMS for an extreme example: CMS is
about as complex as MS-DOS, being a single-user single-tasking OS with no
memory protection or security model. VM is the hypervisor. Together, they date
to about 1968, or a little before if you include research systems.

~~~
rbanffy
There are a lot of parallels between VM/CMS and a microkernel with a service
built specifically to host an application. They are very different beasts at
their core (a microkernel is built to connect services and a hypervisor to
segregate them), but they solve similar problems in sometimes similar ways.

~~~
derleth
You seem to be talking about Service Virtual Machines:

<http://www.garlic.com/~lynn/2010k.html#25>

A Service VM is one where an application runs directly on the 'bare metal'
provided by the VM (that is, the whole point of a VM is to multiplex the
hardware; it provides few or no abstractions as such). There's no guest OS as
you'd think of one.

This idea also exists in exokernel designs:

<http://c2.com/cgi/wiki?ExoKernel>

<http://pdos.csail.mit.edu/exo.html>

In an exokernel, the guest OS is reduced to a library, like libc, which is
(ideally) optimized for the specific application: Emacs has its own, Apache
has its own, and so on. It's a half-step removed from the Service VM idea in
that the applications themselves would still get to use the OS abstractions,
unaware that the OS is basically gone.

------
Legion
<http://pdos.csail.mit.edu/6.828/schedule.html>

The project page gives this link to the schedule, where the lecture notes are
supposed to be, but the link 404's.

Is there a working URL for these lecture notes?

~~~
rtm
<http://pdos.csail.mit.edu/6.828/2011/schedule.html>

------
burgerbrain
This is unspeakably great. I'm going to have to forward this on to my old OS
professor. Really wish we had this when I took that class.

------
roxtar
I encourage you to try out the 6.828 course material, especially the labs.
It's one of the best OS courses. I had taken UCLA's CS 235 which is based on
similar content [1]. Learned a lot from that.

[1]: <http://www.cs.ucla.edu/~kohler/class/10f-aos/>

------
tzs
> Although the Unix v6 source may seem like an ideal introduction to operating
> systems engineering because of its simplicity, students doubted the
> relevance of an obsolete OS written in a now defunct dialect of C. In
> addition, students struggled to learn the details of two different
> architectures, the PDP-11 and x86, at the same time.

Those students were MIT students. I'd expect MIT students to not have had a
problem with either of these, so I'm a bit puzzled.

------
hjalle
Compared to the OS course I've taken in Sweden this seems to cover more, but I
can't find how many credits you get from it. It is scheduled from September to
end of december, but is it full time during this period or do they take other
courses at the same time?

Edit: URL: <http://pdos.csail.mit.edu/6.828/2011/index.html>

~~~
rtm
Most students take 6.828 along with three or four other courses.

------
mahmud
Why not XINU? It's a great little kernel; already exhaustively documented
(Lions' Commentary style) along with its TCP/IP stack.

P.S. I still maintain a very HLL is ideal for presenting multi-
processing/multi-tasking to students.

~~~
jarz
Comer has a new edition of "Operating System Design: The Xinu Approach" that
focuses on a Linksys/Cisco router. I've not read the text officially yet, but
the drafts were very interesting. Purdue CS grad students use Xinu for the OS
course projects (<http://www.cs.purdue.edu/homes/cs503/>).

~~~
mahmud
Very interesting. Thank you :-)

------
roxtar
The info page says that xv6 was released in Fall 2006. What's new?

~~~
rtm
Address spaces based on paging rather than segments. Much clearer context
switching code. File system crash recovery via logging.

~~~
tankenmate
And now using the HLT instruction so you don't chew CPU power unnecessarily,
great for QEMU etc on laptops. I just sent you a patch.

Edit: all the user tests passed.

------
KingEllis
Yip yip yip yip yip yip yip. Good.

