Sign in Join

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

Mailing lists / fpc-pascal / 2006-01

Constants

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Carsten Bager

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?

Regards Carsten

Reply by email

Florian Klaempfl
to Carsten Bager
Carsten Bager wrote 6 lines
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?

Reply by email

Martin Schreiber
to Florian Klaempfl
Florian Klaempfl wrote 9 lines
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?

In embedded work *all* should be possible. Every job is a special job and needs special solutions.

Da kommt noch einiges auf euch zu! ;-)

Martin

Reply by email

Carsten Bager
to Florian Klaempfl: Yes. What's the exact reason you need them in text segment?
Show quoted text 10 lines
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

Reply by email

Martin Schreiber
to Carsten Bager
Carsten Bager wrote 8 lines
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 to have any count of named segments which can be selected at var or const definition.

Var in text <- use the appropriate notation St: array[0..4] of char ='12345'; {Placed in text segment}

Var in bss
St: array[0..4] of char ='12345'; {Placed in data segment}

Const in myspecialseg
St: array[0..4] of char ='12345'; {Placed in special segment}

Martin

Reply by email

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

Show quoted text 34 lines
> 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

Reply by email

Marco van de Voort
to Carsten Bager
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.

Reply by email

Carsten Bager
to Marco van de Voort
Show quoted text 10 lines
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

Reply by email

Tomas Hajny
to Carsten Bager
Carsten Bager wrote 22 lines
> 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) 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

Reply by email

Peter Vreman
to Carsten Bager: Why not just drop static constants in the Text (Code) segment. I have seen other…
Show quoted text 22 lines
> 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.

Reply by email