From: Tim Smith (tzs@stein2.u.washington.edu)
Date: 04/23/93


From: tzs@stein2.u.washington.edu (Tim Smith)
Subject: Re: Linux on Macintrashes? (Was: Re: Linux on
Date: 24 Apr 1993 03:21:18 GMT

torvalds@klaava.Helsinki.FI (Linus Torvalds) writes:
>The current kernel is much less i386-dependent than early versions were:
>early versions made heavy use of the 386 segmentation features (which is
>one of the less portable things to use) to keep processes separate etc.
>The current version still uses segments (you can't avoid it on a i386),
>but the use is generally not that much of a problem - it should be
>reasonably easy to just use paging to do all memory protection.

How extensive is segment use, compared to, say, System V for Intel
machines? System V basically runs everything in small model (or
maybe it's tiny model). It pretty much sets up the segment registers
at process initialization, and then leaves them alone.

>On the other hand, porting an OS is never trivial, especially for the
>first time. It gets easier to do later ports due to the machine-
>dependent parts usually being fixed or at least more well known during
>the first port. Linux still uses a lot of available 386 features to
>implement task switching etc, and this needs some work for another
>processor. But task switching is generally the easiest part: memory
>management code is also very hardware dependent, as are all the device
>drivers and so on. And to do a port you generally need to know the
>target machine very well, as well as knowing something about the
>original machine (or you won't understand why things are done like they
>are in the first place).

The big question is how much 386-specific stuff is in the hard parts?
I did the design a few years ago for a System III port from either VAX
or some 3B (I don't know which!) to a 68k, adding virtual memory, and
found that memory management, task switching, and process handling
aren't really that hard. Later, at Interactive, I did a lot of work on
porting System V Release 3 to the 286 (gag!), and found that was much
harder. The big difference, I think, was that on the System III port,
I didn't even really look at the memory management, etc. (that's one
of the reasons I don't know what machine the source code was for!).
I wanted to do it my way, so I did. At Interactive, we tried to
keep as much of the 3B code as we could, even though the 3B and the
286 do not think at all alike.

The lesson, I think, is that memory management, etc., aren't really
that hard, unless you try to make them work in ways that aren't
natural for your machine. Thus, I think the way to do a Linux port
to the Macintosh is to forget about the 386 code for these sort
of things.

The things to port are things like the file system the device interface
code and things like that. Are these very 386 specific?

Device drivers present a problem. Let's look at what would be needed:

SCREEN Screen should not be too bad. For NuBus video cards,
        there is a driver in ROM on the card. I believe the interface
        to this is documented, so a Mac Linux driver for NuBus video
        shouldn't be too bad.

        For built-in video, I believe all Macs use a simple memory
        mapped display, which is pretty easy to deal with.

SCSI Almost all Macs have SCSI, using either 5380 or 5396. Both of
        these chips are pretty easy to use. If there is a Linux SCSI
        driver that uses any sort of structure-based interface (e.g.,
        ASPI), it would probably take under a week or two to write
        a compatible version for the Mac.

KEYBOARD and MOUSE Here things get harder. I'm not sure how well
        these are documented. On the other hand, we might not need
        to deal with them directly. I think the Mac ROM could be
        convinced to handle them even without the Mac OS running.
        I seem to recall doing some experimentation once, and determining
        that they worked at boot time, before the OS loaded. If I'm
        remembering right, then there's no problem.

FLOPPY This is a mystery area.

NETWORKING I've only got one computer, so I don't care! :-)
        Seriously, this could be a pain. I don't know if Apple
        documents their ethernet cards or not. All the cards I've
        worked with (both Apple and non-Apple) use normal ethernet
        chips (NIC, LANCE, SONIC), and so aren't hard to deal with
        if you can get documentation on where the heck the chip is,
        but I don't know if that information is easily obtained.

SERIAL PORTS 8350, straightforwardly implemented. The chip is a
        royal pain in the ass to use, though (e.g., it's one of those
        things you put on your resume to show that you are tough :-))

The big problem I see is compatibility. I'd want to be able to run
Mac applications from within Mac Linux. I think that would be a lot
of work. I know it would be a lot of work, because the way I want to
do it is by doing a virtual machine, and letting the Mac OS boot in
the virtual machine. This is probably not the best way, of course,
but I've never done a virtual machine, and I want to.

--Tim Smith