Version bump for last eight commits; cleanup of Alcyon image writing.
authorShamus Hammons <jlhamm@acm.org>
Wed, 24 Jan 2018 04:20:24 +0000 (22:20 -0600)
committerShamus Hammons <jlhamm@acm.org>
Wed, 24 Jan 2018 04:20:24 +0000 (22:20 -0600)
Now at version 1.11.9.

amode.c
mach.c
object.c
parmode.h
version.h

diff --git a/amode.c b/amode.c
index 175fe73fdaf79cd27012da9d48445bc58c2e4bef..f56fe9c1f16c250f34c94b6e20f49c667db40e2d 100644 (file)
--- a/amode.c
+++ b/amode.c
@@ -72,7 +72,7 @@ WORD bf0exattr;                               // Expression's attribute
 SYM * bf0esym;                         // External symbol involved in expr
 
 // Function prototypes
-int check030bf(void);
+int Check030Bitfield(void);
 
 
 //
@@ -132,7 +132,7 @@ int amode(int acount)
        // it's a bitfield instruction--check the parameters inside the {} block
        // for validity
        if (*tok == '{')
-               if (check030bf() == ERROR)
+               if (Check030Bitfield() == ERROR)
                        return ERROR;
 
        if ((acount == 0) || (*tok != ','))
@@ -170,7 +170,7 @@ int amode(int acount)
        // It's a bitfield instruction--check the parameters inside the {} block
        // for validity
        if (*tok == '{')
-        if (check030bf() == ERROR)
+        if (Check030Bitfield() == ERROR)
                return ERROR;
 
        // At this point, it is legal for 020+ to have a ':'. For example divu.l
@@ -184,13 +184,9 @@ int amode(int acount)
                tok++;  //eat the colon
 
                if ((*tok >= KW_D0) && (*tok <= KW_D7))
-               {
                        a2reg = (*tok++) & 7;
-               }
                else if ((*tok >= KW_FP0) && (*tok <= KW_FP7))
-               {
                        a2reg = (*tok++) & 7;
-               }
                else
                        return error("a data or FPU register must follow a :");
        }
@@ -207,9 +203,6 @@ int amode(int acount)
        // Error messages:
 badmode:
        return error("addressing mode syntax");
-
-       //unmode:
-       //return error("unimplemented addressing mode");
 }
 
 
@@ -376,7 +369,7 @@ int fpu_reglist_right(WORD * a_rmask)
 // bfxxx <ea>{param1,param2}
 // param1/2 are either data registers or immediate values
 //
-int check030bf(void)
+int Check030Bitfield(void)
 {
        PTR tp;
        CHECK00;
diff --git a/mach.c b/mach.c
index 64061dc4cef46cf97d152b777f97bbdb1207b450..7c1ab8ea6ae7e1d750f1233ec36875c97721cadb 100644 (file)
--- a/mach.c
+++ b/mach.c
@@ -1186,10 +1186,14 @@ int m_bfop(WORD inst, WORD siz)
 
        //D_word((inst | am0 | a0reg | am1 | a1reg));
        if (inst == B16(11101111, 11000000))
+       {
                // bfins special case
                D_word((inst | am1 | a1reg));
+       }
        else
+       {
                D_word((inst | am0 | a0reg));
+       }
 
        ea0gen(siz);    // Generate EA
 
@@ -1656,7 +1660,7 @@ int m_muls(WORD inst, WORD siz)
 
        if (flg & 16)
        {
-               // OR-in register number 
+               // OR-in register number
                if (flg & 8)
                        inst |= reg_9[a1reg];           // ea1reg in bits 9..11
                else
@@ -1685,7 +1689,7 @@ int m_muls(WORD inst, WORD siz)
 
                 D_word(inst);
 
-               // Generate ea0 if requested 
+               // Generate ea0 if requested
                if (flg & 2)
                        ea0gen(siz);
 
@@ -2908,7 +2912,7 @@ int m_fintrz(WORD inst, WORD siz)
 
        if (activefpu == FPU_68040)
                warn("Instruction is emulated in 68040");
-       
+
        return gen_fpu(inst, siz, B8(00000011), FPU_NOWARN);
 }
 
@@ -3415,7 +3419,7 @@ int m_fsmul(WORD inst, WORD siz)
 {
        if (activefpu & (FPU_68040 | FPU_68060))
                return gen_fpu(inst, siz, B8(01100011), FPU_NOWARN);
-       
+
        return error("Unsupported in current FPU");
 }
 
@@ -3444,7 +3448,7 @@ int m_fneg(WORD inst, WORD siz)
                a1reg = a0reg;
                return gen_fpu(inst, siz, B8(00011010), FPU_NOWARN);
        }
-       
+
        return gen_fpu(inst, siz, B8(00011010), FPU_NOWARN);
 }
 
@@ -3461,7 +3465,7 @@ int m_fsneg(WORD inst, WORD siz)
                        a1reg = a0reg;
                        return gen_fpu(inst, siz, B8(01011010), FPU_NOWARN);
                }
-               
+
                return gen_fpu(inst, siz, B8(01011010), FPU_NOWARN);
        }
 
@@ -3623,7 +3627,7 @@ int m_fsfsqrt(WORD inst, WORD siz)
 {
        if (activefpu & (FPU_68040 | FPU_68060))
                return gen_fpu(inst, siz, B8(01000001), FPU_NOWARN);
-       
+
        return error("Unsupported in current FPU");
 }
 
@@ -3780,8 +3784,10 @@ int m_lpstop(WORD inst, WORD siz)
        CHECKNO60;
        D_word(B16(00000001, 11000000));
 
-       if (a0exattr&DEFINED)
+       if (a0exattr & DEFINED)
+       {
                D_word(a0exval);
+       }
        else
        {
                AddFixup(FU_WORD, sloc, a0expr);
index 205c0a0ebd3b1387896b6da68ad34c09a92fa287..a1847967f879e48648c01787a9ca06298e7af1c8 100644 (file)
--- a/object.c
+++ b/object.c
@@ -100,7 +100,6 @@ uint8_t * AddSymEntry(register uint8_t * buf, SYM * sym, int globflag)
                }
        }
 
-
        //
        // Construct and deposit flag word
        //
@@ -422,49 +421,37 @@ int WriteObject(int fd)
        }
        else if (obj_format == ALCYON)
        {
-               uint32_t symbolmaxsize = 0;
-
                if (verb_flag)
                {
                        if (prg_flag)
-                       {
                                printf("TOS header  : 28 bytes\n");
-                               printf("Total       : %d bytes\n", 28 + sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc);
-                       }
-                       else
-                       {
-                               printf("Total       : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc);
-                       }
+
+                       printf("Total       : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc + (prg_flag ? 28 : 0));
                }
 
-               if (prg_flag != 1)
-                       symbolmaxsize = sy_assign(NULL, NULL) * 28;             // Assign index numbers to the symbols
+               // Assign index numbers to the symbols, get # of symbols (we assume
+               // that all symbols can potentially be extended, hence the x28)
+               uint32_t symbolMaxSize = sy_assign(NULL, NULL) * 28;
 
                // Alloc memory for header + text + data, symbol and relocation
                // information construction.
-               t = tds = sect[TEXT].sloc + sect[DATA].sloc;
-
-               if (t < symbolmaxsize)
-                       t = symbolmaxsize;
-
-               // Is there any reason to do this this way???
-               buf = malloc(t + HDRSIZE);
-               buf += HDRSIZE;
+               tds = sect[TEXT].sloc + sect[DATA].sloc;
+               buf = malloc(HDRSIZE + tds + symbolMaxSize);
 
                // Build object file header just before the text+data image
-               chptr = buf - HDRSIZE;          // -> base of header
+               chptr = buf;                            // -> base of header
                D_word(0x601A);                         // 00 - magic number
                D_long(sect[TEXT].sloc);        // 02 - TEXT size
                D_long(sect[DATA].sloc);        // 06 - DATA size
                D_long(sect[BSS].sloc);         // 0A - BSS size
-               D_long(0);                                      // 0E - symbol table size (will be filled later if non zero)
+               D_long(0);                                      // 0E - symbol table size (filled later)
                D_long(0);                                      // 12 - stack size (unused)
                D_long(PRGFLAGS);                       // 16 - PRGFLAGS
                D_word(0);                                      // 1A - relocation information exists
 
                // Construct text and data segments; fixup relocatable longs in .PRG
                // mode; finally write the header + text + data
-               p = buf;
+               p = buf + HDRSIZE;
 
                for(i=TEXT; i<=DATA; i++)
                {
@@ -477,28 +464,24 @@ int WriteObject(int fd)
 
                // Do a first pass on the Alcyon image, if in PRG mode
                if (prg_flag)
-                       MarkImage(buf, tds, sect[TEXT].sloc, 0);
-
-               unused = write(fd, buf - HDRSIZE, tds + HDRSIZE);
+                       MarkImage(buf + HDRSIZE, tds, sect[TEXT].sloc, 0);
 
-               // Construct and write symbol table
-               if (prg_flag != 1)
+               // Construct symbol table and update the header entry, if necessary
+               if (prg_flag > 1)
                {
-                       sy_assign(buf, AddSymEntry);
-                       unused = write(fd, buf, symsize);
+                       // sy_assign with AddSymEntry updates symsize (stays 0 otherwise)
+                       sy_assign(buf + HDRSIZE + tds, AddSymEntry);
+                       chptr = buf + 0x0E;                     // Point to symbol table size entry
+                       D_long(symsize);
                }
 
+               // Write out the header + text & data + symbol table (if any)
+               unused = write(fd, buf, HDRSIZE + tds + symsize);
+
                // Construct and write relocation information; the size of it changes if
-               // we're writing a RELMODed executable.
+               // we're writing a RELMODed executable. N.B.: Destroys buffer!
                tds = MarkImage(buf, tds, sect[TEXT].sloc, 1);
                unused = write(fd, buf, tds);
-
-               // If we generated a symbol table we need to update the placeholder value
-               // we wrote above in the header
-               lseek(fd, 0xE, 0);
-               symsize = BYTESWAP32(symsize);
-               unused = write(fd, &symsize, 4);
-
        }
        else if (obj_format == ELF)
        {
index 0c5d66dd655f8005d0d360e6f09dae92a8055e63..e0de0376e29ee217f33a7941d3834db253a9d0cd 100644 (file)
--- a/parmode.h
+++ b/parmode.h
                        // Common index handler; enter here with 'tok' pointing at the
                        // comma.
 
-                       AMn_IX0:                 // Handle indexed with missing expr
+AMn_IX0:                 // Handle indexed with missing expr
 
                        AnEXVAL = 0;
                        AnEXATTR = ABS | DEFINED;
 
-                       AMn_IXN:                 // Handle any indexed (tok -> a comma)
+AMn_IXN:                 // Handle any indexed (tok -> a comma)
 
                        if (*tok++ != ',')
                                goto badmode;
                                {
                                        if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                return error("scale factor expression must evaluate");
+
                                        switch (scaleval)
                                        {
                                        case 1:
                        else
                        {
                                expr(AnBEXPR, &AnBEXVAL, &AnBEXATTR, &AnESYM);
+
                                if (CHECK_OPTS(OPT_BASE_DISP) && AnBEXVAL == 0 && AnEXATTR != 0)
                                {
                                        // bd=0 so let's optimise it out
                                        AnEXTEN|=EXT_BDSIZE0;
                                }
                                else if (*tok == DOTL)
-                               {                                               // ([bd.l,...
-                                               AnEXTEN |= EXT_BDSIZEL;
-                                               tok++;
+                               {
+                                       // ([bd.l,...
+                                       AnEXTEN |= EXT_BDSIZEL;
+                                       tok++;
                                }
                                else
-                               {                                               // ([bd[.w],... or ([bd,...
+                               {
+                                       // ([bd[.w],... or ([bd,...
                                        // Is .W forced here?
                                        if (*tok == DOTW)
                                        {
                                        }
                                        else
                                        {
-                                               // Defined, absolute values from $FFFF8000..$00007FFF get optimized
-                                               // to absolute short
+                                               // Defined, absolute values from $FFFF8000..$00007FFF
+                                               // get optimized to absolute short
                                                if (CHECK_OPTS(OPT_ABS_SHORT)
                                                        && ((AnBEXATTR & (TDB | DEFINED)) == DEFINED)
                                                        && (((uint32_t)AnBEXVAL + 0x8000) < 0x10000))
                                tok++;
 
                                // Check for size
+                               // ([bd,An/PC],Xn.W/L...)
+                               switch ((int)*tok)
                                {
-                                       // ([bd,An/PC],Xn.W/L...)
-                                       switch ((int)*tok)
-                               {
-                                       // Index reg size: <empty> | .W | .L
-                                       case DOTW:
-                                               tok++;
-                                               break;
-                                       default:
-                                               break;
-                                       case DOTL:
-                                               AnEXTEN |= EXT_L;
-                                               tok++;
-                                               break;
-                                       case DOTB:
-                                               // .B not allowed here...
-                                               goto badmode;
-                                       }
+                               // Index reg size: <empty> | .W | .L
+                               case DOTW:
+                                       tok++;
+                                       break;
+                               default:
+                                       break;
+                               case DOTL:
+                                       AnEXTEN |= EXT_L;
+                                       tok++;
+                                       break;
+                               case DOTB:
+                                       // .B not allowed here...
+                                       goto badmode;
                                }
 
                                // Check for scale
                                }
 
                                // Check for size
+                               // ([bd,An/PC],Xn.W/L...)
+                               switch ((int)*tok)
                                {
-                                       // ([bd,An/PC],Xn.W/L...)
-                                       switch ((int)*tok)
-                                       {
-                                       // Index reg size: <empty> | .W | .L
-                                       case DOTW:
-                                               tok++;
-                                               break;
-                                       default:
-                                               break;
-                                       case DOTL:
-                                               AnEXTEN |= EXT_L;
-                                               tok++;
-                                               break;
-                                       case DOTB:
-                                               // .B not allowed here...
-                                               goto badmode;
-                                       }
+                               // Index reg size: <empty> | .W | .L
+                               case DOTW:
+                                       tok++;
+                                       break;
+                               default:
+                                       break;
+                               case DOTL:
+                                       AnEXTEN |= EXT_L;
+                                       tok++;
+                                       break;
+                               case DOTB:
+                                       // .B not allowed here...
+                                       goto badmode;
                                }
 
                                // Check for scale
                                else
                                        tok++;  // eat the comma
 
-                               CHECKODn:
+CHECKODn:
                                if (expr(AnEXPR, &AnEXVAL, &AnEXATTR, &AnESYM) != OK)
                                        goto badmode;
 
 
                                        // Is .W forced here?
                                        if (*tok == DOTW)
-                                       {
                                                tok++;
-                                       }
                                }
 
                                // Check for final closing parenthesis
@@ -764,35 +762,34 @@ IS_SUPPRESSEDn:
                                }
 
                                // Check for size
+                               // ([bd,An/PC],Xn.W/L...)
+                               switch ((int)*tok)
                                {
-                                       // ([bd,An/PC],Xn.W/L...)
-                                       switch ((int)*tok)
-                                       {
-                                       // Index reg size: <empty> | .W | .L
-                                       case DOTW:
-                                               tok++;
-                                               break;
-                                       default:
-                                               break;
-                                       case DOTL:
-                                               tok++;
-                                               AnEXTEN |= EXT_L;
-                                               break;
-                                       case DOTB:
-                                       // .B not allowed here...
-                                       goto badmode;
-                                       }
+                               // Index reg size: <empty> | .W | .L
+                               case DOTW:
+                                       tok++;
+                                       break;
+                               default:
+                                       break;
+                               case DOTL:
+                                       tok++;
+                                       AnEXTEN |= EXT_L;
+                                       break;
+                               case DOTB:
+                               // .B not allowed here...
+                               goto badmode;
                                }
 
                                // Check for scale
                                if (*tok == '*')                                // ([bd,An/PC],Xn*...)
-                               {                                                               // scale: *1, *2, *4, *8 
+                               {                                                               // scale: *1, *2, *4, *8
                                        tok++;
 
                                        if (*tok == SYMBOL)
                                        {
                                                if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                        return error("scale factor expression must evaluate");
+
                                                switch (scaleval)
                                                {
                                                case 1:
@@ -950,22 +947,25 @@ IS_SUPPRESSEDn:
 
                                if (*tok == ',')
                                {
-                                       // Check if we're actually doing d8(An,Dn) or (d16,An,Dn[.size][*scale])
-                                       // TODO: not a very clear cut case from what I can think. The only way
-                                       // to distinguish between the two is to check AnEXVAL and see if it's
-                                       // >127 or <-128. But this doesn't work if AnEXVAL isn't defined yet.
-                                       // For now we fall through to d8(An,Dn) but this might bite us in the
-                                       // arse during fixups...
+                                       // Check if we're actually doing d8(An,Dn) or
+                                       // (d16,An,Dn[.size][*scale])
+                                       // TODO: not a very clear cut case from what I can think.
+                                       // The only way to distinguish between the two is to check
+                                       // AnEXVAL and see if it's >127 or <-128. But this doesn't
+                                       // work if AnEXVAL isn't defined yet. For now we fall
+                                       // through to d8(An,Dn) but this might bite us in the arse
+                                       // during fixups...
                                        if ((AnEXATTR & DEFINED) && (AnEXVAL + 0x80 > 0x100))
                                        {
-                                               // We're going to treat it as a full extension format with no
-                                               // indirect access and no base displacement/index register suppression
+                                               // We're going to treat it as a full extension format
+                                               // with no indirect access and no base displacement/
+                                               // index register suppression
                                                AnEXTEN |= EXT_FULLWORD;        // Definitely using full extension format, so set bit 8
                                                AnEXTEN |= EXT_IISPRE0;         // No Memory Indirect Action
                                                AnEXTEN |= EXT_BDSIZEL;         // Base Displacement Size Long
                                                tok++;                                          // Get past the comma
 
-                                               // Our expression is techically a base displacement
+                                               // Our expression is techically a base displacement,
                                                // so let's copy it to the relevant variables so
                                                // eagen0.c can pick it up properly
                                                //AnBEXPR = AnEXPR;
@@ -996,13 +996,14 @@ IS_SUPPRESSEDn:
                                                        }
                                                        // Check for scale
                                                        if (*tok == '*')                // ([bd,An/PC],Xn*...)
-                                                       {                                               // scale: *1, *2, *4, *8 
+                                                       {                                               // scale: *1, *2, *4, *8
                                                                tok++;
 
                                                                if (*tok == SYMBOL)
                                                                {
                                                                        if (expr(scaleexpr, &scaleval, &scaleattr, &scaleesym) != OK)
                                                                                return error("scale factor expression must evaluate");
+
                                                                        switch (scaleval)
                                                                        {
                                                                        case 1:
@@ -1055,7 +1056,7 @@ IS_SUPPRESSEDn:
                                                else
                                                        goto badmode;
                                        }
-                                               
+
                                        AMn = AINDEXED;
                                        goto AMn_IXN;
                                }
index 8cb43f45f2d3a9f970856954b94dfee1f0152852..62dbfcb902b40abc86d1241611d4d2106e333e25 100644 (file)
--- a/version.h
+++ b/version.h
@@ -15,7 +15,7 @@
 
 #define MAJOR   1              // Major version number
 #define MINOR   11             // Minor version number
-#define PATCH   0              // Patch release number
+#define PATCH   9              // Patch release number
 
 #endif // __VERSION_H__