From: <jt...@us...> - 2007-04-28 13:28:46
|
Revision: 254 http://ro-oslib.svn.sourceforge.net/ro-oslib/?rev=254&view=rev Author: jtytgat Date: 2007-04-28 06:28:42 -0700 (Sat, 28 Apr 2007) Log Message: ----------- Start of DefMod2 changes to support both AOF and ELF toolkits using the same binary. - New option: -asmtype specifying which assembler program needs to be used (default: gccaof). - Constify some function APIs, variables. - Made APCS-32 default. Modified Paths: -------------- branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_AOF branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_ELF branches/simplified-build/!OsLib/Tools/DefMod2/Makefile branches/simplified-build/!OsLib/Tools/DefMod2/cheader.c branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h Modified: branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_AOF =================================================================== --- branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_AOF 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_AOF 2007-04-28 13:28:42 UTC (rev 254) @@ -18,7 +18,7 @@ export OBJEXCEPTDIR := $(BUILDDIR)/Objs/Exceptions export BYTEWIDE := $(SOURCEDIR)/ByteWide -export DEFMOD := $(BINDIR)/defmod +export DEFMOD := $(BINDIR)/defmod -asmtype gccaof export REDUCEAOF := $(BINDIR)/reduceaof export BINDHELP := $(BINDIR)/bindhelp Modified: branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_ELF =================================================================== --- branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_ELF 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Source/Makefile.setup.CROSSGCC_ELF 2007-04-28 13:28:42 UTC (rev 254) @@ -18,7 +18,7 @@ export OBJEXCEPTDIR := $(BUILDDIR)/Objs/Exceptions export BYTEWIDE := $(SOURCEDIR)/ByteWide -export DEFMOD := $(BINDIR)/defmod +export DEFMOD := $(BINDIR)/defmod -asmtype gccelf export REDUCEAOF := $(BINDIR)/reduceaof export BINDHELP := $(BINDIR)/bindhelp Modified: branches/simplified-build/!OsLib/Tools/DefMod2/Makefile =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/Makefile 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Tools/DefMod2/Makefile 2007-04-28 13:28:42 UTC (rev 254) @@ -1,11 +1,6 @@ # Targets: all install clean # Using: CC CFLAGS LD LDFLAGS YACC YFLAGS RM INSTALL INSTALL_PROGRAM bindir -# Which assembler DefMod should use (set this using CFLAGS): -# USE_GCC for GCCSDK -# USE_ARMASM for PACE/solaris -# USE_OBJASM for RISC OS native build using Norcroft - .PHONY: all install clean OBJS = \ asmhelp.o \ @@ -20,7 +15,7 @@ # In case they are not defined, use default values. CC ?= /usr/bin/gcc -CFLAGS ?= -g -DUSE_GCC -DUNIX -DEXECUTE_ON_UNIX -D__swi +CFLAGS ?= -g -DUNIX -DEXECUTE_ON_UNIX -D__swi LD ?= /usr/bin/gcc LDFLAGS ?= YACC ?= bison Modified: branches/simplified-build/!OsLib/Tools/DefMod2/cheader.c =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/cheader.c 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Tools/DefMod2/cheader.c 2007-04-28 13:28:42 UTC (rev 254) @@ -72,7 +72,7 @@ break; } - return SKIP; + return NULL; } /*-----------------------------------------------------------------------*/ Modified: branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Tools/DefMod2/defmod.y 2007-04-28 13:28:42 UTC (rev 254) @@ -68,7 +68,7 @@ #endif /* Set this to 1 to make APCS 3/32 the default */ -#define DEFAULT_TO_APCS_32 0 +#define DEFAULT_TO_APCS_32 1 #if DEFAULT_TO_APCS_32 # define HELP_STRING_26 "" # define HELP_STRING_32 " [default]" @@ -1028,7 +1028,7 @@ if (!p) { yyerror ("not enough memory for |qalloc()|"); - exit (1); + exit (EXIT_FAILURE); } //tracef( "qalloc returns 0x%x\n" _ p ); @@ -1122,8 +1122,7 @@ yydebug = 0; - i = 1; - while (i < argc && argv [i] [0] == '-') + for (i = 1; i < argc && argv [i] [0] == '-'; ++i) { if (strcmp (argv [i], "-s") == 0) option = Objasm; else if (strcmp (argv [i], "-l") == 0) @@ -1149,8 +1148,7 @@ else if (strcmp (argv [i], "-o") == 0) output = argv [++i]; else if (strcmp (argv [i], "-help") == 0) - { const char* helptext = "DefMod " VERSION_INFO - ". Copyright � Jonathan Coxhead, 1994.\r" + { const char* helptext = "DefMod" VERSION_INFO ". Copyright � Jonathan Coxhead, 1994.\r" "DefMod comes with ABSOLUTELY NO WARRANTY.\r" "This is free software, and you are welcome to redistribute it " "under certain conditions. See the file Copying for details.\r" @@ -1158,20 +1156,26 @@ "[-o <output-dir> | > <output-file>] " "[-byte_wide <byte-wide-file>] " "[-26bit | -32bit] " + "[-asmtype [objasm | gccaof | armasm | gccelf ]] " "< <module-interface-file>\r" "Purpose: generate output from a module interface file\r" "-v\t\t" "verbose\r" "-q\t\t" "quiet\r" "-o\t\t" "is required when generating a " "directory\r" - "<output-dir>\t" "directory to create\r" + "\t<output-dir>\t" "directory to create\r" "-byte_wide\t" "is required with -s or -l for a " "module interface using byte-wide " "types defined elsewhere\r" - "<byte-wide-file>\t" "file containing whitespace-separated " + "\t<byte-wide-file>\t" "file containing whitespace-separated " "names of byte-wide types\r" "-26bit\t\t" "generate 26 bit code" HELP_STRING_26 "\r" "-32bit\t\t" "generate 32 bit code" HELP_STRING_32 "\r" + "-asmtype\t" "selects the assembler to use\r" + "\tobjasm\t" "...use ObjAsm (on RISC OS only)\r" + "\tgccaof\t" "...use GCC AOF toolkit (GCCSDK 3.4 only)\r" + "\tarmasm\t" "...use ARM ASM\r" + "\tgccelf\t" "...use GCC ELF toolkit (GCCSDK 4 only)\r" "<type> is one of:\r" "\t-asmhelp\t" "SrcEdit assembler help file\r" @@ -1180,13 +1184,13 @@ "\t-chelp\t\t" "SrcEdit C help file\r" "\t-cstrong\t" "StrongHelp C help directory\r" "\t-h\t\t" "C header file\r" - "\t-hdr\t\t" "ObjAsm header file\r" + "\t-hdr\t\t" "assembler header file (ObjAsm or GAS)\r" "\t-h++\t\t" "C++ header file (experimental)\r" "\t-l\t\t" "Directory for running LibFile -c " "-via ViaFile\r" "\t-p\t\t" "Pascal header file (not " "implemented)\r" - "\t-s\t\t" "ObjAsm source file\r"; + "\t-s\t\t" "assembler source file (ObjAsm or GAS)\r"; if ((error = xos_pretty_print (helptext, NULL, NULL)) != NULL) goto finish; @@ -1203,7 +1207,12 @@ #endif enum {Copying, Skipping} state = Skipping; - i++; + if (++i == argc) + { + fprintf (stderr, "Missing option value for -byte_wide\n"); + Parse_Error = TRUE; + goto finish; + } // tracef( "Main opening file: %s\n" _ argv[i] ); @@ -1289,13 +1298,36 @@ { mode = APCS32; } - - i++; + else if (strcmp (argv [i], "-asmtype") == 0) + { + ++i; + if (strcmp (argv [i], "objasm") == 0) + AsmType = AsmType_eObjAsm; + else if (strcmp (argv[i], "gccaof") == 0) + AsmType = AsmType_eGCCAOF; + else if (strcmp (argv[i], "armasm") == 0) + AsmType = AsmType_eARMASM; + else if (strcmp (argv[i], "gccelf") == 0) + AsmType = AsmType_eGCCELF; + else + { + fprintf (stderr, "Unknown option value %s for -asmtype\n", argv[i]); + Parse_Error = TRUE; + goto finish; + } + } + else + { + fprintf (stderr, "Unknown option %s\n", argv[i]); + Parse_Error = TRUE; + goto finish; + } } if (option == None) { tracef( "Parse error: No option\n" ); + fprintf (stderr, "Nothing to do\n"); Parse_Error = TRUE; goto finish; } @@ -1311,9 +1343,9 @@ switch (option) { case Objasm: tracef( "Objasm\n" ); - if ((error = objasm_output (stdout, Title, Author, needses, - needsatends, consts, types, swis, /*separate?*/ FALSE, - mode == APCS32, SKIP)) != NULL) + if ((error = objasm_output (stdout, Title, Author, + types, swis, /*separate?*/ FALSE, + mode == APCS32, NULL)) != NULL) goto finish; break; @@ -1348,10 +1380,9 @@ case Library: tracef( "Library\n" ); if (output != NULL) - if ((error = objasm_output (SKIP, Title, Author, needses, - needsatends, consts, types, swis, /*separate?*/ TRUE, - mode == APCS32, output)) != - NULL) + if ((error = objasm_output (NULL, Title, Author, types, + swis, /*separate?*/ TRUE, + mode == APCS32, output)) != NULL) goto finish; break; @@ -1378,10 +1409,10 @@ finish: trace_terminate (); if (error == NULL) - exit (Parse_Error? 1: 0); + exit (Parse_Error ? EXIT_FAILURE : EXIT_SUCCESS); else { fprintf (stderr, "%s\n", error->errmess); - exit (1); + exit (EXIT_FAILURE); } } Modified: branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Tools/DefMod2/hdr.c 2007-04-28 13:28:42 UTC (rev 254) @@ -1,9 +1,8 @@ -/* Index: OSLib/!OsLib/Tools/DefMod2/defmod/sources/hdr.c 20031228 */ /*hdr.c - output an assembler header file given a module defn*/ /*OSLib---efficient, type-safe, transparent, extensible,\n" register-safe A P I coverage of RISC O S*/ -/*Copyright \xA9 1994 Jonathan Coxhead*/ +/*Copyright � 1994 Jonathan Coxhead*/ /* OSLib is free software; you can redistribute it and/or modify Modified: branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Tools/DefMod2/objasm.c 2007-04-28 13:28:42 UTC (rev 254) @@ -20,24 +20,6 @@ Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139, U S A. */ -#undef ASSEMBLER - -#define OBJASM 1 -#define GCC 2 -#define ARMASM 3 - -#if (defined USE_OBJASM) && !(defined USE_GCC) && !(defined USE_ARMASM) - #define ASSEMBLER OBJASM -#elif !(defined USE_OBJASM) && (defined USE_GCC) && !(defined USE_ARMASM) - #define ASSEMBLER GCC -#elif !(defined USE_OBJASM) && !(defined USE_GCC) && (defined USE_ARMASM) - #define ASSEMBLER ARMASM -#endif - -#ifndef ASSEMBLER - #error Target Assembler Undefined -#endif - #undef TRACE #define TRACE 0 @@ -63,12 +45,10 @@ #include "main.h" #include "objasm.h" -#define MEM_FOR_OBJASM (1024*1024) +AsmType_e AsmType = AsmType_eUnknown; +static const char *Local; -static char *Local; - -static char - *APCS_Names [] = +static const char * const APCS_Names [] = /*names of registers as seen by A P C S*/ { /*arguments*/ "A1", "A2", "A3", "A4", @@ -78,9 +58,9 @@ /*fixed purpose*/ "SL", "FP", "IP", "SP", "LR", "PC" - }, + }; - *SWI_Names [] = +static const char * const SWI_Names [] = /*names of registers as seen by SWI call*/ { /*general*/ "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", @@ -114,7 +94,7 @@ break; } - return SKIP; + return NULL; } /*-----------------------------------------------------------------------*/ static int Set_Count @@ -185,18 +165,19 @@ static int Emit_Header ( FILE *file, - char *title, - char *author + const char *title, + const char *author ) { time_t now; + time (&now); return fprintf ( file, ";ObjAsm file for %s\n" - ";written by DefMod (%s) on %s" + ";written by DefMod (" __DATE__ ") on %s" ";%s\n" "\n" "R0 RN 0\n" @@ -231,8 +212,7 @@ "PC RN 15\n" "\n", title, - __DATE__, - (time (&now), ctime (&now)), + ctime (&now), author ); } @@ -241,7 +221,7 @@ static int Emit0 ( FILE *file, - char *s0 + const char *s0 ) { int rc = 0; @@ -255,8 +235,8 @@ static int Emit1 ( FILE *file, - char *s0, - char *s1 + const char *s0, + const char *s1 ) { int rc = 0; @@ -271,9 +251,9 @@ static int Emit2 ( FILE *file, - char *s0, - char *s1, - char *s2 + const char *s0, + const char *s1, + const char *s2 ) { int rc = 0; @@ -288,10 +268,10 @@ static int Emit3 ( FILE *file, - char *s0, - char *s1, - char *s2, - char *s3 + const char *s0, + const char *s1, + const char *s2, + const char *s3 ) { int rc = 0; @@ -306,7 +286,7 @@ static int Emit_Label ( FILE *file, - char *s0 + const char *s0 ) { return fprintf (file, "%s ROUT\n", s0); @@ -316,7 +296,7 @@ static int Emit_Local ( FILE *file, - char *s0 + const char *s0 ) { file = file; @@ -338,7 +318,7 @@ static int Emit_Comment ( FILE *file, - char *comment + const char *comment ) { return fprintf (file, ";%s\n", comment); @@ -353,19 +333,20 @@ ) { char *cc = s0; - int n, rc = 0; + int n; for (n = 0; n < 16; n++) if (Set_Elem (n, set)) { - if ((rc = sprintf (cc, cc == s0? "{%s": ", %s", APCS_Names [n])) - < 0) + int rc; + + if ((rc = sprintf (cc, (cc == s0) ? "{%s" : ", %s", APCS_Names [n])) < 0) return rc; - cc += strlen (cc); + cc += rc; } - return sprintf (cc, cc == s0? "{}%s": "}%s", hat? "^": ""); + return sprintf (cc, (cc == s0) ? "{}%s" : "}%s", hat ? "^" : ""); } /*-----------------------------------------------------------------------*/ @@ -377,26 +358,27 @@ ) { char *cc = s0; - int n, rc = 0; + int n; for (n = 0; n < 16; n++) if (Set_Elem (n, set)) { - if ((rc = sprintf (cc, cc == s0? "{%s": ", %s", SWI_Names [n])) - < 0) + int rc; + + if ((rc = sprintf (cc, (cc == s0) ? "{%s" : ", %s", SWI_Names [n])) < 0) return rc; - cc += strlen (cc); + cc += rc; } - return sprintf (cc, cc == s0? "{}%s": "}%s", hat? "^": ""); + return sprintf (cc, (cc == s0) ? "{}%s" : "}%s", hat ? "^" : ""); } /*-----------------------------------------------------------------------*/ static int Emit_Code ( FILE *file, - char *swi, + const char *swi, def_s s, osbool nonx, osbool apcs32, @@ -899,11 +881,8 @@ os_error *objasm_output ( FILE *file, - char *title, - char *author, - lookup_t needs, - lookup_t needsatends, - lookup_t consts, + const char *title, + const char *author, lookup_t types, lookup_t swis, osbool separate, /*if |separate|, output is to the directory |output|; otherwise, @@ -920,8 +899,12 @@ osbool done_fopen_via_file = FALSE, done_fopen_object = FALSE; FILE *via_file = NULL, *object = NULL /*for Norcroft*/; - needs = needs, consts = consts, types = types; - NOT_USED (needsatends) + /* Make sure the assembler type has been set. */ + if (AsmType == AsmType_eUnknown) + { + fprintf (stderr, "Assembler type has not been set (-asmtype option)\n"); + goto finish; + } if (!separate) { @@ -945,9 +928,9 @@ /*Export the symbol with a preceding 'x.'*/ def_as_extern (c_name + 1, swi); c_name [0] = 'x'; - #if 0 +#if 0 def_as_c_plus_plus (c_plus_plus_name + 1, swi, s); - #endif +#endif c_plus_plus_name [0] = 'x'; if ((rc = Emit1 (file, "EXPORT", c_name)) < 0) @@ -1007,19 +990,6 @@ if ((error = xosfile_create_dir (output, 0)) != NULL) goto finish; -#if 0 - /*Get the prefix - needed because we'll be starting a subtask.*/ - if ((error = xos_read_var_val ("Prefix$Dir", prefix_dir, - FILENAME_MAX, context1, os_VARTYPE_EXPANDED, &len, &context1, - &var_type)) != NULL) - goto finish; - - if (len == 0) - strcpy (prefix_dir, "@"); - else - prefix_dir [len] = '\0'; -#endif - //#ifndef EXECUTE_ON_UNIX if ((via_file = fopen ("ViaFile", "w+")) == NULL) { @@ -1125,35 +1095,46 @@ } done_fopen_object = FALSE; -#if ASSEMBLER == GCC - /* The gcc '-mapcs-32' or '-mapcs-26' option is a requirement - for GCCSDK 3.4.6 Release 1 onwards if you want to control - the APCS flavour in the assembler backend. - The pass-through '-apcs26'/'-apcs32' is only necessary for - pre-GCCSDK 3.4.6 Release 1 releases, so for backwards - compatibility only as the gcc '-mapcs-32'/'-mapcs-26' - option will always be passed through the as assembler - as '-apcs26'/'-apcs32' from that release onwards. */ - if ((rc = sprintf( cmd, + switch (AsmType) + { + case AsmType_eObjAsm: + if ((rc = sprintf (cmd, "ObjAsm -from %s -to %s -apcs 3/%dbit/SWstackcheck", + name1, name2, apcs32 ? 32 : 26)) < 0) + goto finish; + break; + case AsmType_eGCCAOF: + /* The gcc '-mapcs-32' or '-mapcs-26' option is a requirement + for GCCSDK 3.4.6 Release 1 onwards if you want to control + the APCS flavour in the assembler backend. + The pass-through '-apcs26'/'-apcs32' is only necessary for + pre-GCCSDK 3.4.6 Release 1 releases, so for backwards + compatibility only as the gcc '-mapcs-32'/'-mapcs-26' + option will always be passed through the as assembler + as '-apcs26'/'-apcs32' from that release onwards. */ + if ((rc = sprintf (cmd, "gcc %s -c -xassembler -Wa,-objasm%s -o %s %s", apcs32 ? "-mapcs-32" : "-mapcs-26", apcs32 ? ",-apcs32" : ",-apcs26", name2, name1)) < 0) - goto finish; + goto finish; + break; + case AsmType_eARMASM: + if ((rc = sprintf (cmd, "armasm -from %s -to %s -apcs 3/%dbit/SWstackcheck", + name1, name2, apcs32 ? 32 : 26)) < 0) + goto finish; + break; + case AsmType_eGCCELF: + if ((rc = sprintf (cmd, + "arm-unknown-riscos-gcc -c -xassembler -Wa,%s -o %s %s", + apcs32 ? "-mapcs-32" : "-mapcs-26", + name2, name1)) < 0) + goto finish; + break; + default: + fprintf (stderr, "Unknown assembler type\n"); + goto finish; + } -#elif ASSEMBLER == OBJASM - if ((rc = sprintf (cmd, "ObjAsm -from %s -to %s " - "-apcs 3/%dbit/SWstackcheck", - name1, name2, apcs32 ? 32 : 26)) < 0) - goto finish; - -#elif ASSEMBLER == ARMASM - if ((rc = sprintf (cmd, "armasm -from %s -to %s " - "-apcs 3/%dbit/SWstackcheck", - name1, name2, apcs32 ? 32 : 26)) < 0) - goto finish; -#endif - tracef ("%s ...\n" _ cmd); if (!Quiet) if ((rc = printf ("%s\n", cmd)) < 0) Modified: branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h =================================================================== --- branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h 2007-04-26 20:11:09 UTC (rev 253) +++ branches/simplified-build/!OsLib/Tools/DefMod2/objasm.h 2007-04-28 13:28:42 UTC (rev 254) @@ -13,7 +13,17 @@ #include "lookup.h" #endif -extern os_error *objasm_output (FILE *, char *, char *, lookup_t, lookup_t, - lookup_t, lookup_t, lookup_t, osbool, osbool, char *output); +typedef enum { + AsmType_eUnknown, + AsmType_eObjAsm, + AsmType_eGCCAOF, + AsmType_eARMASM, + AsmType_eGCCELF + } AsmType_e; +extern AsmType_e AsmType; + +/*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); + #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |