Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ext.appNameLowerCase = appName.toLowerCase(Locale.US)
ext.junitVersion = '6.1.3'
ext.junitLauncherVersion = '6.1.3'
ext.jacocoVersion = '0.8.14'
ext.pmdVersion = '7.20.0'
ext.pmdVersion = '7.26.0'
ext.spotbugsVersion = '4.9.8'
ext.palantirVersion = '2.97.0'
// End tunables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public CommandLineParserBuilder addBoolean(
* @param defaultValue The default value of the argument.
* @return This instance of {@link CommandLineParserBuilder}.
*/
@SuppressWarnings("PMD.UseObjectForClearerAPI")
public CommandLineParserBuilder addString(
final String shortName, final String longName, final String description, final String defaultValue) {
arguments.add(new StringArgument(shortName, longName, description, defaultValue));
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/ledmington/emu/ELFLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,14 @@ private void loadCommandLineArgumentsAndEnvironmentVariables(
for (final String arg : commandLineArguments) {
wb.write(stringsOffset);
sb.append(arg).append('\0');
stringsOffset += (arg.length() + 1);
stringsOffset += arg.length() + 1;
}
wb.write(0L); // argv[argc]

for (final Map.Entry<String, String> env : environmentVariables.entrySet()) {
wb.write(stringsOffset);
sb.append(env.getKey()).append('=').append(env.getValue()).append('\0');
stringsOffset += (env.getKey().length() + 1 + env.getValue().length() + 1);
stringsOffset += env.getKey().length() + 1 + env.getValue().length() + 1;
}
wb.write(0L); // envp[envc]

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/ledmington/emu/X86RegisterFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void resetFlags() {
}

private void set(final RFlags f) {
rflags |= (1L << f.bit());
rflags |= 1L << f.bit();
}

private void reset(final RFlags f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ public ConstructorsSection(
}

int constructorsSizeInBytes = 0; // bytes
{
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_INIT_ARRAYSZ) {
constructorsSizeInBytes =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_INIT_ARRAYSZ) {
constructorsSizeInBytes =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ public DestructorsSection(
}

int destructorsSizeInBytes = 0; // bytes
{
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_FINI_ARRAYSZ) {
destructorsSizeInBytes =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_FINI_ARRAYSZ) {
destructorsSizeInBytes =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ public GnuVersionDefinitionSection(
this.header = Objects.requireNonNull(sectionHeader);

int versionDefinitionEntryNum = 0;
{
Objects.requireNonNull(dynamicSection);
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_VERDEFNUM) {
versionDefinitionEntryNum =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
Objects.requireNonNull(dynamicSection);
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_VERDEFNUM) {
versionDefinitionEntryNum =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ public GnuVersionRequirementsSection(
this.header = Objects.requireNonNull(sectionHeader);

int versionRequirementsEntryNum = 0;
{
Objects.requireNonNull(dynamicSection);
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_VERNEEDNUM) {
versionRequirementsEntryNum =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
Objects.requireNonNull(dynamicSection);
for (int i = 0; i < dynamicSection.getTableLength(); i++) {
if (dynamicSection.getEntry(i).getTag() == DynamicTableEntryTag.DT_VERNEEDNUM) {
versionRequirementsEntryNum =
BitUtils.asInt(dynamicSection.getEntry(i).getContent());
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/java/com/ledmington/view/ELFView.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private record Range(int offset, int length) {

private static final int MINIMUM_ALLOWED_LENGTH = 1;

public Range {
/* default */ Range {
if (offset < 0 || length < MINIMUM_ALLOWED_LENGTH) {
throw new IllegalArgumentException(String.format("Invalid range [%d; %d+%d]", offset, offset, length));
}
Expand Down
17 changes: 7 additions & 10 deletions gui/src/main/java/com/ledmington/view/Emu.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ public Emu(final Stage stage) {
bPane.setTop(topPane);

final BorderPane mainPane = new BorderPane();
{
mainPane.setCenter(
LabelFactory.getDefaultLabel(
String.join(
"\n",
"Welcome to Emu, a processor emulator made by Filippo Barbari (filippo.barbari@gmail.com).",
"",
"If you happen to find any bugs, please report them at https://github.com/Ledmington/emu/issues.")));
mainPane.setPadding(new Insets(5));
}
mainPane.setCenter(LabelFactory.getDefaultLabel(String.join(
"\n",
"Welcome to Emu, a processor emulator made by Filippo Barbari (filippo.barbari@gmail.com).",
"",
"If you happen to find any bugs, please report them at https://github.com/Ledmington/emu/issues.")));
mainPane.setPadding(new Insets(5));

bPane.setCenter(mainPane);

final FlowPane bottomPane = new FlowPane();
Expand Down
55 changes: 25 additions & 30 deletions gui/src/main/java/com/ledmington/view/SettingsWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,33 @@ public SettingsWindow() {
final Scene scene = new Scene(bPane);

final GridPane mainPane = new GridPane(10, 5);
{
mainPane.add(LabelFactory.getDefaultLabel("Font"), 0, 0);
this.fonts = new ComboBox<>();
for (final String fontFamily : Font.getFamilies()) {
final Label lbl = getFontLabel(fontFamily);
this.fonts.getItems().add(lbl);
if (this.fonts.getValue() == null) {
this.fonts.setValue(lbl);
}
mainPane.add(LabelFactory.getDefaultLabel("Font"), 0, 0);
this.fonts = new ComboBox<>();
for (final String fontFamily : Font.getFamilies()) {
final Label lbl = getFontLabel(fontFamily);
this.fonts.getItems().add(lbl);
if (this.fonts.getValue() == null) {
this.fonts.setValue(lbl);
}
mainPane.add(this.fonts, 1, 0);
}
{
mainPane.add(LabelFactory.getDefaultLabel("Font Size"), 0, 1);
this.fontSize = new Spinner<>(1, 20, AppConstants.getDefaultFontSize());
mainPane.add(this.fontSize, 1, 1);
}
{
mainPane.add(LabelFactory.getDefaultLabel("Max emulator instructions"), 0, 2);
this.maxCodeInstructions = new Spinner<>(1, 1000, AppConstants.getMaxCodeInstructions());
mainPane.add(this.maxCodeInstructions, 1, 2);
}
{
mainPane.add(LabelFactory.getDefaultLabel("Max emulator memory lines"), 0, 3);
this.maxMemoryLines = new Spinner<>(1, 1000, AppConstants.getMaxMemoryLines());
mainPane.add(this.maxMemoryLines, 1, 3);
}
{
mainPane.add(LabelFactory.getDefaultLabel("Memory bytes per line"), 0, 4);
this.memoryBytesPerLine = new Spinner<>(1, 1000, AppConstants.getMemoryBytesPerLine());
mainPane.add(this.memoryBytesPerLine, 1, 4);
}
mainPane.add(this.fonts, 1, 0);

mainPane.add(LabelFactory.getDefaultLabel("Font Size"), 0, 1);
this.fontSize = new Spinner<>(1, 20, AppConstants.getDefaultFontSize());
mainPane.add(this.fontSize, 1, 1);

mainPane.add(LabelFactory.getDefaultLabel("Max emulator instructions"), 0, 2);
this.maxCodeInstructions = new Spinner<>(1, 1000, AppConstants.getMaxCodeInstructions());
mainPane.add(this.maxCodeInstructions, 1, 2);

mainPane.add(LabelFactory.getDefaultLabel("Max emulator memory lines"), 0, 3);
this.maxMemoryLines = new Spinner<>(1, 1000, AppConstants.getMaxMemoryLines());
mainPane.add(this.maxMemoryLines, 1, 3);

mainPane.add(LabelFactory.getDefaultLabel("Memory bytes per line"), 0, 4);
this.memoryBytesPerLine = new Spinner<>(1, 1000, AppConstants.getMemoryBytesPerLine());
mainPane.add(this.memoryBytesPerLine, 1, 4);

mainPane.setPadding(new Insets(5));
bPane.setCenter(mainPane);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"PMD.TooManyMethods",
"PMD.AvoidDuplicateLiterals",
"PMD.CouplingBetweenObjects",
"PMD.TooManyStaticImports",
"PMD.NcssCount",
"PMD.CognitiveComplexity",
"PMD.TooFewBranchesForSwitch",
Expand Down Expand Up @@ -262,6 +261,7 @@ private static Immediate parseImmediate(final String imm) {
throw new IllegalArgumentException(String.format("Immediate too long: '%s'.", imm));
}

@SuppressWarnings("PMD.AvoidDeeplyNestedIfStmts")
private static Operand parseOperand(
final String input, final Operand previousOperand, final Optional<Integer> compressedDisplacement) {
if (fromStringToRegister.containsKey(input)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
* there are the LOCK/REP/REPNE, then the CS segment override, then the address size override, then the operand size
* override.
*/
// FIXME: reduce these suppressions
@SuppressWarnings({
"PMD.AvoidLiteralsInIfCondition",
"PMD.NPathComplexity",
"PMD.CyclomaticComplexity",
"PMD.UselessParentheses",
"PMD.NcssCount",
"PMD.CognitiveComplexity",
"PMD.TooManyStaticImports",
"PMD.TooManyMethods",
"PMD.LinguisticNaming",
"PMD.CommentDefaultAccessModifier",
Expand Down
10 changes: 2 additions & 8 deletions id/src/test/java/com/ledmington/cpu/X64Encodings.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@
import com.ledmington.cpu.x86.Opcode;
import com.ledmington.cpu.x86.SegmentedAddress;
import com.ledmington.utils.BitUtils;
import com.ledmington.utils.SuppressFBWarnings;

@SuppressWarnings("PMD.TooManyStaticImports")
@SuppressWarnings("PMD.UseUtilityClass")
public sealed class X64Encodings permits TestDecoding, TestDecodeIncompleteInstruction {

private static final Immediate one = new Immediate((byte) 1);
Expand All @@ -190,12 +189,7 @@ public sealed class X64Encodings permits TestDecoding, TestDecodeIncompleteInstr

// FIXME: this is ugly
// TODO: do the allowed encodings need to be a set (instead of a list)?
protected record X64EncodingTestCase(Instruction instruction, String intelSyntax, Set<byte[]> allowedEncodings) {
@SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "This object as is it is for now.")
public Set<byte[]> allowedEncodings() {
return allowedEncodings;
}
}
protected record X64EncodingTestCase(Instruction instruction, String intelSyntax, Set<byte[]> allowedEncodings) {}

private static X64EncodingTestCase test(final Instruction instruction, final String intelSyntax, final String hex) {
final String[] splitted = hex.strip().split(" ");
Expand Down
20 changes: 10 additions & 10 deletions mem/src/main/java/com/ledmington/mem/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ default int read4(final MemoryAddress address) {
// Little-endian
int x = 0;
x |= BitUtils.asInt(read(address));
x |= (BitUtils.asInt(read(address.plus(1L))) << 8);
x |= (BitUtils.asInt(read(address.plus(2L))) << 16);
x |= (BitUtils.asInt(read(address.plus(3L))) << 24);
x |= BitUtils.asInt(read(address.plus(1L))) << 8;
x |= BitUtils.asInt(read(address.plus(2L))) << 16;
x |= BitUtils.asInt(read(address.plus(3L))) << 24;
return x;
}

Expand All @@ -74,13 +74,13 @@ default long read8(final MemoryAddress address) {
// Little-endian
long x = 0x0000000000000000L;
x |= BitUtils.asLong(read(address));
x |= (BitUtils.asLong(read(address.plus(1L))) << 8);
x |= (BitUtils.asLong(read(address.plus(2L))) << 16);
x |= (BitUtils.asLong(read(address.plus(3L))) << 24);
x |= (BitUtils.asLong(read(address.plus(4L))) << 32);
x |= (BitUtils.asLong(read(address.plus(5L))) << 40);
x |= (BitUtils.asLong(read(address.plus(6L))) << 48);
x |= (BitUtils.asLong(read(address.plus(7L))) << 56);
x |= BitUtils.asLong(read(address.plus(1L))) << 8;
x |= BitUtils.asLong(read(address.plus(2L))) << 16;
x |= BitUtils.asLong(read(address.plus(3L))) << 24;
x |= BitUtils.asLong(read(address.plus(4L))) << 32;
x |= BitUtils.asLong(read(address.plus(5L))) << 40;
x |= BitUtils.asLong(read(address.plus(6L))) << 48;
x |= BitUtils.asLong(read(address.plus(7L))) << 56;
return x;
}

Expand Down
14 changes: 7 additions & 7 deletions mem/src/main/java/com/ledmington/mem/MemoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ public long read8(final MemoryAddress address) {
// Little-endian
long x = 0x0000000000000000L;
x |= BitUtils.asLong(mem.read(address));
x |= (BitUtils.asLong(mem.read(address.plus(1L))) << 8);
x |= (BitUtils.asLong(mem.read(address.plus(2L))) << 16);
x |= (BitUtils.asLong(mem.read(address.plus(3L))) << 24);
x |= (BitUtils.asLong(mem.read(address.plus(4L))) << 32);
x |= (BitUtils.asLong(mem.read(address.plus(5L))) << 40);
x |= (BitUtils.asLong(mem.read(address.plus(6L))) << 48);
x |= (BitUtils.asLong(mem.read(address.plus(7L))) << 56);
x |= BitUtils.asLong(mem.read(address.plus(1L))) << 8;
x |= BitUtils.asLong(mem.read(address.plus(2L))) << 16;
x |= BitUtils.asLong(mem.read(address.plus(3L))) << 24;
x |= BitUtils.asLong(mem.read(address.plus(4L))) << 32;
x |= BitUtils.asLong(mem.read(address.plus(5L))) << 40;
x |= BitUtils.asLong(mem.read(address.plus(6L))) << 48;
x |= BitUtils.asLong(mem.read(address.plus(7L))) << 56;
return x;
}

Expand Down
2 changes: 1 addition & 1 deletion mem/src/main/java/com/ledmington/mem/PagedMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static final class Page {
private final byte[] bytes;
private final boolean[] initialized;

public Page(final long numBytes, final MemoryInitializer initializer) {
/* default */ Page(final long numBytes, final MemoryInitializer initializer) {
this.bytes = new byte[Math.toIntExact(numBytes)];
this.initialized = new boolean[Math.toIntExact(numBytes)];
for (int i = 0; i < numBytes; i++) {
Expand Down
3 changes: 1 addition & 2 deletions mem/src/test/java/com/ledmington/mem/TestPagedMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
package com.ledmington.mem;

@SuppressWarnings("PMD.TestClassWithoutTestCases")
public final class TestPagedMemory extends TestMemory {
final class TestPagedMemory extends TestMemory {
@Override
protected Memory getMemory() {
return new PagedMemory(MemoryInitializer.random());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/
package com.ledmington.mem;

@SuppressWarnings("PMD.TestClassWithoutTestCases")
public final class TestRandomAccessMemory extends TestMemory {
final class TestRandomAccessMemory extends TestMemory {
@Override
protected Memory getMemory() {
return new RandomAccessMemory(MemoryInitializer.random());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class TestUninitializedMemory {
private MemoryController mem;

@BeforeEach
public void setup() {
/* default */ void setup() {
// Creating a memory controller with all permissions on the whole range, but without initializing anything
mem = new MemoryController(new RandomAccessMemory(MemoryInitializer.random()), true, true, true, true, true);
}
Expand Down
1 change: 1 addition & 0 deletions objdump/src/main/java/com/ledmington/objdump/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static void main(final String[] args) {
String filename = null;
boolean disassembleExecutableSections = false;

// FIXME: rewrite using package 'cmdline'
for (final String arg : args) {
switch (arg) {
case "-H", "--help":
Expand Down
7 changes: 7 additions & 0 deletions prod.ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
</properties>
</rule>

<!-- Avoid reporting files with too many static imports (FIXME: workaround until [this issue](https://github.com/pmd/pmd/issues/6983) gets fixed in PMD) -->
<rule ref="category/java/codestyle.xml/TooManyStaticImports">
<properties>
<property name="maximumStaticImports" value="10" />
</properties>
</rule>

<rule ref="category/java/design.xml">
<!-- Avoid reporting classes with too many imports -->
<exclude name="ExcessiveImports" />
Expand Down
Loading
Loading