mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-23 03:22:08 +00:00
Allow JR between sections
Previously, JR was only allowed if the destination label was in the same section as the JR. This patch removes this restriction. The check to see if the relative value overflows is now done when linking the ROM. Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -455,7 +455,6 @@ static void updateUnion(void)
|
||||
%type <nConstValue> const_3bit
|
||||
%type <sVal> const_8bit
|
||||
%type <sVal> const_16bit
|
||||
%type <sVal> const_PCrel
|
||||
%type <nConstValue> sectiontype
|
||||
|
||||
%type <tzString> string
|
||||
@@ -1116,14 +1115,6 @@ constlist_32bit_entry_single : /* empty */
|
||||
}
|
||||
;
|
||||
|
||||
const_PCrel : relocconst
|
||||
{
|
||||
if (!rpn_isPCRelative(&$1))
|
||||
yyerror("Expression must be PC-relative");
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
|
||||
const_8bit : relocconst
|
||||
{
|
||||
if( (!rpn_isReloc(&$1)) && (($1.nVal < -128) || ($1.nVal > 255)) )
|
||||
@@ -1612,12 +1603,12 @@ z80_jp : T_Z80_JP const_16bit
|
||||
}
|
||||
;
|
||||
|
||||
z80_jr : T_Z80_JR const_PCrel
|
||||
z80_jr : T_Z80_JR const_16bit
|
||||
{
|
||||
out_AbsByte(0x18);
|
||||
out_PCRelByte(&$2);
|
||||
}
|
||||
| T_Z80_JR ccode comma const_PCrel
|
||||
| T_Z80_JR ccode comma const_16bit
|
||||
{
|
||||
out_AbsByte(0x20 | ($2 << 3));
|
||||
out_PCRelByte(&$4);
|
||||
|
||||
@@ -593,7 +593,7 @@ void out_SetFileName(char *s)
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a section by name and type. If it doesn't exist, create it
|
||||
* Find a section by name and type. If it doesn't exist, create it
|
||||
*/
|
||||
struct Section *out_FindSection(char *pzName, uint32_t secttype, int32_t org,
|
||||
int32_t bank, int32_t alignment)
|
||||
@@ -764,7 +764,7 @@ void out_String(char *s)
|
||||
}
|
||||
|
||||
/*
|
||||
* Output a relocatable byte. Checking will be done to see if it
|
||||
* Output a relocatable byte. Checking will be done to see if it
|
||||
* is an absolute value in disguise.
|
||||
*/
|
||||
void out_RelByte(struct Expression *expr)
|
||||
@@ -803,7 +803,7 @@ void out_AbsWord(int32_t b)
|
||||
}
|
||||
|
||||
/*
|
||||
* Output a relocatable word. Checking will be done to see if
|
||||
* Output a relocatable word. Checking will be done to see if
|
||||
* it's an absolute value in disguise.
|
||||
*/
|
||||
void out_RelWord(struct Expression *expr)
|
||||
@@ -847,7 +847,7 @@ void out_AbsLong(int32_t b)
|
||||
}
|
||||
|
||||
/*
|
||||
* Output a relocatable longword. Checking will be done to see if
|
||||
* Output a relocatable longword. Checking will be done to see if
|
||||
* is an absolute value in disguise.
|
||||
*/
|
||||
void out_RelLong(struct Expression *expr)
|
||||
@@ -875,19 +875,31 @@ void out_RelLong(struct Expression *expr)
|
||||
}
|
||||
|
||||
/*
|
||||
* Output a PC-relative byte
|
||||
* Output a PC-relative relocatable byte. Checking will be done to see if it
|
||||
* is an absolute value in disguise.
|
||||
*/
|
||||
void out_PCRelByte(struct Expression *expr)
|
||||
{
|
||||
int32_t b = expr->nVal;
|
||||
|
||||
checkcodesection();
|
||||
checksectionoverflow(1);
|
||||
b = (b & 0xFFFF) - (nPC + 1);
|
||||
if (nPass == 2 && (b < -128 || b > 127))
|
||||
yyerror("PC-relative value must be 8-bit");
|
||||
if (rpn_isReloc(expr)) {
|
||||
if (nPass == 2) {
|
||||
pCurrentSection->tData[nPC] = 0;
|
||||
createpatch(PATCH_BYTE_JR, expr);
|
||||
}
|
||||
pCurrentSection->nPC += 1;
|
||||
nPC += 1;
|
||||
pPCSymbol->nValue += 1;
|
||||
} else {
|
||||
int32_t b = expr->nVal;
|
||||
|
||||
out_AbsByte(b);
|
||||
b = (int16_t)((b & 0xFFFF) - (nPC + 1));
|
||||
|
||||
if (nPass == 2 && ((b < -128) || (b > 127)))
|
||||
yyerror("PC-relative value must be 8-bit");
|
||||
|
||||
out_AbsByte(b & 0xFF);
|
||||
}
|
||||
rpn_Reset(expr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user