]> git.sur5r.net Git - cc65/blobdiff - doc/ld65.sgml
Revert "No linuxdoc here. Documenation is to be maintained as HTML in branch 'gh...
[cc65] / doc / ld65.sgml
index ca431ff6e613a1c15efd3f3e69aeb68b7bbee2cb..5330a21d97d89a2ac7d98cca491ace6ae00ebc53 100644 (file)
@@ -1,4 +1,4 @@
-<!doctype linuxdoc system>
+<!doctype linuxdoc system>      <!-- -*- text-mode -*- -->
 
 <article>
 <title>ld65 Users Guide
@@ -67,6 +67,7 @@ Short options:
   -m name               Create a map file
   -o name               Name the default output file
   -t sys                Set the target system
+  -u sym                Force an import of symbol `sym'
   -v                    Verbose mode
   -vm                   Verbose map file
 
@@ -77,6 +78,7 @@ Long options:
   --define sym=val      Define a symbol
   --dump-config name    Dump a builtin configuration
   --end-group           End a library group
+  --force-import sym    Force an import of symbol `sym'
   --help                Help (this text)
   --lib file            Link this library
   --lib-path path       Specify a library search path
@@ -152,6 +154,7 @@ Here is a description of all the command line options:
 
   <itemize>
   <item>none
+  <item>module
   <item>apple2
   <item>apple2enh
   <item>atari
@@ -159,21 +162,39 @@ Here is a description of all the command line options:
   <item>c16 (works also for the c116 with memory up to 32K)
   <item>c64
   <item>c128
-  <item>plus4
   <item>cbm510 (CBM-II series with 40 column video)
   <item>cbm610 (all CBM series-II computers with 80 column video)
-  <item>pet (all CBM PET systems except the 2001)
-  <item>geos
+  <item>geos-apple
+  <item>geos-cbm
   <item>lunix
-  <item>atmos
+  <item>lynx
   <item>nes
+  <item>pet (all CBM PET systems except the 2001)
+  <item>plus4
   <item>supervision
+  <item>vic20
   </itemize>
 
   There are a few more targets defined but neither of them is actually
   supported.
 
 
+  <tag><tt>-u sym[:addrsize], --force-import sym[:addrsize]</tt></tag>
+
+  Force an import of a symbol. While object files are always linked to the
+  output file, regardless if there are any references, object modules from
+  libraries get only linked in if an import can be satisfied by this module.
+  The <tt/--fore-import/ option may be used to add a reference to a symbol and
+  as a result force linkage of the module that exports the identifier.
+
+  The name of the symbol may optionally be followed by a colon and an address
+  size specifier. If no address size is specified, the default address size
+  for the target machine is used.
+
+  Please note that the symbol name needs to have the internal representation,
+  meaning you have to prepend an underline for C identifiers.
+
+
   <label id="option-v">
   <tag><tt>-v, --verbose</tt></tag>
 
@@ -260,7 +281,7 @@ Here is a description of all the command line options:
   written to this file. Using the <tt/-g/ option for the compiler and assembler
   will increase the amount of information available. Please note that debug
   information generation is currently being developed, so the format of the
-  file and it's contents are subject to change without further notice.
+  file and its contents are subject to change without further notice.
 
 
   <tag><tt>--lib file</tt></tag>
@@ -306,9 +327,8 @@ The library search path contains in this order:
 <item>A compiled in library path which is often <tt>/usr/lib/cc65/lib</tt> on
       Linux systems.
 <item>The value of the environment variable <tt/LD65_LIB/ if it is defined.
-<item>The value of the environment variable <tt/CC65_LIB/ if it is defined.
-      Please note that use of this environment variable is obsolete and may
-      get removed in future versions.
+<item>A subdirectory named <tt/lib/ of the directory defined in the environment
+      variable <tt/CC65_HOME/, if it is defined.
 <item>Any directory added with the <tt><ref id="option--lib-path"
       name="--lib-path"></tt> option on the command line.
 </enum>
@@ -320,12 +340,11 @@ The object file search path contains in this order:
 
 <enum>
 <item>The current directory.
-<item>A compiled in directory which is often <tt>/usr/lib/cc65/lib</tt> on
+<item>A compiled in directory which is often <tt>/usr/lib/cc65/obj</tt> on
       Linux systems.
 <item>The value of the environment variable <tt/LD65_OBJ/ if it is defined.
-<item>The value of the environment variable <tt/CC65_LIB/ if it is defined.
-      Please note that use of this environment variable is obsolete and may
-      get removed in future versions.
+<item>A subdirectory named <tt/obj/ of the directory defined in the environment
+      variable <tt/CC65_HOME/, if it is defined.
 <item>Any directory added with the <tt><ref id="option--obj-path"
       name="--obj-path"></tt> option on the command line.
 </enum>
@@ -337,9 +356,11 @@ The config file search path contains in this order:
 
 <enum>
 <item>The current directory.
-<item>A compiled in directory which is often <tt>/usr/lib/cc65/lib</tt> on
+<item>A compiled in directory which is often <tt>/usr/lib/cc65/cfg</tt> on
       Linux systems.
 <item>The value of the environment variable <tt/LD65_CFG/ if it is defined.
+<item>A subdirectory named <tt/cfg/ of the directory defined in the environment
+      variable <tt/CC65_HOME/, if it is defined.
 <item>Any directory added with the <tt><ref id="option--cfg-path"
       name="--cfg-path"></tt> option on the command line.
 </enum>
@@ -381,7 +402,7 @@ for the segments and define any linker symbols (see <ref id="config-files"
 name="Configuration files">).
 
 After that, the linker is ready to produce an output file. Before doing that,
-it checks it's data for consistency. That is, it checks for unresolved
+it checks its data for consistency. That is, it checks for unresolved
 externals (if the output format is not relocatable) and for symbol type
 mismatches (for example a zero page symbol is imported by a module as absolute
 symbol).
@@ -575,11 +596,24 @@ names here. Segments that go into <tt/ROM1/ will be written to a file named
 named "rom2.bin". The name given on the command line is ignored in both cases.
 
 Assigning an empty file name for a memory area will discard the data written
-to it. This is useful, if the a memory area has segments assigned that are
-empty (for example because they are of type bss). In that case, the linker
-will create an empty output file. This may be suppressed by assigning an empty
-file name to that memory area.
+to it. This is useful, if the memory area has segments assigned that are empty
+(for example because they are of type bss). In that case, the linker will
+create an empty output file. This may be suppressed by assigning an empty file
+name to that memory area.
 
+The <tt/%O/ sequence is also allowed inside a string. So using
+
+<tscreen><verb>
+       MEMORY {
+                   ROM1:  start = $A000, size = $2000, file = "%O-1.bin";
+           ROM2:  start = $E000, size = $2000, file = "%O-2.bin";
+       }
+</verb></tscreen>
+
+would write two files that start with the name of the output file specified on
+the command line, with "-1.bin" and "-2.bin" appended respectively. Because
+'%' is used as an escape char, the sequence "%%" has to be used if a single
+percent sign is required.
 
 <sect1>LOAD and RUN addresses (ROMable code)<p>
 
@@ -605,9 +639,9 @@ segment, than storing it into one of the ROMs, we have to put it there. But
 unfortunately, ROM is not writable, so we have to copy it into RAM before
 running the actual code.
 
-The linker cannot help you copying the data from ROM into RAM (this must be
-done by the startup code of your program), but it has some features that will
-help you in this process.
+The linker won't copy the data from ROM into RAM for you (this must be done by
+the startup code of your program), but it has some features that will help you
+in this process.
 
 First, you may not only specify a "<tt/load/" attribute for a segment, but
 also a "<tt/run/" attribute. The "<tt/load/" attribute is mandatory, and, if
@@ -628,7 +662,7 @@ Let's have a closer look at this <tt/SEGMENTS/ section. We specify that the
 goes into <tt/ROM2/. Read/write data will be loaded into <tt/ROM2/ but is run
 in <tt/RAM2/. That means that all references to labels in the <tt/DATA/
 segment are relocated to be in <tt/RAM2/, but the segment is written to
-<tt/ROM2/. All your startup code has to do is, to copy the data from it's
+<tt/ROM2/. All your startup code has to do is, to copy the data from its
 location in <tt/ROM2/ to the final location in <tt/RAM2/.
 
 So, how do you know, where the data is located? This is the second point,
@@ -650,6 +684,10 @@ So, what your startup code must do, is to copy <tt/__DATA_SIZE__/ bytes from
 All references to labels in the <tt/DATA/ segment are relocated to <tt/RAM2/
 by the linker, so things will work properly.
 
+There's a library subroutine called <tt/copydata/ (in a module named
+<tt/copydata.s/) that might be used to do actual copying. Be sure to have a
+look at it's inner workings before using it!
+
 
 <sect1>Other MEMORY area attributes<p>
 
@@ -665,17 +703,20 @@ useful for things like a software stack, or an i/o area.
        }
 </verb></tscreen>
 
-This will define three external symbols that may be used in your code:
+This will define some external symbols that may be used in your code:
 
 <tscreen><verb>
                __STACK_START__         This is set to the start of the memory
-                               area, $C000 in this example.
+                               area, $C000 in this example.
        __STACK_SIZE__          The size of the area, here $1000.
         __STACK_LAST__         This is NOT the same as START+SIZE.
-                               Instead, it it defined as the first
-                               address that is not used by data. If we
-                               don't define any segments for this area,
-                               the value will be the same as START.
+                               Instead, it it defined as the first
+                               address that is not used by data. If we
+                               don't define any segments for this area,
+                               the value will be the same as START.
+        __STACK_FILEOFFS__      The binary offset in the output file. This
+                                is not defined for relocatable output file
+                                formats (o65).
 </verb></tscreen>
 
 A memory section may also have a type. Valid types are
@@ -691,14 +732,24 @@ into a memory area that is marked as readonly.
 Unused memory in a memory area may be filled. Use the "<tt/fill = yes/"
 attribute to request this. The default value to fill unused space is zero. If
 you don't like this, you may specify a byte value that is used to fill these
-areas with the "<tt/fillval/" attribute. This value is also used to fill unfilled
-areas generated by the assemblers <tt/.ALIGN/ and <tt/.RES/ directives.
+areas with the "<tt/fillval/" attribute. If there is no "<tt/fillval/"
+attribute for the segment, the "<tt/fillval/" attribute of the memory area (or
+its default) is used instead. This means that the value may also be used to
+fill unfilled areas generated by the assemblers <tt/.ALIGN/ and <tt/.RES/
+directives.
 
 The symbol <tt/%S/ may be used to access the default start address (that is,
 the one defined in the <ref id="FEATURES" name="FEATURES"> section, or the
 value given on the command line with the <tt><ref id="option-S" name="-S"></tt>
 option).
 
+To support systems with banked memory, a special attribute named <tt/bank/ is
+available. The attribute value is an arbitrary 32 bit integer. The assembler
+has a builtin function named <tt/.BANK/ which may be used with an argument
+that has a segment reference (for example a symbol). The result of this
+function is the value of the bank attribute for the run memory area of the
+segment.
+
 
 <sect1>Other SEGMENT attributes<p>
 
@@ -760,6 +811,13 @@ segment in the load memory area, in case different load and run areas have
 been specified. There are no special attributes to set start or offset for
 just the load memory area.
 
+A "<tt/fillval/" attribute may not only be specified for a memory area, but
+also for a segment. The value must be an integer between 0 and 255. It is used
+as fill value for space reserved by the assemblers <tt/.ALIGN/ and <tt/.RES/
+commands. It is also used as fill value for space between sections (part of a
+segment that comes from one object file) caused by alignment, but not for
+space that preceeds the first section.
+
 To suppress the warning, the linker issues if it encounters a segment that is
 not found in any of the input files, use "<tt/optional=yes/" as additional
 segment attribute. Be careful when using this attribute, because a missing
@@ -801,8 +859,9 @@ The necessary o65 attributes are defined in a special section labeled
 
 The <tt/FORMAT/ section is used to describe file formats. The default (binary)
 format has currently no attributes, so, while it may be listed in this
-section, the attribute list is empty. The second supported format, o65, has
-several attributes that may be defined here.
+section, the attribute list is empty. The second supported format,
+<htmlurl url="http://www.6502.org/users/andre/o65/fileformat.html" name="o65">,
+has several attributes that may be defined here.
 
 <tscreen><verb>
     FORMATS {
@@ -879,6 +938,13 @@ The <tt/CONDES/ feature has several attributes:
 
   Please note that the order of entries with equal priority is undefined.
 
+  <tag><tt>import</tt></tag>
+
+  This attribute defines a valid symbol name, that is added as an import
+  to the modules defining a constructor/desctructor of the given type.
+  This can be used to force linkage of a module if this module exports the
+  requested symbol.
+
 </descrip>
 
 Without specifying the <tt/CONDES/ feature, the linker will not create any
@@ -910,12 +976,41 @@ mean, that the <tt/FEATURES/ section has to go to the top of the config file.
 <sect1>The SYMBOLS section<label id="SYMBOLS"><p>
 
 The configuration file may also be used to define symbols used in the link
-stage. The mandatory attribute for a symbol is its value. A second, boolean
-attribute named <tt/weak/ is available. If a symbol is marked as weak, it may
-be overridden by defining a symbol of the same name from the command line. The
-default for symbols is that they're strong, which means that an attempt to
-define a symbol with the same name from the command line will lead to an
-error.
+stage or to force symbols imports. This is done in the SYMBOLS section. The
+symbol name is followed by a colon and symbol attributes.
+
+The following symbol attributes are supported:
+
+<descrip>
+
+  <tag><tt>addrsize</tt></tag>
+
+  The <tt/addrsize/ attribute specifies the address size of the symbol and
+  may be one of
+<itemize>
+    <item><tt/zp/, <tt/zeropage/ or <tt/direct/
+    <item><tt/abs/, <tt/absolute/ or <tt/near/
+    <item><tt/far/
+    <item><tt/long/ or <tt/dword/.
+</itemize>
+
+Without this attribute, the default address size is <tt/abs/.
+
+  <tag><tt>type</tt></tag>
+
+  This attribute is mandatory. Its value is one of <tt/export/, <tt/import/ or
+  <tt/weak/. <tt/export/ means that the symbol is defined and exported from
+  the linker config. <tt/import/ means that an import is generated for this
+  symbol, eventually forcing a module that exports this symbol to be included
+  in the output. <tt/weak/ is similar as <tt/export/. However, the symbol is
+  only defined if it is not defined elsewhere.
+
+  <tag><tt>value</tt></tag>
+
+  This must only be given for symbols of type <tt/export/ or <tt/weak/. It
+  defines the value of the symbol and may be an expression.
+
+</descrip>
 
 The following example defines the stack size for an application, but allows
 the programmer to override the value by specifying <tt/--define
@@ -924,7 +1019,7 @@ __STACKSIZE__=xxx/ on the command line.
 <tscreen><verb>
                SYMBOLS {
             # Define the stack size for the application
-                   __STACKSIZE__:      value = $800, weak = yes;
+                   __STACKSIZE__:  type = weak, value = $800;
                }
 </verb></tscreen>
 
@@ -932,15 +1027,22 @@ __STACKSIZE__=xxx/ on the command line.
 
 <sect1>Builtin configurations<p>
 
-The builtin configurations are part of the linker source. They are also
-distributed together with the machine specific binary packages (usually in the
-doc directory) and don't have a special format. So if you need a special
-configuration, it's a good idea to start with the builtin configuration for
-your system. In a first step, just replace <tt/-t target/ by <tt/-C
+The builtin configurations are part of the linker source. They can be retrieved
+with <tt/--dump-config/ and don't have a special format. So if you need a
+special configuration, it's a good idea to start with the builtin configuration
+for your system. In a first step, just replace <tt/-t target/ by <tt/-C
 configfile/. Then go on and modify the config file to suit your needs.
 
 
 
+<sect1>Secondary configurations<p>
+
+Several machine specific binary packages are distributed together with secondary
+configurations (in the cfg directory). These configurations can be used with
+<tt/-C configfile/ too.
+
+
+
 <sect>Special segments<p>
 
 The builtin config files do contain segments that have a special meaning for
@@ -965,10 +1067,11 @@ This segment contains the startup code which initializes the C software stack
 and the libraries. It is placed in its own segment because it needs to be
 loaded at the lowest possible program address on several platforms.
 
-<sect1>HEAP<p>
+<sect1>ZPSAVE<p>
 
-This segment defines the location of the memory heap used by the malloc
-routine.
+The ZPSAVE segment contains the original values of the zeropage locations used
+by the ZEROPAGE segment. It is placed in its own segment because it must not be
+initialized.