GithubHelp home page GithubHelp logo

zu2 / smallc68 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from linuxha/smallc68

0.0 0.0 0.0 691 KB

FLEX 6800 Small C compiler

License: GNU Lesser General Public License v2.1

Python 0.91% C 62.66% Assembly 24.96% Logos 3.11% Makefile 0.28% Batchfile 5.36% Raku 2.72%

smallc68's Introduction

fork from - linuxha/SmallC68: FLEX 6800 Small C compiler

The license and other restrictions of this fork follow the original. I am interested in a compiler for the MC6800, and I don't know (can't check) whether the code for MC6801/3/9 will work correctly.

							ZUKERAN, shin (@zu2)

SmallC68XX - Small C for the Motorola 68XX family under Linux

I am on a quest for a Small C compiler to support the various 6800/6803/6809/68000 boards I have. So with that in mind I am posting my notes and everything else I find on Small C. So for a while this will be quite a mess.

Ron Cain's 1.1 Small C compiler for the 6800, 6801, 6803 and 6809. Maybe the 68HC11. The original Author of the Flex port is S. Stepanoff

Originally these were Flex OS Compilers but I think I can make this work under Linux and the output code should be OS agnotic. My intention is to set them up to work on Linux as a cross-compiler.

Notes

There are currently 3 sets of source code for the Small C compiler. The 6800 version (a C to peudo code compiler), the silifen version (looks like a C to asm code compiler), and the v22 version (MSDOS C to executable).

6800/ ..... Early version of the Flex OS Small C compiler (very limitted, v1.1 1982)
silifen/ .. Later version of the Flex OS Small C compiler (has for(), etc v2.1 1985)
v22/ ...... MSDOS version of the Small C compiler (v2.2, outputs 8086 code)
MicroC/ ... Dave Dunfield's Micro C (CUG422_* DOS Binaries)
LICENSE ... Proposed License (I may need to change this)
Makefile .. Ignore this, make files have moved their respective directories
README.md . This file
ccint.txt . Ignore this file (Small C interpreter used in 6800 version)

After reading and poking around the Flex Small C Compiler DSK images I've guessed that these are Ron Cain's Small C V1.1 compiler and that the runXX (00,01,09) are the runtime files that take the psuedo code and make it understandable (assemble) under Flex.

The ccx.c files is the smallc.c file broken into 9 sections so the small C compiler can compile itself on Flex. Since I'll be using Linux to cross compile. I'll not include this files.

cc0.c
cc1.c
cc2.c
cc3.c
cc4.c
cc5.c
cc6.c
cc7.c
cc8.c

The important file is smallc.c, that's my starting point. The p.c file is a C pre-processor. I'm not sure if I'll use it but decided to keep it here for now. The rest of the files are files needed to assemble the psuedo code generated by the small C compiler. At this time I'm not sure which is which. I'll work on that.

ccc.h
ccint.txt
flexptrs.txt
LICENSE
p.c
prtlib.asm
prtlib.c
prtlib.lib
README.md
run1.asm
run9.asm
run9.c
smallc.c

2023/02/04 - I've got the compiler hacked together and mostly working. What I've found is that the small c compiler outputs pseudo code and that the run9 (6809) and run1 (6801) code are the asm source to an interpreter. Assemble the code together and you have a program. This small C compiler is still quite limitted but may be useful and as one of the notes files points out C is easier to write than asm code. Anyway I'm posting this mess so I don't lose it and so other might get ideas. Just note that this is terrible C code. It was meant to use the very limmited small c compiler to compile itself. I'm in the process of making it work under Linux as a cross compiler for any of the Motorola preocessors. It will no longer compiler itself.

2024/05/19 - I've added more debugging to the Small C compiler and I've written an Alpha version of therun0.asm (6800 version). I haven't tested it yet.

Understanding so far (Operation)

Okay I'm getting a better grasp of the Small C Byte compiler. It appears The Small C compiler sees the CPU as a virtual CPU with a 16 bit register, A 16 bit wide stack. There are about 42 pseudo-op codes. You write the libraries and 'micro code' in the assembly language of your choice. If you include the run9.asm (6809) at the start of your C code the compiler will include that into the output. The run9.asm contains the init code, the interpreter, the 'micro-code' and the point where the interpreted code starts. The compiler then adds the byte codes and FCB, FDB, etc. So one nice assembly file. You then assemble the code.

The (byte code) interpreter treats the bytes as assembly language and looks up the byte code in a jump table (at least for the 68xx processors). And runs that code, the returns to the interpreter when done. Here I've removed the asm library (printf, puts, gets etc.) and the interpreter except for the jump table. After the jump table would be the 'micro-code' followed bu the C byte code (I've trimmed it to just the main() section).

:* Jump table from interpreter code, second #xx is the Small C vop-code
JTABLE  FDB     LD1IM           ;*  #0  #0
        FDB     LD1SOFF         ;*  #1  #2
        FDB     LD1             ;*  #2  #4
        FDB     LDB1            ;*  #3  #6
        FDB     LD1R            ;*  #4  #8
        FDB     LDB1R           ;*  #5  #10
        FDB     ST1             ;*  #6  #12
        FDB     STB1            ;*  #7  #14
        FDB     ST1SP           ;*  #8  #16
        FDB     STB1SP          ;*  #9  #18
        FDB     PUSHR1          ;*  #10 #20
        FDB     EXG1            ;*  #11 #22
        FDB     JMPL            ;*  #12 #24
        FDB     BRZL            ;*  #13 #26
        FDB     JSRL            ;*  #14 #28
        FDB     JSRSP           ;*  #15 #30
        FDB     RTSC            ;*  #16 #32
        FDB     MODSP           ;*  #17 #34
        FDB     DBL1            ;*  #18 #36
        FDB     ADDS            ;*  #19 #38
        FDB     SUBFST          ;*  #20 #40
        FDB     MUL1            ;*  #21 #42
        FDB     DIV1            ;*  #22 #44
        FDB     MOD             ;*  #23 #46
        FDB     ORS             ;*  #24 #48
        FDB     XORS            ;*  #25 #50
        FDB     ANDS            ;*  #26 #52
        FDB     ASRS            ;*  #27 #54
        FDB     ASLS            ;*  #28 #56
        FDB     NEGR            ;*  #29 #58
        FDB     NOTR            ;*  #30 #60
        FDB     INCR            ;*  #31 #62
        FDB     DECR            ;*  #32 #64
        FDB     ZEQ             ;*  #33 #66
        FDB     ZNE             ;*  #34 #68
        FDB     ZLT             ;*  #35 #70
        FDB     ZLE             ;*  #36 #72
        FDB     ZGT             ;*  #37 #74
        FDB     ZGE             ;*  #38 #76
        FDB     ULT             ;*  #39 #78
        FDB     ULE             ;*  #40 #80
        FDB     UGT             ;*  #41 #82
        FDB     UGE             ;*  #42 #84
        FDB     ASMC            ;*  #43 #86

Here's just the main() part compiled under Flex and Small C for the 6809:

*main(argc, argv)
main 
*int  argc;
*char *argv[];
*{
*    /* Let's cheat, @ thru DEL get 0110 knocked off */
*    /* so \@ (x40) becomes NULL (x00), A (x41) or a (x61) becomes ^A (x01), etc
* */
*    while (--argc > 0) {
cc6 
 	FCB 	2		;* LD1SOFF
 	FDB 	4		;*
 	FCB 	20		;* PUSHR1
 	FCB 	8		;* LD1R
 	FCB 	64		;* DECR
 	FCB 	16		;* RTSC
 	FCB 	20		;*
 	FCB 	0		;*
 	FDB 	0		;*
 	FCB 	74		;*
 	FCB 	26		;*
 	FDB 	cc7		;*
*        ++argv;
 	FCB 	2		;*
 	FDB 	2		;*
 	FCB 	20		;*
 	FCB 	8		;*
 	FCB 	62		;*
 	FCB 	16		;*
*        print(*argv);           /* print the 'word' */
 	FCB 	2		;*
 	FDB 	2		;*
 	FCB 	8		;*
 	FCB 	10		;*
 	FCB 	20		;*
 	FCB 	28		;*
 	FDB 	print		;*
 	FCB 	34		;*
 	FDB 	2		;*
*        putchar(' ');
 	FCB 	0		;*
 	FDB 	32		;*
 	FCB 	20		;*
 	FCB 	28		;*
 	FDB 	putchar		;*
 	FCB 	34		;*
 	FDB 	2		;*
*    }
 	FCB 	24		;*
 	FDB 	cc6		;*
cc7 
*    /* nl(); */
*}
 	FCB 	32		;*
*/*
*-*- mode: c-mode; -*-
**/
 ORG RAM
 END RUN

* --- End of Compilation ---

Currently the Small C compiler I have under Linux has a few issues I need to work on.

Useful links:

http://www.pennelynn.com/Documents/CUJ/HTML/90HTML/199000DA.HTM A Survey Of CUG C Compilers by Victor Volkman https://archive.org/details/cug995 C Users' Group CDROM, September 1995 edition https://github.com/linuxha/asl ASL Macro assembler https://github.com/EtchedPixels/CC6303 A C compiler for the 6800/6803/6303 processors https://github.com/aladur/flexemu - 6809 Flex OS Emulator for Linux & Windows https://hackaday.io/project/189491-small-c-68xx - Hackaday project

                      Summary of CUG C Compilers

                      Target      Implementation
 CUG     Target      Operating    Based on Port   Date of Last  Overall
Disk #    CPU         System          From          Revision    Rating
------------------------------------------------------------------------

 104    Z-80/8080  CP/M 80 v2.2  RC Small C v1.1  06/28/1981    ***
 132    6809       0S-9          RC Small C v1.1  10/18/1983    **
 146    6800       FLEX v2.1     RC Small C v1.1  09/09/1982    **
 156    Z-80       CP/M          RC Small C v1.2  08/02/1984    ****
 163    8086       PC-DOS 1.1    JH Small C v2.0  01/14/1984    ***
 170    8086       PC-DOS 1.0    RC Small C v1.0  06/01/1982    *
 204    68000      Unix V        N/A              01/01/1986    ****
 221    6809       FLEX          RC Small C v1.0  11/15/1986    ***
 243    8086       PC-DOS 2.0    DECUS            12/01/1985    N/A

License

For the moment I've selected LGPL 2.1, I'm not certain I can do this as the previous programmers had different licenses. I'll adjust as needed.

smallc68's People

Contributors

linuxha avatar zu2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.