* .version: bumped version number to 2.4.8
[fw/sdcc] / doc / sdccman.lyx
index 5a54930de135e087111ba83ff777d7f621b0476c..2c211266192251a6999ab64d8248df7701c1c7db 100644 (file)
@@ -83,7 +83,7 @@ SDCC Compiler User Guide
 
 
 \size normal 
-SDCC 2.4.6
+SDCC 2.4.7
 \size footnotesize 
 
 \newline 
@@ -6043,7 +6043,33 @@ status Collapsed
 
 \end_inset 
 
- Causes the linker use unused register banks for data variables or stack.
+ Causes the linker to use unused register banks for data variables and pack
+ data, idata and stack together.
+ This is the default now.
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\series bold 
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-no-pack-iram
+\series default 
+\SpecialChar ~
+
+\begin_inset LatexCommand \index{-\/-pack-iram}
+
+\end_inset 
+
+ Causes the linker to use old style for allocating memory areas.
 \layout Subsection
 
 DS390 / DS400 Options
@@ -6905,6 +6931,7 @@ reentrant
  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.
  
 \layout List
 \labelwidthstring 00.00.0000
@@ -7184,8 +7211,8 @@ status Collapsed
 /
 \end_inset 
 
--nostdincl
-\begin_inset LatexCommand \index{-\/-nostdincl}
+-nostdinc
+\begin_inset LatexCommand \index{-\/-nostdinc}
 
 \end_inset 
 
@@ -8245,8 +8272,10 @@ pdata
 
 \layout Standard
 
-Paged xdata access is currently not as straightforward as using the other
- addressing modes of a 8051.
+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 address pointed to.
  Please note, pdata access physically accesses xdata memory.
  The high byte of the address is determined by port P2 
@@ -8329,7 +8358,7 @@ F2\SpecialChar ~
 movx @r0,a 
 \layout Standard
 
-Be extremely carefull if you use pdata together with the -
+If the -
 \begin_inset ERT
 status Collapsed
 
@@ -8344,7 +8373,8 @@ status Collapsed
 
 \end_inset 
 
- option.
+ 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.
 \layout Subsubsection
 
 code
@@ -8775,14 +8805,15 @@ data
 
  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 after
- the byte holding the last bit variable.
+ 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), 
 \emph on 
 data
 \emph default 
- variables will be placed starting at address 0x22.
+ variables will be placed starting from address 0x10 to 0x20 and continue
+ at address 0x22.
  You can also use -
 \begin_inset ERT
 status Collapsed
@@ -8824,7 +8855,7 @@ idata
  
 \layout Standard
 
-By default the 8051 linker will place the stack after the last byte of data
+By default the 8051 linker will place the stack after the last byte of (i)data
  variables.
  Option -
 \begin_inset ERT
@@ -11060,10 +11091,30 @@ _sdcc_external_startup()
  or perform some other critical operation prior to static & global variable
  initialization.
  On some mcs51 variants xdata has to be explicitly enabled before it can
- be accessed, this is the place to do it.
- The startup code clears the complete 256 byte of idata memory, this might
- cause problems for 128 byte devices (endless loop reported for Chipcon
- CC1010).
+ be accessed or if the watchdog needs to be disabled, this is the place
+ to do it.
+ The startup code clears all internal data memory, 256 bytes by default,
+ but from 0 to n-1 if 
+\emph on 
+-
+\begin_inset ERT
+status Collapsed
+
+\layout Standard
+
+\backslash 
+/
+\end_inset 
+
+-iram-size
+\begin_inset LatexCommand \index{-\/-iram-size}
+
+\end_inset 
+
+n
+\emph default 
+ is used.
+ (recommended for Chipcon CC1010).
 \layout Standard
 
 See also the compiler option 
@@ -13913,15 +13964,6 @@ External Stack
 
 \layout Standard
 
-
-\series bold 
-Attention
-\series default 
-: this option wasn't maintained for a long time and is quite buggy.
- Small programs might work.
- You've been warned!
-\layout Standard
-
 The external stack (-
 \begin_inset ERT
 status Collapsed
@@ -13942,8 +13984,9 @@ status Collapsed
 
 \end_inset 
 
- memory (usually at the start of the external ram segment) and is 256 bytes
- in size.
+ memory (usually at the start of the external ram segment) and uses all
+ unused space in pdata (max.
+ 256 bytes).
  When -
 \begin_inset ERT
 status Collapsed
@@ -13979,7 +14022,8 @@ status Collapsed
 
  option, all parameters and local variables are allocated on the external
  stack (note: support libraries will need to be recompiled with the same
- options).
+ options.
+ There is a predefined target in the library makefile).
 \layout Standard
 
 The compiler outputs the higher order address byte of the external ram segment
@@ -15362,8 +15406,15 @@ status Collapsed
 \layout List
 \labelwidthstring 00.00.0000
 
-1 checkes previous used register and if it is the same then doesn't emit
+1 checks previous used register and if it is the same then does not emit
  BANKSEL, accounts only for labels.
+\layout List
+\labelwidthstring 00.00.0000
+
+2 tries to check the location of (even different) symbols and removes BANKSELs
+ if they are in the same bank.
+ Important: This will only work properly if the linker script does not have
+ sections across bank borders!
 \end_deeper 
 \layout List
 \labelwidthstring 00.00.0000
@@ -15583,8 +15634,7 @@ status Collapsed
 /
 \end_inset 
 
--flr-support When entering/leaving a function, call support functions to
- store/restore used registers
+-optimize-goto Try to use (conditional) BRA instead of GOTO
 \layout Subsubsection
 
 Debugging Options
@@ -15885,25 +15935,49 @@ PIC16 port currently supports the following pragmas:
 
 stack pragma stack forces the code generator to initialize the stack & frame
  pointers at a specific address.
- This is an adhoc solution since gplink does not support yet stack.
- When the gplink issue is resolved the pragma will be deprecated
-\begin_inset Foot
-collapsed true
+ This is an adhoc solution for cases where no STACK directive is available
+ in the linker script or gplink is not instructed to create a stack section.
+\newline 
+The stack pragma should be used only once in a project.
+ Multiple pragmas may result in indeterminate behaviour of the program.
+\newline 
+The format is as follows:
+\layout LyX-Code
 
+#pragma stack bottom_address [stack_size]
 \layout Standard
 
 
 \emph on 
-It is important to initialize the stack, otherwise strange things can happen.
- Stack is not initialized by default because there are some sources that
- do not require it.
- (like library sources)
-\end_inset 
+bottom_address
+\emph default 
+ is the lower bound of the stack section.
+ The stack pointer initially will point at address (bottom_address+stack_size-1).
+\layout LyX-Code
+
+Example:
+\layout LyX-Code
+
+\layout LyX-Code
+
+/* initializes stack of 100 bytes at RAM address 0x200 */
+\layout LyX-Code
+
+#pragma stack 0x200 100
+\layout List
+\labelwidthstring 00.00.0000
+
+wparam use the WREG to pass one byte of the first function argument.
+ This improves speed but you may not use this for functions with arguments
+ that are called via function pointers, otherwise one byte of the first
+ parameter will get lost.
+ This pragma should be placed in the header file to propagate the calling
+ convention to all callers.
+\layout LyX-Code
+
+#pragma wparam function1[, function2, ...]
+\layout LyX-Code
 
-.
-\newline 
-The stack pragma should be used only once in a project.
- Multiple pragmas may result in indeterminate behaviour of the program.
 \layout LyX-Code
 
 Example:
@@ -15911,10 +15985,13 @@ Example:
 
 \layout LyX-Code
 
-/* initializes stack at RAM address 0x5ff */
+/* pass one byte via stack and one byte via WREG */
+\layout LyX-Code
+
+#pragma wparam foo
 \layout LyX-Code
 
-#pragma stack 0x5ff
+void foo(int x);
 \layout List
 \labelwidthstring 00.00.0000
 
@@ -15951,8 +16028,8 @@ Example:
 char foo;
 \layout Standard
 
-In order for this pragma to work there are some changes that must be made
- in the .lkr script used in link stage.
+In order for this pragma to work extra SECTION directives should be added
+ in the .lkr script.
  In the following example a sample .lkr file is shown:
 \layout LyX-Code
 
@@ -16015,16 +16092,16 @@ SECTION    NAME=CONFIG     ROM=config
 
 \layout LyX-Code
 
-SECTION    NAME=bank0      RAM=gpr0
+SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
 \layout LyX-Code
 
-SECTION    NAME=bank1      RAM=gpr1
+SECTION    NAME=bank1      RAM=gpr1       # should be added to link
 \layout LyX-Code
 
-SECTION    NAME=bank2      RAM=gpr2
+SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
 \layout LyX-Code
 
-SECTION    NAME=bank3      RAM=gpr3
+SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
 \layout LyX-Code
 
 SECTION    NAME=bank4      RAM=gpr4
@@ -16036,6 +16113,234 @@ SECTION    NAME=bank5      RAM=gpr5
 The linker will recognise the section name set in the pragma statement and
  will position the variable at the memory bank set with the RAM field at
  the SECTION line in the linker script file.
+\layout List
+\labelwidthstring 00.00.0000
+
+library instructs the linker to use a library module.
+\newline 
+Usage:
+\layout LyX-Code
+
+#pragma library module_name
+\layout Standard
+
+
+\emph on 
+module_name
+\emph default 
+ can be any library or object file (including its path).
+ Note that there are four reserved keywords which have special meaning.
+ These are:
+\layout Standard
+\align center 
+
+\begin_inset  Tabular
+<lyxtabular version="3" rows="6" columns="3">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="block" valignment="top" leftline="true" width="20page%">
+<column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Keyword
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Description
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Module to link
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+ignore
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+ignore all library pragmas
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+(none)
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+c
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the C library
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libc18f
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+math
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the Math libarary
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libm18f
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+io
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the I/O library
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libio18f*
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\series bold 
+debug
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+link the debug library
+\end_inset 
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\emph on 
+libdebug
+\emph default 
+.lib
+\end_inset 
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset 
+
+
+\newline 
+* is the device number, i.e.
+ 452 for PIC18F452 MCU.
+\layout Standard
+
+This feature allows for linking with specific libraries withoug having to
+ explicit name them in the command line.
+ Note that the 
+\noun on 
+ignore
+\noun default 
+ keyword will reject all modules specified by the library pragma.
 \layout Subsection
 
 Header Files
@@ -16091,6 +16396,47 @@ Libraries are created with gplib which is part of the gputils package
 \end_inset 
 
 .
+\layout Subsubsection
+
+Building the libraries
+\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.
+\layout Standard
+
+The steps to compile the pic16 libraries under Linux are:
+\layout LyX-Code
+
+cd device/lib/pic16
+\layout LyX-Code
+
+./configure
+\layout LyX-Code
+
+make
+\layout LyX-Code
+
+cd ..
+\layout LyX-Code
+
+make model-pic16
+\layout LyX-Code
+
+su -c 'make install'     # install the libraries, you need the root password
+\layout Standard
+
+If you need to install the headers to, do:
+\layout LyX-Code
+
+cd device/include
+\layout LyX-Code
+
+su -c 'make install'     # install the headers, you need the root password
+\layout LyX-Code
+
 \layout Subsection
 
 Memory Models
@@ -16244,10 +16590,18 @@ FSR2 is assigned as frame pointer
 The following stack models are supported by the PIC16 port
 \layout Itemize
 
-small model
+
+\noun on 
+small
+\noun default 
+ model
 \layout Itemize
 
-large model
+
+\noun on 
+large
+\noun default 
+ model
 \layout Standard
 
 
@@ -16359,16 +16713,27 @@ Frame pointer FSR2
 \layout Standard
 
 
-\series bold 
-Currently stack and frame pointers should be initialized explicit by the
- user at the desired Data RAM position (see 
-\begin_inset LatexCommand \ref{sub:PIC16_Pragmas}
+\noun on 
+Large 
+\noun default 
+stack model is currently not working properly throughout the code generator.
+ So its use is not advised.
+ Also there are some other points that need special care:
+\newline 
 
-\end_inset 
+\layout Enumerate
+
+Do not create stack sections with size more than one physical bank (that
+ is 256 bytes)
+\layout Enumerate
+
+Stack sections should no cross physical bank limits (i.e.
+ #pragma stack 0x50 0x100)
+\layout Standard
 
- Pragma stack).
- Uninitialized stack and frame pointers can result in unexpected behavior
of the resulting binary.
+These limitations are caused by the fact that only FSRxL is modified when
+ using SMALL stack model, so no more than 256 bytes of stack can be used.
This problem will disappear after LARGE model is fully implemented.
 \layout Subsection
 
 Function return values