Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-04

Adding a redcode assembler to Free Pascal Compiler

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Skybuck Flying

Hello,

I kinda forget to mention something in my previous posting to this mailing list, but perhaps it should go into a seperate thread anyway:

As I mentioned in the previous posting with subject: "Adding a new assembler to Free Pascal Compiler"... I am interested in using free pascal compiler to create support for virtual machines and perhaps new hardware in the future.

As a learning exercise I would like to start with writing a little redcode assembler for Free Pascal Compiler to be able to compile Pascal Source Code to Redcode/PMARS95 instructions/assembler. (Redcode is the assembly code/language for PMARS95 which is the virtual machine).

I already have a virtual machine for the redcode assembly/instructions, there is also the open source pmars virtual machine which you can have a look at to see what I am writing about ;)

So I wonder what is involved in supporting a new platform... be it real hardware or virtual machines.

One thing which comes to mind is the RTL ?

Do new "targets" (as it's called ?) require their own RTL as well ? I did see a mention about a dummy RTL as a possibility (Not sure if that's needed but I would guess so ;)).

So it would be cool if free pascal compiler could compile pascal sources into redcode assembly, which can then be further compiled by the PMARS executable/assembler.

So I just need free pascal compiler to output redcode assembly... it probably doesn't have to link anything or assemble anything further, though a little bit of linking support for using multiple pascal sources would be cool as well... not sure how that would work at assembly level... maybe that's a good question too... would free pascal compiler simply perform some kind of linking/syntax checking for uses clausule based on assembly files (*.s) ? Or perhaps it does it via interface/header files ? (probably last one). So as long as all headers are present then assembly of those files don't matter and compiler knows what it's doing... So linking of assemblies only happens later by other tools (?). So for example: a call to a routine of some unit is outputted as a call to a label... and then the external assembler tool will hopefully know what to do with those labels ;) (User will probably have to supply multiple assembly files in such a case ;) that probably what make files are for ;))

Bye,
Skybuck.

Reply by email

Michael Schnell
to Skybuck Flying
Skybuck Flying wrote
So it would be cool if free pascal compiler could compile pascal sources into redcode assembly, which can then be further compiled by the PMARS executable/assembler.

AFAIK, other than gcc, FP is designed to drop the ASM source code step of code generation and is intended to directly output a linkable binary. An internal linker is optionally usable in some archs as well, making FP directly output an executable

-Michael

Reply by email

Sven Barth
to Michael Schnell
Michael Schnell wrote 8 lines
On 04/05/2011 02:21 AM, Skybuck Flying wrote: > So it would be cool if free pascal compiler could compile pascal > sources into redcode assembly, which can then be further compiled by > the PMARS executable/assembler. AFAIK, other than gcc, FP is designed to drop the ASM source code step of code generation and is intended to directly output a linkable binary. An internal linker is optionally usable in some archs as well, making FP directly output an executable

FPC does generate ASM. You can see it by adding the option "-al", if I remember correctly. There is just one difference: unlike GCC FPC contains an internal assembler for i386 (and maybe x86_64 as well). Other targets like arm need an external assembler binary.

Regards,
Sven

Reply by email

Hans-Peter Diettrich
to Skybuck Flying: I kinda forget to mention something in my previous posting to this mailing list, but…
Show quoted text 8 lines
So I wonder what is involved in supporting a new platform... be it real hardware or virtual machines. One thing which comes to mind is the RTL ? Do new "targets" (as it's called ?) require their own RTL as well ? I did see a mention about a dummy RTL as a possibility (Not sure if that's needed but I would guess so ;)).

Of course every platform needs a RTL, at least for memory allocation, basic I/O and probably for file handling.

So it would be cool if free pascal compiler could compile pascal sources into redcode assembly, which can then be further compiled by the PMARS executable/assembler.

Prepare your nodes to create the assembler code, and make the external assembler called for these source files.

Show quoted text 11 lines
So I just need free pascal compiler to output redcode assembly... it probably doesn't have to link anything or assemble anything further, though a little bit of linking support for using multiple pascal sources would be cool as well... not sure how that would work at assembly level... maybe that's a good question too... would free pascal compiler simply perform some kind of linking/syntax checking for uses clausule based on assembly files (*.s) ? Or perhaps it does it via interface/header files ? (probably last one). So as long as all headers are present then assembly of those files don't matter and compiler knows what it's doing... So linking of assemblies only happens later by other tools (?).

IMO the compiler creates .ppu files for all units, as usual, and you'll have to call the external linker with the .o files, created by the also external assembler.

Show quoted text 5 lines
So for example: a call to a routine of some unit is outputted as a call to a label... and then the external assembler tool will hopefully know what to do with those labels ;) (User will probably have to supply multiple assembly files in such a case ;) that probably what make files are for ;))

Get a description of the assembler syntax, so that you know what to put into your files.

DoDi

Reply by email

Michael Schnell
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote
Of course every platform needs a RTL, at least for memory allocation, basic I/O and probably for file handling.

Thread handling (e.g. threadvars) is another example. Using libc (in Linux) prevents doing ASM or arch depending code in the RTL. This has pros and cons which already have been discussed here several times.

-Michael

Reply by email