mirror of http://shamusworld.gotdns.org/git/rmac
.equr overhaul part 3: store and handle banks in .equr evaluation
This commit is contained in:
parent
216bfb25e0
commit
f23a0935e1
1
error.c
1
error.c
|
@ -20,6 +20,7 @@ char * interror_msg[] = {
|
|||
"Can't find generated code in section", // Error #6
|
||||
"Fixup (loc) out of range" // Error #7
|
||||
"Absolute top filename found" // Error #8
|
||||
""
|
||||
};
|
||||
|
||||
// Exported variables
|
||||
|
|
18
expr.c
18
expr.c
|
@ -467,15 +467,15 @@ int expr(TOKEN * otk, uint64_t * a_value, WORD * a_attr, SYM ** a_esym)
|
|||
// return ERROR;
|
||||
}
|
||||
|
||||
// Check register bank usage
|
||||
if (symbol->sattre & EQUATEDREG)
|
||||
{
|
||||
if ((regbank == BANK_0) && (symbol->sattre & BANK_1) && !altbankok)
|
||||
warn("equated symbol '%s' cannot be used in register bank 0", symbol->sname);
|
||||
|
||||
if ((regbank == BANK_1) && (symbol->sattre & BANK_0) && !altbankok)
|
||||
warn("equated symbol '%s' cannot be used in register bank 1", symbol->sname);
|
||||
}
|
||||
// Check register bank usage (moved to EvaluateRegisterFromTokenStream()))
|
||||
//if (symbol->sattre & EQUATEDREG)
|
||||
//{
|
||||
// if ((regbank == BANK_0) && (symbol->sattre & BANK_1) && !altbankok)
|
||||
// warn("equated symbol '%s' cannot be used in register bank 0", symbol->sname);
|
||||
//
|
||||
// if ((regbank == BANK_1) && (symbol->sattre & BANK_0) && !altbankok)
|
||||
// warn("equated symbol '%s' cannot be used in register bank 1", symbol->sname);
|
||||
//}
|
||||
|
||||
*evalTokenBuffer.u32++ = SYMBOL;
|
||||
#if 0
|
||||
|
|
134
riscasm.c
134
riscasm.c
|
@ -201,9 +201,23 @@ 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.
|
||||
if (*tok >= KW_R0 && *tok <= KW_R31)
|
||||
int reg = *tok & 255;
|
||||
if (reg >= KW_R0 && reg <= KW_R31)
|
||||
{
|
||||
int reg = *tok - KW_R0;
|
||||
// Check register bank usage in the case of .equr register
|
||||
// (encoded as bits 30 and 31 in *tok).
|
||||
// (I still think that this is superfluous and should be taken out, see my note in token.c)
|
||||
if (*tok & 0x80000000)
|
||||
{
|
||||
// Oops, with all the evaluation in token.c we now lost the equated symbol reference, so we
|
||||
// don't know its name or anything else. Oh well...
|
||||
if ((regbank == BANK_0) && (*tok & 0x40000000) && !altbankok)
|
||||
return error("equated symbol cannot be used in register bank 0");
|
||||
|
||||
if ((regbank == BANK_1) && !(*tok & 0x40000000) && !altbankok)
|
||||
return error("equated symbol cannot be used in register bank 1");
|
||||
}
|
||||
reg -= KW_R0;
|
||||
tok++;
|
||||
return reg;
|
||||
}
|
||||
|
@ -230,12 +244,15 @@ static int EvaluateRegisterFromTokenStream(uint32_t fixup)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// If we got a register in range (0-31), return it
|
||||
if (eattr & RISCREG)
|
||||
return (int)eval - KW_R0;
|
||||
// We shouldn't get here, that should not be legal
|
||||
interror(9);
|
||||
|
||||
// Otherwise, it's out of range & we flag an error
|
||||
return error(reg_err);
|
||||
// If we got a register in range (0-31), return it
|
||||
//if (eattr & RISCREG)
|
||||
// return (int)eval - KW_R0;
|
||||
|
||||
//// Otherwise, it's out of range & we flag an error
|
||||
//return error(reg_err);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -454,35 +471,38 @@ int GenerateRISCCode(int state)
|
|||
if ((tok[1] == '+') || (tok[1] == '-'))
|
||||
{
|
||||
// Trying to make indexed call
|
||||
if ((*tok == KW_R14) || (*tok == KW_R15))
|
||||
indexed = (*tok - KW_R0);
|
||||
// Note: no bank check for .equr symbol here, but the original code for .equr
|
||||
// below also didn't check for banks. Even more reasons to throw away
|
||||
// bank checks.
|
||||
if (((*tok & 0xff) == KW_R14) || ((*tok &0xff) == KW_R15))
|
||||
indexed = ((*tok & 0xff) - KW_R0);
|
||||
else
|
||||
return IllegalIndexedRegister(*tok);
|
||||
}
|
||||
|
||||
if (*tok == SYMBOL)
|
||||
{
|
||||
sy = lookup(string[tok[1]], LABEL, 0);
|
||||
|
||||
if (!sy)
|
||||
{
|
||||
error(reg_err);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (sy->sattre & EQUATEDREG)
|
||||
{
|
||||
if ((tok[2] == '+') || (tok[2] == '-'))
|
||||
{
|
||||
if ((sy->svalue - KW_R0) == 14 || (sy->svalue - KW_R0) == 15) {
|
||||
indexed = (sy->svalue - KW_R0);
|
||||
tok++;
|
||||
}
|
||||
else
|
||||
return IllegalIndexedRegisterEqur(sy);
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (*tok == SYMBOL)
|
||||
//{
|
||||
// sy = lookup(string[tok[1]], LABEL, 0);
|
||||
//
|
||||
// if (!sy)
|
||||
// {
|
||||
// error(reg_err);
|
||||
// return ERROR;
|
||||
// }
|
||||
//
|
||||
// if (sy->sattre & EQUATEDREG)
|
||||
// {
|
||||
// if ((tok[2] == '+') || (tok[2] == '-'))
|
||||
// {
|
||||
// if ((sy->svalue - KW_R0) == 14 || (sy->svalue - KW_R0) == 15) {
|
||||
// indexed = (sy->svalue - KW_R0);
|
||||
// tok++;
|
||||
// }
|
||||
// else
|
||||
// return IllegalIndexedRegisterEqur(sy);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
if (!indexed)
|
||||
{
|
||||
|
@ -499,7 +519,7 @@ int GenerateRISCCode(int state)
|
|||
parm = (WORD)(reg1 - 14 + 58);
|
||||
tok++;
|
||||
|
||||
if ((*tok >= KW_R0) && (*tok <= KW_R31))
|
||||
if (((*tok & 0xff) >= KW_R0) && ((*tok & 0xff) <= KW_R31))
|
||||
indexed = 1;
|
||||
|
||||
if (*tok == SYMBOL)
|
||||
|
@ -575,29 +595,31 @@ int GenerateRISCCode(int state)
|
|||
tok++;
|
||||
indexed = 0;
|
||||
|
||||
if (((*tok == KW_R14) || (*tok == KW_R15)) && (tok[1] != ')'))
|
||||
indexed = *tok - KW_R0;
|
||||
// Again, no bank checks here or in the original code.
|
||||
// This check has more holes than a very hole-y thing.
|
||||
if ((((*tok & 0xff) == KW_R14) || ((*tok & 0xff) == KW_R15)) && (tok[1] != ')'))
|
||||
indexed = (*tok & 0xff) - KW_R0;
|
||||
|
||||
if (*tok == SYMBOL)
|
||||
{
|
||||
sy = lookup(string[tok[1]], LABEL, 0);
|
||||
|
||||
if (!sy)
|
||||
{
|
||||
error(reg_err);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (sy->sattre & EQUATEDREG)
|
||||
{
|
||||
if (((sy->svalue - KW_R0) == 14 || (sy->svalue - KW_R0) == 15)
|
||||
&& (tok[2] != ')'))
|
||||
{
|
||||
indexed = (sy->svalue - KW_R0);
|
||||
tok++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//if (*tok == SYMBOL)
|
||||
//{
|
||||
// sy = lookup(string[tok[1]], LABEL, 0);
|
||||
//
|
||||
// if (!sy)
|
||||
// {
|
||||
// error(reg_err);
|
||||
// return ERROR;
|
||||
// }
|
||||
//
|
||||
// if (sy->sattre & EQUATEDREG)
|
||||
// {
|
||||
// if (((sy->svalue - KW_R0) == 14 || (sy->svalue - KW_R0) == 15)
|
||||
// && (tok[2] != ')'))
|
||||
// {
|
||||
// indexed = (sy->svalue - KW_R0);
|
||||
// tok++;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
if (!indexed)
|
||||
{
|
||||
|
@ -614,7 +636,7 @@ int GenerateRISCCode(int state)
|
|||
parm = (WORD)(reg2 - 14 + 60);
|
||||
tok++;
|
||||
|
||||
if ((*tok >= KW_R0) && (*tok <= KW_R31))
|
||||
if (((*tok & 0xff) >= KW_R0) && ((*tok & 0xff) <= KW_R31))
|
||||
indexed = 1;
|
||||
|
||||
if (*tok == SYMBOL)
|
||||
|
|
21
token.c
21
token.c
|
@ -1205,12 +1205,31 @@ DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); }
|
|||
if ((j < 0) || (state < 0))
|
||||
{
|
||||
// Last attempt: let's see if this is an equated register
|
||||
char temp = *ln;
|
||||
*ln = 0;
|
||||
sy = lookup(nullspot, LABEL, 0);
|
||||
*ln = temp;
|
||||
if (sy)
|
||||
{
|
||||
if (sy->sattre & EQUATEDREG)
|
||||
{
|
||||
*tk.u32++ = sy->svalue;
|
||||
uint32_t register_token = sy->svalue;
|
||||
if (rgpu || rdsp)
|
||||
{
|
||||
// If we are in GPU or DSP mode then mark the register bank.
|
||||
// We will use it during EvaluateRegisterFromTokenStream()
|
||||
// when we check if we can use the equated register with the currently
|
||||
// selected bank.
|
||||
// Note (ggn): I find all this superfluous. Do we really want to be so
|
||||
// protective? Plus, the current implementation happily skips
|
||||
// these checks on .equr that are set during fixups - oops!
|
||||
register_token |= 0x80000000; // Mark that this is an .equr
|
||||
if (sy->sattre & BANK_1)
|
||||
{
|
||||
register_token |= 0x40000000; // Mark bank 1
|
||||
}
|
||||
}
|
||||
*tk.u32++ = register_token;
|
||||
stuffnull = 0;
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue