tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Very sorry - newbie questions


From: Michael Matz
Subject: Re: [Tinycc-devel] Very sorry - newbie questions
Date: Mon, 13 Mar 2017 01:20:47 +0100 (CET)
User-agent: Alpine 2.20 (LSU 67 2015-01-07)

Hi,

On Sun, 12 Mar 2017, Tony Robinson wrote:

Very sorry for newbie questions but I'm looking for C compiler for a processor that I've been very slowly building as a hobby. The instruction set is super simple (Rz = Rx op Ry for op in ADD, SUB, AND, OR, XOR, ASR plus basic LOAD/STORE/PUSH/POP instructions) and as the clock rate is only about 50kHz I'm not too worried about optimization. Portability is key - I will port FORTH but would love C.

Writing a TCC backend is relatively straight forward if you don't need to care for compatibility with existing target practice (like e.g. calling conventions). The few registers you have should be enough. The limitations in the instruction set (e.g. no multiplication, no float) can be ignored at first (you'd have to write some routines to do that for you and call these instead of the missing insns).

But that's only the code generator itself, there might be some difficulties because you have a bare-metal target: no executable file format, no standard libraries. And there might be hidden hardcoded assumptions about e.g. int being at least 32bit, or the width of relocations.

I would suggest to start with emitting some ELF files (that's the native exe format of TCC) and converting them after the fact to some binary blob containing only the data and instructions (you'll have to think about how to actually layout your executables and load them only your board anyway).

(Well, the actual start will of course be with the code generator :) )

a) tcc is the simplest C compiler for me to retarget and

TCC probably has the simplest target interface with the advantage that you don't need to learn any domain specific new language to write it, just normal C code emitting the right bytes. The compiler itself (also because it contains preprocessor and linker (and assembler) in one place and implements C fairly completely) is very small but not the simplest possible.

b) assuming that it is, I did the standard:

$ tar xvf tcc-0.9.26.tar.bz2
$ cd tcc-0.9.26

That's already too old, don't even start with that. We're currently in the process of working towards a new release, but it's simpler to just start with the mob branch from git:

% git clone git://repo.or.cz/tinycc.git

P.S. more CPU info than you probably wanted to know at nanocpu.org

A daunting plan you have there :)  (but a very nice thing!)


Ciao,
Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]