//
// RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
// RISCA.C - GPU/DSP Assembler
-// Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011 - 2017 Reboot and Friends
// RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
// Source utilised with the kind permission of Landon Dyer
//
#include "riscasm.h"
+#include "amode.h"
+#include "direct.h"
#include "error.h"
-#include "sect.h"
-#include "token.h"
#include "expr.h"
-#include "direct.h"
#include "mark.h"
-#include "amode.h"
+#include "procln.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
+#define DEF_KW // Declare keyword values
#include "kwtab.h" // Incl. generated keyword tables & defs
unsigned altbankok = 0; // Ok to use alternate register bank
-unsigned orgactive = 0; // RISC org directive active
+unsigned orgactive = 0; // RISC/6502 org directive active
unsigned orgaddr = 0; // Org'd address
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";
-// Jaguar Jump Condition Names
-const char condname[MAXINTERNCC][5] = {
+// Jaguar jump condition names
+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
+// Jaguar jump condition numbers
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
{ MR_NORMI, RI_TWO, 56 },
{ MR_NOP, RI_NONE, 57 },
{ MR_SAT24, RI_ONE, 62 },
- { MR_UNPACK, RI_ONE, 63 + GPUONLY },
- { MR_PACK, RI_ONE, 63 + GPUONLY },
+ { MR_UNPACK, RI_ONE, 63 + GPUONLY | (0 << 6) },
+ { MR_PACK, RI_ONE, 63 + GPUONLY | (1 << 6) },
{ MR_ADDQMOD, RI_NUM_32, 63 + DSPONLY },
{ MR_MOVE, RI_MOVE, 0 },
{ MR_LOAD, RI_LOAD, 0 },
return errors("Malformed opcode [internal $%s]", buf);
}
+//
+// Function to return "Illegal Indexed Register" error
+// Anyone trying to index something other than R14 or R15
+//
+static inline int IllegalIndexedRegister(int reg)
+{
+ char buf[16];
+ sprintf(buf, "%d", reg - KW_R0);
+ return errors("Attempted index reference with non-indexable register (r%s)", buf);
+}
+
+//
+// Function to return "Illegal Indexed Register" error for EQUR scenarios
+// Trying to use register value within EQUR that isn't 14 or 15
+//
+static inline int IllegalIndexedRegisterEqur(SYM *sy)
+{
+ //char buf[160];
+ char *buf = NULL;
+ buf = (char *)malloc((strlen(sy->sname) + 7) * sizeof(char));
+ if (NULL != buf) {
+ sprintf(buf, "%s = r%d",sy->sname, sy->svalue);
+ return errors("Attempted index reference with non-indexable register within EQUR (%s)", buf);
+ }
+ return errors("Unable to allocate memory! (IllegalIndexRegisterEqur)", "OOPS");
+}
//
// Build RISC instruction word
// Check for absolute address setting
if (!orgwarning && !orgactive)
{
-// warn("GPU/DSP code outside of absolute section");
warn("RISC code generated with no origin defined");
orgwarning = 1;
}
int value = ((opcode & 0x3F) << 10) + ((reg1 & 0x1F) << 5) + (reg2 & 0x1F);
D_word(value);
+//printf("BuildRISC: opcode=$%X, reg1=$%X, reg2=$%X, final=$%04X\n", opcode, reg1, reg2, value);
}
if (!(eattr & DEFINED))
{
- AddFixup((WORD)(FU_WORD | rattr), sloc, r_expr);
+ AddFixup((WORD)(FU_WORD | rattr), sloc, r_expr);
return 0;
}
// Get opcode parameter and type
unsigned short parm = (WORD)(roptbl[state - 3000].parm);
unsigned type = roptbl[state - 3000].typ;
+ riscImmTokenSeen = 0; // Set to "token not seen yet"
// Detect whether the opcode parmeter passed determines that the opcode is
// specific to only one of the RISC processors and ensure it is legal in
break;
// Single operand instructions (Rd)
- // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S, UNPACK
+ // 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);
- break;
+ break;
// Two operand instructions (Rs,Rd)
- // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT, MMULT,
- // MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
- case RI_TWO:
+ // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT,
+ // MMULT, MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
+ case RI_TWO:
if (parm == 37)
altbankok = 1; // MOVEFA
reg1 = GetRegister(FU_REGONE);
- CHECK_COMMA;
+ CHECK_COMMA;
if (parm == 36)
altbankok = 1; // MOVETA
case RI_NUM_31:
// Numeric operand (n,Rd) where n = 1..32
- // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ, RORQ
+ // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ,
+ // RORQ
case RI_NUM_32:
switch (type)
{
return MalformedOpcode(0x01);
tok++;
+ riscImmTokenSeen = 1;
if (expr(r_expr, &eval, &eattr, &esym) != OK)
return MalformedOpcode(0x02);
if ((int)eval < reg1 || (int)eval > reg2)
return error("constant out of range");
- if (parm & SUB32)
- reg1 = 32 - eval;
+ if (parm & SUB32)
+ reg1 = 32 - eval;
else if (type == RI_NUM_32)
reg1 = (reg1 == 32 ? 0 : eval);
else
return MalformedOpcode(0x03);
tok++;
+ riscImmTokenSeen = 1;
+
+ // Check for equated register after # and return error if so
+ if (*tok == SYMBOL)
+ {
+ sy = lookup(string[tok[1]], LABEL, 0);
+
+ if (sy && (sy->sattre & EQUATEDREG))
+ return error("equated register in 1st operand of MOVEI instruction");
+ }
if (expr(r_expr, &eval, &eattr, &esym) != OK)
return MalformedOpcode(0x04);
{
if (eattr & TDB)
//{
-//printf("risca: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB);
- rmark(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL);
+//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 = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
+ val = WORDSWAP32(eval);
CHECK_COMMA;
reg2 = GetRegister(FU_REGTWO);
at_eol();
break;
// (Rn),Rn = 41 / (R14/R15+n),Rn = 43/44 / (R14/R15+Rn),Rn = 58/59
- case RI_LOAD:
+ case RI_LOAD:
indexed = 0;
parm = 41;
tok++;
- if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')'))
- indexed = (*tok - KW_R0);
+ if ((*(tok + 1) == '+') || (*(tok + 1) == '-')) {
+ // Trying to make indexed call
+ if ((*tok == KW_R14 || *tok == KW_R15)) {
+ indexed = (*tok - KW_R0);
+ } else {
+ return IllegalIndexedRegister(*tok);
+ }
+ }
if (*tok == SYMBOL)
{
if (sy->sattre & EQUATEDREG)
{
- if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
- && (*(tok + 2) != ')'))
- {
- indexed = (sy->svalue & 0x1F);
- tok++;
+ if ((*(tok + 2) == '+') || (*(tok + 2) == '-')) {
+ if ((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15) {
+ indexed = (sy->svalue & 0x1F);
+ tok++;
+ } else {
+ return IllegalIndexedRegisterEqur(sy);
+ }
}
}
}
break;
// Rn,(Rn) = 47 / Rn,(R14/R15+n) = 49/50 / Rn,(R14/R15+Rn) = 60/61
- case RI_STORE:
+ case RI_STORE:
parm = 47;
reg1 = GetRegister(FU_REGONE);
CHECK_COMMA;
tok++;
indexed = 0;
- if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')'))
+ if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')'))
indexed = (*tok - KW_R0);
if (*tok == SYMBOL)
return ERROR;
}
- if (sy->sattre & EQUATEDREG)
+ if (sy->sattre & EQUATEDREG)
{
if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
&& (*(tok + 2) != ')'))
break;
// LOADB/LOADP/LOADW (Rn),Rn
- case RI_LOADN:
+ case RI_LOADN:
if (*tok != '(')
return MalformedOpcode(0x0B);
break;
// STOREB/STOREP/STOREW Rn,(Rn)
- case RI_STOREN:
+ case RI_STOREN:
reg1 = GetRegister(FU_REGONE);
CHECK_COMMA;