]> Shamusworld >> Repos - rmac/blobdiff - rmac.c
Various code cleanups, mainly to do with RISC assembly.
[rmac] / rmac.c
diff --git a/rmac.c b/rmac.c
index 3cc24f4e3ee74dc80416735311ede284c72cb74d..6dd9475d7db3b7a7aa848820977d45f2e78bdf75 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -15,7 +15,7 @@
 #include "sect.h"
 #include "mark.h"
 #include "macro.h"
-#include "risca.h"
+#include "riscasm.h"
 #include "direct.h"
 #include "version.h"
 #include "debug.h"
@@ -37,7 +37,6 @@ int rgpu, rdsp;                                               // Assembling Jaguar GPU or DSP code
 int list_fd;                                           // File to write listing to
 int regbank;                                           // RISC register bank
 int segpadsize;                                                // Segment padding size
-int in_main;                                           // In main memory flag for GPUMAIN
 int endian;                                                    // Host processor endianess
 char * objfname;                                       // Object filename pointer
 char * firstfname;                                     // First source filename
@@ -66,7 +65,8 @@ static int qsz;                                             // Size of each reco
 static int thresh;                                          // THRESHold in chars 
 static int mthresh;                                         // MTHRESHold in chars
 
-
+// This is unused BOLLOCKS
+#if 0
 //
 // qst: Do a quicksort. First, find the median element, and put that one in the
 // first place as the discriminator. (This "median" is just the median of the
@@ -299,8 +299,9 @@ int rmac_qsort(char * base, int n, int size, int (*compar)())
 
        return 0;
 }
+#endif
 
-
+#if 0
 //
 // Allocate memory; Panic and Quit if we Run Out
 //
@@ -308,14 +309,16 @@ char * amem(LONG amount)
 {
        char * p;
 
-       if (amount & 1)                                           // Keep word alignment
-               ++amount;
+//     if (amount & 1)                                                         // Keep word alignment
+//             amount++;
+       amount = (amount + 1) & ~(0x01);                        // Keep word alignment
 
+       // Honor *small* request (< 64 bytes)
        if (amount < A_THRESH)
-       {                                  // Honor *small* request
+       {
                if (a_amount < amount)
                {
-                       a_ptr = amem(A_AMOUNT);
+                       a_ptr = amem(A_AMOUNT);                         // Allocate 4K bytes
                        a_amount = A_AMOUNT;
                }
 
@@ -325,17 +328,18 @@ char * amem(LONG amount)
        }
        else
        {
-               amemtot += amount;                                    // Bump total alloc
-               p = (char *)malloc(amount);                           // Get memory from malloc
+               amemtot += amount;                                              // Bump total alloc
+               p = (char *)malloc(amount);                             // Get memory from malloc
 
-               if ((LONG)p == (LONG)NULL)
-                       fatal("memory exhausted");
+               if (p == NULL)
+                       fatal("Memory exhausted!");
 
                memset(p, 0, amount);
        }
 
        return p;
 }
+#endif
 
 
 //
@@ -558,20 +562,19 @@ int process(int argc, char ** argv)
        orgwarning = 0;                                 // No ORG warning issued
        a_amount = 0;
        segpadsize = 2;                                 // Initialise segment padding size
-       in_main = 0;
 
        // Initialise modules
-       init_sym();                                             // Symbol table
+       InitSymbolTable();                              // Symbol table
        init_token();                                   // Tokenizer
        init_procln();                                  // Line processor
        init_expr();                                    // Expression analyzer
        init_sect();                                    // Section manager / code generator
        init_mark();                                    // Mark tape-recorder
-       init_macro();                                   // Macro processor
+       InitMacro();                                    // Macro processor
        init_list();                                    // Listing generator
 
        // Process command line arguments and assemble source files
-       for(argno = 0; argno < argc; ++argno)
+       for(argno=0; argno<argc; ++argno)
        {
                if (*argv[argno] == '-')
                {
@@ -599,7 +602,7 @@ int process(int argc, char ** argv)
 
                                if (sy == NULL)
                                {
-                                       sy = newsym(argv[argno] + 2, LABEL, 0);
+                                       sy = NewSymbol(argv[argno] + 2, LABEL, 0);
                                        sy->svalue = 0;
                                }
 
@@ -626,7 +629,7 @@ int process(int argc, char ** argv)
                                        break;
                                default:
                                        printf("-f: unknown object format specified\n");
-                                       ++errcnt;
+                                       errcnt++;
                                        return errcnt;
                                }
                                break;
@@ -643,7 +646,7 @@ int process(int argc, char ** argv)
                                list_fname = argv[argno] + 2;
                                listing = 1;
                                list_flag = 1;
-                               ++lnsave;
+                               lnsave++;
                                break;
                        case 'o':                                       // Direct object file output
                        case 'O':
@@ -654,7 +657,7 @@ int process(int argc, char ** argv)
                                        if (++argno >= argc)
                                        {
                                                printf("Missing argument to -o");
-                                               ++errcnt;
+                                               errcnt++;
                                                return errcnt;
                                        }
                                        objfname = argv[argno];
@@ -711,20 +714,20 @@ int process(int argc, char ** argv)
                                        firstfname = defname;
 
                                include(0, "(stdin)");
-                               assemble();
+                               Assemble();
                                break;
                        case 'h':                                       // Display command line usage
                        case 'H':
                        case '?':
                                display_version();
                                display_help();
-                               ++errcnt;
+                               errcnt++;
                                break;
                        default:
                                display_version();
                                printf("Unknown switch: %s\n\n", argv[argno]);
                                display_help();
-                               ++errcnt;
+                               errcnt++;
                                break;
                        }
                }
@@ -741,12 +744,12 @@ int process(int argc, char ** argv)
                        if (fd < 0)
                        {
                                printf("Cannot open: %s\n", fnbuf);
-                               ++errcnt;
+                               errcnt++;
                                continue;
                        }
 
                        include(fd, fnbuf);
-                       assemble();
+                       Assemble();
                }
        }
 
@@ -791,8 +794,8 @@ int process(int argc, char ** argv)
        //       (`lo68' format, extended (postfix) format....)
        // (2)   generate the output file image and symbol table;
        // (3)   generate relocation information from left-over fixups.
-       fixups();                                                // Do all fixups
-       stopmark();                                              // Stop mark tape-recorder
+       ResolveAllFixups();                                             // Do all fixups
+       stopmark();                                                             // Stop mark tape-recorder
 
        if (errcnt == 0)
        {
@@ -851,27 +854,19 @@ int get_endianess(void)
 //
 int main(int argc, char ** argv)
 {
-       int status;
-       int i;
-
        perm_verb_flag = 0;                             // Clobber "permanent" verbose flag
        cmdlnexec = argv[0];                    // Obtain executable name
 
        endian = get_endianess();               // Get processor endianess
 
-       for(i=0; i<MAXFWDJUMPS; i++)
-               fwdjump[i] = 0;
-
-       // Full command line passed
+       // If commands were passed in, process them
        if (argc > 1)
        {
-               status = process(argc - 1, argv + 1);              
-       }
-       else
-       {
-               display_version();
-               display_help();
+               return process(argc - 1, argv + 1);              
        }
 
-       return status;
+       display_version();
+       display_help();
+
+       return 0;
 }