X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=riscasm.c;h=3092e6e7017d4c0e0a5145baf33d3ffd2d09663a;hp=a76cb2e19a1438310e38939571546a29cc1569cb;hb=HEAD;hpb=f3c7d186a15b89c39e360b9cc89545a0d24bd6a4 diff --git a/riscasm.c b/riscasm.c index a76cb2e..3399b81 100644 --- a/riscasm.c +++ b/riscasm.c @@ -1,7 +1,7 @@ // -// RMAC - Reboot's Macro Assembler for all Atari computers +// RMAC - Renamed Macro Assembler for all Atari computers // RISCA.C - GPU/DSP Assembler -// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -13,15 +13,34 @@ #include "expr.h" #include "mark.h" #include "procln.h" +#include "rmac.h" #include "sect.h" #include "token.h" #define DEF_MR // Declare keyword values #include "risckw.h" // Incl. generated risc keywords -#define DEF_KW // Declare keyword values -#include "kwtab.h" // Incl. generated keyword tables & defs +#define DEF_REGRISC +#include "riscregs.h" // Incl. generated keyword tables & defs +#define MAXINTERNCC 26 // Maximum internal condition codes + +// Useful macros +#define EVAL_REG_RETURN_IF_ERROR(x, y) \ +x = EvaluateRegisterFromTokenStream(y); \ +\ +if (x == ERROR) \ + return ERROR; + +#define EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(x, y) \ +x = EvaluateRegisterFromTokenStream(y); \ +\ +if ((x == ERROR) || (ErrorIfNotAtEOL() == ERROR)) \ + return ERROR; + +#define CHECK_EOL \ +if (ErrorIfNotAtEOL() == ERROR) \ + return ERROR; unsigned altbankok = 0; // Ok to use alternate register bank unsigned orgactive = 0; // RISC/6502 org directive active @@ -30,22 +49,29 @@ unsigned orgwarning = 0; // Has an ORG warning been issued int lastOpcode = -1; // Last RISC opcode assembled uint8_t riscImmTokenSeen; // The '#' (immediate) token was seen -const char reg_err[] = "missing register R0...R31"; +static const char reg_err[] = "missing register R0...R31"; // Jaguar jump condition names -const char condname[MAXINTERNCC][5] = { +static const char condname[MAXINTERNCC][5] = { "NZ", "Z", "NC", "NCNZ", "NCZ", "C", "CNZ", "CZ", "NN", "NNNZ", "NNZ", "N", "N_NZ", "N_Z", "T", "A", "NE", "EQ", "CC", "HS", "HI", "CS", "LO", "PL", "MI", "F" }; // Jaguar jump condition numbers -const char condnumber[] = { +static const char condnumber[] = { 1, 2, 4, 5, 6, 8, 9, 10, 20, 21, 22, 24, 25, 26, 0, 0, 1, 2, 4, 4, 5, 8, 8, 20, 24, 31 }; -const struct opcoderecord roptbl[] = { +// Opcode Specific Data +struct opcoderecord { + uint16_t state; // Opcode Name (unused) + uint16_t type; // Opcode Type + uint16_t param; // Opcode Parameter +}; + +static const struct opcoderecord roptbl[] = { { MR_ADD, RI_TWO, 0 }, { MR_ADDC, RI_TWO, 1 }, { MR_ADDQ, RI_NUM_32, 2 }, @@ -102,24 +128,27 @@ const struct opcoderecord roptbl[] = { { MR_NORMI, RI_TWO, 56 }, { MR_NOP, RI_NONE, 57 }, { MR_SAT24, RI_ONE, 62 }, - { MR_UNPACK, RI_ONE, 63 + GPUONLY | (0 << 6) }, - { MR_PACK, RI_ONE, 63 + GPUONLY | (1 << 6) }, + { MR_UNPACK, RI_ONE, 63 + GPUONLY | (1 << 6) }, + { MR_PACK, RI_ONE, 63 + GPUONLY | (0 << 6) }, { MR_ADDQMOD, RI_NUM_32, 63 + DSPONLY }, { MR_MOVE, RI_MOVE, 0 }, { MR_LOAD, RI_LOAD, 0 }, { MR_STORE, RI_STORE, 0 } }; +#define MALF_NUM 0 +#define MALF_EXPR 1 +#define MALF_LPAREN 2 +#define MALF_RPAREN 3 -// -// Convert a string to uppercase -// -void strtoupper(char * s) -{ - while (*s) - *s++ &= 0xDF; -} +static const char malform1[] = "missing '#'"; +static const char malform2[] = "bad expression"; +static const char malform3[] = "missing ')'"; +static const char malform4[] = "missing '('"; +static const char * malformErr[] = { + malform1, malform2, malform3, malform4 +}; // // Function to return "malformed expression" error @@ -127,20 +156,18 @@ void strtoupper(char * s) // static inline int MalformedOpcode(int signal) { - return error("Malformed opcode [internal $%02X]", signal); + return error("Malformed opcode, %s", malformErr[signal]); } - // // Function to return "Illegal Indexed Register" error // Anyone trying to index something other than R14 or R15 // static inline int IllegalIndexedRegister(int reg) { - return error("Attempted index reference with non-indexable register (r%d)", reg - KW_R0); + return error("Attempted index reference with non-indexable register (r%d)", reg - REGRISC_R0); } - // // Function to return "Illegal Indexed Register" error for EQUR scenarios // Trying to use register value within EQUR that isn't 14 or 15 @@ -150,11 +177,10 @@ static inline int IllegalIndexedRegisterEqur(SYM * sy) return error("Attempted index reference with non-indexable register within EQUR (%s = r%d)", sy->sname, sy->svalue); } - // -// Build RISC instruction word +// Build up & deposit RISC instruction word // -void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2) +static void DepositRISCInstructionWord(uint16_t opcode, int reg1, int reg2) { // Check for absolute address setting if (!orgwarning && !orgactive) @@ -164,43 +190,53 @@ void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2) } int value = ((opcode & 0x3F) << 10) + ((reg1 & 0x1F) << 5) + (reg2 & 0x1F); + GENLINENOSYM(); D_word(value); -//printf("BuildRISC: opcode=$%X, reg1=$%X, reg2=$%X, final=$%04X\n", opcode, reg1, reg2, value); } - // -// Get a RISC register +// Evaluate the RISC register from the token stream. Passed in value is the +// FIXUP attribute to use if the expression comes back as undefined. // -int GetRegister(WORD rattr) +static int EvaluateRegisterFromTokenStream(uint32_t fixup) { + // Firstly, check to see if it's a register token and return that. No + // need to invoke expr() for easy cases like this. + int reg = *tok & 255; + if (reg >= REGRISC_R0 && reg <= REGRISC_R31) + { + reg -= REGRISC_R0; + tok++; + return reg; + } + + if (*tok != SYMBOL) + { + // If at this point we don't have a symbol then it's garbage. Punt. + return error("Expected register number or EQUREG"); + } + uint64_t eval; // Expression value WORD eattr; // Expression attributes SYM * esym; // External symbol involved in expr. TOKEN r_expr[EXPRSIZE]; // Expression token list // Evaluate what's in the global "tok" buffer - if (expr((TOKENPTR)r_expr, &eval, &eattr, &esym) != OK) + // N.B.: We should either get a fixup or a register name from EQUR + if (expr(r_expr, &eval, &eattr, &esym) != OK) return ERROR; - if ((challoc - ch_size) < 4) - chcheck(4L); - if (!(eattr & DEFINED)) { - AddFixup((WORD)(FU_WORD | rattr), sloc, (TOKENPTR)r_expr); + AddFixup(FU_WORD | fixup, sloc, r_expr); return 0; } - // If we got a register in range (0-31), return it - if ((eval >= 0) && (eval <= 31)) - return (int)eval; - - // Otherwise, it's out of range & we flag an error - return error(reg_err); + // We shouldn't get here, that should not be legal + interror(9); + return 0; // Not that this will ever execute, but let's be nice and pacify gcc warnings } - // // Do RISC code generation // @@ -214,17 +250,17 @@ int GenerateRISCCode(int state) SYM * sy; int i, commaFound; TOKEN * t; - WORD attrflg; + uint16_t attrflg; int indexed; // Indexed register flag uint64_t eval; // Expression value - WORD eattr; // Expression attributes - SYM * esym; // External symbol involved in expr. + uint16_t eattr; // Expression attributes + SYM * esym = NULL; // External symbol involved in expr. TOKEN r_expr[EXPRSIZE]; // Expression token list // Get opcode parameter and type - unsigned short parm = (WORD)(roptbl[state - 3000].parm); - unsigned type = roptbl[state - 3000].typ; + uint16_t parm = roptbl[state - 3000].param; + uint16_t type = roptbl[state - 3000].type; riscImmTokenSeen = 0; // Set to "token not seen yet" // Detect whether the opcode parmeter passed determines that the opcode is @@ -239,16 +275,15 @@ int GenerateRISCCode(int state) // No operand instructions // NOP (57) case RI_NONE: - BuildRISCIntructionWord(parm, 0, 0); + DepositRISCInstructionWord(parm, 0, 0); break; // Single operand instructions (Rd) // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S, // UNPACK case RI_ONE: - reg2 = GetRegister(FU_REGTWO); - at_eol(); - BuildRISCIntructionWord(parm, parm >> 6, reg2); + EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(reg2, FU_REGTWO); + DepositRISCInstructionWord(parm, parm >> 6, reg2); break; // Two operand instructions (Rs,Rd) @@ -258,15 +293,14 @@ int GenerateRISCCode(int state) if (parm == 37) altbankok = 1; // MOVEFA - reg1 = GetRegister(FU_REGONE); + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); CHECK_COMMA; if (parm == 36) altbankok = 1; // MOVETA - reg2 = GetRegister(FU_REGTWO); - at_eol(); - BuildRISCIntructionWord(parm, reg1, reg2); + EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(reg2, FU_REGTWO); + DepositRISCInstructionWord(parm, reg1, reg2); break; // Numeric operand (n,Rd) where n = -16..+15 @@ -298,27 +332,30 @@ int GenerateRISCCode(int state) if (parm & SUB32) attrflg |= FU_SUB32; - if (*tok.u32 != '#') - return MalformedOpcode(0x01); + if (*tok != '#') + return MalformedOpcode(MALF_NUM); - tok.u32++; + tok++; riscImmTokenSeen = 1; - if (expr((TOKENPTR)r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(0x02); - - if ((challoc - ch_size) < 4) - chcheck(4L); + if (expr(r_expr, &eval, &eattr, &esym) != OK) + return MalformedOpcode(MALF_EXPR); if (!(eattr & DEFINED)) { - AddFixup((WORD)(FU_WORD | attrflg), sloc, (TOKENPTR)r_expr); + AddFixup((WORD)(FU_WORD | attrflg), sloc, r_expr); reg1 = 0; } else { - if ((int)eval < reg1 || (int)eval > reg2) - return error("constant out of range"); + if (esym && (esym->sattre & EQUATEDREG)) + return error("equated register seen for immediate value"); + + if (eattr & RISCREG) + return error("register seen for immediate value"); + + if (((int)eval < reg1) || ((int)eval > reg2)) + return error("constant out of range (%d to %d)", reg1, reg2); if (parm & SUB32) reg1 = 32 - (int)eval; @@ -329,87 +366,78 @@ int GenerateRISCCode(int state) } CHECK_COMMA; - reg2 = GetRegister(FU_REGTWO); - at_eol(); - BuildRISCIntructionWord(parm, reg1, reg2); + EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(reg2, FU_REGTWO); + DepositRISCInstructionWord(parm, reg1, reg2); break; // Move Immediate--n,Rn--n in Second Word case RI_MOVEI: - if (*tok.u32 != '#') - return MalformedOpcode(0x03); + if (*tok != '#') + return MalformedOpcode(MALF_NUM); - tok.u32++; + tok++; riscImmTokenSeen = 1; // Check for equated register after # and return error if so - if (*tok.u32 == SYMBOL) + if (*tok == SYMBOL) { - sy = lookup(string[tok.u32[1]], LABEL, 0); + sy = lookup(string[tok[1]], LABEL, 0); if (sy && (sy->sattre & EQUATEDREG)) return error("equated register in 1st operand of MOVEI instruction"); } - if (expr((TOKENPTR)r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(0x04); + if (expr(r_expr, &eval, &eattr, &esym) != OK) + return MalformedOpcode(MALF_EXPR); - if (lastOpcode == RI_JUMP || lastOpcode == RI_JR) + if ((lastOpcode == RI_JUMP) || (lastOpcode == RI_JR)) { if (legacy_flag) { // User doesn't care, emit a NOP to fix - BuildRISCIntructionWord(57, 0, 0); + DepositRISCInstructionWord(57, 0, 0); warn("MOVEI following JUMP, inserting NOP to fix your BROKEN CODE"); } else warn("MOVEI immediately follows JUMP"); } - if ((challoc - ch_size) < 4) - chcheck(4L); - if (!(eattr & DEFINED)) { - AddFixup(FU_LONG | FU_MOVEI, sloc + 2, (TOKENPTR)r_expr); + AddFixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr); eval = 0; } else { if (eattr & TDB) -//{ -//printf("RISCASM: Doing MarkRelocatable for RI_MOVEI (tdb=$%X)...\n", eattr & TDB); MarkRelocatable(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL); -//} } -// val = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000); - val = WORDSWAP32(eval); CHECK_COMMA; - reg2 = GetRegister(FU_REGTWO); - at_eol(); - D_word((((parm & 0x3F) << 10) + reg2)); + EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(reg2, FU_REGTWO); + + DepositRISCInstructionWord(parm, 0, reg2); + val = WORDSWAP32(eval); D_long(val); break; // PC,Rd or Rs,Rd case RI_MOVE: - if (*tok.u32 == KW_PC) + if (*tok == REGRISC_PC) { parm = 51; reg1 = 0; - tok.u32++; + tok++; } else { parm = 34; - reg1 = GetRegister(FU_REGONE); + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); } CHECK_COMMA; - reg2 = GetRegister(FU_REGTWO); - at_eol(); - BuildRISCIntructionWord(parm, reg1, reg2); + EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(reg2, FU_REGTWO); + DepositRISCInstructionWord(parm, reg1, reg2); break; // (Rn),Rn = 41 / (R14/R15+n),Rn = 43/44 / (R14/R15+Rn),Rn = 58/59 @@ -417,66 +445,41 @@ int GenerateRISCCode(int state) indexed = 0; parm = 41; - if (*tok.u32 != '(') - return MalformedOpcode(0x05); - - tok.u32++; + if (*tok != '(') + return MalformedOpcode(MALF_LPAREN); - if ((*(tok.u32 + 1) == '+') || (*(tok.u32 + 1) == '-')) { - // Trying to make indexed call - if ((*tok.u32 == KW_R14 || *tok.u32 == KW_R15)) { - indexed = (*tok.u32 - KW_R0); - } else { - return IllegalIndexedRegister(*tok.u32); - } - } + tok++; - if (*tok.u32 == SYMBOL) + if ((tok[1] == '+') || (tok[1] == '-')) { -// sy = lookup((char *)tok.u32[1], LABEL, 0); - sy = lookup(string[tok.u32[1]], LABEL, 0); - - if (!sy) - { - error(reg_err); - return ERROR; - } - - if (sy->sattre & EQUATEDREG) - { - if ((*(tok.u32 + 2) == '+') || (*(tok.u32 + 2) == '-')) { - if ((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15) { - indexed = (sy->svalue & 0x1F); - tok.u32++; - } else { - return IllegalIndexedRegisterEqur(sy); - } - } - } + // Trying to make indexed call + if ((*tok == REGRISC_R14) || (*tok == REGRISC_R15)) + indexed = (*tok - REGRISC_R0); + else + return IllegalIndexedRegister(*tok); } if (!indexed) { - reg1 = GetRegister(FU_REGONE); + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); } else { reg1 = indexed; indexed = 0; - tok.u32++; + tok++; - if (*tok.u32 == '+') + if (*tok == '+') { parm = (WORD)(reg1 - 14 + 58); - tok.u32++; + tok++; - if (*tok.u32 >= KW_R0 && *tok.u32 <= KW_R31) + if ((*tok >= REGRISC_R0) && (*tok <= REGRISC_R31)) indexed = 1; - if (*tok.u32 == SYMBOL) + if (*tok == SYMBOL) { -// sy = lookup((char *)tok.u32[1], LABEL, 0); - sy = lookup(string[tok.u32[1]], LABEL, 0); + sy = lookup(string[tok[1]], LABEL, 0); if (!sy) { @@ -490,15 +493,12 @@ int GenerateRISCCode(int state) if (indexed) { - reg1 = GetRegister(FU_REGONE); + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); } else { - if (expr((TOKENPTR)r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(0x06); - - if ((challoc - ch_size) < 4) - chcheck(4L); + if (expr(r_expr, &eval, &eattr, &esym) != OK) + return MalformedOpcode(MALF_EXPR); if (!(eattr & DEFINED)) return error("constant expected after '+'"); @@ -513,8 +513,8 @@ int GenerateRISCCode(int state) } else { - if (reg1 < 1 || reg1 > 32) - return error("constant in LOAD out of range"); + if ((reg1 < 1) || (reg1 > 32)) + return error("constant in LOAD out of range (1-32)"); if (reg1 == 32) reg1 = 0; @@ -525,77 +525,55 @@ int GenerateRISCCode(int state) } else { - reg1 = GetRegister(FU_REGONE); + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); } } - if (*tok.u32 != ')') - return MalformedOpcode(0x07); + if (*tok != ')') + return MalformedOpcode(MALF_RPAREN); - tok.u32++; + tok++; CHECK_COMMA; - reg2 = GetRegister(FU_REGTWO); - at_eol(); - BuildRISCIntructionWord(parm, reg1, reg2); + EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(reg2, FU_REGTWO); + DepositRISCInstructionWord(parm, reg1, reg2); break; // Rn,(Rn) = 47 / Rn,(R14/R15+n) = 49/50 / Rn,(R14/R15+Rn) = 60/61 case RI_STORE: parm = 47; - reg1 = GetRegister(FU_REGONE); + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); CHECK_COMMA; - if (*tok.u32 != '(') - return MalformedOpcode(0x08); + if (*tok != '(') + return MalformedOpcode(MALF_LPAREN); - tok.u32++; + tok++; indexed = 0; - if ((*tok.u32 == KW_R14 || *tok.u32 == KW_R15) && (*(tok.u32 + 1) != ')')) - indexed = (*tok.u32 - KW_R0); - - if (*tok.u32 == SYMBOL) - { - sy = lookup(string[tok.u32[1]], LABEL, 0); - - if (!sy) - { - error(reg_err); - return ERROR; - } - - if (sy->sattre & EQUATEDREG) - { - if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15) - && (*(tok.u32 + 2) != ')')) - { - indexed = (sy->svalue & 0x1F); - tok.u32++; - } - } - } + if (((*tok == REGRISC_R14) || (*tok == REGRISC_R15)) && (tok[1] != ')')) + indexed = *tok - REGRISC_R0; if (!indexed) { - reg2 = GetRegister(FU_REGTWO); + EVAL_REG_RETURN_IF_ERROR(reg2, FU_REGTWO); } else { reg2 = indexed; indexed = 0; - tok.u32++; + tok++; - if (*tok.u32 == '+') + if (*tok == '+') { parm = (WORD)(reg2 - 14 + 60); - tok.u32++; + tok++; - if (*tok.u32 >= KW_R0 && *tok.u32 <= KW_R31) + if ((*tok >= REGRISC_R0) && (*tok <= REGRISC_R31)) indexed = 1; - if (*tok.u32 == SYMBOL) + if (*tok == SYMBOL) { - sy = lookup(string[tok.u32[1]], LABEL, 0); + sy = lookup(string[tok[1]], LABEL, 0); if (!sy) { @@ -609,19 +587,16 @@ int GenerateRISCCode(int state) if (indexed) { - reg2 = GetRegister(FU_REGTWO); + EVAL_REG_RETURN_IF_ERROR(reg2, FU_REGTWO); } else { - if (expr((TOKENPTR)r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(0x09); - - if ((challoc - ch_size) < 4) - chcheck(4L); + if (expr(r_expr, &eval, &eattr, &esym) != OK) + return MalformedOpcode(MALF_EXPR); if (!(eattr & DEFINED)) { - AddFixup(FU_WORD | FU_REGTWO, sloc, (TOKENPTR)r_expr); + AddFixup(FU_WORD | FU_REGTWO, sloc, r_expr); reg2 = 0; } else @@ -636,8 +611,8 @@ int GenerateRISCCode(int state) } else { - if (reg2 < 1 || reg2 > 32) - return error("constant in STORE out of range"); + if ((reg2 < 1) || (reg2 > 32)) + return error("constant in STORE out of range (1-32)"); if (reg2 == 32) reg2 = 0; @@ -649,53 +624,52 @@ int GenerateRISCCode(int state) } else { - reg2 = GetRegister(FU_REGTWO); + EVAL_REG_RETURN_IF_ERROR(reg2, FU_REGTWO); } } - if (*tok.u32 != ')') - return MalformedOpcode(0x0A); + if (*tok != ')') + return MalformedOpcode(MALF_RPAREN); - tok.u32++; - at_eol(); - BuildRISCIntructionWord(parm, reg2, reg1); + tok++; + CHECK_EOL; + DepositRISCInstructionWord(parm, reg2, reg1); break; // LOADB/LOADP/LOADW (Rn),Rn case RI_LOADN: - if (*tok.u32 != '(') - return MalformedOpcode(0x0B); + if (*tok != '(') + return MalformedOpcode(MALF_LPAREN); - tok.u32++; - reg1 = GetRegister(FU_REGONE); + tok++; + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); - if (*tok.u32 != ')') - return MalformedOpcode(0x0C); + if (*tok != ')') + return MalformedOpcode(MALF_RPAREN); - tok.u32++; + tok++; CHECK_COMMA; - reg2 = GetRegister(FU_REGTWO); - at_eol(); - BuildRISCIntructionWord(parm, reg1, reg2); + EVAL_REG_RETURN_IF_ERROR_OR_NO_EOL(reg2, FU_REGTWO); + DepositRISCInstructionWord(parm, reg1, reg2); break; // STOREB/STOREP/STOREW Rn,(Rn) case RI_STOREN: - reg1 = GetRegister(FU_REGONE); + EVAL_REG_RETURN_IF_ERROR(reg1, FU_REGONE); CHECK_COMMA; - if (*tok.u32 != '(') - return MalformedOpcode(0x0D); + if (*tok != '(') + return MalformedOpcode(MALF_LPAREN); - tok.u32++; - reg2 = GetRegister(FU_REGTWO); + tok++; + EVAL_REG_RETURN_IF_ERROR(reg2, FU_REGTWO); - if (*tok.u32 != ')') - return MalformedOpcode(0x0E); + if (*tok != ')') + return MalformedOpcode(MALF_RPAREN); - tok.u32++; - at_eol(); - BuildRISCIntructionWord(parm, reg2, reg1); + tok++; + CHECK_EOL; + DepositRISCInstructionWord(parm, reg2, reg1); break; // Jump Relative - cc,n - n=-16..+15 words, reg2=cc @@ -707,7 +681,7 @@ int GenerateRISCCode(int state) // the JR or JUMP should default to 0, Jump Always commaFound = 0; - for(t=tok.u32; *t!=EOL; t++) + for(t=tok; *t!=EOL; t++) { if (*t == ',') { @@ -718,20 +692,19 @@ int GenerateRISCCode(int state) if (commaFound) { - if (*tok.u32 == CONST) + if (*tok == CONST) { - // CC using a constant number - tok.u32++; - uint64_t *tok64 = (uint64_t *)tok.u32; - val = (int)*tok64++; - tok.u32 = (uint32_t *)tok64; + // CC using a constant number (O_o) + PTR tp; + tp.tk = tok + 1; + val = *tp.i64++; + tok = tp.tk; CHECK_COMMA; } - else if (*tok.u32 == SYMBOL) + else if (*tok == SYMBOL) { - val = 99; -// strcpy(scratch, (char *)tok.u32[1]); - strcpy(scratch, string[tok.u32[1]]); + val = 9999; + strcpy(scratch, string[tok[1]]); strtoupper(scratch); for(i=0; isattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC)) - val = ccsym->svalue; + val = (int)ccsym->svalue; else return error("unknown condition code"); } - tok.u32 += 2; + tok += 2; CHECK_COMMA; } - else if (*tok.u32 == '(') + else if (*tok == '(') { // Set CC to "Jump Always" val = 0; @@ -771,7 +743,7 @@ int GenerateRISCCode(int state) val = 0; } - if (val < 0 || val > 31) + if ((val < 0) || (val > 31)) return error("condition constant out of range"); // Store condition code @@ -780,15 +752,12 @@ int GenerateRISCCode(int state) if (type == RI_JR) { // JR cc,n - if (expr((TOKENPTR)r_expr, &eval, &eattr, &esym) != OK) - return MalformedOpcode(0x0F); - - if ((challoc - ch_size) < 4) - chcheck(4L); + if (expr(r_expr, &eval, &eattr, &esym) != OK) + return MalformedOpcode(MALF_EXPR); if (!(eattr & DEFINED)) { - AddFixup(FU_WORD | FU_JR, sloc, (TOKENPTR)r_expr); + AddFixup(FU_WORD | FU_JR, sloc, r_expr); reg2 = 0; } else @@ -796,31 +765,29 @@ int GenerateRISCCode(int state) reg2 = ((int)(eval - ((orgactive ? orgaddr : sloc) + 2))) / 2; if ((reg2 < -16) || (reg2 > 15)) - error("PC relative overflow (outside of -16 to 15)"); + error("PC relative overflow in JR (outside of -16 to 15)"); } - - BuildRISCIntructionWord(parm, reg2, reg1); } else { // JUMP cc, (Rn) - if (*tok.u32 != '(') - return MalformedOpcode(0x10); + if (*tok != '(') + return MalformedOpcode(MALF_LPAREN); - tok.u32++; - reg2 = GetRegister(FU_REGTWO); + tok++; + EVAL_REG_RETURN_IF_ERROR(reg2, FU_REGTWO); - if (*tok.u32 != ')') - return MalformedOpcode(0x11); + if (*tok != ')') + return MalformedOpcode(MALF_RPAREN); - tok.u32++; - at_eol(); - BuildRISCIntructionWord(parm, reg2, reg1); + tok++; + CHECK_EOL; } + DepositRISCInstructionWord(parm, reg2, reg1); break; - // Should never get here :-D + // We should never get here. If we do, somebody done fucked up. :-D default: return error("Unknown RISC opcode type"); } @@ -828,4 +795,3 @@ int GenerateRISCCode(int state) lastOpcode = type; return 0; } -