mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
LibDisassembly: Add common priviledged instructions
This does not include all instructions for S- and M-mode from the priviledged spec, but these are the common ones that we will definitely need (and use ourselves)
This commit is contained in:
1 parent
6b50d895ba
commit
1d5cd6a903
5 files changed
+103
No files matched your search
@@ -6,6 +6,7 @@ set(SOURCES
|
||||
riscv64/Formatting.cpp
|
||||
riscv64/Instruction.cpp
|
||||
riscv64/IM.cpp
|
||||
riscv64/Priviledged.cpp
|
||||
riscv64/Zicsr.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "Formatting.h"
|
||||
#include "Instruction.h"
|
||||
#include "Priviledged.h"
|
||||
|
||||
namespace Disassembly::RISCV64 {
|
||||
|
||||
@@ -316,6 +317,21 @@ String InstructionFetchFence::mnemonic() const
|
||||
return "fence.i"_string;
|
||||
}
|
||||
|
||||
String MachineModeTrapReturn::mnemonic() const
|
||||
{
|
||||
return "mret"_string;
|
||||
}
|
||||
|
||||
String SupervisorModeTrapReturn::mnemonic() const
|
||||
{
|
||||
return "sret"_string;
|
||||
}
|
||||
|
||||
String WaitForInterrupt::mnemonic() const
|
||||
{
|
||||
return "wfi"_string;
|
||||
}
|
||||
|
||||
String CSRImmediateInstruction::to_string(DisplayStyle display_style, u32, Optional<SymbolProvider const&>) const
|
||||
{
|
||||
return MUST(String::formatted("{:10} {}, {:#x}, {}", mnemonic(), format_register(destination_register(), display_style), csr(), immediate()));
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Encoding.h"
|
||||
#include "FD.h"
|
||||
#include "IM.h"
|
||||
#include "Priviledged.h"
|
||||
#include "Zicsr.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
@@ -113,6 +114,9 @@ bool simple_instruction_equals(InstructionType const& self, InstructionImpl cons
|
||||
M(FloatMemoryStore) \
|
||||
M(EnvironmentCall) \
|
||||
M(EnvironmentBreak) \
|
||||
M(MachineModeTrapReturn) \
|
||||
M(SupervisorModeTrapReturn) \
|
||||
M(WaitForInterrupt) \
|
||||
M(CSRInstruction) \
|
||||
M(CSRRegisterInstruction) \
|
||||
M(CSRImmediateInstruction) \
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2023, kleines Filmröllchen <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Priviledged.h"
|
||||
#include "IM.h"
|
||||
#include "Zicsr.h"
|
||||
|
||||
namespace Disassembly::RISCV64 {
|
||||
|
||||
NonnullOwnPtr<InstructionImpl> parse_system(u32 instruction)
|
||||
{
|
||||
auto raw_parts = RawIType::parse(instruction);
|
||||
if (raw_parts.funct3 != 0b000 && raw_parts.funct3 != 0b100)
|
||||
return parse_csr(raw_parts);
|
||||
|
||||
auto system_opcode = instruction >> 7;
|
||||
switch (system_opcode) {
|
||||
case 0b000000000000'00000'000'00000:
|
||||
return make<EnvironmentCall>();
|
||||
case 0b000000000001'00000'000'00000:
|
||||
return make<EnvironmentBreak>();
|
||||
case 0b0001000'00010'00000'000'00000:
|
||||
return make<SupervisorModeTrapReturn>();
|
||||
case 0b0011000'00010'00000'000'00000:
|
||||
return make<MachineModeTrapReturn>();
|
||||
case 0b0001000'00101'00000'000'00000:
|
||||
return make<WaitForInterrupt>();
|
||||
default:
|
||||
return make<UnknownInstruction>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2023, kleines Filmröllchen <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Instruction.h"
|
||||
|
||||
// Instructions from various priviledged extensions.
|
||||
namespace Disassembly::RISCV64 {
|
||||
|
||||
class SupervisorModeTrapReturn : public InstructionWithoutArguments {
|
||||
public:
|
||||
virtual ~SupervisorModeTrapReturn() = default;
|
||||
virtual String mnemonic() const override;
|
||||
virtual bool instruction_equals(InstructionImpl const&) const override;
|
||||
bool operator==(SupervisorModeTrapReturn const&) const = default;
|
||||
|
||||
SupervisorModeTrapReturn() = default;
|
||||
};
|
||||
|
||||
class MachineModeTrapReturn : public InstructionWithoutArguments {
|
||||
public:
|
||||
virtual ~MachineModeTrapReturn() = default;
|
||||
virtual String mnemonic() const override;
|
||||
virtual bool instruction_equals(InstructionImpl const&) const override;
|
||||
bool operator==(MachineModeTrapReturn const&) const = default;
|
||||
|
||||
MachineModeTrapReturn() = default;
|
||||
};
|
||||
|
||||
class WaitForInterrupt : public InstructionWithoutArguments {
|
||||
public:
|
||||
virtual ~WaitForInterrupt() = default;
|
||||
virtual String mnemonic() const override;
|
||||
virtual bool instruction_equals(InstructionImpl const&) const override;
|
||||
bool operator==(WaitForInterrupt const&) const = default;
|
||||
|
||||
WaitForInterrupt() = default;
|
||||
};
|
||||
|
||||
NonnullOwnPtr<InstructionImpl> parse_system(u32 instruction);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user