@nataliapc/mcp-openmsx 1.2.9 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -2
- package/bin/win-x64/mcp-openmsx-sspi-proxy.exe +0 -0
- package/dist/chunker.js +187 -0
- package/dist/embedder.js +250 -0
- package/dist/openmsx.js +113 -248
- package/dist/openmsx_windows.js +316 -0
- package/dist/server.js +6 -1
- package/dist/server_tools.js +6 -5
- package/dist/vectordb.js +94 -35
- package/package.json +16 -18
- package/resources/audio/chipsfmpacpr1_en.md +209 -0
- package/resources/audio/chipsfmpacpr2_en.md +170 -0
- package/resources/audio/toc.json +12 -0
- package/resources/book--msx-top-secret-3/MTS3-Appendix-English-Upd2.pdf +0 -0
- package/resources/book--msx-top-secret-3/MTS3-Complete-English.pdf +0 -0
- package/resources/book--msx2-technical-handbook/toc.json +1 -1
- package/resources/book--the-msx-red-book/Chapter1_Programmable_Peripheral_Interface.md +112 -0
- package/resources/book--the-msx-red-book/Chapter2_Video_Display_Processor.md +308 -0
- package/resources/book--the-msx-red-book/Chapter3_Programmable_Sound_Generator.md +168 -0
- package/resources/book--the-msx-red-book/Chapter4_ROM_BIOS.md +2528 -0
- package/resources/book--the-msx-red-book/Chapter5_ROM_BASIC_Interpreter.md +3975 -0
- package/resources/book--the-msx-red-book/Chapter6_Memory_Map.md +1963 -0
- package/resources/book--the-msx-red-book/Chapter7_Machine_Code_Programs.md +1238 -0
- package/resources/book--the-msx-red-book/Introduction.md +104 -0
- package/resources/book--the-msx-red-book/toc.json +38 -3
- package/resources/processors/toc.json +3 -3
- package/resources/processors/z80-undocumented.md +141 -0
- package/resources/sdcc/1_Introduction.md +199 -0
- package/resources/sdcc/2_Installing_SDCC.md +533 -0
- package/resources/sdcc/3_Using_SDCC.md +1758 -0
- package/resources/sdcc/4_Notes_on_supported_Processors.md +1638 -0
- package/resources/sdcc/5_Debugging.md +210 -0
- package/resources/sdcc/6_Tips_and_Support.md +258 -0
- package/resources/sdcc/7_SDCC_Technical_Data.md +489 -0
- package/resources/sdcc/8_Compiler_internals.md +477 -0
- package/resources/sdcc/toc.json +44 -2
- package/vector-db/msxdocs.lance/_indices/4d3bd360-e3c6-408d-b0ff-a4d6bd9580cb/metadata.lance +0 -0
- package/vector-db/msxdocs.lance/_indices/4d3bd360-e3c6-408d-b0ff-a4d6bd9580cb/part_0_docs.lance +0 -0
- package/vector-db/msxdocs.lance/_indices/4d3bd360-e3c6-408d-b0ff-a4d6bd9580cb/part_0_invert.lance +0 -0
- package/vector-db/msxdocs.lance/_indices/4d3bd360-e3c6-408d-b0ff-a4d6bd9580cb/part_0_tokens.lance +0 -0
- package/vector-db/msxdocs.lance/_transactions/0-6f47c9fc-3657-40f0-9dd4-c7226b2a4805.txn +0 -0
- package/vector-db/msxdocs.lance/_transactions/1-2bb7426e-a4b0-40ea-9a58-00c4985fc6a9.txn +0 -0
- package/vector-db/msxdocs.lance/_versions/18446744073709551613.manifest +0 -0
- package/vector-db/msxdocs.lance/_versions/18446744073709551614.manifest +0 -0
- package/vector-db/msxdocs.lance/_versions/latest_version_hint.json +1 -0
- package/vector-db/msxdocs.lance/data/110001110001011010001000876c134b8296fbc47762d1e1ab.lance +0 -0
- package/resources/book--the-msx-red-book/the_msx_red_book.md +0 -10349
- package/resources/processors/z80-undocumented.tex +0 -5617
- package/resources/sdcc/lyx2md.py +0 -745
- package/resources/sdcc/sdccman.lyx +0 -81574
- package/resources/sdcc/sdccman.md +0 -5557
- package/vector-db/index.json +0 -1
|
@@ -0,0 +1,1758 @@
|
|
|
1
|
+
# SDCC Compiler User Guide
|
|
2
|
+
|
|
3
|
+
## Using SDCC
|
|
4
|
+
|
|
5
|
+
### Standard-Compliance range none pageformat default Standard-compliance
|
|
6
|
+
|
|
7
|
+
SDCC aims to be a conforming freestanding implementation of the C programming language. The latest publicly available version of the standard *ISO/IEC 9899 - Programming languages - C* should be available at: https://www.open-std.org/jtc1/sc22/wg14/www/projects#9899.
|
|
8
|
+
|
|
9
|
+
#### ISO C90 and ANSI C89
|
|
10
|
+
|
|
11
|
+
Use --std-c90 range none pageformat default --std-c90** to compile in this mode.
|
|
12
|
+
|
|
13
|
+
Deviations from standard compliance
|
|
14
|
+
|
|
15
|
+
- initialization of structure arrays must be fully braced.
|
|
16
|
+
```c
|
|
17
|
+
struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
|
|
18
|
+
struct s { char x } a[] = {{1}, {2}}; /* OK */
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- float range none pageformat default Floating point support is substituted for (long) double range none pageformat default double (not supported) and a warning is emitted.
|
|
22
|
+
- K&R style range none pageformat default K R style functions are syntactically supported, but with the semantics of ISO style functions.
|
|
23
|
+
Features missing in some ports
|
|
24
|
+
|
|
25
|
+
- pic14, pic16: structures range none pageformat default struct and unions range none pageformat default union cannot be passed as function parameters
|
|
26
|
+
- hc08, s08, mos6502, pic14, pic16: they cannot be a return value range none pageformat default return value from a function, e.g.:
|
|
27
|
+
```c
|
|
28
|
+
struct s {... };
|
|
29
|
+
**struct** s foo1 (**struct** s parms) /* unsupported in these SDCC ports */
|
|
30
|
+
{
|
|
31
|
+
struct s rets;
|
|
32
|
+
...
|
|
33
|
+
return rets; /* unsupported in these SDCC ports */
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- mcs51, ds390, hc08, s08, pdk13, pdk14, pdk15 and mos6502 ports: functions are not reentrant unless explicitly declared as such or --** stack-auto** is specified.
|
|
38
|
+
|
|
39
|
+
#### ISO C94 (aka ISO C95)
|
|
40
|
+
|
|
41
|
+
Use --std-c94 range none pageformat default --std-c94** or --std-c95 range none pageformat default --std-c95** to compile in this mode.
|
|
42
|
+
|
|
43
|
+
Implementation status
|
|
44
|
+
|
|
45
|
+
Except for the issues mentioned in the section above, this standard is supported.
|
|
46
|
+
|
|
47
|
+
#### ISO C99
|
|
48
|
+
|
|
49
|
+
Use --std-c99 range none pageformat default --std-c99** to compile in this mode.
|
|
50
|
+
|
|
51
|
+
Deviations from standard compliance
|
|
52
|
+
|
|
53
|
+
In addition to what is mentioned in the section above, the following features of this standard are not supported by SDCC:
|
|
54
|
+
|
|
55
|
+
- Objects of variably-modified types.
|
|
56
|
+
- ptrdiff_t has 16 bits, while the standard requires at least 17 bits.
|
|
57
|
+
Features missing in some ports
|
|
58
|
+
|
|
59
|
+
- pic14: there is no support for 64 bit integer types.
|
|
60
|
+
|
|
61
|
+
#### ISO C11 and ISO C17
|
|
62
|
+
|
|
63
|
+
Use --std-c11 range none pageformat default --std-c11** to compile in this mode.
|
|
64
|
+
|
|
65
|
+
Implementation status
|
|
66
|
+
|
|
67
|
+
Except for the issues mentioned in the section above, this standard is supported. Note: Variably-modified types became optional in this version.
|
|
68
|
+
|
|
69
|
+
#### ISO C23
|
|
70
|
+
|
|
71
|
+
Use --std-c23 range none pageformat default --std-c23** to compile in this mode.
|
|
72
|
+
|
|
73
|
+
Deviations from standard compliance
|
|
74
|
+
|
|
75
|
+
- initialization of structure arrays must be fully braced.
|
|
76
|
+
```c
|
|
77
|
+
struct s { char x } a[] = {1, 2}; /* invalid in SDCC */
|
|
78
|
+
struct s { char x } a[] = {{1}, {2}}; /* OK */
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
- float range none pageformat default Floating point support is substituted for (long) double range none pageformat default double (not supported) and a warning is emitted.
|
|
82
|
+
- Support for attributes is slightly incomplete.
|
|
83
|
+
- Checked integer arithmetic is not supported for (unsigned) long long.
|
|
84
|
+
- Qualifier-preserving standard library functions are not implemented.
|
|
85
|
+
- constexpr is not implemented.
|
|
86
|
+
Features missing in some ports
|
|
87
|
+
|
|
88
|
+
- pic14, pic16: structures range none pageformat default struct and unions range none pageformat default union cannot be passed as function parameters
|
|
89
|
+
- hc08, s08, mos6502, pic14, pic16: they cannot be a return value range none pageformat default return value from a function, e.g.:
|
|
90
|
+
struct s {... };
|
|
91
|
+
**struct** s foo1 (**struct** s parms) /* unsupported in these SDCC ports */
|
|
92
|
+
{
|
|
93
|
+
struct s rets;
|
|
94
|
+
...
|
|
95
|
+
return rets; /* unsupported in these SDCC ports */
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- mcs51, ds390, hc08, s08, pdk13, pdk14, pdk15 and mos6502 ports: functions are not reentrant unless explicitly declared as such or --** stack-auto** is specified.
|
|
99
|
+
- pic14: there is no support for 64 bit integer types.
|
|
100
|
+
- pic14, pic16: _BitInt is not supported.
|
|
101
|
+
|
|
102
|
+
#### ISO C2y preview
|
|
103
|
+
|
|
104
|
+
Use --std-c2y range none pageformat default --std-c2y** to compile in this mode.
|
|
105
|
+
|
|
106
|
+
Implementation status
|
|
107
|
+
|
|
108
|
+
In anticipation of the upcoming version of the language standard, C2y, SDCC supports the following prospective features:
|
|
109
|
+
|
|
110
|
+
- LatexCommand href name "N3260" target "https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3260.pdf" literal "false": _Generic selection expression with a type operand
|
|
111
|
+
- LatexCommand href name "N3353" target "https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3353.htm" literal "false": Obsolete Octal and Provide New, Proper Escape Sequences
|
|
112
|
+
- LatexCommand href name "N3356" target "https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3356.htm" literal "false": if Declarations
|
|
113
|
+
- LatexCommand href name "N3369" target "https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3369.pdf" literal "false": The _Lengthof Operator (Note: renamed to _Countof following LatexCommand href name "N3469" target "https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3469.htm" literal "false")
|
|
114
|
+
- LatexCommand href name "N3370" target "https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3370.htm" literal "false": Case range expressions
|
|
115
|
+
|
|
116
|
+
#### Embedded C
|
|
117
|
+
|
|
118
|
+
SDCC supports objects in named address spaces and to some degree pointers to such objects. The support for fixed-point math in SDCC is inconsistent with the standard. Other parts of the standard are not supported.
|
|
119
|
+
|
|
120
|
+
#### Implementation-defined behavior
|
|
121
|
+
|
|
122
|
+
##### Translation
|
|
123
|
+
|
|
124
|
+
- Diagnostics are output to stderr, in the format <filename>:<line-number>:
|
|
125
|
+
- Nonempty sequences of white-space are retained in translation phase 3.
|
|
126
|
+
|
|
127
|
+
##### Environment
|
|
128
|
+
|
|
129
|
+
- See SDCC source (and your own code if you use a custom crt0 for a target that supports it) for any information on the environment.
|
|
130
|
+
|
|
131
|
+
##### Identifiers
|
|
132
|
+
|
|
133
|
+
- See the compiler and assembler source for information on characters that may appear in identifiers and on the number of significant initial characters.
|
|
134
|
+
|
|
135
|
+
##### Characters
|
|
136
|
+
|
|
137
|
+
- There are 8 bits in a byte.
|
|
138
|
+
- Values of members of the execution character set: TODO.
|
|
139
|
+
- Values of members of the execution character set for escape sequences: TODO.
|
|
140
|
+
- Value of char with something weird stored in it: TODO.
|
|
141
|
+
- unsigned char has the same range, representation and behavior as" plain" char (unless - -fsigned-char **range none pageformat default --fsigned-char** is used).
|
|
142
|
+
- See the SDCC source for further information on character sets.
|
|
143
|
+
|
|
144
|
+
##### Integers
|
|
145
|
+
|
|
146
|
+
- There are no extended integer types.
|
|
147
|
+
|
|
148
|
+
##### Floating point
|
|
149
|
+
|
|
150
|
+
- See the implementation (soft float library) for any information on floating point.
|
|
151
|
+
|
|
152
|
+
##### Arrays and Pointers
|
|
153
|
+
|
|
154
|
+
- For the result of converting between pointers and integers see the SDCC source code.
|
|
155
|
+
- For the size of the result of subtracting two pointers to elements of the same array see the SDCC source code.
|
|
156
|
+
|
|
157
|
+
##### Hints
|
|
158
|
+
|
|
159
|
+
- The extend to which suggestions made by register are effective depends on the target.
|
|
160
|
+
- SDCC will inline functions if and only if they are declared using inline and do not have variable arguments.
|
|
161
|
+
|
|
162
|
+
##### Structures, unions, enumerations and bit-fields
|
|
163
|
+
|
|
164
|
+
- A plain int bit-field is treated as an unsigned int bit-field.
|
|
165
|
+
- There are no allowed bit-field types other than _Bool, int, signed int, unsigned int and the bit-precise integer types.
|
|
166
|
+
- Atomic types are not permitted for bit-fields.
|
|
167
|
+
- If a bit-fields does not fit into the same byte as the previous bit-fields, it starts on the next byte.
|
|
168
|
+
- bit-fields are allocated in the same order as they appear in the source.
|
|
169
|
+
- Non-bit-field members of structures are aligned on byte boundaries (i.e. there are no padding bytes).
|
|
170
|
+
- For enumerations, the compatible type is the first from the following list that fits the constants: bool, unsigned char, signed char, unsigned int, signed int, unsigned long int, signed long int, unsigned long long int, signed long long int.
|
|
171
|
+
|
|
172
|
+
##### Qualifiers
|
|
173
|
+
|
|
174
|
+
- SDCC shall preserve all volatile reads and writes, but does not guarantee them to be atomic (except for atomic types and volatile sig_atomic_t).
|
|
175
|
+
|
|
176
|
+
##### Preprocessing directives
|
|
177
|
+
|
|
178
|
+
- See the preprocessor source for information on preprocessing directives.
|
|
179
|
+
|
|
180
|
+
##### Library functions
|
|
181
|
+
|
|
182
|
+
- See the respective library headers for the library functions available.
|
|
183
|
+
- See assert.h and library source for the format of the diagnostic printed by the assert macro.
|
|
184
|
+
- There is no fegetexceptflag function.
|
|
185
|
+
- There is no feraiseexcept function.
|
|
186
|
+
- There is no setlocale function.
|
|
187
|
+
- There is no FLT_EVAL_METHOD macro.
|
|
188
|
+
- There is no DEC_EVAL_METHOD macro.
|
|
189
|
+
- There are no non-required domain errors for mathematics functions.
|
|
190
|
+
- See library source for the values returned by mathematical functions on domain error and pole error (and anything else on mathematical functions and floating type encodings).
|
|
191
|
+
- See library headers for the null-pointer constant to which NULL expands.
|
|
192
|
+
- See library headers and source for anything else about the library.
|
|
193
|
+
|
|
194
|
+
##### Architecture
|
|
195
|
+
|
|
196
|
+
- See the respective library headers for the values or expressions for macros specified in float.h, limits.h, stdint.h.
|
|
197
|
+
- Multithreading is not supported.
|
|
198
|
+
- The number of bytes in any object is the minimum allowed (except for some padding bits on bit-fields), byte order depends on the target.
|
|
199
|
+
- No extended alignments are supported.
|
|
200
|
+
- There are no valid alignments other than those returned by _Alignof.
|
|
201
|
+
- sizeof always returns the smallest value allowed assuming an 8-bit char. _Alignof always returns 0.
|
|
202
|
+
|
|
203
|
+
### Compiling
|
|
204
|
+
|
|
205
|
+
#### Single Source File Projects
|
|
206
|
+
|
|
207
|
+
For single source file 8051 projects the process is very simple. Compile your programs with the following command **"sdcc sourcefile.c".** This will compile, assemble and link your source file. Output files are as follows:
|
|
208
|
+
|
|
209
|
+
- sourcefile.asm range none pageformat default- Assembler source range none pageformat default Assembler source file created by the compiler
|
|
210
|
+
- sourcefile.lst range none pageformat default- Assembler listing range none pageformat default Assembler listing file created by the Assembler
|
|
211
|
+
- sourcefile.rst range none pageformat default- Assembler listing range none pageformat default Assembler listing file updated with linkedit information, created by linkage editor
|
|
212
|
+
- sourcefile.sym range none pageformat default- symbol listing range none pageformat default Symbol listing for the sourcefile, created by the assembler
|
|
213
|
+
- sourcefile.rel range none pageformat default- Object file range none pageformat default Object file created by the assembler, input to Linkage editor
|
|
214
|
+
- sourcefile.map range none pageformat default- The memory map range none pageformat default Memory map for the load module, created by the Linker
|
|
215
|
+
- sourcefile.mem range none pageformat default- A file with a summary of the memory usage
|
|
216
|
+
- sourcefile.ihx range none pageformat default- The load module in Intel hex format range none pageformat default Intel hex format (you can select the Motorola S19 format range none pageformat default Motorola S19 format with --out-fmt-s19 range none pageformat default --out-fmt-s19. If you need another format you might want to use *objdump* range none pageformat default objdump (tool) or *srecord* range none pageformat default srecord (bin, hex,... tool) hyperlinks needed- see also section Postprocessing the Intel Hex). Both formats are documented in the documentation of srecord range none pageformat default srecord (bin, hex,... tool)
|
|
217
|
+
- sourcefile.adb range none pageformat default- An intermediate file containing debug information needed to create the.cdb file (with --debug range none pageformat default --debug)
|
|
218
|
+
- sourcefile.cdb range none pageformat default- An optional file (with --debug) containing debug information. The format is documented in cdbfileformat.pdf
|
|
219
|
+
- sourcefile.omf range none pageformat default- An optional AOMF or AOMF51 range none pageformat default AOMF, AOMF51 file containing debug information (generated with option --debug). The (Intel) *a* bsolute *o* bject *m* odule *f* ormat is a subformat of the OMF51 format and is commonly used by third party tools (debuggers range none pageformat default Debugger, simulators, emulators).
|
|
220
|
+
- sourcefile.dump*range none pageformat default- Dump file to debug the compiler it self (generated with option --dumpall) (see section Intermediate Dump Options and section The anatomy of the compiler" Anatomy of the compiler").
|
|
221
|
+
|
|
222
|
+
#### Postprocessing the Intel Hex range none pageformat default Intel hex format file
|
|
223
|
+
|
|
224
|
+
In most cases this won't be needed but the Intel Hex file range none pageformat default which is generated by SDCC might include lines of varying length and the addresses within the file are not guaranteed to be strictly ascending. If your toolchain or a bootloader does not like this you can use the tool packihx range none pageformat default packihx (tool) which is part of the SDCC distribution:
|
|
225
|
+
|
|
226
|
+
**packihx sourcefile.ihx >sourcefile.hex**
|
|
227
|
+
|
|
228
|
+
The separately available *srecord* range none pageformat default srecord (bin, hex,... tool) package additionally allows to set undefined locations to a predefined value, to insert checksums range none pageformat default checksum of various flavours (crc, add, xor) and to perform other manipulations (convert, split, crop, offset,...).
|
|
229
|
+
|
|
230
|
+
**srec_cat sourcefile.ihx -intel-o sourcefile.hex -intel
|
|
231
|
+
|
|
232
|
+
** An example for a more complex command line the command backfills range none pageformat default backfill unused memory unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte block is zero. If the program counter on an mcs51 runs wild the backfill pattern 0x12 will be interpreted as an lcall to address 0x1212 (where an emergency routine could sit). could look like:
|
|
233
|
+
|
|
234
|
+
**srec_cat sourcefile.ihx -intel-fill 0x12 0x0000 0xfffe-little-endian-checksum-negative 0xfffe 0x02 0x02-o sourcefile.hex -intel
|
|
235
|
+
|
|
236
|
+
** The srecord package is available at http://sourceforge.net/projects/srecord/.
|
|
237
|
+
|
|
238
|
+
#### Projects with Multiple Source Files
|
|
239
|
+
|
|
240
|
+
SDCC can compile only ONE file at a time. Let us for example assume that you have a project containing the following files:
|
|
241
|
+
|
|
242
|
+
foo1.c (contains some functions)
|
|
243
|
+
foo2.c (contains some more functions)
|
|
244
|
+
foomain.c (contains more functions and the function main)
|
|
245
|
+
|
|
246
|
+
The first two files will need to be compiled separately with the commands:
|
|
247
|
+
|
|
248
|
+
**sdcc-c foo1.c**
|
|
249
|
+
**sdcc-c foo2.c**
|
|
250
|
+
|
|
251
|
+
Then compile the source file containing the *main()* function and link range none pageformat default Linker the files together with the following command:
|
|
252
|
+
|
|
253
|
+
**sdcc foomain.c foo1.rel foo2.rel** range none pageformat default
|
|
254
|
+
|
|
255
|
+
Note that in this case, the source file being compiled is always linked in first, regardless of its position in the command line. This can be problematic when a custom CRT is supplied as object file. As an alternative to the above, *foomain.c* can be compiled separately, and the resulting object file can then be linked with the other object files using a separate command: **
|
|
256
|
+
|
|
257
|
+
`sdcc-c foomain.c`
|
|
258
|
+
`sdcc foomain.rel foo1.rel foo2.rel`
|
|
259
|
+
|
|
260
|
+
** The file containing the *main()* function must be the first file specified in the command line, since the linkage editor processes object files in the order they are presented to it. The linker is invoked from SDCC using a script file with extension.lnk range none pageformat default. You can view this file to troubleshoot linking problems such as those arising from missing libraries.
|
|
261
|
+
|
|
262
|
+
#### Projects with Additional Libraries range none pageformat default Libraries
|
|
263
|
+
|
|
264
|
+
Some reusable routines may be compiled into a library, see the documentation for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc) for how to create a *.lib range none pageformat default* library file. Section Using sdar to Create and Manage Libraries below contains a minimal example. Libraries created in this manner can be included in the command line. Make sure you include the -L <library-path> option to tell the linker where to look for these files if they are not in the current directory. Here is an example, assuming you have the source file *foomain.c* and a library *foolib.lib* in the directory *mylib* (if that is not the same as your current project):
|
|
265
|
+
|
|
266
|
+
**sdcc foomain.c foolib.lib -L mylib
|
|
267
|
+
|
|
268
|
+
** Note here that *mylib* must be an absolute path name.
|
|
269
|
+
|
|
270
|
+
The most efficient way to use libraries is to keep separate modules in separate source files. The lib file now should name all the modules.rel range none pageformat default files. For an example see the standard library file *libsdcc.lib* in the directory <installdir>/share/lib/small.
|
|
271
|
+
|
|
272
|
+
#### Using sdar to Create and Manage Libraries range none pageformat default sdar
|
|
273
|
+
|
|
274
|
+
Support for sdar format libraries was introduced in SDCC 2.9.0. **
|
|
275
|
+
|
|
276
|
+
** Both the GNU and BSD ar format variants are supported by sdld linkers. **
|
|
277
|
+
|
|
278
|
+
** To create a library containing sdas object files, you should use the following sequence: **
|
|
279
|
+
|
|
280
|
+
**sdar -rc <library name>.lib <list of.rel files>
|
|
281
|
+
|
|
282
|
+
### Command Line Options range none pageformat default Command Line Options
|
|
283
|
+
|
|
284
|
+
#### Processor Selection Options range none pageformat default Options processor selection range none pageformat default Processor selection options
|
|
285
|
+
|
|
286
|
+
**-mmcs51 range none pageformat default -mmcs51** Generate code for the Intel MCS51 range none pageformat default MCS51 family of processors. This is the default processor target.
|
|
287
|
+
|
|
288
|
+
**-mds390 range none pageformat default -mds390** Generate code for the Dallas DS80C390 range none pageformat default DS80C390 processor.
|
|
289
|
+
|
|
290
|
+
**-mds400 range none pageformat default -mds400** Generate code for the Dallas DS80C400 range none pageformat default DS80C400 processor.
|
|
291
|
+
|
|
292
|
+
**-mhc08 range none pageformat default -mhc08** Generate code for the Freescale/Motorola HC08 (aka 68HC08) range none pageformat default HC08 family of processors.
|
|
293
|
+
|
|
294
|
+
**-ms08 range none pageformat default -ms08** Generate code for the Freescale/Motorola S08 (aka 68HCS08, HCS08, CS08) range none pageformat default S08 family of processors.
|
|
295
|
+
|
|
296
|
+
**-mz80 range none pageformat default -mz80** Generate code for the Zilog Z80 range none pageformat default Z80 family of processors.
|
|
297
|
+
|
|
298
|
+
**-mz180 range none pageformat default -mz180** Generate code for the Zilog Z180 range none pageformat default Z180 family of processors.
|
|
299
|
+
|
|
300
|
+
**-mr2k range none pageformat default -mr2k** Generate code for the Rabbit 2000 / Rabbit 3000 family of processors.
|
|
301
|
+
|
|
302
|
+
**-mr3ka range none pageformat default -mr3ka** Generate code for the Rabbit 3000A family of processors.
|
|
303
|
+
|
|
304
|
+
**-msm83 range none pageformat default -msm83** Generate code for the Sharp SM83 range none pageformat default sm83 (GameBoy Z80) processor.
|
|
305
|
+
|
|
306
|
+
**-mtlcs90 range none pageformat default -mtlcs90** Generate code for the Toshiba TLCS-90 processor.
|
|
307
|
+
|
|
308
|
+
**-mez80_z80 range none pageformat default -mez80_z80** Generate code for the Zilog eZ80 processor in Z80 mode.
|
|
309
|
+
|
|
310
|
+
**-mstm8 range none pageformat default -mstm8** Generate code for the STMicroelectronics STM8 family of processors.
|
|
311
|
+
|
|
312
|
+
**-mpdk13 range none pageformat default -mpdk13** Generate code for Padauk processors with 13 bit wide program memory.
|
|
313
|
+
|
|
314
|
+
**-mpdk14 range none pageformat default -mpdk14** Generate code for Padauk processors with 14 bit wide program memory.
|
|
315
|
+
|
|
316
|
+
**-mpdk15 range none pageformat default -mpdk15** Generate code for Padauk processors with 15 bit wide program memory.
|
|
317
|
+
|
|
318
|
+
**-mpic14 range none pageformat default -mpic14** Generate code for the Microchip PIC 14 range none pageformat default PIC14-bit processors (p16f84 and variants. In development, not complete).
|
|
319
|
+
|
|
320
|
+
p16f627 p16f628 p16f84 p16f873 p16f877?
|
|
321
|
+
|
|
322
|
+
**-mpic16 range none pageformat default -mpic16** Generate code for the Microchip PIC 16 range none pageformat default PIC16-bit processors (p18f452 and variants. In development, not complete).
|
|
323
|
+
|
|
324
|
+
**-mmos6502 range none pageformat default -mmos6502** Generate code for the original MOS Technology NMOS 6502 processor and compatible derivatives including the 6510 and 8502.
|
|
325
|
+
|
|
326
|
+
**-mmos65c02 range none pageformat default -mmos65c02** Generate code for the CMOS Rockwell/WDC 65C02.
|
|
327
|
+
|
|
328
|
+
SDCC inspects the program name it was called with so the processor family can also be selected by renaming the sdcc binary (to f.e. z80-sdcc) or by calling SDCC from a suitable link. Option -m has higher priority than setting from program name.
|
|
329
|
+
|
|
330
|
+
#### Preprocessor Options range none pageformat default Options preprocessor range none pageformat default Preprocessor!Options range none pageformat default sdcpp (preprocessor)
|
|
331
|
+
|
|
332
|
+
SDCC uses *sdcpp*, an adapted version of the GNU Compiler Collection range none pageformat default gcc (GNU Compiler Collection) preprocessor *cpp* range none pageformat default cpp|see sdcpp (*gcc* http://gcc.gnu.org/). If you need more dedicated options than those listed below please refer to the GCC CPP Manual at http://www.gnu.org/software/gcc/onlinedocs/.
|
|
333
|
+
|
|
334
|
+
**-I<path> range none pageformat default -I<path>** The additional location where the preprocessor will look for <..h> or“..h” files.
|
|
335
|
+
|
|
336
|
+
**-D<macro[=value]> range none pageformat default -D<macro[=value]>** Command line definition of macros. Passed to the preprocessor.
|
|
337
|
+
|
|
338
|
+
**-M range none pageformat default -M** Tell the preprocessor to output a rule suitable for make describing the dependencies of each object file. For each source file, the preprocessor outputs one make-rule whose target is the object file name for that source file and whose dependencies are all the files `#include'd in it. This rule may be a single line or may be continued with `\ '-newline if it is long. The list of rules is printed on standard output instead of the preprocessed C program. `-M' implies `-E range none pageformat default -E '.
|
|
339
|
+
|
|
340
|
+
**-C range none pageformat default -C** Tell the preprocessor not to discard comments. Used with the `-E' option.
|
|
341
|
+
|
|
342
|
+
**-MM range none pageformat default -MM** Like `-M' but the output mentions only the user header files included with `#include“ file"'. System header files included with `#include <file>' are omitted.
|
|
343
|
+
|
|
344
|
+
**-Aquestion(answer) range none pageformat default -Aquestion(answer)** Assert the answer answer for question, in case it is tested with a preprocessor conditional such as `#if #question(answer)'. `-A-' disables the standard assertions that normally describe the target machine.
|
|
345
|
+
|
|
346
|
+
**-Umacro range none pageformat default -Umacro** Undefine macro macro. `-U' options are evaluated after all `-D' options, but before any `-include' and `-imacros' options.
|
|
347
|
+
|
|
348
|
+
**-dM range none pageformat default -dM** Tell the preprocessor to output only a list of the macro definitions that are in effect at the end of preprocessing. Used with the `-E' option.
|
|
349
|
+
|
|
350
|
+
**-dD range none pageformat default -dD** Tell the preprocessor to pass all macro definitions into the output, in their proper sequence in the rest of the output.
|
|
351
|
+
|
|
352
|
+
**-dN range none pageformat default -dN** Like `-dD' except that the macro arguments and contents are omitted. Only `#define name' is included in the output.
|
|
353
|
+
|
|
354
|
+
**-Wp preprocessorOption[,preprocessorOption]** range none pageformat default -Wp preprocessorOption[,preprocessorOption]... Pass the preprocessorOption to the preprocessor sdcpp range none pageformat default sdcpp (preprocessor).
|
|
355
|
+
|
|
356
|
+
#### Optimization Options range none pageformat default Options optimization range none pageformat default Optimization options
|
|
357
|
+
|
|
358
|
+
**--nogcse range none pageformat default --nogcse** Will not do global common subexpression elimination, this option may be used when the compiler creates undesirably large stack/data spaces to store compiler temporaries (*s* pill *loc* ations, sloc range none pageformat default sloc (spill location)). A warning message will be generated when this happens and the compiler will indicate the number of extra bytes it allocated. It is recommended that this option NOT be used, #pragma nogcse range none pageformat default pragma nogcse can be used to turn off global subexpression elimination range none pageformat default Subexpression elimination for a given function only.
|
|
359
|
+
|
|
360
|
+
**--noinvariant range none pageformat default --noinvariant** Will not do loop invariant optimizations, this may be turned off for reasons explained for the previous option. For more details of loop optimizations performed see Loop Invariants in section Loop Optimizations. It is recommended that this option NOT be used, #pragma noinvariant range none pageformat default pragma noinvariant can be used to turn off invariant optimizations for a given function only.
|
|
361
|
+
|
|
362
|
+
**--noinduction range none pageformat default --noinduction** Will not do loop induction optimizations, see section strength reduction for more details. It is recommended that this option is NOT used, #pragma noinduction range none pageformat default pragma noinduction can be used to turn off induction optimizations for a given function only.
|
|
363
|
+
|
|
364
|
+
**--noloopreverse range none pageformat default --noloopreverse** Will not do loop reversal range none pageformat default Loop reversing optimization.
|
|
365
|
+
|
|
366
|
+
-- **nolabelopt** range none pageformat default --nolabelopt Will not optimize labels (makes the dumpfiles more readable).
|
|
367
|
+
|
|
368
|
+
**--no-xinit-opt range none pageformat default --no-xinit-opt** Will not memcpy initialized data from code space into xdata space. This saves a few bytes in code space if you don't have initialized data range none pageformat default Variable initialization.
|
|
369
|
+
|
|
370
|
+
**--nooverlay range none pageformat default --nooverlay** The compiler will not overlay parameters and local variables of any function, see section Parameters and local variables for more details.
|
|
371
|
+
|
|
372
|
+
**--no-peep range none pageformat default --no-peep** Disable peep-hole optimization with built-in rules.
|
|
373
|
+
|
|
374
|
+
**--peep-file** range none pageformat default --peep-file See section Peephole Optimizer Peep Hole optimizations for details on how to write these rules.
|
|
375
|
+
|
|
376
|
+
**--peep-asm range none pageformat default --peep-asm** Pass the inline assembler code through the peep hole optimizer. This can cause unexpected changes to inline assembler code, please go through the peephole optimizer range none pageformat default Peephole optimizer rules defined in the source file tree '<target>/peeph.def' before using this option.
|
|
377
|
+
|
|
378
|
+
**--peep-return range none pageformat default --peep-return** Let the peep hole optimizer do return optimizations. This is the default without **--** debug **range none pageformat default --debug**.
|
|
379
|
+
|
|
380
|
+
**--no-peep-return range none pageformat default --no-peep-return** Do not let the peep hole optimizer do return optimizations. This is the default with **--** debug **range none pageformat default --debug**.
|
|
381
|
+
|
|
382
|
+
**--opt-code-speed range none pageformat default --opt-code-speed** The compiler will optimize code generation towards fast code, possibly at the expense of code size.
|
|
383
|
+
|
|
384
|
+
**--opt-code-size range none pageformat default --opt-code-size** The compiler will optimize code generation towards compact code, possibly at the expense of code speed.
|
|
385
|
+
|
|
386
|
+
-- **fomit-frame-pointer** range none pageformat default --fomit-frame-pointer Frame pointer will be omitted when the function uses no local variables. On the z80-related ports this option will result in the frame pointer always being omitted.
|
|
387
|
+
|
|
388
|
+
-- **max-allocs-per-node** range none pageformat default --max-allocs-per-node Setting this to a high value will result in increased compilation time (and increased memory use during compilation) and more optimized code being generated. Setting it to lower values speeds up compilation, but does not optimize as much. The default value is 3000. This option currently does not affect the mcs51, ds390, pic14 and pic16 ports.
|
|
389
|
+
|
|
390
|
+
-- **nolospre** range none pageformat default --nolospre Disable lospre. lospre is an advanced redundancy elimination technique, essentially an improved variant of global subexpression elimination.
|
|
391
|
+
|
|
392
|
+
-- **allow-unsafe-read** range none pageformat default --allow-unsafe-read Allow optimizations to generate unsafe reads. This will enable additional optimizations, but can result in spurious reads from undefined memory addresses, which can be harmful if the target system uses certain ways of doing memory-mapped I/O.
|
|
393
|
+
|
|
394
|
+
-- **nostdlibcall** range none pageformat default --nostdlibcall Disable the optimization of calls to the standard library.
|
|
395
|
+
|
|
396
|
+
#### Other Options range none pageformat default Options other
|
|
397
|
+
|
|
398
|
+
**-v--version range none pageformat default --version range none pageformat default -v** displays the sdcc version.
|
|
399
|
+
|
|
400
|
+
**-c--compile-only range none pageformat default --compile-only range none pageformat default -c** will compile and assemble the source, but will not call the linkage editor.
|
|
401
|
+
|
|
402
|
+
**--c1mode range none pageformat default --c1mode** reads the preprocessed source from standard input and compiles it. The file name for the assembler output must be specified using the -o option.
|
|
403
|
+
|
|
404
|
+
**-E range none pageformat default -E** Run only the C preprocessor range none pageformat default Preprocessor. Preprocess all the C source files specified and output the results to standard output.
|
|
405
|
+
|
|
406
|
+
**--syntax-only range none pageformat default --syntax-only** Parse and verify syntax only, no output files are produced.
|
|
407
|
+
|
|
408
|
+
**-o range none pageformat default -o <path/file>** The output path where everything will be placed or the file name used for all generated output files. If the parameter is a path, it must have a trailing slash (or backslash for the Windows binaries) to be recognized as a path. Note for Windows users: if the path contains spaces, it should be surrounded by quotes. The trailing backslash should be doubled in order to prevent escaping the final quote, for example: *-o" F:\ Projects\ test3\ output 1\\"* or put after the final quote, for example: *-o" F:\ Projects\ test3\ output 1"\*. The path using slashes for directory delimiters can be used too, for example: *-o" F:/Projects/test3/output 1/"*.
|
|
409
|
+
|
|
410
|
+
**-x range none pageformat default -x <type>** The specified type overrides the file type that SDCC detected based on the file name extension. The currently supported options are" c"," c-header" and" none". The option" none" restores the default behavior.
|
|
411
|
+
|
|
412
|
+
**--stack-auto range none pageformat default --stack-auto** All functions in the source file will be compiled as *reentrant* range none pageformat default reentrant, i.e. the parameters and local variables will be allocated on the stack range none pageformat default stack. See section Parameters Parameters and Local Variables for more details. If this option is used all source files in the project should be compiled with this option. It automatically implies - -int-long-reent and - -float-reent.
|
|
413
|
+
|
|
414
|
+
**--callee-saves range none pageformat default --callee-saves function1[,function2][,function3]....** The compiler by default uses a caller saves convention for register saving across function calls, however this can cause unnecessary register pushing and popping when calling small functions from larger functions. This option can be used to switch the register saving convention for the function names specified. The compiler will not save registers when calling these functions, no extra code will be generated at the entry and exit (function prologue **range none pageformat default function prologue** and epilogue **range none pageformat default function epilogue**) for these functions to save and restore the registers used by these functions, this can SUBSTANTIALLY reduce code and improve run time performance of the generated code. In the future the compiler (with inter procedural analysis) will be able to determine the appropriate scheme to use for each function call. DO NOT use this option for built-in functions such as _mulint..., if this option is used for a library function the appropriate library function needs to be recompiled with the same option. If the project consists of multiple source files then all the source file should be compiled with the same --callee-saves option string. Also see #pragma callee_saves range none pageformat default pragma callee saves Pragmas.
|
|
415
|
+
|
|
416
|
+
**--all-callee-saves range none pageformat default --all-callee-saves** Function of --callee-saves will be applied to all functions by default.
|
|
417
|
+
|
|
418
|
+
**--debug range none pageformat default --debug** When this option is used the compiler will generate debug information. By default, the debug information collected in a file with.cdb extension can be used with the SDCDB. For more information see documentation for SDCDB. Another file with a.omf extension contains debug information in AOMF or AOMF51 range none pageformat default AOMF, AOMF51 format which is commonly used by third party tools. When --out-gmt-elf is used, the debug information is in DWARF format instead.
|
|
419
|
+
|
|
420
|
+
**-S range none pageformat default -S** Stop after the stage of compilation proper; do not assemble. The output is an assembler code file for the input file specified.
|
|
421
|
+
|
|
422
|
+
**--int-long-reent range none pageformat default --int-long-reent** Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant. Note by default these libraries are compiled as non-reentrant. See section Installation for more details.
|
|
423
|
+
|
|
424
|
+
**--cyclomatic range none pageformat default --cyclomatic** This option will cause the compiler to generate an information message for each function in the source file. The message contains some *important* information about the function. The number of edges and nodes the compiler detected in the control flow graph of the function, and most importantly the *cyclomatic complexity range none pageformat default Cyclomatic complexity* see section on Cyclomatic Complexity for more details.
|
|
425
|
+
|
|
426
|
+
**--float-reent range none pageformat default --float-reent** Floating point library is compiled as reentrant range none pageformat default reentrant. See section Installation for more details.
|
|
427
|
+
|
|
428
|
+
**--fsigned-char range none pageformat default --fsigned-char** By default char is unsigned. To set the signedness for characters to signed, use the option - -fsigned-char. If this option is set and no signedness keyword (unsigned/signed) is given, a char will be unsigned. All other types are unaffected.
|
|
429
|
+
|
|
430
|
+
**--nostdinc range none pageformat default --nostdinc** This will prevent the compiler from passing on the default include path to the preprocessor.
|
|
431
|
+
|
|
432
|
+
**--nostdlib range none pageformat default --nostdlib** This will prevent the compiler from passing on the default library range none pageformat default Libraries path to the linker.
|
|
433
|
+
|
|
434
|
+
**--verbose range none pageformat default --verbose** Shows the various actions the compiler is performing.
|
|
435
|
+
|
|
436
|
+
**-V range none pageformat default -V** Shows the actual commands the compiler is executing.
|
|
437
|
+
|
|
438
|
+
**--no-c-code-in-asm range none pageformat default --no-c-code-in-asm** Hides your ugly and inefficient c-code from the asm file, so you can always blame the compiler:)
|
|
439
|
+
|
|
440
|
+
**--no-peep-comments range none pageformat default --no-peep-comments** Don't include peep-hole comments in the generated asm files even if - -fverbose-asm option is specified.
|
|
441
|
+
|
|
442
|
+
**--i-code-in-asm range none pageformat default --i-code-in-asm** Include i-codes in the asm file. Sounds like noise but is helpful for debugging the compiler itself.
|
|
443
|
+
|
|
444
|
+
**--less-pedantic range none pageformat default pedantic range none pageformat default --less-pedantic** Disable some of the more pedantic warnings range none pageformat default Warnings. For more details, see the less_pedantic pragma Pragmas.
|
|
445
|
+
|
|
446
|
+
**--disable-warning range none pageformat default --disable-warning** Disable specific warning with number <nnnn>.
|
|
447
|
+
|
|
448
|
+
**--Werror range none pageformat default --Werror** Treat all warnings as errors.
|
|
449
|
+
|
|
450
|
+
**--print-search-dirs range none pageformat default --print-search-dirs** Display the directories in the compiler's search path
|
|
451
|
+
|
|
452
|
+
**--vc range none pageformat default --vc** Display errors and warnings using MSVC style, so you can use SDCC with the visual studio IDE range none pageformat default IDE. With SDCC both offering a GCC-like (the default) and a MSVC-like range none pageformat default MSVC output style output style, integration into most programming editors should be straightforward.
|
|
453
|
+
|
|
454
|
+
**--use-stdout range none pageformat default --use-stdout** Send errors and warnings to stdout instead of stderr.
|
|
455
|
+
|
|
456
|
+
**-Wa asmOption[,asmOption]** range none pageformat default -Wa asmOption[,asmOption]... Pass the asmOption to the assembler range none pageformat default Options assembler range none pageformat default Assembler options. See file sdcc/sdas/doc/asmlnk.txt for assembler options.cd
|
|
457
|
+
|
|
458
|
+
**--std-<arg>** Determine the language standard. For enhanced compatibility with other compilers, **--std** can also be used with a single dash (i.e. **-std**) and with **=** or (whitespace) as delimiter. The language standard, specified via , can be one of the following:
|
|
459
|
+
|
|
460
|
+
**c90 range none pageformat default --std-c89** Follow the ISO/IEC 9899 First Edition standard (ANSI C89 / ISO C90). Alternative spellings: **c89**, **iso9899:1990
|
|
461
|
+
|
|
462
|
+
**c94 range none pageformat default --std-sdcc99** Follow the ISO/IEC 9899 First Edition standard as modified in amendment 1. Alternative spelling: **c95, iso9899:199409
|
|
463
|
+
|
|
464
|
+
**c99 range none pageformat default --std-sdcc99** Follow the ISO/IEC 9899 Second Edition standard (ISO C99). Alternative spelling: **iso9899:1999
|
|
465
|
+
|
|
466
|
+
**c11 range none pageformat default --std-sdcc11** Follow the ISO/IEC 9899 Third Edition standard (ISO C11). Alternative spelling: **iso9899:2011
|
|
467
|
+
|
|
468
|
+
**c17 range none pageformat default --std-sdcc17** Follow the ISO/IEC 9899 Fourth Edition standard (ISO C17). Alternative spellings: **iso9899:2017**, **c18**, **iso9899:2018
|
|
469
|
+
|
|
470
|
+
**c23 range none pageformat default --std-sdcc23** Follow the ISO/IEC 9899 Fifth Edition standard (ISO C23). Alternative spelling: **c2x
|
|
471
|
+
|
|
472
|
+
**c2y range none pageformat default --std-sdcc2y** Enable features anticipated for the Sixth Edition standard (currently abbreviated ISO C2y).
|
|
473
|
+
|
|
474
|
+
**sdcc90 range none pageformat default --std-sdcc89** Generally follow ANSI C89 / ISO C90, but allow some SDCC behaviour that conflicts with the standard. Alternative spelling: **sdcc89
|
|
475
|
+
|
|
476
|
+
**sdcc99 range none pageformat default --std-sdcc99** Generally follow ISO C99, but allow some SDCC behaviour that conflicts with the standard.
|
|
477
|
+
|
|
478
|
+
**sdcc11 range none pageformat default --std-sdcc11** Generally follow ISO C11, but allow some SDCC behaviour that conflicts with the standard (default).
|
|
479
|
+
|
|
480
|
+
**sdcc17 range none pageformat default --std-sdcc17** Generally follow ISO C17, but allow some SDCC behaviour that conflicts with the standard. Alternative spelling: **sdcc18
|
|
481
|
+
|
|
482
|
+
**sdcc23 range none pageformat default --std-sdcc23** Generally follow ISO C23, but allow some SDCC behaviour that conflicts with the standard. Alternative spelling: **sdcc2x
|
|
483
|
+
|
|
484
|
+
**sdcc2y range none pageformat default --std-sdcc2y** Generally follow ISO C2y, but allow some SDCC behaviour that conflicts with the standard.
|
|
485
|
+
|
|
486
|
+
**--codeseg** range none pageformat default --codeseg <Value> range none pageformat default code segment, default CSEG. This is useful if you need to tell the compiler to put the code in a special segment so you can later on tell the linker to put this segment in a special place in memory. Can be used for instance when using bank switching to put the code in a bank.
|
|
487
|
+
|
|
488
|
+
**--constseg** range none pageformat default --constseg <Value> range none pageformat default const segment, default CONST. This is useful if you need to tell the compiler to put the const data in a special segment so you can later on tell the linker to put this segment in a special place in memory. Can be used for instance when using bank switching to put the const data in a bank.
|
|
489
|
+
|
|
490
|
+
**--fdollars-in-identifiers range none pageformat default --fdollars-in-identifiers** Permit '$' as an identifier character.
|
|
491
|
+
|
|
492
|
+
**--more-pedantic** range none pageformat default --more-pedantic range none pageformat default pedantic Actually this is *not* a SDCC compiler option but if you want *more* warnings you can use a separate tool dedicated to syntax checking like splint range none pageformat default lint (syntax checking tool) http://www.splint.org. To make your source files parseable by splint you will have to include lint.h range none pageformat default splint (syntax checking tool) in your source file and add brackets around extended keywords (like" __at **(** 0xab **)** " and" __interrupt (2)").
|
|
493
|
+
Splint has an excellent on line manual at http://www.splint.org/manual/ and it's capabilities go beyond pure syntax checking. You'll need to tell splint the location of SDCC's include files so a typical command line could look like this:
|
|
494
|
+
splint-I /usr/local/share/sdcc/include/mcs51/ myprogram.c
|
|
495
|
+
|
|
496
|
+
**--use-non-free** range none pageformat default --use-non-free Search / include non-free licensed libraries and header files, located under the non-free directory - see section Search Paths
|
|
497
|
+
|
|
498
|
+
#### Linker Options range none pageformat default Options linker range none pageformat default Linker options
|
|
499
|
+
|
|
500
|
+
**--lib-path range none pageformat default --lib-path <path>** range none pageformat default Libraries search path. The path name must be absolute. Additional library files may be specified in the command line. See section Compiling programs for more details.
|
|
501
|
+
|
|
502
|
+
**-L range none pageformat default -L <path>**
|
|
503
|
+
|
|
504
|
+
**--xram-loc** range none pageformat default --xram-loc <Value> range none pageformat default xdata (mcs51, ds390 named address space), default value is 0. The value entered can be in Hexadecimal or Decimal format, e.g.:--xram-loc 0x8000 or --xram-loc 32768.
|
|
505
|
+
|
|
506
|
+
**--code-loc** range none pageformat default --code-loc <Value> range none pageformat default code segment, default value 0. Note when this option is used the interrupt vector table range none pageformat default interrupt vector table is also relocated to the given address. The value entered can be in Hexadecimal or Decimal format, e.g.:--code-loc 0x8000 or --code-loc 32768.
|
|
507
|
+
|
|
508
|
+
**--stack-loc** range none pageformat default --stack-loc <Value> e.g.--stack-loc 0x20 or --stack-loc 32.
|
|
509
|
+
|
|
510
|
+
For stm8, by default the stack is placed at the device-specific reset value. By using this option, the stack can be placed anywhere in the lower 16-bits of the stm8 memory space. This is particularly useful for working around the stack roll-over antifeature present in some stm8 devices.
|
|
511
|
+
|
|
512
|
+
**--xstack-loc** range none pageformat default --xstack-loc <Value> range none pageformat default xstack is placed after the __pdata range none pageformat default pdata (mcs51, ds390 named address space) segment. Using this option the xstack can be placed anywhere in the external memory space of the 8051. The value entered can be in Hexadecimal or Decimal format, e.g.--xstack-loc 0x8000 or --xstack-loc 32768. The provided value should not overlap any other memory areas such as the pdata or xdata segment and with enough space for the current application.
|
|
513
|
+
|
|
514
|
+
**--data-loc** range none pageformat default --data-loc <Value> range none pageformat default data (mcs51, ds390 named address space) segment. The value entered can be in Hexadecimal or Decimal format, eg.--data-loc 0x20 or --data-loc 32. (By default, the start location of the internal ram data segment is set as low as possible in memory, taking into account the used register banks and the bit segment at address 0x20. For example if register banks 0 and 1 are used without bit variables, the data segment will be set, if --data-loc is not used, to location 0x10.)
|
|
515
|
+
|
|
516
|
+
**--idata-loc** range none pageformat default --idata-loc <Value> range none pageformat default idata (mcs51, ds390 named address space) of the 8051, default value is 0x80. The value entered can be in Hexadecimal or Decimal format, eg.--idata-loc 0x88 or --idata-loc 136.
|
|
517
|
+
|
|
518
|
+
**--bit-loc** range none pageformat default bit addressable internal ram of the 8051. This is *not* implemented yet. Instead an option can be passed directly to the linker:-Wl-bBSEG=<Value>.
|
|
519
|
+
|
|
520
|
+
**--out-fmt-ihx range none pageformat default --out-fmt-ihx** The linker output (final object code) is in Intel Hex format. range none pageformat default Intel hex format This is the default option. The format itself is documented in the documentation of srecord range none pageformat default srecord (bin, hex,... tool).
|
|
521
|
+
|
|
522
|
+
**--out-fmt-s19 range none pageformat default --out-fmt-s19** The linker output (final object code) is in Motorola S19 format range none pageformat default Motorola S19 format. The format itself is documented in the documentation of srecord.
|
|
523
|
+
|
|
524
|
+
**--out-fmt-elf range none pageformat default --out-fmt-s19 range none pageformat default HC08!Options!--out-fmt-elf** The linker output (final object code) is in ELF format range none pageformat default ELF format. (Currently only supported for the HC08 range none pageformat default HC08, S08 and STM8 processors). When used with --debug, the debug info is in DWARF format instead of CDB.
|
|
525
|
+
|
|
526
|
+
**-Wl linkOption[,linkOption]** range none pageformat default -Wl linkOption[,linkOption]... Pass the linkOption to the linker. If a bootloader is used an option like"-Wl-bCSEG=0x1000" would be typical to set the start of the code segment. Either use the double quotes around this option or use no space (e.g.-Wl-bCSEG=0x1000). See also #pragma constseg and #pragma codeseg in section Pragmas. File sdcc/sdas/doc/asmlnk.txt has more on linker options.
|
|
527
|
+
|
|
528
|
+
#### MCS51 Options range none pageformat default Options MCS51 range none pageformat default MCS51 options
|
|
529
|
+
|
|
530
|
+
**--model-small range none pageformat default --model-small** Generate code for Small model programs, see section Memory Models for more details. This is the default model.
|
|
531
|
+
|
|
532
|
+
**--model-medium range none pageformat default --model-medium** Generate code for Medium model programs, see section Memory Models for more details. If this option is used all source files in the project have to be compiled with this option. It must also be used when invoking the linker.
|
|
533
|
+
|
|
534
|
+
**--model-large range none pageformat default --model-large** Generate code for Large model programs, see section Memory Models for more details. If this option is used all source files in the project have to be compiled with this option. It must also be used when invoking the linker.
|
|
535
|
+
|
|
536
|
+
**--model-huge range none pageformat default --model-huge** Generate code for Huge model programs, see section Memory Models for more details. If this option is used all source files in the project have to be compiled with this option. It must also be used when invoking the linker.
|
|
537
|
+
|
|
538
|
+
**--xstack range none pageformat default --xstack** Uses a pseudo stack in the __pdata range none pageformat default pdata (mcs51, ds390 named address space) area (usually the first 256 bytes in the external ram) for allocating variables and passing parameters. See section External Stack External Stack for more details.
|
|
539
|
+
|
|
540
|
+
**--iram-size** range none pageformat default --iram-size <Value> Causes the linker to check if the internal ram usage is within limits of the given value.
|
|
541
|
+
|
|
542
|
+
**--xram-size** range none pageformat default --xram-size <Value> Causes the linker to check if the external ram usage is within limits of the given value.
|
|
543
|
+
|
|
544
|
+
**--code-size** range none pageformat default --code-size <Value> Causes the linker to check if the code memory usage is within limits of the given value.
|
|
545
|
+
|
|
546
|
+
**--stack-size** range none pageformat default --stack-size <Value> Causes the linker to check if there is at minimum <Value> bytes for stack.
|
|
547
|
+
|
|
548
|
+
**--acall-ajmp** range none pageformat default --acall-ajmp Replaces the three byte instructions lcall/ljmp with the two byte instructions acall/ajmp. Only use this option if your code is in the same 2k block of memory. You may need to use this option for some 8051 derivatives which lack the lcall/ljmp instructions.
|
|
549
|
+
|
|
550
|
+
**--no-ret-without-call** range none pageformat default --no-ret-without-call Causes the code generator to insert an extra lcall or acall instruction whenever it needs to use a ret instruction in a context other than a function returning. This option is needed when using the Infineon range none pageformat default Infineon XC800 series microcontrollers to keep its Memory Extension Stack balanced.
|
|
551
|
+
|
|
552
|
+
#### DS390 / DS400 Options range none pageformat default Options DS390 range none pageformat default DS390
|
|
553
|
+
|
|
554
|
+
**--model-flat24** range none pageformat default DS390!Options!--model-flat24 Generate 24-bit flat mode code. This is the one and only that the ds390 code generator supports right now and is default when using *-mds390*. See section Memory Models for more details.
|
|
555
|
+
|
|
556
|
+
**--protect-sp-update range none pageformat default DS390!Options!--protect-sp-update** disable interrupts during ESP:SP updates.
|
|
557
|
+
|
|
558
|
+
**--stack-8-bit - switches off the 10-bit mode
|
|
559
|
+
|
|
560
|
+
**--stack-10bit** range none pageformat default DS390!Options!--stack-10bit Generate code for the 10 bit stack mode of the Dallas DS80C390 part. This is the one and only that the ds390 code generator supports right now and is default when using *-mds390*. In this mode, the stack is located in the lower 1K of the internal RAM, which is mapped to 0x400000. Note that the support is incomplete, since it still uses a single byte as the stack pointer. This means that only the lower 256 bytes of the potential 1K stack space will actually be used. However, this does allow you to reclaim the precious 256 bytes of low RAM for use for the DATA and IDATA segments. The compiler will not generate any code to put the processor into 10 bit stack mode. It is important to ensure that the processor is in this mode before calling any re-entrant functions compiled with this option. In principle, this should work with the *--stack-auto range none pageformat default --stack-auto* option, but that has not been tested. It is incompatible with the *--xstack range none pageformat default --xstack* option. It also only makes sense if the processor is in 24 bit contiguous addressing mode (see the *--model-flat24 option*). **
|
|
561
|
+
|
|
562
|
+
**--stack-probe range none pageformat default DS390!Options!--stack-probe** insert call to function __stack_probe at each function prologue.
|
|
563
|
+
|
|
564
|
+
**--tini-libid range none pageformat default DS390!Options!--tini-libid**
|
|
565
|
+
|
|
566
|
+
**--use-accelerator range none pageformat default DS390!Options!--use-accelerator** generate code for DS390 Arithmetic Accelerator.
|
|
567
|
+
|
|
568
|
+
#### Options common to all z80-related ports (z80, z180, r2k, r3ka, sm83, tlcs90, ez80_z80)
|
|
569
|
+
|
|
570
|
+
**--no-std-crt0** range none pageformat default Z80!Options!--no-std-crt0 When linking, skip the standard crt0.rel object file. You must provide your own crt0.rel for your system when linking.
|
|
571
|
+
|
|
572
|
+
**--callee-saves-bc** range none pageformat default Z80!Options!--callee-saves-bc Force a called function to always save BC.
|
|
573
|
+
|
|
574
|
+
**--codeseg** range none pageformat default Z80!Options!--codeseg <Value> Use <Value> for the code segment name.
|
|
575
|
+
|
|
576
|
+
**--constseg** range none pageformat default Z80!Options!--constseg <Value> Use <Value> for the const segment name.
|
|
577
|
+
|
|
578
|
+
#### Z80 Options range none pageformat default Options Z80 range none pageformat default Z80 (apply to z80, z180, r2k, r3ka, tlcs90, ez80_z80)
|
|
579
|
+
|
|
580
|
+
**--portmode=** range none pageformat default Z80!Options!--portmode=<Value> Determinate PORT I/O mode (<Value> is z80 or z180).
|
|
581
|
+
|
|
582
|
+
**--asm=** range none pageformat default Z80!Options!--asm=<Value> Define assembler name (<Value> is rgbds, sdasz80, isas or z80asm).
|
|
583
|
+
|
|
584
|
+
**--reserve-regs-iy** range none pageformat default Z80!Options!--reserve-regs-iy This option tells the compiler that it is not allowed to use register pair iy. The option can be useful for systems where iy is reserved for the OS. This option is incompatible with --fomit-frame-pointer.
|
|
585
|
+
|
|
586
|
+
**--fno-omit-frame-pointer** range none pageformat default Z80!Options!--fno-omit-frame-pointer Never omit the frame pointer.
|
|
587
|
+
|
|
588
|
+
#### SM83 Options range none pageformat default Options GBZ80 range none pageformat default SM83
|
|
589
|
+
|
|
590
|
+
**-bo** range none pageformat default GBZ80!Options!-bo <Num> Use code bank <Num>.
|
|
591
|
+
|
|
592
|
+
**-ba** range none pageformat default GBZ80!Options!-ba <Num> Use data bank <Num>.
|
|
593
|
+
|
|
594
|
+
#### STM8 Options range none pageformat default Options STM8 range none pageformat default STM8 options
|
|
595
|
+
|
|
596
|
+
**--model-medium range none pageformat default --model-medium** Generate code for Medium model programs, see section Memory Models for more details. This is the default model.
|
|
597
|
+
|
|
598
|
+
**--model-large range none pageformat default --model-large** Generate code for Large model programs, see section Memory Models for more details. If this option is used all source files in the project have to be compiled with this option. It must also be used when invoking the linker.
|
|
599
|
+
|
|
600
|
+
#### MOS6502 Options range none pageformat default Options MOS6502 range none pageformat default MOS6502 options (apply to mos6502, mos65c02)
|
|
601
|
+
|
|
602
|
+
**--model-small range none pageformat default --model-small** Generate code for small model programs, see section Memory Models for more details.
|
|
603
|
+
|
|
604
|
+
**--model-large range none pageformat default --model-large** Generate code for large model programs, see section Memory Models for more details. This is the default memory model.
|
|
605
|
+
|
|
606
|
+
**--no-zp-spill range none pageformat default --no-zp-spill** Force the compiler to spill registers to 16-bit addressable memory (xdata) instead of Page Zero. When running out of Page Zero space, this option will allow to free many Page Zero locations at the expense of slightly larger and slower code
|
|
607
|
+
|
|
608
|
+
#### Intermediate Dump Options range none pageformat default Options intermediate dump range none pageformat default Intermediate dump options
|
|
609
|
+
|
|
610
|
+
The following options are provided for the purpose of retargetting and debugging the compiler. They provide a means to dump the intermediate code (iCode range none pageformat default iCode) generated by the compiler in human readable form at various stages of the compilation process. More on iCodes see chapter The anatomy of the compiler" The anatomy of the compiler".
|
|
611
|
+
|
|
612
|
+
**--dum-ast range none pageformat default --dump-ast** This option will cause the compiler to dump the abstract syntax tree to the econsole.
|
|
613
|
+
|
|
614
|
+
**--dump-i-code range none pageformat default --dump-i-code** Will dump iCodes at various stages into files named **.
|
|
615
|
+
|
|
616
|
+
**--dump-graphs range none pageformat default --dump-graphs** Will dump internal representations as graphviz.dot files. Depending on other options, this can include the control-flow graph at lospre, insertion of bank selection instructions or register allocation and the conflict graph and tree-decomposition at register allocation.
|
|
617
|
+
|
|
618
|
+
**--fverbose-asm range none pageformat default --no-gen-comments** Include code generator and peep-hole comments in the generated asm files.
|
|
619
|
+
|
|
620
|
+
#### Redirecting output on Windows Shells
|
|
621
|
+
|
|
622
|
+
By default SDCC writes its error messages to" standard error". To force all messages to" standard output" use **-* ***-** use-stdout range none pageformat default --use-stdout. Additionally, if you happen to have visual studio installed in your Windows machine, you can use it to compile your sources using a custom build and the SDCC - **-vc range none pageformat default --vc option. Something like this should work:
|
|
623
|
+
|
|
624
|
+
`c:\ sdcc\ bin\ sdcc.exe -* ***-vc -* ***-model-large -c $(InputPath)`
|
|
625
|
+
|
|
626
|
+
### Environment variables range none pageformat default Environment variables
|
|
627
|
+
|
|
628
|
+
SDCC recognizes the following environment variables:
|
|
629
|
+
|
|
630
|
+
**SDCC_LEAVE_SIGNALS range none pageformat default SDCC!Environment variables!SDCC LEAVE SIGNALS** SDCC installs a signal handler range none pageformat default signal handler to be able to delete temporary files after an user break (^C) or an exception. If this environment variable is set, SDCC won't install the signal handler in order to be able to debug SDCC.
|
|
631
|
+
|
|
632
|
+
**TMP, TEMP, TMPDIR range none pageformat default SDCC!Environment variables!TMP, TEMP, TMPDIR** Path, where temporary files will be created. The order of the variables is the search order. In a standard *nix environment these variables are not set, and there's no need to set them. On Windows it's recommended to set one of them.
|
|
633
|
+
|
|
634
|
+
**SDCC_HOME range none pageformat default SDCC!Environment variables!SDCC HOME** Path, see section Install paths" Install Paths".
|
|
635
|
+
|
|
636
|
+
**SDCC_INCLUDE range none pageformat default SDCC!Environment variables!SDCC INCLUDE** Path, see section Search Paths" Search Paths".
|
|
637
|
+
|
|
638
|
+
**SDCC_LIB range none pageformat default SDCC!Environment variables!SDCC LIB** Path, see section Search Paths" Search Paths"..
|
|
639
|
+
|
|
640
|
+
There are some more environment variables recognized by SDCC, but these are mainly used for debugging purposes. They can change or disappear very quickly, and won't be documented if you are curious search in SDCC's sources for" getenv" range none pageformat default SDCC!Environment variables!undocumented.
|
|
641
|
+
|
|
642
|
+
### SDCC Language Extensions
|
|
643
|
+
|
|
644
|
+
SDCC supports some language extensions useful for embedded systems. These include named address spaces (see also section 5.1 of the Embedded C standard). SDCC supports both intrinsic named address spaces (which ones are supported depends on the target architecture) and non-intrinsic named address spaces (defined by the user using the keyword __addressmod, they are particularly useful with custom bank-switching hardware). Unlike the Embedded C standard, SDCC allows local variables to have an intrinsic named address space even when not explicitly declared as static or extern. Depending on the target architecture, support can be limited to objects in such address spaces and exclude pointer-based access to those.
|
|
645
|
+
|
|
646
|
+
#### MCS51/DS390 intrinsic named address spaces
|
|
647
|
+
|
|
648
|
+
SDCC supports the following MCS51-specific intrinsic address spaces:
|
|
649
|
+
|
|
650
|
+

|
|
651
|
+
|
|
652
|
+
##### __data range none pageformat default data (mcs51, ds390 named address space) / __near range none pageformat default near (named address space)
|
|
653
|
+
|
|
654
|
+
This is the **default** (generic) address space for the Small Memory model. Variables in this address space will be allocated in the directly addressable portion of the internal RAM of a 8051, e.g.:
|
|
655
|
+
|
|
656
|
+
__data unsigned char test_data;
|
|
657
|
+
|
|
658
|
+
Writing 0x01 to this variable generates the assembly code:
|
|
659
|
+
|
|
660
|
+
75*00 01 mov _test_data,#0x01
|
|
661
|
+
|
|
662
|
+
##### __xdata range none pageformat default xdata (mcs51, ds390 named address space) / __far range none pageformat default far (named address space)
|
|
663
|
+
|
|
664
|
+
Variables in this address space will be placed in the external RAM. This is the **default** (generic) address space for the Large Memory model, e.g.:
|
|
665
|
+
|
|
666
|
+
__xdata unsigned char test_xdata;
|
|
667
|
+
|
|
668
|
+
Writing 0x01 to this variable generates the assembly code:
|
|
669
|
+
|
|
670
|
+
90s00r00 mov dptr,#_test_xdata
|
|
671
|
+
74 01 mov a,#0x01
|
|
672
|
+
F0 movx @dptr,a
|
|
673
|
+
|
|
674
|
+
##### __idata range none pageformat default idata (mcs51, ds390 named address space)
|
|
675
|
+
|
|
676
|
+
Variables in this address space will be allocated into the indirectly addressable portion of the internal ram of a 8051, e.g.:
|
|
677
|
+
|
|
678
|
+
`__idata unsigned char test_idata;`
|
|
679
|
+
|
|
680
|
+
Writing 0x01 to this variable generates the assembly code:
|
|
681
|
+
|
|
682
|
+
```
|
|
683
|
+
78r00 mov r0,#_test_idata
|
|
684
|
+
76 01 mov @r0,#0x01
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
Please note, the first 128 byte of idata physically access the same RAM as the data memory. The original 8051 had 128 byte idata memory, nowadays most devices have 256 byte idata memory. The stack range none pageformat default stack is located in idata memory (unless --xstack is specified).
|
|
688
|
+
|
|
689
|
+
##### __pdata range none pageformat default pdata (mcs51, ds390 named address space)
|
|
690
|
+
|
|
691
|
+
Paged xdata access is just as straightforward as using the other addressing modes of a 8051. It is typically located at the start of xdata and has a maximum size of 256 bytes. The following example writes 0x01 to the pdata variable. Please note, pdata access physically accesses xdata memory. The high byte of the address is determined by port P2 range none pageformat default P2 (mcs51 sfr) (or in case of some 8051 variants by a separate Special Function Register, see section MCS51 variants). This is the **default** (generic) address space for the Medium Memory model, e.g.:
|
|
692
|
+
|
|
693
|
+
`__pdata unsigned char test_pdata;`
|
|
694
|
+
|
|
695
|
+
Writing 0x01 to this variable generates the assembly code:
|
|
696
|
+
```
|
|
697
|
+
78r00 mov r0,#_test_pdata
|
|
698
|
+
74 01 mov a,#0x01
|
|
699
|
+
F2 movx @r0,a
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
If the --xstack range none pageformat default --xstack option is used the pdata memory area is followed by the xstack memory area and the sum of their sizes is limited to 256 bytes.
|
|
703
|
+
|
|
704
|
+
##### __code range none pageformat default code
|
|
705
|
+
|
|
706
|
+
'Variables' in this address space will be placed in the code memory:
|
|
707
|
+
|
|
708
|
+
`__code unsigned char test_code;`
|
|
709
|
+
|
|
710
|
+
Read access to this variable generates the assembly code:
|
|
711
|
+
```
|
|
712
|
+
90s00r6F mov dptr,#_test_code
|
|
713
|
+
E4 clr a
|
|
714
|
+
93 movc a,@a+dptr
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
char indexed arrays of characters in code memory can be accessed efficiently:
|
|
718
|
+
|
|
719
|
+
`__code char test_array[] = {'c','h','e','a','p'};`
|
|
720
|
+
|
|
721
|
+
Read access to this array using an 8-bit unsigned index generates the assembly code:
|
|
722
|
+
```
|
|
723
|
+
E5*00 mov a,_index
|
|
724
|
+
|
|
725
|
+
90s00r41 mov dptr,#_test_array
|
|
726
|
+
|
|
727
|
+
93 movc a,@a+dptr
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
##### __bit range none pageformat default bit
|
|
731
|
+
|
|
732
|
+
This is a data-type and an address space. When a variable is declared as a bit, it is allocated into the bit addressable memory of 8051, e.g.:
|
|
733
|
+
|
|
734
|
+
`__bit test_bit;`
|
|
735
|
+
|
|
736
|
+
Writing 1 to this variable generates the assembly code:
|
|
737
|
+
```
|
|
738
|
+
D2*00 setb _test_bit
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
The bit addressable memory consists of 128 bits which are located from 0x20 to 0x2f in data memory.
|
|
742
|
+
Apart from this 8051 specific intrinsic named address space most architectures support ANSI-C bit-fields range none pageformat default bit-fields Not really meant as examples, but nevertheless showing what bit-fields are about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c. In accordance with ISO/IEC 9899 bits and bitfields without an explicit signed modifier are implemented as unsigned.
|
|
743
|
+
|
|
744
|
+
##### __sfr range none pageformat default sfr / __sfr16 range none pageformat default sfr16 / __sfr32 range none pageformat default sfr32 / __sbit range none pageformat default sbit
|
|
745
|
+
|
|
746
|
+
Like the __bit keyword, *__sfr / __sfr16 / __sfr32 / __sbit* signify both a data-type and named address space, they are used to describe the *s* pecial *f* unction *r* egisters and special *__bit* variables of a 8051, eg:
|
|
747
|
+
```c
|
|
748
|
+
__sfr __at range none pageformat default at (0x80) P0; /* special function register P0 at location 0x80 */
|
|
749
|
+
|
|
750
|
+
/* 16 bit special function register combination for timer 0
|
|
751
|
+
with the high byte at location 0x8C and the low byte at location 0x8A */
|
|
752
|
+
__sfr16 __at (0x8C8A) TMR0;
|
|
753
|
+
|
|
754
|
+
__sbit __at range none pageformat default at (0xd7) CY; /* CY (Carry Flag range none pageformat default Flags range none pageformat default Carry flag) */
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
Special function registers which are located on an address dividable by 8 are bit-addressable, an *__sbit* addresses a specific bit within these sfr.
|
|
758
|
+
16 Bit and 32 bit special function register combinations which require a certain access order are better not declared using *__sfr16* or *__sfr32.* Although SDCC usually accesses them Least Significant Byte (LSB) first, this is not guaranteed.
|
|
759
|
+
|
|
760
|
+
Please note, if you use a header file which was written for another compiler then the __sfr / __sfr16 / __sfr32 / __sbit intrinsic named address spaces will most likely be *not* compatible. Specifically the syntax sfr P0 = 0x80; is compiled *without warning* by SDCC to an assignment of 0x80 to a variable called P0. **Nevertheless with the file compiler.h range none pageformat default compiler.h (include file) it is possible to write header files range none pageformat default Header files range none pageformat default Include files which can be shared among different compilers (see section Porting code from or to other compilers).
|
|
761
|
+
|
|
762
|
+
##### Pointers range none pageformat default Pointer to MCS51/DS390 intrinsic named address spaces
|
|
763
|
+
|
|
764
|
+
SDCC allows (via language extensions) pointers to explicitly point to any of the named address spaces range none pageformat default Memory model of the 8051. In addition to the explicit pointers, the compiler uses (by default) generic pointers which can be used to point to any of the memory spaces.
|
|
765
|
+
|
|
766
|
+
Pointer declaration examples:
|
|
767
|
+
```c
|
|
768
|
+
/* pointer physically in internal ram pointing to object in external ram */
|
|
769
|
+
__xdata unsigned char * __data p;
|
|
770
|
+
|
|
771
|
+
/* pointer physically in external ram pointing to object in internal ram */
|
|
772
|
+
__data unsigned char * __xdata p;
|
|
773
|
+
|
|
774
|
+
/* pointer physically in code rom pointing to data in xdata space */
|
|
775
|
+
__xdata unsigned char * __code p;
|
|
776
|
+
|
|
777
|
+
/* pointer physically in code space pointing to data in code space */
|
|
778
|
+
__code unsigned char * __code p;
|
|
779
|
+
|
|
780
|
+
/* generic pointer physically located in xdata space */
|
|
781
|
+
unsigned char * __xdata p;
|
|
782
|
+
|
|
783
|
+
/* generic pointer physically located in default memory space */
|
|
784
|
+
unsigned char * p;
|
|
785
|
+
|
|
786
|
+
/* the following is a function pointer range none pageformat default function pointer physically located in data space */
|
|
787
|
+
char (* __data fp)(void);
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
Well you get the idea.
|
|
791
|
+
|
|
792
|
+
All unqualified pointers are treated as 3-byte (4-byte for the ds390) *generic* pointers.
|
|
793
|
+
|
|
794
|
+
The highest order byte of the *generic* pointers contains the data space information. Assembler support routines are called whenever data is stored or retrieved using *generic* pointers. These are useful for developing reusable library range none pageformat default Libraries routines. Explicitly specifying the pointer range none pageformat default Pointer type will generate the most efficient code.
|
|
795
|
+
|
|
796
|
+
##### Notes on MCS51 memory range none pageformat default MCS51 memory layout
|
|
797
|
+
|
|
798
|
+
The 8051 family of microcontrollers have a minimum of 128 bytes of internal RAM memory *`__data`* range none pageformat default data (mcs51, ds390 named address space) which is structured as follows:
|
|
799
|
+
|
|
800
|
+
- Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
|
|
801
|
+
- Bytes 20-2F - 16 bytes to hold 128 bit range none pageformat default bit variables and,
|
|
802
|
+
- Bytes 30-7F - 80 bytes for general purpose use.
|
|
803
|
+
|
|
804
|
+
Additionally some members of the MCS-51 family may have up to 128 bytes of additional, indirectly addressable, internal RAM memory (*`__idata`* range none pageformat default idata (mcs51, ds390 named address space)). Furthermore, some chips may have some built in external memory (*`__xdata`* range none pageformat default xdata (mcs51, ds390 named address space)) which should not be confused with the internal, directly addressable RAM memory (*`__data`* range none pageformat default data (mcs51, ds390 named address space)). Sometimes this built in *`__xdata`* memory has to be activated before using it (you can probably find this information on the datasheet of the microcontroller your are using, see also section MCS51/DS390 Startup Code Startup-Code).
|
|
805
|
+
|
|
806
|
+
Normally SDCC will only use the first bank range none pageformat default register bank (mcs51, ds390) of registers (register bank 0), but it is possible to specify that other banks of registers (keyword *`__usingrange none` pageformat default using (mcs51, ds390 register bank)*) should be used for example in interrupt range none pageformat default interrupt range none pageformat default interrupt routines. By default, the compiler will place the stack after the last byte of allocated memory for variables. For example, if the first 2 banks of registers are used, and only four bytes are used for *`__data`*` variables, it will position the base of the internal stack at address 20 (0x14). This implies that as the stack range none pageformat default stack grows, it will use up the remaining register banks, and the 16 bytes used by the 128 bit variables, and 80 bytes for general purpose use. If any bit variables are used, the *`__data`* variables will be placed in unused register banks and after the byte holding the last `__bit` variable. For example, if register banks 0 and 1 are used, and there are 9 bit variables (two bytes used), *`__data`* variables will be placed starting from address 0x10 to 0x20 and continue at address 0x22. You can also use --data-loc range none pageformat default --data-loc <Value> to specify the start address of the *__data* and --iram-size range none pageformat default --iram-size <Value> to specify the size of the total internal RAM (*__idata*).
|
|
807
|
+
|
|
808
|
+
By default the 8051 linker will place the stack after the last byte of __(i)data variables. Option --stack-loc range none pageformat default --stack-loc <Value> allows you to specify the start of the stack, i.e. you could start it after any data in the general purpose area. If your microcontroller has additional indirectly addressable internal RAM (*idata*) you can place the stack on it. You may also need to use --xdata-loc range none pageformat default --xdata-loc<Value> to set the start address of the external RAM (*xdata*) and --xram-size range none pageformat default --xram-size <Value> to specify its size. Same goes for the code memory, using --code-loc range none pageformat default --code-loc <Value> and --code-size range none pageformat default --code-size <Value>. If in doubt, don't specify any options and see if the resulting memory layout is appropriate, then you can adjust it.
|
|
809
|
+
|
|
810
|
+
The linker generates two files with memory allocation information. The first, with extension.map range none pageformat default shows all the variables and segments. The second with extension.mem range none pageformat default shows the final memory layout. The linker will complain either if memory segments overlap, there is not enough memory, or there is not enough space for stack. If you get any linking warnings and/or errors related to stack or segments allocation, take a look at either the.map or.mem files to find out what the problem is. The.mem file may even suggest a solution to the problem.
|
|
811
|
+
|
|
812
|
+
#### Z80/Z180/eZ80 intrinsic named address spaces
|
|
813
|
+
|
|
814
|
+
##### __sfr range none pageformat default sfr (in/out to 8-bit addresses)
|
|
815
|
+
|
|
816
|
+
The Z80 range none pageformat default Z80 family has separate address spaces for memory and *i*nput/*o*utput memory. I/O memory range none pageformat default I/O memory (Z80, Z180) range none pageformat default Z80!I/O memory range none pageformat default Z180!I/O memory is accessed with special instructions, e.g.:
|
|
817
|
+
```c
|
|
818
|
+
__sfr __at(0x78) IoPort; /* define a var in I/O space at 78h called IoPort */
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
Writing 0x01 to this variable generates the assembly code:
|
|
822
|
+
```
|
|
823
|
+
3E 01 ld a,#0x01
|
|
824
|
+
D3 78 out (_IoPort),a
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
##### __banked __sfr range none pageformat default sfr (in/out to 16-bit addresses)
|
|
828
|
+
|
|
829
|
+
The keyword *`__banked`* is used to support 16 bit addresses in I/O memory e.g.:
|
|
830
|
+
```c
|
|
831
|
+
__sfr __banked __at range none pageformat default at (0x123) IoPort;
|
|
832
|
+
```
|
|
833
|
+
Writing 0x01 to this variable generates the assembly code:
|
|
834
|
+
```
|
|
835
|
+
01 23 01 ld bc,#_IoPort
|
|
836
|
+
3E 01 ld a,#0x01
|
|
837
|
+
ED 79 out (c),a
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
##### __sfr range none pageformat default sfr (in0/out0 to 8 bit addresses on Z180 range none pageformat default Z180 /HD64180 range none pageformat default HD64180 (see Z180))
|
|
841
|
+
|
|
842
|
+
The compiler option --portmode range none pageformat default Z180!Options!--portmode =180 (80) and a compiler #pragma portmode range none pageformat default Z180!Pragmas! pragma portmode z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructions in0/out0 instead of in/out. If you include the file z180.h this will be set automatically.
|
|
843
|
+
|
|
844
|
+
#### SM83 intrinsic named address spaces
|
|
845
|
+
|
|
846
|
+
##### __sfr range none pageformat default sfr
|
|
847
|
+
|
|
848
|
+
The keyword *`__sfr`* is an alternative way to access memory locations 0xff00 to 0xffff, which are typically used for memory-mapped I/O e.g.:
|
|
849
|
+
```c
|
|
850
|
+
__sfr __at range none pageformat default at (0xff01) IoPort;
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
#### HC08/S08 intrinsic named address spaces
|
|
854
|
+
|
|
855
|
+
##### __data range none pageformat default data (hc08 named address space)
|
|
856
|
+
|
|
857
|
+
Variables in the address space __data resides in the first 256 bytes of memory (the direct page). The HC08 range none pageformat default HC08 is most efficient at accessing variables (especially pointers) stored here.
|
|
858
|
+
|
|
859
|
+
##### __xdata range none pageformat default xdata (hc08 named address space)
|
|
860
|
+
|
|
861
|
+
Variables in the address space__xdata can reside anywhere in memory. This is the default (generic address space).
|
|
862
|
+
|
|
863
|
+
#### PDK14/PDK15 intrinsic named address spaces
|
|
864
|
+
|
|
865
|
+
##### __sfr range none pageformat default sfr
|
|
866
|
+
|
|
867
|
+
The Padauk family has separate address spaces for memory and *i* nput/ *o* utput memory. I/O memory is accessed with special instructions, e.g.:
|
|
868
|
+
```c
|
|
869
|
+
__sfr __at(0x18) gpcc; /* define a var in I/O space at 18h called gpcc */
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
##### __sfr16 range none pageformat default sfr16
|
|
873
|
+
|
|
874
|
+
The Padauk family has a 16-bit timer accessed with special instructions.
|
|
875
|
+
|
|
876
|
+
#### MOS6502 intrinsic named address spaces
|
|
877
|
+
|
|
878
|
+
##### __zp/__data range none pageformat default data (mos6502 named address space) /__near
|
|
879
|
+
|
|
880
|
+
Variables in the address space __zp reside in the first 256 bytes of memory (the Page Zero). The MOS6502 range none pageformat default MOS6502 is most efficient at accessing variables stored here. Pointers can only be dereferenced directly if they reside in Page Zero. This is the default for the small memory model.
|
|
881
|
+
|
|
882
|
+
##### __xdata range none pageformat default xdata (mos6502 named address space) /__far
|
|
883
|
+
|
|
884
|
+
Variables in the address space __xdata can reside anywhere in the 64K memory space. This is the default (for the large memory model).
|
|
885
|
+
|
|
886
|
+
#### Non-intrinsic named address spaces range none pageformat default Non-intrinsic named address spaces
|
|
887
|
+
|
|
888
|
+
SDCC supports user-defined non-intrinsic named address spaces. So far SDCC only supports them for bank-switching. You need to have a function that switches to the desired memory bank and declare a corresponding named address space:
|
|
889
|
+
```c
|
|
890
|
+
void setb0(void); // The function that sets the currently active memory bank to b0
|
|
891
|
+
void setb1(void); // The function that sets the currently active memory bank to b1
|
|
892
|
+
__addressmod range none pageformat default addressmod setb0 spaceb0; // Declare a named address space called spaceb0 that uses setb0()
|
|
893
|
+
__addressmod setb1 spaceb1; // Declare a named address space called spaceb1 that uses setb1()
|
|
894
|
+
spaceb0 int x; // An int in address space spaceb0
|
|
895
|
+
spaceb1 int *y; // A pointer to an int in address space spaceb1
|
|
896
|
+
spaceb0 int *spaceb1 z; // A pointer in address space spaceb1 that points to an int in address space spaceb0
|
|
897
|
+
```
|
|
898
|
+
Non-intrinsic named address spaces for data in ROM are declared using the const keyword:
|
|
899
|
+
```c
|
|
900
|
+
void setb0(void); // The function that sets the currently active memory bank to b0
|
|
901
|
+
void setb1(void); // The function that sets the currently active memory bank to b1
|
|
902
|
+
__addressmod range none pageformat default addressmod setb0 const spaceb0; // Declare a named address space called spaceb0 that uses setb0() and resides in ROM
|
|
903
|
+
__addressmod setb1 spaceb1; // Declare a named address space called spaceb1 that uses setb1() and resides in RAM
|
|
904
|
+
const spaceb0 int x = 42; // An int in address space spaceb0
|
|
905
|
+
spaceb1 int *y; // A pointer to an int in address space spaceb1
|
|
906
|
+
const spaceb0 int *spaceb1 z; // A pointer in address space spaceb1 that points to a constant int in address space spaceb0
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
Variables in non-intrinsic named address spaces will be placed in areas of the same name (this can be used for the placement of named address spaces in memory by the linker).
|
|
910
|
+
|
|
911
|
+
SDCC will automatically insert calls to the corresponding function before accessing the variable. SDCC inserts the minimum possible number calls to the bank selection functions. See Philipp Klaus Krause," Optimal Placement of Bank Selection Instructions in Polynomial Time" for details on how this works.
|
|
912
|
+
|
|
913
|
+
#### Absolute Addressing range none pageformat default Absolute addressing
|
|
914
|
+
|
|
915
|
+
Data items can be assigned an absolute address with the *__at range none pageformat default at* keyword (the address needs to be either a parenthesized constant expression or a constant), which can also be used in addition to a named address space, e.g.:
|
|
916
|
+
```c
|
|
917
|
+
__xdata unsigned int __at (0x7ffe) chksum;
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
In the above example the variable chksum will be located at 0x7ffe and 0x7fff of the external ram. The compiler does *not* reserve any space for variables declared in this way **! (they are implemented with an equate in the assembler). Thus it is left to the programmer to make sure there are no overlaps with other variables that are declared without the absolute address. The assembler listing file (.lst range none pageformat default) and the linker output files (.rst range none pageformat default) and (.map range none pageformat default) are good places to look for such overlaps.
|
|
921
|
+
|
|
922
|
+
If however you provide an initializer range none pageformat default Variable initialization actual memory allocation will take place and overlaps will be detected by the linker. E.g.:
|
|
923
|
+
```c
|
|
924
|
+
__code char __at (0x7ff0) Id[5] =" SDCC";
|
|
925
|
+
```
|
|
926
|
+
In the above example the variable Id will be located from 0x7ff0 to 0x7ff4 in code memory.
|
|
927
|
+
|
|
928
|
+
In case of memory mapped I/O devices the keyword *volatile* has to be used to tell the compiler that accesses might not be removed:
|
|
929
|
+
|
|
930
|
+
volatile range none pageformat default volatile __xdata range none pageformat default xdata (mcs51, ds390 named address space) unsigned char __at range none pageformat default at (0x8000) PORTA_8255;
|
|
931
|
+
|
|
932
|
+
For some architectures (mcs51) array accesses are more efficient if an (xdata/far) array range none pageformat default Aligned array starts at a block (256 byte) boundary range none pageformat default block boundary (section A Step by Step Introduction has an example).
|
|
933
|
+
Absolute addresses can be specified for variables in all named address spaces, e.g.:
|
|
934
|
+
```c
|
|
935
|
+
__bit range none pageformat default bit __at range none pageformat default at (0x02) bvar;
|
|
936
|
+
```
|
|
937
|
+
The above example will allocate the variable at offset 0x02 in the bit-addressable space. There is no real advantage to assigning absolute addresses to variables in this manner, unless you want strict control over all the variables allocated. One possible use would be to write hardware portable code. For example, if you have a routine that uses one or more of the microcontroller I/O pins, and such pins are different for two different hardwares, you can declare the I/O pins in your routine using:
|
|
938
|
+
```c
|
|
939
|
+
extern volatile range none pageformat default volatile __bit MOSI; /* master out, slave in */
|
|
940
|
+
extern volatile __bit MISO; /* master in, slave out */
|
|
941
|
+
extern volatile __bit MCLK; /* master clock */
|
|
942
|
+
|
|
943
|
+
/* Input and Output of a byte on a 3-wire serial bus.
|
|
944
|
+
If needed adapt polarity of clock, polarity of data and bit order
|
|
945
|
+
*/
|
|
946
|
+
unsigned char spi_io(unsigned char out_byte)
|
|
947
|
+
{
|
|
948
|
+
unsigned char i=8;
|
|
949
|
+
do {
|
|
950
|
+
MOSI = out_byte & 0x80;
|
|
951
|
+
out_byte <<= 1;
|
|
952
|
+
MCLK = 1;
|
|
953
|
+
/* __asm nop __endasm; */ /* for slow peripherals */
|
|
954
|
+
if(MISO)
|
|
955
|
+
out_byte += 1;
|
|
956
|
+
MCLK = 0;
|
|
957
|
+
} while(--i);
|
|
958
|
+
return out_byte;
|
|
959
|
+
}
|
|
960
|
+
```
|
|
961
|
+
Then, someplace in the code for the first hardware you would use
|
|
962
|
+
```c
|
|
963
|
+
__bit __at range none pageformat default at (0x80) MOSI; /* I/O port 0, bit 0 */
|
|
964
|
+
__bit __at (0x81) MISO; /* I/O port 0, bit 1 */
|
|
965
|
+
__bit __at (0x82) MCLK; /* I/O port 0, bit 2 */
|
|
966
|
+
```
|
|
967
|
+
Similarly, for the second hardware you would use
|
|
968
|
+
```c
|
|
969
|
+
__bit __at (0x83) MOSI; /* I/O port 0, bit 3 */
|
|
970
|
+
__bit __at (0x91) MISO; /* I/O port 1, bit 1 */
|
|
971
|
+
__bit range none pageformat default bit __at (0x92) MCLK; /* I/O port 1, bit 2 */
|
|
972
|
+
```
|
|
973
|
+
and you can use the same hardware dependent routine without changes, as for example in a library. This is somehow similar to sbit, but only one absolute address has to be specified in the whole project.
|
|
974
|
+
|
|
975
|
+
#### __sdcc_external_startup range none pageformat default sdcc external startup
|
|
976
|
+
|
|
977
|
+
When a function unsigned char __sdcc_external_startup(void) is present, it is executed before both the initialization of static and global variables, as well as main. This allows to implement functionality that needs to be done early. For example: disabling a hardware watchdog that would otherwise bite during the time it takes to initialize global variables; setup or calibration of system/peripheral clocks; or, a memory check that needs to be done before any memory (other than the return address for __sdcc_external_startup itself) is in use.
|
|
978
|
+
|
|
979
|
+
If this routine returns a non-zero value, the static and global variable initialization will be skipped and the function main will be invoked. Otherwise static and global variables will be initialized before the function main is invoked.
|
|
980
|
+
|
|
981
|
+
For mos6502, z80, z80n, z180, sm83, ez80_z80, tlcs90, r2k, r2ka, r3ka, when using a custom crt0, support depends on the custom crt0.
|
|
982
|
+
|
|
983
|
+
#### Preserved register specification
|
|
984
|
+
|
|
985
|
+
SDCC allows to specify preserved registers in function declarations, to enable further optimizations on calls to functions implemented in assembler. Example for the Z80 architecture specifying that a function will preserve register pairs bc and iy:
|
|
986
|
+
```c
|
|
987
|
+
void f(void) __preserves_regs(b, c, iyl, iyh);
|
|
988
|
+
```
|
|
989
|
+
#### Binary constants range none pageformat default Binary constants
|
|
990
|
+
|
|
991
|
+
SDCC supports the use of C23 binary constants, such as 0b01100010 when the compiler is invoked using --std-sdccxx, even when the corresponding --std-cxx, does not. Note: xx is a placeholder for the desired version of the C standard.
|
|
992
|
+
|
|
993
|
+
#### Returning void
|
|
994
|
+
|
|
995
|
+
SDCC allows functions to return expressions of type void. This feature is only enabled when the compiler is invoked using --std-sdccxx. Note: xx is a placeholder for the desired version of the C standard.
|
|
996
|
+
|
|
997
|
+
#### Omitting promotion on arguments of vararg function (does not apply to pdk13, pdk14, pdk15)
|
|
998
|
+
|
|
999
|
+
Arguments to vararg functions are not promoted when explicitly cast. This feature is only enabled when the compiler is invoked using --std-sdccxx. This breaks compability with the C standards, so linking code compiled with --std-sdccxx with code compiled using --std-cxx can result in failing programs when arguments to vararg functions are explicitly cast. Note: xx is a placeholder for the desired version of the C standard.
|
|
1000
|
+
|
|
1001
|
+
### Parameters range none pageformat default Parameters range none pageformat default function parameter and Local Variables range none pageformat default local variables
|
|
1002
|
+
|
|
1003
|
+
Automatic (local) variables and parameters to functions are placed on the stack for most targets. For MCS51/DS390/HC08/S08/MOS6502/PDK13/PDK14/PDK15 they can either be placed on the stack or in data-space. The default action of the compiler is to place these variables in the internal RAM (for small model) or external RAM (for medium or large model). This in fact makes them similar to *static range none pageformat default static* so by default functions are non-reentrant range none pageformat default reentrant.
|
|
1004
|
+
|
|
1005
|
+
They can be placed on the stack range none pageformat default stack by using the *--stack-auto range none pageformat default --stack-auto* option, by using *#pragma stackauto* range none pageformat default pragma stackauto or by using the *__reentrant range none pageformat default reentrant* keyword in the function declaration, e.g.:
|
|
1006
|
+
```c
|
|
1007
|
+
unsigned char foo(char i) __reentrant
|
|
1008
|
+
{
|
|
1009
|
+
...
|
|
1010
|
+
}
|
|
1011
|
+
```
|
|
1012
|
+
Since stack space on 8051 and MOS6502 is limited, and accessing the stack is slow for the Padauk, the *__reentrant* keyword or the *--stack-auto* option should be used sparingly. Note that the *__reentrant* keyword just means that the parameters & local variables will be allocated to the stack, it *does not* mean that the function is register bank range none pageformat default register bank (mcs51, ds390) independent.
|
|
1013
|
+
|
|
1014
|
+
Local variables range none pageformat default local variables can be assigned intrinsic named address spaces and absolute range none pageformat default Absolute addressing addresses, e.g.:
|
|
1015
|
+
```c
|
|
1016
|
+
unsigned char foo(__xdata int parm)
|
|
1017
|
+
{
|
|
1018
|
+
__xdata unsigned char i;
|
|
1019
|
+
__bit bvar;
|
|
1020
|
+
__data unsigned char __at range none pageformat default at (0x31) j;
|
|
1021
|
+
...
|
|
1022
|
+
}
|
|
1023
|
+
```
|
|
1024
|
+
In the above example the parameter range none pageformat default function parameter *parm* and the variable *i* will be allocated in the external ram, *bvar* in bit addressable space and *j* in internal ram. When compiled with *--stack-auto* or when a function is declared as *reentrant* this should only be done for static variables.
|
|
1025
|
+
|
|
1026
|
+
It is however allowed to use bit parameters in reentrant functions and also non-static local bit variables are supported. Efficient use is limited to 8 semi-bitregisters in bit space. They are pushed and popped to stack range none pageformat default stack as a single byte just like the normal registers.
|
|
1027
|
+
|
|
1028
|
+
### Overlaying range none pageformat default Overlaying
|
|
1029
|
+
|
|
1030
|
+
For non-reentrant range none pageformat default reentrant functions SDCC will try to reduce internal ram space usage by overlaying parameters and local variables of a function (if possible). Parameters and local variables range none pageformat default local variables of a function will be allocated to an overlayable segment if the function has *no other function calls and the function is non-reentrant and the memory model range none pageformat default Memory model is small.* If an explicit intrinsic named address space range none pageformat default intrinsic named address space is specified for a local variable, it will NOT be overlaid.
|
|
1031
|
+
|
|
1032
|
+
Note that the compiler (not the linkage editor) makes the decision for overlaying the data items. Functions that are called from an interrupt service routine **! should be preceded by a #pragma nooverlay range none pageformat default pragma nooverlay if they are not reentrant.
|
|
1033
|
+
|
|
1034
|
+
Also note that the compiler does not do any processing of inline assembler code, so the compiler might incorrectly assign local variables and parameters of a function into the overlay segment if the inline assembler code calls other c-functions that might use the overlay. In that case the #pragma nooverlay should be used.
|
|
1035
|
+
|
|
1036
|
+
Parameters and local variables of functions that contain 16 or 32 bit multiplication range none pageformat default Multiplication or division range none pageformat default Division will NOT be overlaid since these are implemented using external functions, e.g.:
|
|
1037
|
+
```c
|
|
1038
|
+
#pragma save
|
|
1039
|
+
#pragma nooverlay range none pageformat default pragma nooverlay
|
|
1040
|
+
void set_error(unsigned char errcd)
|
|
1041
|
+
{
|
|
1042
|
+
P3 = errcd;
|
|
1043
|
+
}
|
|
1044
|
+
#pragma restore
|
|
1045
|
+
|
|
1046
|
+
void some_isr () __interrupt range none pageformat default interrupt (2)
|
|
1047
|
+
{
|
|
1048
|
+
...
|
|
1049
|
+
set_error(10);
|
|
1050
|
+
...
|
|
1051
|
+
}
|
|
1052
|
+
```
|
|
1053
|
+
In the above example the parameter *errcd* for the function *set_error* would be assigned to the overlayable segment if the #pragma nooverlay was not present, this could cause unpredictable runtime behaviour when called from an interrupt service routine. The #pragma nooverlay ensures that the parameters and local variables for the function are NOT overlaid.
|
|
1054
|
+
|
|
1055
|
+
### Interrupt Service Routines
|
|
1056
|
+
|
|
1057
|
+
#### General Information
|
|
1058
|
+
|
|
1059
|
+
SDCC allows *i* nterrupt *s* ervice *r* outines to be coded in C, with some extended keywords.
|
|
1060
|
+
```c
|
|
1061
|
+
void timer_isr (void) __interrupt (1) __using (1)
|
|
1062
|
+
{
|
|
1063
|
+
...
|
|
1064
|
+
}
|
|
1065
|
+
```
|
|
1066
|
+
The optional number following the *__interrupt range none pageformat default interrupt range none pageformat default interrupt* keyword is the interrupt number this routine will service. When present, the compiler will insert a call to this routine in the interrupt vector table range none pageformat default interrupt vector table for the interrupt number specified. If you have multiple source files in your project, interrupt service routines can be present in any of them, but a prototype of the isr MUST be present or included in the file that contains the function *main*. The optional (8051 specific) keyword *__using range none pageformat default using (mcs51, ds390 register bank)* can be used to tell the compiler to use the specified register bank when generating code for this function.
|
|
1067
|
+
Interrupt service routines open the door for some very interesting bugs:
|
|
1068
|
+
|
|
1069
|
+
##### Common interrupt pitfall: variable not declared *volatile
|
|
1070
|
+
|
|
1071
|
+
If an interrupt service routine changes variables which are accessed by other functions these variables have to be declared *volatile* range none pageformat default volatile. See http://en.wikipedia.org/wiki/Volatile_variable.
|
|
1072
|
+
|
|
1073
|
+
##### Common interrupt pitfall: *non-atomic access
|
|
1074
|
+
|
|
1075
|
+
If the access to these variables is not *atomic range none pageformat default atomic* (i.e. the processor needs more than one instruction for the access and could be interrupted while accessing the variable) the interrupt must be disabled during the access to avoid inconsistent data.
|
|
1076
|
+
Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and should be protected by disabling interrupts. You're not automatically on the safe side if you use 8 bit variables though. We need an example here: f.e. on the 8051 the harmless looking" flags |= 0x80;" is not atomic if flags resides in xdata. Setting" flags |= 0x40;" from within an interrupt routine might get lost if the interrupt occurs at the wrong time." counter += 8;" is not atomic on the 8051 even if counter is located in data memory.
|
|
1077
|
+
Bugs like these are hard to reproduce and can cause a lot of trouble.
|
|
1078
|
+
|
|
1079
|
+
##### Common interrupt pitfall: *stack overflow
|
|
1080
|
+
|
|
1081
|
+
The return address and the registers used in the interrupt service routine are saved on the stack range none pageformat default stack so there must be sufficient stack space. If there isn't variables or registers (or even the return address itself) will be corrupted. This *stack overflow* range none pageformat default stack overflow is most likely to happen if the interrupt occurs during the" deepest" subroutine when the stack is already in use for f.e. many return addresses.
|
|
1082
|
+
|
|
1083
|
+
##### Common interrupt pitfall: *use of non-reentrant functions
|
|
1084
|
+
|
|
1085
|
+
A special note here, integer multiplicative operators and floating-point range none pageformat default Floating point support operations might be implemented using external support routines, depending on the target architecture. If an interrupt service routine needs to do any of these operations on a target where functions are non-reentrant by default, then the support routines (as mentioned in a following section) will have to be recompiled using the *--stack-auto range none pageformat default --stack-auto* option and the source file will need to be compiled using the *--int-long-reent* range none pageformat default --int-long-reent compiler option.
|
|
1086
|
+
Note, the type promotion range none pageformat default type promotion required by ANSI C can cause 16 bit routines to be used **! without the programmer being aware of it. See f.e. the cast **(unsigned char)(tail-1)within the if clause in section A Step by Step Introduction.
|
|
1087
|
+
|
|
1088
|
+
Calling other functions from an interrupt service routine on a target where functions are non-reentrant by default is not recommended, avoid it if possible. Note that when some function is called from an interrupt service routine it should be preceded by a #pragma nooverlay range none pageformat default pragma nooverlay if it is not reentrant. Furthermore non-reentrant functions should not be called from the main program while the interrupt service routine might be active. They also must not be called from low priority interrupt service routines while a high priority interrupt service routine might be active. You could use semaphores or make the function *critical* if all parameters are passed in registers.
|
|
1089
|
+
Also see section Overlaying about Overlaying and section Functions using private register banks about Functions using private register banks.
|
|
1090
|
+
|
|
1091
|
+
#### MCS51/DS390 Interrupt Service Routines
|
|
1092
|
+
|
|
1093
|
+
Interrupt range none pageformat default interrupt numbers and the corresponding address & descriptions for the Standard 8051/8052 are listed below. SDCC will automatically adjust the range none pageformat default interrupt vector table to the maximum interrupt number specified.
|
|
1094
|
+
|
|
1095
|
+
| Interrupt # | Description | Vector Address |
|
|
1096
|
+
| --- | --- | --- |
|
|
1097
|
+
| 0 | External 0 | 0x0003 |
|
|
1098
|
+
| 1 | Timer 0 | 0x000b |
|
|
1099
|
+
| 2 | External 1 | 0x0013 |
|
|
1100
|
+
| 3 | Timer 1 | 0x001b |
|
|
1101
|
+
| 4 | Serial | 0x0023 |
|
|
1102
|
+
| 5 | Timer 2 (8052) | 0x002b |
|
|
1103
|
+
|... | |... |
|
|
1104
|
+
| n | | 0x0003 + 8*n |
|
|
1105
|
+
| n | | 0x0003 + 8*n |
|
|
1106
|
+
|
|
1107
|
+
If the interrupt service routine is defined without *__using range none pageformat default using (mcs51, ds390 register bank) range none pageformat default using (mcs51, ds390 register bank)* a register bank or with register bank 0 (*__using* (0)), the compiler will save the registers used by itself on the stack upon entry and restore them at exit, however if such an interrupt service routine calls another function then the entire register bank will be saved on the stack. This scheme may be advantageous for small interrupt service routines which have low register usage.
|
|
1108
|
+
|
|
1109
|
+
If the interrupt service routine is defined to be using a specific register bank then only *a, b, dptr* & psw are saved and restored, if such an interrupt service routine calls another function (using another register bank) then the entire register bank of the called function will be saved on the stack range none pageformat default stack. This scheme is recommended for larger interrupt service routines.
|
|
1110
|
+
|
|
1111
|
+
#### HC08 range none pageformat default HC08 Interrupt Service Routines
|
|
1112
|
+
|
|
1113
|
+
Since the number of interrupts range none pageformat default HC08!interrupt available is chip specific and the interrupt vector table always ends at the last byte of memory, the interrupt numbers corresponds to the interrupt vectors in reverse order of address. For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt 2 will use the interrupt vector at 0xfffa, and so on. However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in this way; instead see section MCS51/DS390 Startup Code for details on customizing startup.
|
|
1114
|
+
|
|
1115
|
+
#### Z80, Z180 and eZ80 Interrupt Service Routines
|
|
1116
|
+
|
|
1117
|
+
The Z80 range none pageformat default Z80 uses several different methods for determining the correct interrupt range none pageformat default Z80!interrupt vector depending on the hardware implementation. Therefore, SDCC does not attempt to generate an interrupt vector table.
|
|
1118
|
+
|
|
1119
|
+
By default, SDCC generates code for a maskable interrupt, which uses a RETI instruction to return from the interrupt. To write an interrupt handler for the non-maskable interrupt, which needs a RETN instruction instead, leave out the interrupt number:
|
|
1120
|
+
```c
|
|
1121
|
+
void nmi_isr (void) __critical __interrupt
|
|
1122
|
+
{
|
|
1123
|
+
...
|
|
1124
|
+
}
|
|
1125
|
+
```
|
|
1126
|
+
Since interrupts on the Z80 and Z180 are level-triggered (except for the NMI), interruptible interrupt handlers should only be used where hardware acknowledge is available.
|
|
1127
|
+
|
|
1128
|
+
| Type | Syntax | Behaviour |
|
|
1129
|
+
| --- | --- | --- |
|
|
1130
|
+
| Interruptible interrupt handler | void f(void) __interrupt | Interrupt handler can be interrupted by further interrupts |
|
|
1131
|
+
| Non-interruptible interrupt handler | void f(void) __critical __interrupt(0) | Interrupt handler can be interrupted by NMI only |
|
|
1132
|
+
| NMI handler | void f(void) __critical __interrupt | Interrupt handler can be interrupted by NMI only |
|
|
1133
|
+
| NMI handler | void f(void) __critical __interrupt | Interrupt handler can be interrupted by NMI only |
|
|
1134
|
+
|
|
1135
|
+
#### Rabbit 2000, 3000 and 3000A Interrupt Service Routines
|
|
1136
|
+
|
|
1137
|
+
SDCC does not attempt to generate an interrupt vector table.
|
|
1138
|
+
|
|
1139
|
+
| Type | Syntax | Behaviour |
|
|
1140
|
+
| --- | --- | --- |
|
|
1141
|
+
| Interruptible interrupt handler | void f(void) __interrupt | Interrupt handler can be interrupted by further interrupts of same priority |
|
|
1142
|
+
| Non-interruptible interrupt handler | void f(void) __critical __interrupt(0) | Interrupt handler can be interrupted by interrupts of higher priority only |
|
|
1143
|
+
| Non-interruptible interrupt handler | void f(void) __critical __interrupt(0) | Interrupt handler can be interrupted by interrupts of higher priority only |
|
|
1144
|
+
|
|
1145
|
+
#### SM83 and TLCS-90 Interrupt Service Routines
|
|
1146
|
+
|
|
1147
|
+
SDCC does not attempt to generate an interrupt vector table.
|
|
1148
|
+
|
|
1149
|
+
| Type | Syntax | Behaviour |
|
|
1150
|
+
| --- | --- | --- |
|
|
1151
|
+
| Interruptible interrupt handler | void f(void) __interrupt | Interrupt handler can be interrupted by further interrupts |
|
|
1152
|
+
| Non-interruptible interrupt handler | void f(void) __critical __interrupt(0) | Interrupt handler cannot be interrupted by further interrupts |
|
|
1153
|
+
| Non-interruptible interrupt handler | void f(void) __critical __interrupt(0) | Interrupt handler cannot be interrupted by further interrupts |
|
|
1154
|
+
|
|
1155
|
+
#### STM8 Interrupt Service Routines
|
|
1156
|
+
|
|
1157
|
+
The STM8 interrupt table contains 31 entries: Reset (used by SDCC for program startup), trap and user interrupts 0 to 29. Where the keyword *__interrupt range none pageformat default interrupt* is used for normal user interrupts, the *__trap* keyword is used for the trap handler:
|
|
1158
|
+
```c
|
|
1159
|
+
void handler (void) __trap
|
|
1160
|
+
{
|
|
1161
|
+
...
|
|
1162
|
+
}
|
|
1163
|
+
```
|
|
1164
|
+
### Enabling and Disabling Interrupts
|
|
1165
|
+
|
|
1166
|
+
#### Critical Functions and Critical Statements
|
|
1167
|
+
|
|
1168
|
+
A special keyword may be associated with a block or a function declaring it as *__critical*. SDCC will generate code to disable all interrupts range none pageformat default interrupt upon entry to a critical function and restore the interrupt enable to the previous state before returning (for architectures where there is no efficient way to do so (sm83, tlcs90, stm8), interrupts will be unconditionally enabled instead). Nesting critical functions will need one additional byte on the stack range none pageformat default stack for each call.
|
|
1169
|
+
```c
|
|
1170
|
+
int foo () __critical range none pageformat default critical range none pageformat default critical
|
|
1171
|
+
{
|
|
1172
|
+
...
|
|
1173
|
+
...
|
|
1174
|
+
}
|
|
1175
|
+
```
|
|
1176
|
+
The critical attribute maybe used with other attributes like *reentrant.*
|
|
1177
|
+
The keyword *__critical* may also be used to disable interrupts more locally:
|
|
1178
|
+
|
|
1179
|
+
`__critical{ i++; }`
|
|
1180
|
+
|
|
1181
|
+
More than one statement could have been included in the block.
|
|
1182
|
+
|
|
1183
|
+
#### Enabling and Disabling Interrupts directly
|
|
1184
|
+
|
|
1185
|
+
Interrupts range none pageformat default interrupt can also be disabled and enabled directly (8051):
|
|
1186
|
+
```
|
|
1187
|
+
EA = 0; or: EA_SAVE = EA;
|
|
1188
|
+
|
|
1189
|
+
... EA = 0;
|
|
1190
|
+
|
|
1191
|
+
EA = 1;...
|
|
1192
|
+
|
|
1193
|
+
EA = EA_SAVE;
|
|
1194
|
+
```
|
|
1195
|
+
On other architectures which have separate opcodes for enabling and disabling interrupts you might want to make use of defines with inline assembly range none pageformat default Assembler routines (HC08 range none pageformat default HC08!interrupt):
|
|
1196
|
+
|
|
1197
|
+
#define CLI __asm range none pageformat default asm cli __endasm range none pageformat default endasm;
|
|
1198
|
+
```c
|
|
1199
|
+
#define SEI __asm sei __endasm;
|
|
1200
|
+
```
|
|
1201
|
+
or for SDCC version 3.2.0 or newer:
|
|
1202
|
+
```c
|
|
1203
|
+
#define CLI __asm__ (" cli");
|
|
1204
|
+
|
|
1205
|
+
#define SEI __asm__ (" sei");
|
|
1206
|
+
```
|
|
1207
|
+
Note: it is sometimes sufficient to disable only a specific interrupt source like f.e. a timer or serial interrupt by manipulating an *interrupt mask range none pageformat default interrupt mask* register.
|
|
1208
|
+
|
|
1209
|
+
Usually the time during which interrupts are disabled should be kept as short as possible. This minimizes both *interrupt latency* range none pageformat default interrupt latency (the time between the occurrence of the interrupt and the execution of the first code in the interrupt routine) and *interrupt jitter* range none pageformat default interrupt jitter (the difference between the shortest and the longest interrupt latency). These really are something different, f.e. a serial interrupt has to be served before its buffer overruns so it cares for the maximum interrupt latency, whereas it does not care about jitter. On a loudspeaker driven via a digital to analog converter which is fed by an interrupt a latency of a few milliseconds might be tolerable, whereas a much smaller jitter will be very audible.
|
|
1210
|
+
|
|
1211
|
+
You can re-enable interrupts within an interrupt routine and on some architectures you can make use of two (or more) levels of *interrupt priorities* range none pageformat default interrupt priority. On some architectures which don't support interrupt priorities these can be implemented by manipulating the interrupt mask and re-enabling interrupts within the interrupt routine. Check there is sufficient space on the stack range none pageformat default stack and don't add complexity unless you have to.
|
|
1212
|
+
|
|
1213
|
+
#### Semaphore range none pageformat default semaphore locking (mcs51/ds390)
|
|
1214
|
+
|
|
1215
|
+
Some architectures (mcs51/ds390) have an atomic range none pageformat default atomic bit test and clear instruction. These type of instructions are typically used in preemptive multitasking systems, where a routine f.e. claims the use of a data structure ('acquires a lock range none pageformat default lock on it'), makes some modifications and then releases the lock when the data structure is consistent again. The instruction may also be used if interrupt and non-interrupt code have to compete for a resource. With the atomic bit test and clear instruction interrupts range none pageformat default interrupt don't have to be disabled for the locking operation.
|
|
1216
|
+
|
|
1217
|
+
SDCC generates this instruction if the source follows this pattern:
|
|
1218
|
+
```c
|
|
1219
|
+
volatile range none pageformat default volatile bit resource_is_free;
|
|
1220
|
+
|
|
1221
|
+
if (resource_is_free)
|
|
1222
|
+
{
|
|
1223
|
+
resource_is_free=0;
|
|
1224
|
+
...
|
|
1225
|
+
resource_is_free=1;
|
|
1226
|
+
}
|
|
1227
|
+
```
|
|
1228
|
+
Note, mcs51 and ds390 support only an atomic range none pageformat default atomic bit test and *clear* instruction (as opposed to atomic bit test and *set).
|
|
1229
|
+
|
|
1230
|
+
### Functions using private register banks (mcs51/ds390)
|
|
1231
|
+
|
|
1232
|
+
Some architectures have support for quickly changing register sets. SDCC supports this feature with the *__using range none pageformat default using (mcs51, ds390 register bank) range none pageformat default using (mcs51, ds390 register bank)* attribute (which tells the compiler to use a register bank range none pageformat default register bank (mcs51, ds390) other than the default bank zero). It should only be applied to *interrupt range none pageformat default interrupt* functions (see footnote below). This will in most circumstances make the generated ISR code more efficient since it will not have to save registers on the stack.
|
|
1233
|
+
|
|
1234
|
+
The *__using* attribute will have no effect on the generated code for a *non-interrupt* function (but may occasionally be useful anyway possible exception: if a function is called ONLY from 'interrupt' functions using a particular bank, it can be declared with the same 'using' attribute as the calling 'interrupt' functions. For instance, if you have several ISRs using bank one, and all of them call memcpy(), it might make sense to create a specialized version of memcpy() 'using 1', since this would prevent the ISR from having to save bank zero to the stack on entry and switch to bank zero before calling the function).
|
|
1235
|
+
*(pending: Note, nowadays the* __using *attribute has an effect onthe generated code for a* non-interrupt *function*. *)
|
|
1236
|
+
|
|
1237
|
+
An *interrupt* function using a non-zero bank will assume that it can trash that register bank, and will not save it. Since high-priority interrupts range none pageformat default interrupts range none pageformat default interrupt priority can interrupt low-priority ones on the 8051 and friends, this means that if a high-priority ISR *using* a particular bank occurs while processing a low-priority ISR *using* the same bank, terrible and bad things can happen. To prevent this, no single register bank should be *used* by both a high priority and a low priority ISR. This is probably most easily done by having all high priority ISRs use one bank and all low priority ISRs use another. If you have an ISR which can change priority at runtime, you're on your own: I suggest using the default bank zero and taking the small performance hit.
|
|
1238
|
+
|
|
1239
|
+
It is most efficient if your ISR calls no other functions. If your ISR must call other functions, it is most efficient if those functions use the same bank as the ISR (see note 1 below); the next best is if the called functions use bank zero. It is very inefficient to call a function using a different, non-zero bank from an ISR.
|
|
1240
|
+
|
|
1241
|
+
### Inline Assembler Code range none pageformat default Assembler routines
|
|
1242
|
+
|
|
1243
|
+
#### Inline Assembler Code Formats
|
|
1244
|
+
|
|
1245
|
+
SDCC supports two formats for inline assembler code definition:
|
|
1246
|
+
|
|
1247
|
+
##### Old __asm... __endasm; Format
|
|
1248
|
+
|
|
1249
|
+
Most of inline assembler code examples in this manual use the old inline assembler code format, but the new format could be used equivalently.
|
|
1250
|
+
|
|
1251
|
+
Example:
|
|
1252
|
+
```c
|
|
1253
|
+
__asm
|
|
1254
|
+
; This is a comment
|
|
1255
|
+
label:
|
|
1256
|
+
nop
|
|
1257
|
+
__endasm;
|
|
1258
|
+
```
|
|
1259
|
+
Note: As of SDCC 4.2.9, assembler comments occurring in this type of inline assembler block are affected by macro expansion.
|
|
1260
|
+
|
|
1261
|
+
##### New __asm__ (" inline_assembler_code") Format
|
|
1262
|
+
|
|
1263
|
+
The __asm__ inline assembler code format was introduced in SDCC version 3.2.0. Its main advantage is that it is compatible with all standard compliant C preprocessors.
|
|
1264
|
+
|
|
1265
|
+
Example:
|
|
1266
|
+
```c
|
|
1267
|
+
__asm__ ("; This is a comment\nlabel:\n\tnop");
|
|
1268
|
+
```
|
|
1269
|
+
Or for better readability:
|
|
1270
|
+
```c
|
|
1271
|
+
__asm__ (
|
|
1272
|
+
"; This is a comment\n"
|
|
1273
|
+
"label:\n"
|
|
1274
|
+
"\tnop"
|
|
1275
|
+
);
|
|
1276
|
+
```
|
|
1277
|
+
|
|
1278
|
+
#### A Step by Step Introduction
|
|
1279
|
+
|
|
1280
|
+
Starting from a small snippet of c-code this example shows for the MCS51 how to use inline assembly, access variables, a function parameter and an array in xdata memory. The example uses an MCS51 here but is easily adapted for other architectures. This is a buffer routine which should be optimized:
|
|
1281
|
+
|
|
1282
|
+
unsigned char __far range none pageformat default far (named address space) __at range none pageformat default at (0x7f00) buf[0x100]; range none pageformat default Aligned array
|
|
1283
|
+
unsigned char head, tail; /* if interrupts range none pageformat default interrupt are involved see
|
|
1284
|
+
section about **volatile*/
|
|
1285
|
+
```c
|
|
1286
|
+
void to_buffer(unsigned char c)
|
|
1287
|
+
{
|
|
1288
|
+
if(head!= (unsigned char)(tail-1)) /* cast **needed** to avoid promotion range none pageformat default promotion to signed int range none pageformat default type promotion to integer */ **!
|
|
1289
|
+
buf[head++] = c; /* access to a 256 byte aligned array */
|
|
1290
|
+
}
|
|
1291
|
+
```
|
|
1292
|
+
|
|
1293
|
+
If the code snippet (assume it is saved in buffer.c) is compiled with SDCC then a corresponding buffer.asm file is generated. We define a new function to_buffer_asm() in file buffer.c in which we cut and paste the generated code, removing unwanted comments and some ':'. Then add" **__asm** " and" **__endasm;** " Note, that the single underscore form (_asm and _endasm) are not C99 compatible, and for C99 compatibility, the double-underscore form (__asm and __endasm) has to be used. The latter is also used in the library functions. to the beginning and the end of the function body:
|
|
1294
|
+
```c
|
|
1295
|
+
/* With a cut and paste from the.asm file, we have something to start with.
|
|
1296
|
+
The function is not yet OK! (registers aren't saved) */
|
|
1297
|
+
void to_buffer_asm(unsigned char c)
|
|
1298
|
+
{
|
|
1299
|
+
__asm range none pageformat default asm
|
|
1300
|
+
mov r2,dpl
|
|
1301
|
+
;buffer.c if(head!= (unsigned char)(tail-1)) /* cast **needed** to avoid promotion range none pageformat default promotion to signed int range none pageformat default type promotion to integer */
|
|
1302
|
+
mov a,_tail
|
|
1303
|
+
dec a
|
|
1304
|
+
mov r3,a
|
|
1305
|
+
mov a,_head
|
|
1306
|
+
cjne a,ar3,00106$
|
|
1307
|
+
ret
|
|
1308
|
+
00106$:
|
|
1309
|
+
;buffer.c buf[head++] = c; /* access to a 256 byte aligned array */ range none pageformat default Aligned array
|
|
1310
|
+
mov r3,_head
|
|
1311
|
+
inc _head
|
|
1312
|
+
mov dpl,r3
|
|
1313
|
+
mov dph,#(_buf >> 8)
|
|
1314
|
+
mov a,r2
|
|
1315
|
+
movx @dptr,a
|
|
1316
|
+
00103$:
|
|
1317
|
+
ret
|
|
1318
|
+
__endasm range none pageformat default endasm;
|
|
1319
|
+
}
|
|
1320
|
+
```
|
|
1321
|
+
The new file buffer.c should compile with only one warning about the unreferenced function argument 'c'. Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY (1) and finally have:
|
|
1322
|
+
```c
|
|
1323
|
+
unsigned char __far __at(0x7f00) buf[0x100];
|
|
1324
|
+
unsigned char head, tail;
|
|
1325
|
+
#define USE_ASSEMBLY (1)
|
|
1326
|
+
|
|
1327
|
+
#if!USE_ASSEMBLY
|
|
1328
|
+
|
|
1329
|
+
void to_buffer(unsigned char c)
|
|
1330
|
+
{
|
|
1331
|
+
if(head!= (unsigned char)(tail-1))
|
|
1332
|
+
buf[head++] = c;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
#else
|
|
1336
|
+
|
|
1337
|
+
void to_buffer(unsigned char c)
|
|
1338
|
+
{
|
|
1339
|
+
c; // to avoid warning: unreferenced function argument
|
|
1340
|
+
__asm range none pageformat default asm
|
|
1341
|
+
; save used registers here.
|
|
1342
|
+
; If we were still using r2,r3 we would have to push them here.
|
|
1343
|
+
; if(head!= (unsigned char)(tail-1))
|
|
1344
|
+
mov a,_tail
|
|
1345
|
+
dec a
|
|
1346
|
+
xrl a,_head
|
|
1347
|
+
; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
|
|
1348
|
+
jz t_b_end$
|
|
1349
|
+
;
|
|
1350
|
+
; buf[head++] = c;
|
|
1351
|
+
mov a,dpl; dpl holds lower byte of function argument
|
|
1352
|
+
mov dpl,_head; buf is 0x100 byte aligned so head can be used directly
|
|
1353
|
+
mov dph,#(_buf>>8)
|
|
1354
|
+
movx @dptr,a
|
|
1355
|
+
inc _head
|
|
1356
|
+
; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
|
|
1357
|
+
t_b_end$:
|
|
1358
|
+
; restore used registers here
|
|
1359
|
+
__endasm range none pageformat default endasm;
|
|
1360
|
+
}
|
|
1361
|
+
#endif
|
|
1362
|
+
```
|
|
1363
|
+
|
|
1364
|
+
The inline assembler code can contain any valid code understood by the assembler, this includes any assembler directives and comment lines. The assembler does not like some characters like ':' or ''' in comments. You'll find an 100+ pages assembler manual in sdcc/sdas/doc/asmlnk.txt range none pageformat default sdas (sdasgb, sdas6808, sdas8051, sdasz80) range none pageformat default Assembler documentation or online at http://svn.code.sf.net/p/sdcc/code/trunk/sdcc/sdas/doc/asmlnk.txt.
|
|
1365
|
+
|
|
1366
|
+
The compiler does not do any validation of the code within the __asm range none pageformat default asm... __endasm range none pageformat default endasm; keyword pair. Specifically it will not know which registers are used and thus register pushing/popping range none pageformat default push/pop has to be done manually.
|
|
1367
|
+
|
|
1368
|
+
It is required that each assembly instruction be placed on a separate line. This is also recommended for labels (as the example shows). This is especially important to note when the inline assembler is placed in a C preprocessor macro as the preprocessor will normally put all replacing code on a single line. Only when the macro has each assembly instruction on a single line that ends with a line continuation character will it be placed as separate lines in the resulting.asm file.
|
|
1369
|
+
```c
|
|
1370
|
+
#define DELAY\
|
|
1371
|
+
__asm\
|
|
1372
|
+
nop\
|
|
1373
|
+
nop\
|
|
1374
|
+
__endasm
|
|
1375
|
+
```
|
|
1376
|
+
When the -- *peep-asm range none pageformat default --peep-asm* command line option is used, the inline assembler code will be passed through the peephole optimizer range none pageformat default Peephole optimizer. There are only a few (if any) cases where this option makes sense, it might cause some unexpected changes in the inline assembler code. Please go through the peephole optimizer rules defined in file *peeph.def* before using this option.
|
|
1377
|
+
|
|
1378
|
+
#### Naked Functions range none pageformat default Naked functions
|
|
1379
|
+
|
|
1380
|
+
A special keyword may be associated with a function declaring it as *__naked range none pageformat default naked range none pageformat default naked.* The *_naked* function modifier attribute prevents the compiler from generating prologue range none pageformat default function prologue and epilogue range none pageformat default function epilogue code for that function. This means that the user is entirely responsible for such things as saving any registers that may need to be preserved, selecting the proper register bank, generating the *return* instruction at the end, etc. Practically, this means that the contents of the function must be written in inline assembler. This is particularly useful for interrupt functions, which can have a large (and often unnecessary) prologue/epilogue. For example, compare the code generated by these two functions:
|
|
1381
|
+
```c
|
|
1382
|
+
volatile range none pageformat default volatile __data unsigned char counter;
|
|
1383
|
+
|
|
1384
|
+
void simpleInterrupt(void) __interrupt range none pageformat default interrupt range none pageformat default interrupt (1)
|
|
1385
|
+
{
|
|
1386
|
+
counter++;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
void nakedInterrupt(void) __interrupt (2) __naked
|
|
1390
|
+
{
|
|
1391
|
+
__asm range none pageformat default asm
|
|
1392
|
+
inc _counter; does not change flags, no need to save psw
|
|
1393
|
+
reti; MUST explicitly include ret or reti in _naked function.
|
|
1394
|
+
__endasm range none pageformat default endasm;
|
|
1395
|
+
}
|
|
1396
|
+
```
|
|
1397
|
+
For an 8051 target, the generated simpleInterrupt looks like:
|
|
1398
|
+
|
|
1399
|
+
Note, this is an *outdated* example, recent versions of SDCC generate
|
|
1400
|
+
the *same* code for simpleInterrupt() and nakedInterrupt()!
|
|
1401
|
+
```asm
|
|
1402
|
+
_simpleInterrupt:
|
|
1403
|
+
push acc
|
|
1404
|
+
push b
|
|
1405
|
+
push dpl
|
|
1406
|
+
push dph
|
|
1407
|
+
push psw
|
|
1408
|
+
mov psw,#0x00
|
|
1409
|
+
inc _counter
|
|
1410
|
+
pop psw
|
|
1411
|
+
pop dph
|
|
1412
|
+
pop dpl
|
|
1413
|
+
pop b
|
|
1414
|
+
pop acc
|
|
1415
|
+
reti
|
|
1416
|
+
```
|
|
1417
|
+
whereas nakedInterrupt looks like:
|
|
1418
|
+
```asm
|
|
1419
|
+
_nakedInterrupt:
|
|
1420
|
+
inc _counter; does not change flags, no need to save psw
|
|
1421
|
+
reti; MUST explicitly include ret or reti in _naked function
|
|
1422
|
+
```
|
|
1423
|
+
The related directive #pragma exclude range none pageformat default pragma exclude allows a more fine grained control over pushing & popping range none pageformat default push/pop the registers.
|
|
1424
|
+
|
|
1425
|
+
While there is nothing preventing you from writing C code inside a _naked function, there are many ways to shoot yourself in the foot doing this, and it is recommended that you stick to inline assembler.
|
|
1426
|
+
|
|
1427
|
+
#### Use of Labels within Inline Assembler
|
|
1428
|
+
|
|
1429
|
+
SDCC allows the use of in-line assembler with a few restrictions regarding labels. All labels defined within inline assembler code have to be of the form *nnnnn$* where nnnnn is a number less than 100 (which implies a limit of utmost 100 inline assembler labels *per function*). This is a slightly more stringent rule than absolutely necessary, but stays always on the safe side. Labels in the form of nnnnn$ are local labels in the assembler, locality of which is confined within two labels of the standard form. The compiler uses the same form for labels within a function (but starting from nnnnn=00100); and places always a standard label at the beginning of a function, thus limiting the locality of labels within the scope of the function. So, if the inline assembler part would be embedded into C-code, an improperly placed non-local label in the assembler would break up the reference space for labels created by the compiler for the C-code, leading to an assembling error. The numeric part of local labels does not need to have 5 digits (although this is the form of labels output by the compiler), any valid integer will do. Please refer to the assemblers documentation for further details.
|
|
1430
|
+
```c
|
|
1431
|
+
__asm range none pageformat default asm
|
|
1432
|
+
mov b,#10
|
|
1433
|
+
00001$:
|
|
1434
|
+
djnz b,00001$
|
|
1435
|
+
__endasm range none pageformat default endasm;
|
|
1436
|
+
```
|
|
1437
|
+
Inline assembler code cannot reference any C-labels, however it can reference labels range none pageformat default Labels defined by the inline assembler, e.g.:
|
|
1438
|
+
```c
|
|
1439
|
+
foo() {
|
|
1440
|
+
/* some c code */
|
|
1441
|
+
__asm
|
|
1442
|
+
; some assembler code
|
|
1443
|
+
ljmp 0003$
|
|
1444
|
+
__endasm;
|
|
1445
|
+
/* some more c code */
|
|
1446
|
+
clabel: /* inline assembler cannot reference this label */ Here, the C-label clabel is translated by the compiler into a local label, so the locality of labels within the function is not broken.
|
|
1447
|
+
__asm
|
|
1448
|
+
0003$:;label (can be referenced by inline assembler only)
|
|
1449
|
+
__endasm range none pageformat default endasm;
|
|
1450
|
+
/* some more c code */
|
|
1451
|
+
}
|
|
1452
|
+
```
|
|
1453
|
+
In other words inline assembly code can access labels defined in inline assembly within the scope of the function. The same goes the other way, i.e. labels defines in inline assembly can not be accessed by C statements.
|
|
1454
|
+
|
|
1455
|
+
### Support routines for integer multiplicative operators
|
|
1456
|
+
|
|
1457
|
+
Depending on the target architecture, some integer multiplicative operators might be implemented by support routines. These support routines exist in portable C versions to facilitate porting to other MCUs, although depending on the target, assembler routines might be used instead. The following files contain some of the described routines, all of them can be found in <installdir>/share/sdcc/lib.
|
|
1458
|
+
|
|
1459
|
+
| Function | Description |
|
|
1460
|
+
| --- | --- |
|
|
1461
|
+
| _mulint.c | 16 bit multiplication |
|
|
1462
|
+
| _divsint.c | signed 16 bit division (calls _divuint) |
|
|
1463
|
+
| _divuint.c | unsigned 16 bit division |
|
|
1464
|
+
| _modsint.c | signed 16 bit modulus (calls _moduint) |
|
|
1465
|
+
| _moduint.c | unsigned 16 bit modulus |
|
|
1466
|
+
| _mullong.c | 32 bit multiplication |
|
|
1467
|
+
| _divslong.c | signed 32 division (calls _divulong) |
|
|
1468
|
+
| _divulong.c | unsigned 32 division |
|
|
1469
|
+
| _modslong.c | signed 32 bit modulus (calls _modulong) |
|
|
1470
|
+
| _modulong.c | unsigned 32 bit modulus |
|
|
1471
|
+
| _modulong.c | unsigned 32 bit modulus |
|
|
1472
|
+
|
|
1473
|
+
In the mcs51, ds390, hc08, s08, pdk13, pdk14, pdk15, pic14 and pic16 backends they are by default compiled as *non-reentrant* range none pageformat default reentrant; when targeting on of these architectures, interrupt range none pageformat default interrupt service routines should not do any of the above operations. If this is unavoidable then the above routines will need to be compiled with the *--stack-auto range none pageformat default --stack-auto* option, after which the source program will have to be compiled with *--int-long-reent range none pageformat default --int-long-reent* option. Notice that you don't have to call these routines directly. The compiler will use them automatically every time an integer operation is required.
|
|
1474
|
+
|
|
1475
|
+
### Floating Point Support range none pageformat default Floating point support
|
|
1476
|
+
|
|
1477
|
+
SDCC supports (single precision 4 bytes) floating point numbers; the format is somewhat similar to IEEE, but it is not IEEE; in particular, denormalized floating -point numbers are not supported. The floating point support routines are derived from gcc's floatlib.c and consist of the following routines:
|
|
1478
|
+
|
|
1479
|
+
| Function | Description |
|
|
1480
|
+
| --- | --- |
|
|
1481
|
+
| _fsadd.c | add floating point numbers |
|
|
1482
|
+
| _fssub.c | subtract floating point numbers |
|
|
1483
|
+
| _fsdiv.c | divide floating point numbers |
|
|
1484
|
+
| _fsmul.c | multiply floating point numbers |
|
|
1485
|
+
| _fs2uchar.c | convert floating point to unsigned char |
|
|
1486
|
+
| _fs2schar.c | convert floating point to signed char |
|
|
1487
|
+
| _fs2uint.c | convert floating point to unsigned int |
|
|
1488
|
+
| _fs2sint.c | convert floating point to signed int |
|
|
1489
|
+
| _fs2ulong. c | convert floating point to unsigned long |
|
|
1490
|
+
| _fs2slong.c | convert floating point to signed long |
|
|
1491
|
+
| _uchar2fs.c | convert unsigned char to floating point |
|
|
1492
|
+
| _schar2fs.c | convert signed char to floating point |
|
|
1493
|
+
| _uint2fs.c | convert unsigned int to floating point |
|
|
1494
|
+
| _sint2fs.c | convert signed int to floating point |
|
|
1495
|
+
| _ulong2fs.c | convert unsigned long to floating point |
|
|
1496
|
+
| _slong2fs.c | convert signed long to floating point |
|
|
1497
|
+
| _ulonglong2fs.c | convert unsigned long long to floating point |
|
|
1498
|
+
| _slonglong2fs.c | convert singed long long to floating point |
|
|
1499
|
+
| _slonglong2fs.c | convert singed long long to floating point |
|
|
1500
|
+
|
|
1501
|
+
### Library Routines range none pageformat default Libraries
|
|
1502
|
+
|
|
1503
|
+
*this is messy and incomplete - a little more information is at* http://sdcc.sourceforge.net/wiki/index.php/List_of_the_SDCC_library >
|
|
1504
|
+
|
|
1505
|
+
#### Compiler support routines (_gptrget, _mulint etc.)
|
|
1506
|
+
|
|
1507
|
+
#### Stdclib functions (puts, printf, strcat etc.)
|
|
1508
|
+
|
|
1509
|
+
#####
|
|
1510
|
+
|
|
1511
|
+
`getchar()`, `putchar()`
|
|
1512
|
+
|
|
1513
|
+
range none pageformat default As usual on embedded systems you have to provide your own getchar() range none pageformat default getchar() and putchar() range none pageformat default putchar() range none pageformat default printf()!putchar() routines. SDCC does not know whether the system connects to a serial line with or without handshake, LCD, keyboard or other device. And whether a lf to crlf conversion within putchar() is intended. You'll find examples for serial routines f.e. in sdcc/device/lib. For the mcs51 this minimalistic polling putchar() routine might be a start:
|
|
1514
|
+
```c
|
|
1515
|
+
int putchar (int c) {
|
|
1516
|
+
while (!TI) /* assumes UART is initialized */
|
|
1517
|
+
;
|
|
1518
|
+
TI = 0;
|
|
1519
|
+
SBUF = c;
|
|
1520
|
+
|
|
1521
|
+
return c;
|
|
1522
|
+
}
|
|
1523
|
+
```
|
|
1524
|
+
|
|
1525
|
+
`printf()`
|
|
1526
|
+
|
|
1527
|
+
The default printf() range none pageformat default printf() implementation in printf_large.c does not support float range none pageformat default Floating point support (except on ds390), only <NO FLOAT> range none pageformat default range none pageformat default printf()!floating point support will be printed instead of the value. To enable floating point output, recompile it with the option *- DUSE_FLOATS=1 range none pageformat default USE FLOATS* on the command line. Use *--model-large range none pageformat default --model-large* for the mcs51 port, since this uses a lot of memory. To enable float support for the pic16 targets, see Libraries.
|
|
1528
|
+
|
|
1529
|
+
If you're short on code memory you might want to use printf_small() range none pageformat default printf()!printf small() *instead* of printf(). For the mcs51 there additionally are assembly versions printf_tiny() range none pageformat default printf()!printf tiny() (mcs51) (subset of printf using less than 270 bytes) and printf_fast() range none pageformat default printf()!printf fast() (mcs51) and printf_fast_f() range none pageformat default printf()!printf fast f() (mcs51) (floating-point aware version of printf_fast) which should fit the requirements of many embedded systems (printf_fast() can be customized by unsetting #defines to *not* support long variables and field widths). Be sure to use only one of these printf options within a project.
|
|
1530
|
+
|
|
1531
|
+
Feature matrix of different *printf* options on mcs51.
|
|
1532
|
+
|
|
1533
|
+
| mcs51 | printf range none pageformat default status collapsed printf() | printf USE_FLOATS=1 | printf_small | printf_fast | printf_fast_f | printf_tiny |
|
|
1534
|
+
| --- | --- | --- | --- | --- | --- | --- |
|
|
1535
|
+
| filename | printf_large.c | printf_large.c | printfl.c | printf_fast.c | printf_fast_f.c | printf_tiny.c |
|
|
1536
|
+
| Hello World size small / large | 1.7k / 2.4k | 4.3k / 5.6k | 1.2k / 1.8k | 1.3k / 1.3k | 1.9k / 1.9k | 0.44k / 0.44k |
|
|
1537
|
+
| code size small / large | 1.4k / 2.0k | 2.8k / 3.7k | 0.45k / 0.47k (+ _ltoa) | 1.2k / 1.2k | 1.6k / 1.6k | 0.26k / 0.26k |
|
|
1538
|
+
| formats | cdi o psux | cd f i o psux | c d o s x | cdsux | cdfsux | cdsux |
|
|
1539
|
+
| long (32 bit) support | x | x | x | x | x | - |
|
|
1540
|
+
| byte arguments on stack | b | b | - | - | - | - |
|
|
1541
|
+
| float format range none pageformat default status collapsed Floating point support | - | %f | - | - | %f status collapsed Range limited to +/- 4294967040, precision limited to 8 digits past decimal | - |
|
|
1542
|
+
| float formats %e %g | - | - | - | - | - | - |
|
|
1543
|
+
| field width | x | x | - | x | x | - |
|
|
1544
|
+
| string speed status collapsed Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', ' r', ' n'); standard 8051 @ 22.1184 MHz, empty putchar(), small / large | 1.52 / 2.59 ms | 1.53 / 2.62 ms | 0.92 / 0.93 ms | 0.45 / 0.45 ms | 0.46 / 0.46 ms | 0.45 / 0.45 ms |
|
|
1545
|
+
| int speed status collapsed Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty putchar(), small / large | 3.01 / 3.61 ms | 3.01 / 3.61 ms | 3.51 / 18.13 ms | 0.22 / 0.22 ms | 0.23 / 0.23 ms | 0.25 / 0.25 ms status collapsed printf_tiny integer speed is data dependent, worst case is 0.33 ms |
|
|
1546
|
+
| long speed status collapsed Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz, empty putchar(), small / large | 5.37 / 6.31 ms | 5.37 / 6.31 ms | 8.71 / 40.65 ms | 0.40 / 0.40 ms | 0.40 / 0.40 ms | - |
|
|
1547
|
+
| float speed status collapsed Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz, empty putchar(), small / large | - | 7.49 / 22.47 ms | - | - | 1.04 / 1.04 ms | - |
|
|
1548
|
+
| float speed status collapsed Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz, empty putchar(), small / large | - | 7.49 / 22.47 ms | - | - | 1.04 / 1.04 ms | - |
|
|
1549
|
+
|
|
1550
|
+
##### range none pageformat default malloc.h
|
|
1551
|
+
|
|
1552
|
+
As of SDCC 2.6.2 you no longer need to call an initialization routine before using dynamic memory allocation range none pageformat default dynamic memory allocation (malloc) and a default heap range none pageformat default heap (malloc) space of 1024 bytes is provided for malloc to allocate memory from. If you need a different heap size you need to recompile _heap.c with the required size defined in HEAP_SIZE. It is recommended to make a copy of this file into your project directory and compile it there with:
|
|
1553
|
+
|
|
1554
|
+
`sdcc -c _heap.c -D HEAP_SIZE=2048`
|
|
1555
|
+
|
|
1556
|
+
And then link it with:
|
|
1557
|
+
|
|
1558
|
+
`sdcc main.rel _heap.rel`
|
|
1559
|
+
|
|
1560
|
+
#### Math functions (sinf, powf, sqrtf etc.)
|
|
1561
|
+
|
|
1562
|
+
#####
|
|
1563
|
+
|
|
1564
|
+
See definitions in file <math.h>.
|
|
1565
|
+
|
|
1566
|
+
#### Other libraries
|
|
1567
|
+
|
|
1568
|
+
Libraries range none pageformat default Libraries included in SDCC should have a license at least as liberal as the GPLv2+LE range none pageformat default GPLv2+LE. Exception are pic device libraries and header files which are derived from Microchip header (.inc) and linker script (.lkr) files. Microchip requires that "The header files should state that they are only to be used with authentic Microchip devices" which makes them incompatible with GPL.
|
|
1569
|
+
|
|
1570
|
+
If you have ported some library or want to share experience about some code which f.e. falls into any of these categories Busses (I $^{\textrm{2}}$ C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG...), Media (IDE, Memory cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel, Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list http://sourceforge.net/p/sdcc/mailman/sdcc-user/ would certainly like to hear about it.
|
|
1571
|
+
|
|
1572
|
+
Programmers coding for embedded systems are not especially famous for being enthusiastic, so don't expect a big hurray but as the mailing list is searchable these references are very valuable. Let's help to create a climate where information is shared.
|
|
1573
|
+
|
|
1574
|
+
### Memory Models
|
|
1575
|
+
|
|
1576
|
+
#### MCS51 Memory Models range none pageformat default Memory model range none pageformat default MCS51 memory model
|
|
1577
|
+
|
|
1578
|
+
##### Small, Medium, Large and Huge
|
|
1579
|
+
|
|
1580
|
+
SDCC allows four memory models for MCS51 code, small, medium, large* and huge*. Modules compiled with different memory models should *never* be combined together or the results would be unpredictable. The library routines supplied with the compiler are compiled for all models (however, the libraries for --stack-auto are compiled for the small and large models only). The compiled library modules are contained in separate directories as small, medium, large and huge so that you can link to the appropriate set.
|
|
1581
|
+
|
|
1582
|
+
When the medium, large or huge model is used all variables declared without specifying an intrinsic named address space will be allocated into the external ram, this includes all parameters and local variables (for non-reentrant range none pageformat default reentrant functions). Medium model uses pdata and large and huge models use xdata. When the small model is used variables without an explicitly specified intrinsic named address space are allocated in the internal ram.
|
|
1583
|
+
|
|
1584
|
+
The huge model compiles all functions as *banked Bankswitching* and is otherwise equal to large for now. All other models compile the functions without bankswitching by default.
|
|
1585
|
+
|
|
1586
|
+
Judicious usage of the processor specific intrinsic named address spaces range none pageformat default intrinsic named address space and the 'reentrant' function type will yield much more efficient code, than using the large model. Several optimizations are disabled when the program is compiled using the large model, it is therefore recommended that the small model be used unless absolutely required.
|
|
1587
|
+
|
|
1588
|
+
##### External Stack range none pageformat default stack range none pageformat default External stack (mcs51)
|
|
1589
|
+
|
|
1590
|
+
The external stack (--xstack option range none pageformat default --xstack) is located in pdata range none pageformat default pdata (mcs51, ds390 named address space) memory (usually at the start of the external ram segment) and uses all unused space in pdata (max. 256 bytes). When --xstack option is used to compile the program, the parameters and local variables range none pageformat default local variables of all reentrant functions are allocated in this area. This option is provided for programs with large stack space requirements. When used with the --stack-auto range none pageformat default --stack-auto option, all parameters and local variables are allocated on the external stack (note: support libraries will need to be recompiled with the same options. There is a predefined target in the library makefile).
|
|
1591
|
+
|
|
1592
|
+
The compiler outputs the higher order address byte of the external ram segment into port P2 range none pageformat default P2 (mcs51 sfr) (see also section MCS51 variants), therefore when using the External Stack option, this port *may not* be used by the application program.
|
|
1593
|
+
|
|
1594
|
+
#### DS390 Memory Model range none pageformat default Memory model range none pageformat default DS390 memory model
|
|
1595
|
+
|
|
1596
|
+
The only model supported is Flat 24 range none pageformat default Flat 24 (DS390 memory model). This generates code for the 24 bit contiguous addressing mode of the Dallas DS80C390 part. In this mode, up to four meg of external RAM or code space can be directly addressed. See the data sheets at www.dalsemi.com for further information on this part.
|
|
1597
|
+
|
|
1598
|
+
Note that the compiler does not generate any code to place the processor into 24 bit mode (although *tinibios* in the ds390 libraries will do that for you). If you don't use *tinibios* range none pageformat default Tinibios (DS390), the boot loader or similar code must ensure that the processor is in 24 bit contiguous addressing mode before calling the SDCC startup code.
|
|
1599
|
+
|
|
1600
|
+
Like the *--model-large* option, variables will by default be placed into the XDATA segment.
|
|
1601
|
+
|
|
1602
|
+
Segments may be placed anywhere in the 4 meg address space using the usual --*-loc options. Note that if any segments are located above 64K, the -r flag must be passed to the linker to generate the proper segment relocations, and the Intel HEX output format must be used. The -r flag can be passed to the linker by using the option *-Wl-r* on the SDCC command line. However, currently the linker can not handle code segments > 64k.
|
|
1603
|
+
|
|
1604
|
+
#### STM8 Memory Models range none pageformat default Memory model range none pageformat default STM8 memory models
|
|
1605
|
+
|
|
1606
|
+
SDCC implements two memory models for the STM8: *medium* (default) and *large*. Modules compiled with different memory models should *never* be combined together. The library routines supplied with the compiler are compiled for all models.
|
|
1607
|
+
|
|
1608
|
+
In the medium model the address space is 16 bits for both objects and functions, allowing for a memory space of 64 KB. Since the STM8 typically has Flash starting at 0x8000, this means that only up to 32 KB of Flash can be used (most STM8 devices don't have more than 32 KB of Flash).
|
|
1609
|
+
|
|
1610
|
+
In the large memory model, the address space is 16 bits for objects and 24 bits for functions. Since the STM8 typically has flash starting at 0x8000, this means that up to 32 KB of flash can be used for constant data, while the whole Flash can be used for functions. Code generated for the large model is slightly bigger and slower and needs slightly more stack space than code generated for the medium model.
|
|
1611
|
+
|
|
1612
|
+
#### MOS6502 Memory Models range none pageformat default Memory model range none pageformat default MOS6502 memory models
|
|
1613
|
+
|
|
1614
|
+
SDCC implements two memory models for the MOS6502: *small* and *large* (default). Modules compiled with different memory models should *never* be combined together. The library routines supplied with the compiler are compiled for all models.
|
|
1615
|
+
|
|
1616
|
+
In the small model all data objects are placed by default in Page Zero. This is normally only useful in embedded systems.
|
|
1617
|
+
|
|
1618
|
+
In the large memory model, data is placed by default in 16-bit addressable memory. Critical data can still be placed in Page Zero using the __ZP or __near storage modifier. Code generated for the large model is slightly bigger and slower than code generated for the small model.
|
|
1619
|
+
|
|
1620
|
+
### Pragmas range none pageformat default Pragmas
|
|
1621
|
+
|
|
1622
|
+
Pragmas are used to turn on and/or off certain compiler options. Some of them are closely related to corresponding command-line options (see section Command Line Options).
|
|
1623
|
+
Pragmas should be placed before and/or after a function, placing pragmas inside a function body could have unpredictable results.
|
|
1624
|
+
|
|
1625
|
+
SDCC supports the following #pragma directives:
|
|
1626
|
+
|
|
1627
|
+
- **save** range none pageformat default pragma save- this will save most current options to the save/restore stack. See #pragma restore.
|
|
1628
|
+
- **restore** range none pageformat default pragma restore- will restore saved options from the last save. saves & restores can be nested. SDCC uses a save/restore stack: save pushes current options to the stack, restore pulls current options from the stack. See #pragma save.
|
|
1629
|
+
- **callee_saves** range none pageformat default pragma callee saves range none pageformat default function prologue function1[,function2[,function3...]]- The compiler by default uses a caller saves convention for register saving across function calls, however this can cause unnecessary register pushing and popping range none pageformat default push/pop when calling small functions from larger functions. This option can be used to switch off the register saving convention for the function names specified. The compiler will not save registers when calling these functions, extra code need to be manually inserted at the entry and exit for these functions to save and restore the registers used by these functions, this can SUBSTANTIALLY reduce code and improve run time performance of the generated code. In the future the compiler (with inter procedural analysis) may be able to determine the appropriate scheme to use for each function call. If --callee-saves command line option is used (see page Other Options), the function names specified in #pragma callee_saves range none pageformat default pragma callee saves is appended to the list of functions specified in the command line.
|
|
1630
|
+
- **exclude** range none pageformat default pragma exclude none | {acc[,b[,dpl[,dph[,bits]]]]} - The exclude pragma disables the generation of pairs of push/pop range none pageformat default push/pop instructions in *I* nterrupt range none pageformat default interrupt *S* ervice *R* outines. The directive should be placed immediately before the ISR function definition and it affects ALL ISR functions following it. To enable the normal register saving for ISR functions use #pragma exclude none range none pageformat default pragma exclude. See also the related keyword *__naked* range none pageformat default naked range none pageformat default naked.
|
|
1631
|
+
- **less_pedantic** range none pageformat default pedantic range none pageformat default pragma less pedantic- the compiler will not warn you anymore for obvious mistakes, you're on your own now;-(. See also the command line option --less-pedantic Other Options.
|
|
1632
|
+
More specifically, the following warnings will be disabled: *comparison is always [true/false] due to limited range of data type* (94); *overflow in implicit constant conversion* (158); [the (in)famous] *conditional flow changed by optimizer: so said EVELYN the modified DOG* (110); *function '[function name]' must return value* (59).
|
|
1633
|
+
Furthermore, warnings of less importance (of PEDANTIC and INFO warning level) are disabled, too, namely: *constant value '[dunno what comes here - this warning appears to be unused altogether]', out of range* (81); *[left/right] shifting more than size of object changed to zero* (116); *unreachable code* (126); *integer overflow in expression* (165); *unmatched #pragma save and #pragma restore* (170); *comparison of 'signed char' with 'unsigned char' requires promotion to int* (185); *ISO C90 does not support flexible array members* (187); *extended stack by [number] bytes for compiler temp(s):in function '[function name]': [appears to be always blank - what was supposed to be here* (114); *function '[function name]', # edges [number], # nodes [number], cyclomatic complexity [number]* (121).
|
|
1634
|
+
- **disable_warning** range none pageformat default pragma disable warning- the compiler will not warn you anymore about warning number <nnnn>.
|
|
1635
|
+
- **nogcse** range none pageformat default pragma nogcse- will stop global common subexpression elimination.
|
|
1636
|
+
- **noinduction** range none pageformat default pragma noinduction- will stop loop induction optimizations.
|
|
1637
|
+
- **noinvariant** range none pageformat default pragma noinvariant- will not do loop invariant optimizations. For more details see Loop Invariants in section Loop Optimizations.
|
|
1638
|
+
- **noiv** range none pageformat default pragma noiv- Do not generate interrupt range none pageformat default interrupt vector table range none pageformat default interrupt vector table entries for all ISR functions defined after the pragma. This is useful in cases where the interrupt vector table must be defined manually, or when there is a secondary, manually defined interrupt vector table (e.g. for the autovector feature of the Cypress EZ-USB FX2). More elegantly this can be achieved by omitting the optional interrupt number after the *__interrupt* keyword, see section Interrupt Service Routines about interrupts.
|
|
1639
|
+
- **noloopreverse** range none pageformat default pragma noloopreverse- Will not do loop reversal optimization
|
|
1640
|
+
- **nooverlay** range none pageformat default pragma nooverlay- the compiler will not overlay the parameters and local variables of a function.
|
|
1641
|
+
- **stackauto** range none pageformat default pragma stackauto- See option --stack-auto range none pageformat default --stack-auto and section Parameters Parameters and Local Variables.
|
|
1642
|
+
- **opt_code_speed** range none pageformat default pragma opt code speed- The compiler will optimize code generation towards fast code, possibly at the expense of code size.
|
|
1643
|
+
- **opt_code_size** range none pageformat default pragma opt code size- The compiler will optimize code generation towards compact code, possibly at the expense of code speed.
|
|
1644
|
+
- **opt_code_balanced** range none pageformat default pragma opt code balanced- The compiler will attempt to generate code that is both compact and fast, as long as meeting one goal is not a detriment to the other (this is the default).
|
|
1645
|
+
- **std_sdcc89** range none pageformat default pragma std sdcc89- Generally follow the C89 standard, but allow SDCC features that conflict with the standard.
|
|
1646
|
+
- **std_c89** range none pageformat default pragma std c89- Follow the C89 standard and disable SDCC features that conflict with the standard.
|
|
1647
|
+
- **std_sdcc99** range none pageformat default pragma std sdcc99- Generally follow the C99 standard, but allow SDCC features that conflict with the standard.
|
|
1648
|
+
- **std_c99** range none pageformat default pragma std c99- Follow the C99 standard and disable SDCC features that conflict with the standard.
|
|
1649
|
+
- **std_c11** range none pageformat default pragma std c11- Follow the C11 standard and disable SDCC features that conflict with the standard.
|
|
1650
|
+
- **std_sdcc11** range none pageformat default pragma std sdcc11- Generally follow the C11 standard, but allow SDCC features that conflict with the standard.
|
|
1651
|
+
- **std_c23** range none pageformat default pragma std c23- Follow the C23 standard and disable SDCC features that conflict with the standard (for backwards compatibility, **std_c2x** still exists as an alias).
|
|
1652
|
+
- **std_sdcc23** range none pageformat default pragma std sdcc23- Generally follow the C23 standard, but allow SDCC features that conflict with the standard.
|
|
1653
|
+
- **std_c2** y range none pageformat default pragma std c2y- Follow the C2y standard and disable SDCC features that conflict with the standard.
|
|
1654
|
+
- **std_sdcc2y** range none pageformat default pragma std sdcc2y- Generally follow the C2y standard, but allow SDCC features that conflict with the standard.
|
|
1655
|
+
- **codeseg** range none pageformat default pragma codeseg- Use this name (max. 8 characters) for the code segment. See option --codeseg.
|
|
1656
|
+
- **constseg** range none pageformat default pragma constseg- Use this name (max. 8 characters) for the const segment. See option --constseg.
|
|
1657
|
+
The preprocessor range none pageformat default Preprocessor SDCPP range none pageformat default sdcpp (preprocessor) supports the following #pragma directives:
|
|
1658
|
+
|
|
1659
|
+
- **preproc_asm** range none pageformat default pragma preproc asm (+ | -) - switch the __asm __endasm block preprocessing on / off. Default is on. Below is an example on how to use this pragma.
|
|
1660
|
+
#pragma preproc_asm - range none pageformat default pragma preproc asm
|
|
1661
|
+
```c
|
|
1662
|
+
/* this is a c code nop */
|
|
1663
|
+
#define NOP;
|
|
1664
|
+
|
|
1665
|
+
void foo (void)
|
|
1666
|
+
{
|
|
1667
|
+
...
|
|
1668
|
+
while (--i)
|
|
1669
|
+
NOP
|
|
1670
|
+
...
|
|
1671
|
+
__asm
|
|
1672
|
+
; this is an assembler nop instruction
|
|
1673
|
+
; it is not preprocessed to ';' since the asm preprocessing is disabled
|
|
1674
|
+
NOP
|
|
1675
|
+
__endasm;
|
|
1676
|
+
...
|
|
1677
|
+
}
|
|
1678
|
+
```
|
|
1679
|
+
The pragma preproc_asm should not be used to define multilines of assembly code (even if it supports it), since this behavior is only a side effect of sdcpp __asm __endasm implementation in combination with pragma preproc_asm and is not in conformance with the C standard. This behavior might be changed in the future sdcpp versions. To define multilines of assembly code you have to include each assembly line into it's own __asm __endasm block. Below is an example for multiline assembly defines.
|
|
1680
|
+
```c
|
|
1681
|
+
#define Nop __asm\
|
|
1682
|
+
nop\
|
|
1683
|
+
__endasm
|
|
1684
|
+
|
|
1685
|
+
#define ThreeNops Nop;\
|
|
1686
|
+
Nop;\
|
|
1687
|
+
Nop
|
|
1688
|
+
|
|
1689
|
+
void foo (void)
|
|
1690
|
+
{
|
|
1691
|
+
...
|
|
1692
|
+
ThreeNops;
|
|
1693
|
+
...
|
|
1694
|
+
}
|
|
1695
|
+
```
|
|
1696
|
+
- **sdcc_hash** range none pageformat default pragma sdcc hash (+ | -) - Until SDCC 4.2.8: Allow "naked" hash in macro definition, for example:
|
|
1697
|
+
```c
|
|
1698
|
+
#define DIR_LO(x) #(x & 0xff)
|
|
1699
|
+
//Default is off. Below is an example on how to use this pragma.
|
|
1700
|
+
#pragma preproc_asm +
|
|
1701
|
+
#pragma sdcc_hash + range none pageformat default pragma sdcc hash
|
|
1702
|
+
|
|
1703
|
+
#define ROMCALL(x)\
|
|
1704
|
+
mov R6_B3, #(x & 0xff)\
|
|
1705
|
+
mov R7_B3, #((x >> 8) & 0xff)\
|
|
1706
|
+
lcall __romcall
|
|
1707
|
+
|
|
1708
|
+
...
|
|
1709
|
+
__asm
|
|
1710
|
+
ROMCALL(72)
|
|
1711
|
+
__endasm;
|
|
1712
|
+
...
|
|
1713
|
+
```
|
|
1714
|
+
|
|
1715
|
+
Some of the pragmas are intended to be used to turn-on or off certain optimizations which might cause the compiler to generate extra stack and/or data space to store compiler generated temporary variables. This usually happens in large functions. Pragma directives should be used as shown in the following example, they are used to control options and optimizations for a given function.
|
|
1716
|
+
```c
|
|
1717
|
+
#pragma save range none pageformat default pragma save /* save the current settings */
|
|
1718
|
+
#pragma nogcse range none pageformat default pragma nogcse /* turnoff global subexpression elimination */
|
|
1719
|
+
#pragma noinduction range none pageformat default pragma noinduction /* turn off induction optimizations */
|
|
1720
|
+
int foo ()
|
|
1721
|
+
{
|
|
1722
|
+
...
|
|
1723
|
+
/* large code */
|
|
1724
|
+
...
|
|
1725
|
+
}
|
|
1726
|
+
#pragma restore range none pageformat default pragma restore /* turn the optimizations back on */
|
|
1727
|
+
```
|
|
1728
|
+
The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the save and restore pragmas be used when changing options for a function.
|
|
1729
|
+
|
|
1730
|
+
### Defines Created by the Compiler
|
|
1731
|
+
|
|
1732
|
+
Besides defines from the C standards, the compiler creates the following #defines range none pageformat default defines range none pageformat default Defines created by the compiler:
|
|
1733
|
+
|
|
1734
|
+
| #define | Description |
|
|
1735
|
+
| --- | --- |
|
|
1736
|
+
| __SDCC range none pageformat default status collapsed SDCC!Defines!__SDCC (version macro) range none pageformat default status collapsed version macro | Always defined. Version number string (e.g. SDCC_3_2_0 for sdcc 3.2.0). |
|
|
1737
|
+
| SDCC | OBSOLETE. WILL BE REMOVED IN THE FUTURE. CURRENTLY Only defined for the mcs51 backend (and only if --std-cXX is not used). This macro has been available since SDCC 2.5.6 and is the version number as an int (ex. 256). PLEASE USE OTHER VERSION MACROS INSTEAD! |
|
|
1738
|
+
| __SDCC_mcs51 range none pageformat default status collapsed SDCC!Defines!__SDCC mcs51 or __SDCC_ds390 range none pageformat default status collapsed SDCC!Defines!__SDCC ds390 or __SDCC_z80 range none pageformat default status collapsed SDCC!Defines!__SDCC z80, etc. | depending on the model used (e.g.: -mds390). Older versions used SDCC_mcs51, etc instead. |
|
|
1739
|
+
| __SDCC_STACK_AUTO range none pageformat default status collapsed SDCC!Defines!SDCC STACK AUTO | when - -stack-auto option is used |
|
|
1740
|
+
| __SDCC_MODEL_SMALL range none pageformat default status collapsed SDCC!Defines!SDCC MODEL SMALL | when - -model-small is used |
|
|
1741
|
+
| __SDCC_MODEL_MEDIUM range none pageformat default status collapsed SDCC!Defines!SDCC MODEL MEDIUM | when - -model-medium is used |
|
|
1742
|
+
| __SDCC_MODEL_LARGE range none pageformat default status collapsed SDCC!Defines!SDCC MODEL LARGE | when - -model-large is used |
|
|
1743
|
+
| __SDCC_MODEL_HUGE range none pageformat default status collapsed SDCC!Defines!SDCC MODEL LARGE | when - -model-huge is used |
|
|
1744
|
+
| __SDCC_USE_XSTACK range none pageformat default status collapsed SDCC!Defines!SDCC USE XSTACK | when - -xstack option is used |
|
|
1745
|
+
| __SDCC_STACK_TENBIT range none pageformat default status collapsed SDCC!Defines!SDCC STACK TENBIT (ds390) | when -mds390 is used |
|
|
1746
|
+
| __SDCC_MODEL_FLAT24 range none pageformat default status collapsed SDCC!Defines!SDCC MODEL FLAT24 (ds390) | when -mds390 is used |
|
|
1747
|
+
| __SDCC_VERSION_MAJOR | Always defined. SDCC major version number. E.g. 3 for SDCC 3.5.0 |
|
|
1748
|
+
| __SDCC_VERSION_MINOR | Always defined. SDCC minor version number. E.g. 5 for SDCC 3.5.0 |
|
|
1749
|
+
| __SDCC_VERSION_PATCH | Always defined. SDCC patchlevel version number. E.g. 0 for SDCC 3.5.0 |
|
|
1750
|
+
| __SDCC_REVISION range none pageformat default status collapsed SDCC!Defines!SDCC REVISION (svn revision number) | Always defined. SDCC svn revision number. Older versions of sdcc used SDCC_REVISION instead. |
|
|
1751
|
+
| SDCC_PARMS_IN_BANK1 range none pageformat default status collapsed SDCC!Defines!SDCC PARMS IN BANK1 | when - -parms-in-bank1 is used |
|
|
1752
|
+
| __SDCC_ALL_CALLEE_SAVES range none pageformat default status collapsed SDCC!Defines!SDCC ALL CALLEE SAVES | when - -all-callee-saves is used |
|
|
1753
|
+
| __SDCC_FLOAT_REENT range none pageformat default status collapsed SDCC!Defines!SDCC FLOAT REENT | when - -float-reent is used |
|
|
1754
|
+
| __SDCC_INT_LONG_REENT range none pageformat default status collapsed SDCC!Defines!SDCC INT LONG REENT | when - -int-long-reent is used |
|
|
1755
|
+
| __SDCC_OPTIMIZE_SPEED range none pageformat default status collapsed SDCC!Defines!SDCC OPTIMIZE SPEED | when - -opt-code-speed is used |
|
|
1756
|
+
| __SDCC_OPTIMIZE_SIZE range none pageformat default status collapsed SDCC!Defines!SDCC OPTIMIZE SIZE | when - -opt-code-size is used |
|
|
1757
|
+
| __SDCCCALL range none pageformat default status collapsed SDCC!Defines!SDCCCALL | Default ABI version for calling convention |
|
|
1758
|
+
| __SDCCCALL range none pageformat default status collapsed SDCC!Defines!SDCCCALL | Default ABI version for calling convention |
|