From: <jt...@us...> - 2007-05-01 19:33:34
|
Revision: 259 http://ro-oslib.svn.sourceforge.net/ro-oslib/?rev=259&view=rev Author: jtytgat Date: 2007-05-01 12:33:15 -0700 (Tue, 01 May 2007) Log Message: ----------- Added option -asmtype and support for GAS assembler (ELF iso AOF) Modified Paths: -------------- branches/simplified-build/!OsLib/Tools/DefMod2/Manual.htm,faf branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c branches/simplified-build/!OsLib/Tools/DefMod2/hdr.h branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h Removed Paths: ------------- branches/simplified-build/!OsLib/Tools/DefMod2/unix_eg/ Modified: branches/simplified-build/!OsLib/Tools/DefMod2/Manual.htm,faf =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/Manual.htm,faf 2007-05-01 12:40:24 UTC (rev 258) +++ branches/simplified-build/!OsLib/Tools/DefMod2/Manual.htm,faf 2007-05-01 19:33:15 UTC (rev 259) @@ -2,6 +2,7 @@ <html> <head> <title>DefMod</title> +<meta http-equiv="Content-Type" content="text/html;charset=utf-8" > </head> <body> @@ -17,7 +18,7 @@ <tr><td><a href = "#semantics">Semantics</a></td></tr> <tr><td><a href = "#bytewide">The <tt>ByteWide</tt> file</a></td></tr> - <tr><td><a href = "#apcstoswi"><small>A P C S</small> + <tr><td><a href = "#apcstoswi"><small>APCS</small> to <small>SWI</small></a></td></tr> <tr><td><a href = "#implementation">Implementation notes</a></td></tr> @@ -31,35 +32,43 @@ <p><tt>DefMod</tt> is the tool for generating all sorts of different files from module interface files. A module interface file (with the -conventional file extension <tt>.SWI</tt>) contains enough information +conventional file extension <tt>.swi</tt>) contains enough information to specify, in a language-independent form, the interface to a -<small>RISC O S</small> module. This can be used to generate +<small>RISC OS</small> module. This can be used to generate suitable files to enable the module to be called from any high-level language. The whole of <tt>OSLib</tt> (apart from <tt>"types.h"</tt> and <tt>"macros.h"</tt>) is derived from a set of modules interface files and these <tt>DefMod</tt> options:</p> <dl> + <dt><tt>-asmtype</tt> <asmtype></dt> + <dd>selects the type of assembler program to be used. Possible values for <asmtype> are +<small>objasm</small> (<tt>ObjAsm</tt> running on <small>RISC OS</small>) which is the +default value, +<small>gccaof</small> (<tt>GCCSDK 3.4 AOF</tt>), <small>armasm</small> (<tt>ArmAsm</tt>) +and <small>gccelf</small> (<tt>GCCSDK 4 ELF</tt>). + </dd> + + <dt><tt>-o</tt></dt> + <dd>produces a directory containing <tt>ObjAsm</tt> or <tt>GAS</tt> source files defining +the <small>SWI</small> veneers as separate files; object files corresponding +to them; and a text file <tt>ViaFile</tt> which may be ued as input to +<tt>LibFile</tt> to combine them into a library</dd> + <dt><tt>-h</tt></dt> <dd>produces a commented C header file defining all the constants as -macros, all the types as <tt>typedef</tt>\xB4s and all the -<small>SWI</small>\xB4s as function prototypes</dd> +macros, all the types as <tt>typedef</tt>'s and all the +<small>SWI</small>'s as function prototypes</dd> <dt><tt>-hdr</tt></dt> <dd>produces a commented assembler header file defining all the constants as symbols, all the types and structure offsets as symbols, -and all the <small>SWI</small>\xB4s as symbols</dd> +and all the <small>SWI</small>'s as symbols</dd> <dt><tt>-chelp</tt></dt> <dd>produces a <tt>SrcEdit</tt>-compatible help file for the C interface</dd> - <dt><tt>-o</tt></dt> - <dd>produces: a directory containing <tt>ObjAsm</tt> source files defining -the <small>SWI</small> veneers as separate files; object files corresponding -to them; and a text file <tt>ViaFile</tt> which may be ued as input to -<tt>LibFile</tt> to combine them into a library</dd> - <dt><tt>-cstrong</tt></dt> <dd>produces a <tt>StrongHelp</tt>-compatible help file for the C interface</dd> @@ -111,7 +120,7 @@ <li>a <i>notion</i><tt>_series</tt> is a sequence of <i>notion</i>s separated (but not terminated) by semi-colon tokens;</li> - <li>if `<i>notion</i>\xB4 is the name of a punctuation mark, it is + <li>if <i>notion</i> is the name of a punctuation mark, it is defined as that mark followed by optional white space (a category which includes comments);</li> @@ -152,8 +161,8 @@ <p>This will all be familiar to users of Pascal or <small>ALGOL</small>.</p> - <p>A <tt>type_defn</tt> with no type defines an ``abstract type\xB4\xB4. A -structure type may end with `...,\xB4 in which case various extra macros + <p>A <tt>type_defn</tt> with no type defines an "abstract type". A +structure type may end with <tt>...,</tt> in which case various extra macros will be generated. An abstract type name is often a single letter (as in <tt>wimp_w</tt>, <tt>os_f</tt>).</p> @@ -198,14 +207,14 @@ <p>Defines types. Types are built-in types (<tt>Int</tt>, <tt>Short</tt>, <tt>Byte</tt>, <tt>Char</tt>, <tt>Bits</tt>, <tt>Bytes</tt>, <tt>Bool</tt>, <tt>String</tt>, <tt>Asm</tt>, -<tt>Data</tt>) or derived types. They are classified into ``register,\xB4\xB4 -``non-register fixed-length\xB4\xB4 and ``non-register variable-length\xB4\xB4 +<tt>Data</tt>) or derived types. They are classified into "register", +"non-register fixed-length" and "non-register variable-length" types. The register types are: <tt>Int</tt>, <tt>Short</tt>, <tt>Byte</tt>, <tt>Char</tt>, <tt>Bits</tt>, <tt>Bool</tt>, <tt>Ref</tt> <i>anything</i>, and unions of these; non-register fixed-length types -are: arrays, structures containing no `...\xB4, and unions of anything so +are: arrays, structures containing no <tt>...</tt>, and unions of anything so far; and non-register variable-length types are: <tt>String</tt>, -<tt>Asm</tt>, <tt>Data</tt>, <tt>Struct</tt> with `...\xB4, and unions not +<tt>Asm</tt>, <tt>Data</tt>, <tt>Struct</tt> with <tt>...</tt>, and unions not so far mentioned.</p> <p>In fact, not all the checking that would be desirable can be done, @@ -221,15 +230,15 @@ they are in the file <tt>"types.h"</tt>, included by all headers.</p> <p>Within unions only, the type <tt>Void</tt> is allowed, signifying -that the union may be ``empty\xB4\xB4.</p> +that the union may be "empty".</p> <h3>The <tt>SWI</tt> section</h3> <p>Contains the registers needed on input, and produced on output, by each <small>SWI</small> the module defines. For details of how the -algorithm for producing the <small>A P C S</small> +algorithm for producing the <small>APCS</small> veneers works, see the section <a href = -"#apcstoswi"><small>A P C S</small> to +"#apcstoswi"><small>APCS</small> to <small>SWI</small></a>. Registers may be specified as</p> <ul> @@ -247,26 +256,26 @@ Rx = .Ref Thing: thing </pre> - <p>(``<tt>R</tt><i>x</i> contains a pointer to a <tt>Thing</tt> -called <tt>thing</tt>\xB4\xB4) and</p> + <p>(<tt>R</tt><i>x</i> contains a pointer to a <tt>Thing</tt> +called <tt>thing</tt>) and</p> <pre> Rx -> Thing: thing </pre> - <p>(``<tt>R</tt><i>x</i> points to a <tt>Thing</tt> called -<tt>thing</tt>\xB4\xB4) are closely related: the difference is one of intent + <p>(<tt>R</tt><i>x</i> points to a <tt>Thing</tt> called +<tt>thing</tt>) are closely related: the difference is one of intent only. The second form is used when the argument must be valid on input; so the <small>SWI</small> is accepting a value of type <tt>Thing</tt> as -an argument, represented by a pointer to it (``input\xB4\xB4 arguments); the +an argument, represented by a pointer to it ("input" arguments); the first form is used when the value is not present, but the -<small>SWI</small> will fill it in (``output\xB4\xB4 arguments). (A third form -of syntax could be provided for ``update\xB4\xB4 arguments, but this has not +<small>SWI</small> will fill it in ("output" arguments). (A third form +of syntax could be provided for "update" arguments, but this has not been done.) In C, the first form generates an ordinary pointer, the second a pointer-to-constant.</p> - <p>The <tt>.SWI</tt> file contains the whole of the module interface. -This includes modules <small>SWI</small>\xB4s, structures and constants, as + <p>The <tt>.swi</tt> file contains the whole of the module interface. +This includes modules <small>SWI</small>'s, structures and constants, as expected; but also other resources defined by the module: service calls, vectors, error numbers, upcalls, <tt>Wimp</tt> messages (numbers and structures), events, etc. The vector, upcall and service entries are @@ -281,21 +290,21 @@ <p>The output arguments are not written if a <small>SWI</small> fails.</p> - <p>The case of <small>P S R</small> flags being required on + <p>The case of <small>PSR</small> flags being required on input is not supported. The only two calls where this is necessary are <tt>RemV</tt> and <tt>CnpV</tt>, which are obsolescent anyway.</p> <p>If a call has no output arguments, and exactly one input argument -which is a pointer to an unnamed structure with no `...\xB4 part, then the +which is a pointer to an unnamed structure with no <tt>...</tt> part, then the structure elements are passed in in separate registers. See <tt>Wimp_SetIconState</tt> for an example.</p> <p>If a <small>SWI</small> call happens also to be -<small>A P C S</small>-compliant, this information can +<small>APCS</small>-compliant, this information can be passed to the compiler, which can then generate an inline <small>SWI</small> instruction, by using the <tt>__swi()</tt> directive provided with <small>ARM</small> C release 5. To disable this feature -for use with earlier or non-<small>ARM</small> compilers (e g, +for use with earlier or non-<small>ARM</small> compilers (e.g., <tt>CFront</tt>) requires a header file containing the lines</p> <pre> @@ -328,18 +337,18 @@ <p>There is no support for 2-byte quantities on output.</p> - <h2><a name = apcstoswi><small>A P C S</small> to + <h2><a name = apcstoswi><small>APCS</small> to <small>SWI</small></a></h2> - <p>``<small>A P C S</small> to <small>SWI</small>\xB4\xB4 is + <p>"<small>APCS</small> to <small>SWI</small>" is what <tt>DefMod</tt> does when generating library files: it generates a veneer that assumes the C function has been called via -<small>A P C S</small> (in other words, the first 4 +<small>APCS</small> (in other words, the first 4 arguments are in <tt>R0</tt>, ..., <tt>R3</tt>, and the rest are on the stack), and sets the registers up as they should be for calling the <small>SWI</small>; that calls the <small>SWI</small>; and that then puts all the registers back where they should be for the -<small>A P C S</small>-conformant exit conditions (result +<small>APCS</small>-conformant exit conditions (result in <tt>R0</tt>, other output values written to the addresses supplied on input).</p> @@ -349,11 +358,11 @@ <p>To simplify the discussion, we refer to the registers by 2 sets of names. Considered as input to and output from the <small>SWI</small>, we -call them <tt>R0</tt>, ..., <tt>R9</tt>; considered as -<small>A P C S</small> entry registers, we call them -<tt>A1</tt>, ..., <tt>A4</tt> (the ``argument registers\xB4\xB4) and -<tt>V1</tt>, ..., <tt>V6</tt> (the ``variable registers\xB4\xB4); also, -when considered as the <small>A P C S</small> result register, +call them <tt>R0</tt>, ..., <tt>R9</tt>; considered as +<small>APCS</small> entry registers, we call them +<tt>A1</tt>, ..., <tt>A4</tt> (the "argument registers") and +<tt>V1</tt>, ..., <tt>V6</tt> (the "variable registers"); also, +when considered as the <small>APCS</small> result register, we call <tt>R0</tt> just <tt>R</tt>. The remaining 6 registers are always called <tt>SL</tt>, <tt>FP</tt>, <tt>IP</tt>, <tt>SP</tt>, <tt>LR</tt>, <tt>PC</tt>.</p> @@ -411,7 +420,7 @@ <p>Consider those variable registers <i>V</i> which will have to be preserved by this whole function: these are the ones that -<small>A P C S</small> requires to be preserved which we +<small>APCS</small> requires to be preserved which we will be using ourselves, or which the <small>SWI</small> corrupts:</p> <p><i>V</i> = {4 <u><</u> <i>r</i> < 10: @@ -469,7 +478,7 @@ contains </td> <td> - saved arguments (as set up by <small>A P C S</small>) + saved arguments (as set up by <small>APCS</small>) <td> </tr> <tr> @@ -492,7 +501,7 @@ </td> <td> saved output addresses (also saved by us where not already saved by -<small>A P C S</small>) +<small>APCS</small>) <td> </tr> </table> @@ -696,7 +705,7 @@ </dt> <dd> If it works at all, it will produce the right answer. If it -doesn\xB4t, it shows the error message to the user. +doesn't, it shows the error message to the user. </dd> <dt> @@ -723,7 +732,7 @@ </li> </ol> - These don\xB4t seem to be a problem in practice. + These don't seem to be a problem in practice. </dd> </dl> @@ -1236,7 +1245,7 @@ the pointer to the filled-in buffer, so you could nest calls as with C string functions.</p> - <p>It would be good to have support for <tt>enum</tt>\xB4s, so you could + <p>It would be good to have support for <tt>enum</tt>'s, so you could have cross-references generated in the help files from the type name to allowable values of that type. We could also have support for sets of enumerated types.</p> @@ -1271,7 +1280,7 @@ <td>5<sup>th</sup> Jul 1992</td> <td>J R C</td> <td>Added Handling of <tt>FLAGS</tt> arguments, handling of constant -arguments, handling of <small>SWI</small>\xB4s that corrupt random +arguments, handling of <small>SWI</small>'s that corrupt random registers.</td> </tr> <tr> @@ -1323,7 +1332,7 @@ </table> <!-- - Notes. Remind me never to use H T M L for mathematics again ... + Notes. Remind me never to use HTML for mathematics again ... In proportional text, extra spaces round '+' '-' '×' '÷' and before '(' in function calls seem superfluous, but spaces around relations '=' '>' '<' and ellipses '...' look good. Modified: branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y 2007-05-01 12:40:24 UTC (rev 258) +++ branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y 2007-05-01 19:33:15 UTC (rev 259) @@ -1108,6 +1108,9 @@ } #endif + /* Set AsmType default. */ + AsmType = AsmType_eGCCAOF; + if ( (error = lookup_new (&needses, 16)) != NULL || (error = lookup_new (&needsatends, 16)) != NULL || (error = lookup_new (&consts, 16)) != NULL || Modified: branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c 2007-05-01 12:40:24 UTC (rev 258) +++ branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c 2007-05-01 19:33:15 UTC (rev 259) @@ -38,6 +38,7 @@ #include "def.h" #include "hdr.h" +#include "objasm.h" #undef NEEDSATEND @@ -48,20 +49,27 @@ #define UNLABELLED_INST_COL 1 #define UNLABELLED_ARG_COL 2 -static char *Op [] = {":OR:", ":AND:", "+", ":EOR:"}; +static const char *Op [] = {":OR:", ":AND:", "+", ":EOR:"}; +/* This gives the condition when to use the ':' for marking the end of an + ELF label. */ +#define NeedELFLabel (label != NULL && DoELF) +/* Comment start character. */ +#define COMMENTCHAR ((DoELF) ? '@' : ';') /* emit an instruction - optionally with label */ static int Emit ( FILE *file, - char *label, - char *inst + const char *label, + const char *inst ) { - return label != NULL? - fprintf (file, "%-*s %s\n", LABELLED_INST_COL*TAB - 1, label, inst): - fprintf (file, "%-*s %s\n", UNLABELLED_INST_COL*TAB - 1, "", inst); + return fprintf (file, + NeedELFLabel ? "%-*s: %s\n" : "%-*s %s\n", + (label != NULL) ? LABELLED_INST_COL*TAB - 1 : UNLABELLED_INST_COL*TAB - 1, + (label != NULL) ? label : "", + inst); } @@ -69,17 +77,17 @@ static int EmitS ( FILE *file, - char *label, - char *inst, - char *s + const char *label, + const char *inst, + const char *s ) { - return label != NULL? - fprintf (file, "%-*s %-*s %s\n", LABELLED_INST_COL*TAB - 1, label, - (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1, inst, s): - fprintf (file, "%-*s %-*s %s\n", UNLABELLED_INST_COL*TAB - 1, - "", (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, - inst, s); + return fprintf (file, + NeedELFLabel ? "%-*s: %-*s %s\n" : "%-*s %-*s %s\n", + (label != NULL) ? LABELLED_INST_COL*TAB - 1 : UNLABELLED_INST_COL*TAB - 1, + (label != NULL) ? label : "", + (label != NULL) ? (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1 : (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, + inst, s); } @@ -87,19 +95,18 @@ static int EmitSS ( FILE *file, - char *label, - char *inst, - char *s1, - char *s2 + const char *label, + const char *inst, + const char *s1, + const char *s2 ) { - return label != NULL? - fprintf (file, "%-*s %-*s %s%s\n", LABELLED_INST_COL*TAB - 1, - label, (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1, inst, - s1, s2): - fprintf (file, "%-*s %-*s %s%s\n", UNLABELLED_INST_COL*TAB - 1, - "", (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, - inst, s1, s2); + return fprintf (file, + NeedELFLabel ? "%-*s: %-*s %s%s\n" : "%-*s %-*s %s%s\n", + (label != NULL) ? LABELLED_INST_COL*TAB - 1 : UNLABELLED_INST_COL*TAB - 1, + (label != NULL) ? label : "", + (label != NULL) ? (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1 : (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, + inst, s1, s2); } @@ -107,20 +114,19 @@ static int EmitSSS ( FILE *file, - char *label, - char *inst, - char *s1, - char *s2, - char *s3 + const char *label, + const char *inst, + const char *s1, + const char *s2, + const char *s3 ) { - return label != NULL? - fprintf (file, "%-*s %-*s %s%s%s\n", LABELLED_INST_COL*TAB - 1, - label, (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1, inst, - s1, s2, s3): - fprintf (file, "%-*s %-*s %s%s%s\n", UNLABELLED_INST_COL*TAB - 1, - "", (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, - inst, s1, s2, s3); + return fprintf (file, + NeedELFLabel ? "%-*s: %-*s %s%s%s\n" : "%-*s %-*s %s%s%s\n", + (label != NULL) ? LABELLED_INST_COL*TAB - 1 : UNLABELLED_INST_COL*TAB - 1, + (label != NULL) ? label : "", + (label != NULL) ? (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1 : (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, + inst, s1, s2, s3); } @@ -128,17 +134,17 @@ static int EmitD ( FILE *file, - char *label, - char *inst, + const char *label, + const char *inst, int d ) { - return label != NULL? - fprintf (file, "%-*s %-*s %d\n", LABELLED_INST_COL*TAB - 1, label, - (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1, inst, d): - fprintf (file, "%-*s %-*s %d\n", UNLABELLED_INST_COL*TAB - 1, - "", (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, - inst, d); + return fprintf (file, + NeedELFLabel ? "%-*s: %-*s %d\n" : "%-*s %-*s %d\n", + (label != NULL) ? LABELLED_INST_COL*TAB - 1 : UNLABELLED_INST_COL*TAB - 1, + (label != NULL) ? label : "", + (label != NULL) ? (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1 : (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, + inst, d); } @@ -146,17 +152,17 @@ static int EmitX ( FILE *file, - char *label, - char *inst, + const char *label, + const char *inst, int x ) { - return label != NULL? - fprintf (file, "%-*s %-*s &%X\n", LABELLED_INST_COL*TAB - 1, label, - (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1, inst, x): - fprintf (file, "%-*s %-*s &%X\n", UNLABELLED_INST_COL*TAB - 1, - "", (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, - inst, x); + return fprintf (file, + (DoELF) ? ((label != NULL && label[0]) ? "%-*s: %-*s 0x%X\n" : "%-*s %-*s 0x%X\n") : "%-*s %-*s &%X\n", + (label != NULL) ? LABELLED_INST_COL*TAB - 1 : UNLABELLED_INST_COL*TAB - 1, + (label != NULL) ? label : "", + (label != NULL) ? (LABELLED_ARG_COL - LABELLED_INST_COL)*TAB - 1 : (UNLABELLED_ARG_COL - UNLABELLED_INST_COL)*TAB - 1, + inst, x); } /* Prints a declaration of |v| as an object of type |t|. @@ -165,28 +171,28 @@ static int Emit_Decl1 ( FILE *file, // output file - char *type, // object type - char *v, // object name + const char *type, // object type + const char *v, // object name osbool top_level, // if true then equate, else assign storage - char *cs // number of elements in array + const char *cs // number of elements in array ) { int rc = 0; tracef( "Emit_Decl1: %s; %s; %s\n" _ v _ type _ top_level?"TRUE":"FALSE" ); - if ( top_level ) + if (top_level) { - if ((rc = EmitD (file, "", "^", 0)) < 0) + if ((rc = EmitD (file, NULL, (DoELF) ? ".struct" : "^", 0)) < 0) goto finish; - if ((rc = EmitSS (file, "", "#", cs, type)) < 0) + if ((rc = EmitSS (file, NULL, (DoELF) ? ".skip" : "#", cs, type)) < 0) goto finish; - if ((rc = EmitS (file, v, "*", "@")) < 0) + if ((rc = (DoELF) ? Emit (file, v, "") : EmitS (file, v, "*", "@")) < 0) goto finish; } else { - if ((rc = EmitSS (file, v, "#", cs, type)) < 0) + if ((rc = EmitSS (file, v, (DoELF) ? ".skip" : "#", cs, type)) < 0) goto finish; } @@ -199,7 +205,7 @@ ( FILE *file, // output file def_t t, // object type - char *v, // object name + const char *v, // object name osbool top_level, // if true then equate, else assign storage int count // number of elements in array ) @@ -216,50 +222,42 @@ switch (t->tag) { case def_TYPE_INT: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Int")) < 0) - if (( rc = Emit_Decl1 ( file, "Int", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Int", v, top_level, cs)) < 0) goto finish; break; case def_TYPE_SHORT: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Short")) < 0) - if (( rc = Emit_Decl1 ( file, "Short", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Short", v, top_level, cs)) < 0) goto finish; break; case def_TYPE_BYTE: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Byte")) < 0) - if (( rc = Emit_Decl1 ( file, "Byte", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Byte", v, top_level, cs)) < 0) goto finish; break; case def_TYPE_CHAR: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Char")) < 0) - if (( rc = Emit_Decl1 ( file, "Char", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Char", v, top_level, cs)) < 0) goto finish; break; case def_TYPE_BITS: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Bits")) < 0) - if (( rc = Emit_Decl1 ( file, "Bits", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Bits", v, top_level, cs)) < 0) goto finish; break; case def_TYPE_BYTES: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Bytes")) < 0) - if (( rc = Emit_Decl1 ( file, "Bytes", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Bytes", v, top_level, cs)) < 0) goto finish; break; case def_TYPE_BOOL: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Bool")) < 0) - if (( rc = Emit_Decl1 ( file, "Bool", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Bool", v, top_level, cs)) < 0) goto finish; break; case def_TYPE_REF: -// if ((rc = EmitSS (file, v, top_level? "*": "#", cs, "Ptr")) < 0) - if (( rc = Emit_Decl1 ( file, "Ptr", v, top_level, cs )) < 0 ) + if ((rc = Emit_Decl1 (file, "Ptr", v, top_level, cs)) < 0) goto finish; break; @@ -267,7 +265,11 @@ case def_TYPE_ASM: case def_TYPE_DATA: case def_TYPE_VOID: - if ((rc = EmitS (file, v, top_level? "*": "#", "Skip")) < 0) + if ((rc = + (DoELF) ? + EmitS (file, v, top_level ? "" : ".skip", "Skip") + : + EmitS (file, v, top_level ? "*" : "#", "Skip")) < 0) goto finish; break; @@ -277,15 +279,26 @@ int i; if (top_level) - if ((rc = EmitD (file, "", "^", 0)) < 0) + if ((rc = EmitD (file, NULL, (DoELF) ? ".struct" : "^", 0)) < 0) goto finish; if (t->data AS list.base) { // the struct is based upon another - char v1 [def_ID_LIMIT + 8]; - sprintf( v1, "%s_MEMBERS", t->data AS list.base->data AS id ); - Emit (file, v, v1 ); + if (DoELF) + { + char v1 [def_ID_LIMIT + sizeof("_MEMBERS")-1 + def_ID_LIMIT + sizeof(" Base")-1]; + sprintf (v1, "%s_MEMBERS %s", t->data AS list.base->data AS id, v); + if ((rc = Emit (file, NULL, v1)) < 0) + goto finish; + } + else + { + char v1 [def_ID_LIMIT + sizeof("_MEMBERS")-1]; + sprintf (v1, "%s_MEMBERS", t->data AS list.base->data AS id); + if ((rc = Emit (file, v, v1)) < 0) + goto finish; + } } for (i = 0; i < t->data AS list.count; i++) @@ -304,15 +317,15 @@ } if (top_level) - if ((rc = EmitS (file, v, "*", "@")) < 0) + if ((rc = (DoELF) ? Emit (file, v, "") : EmitS (file, v, "*", "@")) < 0) goto finish; // emit a variable-sized structure as a macro if (t->data AS list.ellipsis && t->data AS list.count > 1) { - char v1 [def_ID_LIMIT + 5]; - char v2 [def_ID_LIMIT + 8]; + char v1 [def_ID_LIMIT + sizeof("_MEMBERS")-1]; + char v2 [def_ID_LIMIT + sizeof("_MEMBERS")-1 + def_ID_LIMIT + sizeof(" Base")-1]; // define a macro describing the members if (top_level) @@ -320,20 +333,38 @@ if ((rc = Emit (file, 0, "")) < 0) goto finish; - if ((rc = Emit (file, 0, "MACRO")) < 0) - goto finish; + if (DoELF) + { + sprintf (v1, "%s_MEMBERS label", v); + if ((rc = Emit (file, NULL, ".altmacro")) < 0 + || (rc = EmitS (file, NULL, ".macro", v1)) < 0) + goto finish; + } + else + { + if ((rc = Emit (file, NULL, "MACRO")) < 0) + goto finish; - sprintf( v1, "%s_MEMBERS", v ); - if ((rc = Emit (file, "$label", v1 )) < 0) - goto finish; + sprintf (v1, "%s_MEMBERS", v); + if ((rc = Emit (file, "$label", v1)) < 0) + goto finish; + } } if (t->data AS list.base) { // the struct is based upon another - sprintf( v1, "%s_MEMBERS", t->data AS list.base->data AS id ); -// Emit (file, v, v1 ); // TV 20021128 - Emit (file, "$label", v1 ); + if (DoELF) + { + sprintf (v1, "%s_MEMBERS \\label", t->data AS list.base->data AS id); + Emit (file, "\\label", v1); + } + else + { + sprintf (v1, "%s_MEMBERS", t->data AS list.base->data AS id); +// Emit (file, v, v1); // TV 20021128 + Emit (file, "$label", v1); + } } if (top_level) @@ -341,7 +372,7 @@ for (i = 0; i < t->data AS list.count - 1; i++) { if ((rc = sprintf (v1, - "$label._%s", + (DoELF) ? "\\label&_%s" : "$label._%s", t->data AS list.members [i]->name ) ) < 0) @@ -354,25 +385,31 @@ } // close the macro definition - if ((rc = Emit (file, 0, "MEND")) < 0) + if ((rc = Emit (file, NULL, (DoELF) ? ".endm" : "MEND")) < 0) goto finish; } // define the base structure in terms of the macro if (top_level) { - if (( rc = sprintf( v1, "%sBase", v ) ) < 0 ) + if ((rc = sprintf (v1, "%sBase", v)) < 0) goto finish; - if (( rc = sprintf( v2, "%s_MEMBERS", v ) ) < 0 ) + if ((rc = (DoELF) ? + sprintf (v2, "%s_MEMBERS %sBase", v, v) + : + sprintf (v2, "%s_MEMBERS", v)) < 0) goto finish; - if ((rc = Emit (file, 0, "")) < 0) + if ((rc = Emit (file, NULL, "")) < 0) goto finish; - if ((rc = EmitD (file, "", "^", 0)) < 0) + if ((rc = EmitD (file, NULL, (DoELF) ? ".struct" : "^", 0)) < 0) goto finish; - if ((rc = Emit (file, v1, v2)) < 0) + if ((rc = Emit (file, (DoELF) ? NULL : v1, v2)) < 0) goto finish; - if ((rc = EmitS (file, v1, "*", "@")) < 0) + if ((rc = (DoELF) ? + Emit (file, v1, "") + : + EmitS (file, v1, "*", "@")) < 0) goto finish; } } @@ -384,13 +421,16 @@ int i; if (top_level) - if ((rc = EmitD (file, "", "^", 0)) < 0) + if ((rc = EmitD (file, NULL, (DoELF) ? ".struct" : "^", 0)) < 0) goto finish; /*Use the union name itself to hold the offset of the start of the union.*/ if (!top_level) - if ((rc = EmitS (file, v, "*", "@")) < 0) + if ((rc = (DoELF) ? + Emit (file, v, "") + : + EmitS (file, v, "*", "@")) < 0) goto finish; for (i = 0; i < t->data AS list.count; i++) @@ -402,12 +442,12 @@ /*Set {VAR} back to the origin of the union.*/ if (!top_level) { - if ((rc = EmitS (file, "", "^", v)) < 0) + if ((rc = EmitS (file, NULL, (DoELF) ? ".struct" : "^", v)) < 0) goto finish; } else { - if ((rc = EmitD (file, "", "^", 0)) < 0) + if ((rc = EmitD (file, NULL, (DoELF) ? ".struct" : "^", 0)) < 0) goto finish; } } @@ -423,7 +463,10 @@ } if (top_level) - if ((rc = EmitS (file, v, "*", "@")) < 0) + if ((rc = (DoELF) ? + Emit (file, v, "") + : + EmitS (file, v, "*", "@")) < 0) goto finish; } break; @@ -443,8 +486,16 @@ break; case def_TYPE_ID: - if ((rc = EmitS (file, v, top_level? "*": "#", t->data AS id)) < 0) - goto finish; + if (DoELF) + { + if ((rc = Emit_Decl1 (file, t->data AS id, v, top_level, "")) < 0) + goto finish; + } + else + { + if ((rc = EmitS (file, v, top_level ? "*" : "#", t->data AS id)) < 0) + goto finish; + } break; default: @@ -579,46 +630,65 @@ return rc; } -static int Emit_Get (FILE *file, char *name) - +static int Emit_Get (FILE *file, const char *name) { int rc; - char s [FILENAME_MAX + 1], get [FILENAME_MAX + 1], - hdr [FILENAME_MAX + 1]; - if ((rc = sprintf (get, "%s%s", "Get_", name)) < 0) - goto finish; - if ((rc = sprintf (hdr, "%s%s", name, "_Hdr")) < 0) - goto finish; + if (DoELF) + { + if ((rc = fprintf (file, "# ifndef Get_%s\n" + "# define Get_%s\n" +#ifdef EXECUTE_ON_UNIX + // FIXME: this is strange, different assembler header output depending on which host + // these were created ?! + "# include \"oslib/%s.Hdr\"\n" +#else + "# include \"oslib.Hdr.%s\"\n" +#endif + "# endif\n", name, name, name)) < 0) + goto finish; + } + else + { + char s [FILENAME_MAX + 1], get [FILENAME_MAX + 1]; + char hdr [FILENAME_MAX + 1]; - if ((rc = EmitSS (file, NULL, "[", ":LNOT: :DEF: ", get)) < 0) - goto finish; - if ((rc = EmitS (file, NULL, "GBLS", get)) < 0) - goto finish; - if ((rc = Emit (file, NULL, "]")) < 0) - goto finish; + if ((rc = sprintf (get, "%s%s", "Get_", name)) < 0) + goto finish; + if ((rc = sprintf (hdr, "%s%s", name, "_Hdr")) < 0) + goto finish; + if ((rc = EmitSS (file, NULL, "[", ":LNOT: :DEF: ", get)) < 0) + goto finish; + if ((rc = EmitS (file, NULL, "GBLS", get)) < 0) + goto finish; + if ((rc = Emit (file, NULL, "]")) < 0) + goto finish; + #ifdef EXECUTE_ON_UNIX - if ((rc = sprintf (s, "\"GET oslib/%s.Hdr\"", name)) < 0) + // FIXME: this is strange, different assembler header output depending on which host + // these were created ?! + if ((rc = sprintf (s, "\"GET oslib/%s.Hdr\"", name)) < 0) #else - if ((rc = sprintf (s, "\"GET oslib.Hdr.%s\"", name)) < 0) + if ((rc = sprintf (s, "\"GET oslib.Hdr.%s\"", name)) < 0) #endif - goto finish; + goto finish; - if ((rc = EmitSS (file, NULL, "[", ":LNOT: :DEF: ", hdr)) < 0) - goto finish; - if ((rc = EmitS (file, get, "SETS", s)) < 0) - goto finish; - if ((rc = Emit (file, NULL, "|")) < 0) - goto finish; - if ((rc = EmitS (file, get, "SETS", "\"\"")) < 0) - goto finish; - if ((rc = Emit (file, NULL, "]")) < 0) - goto finish; + if ((rc = EmitSS (file, NULL, "[", ":LNOT: :DEF: ", hdr)) < 0) + goto finish; + if ((rc = EmitS (file, get, "SETS", s)) < 0) + goto finish; + if ((rc = Emit (file, NULL, "|")) < 0) + goto finish; + if ((rc = EmitS (file, get, "SETS", "\"\"")) < 0) + goto finish; + if ((rc = Emit (file, NULL, "]")) < 0) + goto finish; - if ((rc = sprintf (s, "$Get_%s", name)) < 0) - return rc; - if ((rc = Emit (file, NULL, s)) < 0) - goto finish; + if ((rc = sprintf (s, "$Get_%s", name)) < 0) + goto finish; + if ((rc = Emit (file, NULL, s)) < 0) + goto finish; + } if ((rc = fprintf (file, "\n")) < 0) goto finish; @@ -630,8 +700,8 @@ os_error *hdr_output ( FILE *file, - char *title, - char *author, + const char *title, + const char *author, lookup_t needses, lookup_t needsatends, lookup_t consts, @@ -656,19 +726,33 @@ #endif /*Emit the TITLE declaration.*/ + time (&now); if ((rc = fprintf (file, + (DoELF) ? + "@ GNU AS assembler header file for %s\n" + "@ Written by DefMod (" __DATE__ ") on %s" + "@ %s\n\n" + : ";Assembler header file for %s\n" - ";written by DefMod (%s) on %s" - ";%s\n" - "\n", - title, __DATE__, (time (&now), ctime (&now)), author)) < 0) + ";written by DefMod (" __DATE__ ") on %s" + ";%s\n\n", + title, ctime (&now), author)) < 0) goto finish; /* guard against multiple inclusion */ - if ((rc = EmitSSS (file, NULL, "[", ":LNOT: :DEF: ", title, "_Hdr")) < 0) - goto finish; - if ((rc = EmitSS (file, NULL, "GBLS", title, "_Hdr")) < 0) - goto finish; + if (DoELF) + { + if ((rc = fprintf (file, "#ifndef %s_Hdr\n" + "# define %s_Hdr\n", title, title)) < 0) + goto finish; + } + else + { + if ((rc = EmitSSS (file, NULL, "[", ":LNOT: :DEF: ", title, "_Hdr")) < 0) + goto finish; + if ((rc = EmitSS (file, NULL, "GBLS", title, "_Hdr")) < 0) + goto finish; + } if ((rc = fprintf (file, "\n")) < 0) goto finish; @@ -676,12 +760,6 @@ if ((rc = Emit_Get (file, "Types")) < 0) goto finish; -#if 0 /* not everything needs OS.Hdr */ - /*Make sure we have Hdr.OS.*/ - if ((rc = Emit_Get (file, "OS")) < 0) - goto finish; -#endif - /*Emit the NEEDS declarations.*/ context = 0; while (TRUE) @@ -695,15 +773,6 @@ goto finish; } -#if 0 // moved forward to ensure OS.Hdr is not included recursively - if ((rc = EmitSSS (file, NULL, "[", ":LNOT: :DEF: ", title, "_Hdr")) < 0) - goto finish; - if ((rc = EmitSS (file, NULL, "GBLS", title, "_Hdr")) < 0) - goto finish; - if ((rc = fprintf (file, "\n")) < 0) - goto finish; -#endif - /*Emit the CONST declarations.*/ start = TRUE; context = 0; @@ -716,14 +785,22 @@ if (start) { - if ((rc = fprintf (file, ";Symbols for constants\n")) < 0) + if ((rc = fprintf (file, "%cSymbols for constants\n", COMMENTCHAR)) < 0) goto finish; start = FALSE; } + if (DoELF) + { + if ((rc = fprintf (file, "# define %s 0x%x\n", cnst, c->value)) < 0) + goto finish; + } + else switch (c->type->tag) { - case def_TYPE_INT: case def_TYPE_SHORT: case def_TYPE_BYTE: + case def_TYPE_INT: + case def_TYPE_SHORT: + case def_TYPE_BYTE: if ((rc = EmitD (file, cnst, "*", c->value)) < 0) goto finish; break; @@ -787,8 +864,7 @@ /* emit header if first entry */ if (start) { - if ((rc = fprintf (file, - ";Symbols for structure offsets and sizes\n")) < 0) + if ((rc = fprintf (file, "%cSymbols for structure offsets and sizes\n", COMMENTCHAR)) < 0) goto finish; start = FALSE; } @@ -803,8 +879,17 @@ else { /* for abstract type, equate symbol to its size */ - if ((rc = EmitS (file, type, "*", "4 ;abstract type")) < 0) - goto finish; + if (DoELF) + { + if ((rc = fprintf (file, "@ abstract type\n" + "# define %s 4\n\n", type)) < 0) + goto finish; + } + else + { + if ((rc = EmitS (file, type, "*", "4 ;abstract type")) < 0) + goto finish; + } } } @@ -829,8 +914,7 @@ if (start) { - if ((rc = fprintf (file, - ";Symbols for SWI's and SWI reason codes\n")) < 0) + if ((rc = fprintf (file, "%cSymbols for SWI's and SWI reason codes\n", COMMENTCHAR)) < 0) goto finish; start = FALSE; } @@ -840,20 +924,42 @@ titled = FALSE; if (s->starred_swi) { - if ((rc = EmitX (file, title, "*", s->swi | 1 << 17)) < 0) - goto finish; - if ((rc = EmitX (file, title + 1, "*", s->swi)) < 0) - goto finish; + if (DoELF) + { + if ((rc = fprintf (file, ".set %s,0x%x\n" + ".set %s,0x%x\n", + title, s->swi | (1 << 17), title + 1, s->swi)) < 0) + goto finish; + } + else + { + if ((rc = EmitX (file, title, "*", s->swi | 1 << 17)) < 0 + || (rc = EmitX (file, title + 1, "*", s->swi)) < 0) + goto finish; + } titled = TRUE; } else + { for (i = 0; i < 10; i++) + { if (s->starred_constants [i]) - { if ((rc = EmitX (file, title + 1, "*", s->constants [i])) < 0) - goto finish; + { + if (DoELF) + { + if ((rc = fprintf (file, "# define %s 0x%x\n", title + 1, s->constants [i])) < 0) + goto finish; + } + else + { + if ((rc = EmitX (file, title + 1, "*", s->constants [i])) < 0) + goto finish; + } titled = TRUE; break; } + } + } if (titled) { @@ -865,7 +971,7 @@ { if (first) { - if ((rc = fprintf (file, " ;Entry\n")) < 0) + if ((rc = fprintf (file, " %cEntry\n", COMMENTCHAR)) < 0) goto finish; first = FALSE; } @@ -874,7 +980,8 @@ { /*there is an operation to involve*/ if ((rc = fprintf (file, - " ; R%d = &%X %s %s (", + " %c R%d = &%X %s %s (", + COMMENTCHAR, i, s->constants [i], Op [s->op [i]], s->inputs [i]->name)) < 0) goto finish; @@ -888,7 +995,8 @@ else { if ((rc = fprintf (file, - " ; R%d = &%X\n", + " %c R%d = &%X\n", + COMMENTCHAR, i, s->constants [i])) < 0) goto finish; } @@ -897,12 +1005,13 @@ { if (first) { - if ((rc = fprintf (file, " ;Entry\n")) < 0) + if ((rc = fprintf (file, " %cEntry\n", COMMENTCHAR)) < 0) goto finish; first = FALSE; } - if ((rc = fprintf (file, " ; R%d %s %s (", + if ((rc = fprintf (file, " %c R%d %s %s (", + COMMENTCHAR, i, (s->ri & 1 << i) == 0? "=": "->", s->inputs [i]->name)) < 0) @@ -921,13 +1030,14 @@ { if (first) { - if ((rc = fprintf (file, " ;Exit\n")) < 0) + if ((rc = fprintf (file, " %cExit\n", COMMENTCHAR)) < 0) goto finish; first = FALSE; } if ((rc = fprintf (file, - " ; R%d %s %s (", + " %c R%d %s %s (", + COMMENTCHAR, i, (s->ro & 1 << i) == 0? "=": "->", s->outputs [i]->name)) < 0) @@ -943,13 +1053,13 @@ { if (first) { - if ((rc = fprintf (file, " ;Exit\n")) < 0) + if ((rc = fprintf (file, " %cExit\n", COMMENTCHAR)) < 0) goto finish; first = FALSE; } if ((rc = fprintf (file, - " ; R%d corrupted\n", i)) < 0) + " %c R%d corrupted\n", COMMENTCHAR, i)) < 0) goto finish; } } @@ -974,10 +1084,18 @@ } #endif - if ((rc = Emit (file, NULL, "]")) < 0) - goto finish; - if ((rc = Emit (file, NULL, "END")) < 0) - goto finish; + if (DoELF) + { + if ((rc = fprintf (file, "#endif\n")) < 0) + goto finish; + } + else + { + if ((rc = Emit (file, NULL, "]")) < 0) + goto finish; + if ((rc = Emit (file, NULL, "END")) < 0) + goto finish; + } finish: if (rc < 0) error = (os_error *)_kernel_last_oserror (); /* TV 980115 */ Modified: branches/simplified-build/!OsLib/Tools/DefMod2/hdr.h =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/hdr.h 2007-05-01 12:40:24 UTC (rev 258) +++ branches/simplified-build/!OsLib/Tools/DefMod2/hdr.h 2007-05-01 19:33:15 UTC (rev 259) @@ -13,7 +13,7 @@ #include "lookup.h" #endif -extern os_error *hdr_output (FILE *, char *, char *, lookup_t, lookup_t, +extern os_error *hdr_output (FILE *, const char *, const char *, lookup_t, lookup_t, lookup_t, lookup_t, lookup_t); #endif Modified: branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c 2007-05-01 12:40:24 UTC (rev 258) +++ branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c 2007-05-01 19:33:15 UTC (rev 259) @@ -176,6 +176,14 @@ fprintf ( file, + (DoELF) ? + "@GNU AS file for %s\n" + "@written by DefMod (" __DATE__ ") on %s" + "@%s\n" + "\n" + "R\t.req\tr0\n" + "\n" + : ";ObjAsm file for %s\n" ";written by DefMod (" __DATE__ ") on %s" ";%s\n" @@ -289,7 +297,7 @@ const char *s0 ) { - return fprintf (file, "%s ROUT\n", s0); + return fprintf (file, (DoELF) ? "%s:\n" : "%s ROUT\n", s0); } /*-----------------------------------------------------------------------*/ @@ -321,7 +329,7 @@ const char *comment ) { - return fprintf (file, ";%s\n", comment); + return fprintf (file, (DoELF) ? "@%s\n" : ";%s\n", comment); } /*-----------------------------------------------------------------------*/ @@ -385,9 +393,11 @@ lookup_t types ) { - char c_name [def_ID_LIMIT + 1], - c_plus_plus_name [def_C_PLUS_PLUS_LIMIT + 1], s1 [127 + 1], - s2 [127 + 1]; + char c_name [def_ID_LIMIT + 1], s1 [127 + 1], s2 [127 + 1]; +#if 0 + char c_plus_plus_name [def_C_PLUS_PLUS_LIMIT + 1], +#endif + bits o, v, a, p, w; /*sets*/ int ni, no, nc, nk, nv, na, np, nw, /*set counts*/ n, m, /*menials*/ @@ -400,8 +410,10 @@ def_as_extern (c_name + (!nonx? 1: 0), swi); #if 0 def_as_c_plus_plus (c_plus_plus_name + (!nonx? 1: 0), swi, s); + if (!nonx) c_name [0] = c_plus_plus_name [0] = 'x'; +#else + if (!nonx) c_name [0] = 'x'; #endif - if (!nonx) c_name [0] = c_plus_plus_name [0] = 'x'; /*Count the various set sizes*/ ni = Set_Count (s->i); @@ -577,7 +589,7 @@ if (m == 0) break; /*no more bits*/ - if ((rc = sprintf (s2, "#&%X", m)) < 0) + if ((rc = sprintf (s2, (DoELF) ? "#0x%X" : "#&%X", m)) < 0) goto finish; if ((rc = Emit3 (file, Op (s->op [n]), SWI_Names [n], @@ -607,7 +619,7 @@ if (m == 0) break; /*no more bits*/ - if ((rc = sprintf (s2, "#&%X", m)) < 0) + if ((rc = sprintf (s2, (DoELF) ? "#0x%X" : "#&%X", m)) < 0) goto finish; if (first) @@ -639,12 +651,12 @@ for (n = 0; n < 4; n++) if (Set_Elem (n, w)) /*Trash register |n| now, just to show we can do it.*/ - if ((rc = Emit2 (file, "MOV", SWI_Names [n], "#&FF0")) < 0) + if ((rc = Emit2 (file, "MOV", SWI_Names [n], (DoELF) ? "#0xFF0" : "#&FF0")) < 0) goto finish; #endif /*Registers now set up properly - do the business part.*/ - if ((rc = sprintf (s1, "&%X", s->swi | (!nonx? 1 << 17: 0))) < 0) + if ((rc = sprintf (s1, (DoELF) ? "0x%X" : "&%X", s->swi | (!nonx? 1 << 17: 0))) < 0) goto finish; if ((rc = Emit1 (file, "SWI", s1)) < 0) @@ -655,7 +667,7 @@ for (n = 0; n < 4; n++) if (Set_Elem (n, w)) { /*Check that register |n| still has its contents.*/ - if ((rc = Emit2 (file, "TEQ", SWI_Names [n], "#&FF0")) < 0) + if ((rc = Emit2 (file, "TEQ", SWI_Names [n], (DoELF) ? "#0xFF0" : "#&FF0")) < 0) goto finish; if ((rc = Emit2 (file, "MOVNE", "PC", "#0")) < 0) goto finish; @@ -666,7 +678,7 @@ if (no + f > 0) { if (!nonx) - if ((rc = Emit1 (file, "BVS", "%a99")) < 0) + if ((rc = Emit1 (file, "BVS", (DoELF) ? "99f" : "%a99")) < 0) goto finish; for (n = 0; n < no + f; n++) @@ -755,7 +767,7 @@ { if ((rc = Emit2 (file, "MOV", "R", "#0")) < 0) goto finish; - if ((rc = Emit_Local (file, "99")) < 0) + if ((rc = Emit_Local (file, (DoELF) ? "99:" : "99")) < 0) goto finish; } else @@ -861,6 +873,14 @@ goto finish; } + if (DoELF) + { + /* Define size of function body. */ + sprintf (s2, ". - %s", c_name + (!nonx? 1: 0)); + if ((rc = Emit2 (file, ".size", c_name + (!nonx? 1: 0), s2)) < 0) + goto finish; + } + if (nw > 0) { if ((rc = Format_SWI_List (s1, w, FALSE)) < 0) @@ -896,7 +916,6 @@ def_s s; void *context; int rc = 0; - osbool done_fopen_via_file = FALSE, done_fopen_object = FALSE; FILE *via_file = NULL, *object = NULL /*for Norcroft*/; /* Make sure the assembler type has been set. */ @@ -915,8 +934,10 @@ context = 0; while (TRUE) { - char c_name [def_ID_LIMIT + 1], - c_plus_plus_name [def_C_PLUS_PLUS_LIMIT + 1]; + char c_name [def_ID_LIMIT + 1]; +#if 0 + char c_plus_plus_name [def_C_PLUS_PLUS_LIMIT + 1]; +#endif if ((error = lookup_enumerate (swis, &swi, (void **) &s, &context)) != NULL) @@ -930,26 +951,50 @@ c_name [0] = 'x'; #if 0 def_as_c_plus_plus (c_plus_plus_name + 1, swi, s); + c_plus_plus_name [0] = 'x'; #endif - c_plus_plus_name [0] = 'x'; - if ((rc = Emit1 (file, "EXPORT", c_name)) < 0) - goto finish; - if ((rc = Emit1 (file, "EXPORT", c_name + 1)) < 0) - goto finish; + if (DoELF) + { + if ((rc = Emit1 (file, ".global", c_name)) < 0 + || (rc = Emit2 (file, ".type", c_name, "%function")) < 0 + || (rc = Emit1 (file, ".global", c_name + 1)) < 0 + || (rc = Emit2 (file, ".type", c_name + 1, "%function")) < 0) + goto finish; #if 0 - if ((rc = Emit1 (file, "EXPORT", c_plus_plus_name)) < 0) - goto finish; - if ((rc = Emit1 (file, "EXPORT", c_plus_plus_name + 1)) < 0) - goto finish; + if ((rc = Emit1 (file, ".global", c_plus_plus_name)) < 0 + || (rc = Emit2 (file, ".type", c_plus_plus_name, "%function")) < 0 + || (rc = Emit1 (file, ".global", c_plus_plus_name + 1)) < 0 + || (rc = Emit2 (file, ".type", c_plus_plus_name + 1, "%function")) < 0) + goto finish; #endif + } + else + { + if ((rc = Emit1 (file, "EXPORT", c_name)) < 0 + || (rc = Emit1 (file, "EXPORT", c_name + 1)) < 0) + goto finish; +#if 0 + if ((rc = Emit1 (file, "EXPORT", c_plus_plus_name)) < 0 + || (rc = Emit1 (file, "EXPORT", c_plus_plus_name + 1)) < 0) + goto finish; +#endif + } } } if ((rc = Emit_Line (file)) < 0) goto finish; - if ((rc = Emit2 (file, "AREA", "|SWI$$Code|", "CODE, READONLY, PIC")) < 0) - goto finish; + if (DoELF) + { + if ((rc = Emit0 (file, ".text")) < 0) + goto finish; + } + else + { + if ((rc = Emit2 (file, "AREA", "|SWI$$Code|", "CODE, READONLY, PIC")) < 0) + goto finish; + } if ((rc = Emit_Line (file)) < 0) goto finish; @@ -977,7 +1022,7 @@ goto finish; } - if ((rc = Emit0 (file, "END")) < 0) + if ((rc = Emit0 (file, (DoELF) ? ".end" : "END")) < 0) goto finish; } else @@ -990,21 +1035,19 @@ if ((error = xosfile_create_dir (output, 0)) != NULL) goto finish; -//#ifndef EXECUTE_ON_UNIX if ((via_file = fopen ("ViaFile", "w+")) == NULL) { error = (os_error*)_kernel_last_oserror (); goto finish; } - done_fopen_via_file = TRUE; -//#endif context = 0; while (TRUE) { - char c_name [def_ID_LIMIT + 1], - c_plus_plus_name [def_C_PLUS_PLUS_LIMIT + 1], - dir_name [FILENAME_MAX + 1]; + char c_name [def_ID_LIMIT + 1], dir_name [FILENAME_MAX + 1]; +#if 0 + char c_plus_plus_name [def_C_PLUS_PLUS_LIMIT + 1], +#endif osbool nonx; if ((error = lookup_enumerate (swis, &swi, (void **) &s, @@ -1020,8 +1063,10 @@ #if 0 def_as_c_plus_plus (c_plus_plus_name + (!nonx? 1: 0), swi, s); + if (!nonx) c_name [0] = c_plus_plus_name [0] = 'x'; +#else + if (!nonx) c_name [0] = 'x'; #endif - if (!nonx) c_name [0] = c_plus_plus_name [0] = 'x'; /*Get the SWI number truncated to 4 bits.*/ if ((rc = sprintf (dir_name, "0x%.5X%s", s->swi & 0xDFFF0, @@ -1061,31 +1106,51 @@ error = (os_error*)_kernel_last_oserror (); goto finish; } - done_fopen_object = TRUE; if ((rc = Emit_Header (object, swi, author)) < 0) goto finish; + if (DoELF) + { + if ((rc = Emit1 (object, ".global", c_name)) < 0 + || (rc = Emit2 (object, ".type", c_name, "%function")) < 0) + goto finish; +#if 0 + if ((rc = Emit1 (object, ".global", c_plus_plus_name)) < 0 + || (rc = Emit2 (object, ".type", c_plus_plus_name, "%function")) < 0) + goto finish; +#endif + } + else + { if ((rc = Emit1 (object, "EXPORT", c_name)) < 0) goto finish; #if 0 if ((rc = Emit1 (object, "EXPORT", c_plus_plus_name)) < 0) goto finish; #endif + } if ((rc = Emit_Line (object)) < 0) goto finish; - if ((rc = Emit2 (object, "AREA", - "|SWI$$Code|", "CODE, READONLY, PIC")) < 0) - goto finish; + if (DoELF) + { + if ((rc = Emit0 (object, ".text")) < 0) + goto finish; + } + else + { + if ((rc = Emit2 (object, "AREA", "|SWI$$Code|", "CODE, READONLY, PIC")) < 0) + goto finish; + } if ((rc = Emit_Line (object)) < 0) goto finish; if ((rc = Emit_Code (object, swi, s, nonx, apcs32, types)) < 0) goto finish; - if ((rc = Emit0 (object, "END")) < 0) + if ((rc = Emit0 (object, (DoELF) ? ".end" : "END")) < 0) goto finish; if (fclose (object) == EOF) @@ -1093,7 +1158,7 @@ error = (os_error*)_kernel_last_oserror (); goto finish; } - done_fopen_object = FALSE; + object = NULL; switch (AsmType) { @@ -1125,7 +1190,7 @@ break; case AsmType_eGCCELF: if ((rc = sprintf (cmd, - "arm-unknown-riscos-gcc -c -xassembler -Wa,%s -o %s %s", + "arm-unknown-riscos-gcc -c -xassembler %s -o %s %s", apcs32 ? "-mapcs-32" : "-mapcs-26", name2, name1)) < 0) goto finish; @@ -1159,9 +1224,9 @@ goto finish; } - if (done_fopen_via_file) - if ((rc = fprintf (via_file, "%s\n", name2)) < 0) - goto finish; + if (via_file != NULL + && (rc = fprintf (via_file, "%s\n", name2)) < 0) + goto finish; } } @@ -1172,10 +1237,10 @@ finish: if (rc < 0) error = (os_error*)_kernel_last_oserror (); - if (done_fopen_object && fclose (object) == EOF && error == NULL) + if (object != NULL && fclose (object) == EOF && error == NULL) error = (os_error*)_kernel_last_oserror (); - if (done_fopen_via_file && fclose (via_file) == EOF && error == NULL) + if (via_file != NULL && fclose (via_file) == EOF && error == NULL) error = (os_error*)_kernel_last_oserror (); return error; Modified: branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h 2007-05-01 12:40:24 UTC (rev 258) +++ branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h 2007-05-01 19:33:15 UTC (rev 259) @@ -23,6 +23,8 @@ extern AsmType_e AsmType; +#define DoELF (AsmType == AsmType_eGCCELF) + /*if |separate|, output is to the directory |output|; otherwise, to the file |file|.*/ extern os_error *objasm_output (FILE *file, const char *title, const char *author, lookup_t types, lookup_t swis, osbool separate, osbool apcs32, char *output); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |