Linux now running on the 6502

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
johnwbyrd
Posts: 89
Joined: 01 May 2017

Linux now running on the 6502

Post by johnwbyrd »

Onno Kortman has taken semu (https://github.com/sysprog21/semu), a minimal RISC-V emulator, and cross-compiled it with llvm-mos (https://llvm-mos.org/wiki/Welcome), an LLVM port to the MOS 6502 processor, in order to run Linux on the Commodore 64 with REU. Kortman writes: "The screenshots took VICE a couple hours in 'warp mode' to generate. So, as is, a real C64 should be able to boot Linux within a week or so."

https://github.com/onnokort/semu-c64

Click the image for animation.
Attachments
Animation of an emulated Commodore 64 with REU loading Linux
Animation of an emulated Commodore 64 with REU loading Linux
User avatar
Proxy
Posts: 746
Joined: 03 Aug 2018
Location: Germany

Re: Linux now running on the 6502

Post by Proxy »

that is really impressive!

1200% Speed of a 1MHz 6502 with a 20MHz 65816 co-processor works out to a 12MHz 6502 with a 240 MHz 65816.
just a tiny bit too much for a modern 10-20MHz 65816 based system to handle on it's own.

but calling the emulator "minimal" seems a bit... deceptive.
as besides the base ISA it also has the MUL/DIV and Atomic extensions, plus an MMU and multiple privilege levels.
there is technically no reason to have the MMU at all, as Linux doesn't technically require it (as seen by this hackaday post), which would save some performance.
but i do believe you still need the different privilege levels, though if you could get rid of those as well it would of course run even better.

and if you have the code at that point you might be able to use a compiler directly to the 65816 like Calypsi C, though i've tried to compile an older version of MINIX with it once and it had some internal errors and just gave up. so i doubt it would fare better with a Linux kernel.

oh well, the dream of having an actual OS running on a 65816 continues to be a dream
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Linux now running on the 6502

Post by BigEd »

Wonderful!
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: Linux now running on the 6502

Post by drogon »

Proxy wrote:
oh well, the dream of having an actual OS running on a 65816 continues to be a dream
What's your definition of an actual OS?

Acorn did it way back with a port of their Acorn MOS in their Communicator, then Apple did their thing on the //gs ...

... Fast forward to a year or 2 back and I have my RubyOS'816 going - which is a command-line sort of thing that supports multi-tasking running on my '816 board at 16Mhz - all written in BCPL....

Under which I wrote a RISC-V 32IM emulator (in BCPL) which runs at about 2000 RV instructions/sec, so not going to win any speed records, but if I added the bare minimal MMU support then could it run Linux? Sure - it's a little RAM limited right now though (Has about 350KB free) but in a larger memory system then yes - but as above, slowly...

So it's a good academic/fun exercise but not really usable...

Cheers,

-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
User avatar
Proxy
Posts: 746
Joined: 03 Aug 2018
Location: Germany

Re: Linux now running on the 6502

Post by Proxy »

drogon wrote:
What's your definition of an actual OS?
i'd say something like MS-DOS 2.0 or above. a simple commandline interface where you can run internal commands or external programs. with driver support of course!
drivers would be IMO the most important part as they shift the hardware dependent parts of code away from the OS and user programs.
sadly implementing drivers is really damn difficult and while i want to try myself at making an OS with driver support, i'm still in the "writing down all my ideas and concepts to solve weird edge cases before even writing a single line of code" phase of the project, which is very difficult to break out of. :lol:
drogon wrote:
Acorn did it way back with a port of their Acorn MOS in their Communicator, then Apple did their thing on the //gs ...
main issues with porting Operating systems of older hardware like that is the hardware dependence, sometimes missing source code, and any kind of limitations that you wouldn't have on a more modern system (like the amount of RAM available).
i have been sort of thinking about porting something like GEOS, which seems similar enough to GS/OS, except GEOS has source code. but both are graphical OSes which would be amazing to have, but also seem more error prone compared to simple terminal based OSes.
drogon wrote:
... Fast forward to a year or 2 back and I have my RubyOS'816 going - which is a command-line sort of thing that supports multi-tasking running on my '816 board at 16Mhz - all written in BCPL....
which is pretty damn impressive!
drogon wrote:
Under which I wrote a RISC-V 32IM emulator (in BCPL) which runs at about 2000 RV instructions/sec, so not going to win any speed records, but if I added the bare minimal MMU support then could it run Linux? Sure - it's a little RAM limited right now though (Has about 350KB free) but in a larger memory system then yes - but as above, slowly...

So it's a good academic/fun exercise but not really usable...
well again, you don't need an MMU for linux, just a seperation between User and System mode. and even that might be optional.
if i had an actual C compiler for my SW32VM i could try stuff like this myself. it would likely run as slowly as a RISC-V emulator, but atleast instructions are only 16-bits wide instead of 32-bits like on RISC-V.... but i don't know if that makes up for much in terms of performance, something to test i guess.
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Linux now running on the 6502

Post by BigDumbDinosaur »

Proxy wrote:
oh well, the dream of having an actual OS running on a 65816 continues to be a dream
I guess the Apple ][GS didn’t have an operating system. :D
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
commodorejohn
Posts: 299
Joined: 21 Jan 2016
Location: Placerville, CA
Contact:

Re: Linux now running on the 6502

Post by commodorejohn »

Clearly, that was but a shared hallucination.
User avatar
Proxy
Posts: 746
Joined: 03 Aug 2018
Location: Germany

Re: Linux now running on the 6502

Post by Proxy »

yea yea, i forgot the Apple IIgs existed :p
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Linux now running on the 6502

Post by BigDumbDinosaur »

Proxy wrote:
yea yea, i forgot the Apple IIgs existed :p

I suspect most of the present-day employees at Apple don’t know it existed as well.  Their horizons likely only extend back to the genesis of the iPhone.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
johnwbyrd
Posts: 89
Joined: 01 May 2017

Re: Linux now running on the 6502

Post by johnwbyrd »

Someone has set up a livestream of Linux booting in real time on an actual C64: https://www.youtube.com/watch?v=g-36d07DfgI

EDIT: he's giving up at 12 hours. It will require approximately a week to boot Linux.
Post Reply