Date: Thu, 11 Dec 2014 17:42:38 +0100
From: Philipp Klaus Krause <pkk-dH2bkuHepfc@public.gmane.org
Subject: Re: [Sdcc-user] Migrating from Cosmic to SDCC;
Content-Type: text/plain; charset="windows-1252"
On 18.11.2014 15:14, Rolf Schroder wrote:
FYI: I could not find any information about Storage Class Language
Extensions for the STM8 in the doc so I removed the " <at> near" / " <at> far"
extensions used by the COSMIC compiler (instead of replacing them with
SDCC's version). I am not sure whether the code will still work.
sdcc does not yet support storage class extensions for the stm8. The two
that would make sense are __near and __far (I don't know about Cosmic,
but would suppose that they correspond to their <at> near and <at> far). I do
not consider implementing them a priority currently:
- They are only relevant for global variables.
- Implementing them would require some effort in various places (code
generation, peephole optimization, linker, assembler).
- __near corresponds to what is called short addressing mode in the STM8
manuals. It would allow the programmer to specify up to 256 bytes of
global variables to be in the lower 256 B of memory. Accesses to these
global variables would result in more compact code than other global
variables. Most instructions support short addressing mode, so most
accesses to these variables would result in slightly shorter code than
normal global variables. The programmer would have to make sure that he
uses __near for at most 256B (maybe the linker could give an error
message otherwise). Summary: __near provides a limited code size benefit
at the cost of some extra burden on the programmer.
- What sdcc currently uses for all global variables is called long
addressing mode in the STM8 manual. It allows access to 64 KB of memory.
Enough to access all memory on nearly all STM8 microcontrollers. Most
instructions support long addressing mode. Summary: This is the perfect
default for global variables.
- __far corresponds to what is called extended addressing mode in the
STM8 manual. It allows access to up to 16MB of memory. Only very few
instructions support extended addressing mode (ldf, callf, jpf, retf).
So any access to a __far variable would have to go through ldf
instructions for every byte copying the variable elsewhere first. This
makes access to __far variables very inefficient. Currently no STM8
microcontroller that has more than 6 KB of RAM exists. Very few STM8
microcontrollers have flash memory outside the lower 64 KB. And only if
you want to use that flash for constant global variables (instead of for
code) is this addressing mode useful: Summary: __far is something only
useful in rather exotic use-cases.
- Note that sdcc currently also does not support __banked calls. This
means that code is currently also limited to the lower 64KB of memory.
Lifting this restriction would however be far easier than implementing
__far (we would use callf, jpf, retf), as long as no functions pointers
to functions outside the lower 64KB are used (for function pointers
pointing to code outside the lower 64KB we would need __far).