From: David Given <dg@cowlark.com>
To: linux-8086@vger.kernel.org
Subject: Re: 8-bit Linux?
Date: Wed, 28 Mar 2012 18:20:29 +0100 [thread overview]
Message-ID: <4F73485D.50009@cowlark.com> (raw)
In-Reply-To: <1332952418.67495.YahooMailClassic@web180810.mail.gq1.yahoo.com>
[-- Attachment #1: Type: text/plain, Size: 2592 bytes --]
Chris Cureau wrote:
> Very interesting! I'll look a little closer in a bit...
>
> One of the nice things about the c128 is the built in MMU...which allows remapping of page 0 and page 1 (zero page and stack, respectively) at any given moment. The same thing is possible with the 65816/65265 CPUs, which are the next target. If you also use the o65 format, you can do software relocation. There are still limitations of course, but the barriers are lower given those things...
Being able to remap the stack is a big win. Is 256 bytes a realistic C
stack size, I wonder?
I did some work a while back looking at ways of doing C on the 6502 and
the Z80. They both suck, because both processors predate
stack-frame-based languages, and so don't have any useful addressing
modes (like stack-relative addressing).
On the Z80 you have to copy sp into one of your precious 16-bit index
registers, and then indirect each byte individually; at 4 bytes of code
a byte, that's 8 bytes to read a single 16-bit value off the stack!
On the 6502 it's even worse because of that fixed-position stack. Most
compilers maintain their own C stack, with appalling performance
results, of course. But if you *can* use the 6502 stack as the C stack,
you can do something like this...
stackaddr: // in zero page
dw 0x0100
load_16_bit_value_at_sp_plus_a_into_xy:
tsx
stx stackaddr+1
tay
ldx (stackaddr), y
iny
ldy (stackaddr), y
That's nine bytes, unfortunately, but with luck you may be able to
offset that by much more efficient parameter passing (as you can use
pha/phx/phy to push values onto the stack). Plus, of course, if you were
doing it for real you could arrange that the stack offset starts in Y
rather than A, which would save you a byte.
TBH, I thing the 6502 is such a poor match for C that it'd be better to
compile to p-code (like a more advanced SWEET16); the improved code
density should outweigh the performance issues for most tasks. I did
actually do most of one a while back, with a Z80 interpreter, and had
the ACK compiling to it, at least to a degree... I can dig it out if
anyone cares.
Alternatively you could write your programs in Fortran. The 6502 should
run Fortran quite well.
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Parents let children ride bicycles on the street. But parents do not
│ allow children to hear vulgar words. Therefore we can deduce that
│ cursing is more dangerous than being hit by a car." --- Scott Adams
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
next prev parent reply other threads:[~2012-03-28 17:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-28 14:50 8-bit Linux? Chris Cureau
2012-03-28 15:12 ` Gábor Lénárt
2012-03-28 16:03 ` David Given
2012-03-28 16:33 ` Chris Cureau
2012-03-28 17:20 ` David Given [this message]
2012-03-28 17:43 ` Gábor Lénárt
2012-03-28 17:35 ` Gábor Lénárt
-- strict thread matches above, loose matches on Subject: below --
2012-03-28 0:36 Scott Ferguson
2012-03-28 1:03 ` Stefan de Konink
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F73485D.50009@cowlark.com \
--to=dg@cowlark.com \
--cc=linux-8086@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox