8000 GitHub - retrotinker/plm09: PL/M-80 compiler for the Motorola 6809 (lwasm output), with a 6809 simulator · GitHub
[go: up one dir, main page]

Skip to content
retrotinkerPublic

About

PL/M-80 compiler for the Motorola 6809 (lwasm output), with a 6809 simulator

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

plm09: a minimal PL/M compiler for the 6809

plmc09 compiles a small subset of PL/M-80 into 6809 assembly source for bcc09's assembler as09; its linker ld09 links the program with plm09's runtime libraries, and objcopy09 writes it as S-records, a CoCo .BIN, a FLEX .CMD or an OS-9 module. The output is not tied to any machine or address: all I/O goes through a small hooks library that you choose, or supply, when linking. The test suite runs the compiled programs in sim6809, a headless 6809 simulator that was part of this repository until version 0.5.0.

Full manual: docs/plmc09.pdf (Markdown source next to it). The Fedora RPM puts it in the noarch subpackage plm09-doc.

Building

Requires gcc, make, bcc09 1.0.1's as09 and ar09 (which build the runtime libraries; AS09=..., AR09=... name others). make test also needs bcc09's ld09 and objcopy09, python3 and sim6809 (on PATH, or make test SIM6809=... LD09=...), and its xroar suite uses XRoar with CoCo ROMs and toolshed's decb when they are installed. lwtools isn't needed since 0.7.0.

make            # build/plmc09 and the runtime libraries
make test       # all test suites
make install    # copy plmc09 to BINDIR (default /usr/local/bin), its man page
                # to MANDIR/man1 (default /usr/local/share/man) and the runtime

make install BINDIR=~/bin installs elsewhere; PREFIX (BINDIR is $(PREFIX)/bin, MANDIR $(PREFIX)/share/man, DATADIR $(PREFIX)/share) and DESTDIR (for staged installs) work as usual. plmc09 --version prints its version (0.7.0), and man plmc09 gives a summary of its options. Before 0.6.0 the compiler was called plmc.

The runtime and hooks files are installed in DATADIR/plm09/runtime, so an installed plmc09's output is linked with -L/usr/local/share/plm09/runtime -L/usr/local/share/plm09/runtime/sim in place of -Lruntime -Lruntime/sim.

Fedora RPM: make rpm builds plm09.spec into build/rpm from the release tag v$(VERSION) (the same files as the GitHub release archive the spec's Source0 names; HEAD while the version isn't tagged yet, and never uncommitted changes), running the test suites that need only bcc09, sim6809, python3 and groff (so the bcc09 and sim6809 RPMs must be installed, or given to mock with --addrepo); make rpm first removes the RPMs of earlier builds; make srpm makes just the source RPM (for mock). The RPM build applies a patch, made by tools/rpmdocs.py, that changes the documentation's runtime paths to the installed directory, %{_datadir}/plm09/runtime, and rebuilds the PDFs. Then:

sudo dnf install build/rpm/RPMS/x86_64/plm09-0.7.0-*.x86_64.rpm

It installs plmc09 in /usr/bin, its man page, and the runtime in /usr/share/plm09/runtime:

plmc09 -o hello.s hello.plm
as09 -o hello.o hello.s
ld09 -T0100 -L/usr/share/plm09/runtime -L/usr/share/plm09/runtime/sim -o hello.out -Cplm hello.o -lhooks -lplm
objcopy09 -O srec hello.out hello.s19
sim6809 hello.s19

plm09 is under the MIT license (see LICENSE).

Quick start

/* hello.plm */
HELLO: DO;
PUTCH: PROCEDURE (C) EXTERNAL; DECLARE C BYTE; END PUTCH;
PUTDEC: PROCEDURE (N) EXTERNAL; DECLARE N ADDRESS; END PUTDEC;
DECLARE I BYTE;
I = 1;
DO WHILE I <= 5;
    CALL PUTDEC(I * I);
    I = I + 1;
END;
CALL PUTCH('!');
END HELLO;
build/plmc09 -o hello.s hello.plm
as09 -o hello.o hello.s
ld09 -T0100 -Lruntime -Lruntime/sim -o hello.out -Cplm hello.o -lhooks -lplm
objcopy09 -O srec hello.out hello.s19
sim6809 hello.s19

as09 assembles the program into an object file. ld09 loads it at $0100 (-T; ld09 takes its arguments attached) and links it with the start-up code (-Cplm: crtplm.o), the simulator's hooks (-lhooks, found through -Lruntime/sim) and the runtime routines it uses (-lplm). objcopy09 writes S-records. make run F=hello.plm does all of it. contrib/ has two example programs and a Makefile that builds and runs them with an installed plm09 (the RPM's /usr/share/plm09): make -C contrib, or make -C contrib TARGET=os9. The RPM installs them in /usr/share/doc/plm09/contrib; copy that directory somewhere writable to build them.

For other machines, replace -Lruntime/sim with another target's directory (see Hooks), or link your own hooks object in place of -lhooks, and pick objcopy09's output format: -O decb (a CoCo .BIN), -O flex (a FLEX .CMD), -O binary, and others.

Before 0.7.0 plmc09 wrote lwasm source, with the options --org (now ld09's -T), --obj (now every output is an object), and for OS-9 modules --name and --stack (now objcopy09's -n and -d); it rejects them with a message saying so.

plmc09 options

Option Meaning
-o FILE output file, for as09 (default: stdout)
-I DIR also look for $INCLUDE files in DIR (after the including file's directory)
--vectors also emit the vector table at $FFF0: the reset vector (RT_START) and the vectors of INTERRUPT procedures; link with -Sruntime/vectors.ld, which places it and writes S-records
--os9 generate a position-independent OS-9 program module (see OS-9)
--memory N with --os9: bytes of the data area for MEMORY (default 0)
--tokens print the tokens and stop
--ast print the syntax tree and stop

Language

A program is a labeled block:

NAME: DO;
    declarations
    statements
END NAME;

The source is case-insensitive. $ is ignored inside names and numbers (1$000), and comments are written /* */.

Supported

  • Types: BYTE (8-bit unsigned) and ADDRESS (16-bit unsigned) scalars and arrays.
    • DECLARE X BYTE;
    • DECLARE (A, B) ADDRESS;
    • DECLARE X BYTE, Y ADDRESS;
  • Constants:
    • decimal numbers, or with a base suffix: 0FFH (hex), 1010B (binary), 17O/17Q (octal), 12D (decimal)
    • one- and two-character strings: 'A' is a BYTE, 'AB' is an ADDRESS
  • Operators, from highest to lowest precedence:
    1. unary -
    2. * / MOD
    3. + -
    4. = <> < > <= >=
    5. NOT
    6. AND
    7. OR XOR
  • Macros: DECLARE TRUE LITERALLY '0FFH'; and the like.
    • The text, up to 255 characters, is substituted for the name before parsing, so DCL LITERALLY 'DECLARE' works too.
    • Literals follow block scope, and inner declarations can hide them.
    • --ast shows the result of the substitution.
  • Initialized data:
    • DECLARE GREETING (*) BYTE INITIAL ('HELLO', 0); and DECLARE DAYS (*) BYTE DATA (31, 28, ...);.
    • Values fill scalars in storage order. Strings of any length up to 255 characters supply one character per BYTE and two per ADDRESS.
    • Initial values can also be location references (.BUF + 2), and (*) sizes an array from its list.
    • INITIAL is for the main program's outer level. DATA is stored with the code, can be used anywhere, and can't be assigned.
  • Structures:
    • DECLARE AIRPLANE (20) STRUCTURE (SPEED BYTE, ALTITUDE ADDRESS);, with members referenced as AIRPLANE(I).SPEED; members may be arrays (X(i).M(j)).
    • Structures can be factored and BASED. Whole structures are used only with . and LENGTH/LAST/SIZE.
  • Pointers:
    • DECLARE ITEM BASED PTR BYTE; makes ITEM mean whatever PTR points at; BASED arrays work too.
    • .X, .A(i) and .P give the address of a variable, an element or an outer-level procedure.
    • .('TEXT', 0) gives the address of constant bytes stored with the program.
    • DECLARE (LO, HI) BYTE AT (.WORD); makes aliases that share another variable's storage, and DECLARE PORT BYTE AT (0FF00H); puts a variable at a fixed address (for I/O registers). The 6809 is big-endian, so a BYTE AT an ADDRESS is its high-order byte.
  • Arrays:
    • DECLARE BUF(80) BYTE; declares BUF(0) to BUF(79).
    • Elements can be used anywhere a variable can, including as assignment targets.
    • Subscripts are any expression and aren't range-checked, as in PL/M-80.
    • A plain BUF means BUF(0).
    • LENGTH(BUF) and LAST(BUF) give the number of elements and the highest subscript (BYTE if 255 or less, as in PL/M-80), and SIZE(X) the number of bytes.
  • Built-ins: all of PL/M-80's except INPUT and OUTPUT, as built-ins only where the name isn't declared:
    • HIGH(W), LOW(W) and DOUBLE(B) convert between BYTE and ADDRESS; SHL(P, N)/SHR(P, N) shift a BYTE or ADDRESS, and ROL(P, N)/ROR(P, N) rotate a BYTE. They compile to inline code, so they work on every target.
    • CARRY, ZERO, SIGN and PARITY read the flags of the last + - PLUS MINUS SCL SCR DEC executed; SCL/SCR rotate through the carry, and DEC(A + B) adjusts a BCD addition. Unlike on the 8080, these flags are exact: plmc09 keeps them in memory.
    • CALL MOVE(count, from, to) copies bytes; CALL TIME(n) waits n × 100 µs, timed by the hooks' RT_CYCLES100.
    • MEMORY is the memory after the program (--memory N bytes under OS-9), and STACKPTR is the S register.
    • Arrays can't be parameters.
  • Statements:
    • assignment, including several targets (A, B = 0;)
    • IF ... THEN ... [ELSE ...]
    • DO; ... END; blocks, which may have their own declarations
    • DO WHILE ...; ... END;
    • DO I = start TO limit [BY step]; ... END;, with PL/M-80's rules: the limit and step are re-evaluated on each pass, and the loop ends when the index wraps around, so DO I = 0 TO 255 with a BYTE I ends
    • DO CASE expr; case-0; case-1; ... END;; an out-of-range selector runs no case
    • CALL, RETURN [expr], HALT, and the empty statement ;
  • Procedures:
    • P: PROCEDURE (A, B) [BYTE|ADDRESS] [EXTERNAL|PUBLIC] [REENTRANT] [INTERRUPT n]; ... END P;
    • PUBLIC (at a module's outer level) makes the procedure callable from other modules, which declare it EXTERNAL, and from assembly code, by its own name with the EXTERNAL calling convention. See Object files.
    • INTERRUPT 0, 1 and 2 are IRQ, FIRQ and NMI. The procedure runs when that interrupt occurs and returns with RTI; it must acknowledge the device itself. The hooks' PLM_SETINT installs it at start-up (CoCo: BASIC's RAM vectors, restored at exit), and --vectors puts it in the vector table. ENABLE; and DISABLE; unmask and mask IRQ and FIRQ. Not available with --os9.
    • Each parameter must be declared in the procedure body.
    • Procedures may be nested, and a nested procedure can see the variables of the procedures around it.
    • A typed procedure with no parameters is called just by naming it in an expression.
  • Labels and GOTO:
    • Any statement may be labeled (L1: L2: stmt), and GOTO L / GO TO L jumps to a label in the same block or an enclosing one (never into a block).
    • A GOTO out of a procedure may only go to the outer level of the main program; the stack is reset.
    • END name after a DO is checked against its labels.
    • DECLARE (L1, L2) LABEL; declares labels at the start of a block; they must label statements at the outer level of that block. LABEL PUBLIC also exports the label to assembly code under its own name, and LABEL EXTERNAL names an assembly-language label (in the hooks, say) that GOTO can jump to.

Semantics (following PL/M-80)

  • Unsigned: all arithmetic and comparisons are unsigned.
  • Result types:
    • + - MOD AND OR XOR give BYTE when both operands are BYTE, and ADDRESS otherwise. BYTE results wrap at 8 bits: with BYTE B = 200, B + 100 is 44, even when it is assigned to an ADDRESS.
    • * and / always give an ADDRESS.
    • PLUS and MINUS add and subtract with the carry (borrow) of the last +, -, PLUS, MINUS, SCL, SCR or DEC executed, for numbers wider than 16 bits: SL = AL + BL; SH = AH PLUS BH;. Unlike the 8080 compiler's flag, this carry is well defined (nothing else changes it).
    • Relational operators give a BYTE: 0FFH for true and 0 for false.
    • Unary - and NOT keep the type of their operand.
    • A constant is a BYTE if it is 255 or less.
  • Conditions: IF and WHILE test only bit 0 of the condition, so IF 2 is false and IF 3 is true. AND and OR always evaluate both sides.
  • Conversions: assigning an ADDRESS to a BYTE keeps the low byte, and a BYTE is zero-extended when it becomes an ADDRESS. Arguments and RETURN values are converted to the declared parameter or result type in the same way.
  • Division by zero gives a quotient of 0FFFFH and a remainder equal to the dividend. Programs should not rely on this.
  • Declaration order: a name must be declared before it is used.
  • Recursion needs REENTRANT: as in classic PL/M, an ordinary procedure's parameters and locals are stored in fixed RAM locations, and the compiler reports direct and indirect recursion through such a procedure as an error. A REENTRANT procedure keeps them on the stack (Y-relative frame) and may be recursive; inside a REENTRANT procedure, REENTRANT procedures may be called before they are declared.
  • INCLUDE: a line $INCLUDE(FILE.PLM) (or $IC(...)), with $ in column 1, compiles that file's text in its place. The file is looked for in the including file's directory and then in the -I directories, as written and in lower case; an ISIS drive prefix such as :F1: is dropped. Errors in an included file name that file. Other compiler controls ($NOLIST, $TITLE(...), ...) are ignored with a warning.
  • Undefined values: variables start with whatever is in memory. The simulator fills memory with $A5 so that use of an uninitialized variable shows up.

Not supported yet:

  • PUBLIC and EXTERNAL variables (PUBLIC and EXTERNAL procedures work)
  • embedded assignment :=

Not supported: INPUT(n) and OUTPUT(n), the 8080's port I/O. The 6809 has no I/O instructions or ports, only memory-mapped devices: declare their registers AT their addresses instead, as in DECLARE IO(16) BYTE AT (0FF00H); for the simulator's I/O block. INPUT and OUTPUT are then ordinary names a program may declare.

The compiler reports these with an error ("... is not supported") rather than misreading them.

Hooks

ld09 links the program with the start-up code runtime/crtplm.o, the runtime library runtime/libplm.a (only the routines the program uses) and a hooks library, libhooks.a, found through -L: so the same compiler output can target any machine. A hooks file is an as09 module (hooks.s) that exports its symbols.

Symbols a hooks file must define (and EXPORT)

Symbol Purpose
RT_STACKTOP the initial S. The stack grows down from here. 0 means keep the caller's stack; the caller's S is saved in RT_ENTRYS, so PLM_EXIT can return with LDS RT_ENTRYS / RTS.
PLM_EXIT jumped to when the program finishes, with the exit status in B (0 for a normal end)
PLM_HALT jumped to by HALT
RT_CYCLES100, RT_TIMEK only for programs that use TIME: CPU cycles in 100 µs, and (RT_CYCLES100-4)/8 for the runtime's delay loop
PLM_SETINT only for programs with INTERRUPT procedures: installs handler X for interrupt B
one label per EXTERNAL procedure the procedure's PL/M name, in upper case

Calling convention for EXTERNAL procedures

  • Arguments: each one is pushed as a 16-bit word, left to right (BYTE values are zero-extended first). On entry, the last argument is at 2,S, just above the return address, and is also in D.
  • Cleanup: the caller removes the arguments.
  • Results: a BYTE result is returned in B and an ADDRESS result in D.
  • Registers: a hook may change any register except S.

A one-argument hook therefore needs no stack access:

PUTCH   STB   $FF00     ; PUTCH: PROCEDURE (C) EXTERNAL; DECLARE C BYTE;
        RTS

Provided hooks files

  • runtime/sim/, for sim6809, which has its I/O at $FF00. It provides PUTCH, PUTDEC (prints a number and a newline), GETCH (returns 0 at end of input) and EXIT.
  • runtime/coco/, for the Tandy Color Computer 1/2/3 under Color BASIC. It provides PUTCH, PUTDEC, GETCH, EXIT and CLS. See Color Computer.
  • runtime/os9/, for OS-9 and NitrOS-9 program modules built with --os9. See OS-9.
  • runtime/flex/, for FLEX 9 commands. See FLEX.
  • runtime/simon6809/, for the Simon6809 board under its BUGGY monitor. See Simon6809.
  • runtime/kswichit/, for Wichit Sirichote's 6809 Microprocessor Kit under its monitor. See 6809 Microprocessor Kit.
  • runtime/searle6809/, for Grant Searle's 6809 SBC (and Jeff Tranter's PCB of it), under the ASSIST09 monitor or BASIC. See Grant Searle's 6809 SBC.
  • runtime/example/, a template for an MC6850 ACIA board. It has the same four procedures, with PUTDEC written on top of RT_DIV16. Copy hooks.s, adjust the addresses for your machine, assemble it (as09 -o hooks.o hooks.s) and link hooks.o in place of -lhooks. The test suite only checks that it assembles and links.

as09 has no -D and no conditional assembly on defined symbols, so a value such as a stack top or a clock rate is changed by editing a copy of the hooks file.

Programs of several modules

Every module plmc09 compiles is an object for ld09, so a program can be split into modules, each compiled and assembled on its own and all linked together. The main module is the one with statements: the start-up code calls its PLM_MAIN. The others hold declarations and procedures. Modules call each other's PUBLIC procedures through EXTERNAL declarations:

/* main.plm */                                  /* util.plm */
MAIN: DO;                                       UTIL: DO;
PUTDEC: PROCEDURE (N) EXTERNAL;                 GCD: PROCEDURE (A, B) ADDRESS PUBLIC;
    DECLARE N ADDRESS; END PUTDEC;                  DECLARE (A, B, T) ADDRESS;
GCD: PROCEDURE (A, B) ADDRESS EXTERNAL;             DO WHILE B <> 0;
    DECLARE (A, B) ADDRESS; END GCD;                    T = A MOD B; A = B; B = T;
CALL PUTDEC(GCD(1071, 462));                        END;
END MAIN;                                           RETURN A;
                                                END GCD;
                                                END UTIL;
plmc09 -o main.s main.plm
plmc09 -o util.s util.plm
as09 -o main.o main.s
as09 -o util.o util.s
ld09 -T0100 -Lruntime -Lruntime/sim -o demo.out -Cplm main.o util.o -lhooks -lplm
objcopy09 -O srec demo.out demo.s19
sim6809 demo.s19                                # prints 21

Only the main module may have INTERRUPT procedures, --vectors or INITIAL ... AT a fixed address (which its PLM_MAIN stores at start-up); the PLUS/CARRY flags are kept per module. OS-9 modules (--os9) are single modules. contrib/obj has a complete example with a Makefile.

Color Computer

The runtime/coco/ hooks call the Color BASIC ROM, so programs run under Color BASIC, Extended BASIC or Disk BASIC on a CoCo 1, 2 or 3:

build/plmc09 -o hello.s hello.plm
as09 -o hello.o hello.s
ld09 -T3000 -Lruntime -Lruntime/coco -o hello.out -Cplm hello.o -lhooks -lplm
objcopy09 -O decb hello.out HELLO.BIN

Then, on the CoCo:

CLEAR 200,&H2FFF
LOADM"HELLO":EXEC
  • Load address: link with -T. ld09's default, 0, and the usual $0100 would overwrite BASIC's RAM interrupt vectors at $0100–$0111. CLEAR 200,&H2FFF keeps BASIC out of memory from $3000 up. Never use --vectors here, because $FFFE is in ROM.
  • Stack and exit: the program runs on BASIC's stack. It returns to BASIC when it ends, on HALT, or when it calls EXIT, and BASIC discards the exit status.
  • Output: PUTCH and PUTDEC print through the ROM's CHROUT routine. Color BASIC ignores LF, so PUTCH(10) is sent as CR, the CoCo's newline. That way programs written for the simulator print correctly. Lower-case letters show as inverse video on a CoCo 1/2.
  • Input: GETCH waits for a key through the ROM's POLCAT routine. ENTER gives 13.
  • Clearing the screen: CLS (CLS: PROCEDURE EXTERNAL; END CLS;) calls the ROM's clear-screen routine.
  • Low memory: a program linked at $0E00 (-T0E00) sits where Disk BASIC's default graphics pages start (the BASIC program starts at $2600), so it must not use PMODE graphics, and its code and variables must end below $2600.

Testing

  • make coco-test runs the CoCo hooks in sim6809 with a stand-in for the ROM (tests/coco/fakerom.s). The stand-in also checks that the program returns to BASIC with the stack intact. One test (tests/coco/obj) is a program of two modules linked at $0E00; make xroar-test also runs it on the emulated CoCo, as a .BIN written by objcopy09 -O decb.
  • make xroar-test runs the same programs on an emulated CoCo 2 with Disk Extended Color BASIC 1.1. It writes each program to a disk image with toolshed's decb, has XRoar type LOADM"T":EXEC, and compares the text screen with tests/coco/*.screen. It is skipped when XRoar, decb or the ROMs are missing.

OS-9

build/plmc09 --os9 -o sum.s sum.plm
as09 -o sum.o sum.s
ld09 -i -Lruntime -Lruntime/os9 -o sum.out -Cplmos9 sum.o -lhooks -lplm
objcopy09 -O os9 -n sum -v 1 -d 256 sum.out sum
  • Running it: copy sum to CMDS on an OS-9 disk (with toolshed: os9 copy sum disk.dsk,CMDS/sum and os9 attr -e -pe disk.dsk,CMDS/sum) and run it from the shell. sim6809 --os9 sum runs it without OS-9.
  • Linking: ld09 -i links the data at 0, so it is reached through U; -Cplmos9 links the OS-9 start-up code (crtplmos9.o) first. objcopy09 -O os9 writes the module: the header (revision 1 with -v 1), the code, the name (-n) and the CRC. The data area holds the variables, MEMORY (--memory) and -d bytes of stack (256 here; objcopy09's own default is 1024).
  • What --os9 produces:
    • The module is position-independent (LBSR/LBRA instead of JSR/JMP) and reentrant.
    • All variables live in the process's data area, at fixed offsets from U, in one common block (RT_DATA), which takes no room in the module.
    • The hooks use I$Write, I$Read and F$Exit, with their buffers on the stack.
  • Choosing the module name: give it the name of the file it will be installed as. If it matches a command already in memory (for example echo), OS-9 runs that command instead.

FLEX

build/plmc09 -o sum.s sum.plm
as09 -o sum.o sum.s
ld09 -T0100 -Lruntime -Lruntime/flex -o sum.out -Cplm sum.o -lhooks -lplm
objcopy09 -O flex sum.out SUM.CMD
  • Running it: copy SUM.CMD to a FLEX disk and type SUM. sim6809 --flex SUM.CMD runs it in the simulator, which emulates FLEX's DOS entry points.
  • Any FLEX 9 system: the hooks only use FLEX's jump table at $CD00 (PUTCHR, PCRLF, GETCHR, OUTDEC, WARMS). The program returns to FLEX when it ends.
  • Machine-dependent values: the stack top (RT_STACKTOP, $C700, the top of FLEX's utility command area) and the clock for TIME (RT_CYCLES100, 1 MHz) are in runtime/flex/hooks.s; for others, link an edited copy in place of -lhooks.
  • objcopy09 -O flex writes a FLEX binary (.CMD), with the program's entry point as the transfer address.
  • Tested on real FLEX: the dragonflex suite runs the test programs on Compusense FLEX for the Dragon 64 under XRoar ($FLEX_DISK, default ~/coco/flex/FLEX_1.3.2.VDK).

Simon6809

build/plmc09 -o sum.s sum.plm
as09 -o sum.o sum.s
ld09 -T0400 -Lruntime -Lruntime/simon6809 -o sum.out -Cplm sum.o -lhooks -lplm
objcopy09 -O srec sum.out sum.s19
  • Running it: send the S1/S9 lines of sum.s19 at the BUGGY monitor's prompt and type G400. The program returns to the monitor (with SWI), which shows the registers, B being the exit status.
  • The board (drpeker/simon6809-ROM-Monitor): a 1 MHz 6809, 32 KB RAM (programs from $0400), an F 8A7E T245RL USB FIFO console that the hooks use through the monitor's getchar/putchar vectors, and RAM interrupt vectors that PLM_SETINT patches.
  • Tested on the board's real monitor ROM in sim6809 (--ft245, --swi): the simon6809 suite ($SIMON_ROM, default ~/coco/simon6809/simon09.rom.s19).

6809 Microprocessor Kit

build/plmc09 -o sum.s sum.plm
as09 -o sum.o sum.s
ld09 -T0200 -Lruntime -Lruntime/kswichit -o sum.out -Cplm sum.o -lhooks -lplm
objcopy09 -O srec sum.out sum.s19
  • Running it: press LOAD, send sum.s19 over the serial port (19200 8N1, 1 ms character delay), then GO (from $0200). The program returns to the monitor with SWI.
  • The kit (Wichit Sirichote, kswichit.net/6809/6809.htm): a 68B09 at 1.2288 MHz, 32 KB RAM, an MC6850 ACIA at $A000 that the hooks use directly (the monitor's routine addresses vary between versions), I/O at $8000 (the GPIO1 LEDs, keypad and display), and RAM interrupt vectors at $7FF0--$7FF8 that PLM_SETINT patches. The stack is at $7000, below the monitor's variables.
  • Tested in sim6809 with an ACIA (--acia) and a stand-in monitor: the kswichit suite.

Grant Searle's 6809 SBC

build/plmc09 -o sum.s sum.plm
as09 -o sum.o sum.s
ld09 -T1000 -Lruntime -Lruntime/searle6809 -o sum.out -Cplm sum.o -lhooks -lplm
objcopy09 -O srec sum.out sum.s19
  • Running it with Jeff Tranter's combined ROM: type L at ASSIST09's > prompt, send sum.s19's S1/S9 lines, then C 1000 (call; the program returns with RTS, and ASSIST09 shows the registers, B being the exit status). With Grant Searle's BASIC ROM: get the program into RAM, then CLEAR 200,&HFFF and EXEC &H1000.
  • The board (searle.wales/6809/Simple6809.html): a 68B09 at 1.8432 MHz, 32 KB RAM, a 6850 ACIA at $A000 that the hooks use directly, and a 16 KB ROM. PLM_SETINT handles both ROMs' interrupt routing (ASSIST09's RAM vector table, or BASIC's RAM JMPs).
  • Tested on both real ROMs in sim6809 (--acia, --rom, --reset, Intel HEX loading): the searle6809 suite ($SEARLE_ROM, $SEARLE_BASIC, defaults in ~/coco/searle6809/).

Generated code

  • Memory layout: ld09 puts the code at -T's address, starting with RT_START (crtplm.o), which sets up the stack and DP=0, then calls the main program (PLM_MAIN). The modules' code, the runtime and the hooks follow, then each module's variables, in declaration order (objcopy09 writes those without initial values as zeros). MEMORY starts after them (ld09's __end).

  • Sections: plmc09 puts code, DATA and constant lists in .TEXT and the variables in .DATA (one section, so that an AT alias may span several), and IMPORTs what other modules define (the runtime, the hooks, EXTERNAL procedures).

  • Registers: BYTE values are computed in B and ADDRESS values in D.

  • Multiply and divide: BYTE×BYTE uses the MUL instruction directly. Other multiplications and all divisions call RT_MUL16 and RT_DIV16 in the runtime library.

  • Source comments: each statement is preceded by its source line as a comment.

  • Label names: PL/M names can't contain _, so these prefixes never clash with your names.

    Label Meaning
    V_X global variable
    Vn_X variable in nested scope n
    M_X / Mn_X variable AT a fixed address
    P_X / Pn_X procedure
    G_X / Gn_X statement label
    Lnnn compiler-generated label
    RT_* runtime routine
    PLM_* hook entry point
    exact name EXTERNAL procedure

sim6809

sim6809 runs the programs built with runtime/sim, and has OS-9 and FLEX modes and board devices for the other targets' tests; see its manual for the options. A PL/M program can also reach its I/O block directly, as DECLARE IO(16) BYTE AT (0FF00H);.

I/O block

Address Access Meaning
$FF00 write put a character
$FF01 read get a character (0 at end of input)
$FF02 write exit with this status
$FF04/$FF05 write print the 16-bit value and a newline, triggered by the write to $FF05 (STD $FF04)
$FF06 write / read assert interrupt lines (1 IRQ, 2 FIRQ, 4 NMI) / read the asserted lines
$FF07 write release interrupt lines
$FF08/$FF09 write timer: assert lines every N instructions, started by the write to $FF09 (0 stops it)
$FF0A write the lines the timer asserts (default IRQ)

Exit status

  • the value the program writes to $FF02
  • 124 if the instruction limit is reached
  • 125 for an illegal opcode or an unsupported instruction (SWI, SWI2, SWI3)

It implements the full MC6809 instruction set, IRQ/FIRQ/NMI (level-triggered IRQ and FIRQ, as on the chip) with CWAI and SYNC, but not cycle timing.

Tests

make test runs these suites (each also has its own target, such as make run-test):

Suite What it checks
rt the runtime library's routines and the sim hooks, called from assembly (as09, linked by ld09) with hand-checked expected values
man the plmc09 man page formats without groff warnings and names every --help option
lex, parse --tokens and --ast output against golden files
err each program must fail to compile with the expected message
run compile, assemble, run, and compare output and exit status
obj programs of several modules, each compiled and assembled, linked by ld09, run in sim6809
coco the CoCo hooks in sim6809 against a stand-in ROM
os9 the run programs and fuzz programs as OS-9 modules in sim6809 --os9, at two load addresses
nitros9 the run programs on NitrOS-9 Level 2 booted under XRoar (skipped without XRoar, toolshed, $NITROS9_DISK and $COCO3_ROM)
xroar the CoCo programs on an emulated CoCo 2, comparing the screen (skipped without XRoar, ROMs and toolshed)
fuzz random expression programs checked against a C model of the typing rules; make fuzz-test N=2000 runs more

About

PL/M-80 compiler for the Motorola 6809 (lwasm output), with a 6809 simulator

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0