Help porting newlib to a new CPU architecture (sorta)

Orlando Arias
Wed Jul 7 20:56:44 GMT 2021


On 7/7/21 4:32 PM, ElijaxApps wrote:
> Hi all,
> I started reading GCC Internals Book, chapter 16 & 17.
> I am deciding how exactly define insn statements at this very right moment.
> I am using pdp11 as a template. However, there are lots of things I don't
> really need, in this config spec.
> As far as I have understood, I can follow two paths:
> a) Define instructions as my pseudo assy, and use my own "assembler".
> b) Define instructions as Linux ASM and use GAS, GNU Assembler.

Please allow me to contribute to the discussion at hand rather than
derail it any further.

Nikolai Kim has a very nice series of videos in YouTube describing how
he added a back-end to gcc for his CPU [1]. Notice that the instructions
he is adding are actually pseudoassembly (as far as I can tell anyway).
From the perspective of gcc [technically cc1 and cc1plus], the code that
gets emitted by the back-end of the compiler does not matter. The
compiler's job stops there. It's the assembler's job to actually
generate object files. If you are in Linux (or any other platform that
allows for it), you can

strace -f -o trace_gcc_driver gcc -o test.elf my_code.c

and see how the driver program calls different portions of the toolchain
to actually build an executable. You will see calls to the fork() and
execve() family of functions calling things like the compiler proper,
assembler, and linker.

Anyway, Nikolai Kim also has videos on adding a backend to binutils,
which is also worth checking out if you are interested. I believe his
code is online somewhere. Keep in mind that his code works for the
versions of gcc [and binutils] that he is modifying. These projects are
moving targets and internals are bound to change across releases.

As for your question about ABIs, you can find a portion of the ABI for
avr in [2]. It is missing things like how to deal with unwind sections,
debug infos, and the likes. Since this is your own CPU, you define the
ABI as you wish it to be. The one for Arm is found in [3].





-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Newlib mailing list