Recent

Author Topic: Investigating the use of freepascal for embedded systems (or small containers)  (Read 414 times)

Bogen85

  • Newbie
  • Posts: 3
I'm trying this out on Linux x86_64, to see what is involved for getting the minimum viable sized pascal app.
My first attempt results in something about half the size of an equivalent C app, but with some reduced maintainability.
(4440 bytes versus 8544 bytes).


I have several files and a discussion involved, so I put in it a gist here:
https://gist.github.com/bogen85/4e24f5e6d1b8ad3ea2ec97af4f2d3172

The basic questions I need answers to are:
1) How does one reference literal strings from other units in free pascal in inline assembler?
2) How to I get access to fpc_shortstr_to_shortstr while still maintaining a fairly small size? (Yes, I understand each added item witll cause the app size to grow).
3) Or addition of things like writeln? (assuming I'll have to the needed output routines, in pascal, assembly, from some existing c code, or a combination of those).

In my example gist I'm linking with gcc. I assume to get things like fpc_shortstr_to_shortstr I'd need to link with fpc, as I was not finding that symbol in any library.
I'd like to keep the size small, 10s of kb, versus hundreds...

« Last Edit: August 12, 2020, 02:24:06 pm by Bogen85 »

Bogen85

  • Newbie
  • Posts: 3
Of course I know how to do a hello world in free pascal, but a standard one is over 100K, not just over 4K as in the initial prototype attempt.

Handoko

  • Hero Member
  • *****
  • Posts: 3869
  • My goal: build my own game engine using Lazarus
Hello Bogen85,
Welcome to the forum.

I use Lazarus. As I don't use FPC directly, I cannot answer your questions. But I know a page that I think maybe you will be interested:

https://wiki.freepascal.org/Size_Matters

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 778
You may want to check out the embedded target, which is built specifically to strip out unused parts of the RTL without having to manually tinker with the generated code. There's some information about it on https://wiki.freepascal.org/TARGET_Embedded, but not that much and it focuses on architectures that are more often used in embedded contexts.

Additionally, "fpc -i" prints the "Recognized compiler and RTL features". You can use those strings with the -Sf  command line option to determine which features should be included when compiling the RTL, in particular when compiling for the "Embedded" target (-Tembedded). See rtl/embedded/*.cfg

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8800
  • FPC developer.
And if you really want to go low on production targets, you can't escape cutting down the RTL yourself.

Bogen85

  • Newbie
  • Posts: 3
Yeah, I'll need to the embedded target route and cut down the RTL... Just shutting on/off RTL features is not enough. Thanks.

 

TinyPortal © 2005-2018