Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Issue 7387 - call instruction does not understand $ #11624

Merged
merged 1 commit into from Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/dmd/iasmdmd.d
Expand Up @@ -777,6 +777,14 @@ RETRY:
enum log = false;
if (log) { printf("`%s`\n", asm_opstr(pop)); }
if (log) { printf("opflags1 = "); asm_output_flags(opflags[0]); printf("\n"); }

if (pop.ptb.pptb1.opcode == 0xE8 &&
opnds[0].s == asmstate.psDollar &&
(opnds[0].disp >= byte.min && opnds[0].disp <= byte.max)
)
// Rewrite CALL $+disp from rel8 to rel32
opflags[0] = CONSTRUCT_FLAGS(OpndSize._32, _rel, _flbl, 0);

PTRNTAB1 *table1;
for (table1 = pop.ptb.pptb1; table1.opcode != ASM_END;
table1++)
Expand Down Expand Up @@ -1232,9 +1240,9 @@ opflag_t asm_determine_operand_flags(ref OPND popnd)
if (popnd.disp >= byte.min &&
popnd.disp <= byte.max)
us = CONSTRUCT_FLAGS(OpndSize._8, _rel, _flbl,0);
else if (popnd.disp >= short.min &&
popnd.disp <= short.max && !global.params.is64bit)
us = CONSTRUCT_FLAGS(OpndSize._16, _rel, _flbl,0);
//else if (popnd.disp >= short.min &&
//popnd.disp <= short.max && global.params.is16bit)
//us = CONSTRUCT_FLAGS(OpndSize._16, _rel, _flbl,0);
Comment on lines +1243 to +1245
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to leave a reminder if I ever ported it back to DMC. That piece is necessary for 16 bit assembler.

else
us = CONSTRUCT_FLAGS(OpndSize._32, _rel, _flbl,0);
}
Expand Down
8 changes: 8 additions & 0 deletions test/runnable/iasm.d
Expand Up @@ -4748,6 +4748,10 @@ void test9866()
0x66, 0x0f, 0xb7, 0x00, // movzx AX, word ptr [EAX];
0x0f, 0xb7, 0xc0, // movzx EAX, AX;
0x0f, 0xb7, 0x00, // movzx EAX, word ptr [EAX];

0xEB, 0x00, //jmp $;
0xE9, 0xCD, 0xAB, 0x00, 0x00, // jmp $+0xABCD;
0xE8, 0x05, 0x00, 0x00, 0x00, // call $+5;
];

asm
Expand All @@ -4772,6 +4776,10 @@ void test9866()
movzx EAX, AX;
movzx EAX, word ptr [EAX];

jmp $;
jmp $+0xABCD;
call $+5;

L1: pop EAX;
mov p[EBP],EAX;
}
Expand Down
37 changes: 37 additions & 0 deletions test/runnable/iasm64.d
Expand Up @@ -6864,6 +6864,42 @@ void test20126()

/****************************************************/

void test63()
{
asm
{
L1:
mov EAX,0;
jmp L2;

db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
db 0,0,0,0,0,0,0,0 ;
}
asm
{
jmp L1; // more than 128 bytes away
}
L2:
{
}
}

/****************************************************/

int main()
{
printf("Testing iasm64.d\n");
Expand Down Expand Up @@ -6940,6 +6976,7 @@ int main()
test17027();
test18553();
test20126();
test63();

printf("Success\n");
return 0;
Expand Down