欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

ld65-5.html

cc65 的编译器文档
HTML
第 1 页 / 共 2 页
字号:
<P>So, what your startup code must do, is to copy <CODE>__DATA_SIZE__</CODE> bytes from<CODE>__DATA_LOAD__</CODE> to <CODE>__DATA_RUN__</CODE> before any other routines are called.All references to labels in the <CODE>DATA</CODE> segment are relocated to <CODE>RAM2</CODE>by the linker, so things will work properly.</P><H2><A NAME="ss5.5">5.5</A> <A HREF="ld65.html#toc5.5">Other MEMORY area attributes</A></H2><P>There are some other attributes not covered above. Before starting thereference section, I will discuss the remaining things here.</P><P>You may request symbols definitions also for memory areas. This may beuseful for things like a software stack, or an i/o area.</P><P><BLOCKQUOTE><CODE><PRE>        MEMORY {            STACK:  start = $C000, size = $1000, define = yes;        }</PRE></CODE></BLOCKQUOTE></P><P>This will define three external symbols that may be used in your code:</P><P><BLOCKQUOTE><CODE><PRE>        __STACK_START__         This is set to the start of the memory                                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.</PRE></CODE></BLOCKQUOTE></P><P>A memory section may also have a type. Valid types are</P><P><BLOCKQUOTE><CODE><PRE>        ro      for readonly memory        rw      for read/write memory.</PRE></CODE></BLOCKQUOTE></P><P>The linker will assure, that no segment marked as read/write or bss is putinto a memory area that is marked as readonly.</P><P>Unused memory in a memory area may be filled. Use the "<CODE>fill = yes</CODE>"attribute to request this. The default value to fill unused space is zero. Ifyou don't like this, you may specify a byte value that is used to fill theseareas with the "<CODE>fillval</CODE>" attribute. This value is also used to fill unfilledareas generated by the assemblers <CODE>.ALIGN</CODE> and <CODE>.RES</CODE> directives.</P><H2><A NAME="ss5.6">5.6</A> <A HREF="ld65.html#toc5.6">Other SEGMENT attributes</A></H2><P>Segments may be aligned to some memory boundary. Specify "<CODE>align = num</CODE>" torequest this feature. Num must be a power of two. To align all segments on apage boundary, use</P><P><BLOCKQUOTE><CODE><PRE>        SEGMENTS {            CODE:   load = ROM1, type = ro, align = $100;            RODATA: load = ROM2, type = ro, align = $100;            DATA:   load = ROM2, run = RAM2, type = rw, define = yes,                    align = $100;            BSS:    load = RAM2, type = bss, define = yes, align = $100;        }</PRE></CODE></BLOCKQUOTE></P><P>If an alignment is requested, the linker will add enough space to the outputfile, so that the new segment starts at an address that is divideable by thegiven number without a remainder. All addresses are adjusted accordingly. Tofill the unused space, bytes of zero are used, or, if the memory area has a"<CODE>fillval</CODE>" attribute, that value. Alignment is always needed, if you havethe used the <CODE>.ALIGN</CODE> command in the assembler. The alignment of a segmentmust be equal or greater than the alignment used in the <CODE>.ALIGN</CODE> command.The linker will check that, and issue a warning, if the alignment of a segmentis lower than the alignment requested in a <CODE>.ALIGN</CODE> command of one of themodules making up this segment.</P><P>For a given segment you may also specify a fixed offset into a memory area ora fixed start address. Use this if you want the code to run at a specificaddress (a prominent case is the interrupt vector table which must go ataddress $FFFA). Only one of <CODE>ALIGN</CODE> or <CODE>OFFSET</CODE> or <CODE>START</CODE> may bespecified. If the directive creates empty space, it will be filled with zero,of with the value specified with the "<CODE>fillval</CODE>" attribute if one is given.The linker will warn you if it is not possible to put the code at thespecified offset (this may happen if other segments in this area are toolarge). Here's an example:</P><P><BLOCKQUOTE><CODE><PRE>        SEGMENTS {            VECTORS: load = ROM2, type = ro, start = $FFFA;        }</PRE></CODE></BLOCKQUOTE></P><P>or (for the segment definitions from above)</P><P><BLOCKQUOTE><CODE><PRE>        SEGMENTS {            VECTORS: load = ROM2, type = ro, offset = $1FFA;        }</PRE></CODE></BLOCKQUOTE></P><P>To suppress the warning, the linker issues if it encounters a segment that isnot found in any of the input files, use "<CODE>optional=yes</CODE>" as additionalsegment attribute. Be careful when using this attribute, because a missingsegment may be a sign of a problem, and if you're suppressing the warning,there is no one left to tell you about it.</P><P>File names may be empty, data from segments assigned to a memory area withan empty file name is discarded. This is useful, if the a memory area hassegments assigned that are empty (for example because they are of typebss). In that case, the linker will create an empty output file. This maybe suppressed by assigning an empty file name to that memory area.</P><P>The symbol <CODE>%S</CODE> may be used to access the default start address (that is,$200 or the value given on the command line with the <CODE><A HREF="ld65-2.html#option-S">-S</A></CODE> option).</P><H2><A NAME="ss5.7">5.7</A> <A HREF="ld65.html#toc5.7">The FILES section</A></H2><P>The <CODE>FILES</CODE> section is used to support other formats than straight binary(which is the default, so binary output files do not need an explicit entryin the <CODE>FILES</CODE> section).</P><P>The <CODE>FILES</CODE> section lists output files and as only attribute the format ofeach output file. Assigning binary format to the default output file wouldlook like this:</P><P><BLOCKQUOTE><CODE><PRE>        FILES {            %O: format = bin;        }</PRE></CODE></BLOCKQUOTE></P><P>The only other available output format is the o65 format specified by AndreFachat. It is defined like this:</P><P><BLOCKQUOTE><CODE><PRE>        FILES {            %O: format = o65;        }</PRE></CODE></BLOCKQUOTE></P><P>The necessary o65 attributes are defined in a special section labeled<CODE>FORMAT</CODE>.</P><H2><A NAME="ss5.8">5.8</A> <A HREF="ld65.html#toc5.8">The FORMAT section</A></H2><P>The <CODE>FORMAT</CODE> section is used to describe file formats. The default (binary)format has currently no attributes, so, while it may be listed in thissection, the attribute list is empty. The second supported format, o65, hasseveral attributes that may be defined here.</P><P><BLOCKQUOTE><CODE><PRE>    FORMATS {        o65: os = lunix, version = 0, type = small,             import = LUNIXKERNEL,             export = _main;    }</PRE></CODE></BLOCKQUOTE></P><H2><A NAME="ss5.9">5.9</A> <A HREF="ld65.html#toc5.9">Features</A></H2><P>In addition to the <CODE>MEMORY</CODE> and <CODE>SEGMENTS</CODE> sections described above, thelinker has features that may be enabled by an additional section labeled<CODE>FEATURES</CODE>. Currently, one such feature is available: <CODE>CONDES</CODE> is usedto tell the linker to emit module constructor/destructor tables.</P><P><BLOCKQUOTE><CODE><PRE>        FEATURES {            CONDES: segment = RODATA,                    type = constructor,                    label = __CONSTRUCTOR_TABLE__,                    count = __CONSTRUCTOR_COUNT__;        }</PRE></CODE></BLOCKQUOTE></P><P>The <CODE>CONDES</CODE> feature has several attributes:</P><P><DL><DT><B><CODE>segment</CODE></B><DD><P>This attribute tells the linker into which segment the table should beplaced. If the segment does not exist, it is created.</P><DT><B><CODE>type</CODE></B><DD><P>Describes the type of the routines to place in the table. Type may beone of the predefined types <CODE>constructor</CODE> or <CODE>destructor</CODE>, or anumeric value between 0 and 6.</P><DT><B><CODE>label</CODE></B><DD><P>This specifies the label to use for the table. The label points to thestart of the table in memory and may be used from within user writtencode.</P><DT><B><CODE>count</CODE></B><DD><P>This is an optional attribute. If specified, an additional symbol isdefined by the linker using the given name. The value of this symbolis the number of entries (<EM>not</EM> bytes) in the table. While thisattribute is optional, it is often useful to define it.</P><DT><B><CODE>order</CODE></B><DD><P>Optional attribute that takes one of the keywords <CODE>increasing</CODE> or<CODE>decreasing</CODE> as an argument. Specifies the sorting order of the entrieswithin the table. The default is <CODE>increasing</CODE>, which means that theentries are sorted with increasing priority (the first entry has the lowestpriority). "Priority" is the priority specified when declaring a symbol as<CODE>.CONDES</CODE> with the assembler, higher values mean higher priority. You maychange this behaviour by specifying <CODE>decreasing</CODE> as the argument, theorder of entries is reversed in this case.</P><P>Please note that the order of entries with equal priority is undefined.</P></DL></P><P>Without specifying the <CODE>CONDES</CODE> feature, the linker will not create anytables, even if there are <CODE>condes</CODE> entries in the object files.</P><P>For more information see the <CODE>.CONDES</CODE> command in the <A HREF="ca65.html">ca65 manual</A>.</P><H2><A NAME="ss5.10">5.10</A> <A HREF="ld65.html#toc5.10">Builtin configurations</A></H2><P>The builtin configurations are part of the linker source. They are alsodistributed together with the machine specific binary packages (usually in thedoc directory) and don't have a special format. So if you need a specialconfiguration, it's a good idea to start with the builtin configuration foryour system. In a first step, just replace <CODE>-t target</CODE> by <CODE>-Cconfigfile</CODE>. The go on and modify the config file to suit your needs.</P><HR><A HREF="ld65-6.html">Next</A><A HREF="ld65-4.html">Previous</A><A HREF="ld65.html#toc5">Contents</A></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -