Re: Constants

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Constants

Carsten Bager
Hi

Would there be a chance to implement "Static" or something that did
the same trick, in the compiler. Now I write my constants in an
assembler file. That´s acceptable, but it is not a very elegant way to
do it.

Regards Carsten


> > Carsten Bager wrote:
> >
> > > Hi
> > > I am programming to an embedded ARM platform and my question
> > > is, is it possible to force constants to stay in the code segment
> > > (constant strings etc.) In C you can do this using "static".
> > > It looks as all string constants are placed in the data segment, and all
> > > variables are placed in the bss segment. Is that always the case?
> >
> > Yes. What's the exact reason you need them in text segment?
>
> The Arm I use has 512KB flash and 32KB Ram, therefore I would
> like if I could define text constants that where placed in the flash
> segment (text). A way around this is:
> 1. To define string constants in an assembler file.
> 2. To tell the linker that the data segment are placed in flash (at the
> right location). Then change the start up code so it dos not initialize
> the data segment and change the system files so all predefined
> variables are changed to normal variables which are initialized.
> I have not tried (2), but I assume it is possible.
>
> The very best would be if things was like this
>
> Static
> St: array[0..4] of char ='12345'; {Placed in text segment}
>
> Var
> St: array[0..4] of char ='12345'; {Placed in data segment}
>
> Or something that worked the same way.
>
> Regards
> Carsten
>


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Constants

Marco van de Voort
> Would there be a chance to implement "Static" or something that did
> the same trick, in the compiler. Now I write my constants in an
> assembler file. That?s acceptable, but it is not a very elegant way to
> do it.

It's not the keyword that is the problem. The whole logic for this would
have to be implemented.  Think switches, commands to the linker, a way to
configure the name for the segment etc. Part of this is specific for your
device setup.

If writable const is off, also variables declared with CONST could be put in
a different segment. There is no need to invent new syntax.

However all the linker stuff should be implemented by sb who has such a
device and the interest to work on it.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Constants

Carsten Bager
> It's not the keyword that is the problem. The whole logic for this would
> have to be implemented.  Think switches, commands to the linker, a way to
> configure the name for the segment etc. Part of this is specific for your
> device setup.
>
> If writable const is off, also variables declared with CONST could be put in
> a different segment. There is no need to invent new syntax.
>
> However all the linker stuff should be implemented by sb who has such a
> device and the interest to work on it.

Why not just drop static constants in the Text (Code) segment. I have
seen other compilers do that. This will not involve any change of the
interface with the linker (That is what I am doing now in a separate
assembler file).
On the other hand I am already using a configuration file for the
linker. (Where to place Stack, data code etc.)  I assume that it would
be easy to take care of an extra segment in the linker configuration
file.

Regards Carsten


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Constants

Tomas Hajny
Carsten Bager wrote:

>> It's not the keyword that is the problem. The whole logic for this would
>> have to be implemented.  Think switches, commands to the linker, a way
>> to
>> configure the name for the segment etc. Part of this is specific for
>> your
>> device setup.
>>
>> If writable const is off, also variables declared with CONST could be
>> put in
>> a different segment. There is no need to invent new syntax.
>>
>> However all the linker stuff should be implemented by sb who has such a
>> device and the interest to work on it.
>
> Why not just drop static constants in the Text (Code) segment. I have
> seen other compilers do that. This will not involve any change of the
> interface with the linker (That is what I am doing now in a separate
> assembler file).
> On the other hand I am already using a configuration file for the
> linker. (Where to place Stack, data code etc.)  I assume that it would
> be easy to take care of an extra segment in the linker configuration
> file.

I might be completely wrong, but I suspect it isn't such an easy decision
(as a general rule at least). Some CPUs/platforms might not allow data
access in TEXT (code) segment at all. I don't know whether this is the
case for any of our currently supported platforms (I surely know that it
is _not_ the case for x86 at least ;-) and I guess the same is true for
ARM if you're doing it right now), but it might be (either now or in
future).

Tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Constants

Peter Vreman
In reply to this post by Carsten Bager
>> It's not the keyword that is the problem. The whole logic for this would
>> have to be implemented.  Think switches, commands to the linker, a way
>> to
>> configure the name for the segment etc. Part of this is specific for
>> your
>> device setup.
>>
>> If writable const is off, also variables declared with CONST could be
>> put in
>> a different segment. There is no need to invent new syntax.
>>
>> However all the linker stuff should be implemented by sb who has such a
>> device and the interest to work on it.
>
> Why not just drop static constants in the Text (Code) segment. I have
> seen other compilers do that. This will not involve any change of the
> interface with the linker (That is what I am doing now in a separate
> assembler file).
> On the other hand I am already using a configuration file for the
> linker. (Where to place Stack, data code etc.)  I assume that it would
> be easy to take care of an extra segment in the linker configuration
> file.

In the compiler is support for a .rodata section, but this doesn't work
yet.  It has very low priority to fix this support. You are welcome to
supply patches to make it work. In your own linker script you can then
include the .rodata in the .text segment of the final executable.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal