Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions plat/e6800/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
The emu6800 platform
====================

This port targets the emu6800 emulator and generates code for the Motorola 6800 architecture. It is intended to run within the emu6800 environment.

This implementation is currently **under development and does not work yet**. Many features are incomplete or missing.

**File I/O is not implemented and will not be supported in the future,** because the emu6800 environment does not provide any file input/output functionality.

**Floating point support is not available yet.** Any attempt to use floating-point numbers will result in a build error or undefined behavior. Floating-point functionality may be added in the future.

The code generator is designed specifically for the MC6800, which has a simple architecture and a limited register set. The compiler translates source code to EM (stack-based intermediate code), and then to MC6800 assembly. Arguments and local variables are accessed relative to the frame pointer (Local Base, LB), **which resides in zero page**.

**Temporary results are kept either on the stack or in AccAB (the stack top).** See the source for details on stack frame layout and accumulator usage.

This port is intended to be tested using the emu6800 emulator.

Example command line
====================

ack -mm6800 -O -o hello.bin examples/hello.c

The file hello.bin can then be run using emu6800.

(Please note that this port is experimental and most programs will not yet function as expected.)

----

Work in progress. Contributions and bug reports are welcome.

@zu2
176 changes: 176 additions & 0 deletions plat/e6800/boot.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
.define BASE, EM_BSIZE
.define NBYTES
.define hol0, IGNMASK, ADDR, PROGNAME
.define LB, LBl, ERRPROC
.define ARTH, RETURN, SIGN
.define RETSIZE, TRAPVAL, BRANCH
.define START
.define TMP, TMP2
.define __exit, EXIT
.define _putchar, _getchar, _print, _cpu_counter, _errno
.define _putstr, _puthexl,_puthexi, _puthexc
.define _emu6800_conout, _emu6800_conin

BASE = 240
EM_BSIZE = 4

.sect .zero
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .end


.sect .zero
hol0: .space 16 ! the hol0 block
IGNMASK: .space 2 ! can hold the ingnore mask
ADDR: .space 4 ! used for indirect addressing
LB: .space 2 ! the localbase
LBl: .space 2 ! the second localbase (localbase-BASE)
ERRPROC: .space 2 ! can hold the address of the error handler
ARTH: .space 16 ! used for arithmetic
RETURN: .space 4 ! the return area
SIGN: .space 1
RETSIZE: .space 1
TRAPVAL: .space 1
BRANCH: .space 2
NBYTES: .space 2
TMP: .space 2
TMP2: .space 2
exitsp: .space 2

_errno: .space 2

.define Earray, Erange, Eset
.define Eiovfl, Eidivz, Eiund, Econv
.define Estack, Eheap, Eillins, Eoddz
.define Ecase , Ebadmon
.define Ebadlin, Ebadgto
Earray = 0
Erange = 1
Eset = 2
Eiovfl = 3
Eidivz = 6
Eiund = 8
Econv = 10
Estack = 16
Eheap = 17
Eillins = 18
Eoddz = 19
Ecase = 20
Ebadmon = 25
Ebadlin = 26
Ebadgto = 27

.define F_DUM
F_DUM = 0 ! Dummy floating point constant

!.base 0x0100 ! where to start in the emu6800
.sect .text
! GENERAL PURPOSE ROUTINES
START:
sts exitsp
lds #0xefff
!
clrb
clra
pshb ! envp
psha
pshb ! argv
psha
pshb ! argc
psha
jsr __m_a_i_n ! see. lang/cem/libcc/gen/head_cc.e
ins
ins
ins
ins
___exit:
EXIT:
lds exitsp
staa 0xfefb
ldab RETURN+1
stab 0xfeff
rts
__exit:
tsx
ldab 3,x
stab RETURN+1
bra ___exit
!
! minimal I/O routine
!
_puthexc:
tsx
bra _puthexi3
_puthexl:
tsx
bsr _puthexi2
inx
inx
bra _puthexi2
_puthexi:
tsx
_puthexi2:
ldaa 2,x
bsr _puthex2
_puthexi3:
ldaa 3,x
_puthex2: ! put AccA in 2 hexdigit
bsr _puthexhi
tab
bra _puthexlo
_puthexhi:
tab
lsrb
lsrb
lsrb
lsrb
_puthexlo:
andb #0x0f
cmpb #0x0a
bcs 1f
addb #'A'-'9'-1
1: addb #'0'
stab 0xfefe
rts
_putstr:
stab <TMP+1
staa <TMP
ldx <TMP
bra 2f
1: stab 0xfefe
inx
2: ldab 0,x
bne 1b
rts
_emu6800_conout:
_putchar:
tsx
ldab 3,x
stab 0xfefe
rts
_emu6800_conin:
_getchar:
ldab 0xfefe
stab RETURN+1
clr RETURN
rts
_print:
tsx
ldab 3,x
ldaa 2,x
staa 0xfefc
stab 0xfefd
rts
_cpu_counter:
staa 0xfefb
rts
.sect .data
.define _emu6800_ram
_emu6800_ram: .data2 __end
PROGNAME: ! for initialising the programname pointer
.asciz "emu6800"
.sect .bss
beginbss:
37 changes: 37 additions & 0 deletions plat/e6800/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from build.ab import export
from build.ack import ackcfile, exportheaders
from mach.proto.cg.build import build_cg
from plat.build import build_plat_libs
import importlib

build_as = importlib.import_module("mach.proto.as.build").build_as

build_as(name="as", arch="mc6800")
build_cg(name="cg", arch="mc6800")
build_plat_libs(name="plat_libs", arch="mc6800", plat="e6800")

ackcfile(name="boot", srcs=["./boot.s"], plat="e6800")

export(
name="tools",
items={
"$(PLATDEP)/e6800/as$(EXT)": ".+as",
"$(PLATDEP)/e6800/cg$(EXT)": ".+cg",
"$(PLATIND)/descr/e6800": "./descr",
},
)

export(
name="all",
items={
"$(PLATIND)/e6800/boot.o": ".+boot",
"$(PLATIND)/e6800/libsys.a": "./libsys",
},
deps=[
".+tools",
".+plat_libs",
"util/ack+all",
"plat/e6800/include+all",
],
)

92 changes: 92 additions & 0 deletions plat/e6800/descr
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# $Source$
# $State$
# $Revision$

var w=2
var wa=2
var p=2
var pa=2
var s=2
var sa=2
var l=4
var la=2
var f=4
var fa=2
var d=8
var da=2
var x=8
var xa=2
var ARCH=mc6800
var PLATFORM=e6800
var PLATFORMDIR={EM}/share/ack/{PLATFORM}
#var CPP_F=-D__unix
var ALIGN=-a0:1 -a1:1 -a2:1 -a3:1 -b0:0 -b1:0x100
# see. util/opt/em_opt.6: replace multiplies with constants n times.
var MACHOPT_F=-m0

# Override the setting in fe so that files compiled for linux386 can see
# the platform-specific headers.

var C_INCLUDES=-I{EM}/share/ack/{PLATFORM}/include -I{EM}/share/ack/include/ansi

name be
from .m.g
to .s
program {EM}/lib/ack/{PLATFORM}/cg
args <
stdout
need .e
end
#name asopt
# from .s
# to .so
# program /usr/bin/cat
# args > <
# optimizer
# stdin
# stdout
#end
name as
from .s.so
to .o
program {EM}/lib/ack/{PLATFORM}/as
args - -o > <
prep cond
end
name led
from .o.a
to .out
program {EM}/lib/ack/em_led
mapflag -l* LNAME={PLATFORMDIR}/lib*
# mapflag -i SEPID=-b1:0
mapflag -fp FLOATS={PLATFORMDIR}/libfp.a
args {ALIGN} {SEPID?} \
({RTS}:.b=-u _i_main) \
(.e:{HEAD}={PLATFORMDIR}/boot.o) \
({RTS}:.ocm.bas.b={PLATFORMDIR}/c-ansi.o) \
({RTS}:.c={PLATFORMDIR}/c-ansi.o) \
({RTS}:.mod={PLATFORMDIR}/modula2.o) \
({RTS}:.p={PLATFORMDIR}/pascal.o) \
-o > < \
(.p:{TAIL}={PLATFORMDIR}/libpascal.a) \
(.b:{TAIL}={PLATFORMDIR}/libb.a) \
(.bas:{TAIL}={PLATFORMDIR}/libbasic.a) \
(.mod:{TAIL}={PLATFORMDIR}/libmodula2.a) \
(.ocm:{TAIL}={PLATFORMDIR}/liboccam.a) \
(.ocm.bas.mod.b.c.p:{TAIL}={PLATFORMDIR}/libc.a) \
{FLOATS?} \
(.e:{TAIL}={PLATFORMDIR}/libem.a \
{PLATFORMDIR}/libsys.a \
{PLATFORMDIR}/libc.a \
{PLATFORMDIR}/libem.a \
{PLATFORMDIR}/libsys.a \
{PLATFORMDIR}/libend.a)
linker
end
name cv
from .out
to .img
program {EM}/bin/aslod68
args -v -v -me6800 < >
outfile e6800.img
end
18 changes: 18 additions & 0 deletions plat/e6800/include/ack/plat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* $Source$
* $State$
* $Revision$
*/

#ifndef _ACK_PLAT_H
#define _ACK_PLAT_H

#define ACKCONF_WANT_STDIO_FLOAT 0
#define ACKCONF_WANT_EMULATED_TIME 1
#define ACKCONF_WANT_EMULATED_POPEN 0
#define ACKCONF_WANT_EMULATED_FILE 1

/* We have a very small address space, so override the default buffer size. */

#define BUFSIZ 256

#endif
16 changes: 16 additions & 0 deletions plat/e6800/include/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from build.ab import export
from build.c import clibrary
from glob import glob
from build.ack import exportheaders

headers = glob("**/*.h", root_dir="plat/e6800/include", recursive=True)

clibrary(
name="include",
hdrs={k: f"./{k}" for k in headers},
)

export(
name="all",
items=exportheaders(".+include", prefix="$(PLATIND)/e6800/include"),
)
Loading
Loading