* doc/sdccman.lyx:
[fw/sdcc] / doc / sdccman.lyx
index 00103867b0e7a6bc08d26a7372184cfdb5899ba5..199904bdfbea1d0eb9c37bd54c0cc93623b2454f 100644 (file)
@@ -104,13 +104,13 @@ SDCC Compiler User Guide
 \begin_layout Date
 
 \size normal
-SDCC 2.8.0
+SDCC 2.8.5
 \size footnotesize
 
 \newline
-$Date::             
+$Date: 2008-11-16#
 \newline
-$Revision$
+$Revision: 5272$
 \end_layout
 
 \begin_layout Standard
@@ -1158,10 +1158,168 @@ b = !b; /* toggles b */
 In previous versions, both forms would have toggled the bit.
 \end_layout
 
+\begin_layout Itemize
+in older versions, the preprocessor was always called with 
+\series bold
+-
+\begin_inset ERT
+status collapsed
+
 \begin_layout Standard
 
-\emph on
-<pending: more incompatibilities?>
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-std-c99
+\begin_inset LatexCommand \index{-\/-std-c99}
+
+\end_inset
+
+
+\series default
+ regardless of the 
+\series bold
+-
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-std-xxx
+\series default
+ setting.
+ This is no longer true, and can cause compilation failures on code built
+ with 
+\series bold
+-
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-std-c89
+\begin_inset LatexCommand \index{-\/-std-c89}
+
+\end_inset
+
+
+\series default
+ but using c99 preprocessor features, such as one-line (//) comments
+\end_layout
+
+\begin_layout Itemize
+in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
+ functions supported undocumented and not standard compliant 'b' binary
+ format specifier ("%b", "%hb" and "%lb").
+ The 'b' specifier is now disabled by default.
+ It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
+libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
+g the library.
+\end_layout
+
+\begin_layout Itemize
+in versions older then 2.8.5 the unnamed bitfield structure members participated
+ in initialization, which is not conforming with ISO/IEC 9899:1999 standard
+ (see section Section 6.7.8 Initialization, clause 9)
+\newline
+
+\newline
+Old behavior, before
+ version 2.8.5:
+\family typewriter
+
+\newline
+\InsetSpace ~
+\InsetSpace ~
+struct {
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+int a : 2;
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+char\InsetSpace ~
+ : 2;
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+int b : 2;
+\newline
+\InsetSpace ~
+\InsetSpace ~
+} s = {1, 2, 3};
+\family default
+
+\newline
+
+\family typewriter
+/* s.a = 1, s.b = 3 */
+\family default
+
+\newline
+
+\newline
+New behavior:
+\family typewriter
+
+\newline
+\InsetSpace ~
+\InsetSpace ~
+struct {
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+int a : 2;
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+char\InsetSpace ~
+ : 2;
+\newline
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+\InsetSpace ~
+int b : 2;
+\newline
+\InsetSpace ~
+\InsetSpace ~
+} s = {1, 2};
+\family default
+
+\newline
+
+\family typewriter
+/* s.a = 1, s.b = 2 */
 \end_layout
 
 \begin_layout Section
@@ -1682,6 +1840,24 @@ status collapsed
  Lower runtime footprint.
 \end_layout
 
+\begin_layout List
+\labelwidthstring 00.00.0000
+-
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-without-ccache Do not use ccache even if available
+\end_layout
+
 \begin_layout Standard
 Furthermore the environment variables CC, CFLAGS, ...
  the tools and their arguments can be influenced.
@@ -8028,6 +8204,11 @@ linkOption[,linkOption]
 
 \end_inset
 
+
+\begin_inset LatexCommand \label{lyx:-Wl option}
+
+\end_inset
+
 ...
  Pass the linkOption to the linker.
  If a bootloader is used an option like 
@@ -8040,6 +8221,8 @@ linkOption[,linkOption]
 \end_inset
 
  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 
 \begin_inset LatexCommand \ref{sec:Pragmas}
 
@@ -10828,6 +11011,11 @@ status collapsed
 
 \end_inset
 
+
+\begin_inset LatexCommand \label{lyx:-codeseg}
+
+\end_inset
+
 \InsetSpace ~
 <Name> The name to be used for the code
 \begin_inset LatexCommand \index{code}
@@ -13203,6 +13391,31 @@ The xdata storage class declares a variable that can reside anywhere in
 \end_inset
 
 
+\end_layout
+
+\begin_layout Section
+Other SDCC language extensions
+\begin_inset LatexCommand \index{Other SDCC language extensions}
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Subsection
+Binary constants
+\end_layout
+
+\begin_layout Standard
+SDCC supports the use of binary constants, such as 0b01100010.
+ This feature is only enabled when the compiler is invoked using --std-sdccxx.
+\end_layout
+
+\begin_layout Standard
+\begin_inset VSpace bigskip
+\end_inset
+
+
 \end_layout
 
 \begin_layout Section
@@ -23592,9 +23805,11 @@ SiLabs C8051F120 example
 \newline
 Usually the hardware uses some sfr (an output port or an internal sfr) to
  select a bank and put it in the banked area of the memory map.
- Because the selected bank usually becomes active immediately you cannot
- jump call directly from one bank to another and need to use a so-called
- trampoline in the common area.
+ The selected bank usually becomes active immediately upon assignment to
+ this sfr and when running inside a bank it will switch out this code it
+ is currently running.
+ Therefor you cannot jump or call directly from one bank to another and
+ need to use a so-called trampoline in the common area.
  For SDCC an example trampoline is in crtbank.asm and you may need to change
  it to your 8051 derivative or schematic.
  The presented code is written for the C8051F120.
@@ -23603,11 +23818,18 @@ Usually the hardware uses some sfr (an output port or an internal sfr) to
 \newline
 When calling a banked function
  SDCC will put the LSB of the functions address in register R0, the MSB
- in R1 and the bank in R2 and then call this trampoline __sdcc_banked_call.
+ in R1 and the bank in R2 and then call this trampoline 
+\emph on
+__sdcc_banked_call
+\emph default
+.
  The current selected bank is saved on the stack, the new bank is selected
  and an indirect jump is made.
- When the banked function returns it jumps to __sdcc_banked_ret which restores
- the previous bank and returns to the caller.
+ When the banked function returns it jumps to 
+\emph on
+__sdcc_banked_ret
+\emph default
+ which restores the previous bank and returns to the caller.
 \end_layout
 
 \begin_layout Subsubsection
@@ -23622,10 +23844,22 @@ When writing banked software using SDCC you need to use some special keywords
 
 \newline
 To create a function
- that can be called from another bank it requires the keyword banked.
+ that can be called from another bank it requires the keyword 
+\emph on
+banked
+\emph default
+
+\begin_inset LatexCommand \index{banked}
+
+\end_inset
+
+.
  The caller must see this in the prototype of the callee and the callee
  needs it for a proper return.
- Called functions within the same bank as the caller do not need the banked
+ Called functions within the same bank as the caller do not need the 
+\emph on
+banked
+\emph default
  keyword nor do functions in the common area.
  Beware: SDCC does not know or check if functions are in the same bank.
  This is your responsibility!
@@ -23644,8 +23878,30 @@ Normally all functions you write end up in
 Functions that need to be in a switched bank must be put in a named segment.
  The name can be mostly anything upto eight characters (e.g.
  BANK1).
- To do this you either use --codeseg BANK1 on the command line when compiling
- or #pragma codeseg BANK1 at the top of the C source file.
+ To do this you either use -
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+/
+\end_layout
+
+\end_inset
+
+-codeseg BANK1 (See 
+\begin_inset LatexCommand \ref{lyx:-codeseg}
+
+\end_inset
+
+) on the command line when compiling or #pragma codeseg BANK1 (See 
+\begin_inset LatexCommand \ref{sec:Pragmas}
+
+\end_inset
+
+) at the top of the C source file.
  The segment name always applies to the whole source file and generated
  object so functions for different banks need to be defined in different
  source files.
@@ -23655,7 +23911,12 @@ Functions that need to be in a switched bank must be put in a named segment.
 When linking your objects you need to tell the linker where
  to put your segments.
  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
-00.
+00 (See 
+\begin_inset LatexCommand \ref{lyx:-Wl option}
+
+\end_inset
+
+).
  This sets the virtual start address of this segment.
  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
  The linker will not check for overflows, again this is your responsibility.
@@ -23829,6 +24090,7 @@ The PIC14 port adds support for Microchip
 \end_layout
 
 \begin_layout Standard
+\noindent
 Currently supported devices include:
 \end_layout
 
@@ -23884,6 +24146,7 @@ Currently supported devices include:
 \end_layout
 
 \begin_layout Standard
+\noindent
 An up-to-date list of currently supported devices can be obtained via 
 \family typewriter
 sdcc -mpic14 -phelp foo.c
@@ -24440,21 +24703,44 @@ The PIC16 port adds support for Microchip
 \end_layout
 
 \begin_layout Standard
-18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
- 2620
+18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
+ 24j10
+\end_layout
+
+\begin_layout Standard
+18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
+ 2680, 2682, 2685
 \end_layout
 
 \begin_layout Standard
-18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
- 45j10, 4620
+18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
+ 44j10
 \end_layout
 
 \begin_layout Standard
-18F: 6520, 6620, 6680, 6720
+18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
+ 4680, 4682, 4685
 \end_layout
 
 \begin_layout Standard
-18F: 8520, 8620, 8680, 8720
+18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
+\end_layout
+
+\begin_layout Standard
+18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
+\end_layout
+
+\begin_layout Standard
+18F: 96j60, 96j65, 97j60
+\end_layout
+
+\begin_layout Standard
+\noindent
+An up-to-date list of supported devices is also available via '
+\family typewriter
+sdcc -mpic16 -plist
+\family default
+'.
 \end_layout
 
 \begin_layout Subsection
@@ -24715,7 +25001,7 @@ status collapsed
 
 \end_inset
 
--optimize-goto Try to use (conditional) BRA instead of GOTO.
+-no-optimize-goto Do not use (conditional) BRA instead of GOTO.
 \end_layout
 
 \begin_layout Description
@@ -25237,6 +25523,7 @@ nnn = SMALL or LARGE respectively according to the stack model used
 \end_layout
 
 \begin_layout Standard
+\noindent
 In addition the following macros are defined when calling assembler:
 \end_layout
 
@@ -25845,6 +26132,7 @@ libdebug
 \end_layout
 
 \begin_layout Standard
+\noindent
 This feature allows for linking with specific libraries withoug having to
  explicit name them in the command line.
  Note that the 
@@ -26042,6 +26330,11 @@ The specific microcontroller is selected within the pic18fregs.h automatically,
 
 \begin_layout Subsection
 Libraries
+\begin_inset LatexCommand \label{sub:pic16Libraries}
+
+\end_inset
+
+
 \end_layout
 
 \begin_layout Standard
@@ -26067,6 +26360,7 @@ xxxx
 \end_layout
 
 \begin_layout Standard
+\noindent
 Libraries are created with gplib which is part of the gputils package 
 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
 
@@ -26081,13 +26375,11 @@ Building the libraries
 
 \begin_layout Standard
 Before using SDCC/pic16 there are some libraries that need to be compiled.
- This process is not done automatically by SDCC since not all users use
- SDCC for pic16 projects.
- So each user should compile the libraries separately.
-\end_layout
-
-\begin_layout Standard
-The steps to compile the pic16 libraries under Linux and Mac OS X are:
+ This process is done automatically if gputils are found at SDCC's compile
+ time.
+ Should you require to rebuild the pic16 libraries manually, these are the
+ steps required to do so under Linux or Mac OS X (cygwin might work as well,
+ but is untested):
 \end_layout
 
 \begin_layout LyX-Code
@@ -26095,11 +26387,7 @@ cd device/lib/pic16
 \end_layout
 
 \begin_layout LyX-Code
-./configure
-\end_layout
-
-\begin_layout LyX-Code
-make
+./configure.gnu
 \end_layout
 
 \begin_layout LyX-Code
@@ -26114,6 +26402,10 @@ make model-pic16
 su -c 'make install'     # install the libraries, you need the root password
 \end_layout
 
+\begin_layout LyX-Code
+cd ../..
+\end_layout
+
 \begin_layout Standard
 If you need to install the headers too, do:
 \end_layout
@@ -26126,26 +26418,6 @@ cd device/include
 su -c 'make install'     # install the headers, you need the root password
 \end_layout
 
-\begin_layout Standard
-There exist a special target to build the I/O libraries.
- This target is not automatically build because it will build the I/O library
- for 
-\emph on
-every
-\emph default
- supported device.
- This way building will take quite a lot of time.
- Users are advised to edit the 
-\series bold
-device/lib/pic16/pics.build
-\series default
- file and then execute:
-\end_layout
-
-\begin_layout LyX-Code
-make lib-io
-\end_layout
-
 \begin_layout Subsection
 Adding New Devices to the Port
 \end_layout
@@ -26153,7 +26425,7 @@ Adding New Devices to the Port
 \begin_layout Standard
 Adding support for a new 16
 \begin_inset ERT
-status open
+status collapsed
 
 \begin_layout Standard
 
@@ -26193,35 +26465,26 @@ Add DEVICE to
 \family typewriter
 /path/to/sdcc/device/lib/pic16/pics.all
 \family default
- (and 
-\family typewriter
-.build
-\family default
-).
+
 \newline
 Note: No 18f prefix here!
 \end_layout
 
 \begin_layout Enumerate
-Adjus
+Edi
 \family typewriter
-/path/to/sdcc/device/lib/pic16/libio/*.ignore
-\family default
-
+/path/to/sdcc/device/include/pic16/adc.h
 \newline
-Add your DEVICE if it does not compile in 
-\family typewriter
-adc
-\family default
-, 
-\family typewriter
-i2c
+
 \family default
-, or 
+Add the new devices to the correct ADC style class (depending on the number
+ of ADC channels).
+\newline
+Do not touch 
 \family typewriter
-usart
+adc.h
 \family default
-.
+ if the device does not offer any ADC at all.
 \end_layout
 
 \begin_layout Enumerate
@@ -26229,33 +26492,118 @@ Edit
 \family typewriter
 /path/to/sdcc/device/include/pic16/pic18fregs.h
 \family default
-.
- The file format is self-explanatory, just add
+
+\newline
+The file format is self-explanatory, just add
 \newline
 
 \family typewriter
 #elif defined(picDEVICE)
 \newline
-# include <picDEVICE.h>
+#
+\begin_inset ERT
+status collapsed
+
+\begin_layout Standard
+
+
+\backslash
+\backslash
+\end_layout
+
+\end_inset
+
+include <picDEVICE.h>
 \family default
 
 \newline
-at the right place (keep it sorted).
+at the right place (keep the file sorted, please).
 \end_layout
 
 \begin_layout Enumerate
 Edit 
 \family typewriter
-/path/to/sdcc/src/pic16/devices.inc
+/path/to/sdcc/device/include/pic16devices.txt
+\newline
+
+\family default
+Copy and modify an existing entry or create a new one and insert it at the
+ correct place (keep the file sorted, please).
+\end_layout
+
+\begin_layout Enumerate
+Add the device to 
+\family typewriter
+/path/to/sdcc/device/lib/pic16/libdev/Makefile.am
+\family default
+
+\newline
+Copy an existing entry and adjust the device name.
+\end_layout
+
+\begin_layout Enumerate
+Add the device to 
+\family typewriter
+/path/to/sdcc/device/lib/pic16/libio/Makefile.am
+\family default
+
+\newline
+Copy the record from the 18f2220 and adjust the device name.
+\newline
+If the new device
+ does not offer ADC, I
+\begin_inset Formula $^{\text{2}}$
+\end_inset
+
+C, and/or (E)USART functionality as assumed by the library, remove the lines
+ with references to 
+\family typewriter
+adc/*.c
+\family default
+, 
+\family typewriter
+usart/*.c
+\family default
+, or 
+\family typewriter
+usart/*.c
+\family default
+, respectively.
+\end_layout
+
+\begin_layout Enumerate
+Update 
+\family typewriter
+libdev/Makefile.in
+\family default
+ and 
+\family typewriter
+libio/Makefile.in
+\family default
+ using
+\newline
+
+\family typewriter
+./bootstrap.sh
+\family default
+
+\newline
+in 
+\family typewriter
+/path/to/sdcc/device/lib/pic16
 \family default
 .
- Copy and modify an existing entry and insert it at the correct place (keep
- the file sorted).
- The file is hardly documented, look at the entries for the 18f2221...
 \end_layout
 
 \begin_layout Enumerate
-Recompile SDCC, including the pic16 libraries.
+Recompile the pic16 libraries as described in 
+\begin_inset LatexCommand \ref{sub:pic16Libraries}
+
+\end_inset
+
+.
 \end_layout
 
 \begin_layout Subsection
@@ -26570,6 +26918,7 @@ Frame pointer FSR2
 \end_layout
 
 \begin_layout Standard
+\noindent
 
 \noun on
 Large 
@@ -27419,6 +27768,7 @@ unimplemented pointer type
 \end_layout
 
 \begin_layout Standard
+\noindent
 Generic pointer are read and written with a set of library functions which
  read/write 1, 2, 3, 4 bytes.
 \end_layout
@@ -27467,6 +27817,7 @@ pointer.
 \end_layout
 
 \begin_layout Standard
+\noindent
 \align center
 \begin_inset Tabular
 <lyxtabular version="3" rows="2" columns="7">
@@ -27620,10 +27971,12 @@ upper byte high nubble is 0x2n, the rest are zeroes
 \end_layout
 
 \begin_layout Standard
+\noindent
 Currently implemented there are 3 types of streams defined:
 \end_layout
 
 \begin_layout Standard
+\noindent
 \align center
 \begin_inset Tabular
 <lyxtabular version="3" rows="4" columns="4">
@@ -27798,10 +28151,12 @@ Writes/Reads characters via used defined functions
 \end_layout
 
 \begin_layout Standard
+\noindent
 The stream identifiers are declared as macros in the stdio.h header.
 \end_layout
 
 \begin_layout Standard
+\noindent
 In the libc library there exist the functions that are used to write to
  each of the above streams.
  These are
@@ -28423,6 +28778,7 @@ TMR3 overflow interrupt
 \end_layout
 
 \begin_layout Standard
+\noindent
 The prototypes for these names are defined in the header file 
 \emph on
 signal.h
@@ -28431,6 +28787,7 @@ signal.h
 \end_layout
 
 \begin_layout Standard
+\noindent
 In order to simplify signal handling, a number of macros is provided:
 \end_layout
 
@@ -28640,8 +28997,35 @@ status collapsed
 Known Bugs
 \end_layout
 
+\begin_layout Subsubsection
+Extended Instruction Set
+\end_layout
+
 \begin_layout Standard
-The PIC16 Port currently does not pass SDCC's regression test
+The PIC16 port emits code which is incompatible with the extended instruction
+ set available with many newer devices.
+ Make sure to always explicitly disable it, usually using
+\end_layout
+
+\begin_layout Standard
+
+\family typewriter
+static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
+\end_layout
+
+\begin_layout Standard
+\noindent
+Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
+ instead of _XINST_OFF_4L.
+\end_layout
+
+\begin_layout Subsubsection
+Regression Tests
+\end_layout
+
+\begin_layout Standard
+The PIC16 port currently passes most but not all of the tests in SDCC's
+ regression test
 \begin_inset LatexCommand \index{Regression test (PIC16)}
 
 \end_inset
@@ -28651,10 +29035,8 @@ The PIC16 Port currently does not pass SDCC's regression test
 
 \end_inset
 
-) and thus the snapshot build regression tests for the PIC16 target are
- currently disabled for all hosts
-\emph on
-.
+), thus no automatic regression tests are currently performed for the PIC16
+ target.
 \end_layout
 
 \begin_layout Chapter