Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions id/src/main/java/com/ledmington/cpu/InstructionDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import com.ledmington.cpu.x86.IndirectOperandBuilder;
import com.ledmington.cpu.x86.Instruction;
import com.ledmington.cpu.x86.InstructionBuilder;
import com.ledmington.cpu.x86.InstructionPrefix;
import com.ledmington.cpu.x86.LegacyPrefix;
import com.ledmington.cpu.x86.MaskRegister;
import com.ledmington.cpu.x86.ModRM;
import com.ledmington.cpu.x86.NullRegister;
Expand Down Expand Up @@ -144,7 +144,7 @@ public static Instruction fromIntelSyntax(final String input) {
String opcodeString = readUntilWhitespace(it);
if ("lock".equals(opcodeString) || "rep".equals(opcodeString) || "repnz".equals(opcodeString)) {
final String finalOpcodeString = opcodeString;
ib.prefix(Arrays.stream(InstructionPrefix.values())
ib.prefix(Arrays.stream(LegacyPrefix.values())
.filter(p -> p.name().toLowerCase(Locale.US).equals(finalOpcodeString))
.findAny()
.orElseThrow());
Expand Down Expand Up @@ -599,7 +599,7 @@ yield isIndirectOperandNeeded(modrm)
!pref.hasAddressSizeOverridePrefix(),
pref.rex().hasModRMRMExtension(),
pref.hasOperandSizeOverridePrefix()));
if (pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REPNZ) {
if (pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REPNZ) {
ib.opcode(Opcode.BND_JMP);
} else {
ib.opcode(Opcode.JMP);
Expand Down Expand Up @@ -1356,7 +1356,7 @@ private static Instruction parse2BytesOpcode(
yield Instruction.builder().opcode(Opcode.ENDBR64).build();
} else if (x == (byte) 0xfb) {
yield Instruction.builder().opcode(Opcode.ENDBR32).build();
} else if (pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REP) {
} else if (pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REP) {
final ModRM modrm = new ModRM(x);
yield Instruction.builder()
.opcode(Opcode.RDSSPQ)
Expand Down Expand Up @@ -1515,7 +1515,7 @@ private static Instruction parse2BytesOpcode(
}
case BSF_OPCODE -> {
final ModRM modrm = modrm(b);
final boolean hasRepPrefix = pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REP;
final boolean hasRepPrefix = pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REP;
yield Instruction.builder()
.opcode(hasRepPrefix ? Opcode.TZCNT : Opcode.BSF)
.op(Registers.fromCode(
Expand Down Expand Up @@ -1642,7 +1642,7 @@ yield new GeneralInstruction(
final byte r1 = getByteFromReg(pref.rex(), modrm);
final byte r2 = getByteFromRM(pref, modrm);
final boolean movdqa = pref.hasOperandSizeOverridePrefix();
final boolean movdqu = pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REP;
final boolean movdqu = pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REP;
yield Instruction.builder()
.opcode(movdqa ? Opcode.MOVDQA : (movdqu ? Opcode.MOVDQU : Opcode.MOVQ))
.op((movdqa || movdqu) ? RegisterXMM.fromByte(r1) : RegisterMMX.fromByte(modrm.reg()))
Expand Down Expand Up @@ -2015,15 +2015,15 @@ yield new GeneralInstruction(
final ModRM modrm = modrm(b);
final InstructionBuilder ib = Instruction.builder();
ib.op(RegisterXMM.fromByte(getByteFromReg(pref.rex(), modrm)));
if (pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REP) {
if (pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REP) {
ib.opcode(Opcode.DIVSS)
.op(
isIndirectOperandNeeded(modrm)
? parseIndirectOperand(b, pref, modrm)
.pointer(PointerSize.DWORD_PTR)
.build()
: RegisterXMM.fromByte(getByteFromRM(pref, modrm)));
} else if (pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REPNZ) {
} else if (pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REPNZ) {
ib.opcode(Opcode.DIVSD)
.op(
isIndirectOperandNeeded(modrm)
Expand Down Expand Up @@ -2196,7 +2196,7 @@ yield new GeneralInstruction(
case MOVSD_OPCODE -> {
final ModRM modrm = modrm(b);
final boolean hasRepnePrefix =
pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REPNZ;
pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REPNZ;
yield Instruction.builder()
.opcode(hasRepnePrefix ? Opcode.MOVSD : Opcode.MOVUPS)
.op(RegisterXMM.fromByte(getByteFromReg(pref.rex(), modrm)))
Expand Down Expand Up @@ -2431,7 +2431,7 @@ private static Instruction parseExtendedOpcodeGroup9(
};
}

if (pref.p1().isPresent() && pref.p1().orElseThrow() == InstructionPrefix.REP) {
if (pref.p1().isPresent() && pref.p1().orElseThrow() == LegacyPrefix.REP) {
notImplemented();
}

Expand Down Expand Up @@ -4415,7 +4415,7 @@ private static void invalidValue() {
}

private static Prefixes parsePrefixes(final ReadOnlyByteBuffer b) {
Optional<InstructionPrefix> p1 = Optional.empty(); // Legacy Prefix Group 1
Optional<LegacyPrefix> p1 = Optional.empty(); // Legacy Prefix Group 1
Optional<Byte> p2 = Optional.empty(); // Legacy Prefix Group 2
boolean hasOperandSizeOverridePrefix = false;
boolean hasAddressSizeOverridePrefix = false;
Expand All @@ -4426,7 +4426,7 @@ private static Prefixes parsePrefixes(final ReadOnlyByteBuffer b) {
final byte x = b.read1();

if (isLegacyPrefixGroup1(x)) {
p1 = Optional.of(InstructionPrefix.fromByte(x));
p1 = Optional.of(LegacyPrefix.fromByte(x));
} else if (isLegacyPrefixGroup2(x)) {
p2 = Optional.of(x);
} else if (isOperandSizeOverridePrefix(x)) {
Expand Down Expand Up @@ -4662,9 +4662,9 @@ private static void notImplemented() {
}

private static boolean isLegacyPrefixGroup1(final byte prefix) {
return prefix == InstructionPrefix.LOCK.getCode()
|| prefix == InstructionPrefix.REPNZ.getCode()
|| prefix == InstructionPrefix.REP.getCode();
return prefix == LegacyPrefix.LOCK.getCode()
|| prefix == LegacyPrefix.REPNZ.getCode()
|| prefix == LegacyPrefix.REP.getCode();
}

private static boolean isLegacyPrefixGroup2(final byte prefix) {
Expand Down
8 changes: 4 additions & 4 deletions id/src/main/java/com/ledmington/cpu/InstructionEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.ledmington.cpu.x86.Immediate;
import com.ledmington.cpu.x86.IndirectOperand;
import com.ledmington.cpu.x86.Instruction;
import com.ledmington.cpu.x86.InstructionPrefix;
import com.ledmington.cpu.x86.LegacyPrefix;
import com.ledmington.cpu.x86.MaskRegister;
import com.ledmington.cpu.x86.Opcode;
import com.ledmington.cpu.x86.Operand;
Expand Down Expand Up @@ -330,7 +330,7 @@ private static void encodePrefixes(final WriteOnlyByteBuffer wb, final Instructi
wb.write(OPERAND_SIZE_OVERRIDE_PREFIX);
}
if (inst.hasLockPrefix()) {
wb.write(InstructionPrefix.LOCK.getCode());
wb.write(LegacyPrefix.LOCK.getCode());
}
if (inst.hasRepPrefix()
|| (inst.opcode() == Opcode.RDSSPQ
Expand All @@ -341,7 +341,7 @@ private static void encodePrefixes(final WriteOnlyByteBuffer wb, final Instructi
|| (((inst.opcode() == Opcode.MOVQ || inst.opcode() == Opcode.MOVDQU)
&& isFirstXMM(inst)
&& isSecondM(inst)))) {
wb.write(InstructionPrefix.REP.getCode());
wb.write(LegacyPrefix.REP.getCode());
}
if (inst.hasRepnzPrefix()
|| ((inst.opcode() == Opcode.MOVSD && isFirstXMM(inst) && isSecondM(inst))
Expand All @@ -350,7 +350,7 @@ && isSecondM(inst)))) {
|| (inst.opcode() == Opcode.ADDSD)
|| (inst.opcode() == Opcode.LDDQU)
|| (inst.opcode() == Opcode.BND_JMP))) {
wb.write(InstructionPrefix.REPNZ.getCode());
wb.write(LegacyPrefix.REPNZ.getCode());
}

// TODO: maybe refactor this into 'checkRequiredPrefix'?
Expand Down
2 changes: 1 addition & 1 deletion id/src/main/java/com/ledmington/cpu/x86/EvexPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/** The extended VEX prefix (EVEX): 0x62 + 3 bytes. */
@SuppressWarnings("PMD.UnusedPrivateField")
public final class EvexPrefix {
public final class EvexPrefix implements InstructionPrefix {

private final boolean r;
private final boolean x;
Expand Down
17 changes: 7 additions & 10 deletions id/src/main/java/com/ledmington/cpu/x86/GeneralInstruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/** Most general implementation of an x86 instruction. */
public final class GeneralInstruction implements Instruction {

private final InstructionPrefix prefix;
private final LegacyPrefix prefix;
private final Opcode code;
private final MaskRegister destinationMask;
private final boolean destinationMaskZero;
Expand All @@ -32,7 +32,7 @@ public final class GeneralInstruction implements Instruction {
private final Operand op4;

/* default */ GeneralInstruction(
final InstructionPrefix prefix,
final LegacyPrefix prefix,
final Opcode opcode,
final MaskRegister destinationMask,
final boolean destinationMaskZero,
Expand Down Expand Up @@ -73,10 +73,7 @@ public final class GeneralInstruction implements Instruction {
* @param secondOperand The second operand of the Instruction.
*/
public GeneralInstruction(
final InstructionPrefix prefix,
final Opcode opcode,
final Operand firstOperand,
final Operand secondOperand) {
final LegacyPrefix prefix, final Opcode opcode, final Operand firstOperand, final Operand secondOperand) {
this(prefix, opcode, null, false, firstOperand, secondOperand, null, null);
}

Expand All @@ -103,7 +100,7 @@ public GeneralInstruction(
* @param thirdOperand The third operand of the Instruction.
*/
public GeneralInstruction(
final InstructionPrefix prefix,
final LegacyPrefix prefix,
final Opcode opcode,
final Operand firstOperand,
final Operand secondOperand,
Expand Down Expand Up @@ -147,7 +144,7 @@ public GeneralInstruction(final Opcode opcode, final Operand firstOperand, final
* @param opcode The opcode of the Instruction.
* @param firstOperand The first operand of the Instruction.
*/
public GeneralInstruction(final InstructionPrefix prefix, final Opcode opcode, final Operand firstOperand) {
public GeneralInstruction(final LegacyPrefix prefix, final Opcode opcode, final Operand firstOperand) {
this(prefix, opcode, null, false, firstOperand, null, null, null);
}

Expand All @@ -157,7 +154,7 @@ public GeneralInstruction(final InstructionPrefix prefix, final Opcode opcode, f
* @param prefix The prefix of the Instruction.
* @param opcode The opcode of the Instruction.
*/
public GeneralInstruction(final InstructionPrefix prefix, final Opcode opcode) {
public GeneralInstruction(final LegacyPrefix prefix, final Opcode opcode) {
this(prefix, opcode, null, false, null, null, null, null);
}

Expand Down Expand Up @@ -186,7 +183,7 @@ public boolean hasPrefix() {
}

@Override
public InstructionPrefix getPrefix() {
public LegacyPrefix getPrefix() {
if (!hasPrefix()) {
throw new IllegalArgumentException("No prefix.");
}
Expand Down
8 changes: 4 additions & 4 deletions id/src/main/java/com/ledmington/cpu/x86/Instruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ default Operand operand(final int operandIndex) {
*
* @return The prefix of this instruction.
*/
InstructionPrefix getPrefix();
LegacyPrefix getPrefix();

/**
* Checks whether this instruction has a LOCK prefix.
*
* @return True if this instruction has a LOCK prefix, false otherwise.
*/
default boolean hasLockPrefix() {
return hasPrefix() && getPrefix() == InstructionPrefix.LOCK;
return hasPrefix() && getPrefix() == LegacyPrefix.LOCK;
}

/**
Expand All @@ -155,7 +155,7 @@ default boolean hasLockPrefix() {
* @return True if this instruction has a REP prefix, false otherwise.
*/
default boolean hasRepPrefix() {
return hasPrefix() && getPrefix() == InstructionPrefix.REP;
return hasPrefix() && getPrefix() == LegacyPrefix.REP;
}

/**
Expand All @@ -164,7 +164,7 @@ default boolean hasRepPrefix() {
* @return True if this instruction has a REPNZ prefix, false otherwise.
*/
default boolean hasRepnzPrefix() {
return hasPrefix() && getPrefix() == InstructionPrefix.REPNZ;
return hasPrefix() && getPrefix() == LegacyPrefix.REPNZ;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/** A builder for constructing {@link Instruction} objects. */
public final class InstructionBuilder {

private InstructionPrefix prefix = null;
private LegacyPrefix prefix = null;
private Opcode opcode = null;
private MaskRegister destinationMask = null;
private boolean destinationMaskZero = false;
Expand All @@ -49,7 +49,7 @@ private void assertNotBuilt() {
* @param prefix The prefix to set.
* @return This builder.
*/
public InstructionBuilder prefix(final InstructionPrefix prefix) {
public InstructionBuilder prefix(final LegacyPrefix prefix) {
assertNotBuilt();
if (this.prefix != null) {
throw new IllegalArgumentException("Cannot set prefix twice.");
Expand Down
Loading
Loading