mirror of
https://github.com/keystone-engine/keystone.git
synced 2026-10-12 02:17:10 +00:00
x86: FARJMP/FARCALL support Nasm syntax
This commit is contained in:
@@ -2424,6 +2424,22 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
|
||||
{
|
||||
MCAsmParser &Parser = getParser();
|
||||
InstInfo = &Info;
|
||||
|
||||
// Nasm accepts JMP/CALL, but not LJMP/LCALL
|
||||
if (KsSyntax == KS_OPT_SYNTAX_NASM) {
|
||||
if (Name == "jmp" || Name == "call") {
|
||||
AsmToken Tokens[3];
|
||||
MutableArrayRef<AsmToken> Buf(Tokens);
|
||||
size_t count = getLexer().peekTokens(Buf);
|
||||
if (count == 3 && Tokens[0].getString() == ":") {
|
||||
if (Name == "jmp")
|
||||
Name = "ljmp";
|
||||
else if (Name == "call")
|
||||
Name = "lcall";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringRef PatchedName = Name;
|
||||
|
||||
// FIXME: Hack to recognize setneb as setne.
|
||||
@@ -2584,18 +2600,18 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
|
||||
Parser.eatToEndOfStatement();
|
||||
return true;
|
||||
}
|
||||
// for LJMP/LCALL, check for ':'. otherwise, check for comma and eat it
|
||||
if (Name.startswith("ljmp") || Name.startswith("lcall")) {
|
||||
if (getLexer().is(AsmToken::Colon)) {
|
||||
//Parser.Lex();
|
||||
|
||||
if (getLexer().is(AsmToken::Colon)) {
|
||||
// for LJMP/LCALL, check for ':'. otherwise, check for comma and eat it
|
||||
if (Name.startswith("ljmp") || Name.startswith("lcall"))
|
||||
Operands.push_back(X86Operand::CreateToken(":", consumeToken()));
|
||||
} else
|
||||
else
|
||||
break;
|
||||
} else if (getLexer().is(AsmToken::Comma))
|
||||
Parser.Lex();
|
||||
Parser.Lex();
|
||||
else
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (getLexer().isNot(AsmToken::EndOfStatement) && getLexer().isNot(AsmToken::Eof)) {
|
||||
//return ErrorAndEatStatement(getLexer().getLoc(),
|
||||
@@ -2775,7 +2791,8 @@ bool X86AsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool X86AsmParser::processInstruction(MCInst &Inst, const OperandVector &Ops) {
|
||||
bool X86AsmParser::processInstruction(MCInst &Inst, const OperandVector &Ops)
|
||||
{
|
||||
switch (Inst.getOpcode()) {
|
||||
default: return false;
|
||||
case X86::VMOVZPQILo2PQIrr:
|
||||
|
||||
@@ -15,8 +15,13 @@ class TestX86Intel(regress.RegressTest):
|
||||
ks = Ks(KS_ARCH_X86, KS_MODE_32)
|
||||
# Assemble with zero addr
|
||||
try:
|
||||
# Keystone (LLVM) syntax
|
||||
encoding, count = ks.asm("ljmp 0x33:08", 0)
|
||||
self.assertEqual(encoding, [ 0xea, 0x08, 0x00, 0x30, 0x00 ])
|
||||
# NASM syntax
|
||||
ks.syntax = KS_OPT_SYNTAX_NASM
|
||||
encoding2, count = ks.asm("jmp 0x33:08", 0)
|
||||
self.assertEqual(encoding, encoding2)
|
||||
except KsError as e:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user