Skip to main content
Home Forums 68kMLA Unix for 8-bit Apple
Thread

Unix for 8-bit Apple

68kMLA Development 47 posts Jun 2, 2009 to Apr 25, 2010
Ok, now I'm just really pushing things here, aren't I? :p Aside from my project to write a network game for the Apple II, I also want to look into Unix or any other multi-tasking implementation for 8-bit Apple II, since I got a //e back in March. GNO/ME is good, but that's for the IIgs, so I want to see if something like this is possible for a 64/128k RAM, 6502B machine.

Legend tells that Unix used to fit in 32K of RAM! I found this by reading some old newsgroups. I still have a lot of more searching and researching to do, but here's a list of some stuff which I have found or is on my mind:

- There's a program called Davex which is a command shell; there's also ANIX as well.

- would it be possible to compile Unix for the 6502? I know there is a C compiler out there, so the next thing would be to find old Unix source.

- what about Contiki? I've heard of it, but have never used it.

- has anyone else thought about doing multi-tasking on an 8-bit Apple?

- am I barking up the wrong tree? That is, is there a Linux or something else for the 6502?

More searching brought this page: http://everything2.com/title/6502%2520Unix

Looks like the two keywords are 6052 and UNIX when searching, not Apple II or anything similar. Interesting to note those people say the machine wouldn't have an MMU, but I am pretty sure that the IIe has one for doing bank-switched RAM. However, that would likely require rewrites/patches to get working correctly.

Urg, 6502 is one of the worst processors for C let alone UNIX. The size of the stack (256 bytes) is crippling. So you have to do the stack yourself. Also the 6502 has no virtual memory management, so fork() becomes meaningless.

Also the 6502 has no virtual memory management, so fork() becomes meaningless.
What about the MMU in the //e?

What about the MMU in the //e?
How much memory does the MMU page in and out at a time? Both granularity, and within the memory map of the 6502?

What about the MMU in the //e?
How much memory does the MMU page in and out at a time? Both granularity, and within the memory map of the 6502?
I don't know. I have the IIe Technical Reference Manual, but I haven't read it all yet. I should probably do that.

What about the MMU in the //e?
You might want to take a look at a couple of projects that have come before. But first, you probably want to abandon all hope of re-using source code directly; whatever you are doing, it'll take refactoring to work on your target platform. ;-)

Have a look at the LNG (LUnix Next Generation) project, which includes preemptive multitasking (on the C64):

http://lng.sourceforge.net

Some Apple Contiki notes:

http://a2central.com/?p=1427

Thanks for the links. I have no idea if I'll be able to pull it off or not. Looking around, there doesn't seem to be a whole lot of success stories.

With more searching, I found this Usenet thread: Making a Unix-like environment with an Apple IIe

I've got a lot of reading to do. Good thing it's the summer time now!

I think the closest you'll come to something that works out of the box w/o a lot of work is Contiki. I don't have any experience with it, but some people around here do.

I took a look at ProLine last night, since it apparently has a lot of Unix-like architecture.

I took a look at ProLine last night, since it apparently has a lot of Unix-like architecture.
Except I don't believe it does multitasking, does it?

I took a look at ProLine last night, since it apparently has a lot of Unix-like architecture.
Except I don't believe it does multitasking, does it?
I don't think that it does. I just read the manual last evening, and it looks like it's a bunch of BASIC scripts all tied together. It does have a task scheduler, though.

I played with it a bit last year... I was hoping to get a proline bbs online, but the message board part is pretty archaic and I wasn't up to the task of writing a new one. Neat to play with though, and very well documented too.

Maybe luddite could write a bit about his Contiki experiences for us, and explain the differences between the 1.x and 2.x branches. I recently read something about 2.x being focused on the embedded space, and not even supporting the GUI stuff now??

Unfortunately I don't have much to contribute... I haven't done any programming for Contiki. As far as using it goes, I'm running the 2.x version on the web server and I use 1.3 for browsing. With 64K of memory supported, multitasking is more of a novelty than anything... you can maybe run the browser and calculator at teh same time.

I don't think not programming for Contiki disqualifies you from commenting on its use. :) Anything about the (user perspective!) differences between 1.x and 2.x, using the UI or the browser, response to your server/site, etc, would be fun to hear.

I thought I read once that you can run Contiki as a process under Unix. Not sure though. If true, that might be a good way to get some exposure to it.

Well, the browser is a damned handy thing... with serious limitations. It's not really much good for modern web content, but it is a great way to download files to your Apple II. You can use the wget program to download files to Contiki's directory or disk images can be written directly to disk. I think it's safe to say that most of the other applications are proof-of-concept only... I've had limited success with email and ftp. Unfortunately the telnet app isn't much use, which is a shame because it would actually be quite handy if it was a bit better developed.

As for Contiki 2.x, I believe it does still support the browser and gui, but no one's got round to porting the various programs (other than the web server) yet. There doesn't seem to be much interest in the Apple II community as far as development goes, which is a shame...

WRT the web server... well, it's surprisingly robust! Needs rebooting maybe once a month and has survived several hundred hits per day for short periods. Mine's running off a single Disk ][ floppy, so it's as low-spec as it could be (unless contiki could be patched to load from tape!)... I imagine running it from a CFFA or hard drive would be quite a bit faster -- though not as much fun.

I don't think that it does. I just read the manual last evening, and it looks like it's a bunch of BASIC scripts all tied together. It does have a task scheduler, though.
Here's another possibility for you: http://www.appleoldies.ca/kix/index.htm it's Bill Buckles KYAN Pascal page. Part of the stuff there is a KIX shell that adds several UNIX like features to PRODOS.

Just my two cents worth,

Dean

I don't think that it does. I just read the manual last evening, and it looks like it's a bunch of BASIC scripts all tied together. It does have a task scheduler, though.
Here's another possibility for you: http://www.appleoldies.ca/kix/index.htm it's Bill Buckles KYAN Pascal page. Part of the stuff there is a KIX shell that adds several UNIX like features to PRODOS.
Thanks for the link, I'll check it out. I've seen you quite a few times on csa2 as well. :) UNIX on the Apple II is something that people have been talking about for over 20 years now, it seems.

Thanks for the link, I'll check it out. I've seen you quite a few times on csa2 as well. :) UNIX on the Apple II is something that people have been talking about for over 20 years now, it seems.
Yeah I tend to hang around most of the Apple II forums that I've been able to find. A lot of good discussions, sometimes some stupid spam, and I like the people I've met through the different forums. It's also helped broaden my knowledge of the Apple II world.

What do you go by on there, since I haven't seen Dog Cow as a name on any messages.

Dean

I don't post. I just read the news on my site. See this topic: viewtopic.php?f=6&t=9839
Yeah I saw that thread. It looked like a simple way to check up on CSA2 and some of the other groups I read if Google Groups goes down, which it has done from time to time. I've also looked over your site in general and like the looks of it. When will you be posting the Apple II stuff on there that you have?

Dean

When will you be posting the Apple II stuff on there that you have?
Hopefully in July or August. I need to update the Vault page, though. I've done more work since May.

It looked like a simple way to check up on CSA2 and some of the other groups I read if Google Groups goes down,
Yeah, and the nice thing is that I get my news from a Dutch news server which doesn't censor the email addresses and all the other annoying things that Google does. xx(

I read quite a few Usenet posts last evening on this subject, most from the late 80's. It looks like co-operative multitasking is going to be the way to go, unless one can get a card to generate interrupts every once and awhile. A program known as Daemon uses the Apple Mouse II card as its source of interrupts. Interestingly, the IIgs can be programmed, in software, to generate interrupts at varying intervals. Clearly, the superior system!

OK, maybe I'm just talking to myself by now, but I found this site in Linux Journal magazine: http://www.freertos.org/

There's no port for the 6502/Apple yet, but I'm going to take a look at it and see what I can do.

FreeRTOS.org is a scaleable real time kernel designed specifically for small embedded systems.
Might want to investigate Minix. It's designed for teaching OS design, so even if a porting effort failed, it would be an educational fail :) . It is to some extent unix-like.

Might want to investigate Minix. It's designed for teaching OS design, so even if a porting effort failed, it would be an educational fail :) . It is to some extent unix-like.
I think you might be underestimating the requirements for a UNIX like OS. An 8Mhz 68000 struggles, so how a 6502 is supposed to cope I'm not sure.

What you have to do is stretch the definition of UNIX as much as your brain will allow in order to call the small bit of code you shoe horn into the box as something vaguely reminiscent of an idea they once had back at Bell that may have been somehow related to an operating system. If it doesn't have fork() then it ain't UNIX.

I think you might be underestimating the requirements for a UNIX like OS. An 8Mhz 68000 struggles, so how a 6502 is supposed to cope I'm not sure.
Is it more limited than a PDP-7? I've no idea what kind of comparison that would be...

Comparing a PDP-7 to a 6502 is not a bad comparison, especially when the UNIX group were using it, it was already considered obsolete. :)

Just as update: this discussion is being continued on csa2p. There have been 9 replies since yesterday.

Took me a bit to figure out what that meant. :)

Sounds to me like targetting the IIgs, because it has the most resources, including a built-in source of interrupts, would make sense.

Ah, but that would be the easy route, plus there's already GNO/ME.

Ah, but that would be the easy route, plus there's already GNO/ME.
Bah, that's like MachTen or Mac06 on the Mac. Doesn't count! :D

Targetting the GS first would be helpful as a springboard, learning some techniques for crunching down to low specs. Sure the architecture is quite a bit different, but some of the principles should be the same.

isnt the GS 16 bit?

yeah, but you can also write 8-bit code because the 65c816 also knows about the 65c02.

The PDP-7 was an 18-bit machine. Has a "real Unix" ever been developed for any 8- or 16-bit machine? Doesn't seem a big stretch to run in 16 bits.

The PDP-7 was an 18-bit machine. Has a "real Unix" ever been developed for any 8- or 16-bit machine? Doesn't seem a big stretch to run in 16 bits.
The original QNX ran on 8088. It used the 8086 segmented model so a single process could use a maximum of 64k code+data+stack combined. And fork() really worked because it simply copied the whole proces image and used different segment register values. All pointers were, and had to be 16 bit ( AKA small model ). Processes could also be moved in memory. There was no memory protection at all and if you used assembler you could easily trash the system.

The PDP-7 was an 18-bit machine.
No, it was 16bit but could address 256Mb of memory with 18 address lines. A 6502 has 16 address lines but that doesn't make it a 16bit computer. If you went by that argument an 8086 was a 19bit computer and an 8088 was a 20bit computer.

No, it was 16bit but could address 256Mb of memory with 18 address lines. A 6502 has 16 address lines but that doesn't make it a 16bit computer. If you went by that argument an 8086 was a 19bit computer and an 8088 was a 20bit computer.
My comment was based on what I read about it on Wikipedia, etc. I've never even seen a PDP-7. :)

Anyone heard of LUnix? Unix on a C64 - page seems a bit old though. And uCLinux ideas might be helpful about getting around lack of MMU.

EDIT: Doh...didn't remember that LUnix had already been posted early in this thread.

The //e doesn't have an MMU. There are just soft switches, addresses in the $C03x range you hit to switch banks of RAM. Works the same as the Language Card on the Apple][.

About the closest to Unix anyone ever got was Anix or Anux, which consists of the RWTS portion of DOS 3.3 and a few commands which load from disk and have a Unix-y flavor. No networking, no multitasking, no VM, no remote console, and not developed enough to even use as a base for applications. I worked with a guy once who was a fresh UCB grad and Unix whiz who thought he would base an industrial control system on Anix. He struggled mightily for about a month and gave up. In the end he used DOS and Applesoft, much as it hurt his vanity.

Unix may not be impossible on a 6502, but you'll find it a real challenge. Akin to going 160 MPH on a flat-head Indian. Speaking of hopping up underpowered machines, there are 68000 CPU cards that go in an Apple//e slot. Run the kernel on one of those and the UI on the 6502?

Anyone heard of LUnix? Unix on a C64 - page seems a bit old though. And uCLinux ideas might be helpful about getting around lack of MMU.
EDIT: Doh...didn't remember that LUnix had already been posted early in this thread.
I know of someone who was melding 2.6 kernal and uclinux together to boot on an A500.

and yes i know exactly who it is. he was coming along nicely.

The //e doesn't have an MMU. There are just soft switches, addresses in the $C03x range you hit to switch banks of RAM. Works the same as the Language Card on the Apple][.
Well, it does. That's what Apple calls it. But it's not the same as everyone else's MMU.
Unix may not be impossible on a 6502, but you'll find it a real challenge. Akin to going 160 MPH on a flat-head Indian. Speaking of hopping up underpowered machines, there are 68000 CPU cards that go in an Apple//e slot. Run the kernel on one of those and the UI on the 6502?
Since starting this topic, I've decided to set my goals lower to a simple task-switcher. Much easier, and there have already been some written.

Considering the relatively open design, someone could probably make an MMU card for the Apple. Although you might only be able to effectively use memory that was only addressable by the card. You'd probably need some software to make all the hardware access it's memory through the card though I assume.

The other approach is to simply virtualize the 6502. This is not as ludicrous as it sounds, but it is definitely slower. OTOH, by making stack and the virtual memory manager software, you can make them do anything, and you can always pre-emptively interrupt a virtual processor. To wit,

http://www.floodgap.com/retrobits/kim-1/emu.html

It runs on an unmodified Commodore 64.

...and we've already got a Java VM for the Apple II, so we're all set.

No, it was 16bit but could address 256Mb of memory with 18 address lines. A 6502 has 16 address lines but that doesn't make it a 16bit computer. If you went by that argument an 8086 was a 19bit computer and an 8088 was a 20bit computer.
Not to pointlessly nitpick a really old statement in a zombie thread, but... sure, why not, I'll nitpick an old statement in a zombie thread.

I think Porter is confusing the PDP-7 with the PDP-11. The PDP-7 was a genuinely old-fashioned 18 bit machine, descended from the PDP-1 architecture. (It was basically a cheaper and faster PDP-4, which in some respects was a *simplified* PDP-1) What made it "old fashioned" was that it had no general-purpose registers and a relatively tiny instruction set with 16 opcodes and only a 13 bit "direct" addressing range. It had some "interesting" features compared to similar machines of the age which made it better suited to real time/multitasking than other more batch-oriented "small computers", but it's really a different animal from just about any microprocessor-based computer.

The PDP-11, on the other hand, was a solidly 16-bit machine. They all had 16 bit direct addressing, but "real" UNIX was limited to the PDP-11/45 and larger systems which had a segment-based MMU which expanded physical addressing to 18 to 22 bits. (A "Mini-UNIX" was available for the smaller models, but that lacked any form of memory protection.)

In some respects the closest microcomputer analog to the fully UNIX-capable PDP-11 models is the Intel 80286. The addressing model is similar and the 80286 has a capable-enough MMU to fully allow for virtual memory and swapping. (Keep in mind the reason that Bill Gates called the 80286 "brain-damaged" was that it didn't include a facility for virtualizing "real mode", and thus couldn't easily multitask existing DOS programs. If DOS is off the table it's a quite capable CPU by... late 1970's standards.)

mp.ls