Skip to content

Commit

Permalink
applies clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
eyck committed Oct 29, 2023
1 parent 99eea61 commit 95e3ccb
Show file tree
Hide file tree
Showing 44 changed files with 1,547 additions and 1,627 deletions.
13 changes: 6 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
Language: Cpp
# BasedOnStyle: LLVM
# should be in line with IndentWidth
Expand All @@ -13,8 +12,8 @@ AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
Expand All @@ -39,8 +38,8 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 140
CommentPragmas: '^( IWYU pragma:| @suppress)'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 4
Expand Down Expand Up @@ -76,13 +75,13 @@ PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
Expand Down
7 changes: 3 additions & 4 deletions src/iss/arch/instruction_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ template <typename ARCH> struct instruction_decoder {

static std::unique_ptr<instruction_decoder<ARCH>> create();

template<typename T>
unsigned decode_instruction(T);
template <typename T> unsigned decode_instruction(T);
};
}
}
} // namespace arch
} // namespace iss

#endif /* _ISS_ARCH_INSTRUCTION_DECODER_H_ */
4 changes: 2 additions & 2 deletions src/iss/arch/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace iss {
namespace arch {

template <typename ARCH> struct traits {};
}
}
} // namespace arch
} // namespace iss

#endif /* _TRAITS_H_ */
29 changes: 14 additions & 15 deletions src/iss/arch_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#ifndef _ARCH_IF_H_
#define _ARCH_IF_H_

#include <dbt_rise_common.h>
#include "vm_types.h"
#include "instrumentation_if.h"
#include "vm_types.h"
#include <dbt_rise_common.h>

#include <algorithm>
#include <iomanip>
Expand Down Expand Up @@ -112,15 +112,13 @@ class arch_if {
*
* @return pointer to the registers
*/
virtual uint8_t *get_regs_base_ptr() = 0;
virtual uint8_t* get_regs_base_ptr() = 0;
/**
* whether address translation is needed
*
* @return true if a call to the address translation function is needed
*/
inline bool has_mmu(){
return mmu;
}
inline bool has_mmu() { return mmu; }
/**
* read from addresses
*
Expand All @@ -130,7 +128,7 @@ class arch_if {
* @param data pointer to the memory to read into
* @return success or failure of access
*/
inline iss::status read(const addr_t &addr, const unsigned length, uint8_t *const data){
inline iss::status read(const addr_t& addr, const unsigned length, uint8_t* const data) {
return read(addr.type, addr.access, addr.space, addr.val, length, data);
}
/**
Expand All @@ -142,8 +140,8 @@ class arch_if {
* @param data pointer to the memory to read into
* @return success or failure of access
*/
virtual iss::status read(const address_type type, const access_type access, const uint32_t space,
const uint64_t addr, const unsigned length, uint8_t *const data) = 0;
virtual iss::status read(const address_type type, const access_type access, const uint32_t space, const uint64_t addr,
const unsigned length, uint8_t* const data) = 0;
/**
* write to addresses
*
Expand All @@ -153,7 +151,7 @@ class arch_if {
* @param data pointer to the memory to write from
* @return success or failure of access
*/
inline iss::status write(const addr_t &addr, const unsigned length, const uint8_t *const data){
inline iss::status write(const addr_t& addr, const unsigned length, const uint8_t* const data) {
return write(addr.type, addr.access, addr.space, addr.val, length, data);
}
/**
Expand All @@ -165,9 +163,9 @@ class arch_if {
* @param data pointer to the memory to write from
* @return success or failure of access
*/
virtual iss::status write(const address_type type, const access_type access, const uint32_t space,
const uint64_t addr, const unsigned length, const uint8_t *const data) = 0;
/**
virtual iss::status write(const address_type type, const access_type access, const uint32_t space, const uint64_t addr,
const unsigned length, const uint8_t* const data) = 0;
/**
* vm encountered a trap (exception, interrupt), process accordingly in core
*
* @param flags trap flags
Expand Down Expand Up @@ -210,10 +208,11 @@ class arch_if {
*
* @return non-owning pointer to the instrumentation interface of the architecture or nullptr
*/
virtual instrumentation_if *get_instrumentation_if() { return nullptr; };
virtual instrumentation_if* get_instrumentation_if() { return nullptr; };

private:
bool mmu{false};
};
}
} // namespace iss

#endif /* _ARCH_IF_H_ */
60 changes: 30 additions & 30 deletions src/iss/asmjit/jit_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@

#include <iss/log_categories.h>


#include "jit_helper.h"
#include <array>
#include <exception>
#include <fmt/format.h>
#include <iostream>
#include <memory>
#include "jit_helper.h"
#include <sys/mman.h>
#include <exception>
#include <fmt/format.h>




using namespace asmjit;
using namespace logging;
namespace iss{
namespace iss {
namespace asmjit {
//according to https://github.com/LuaDist/tcc/blob/255ba0e8e34f999ee840407ce4e9c444dfd312bf/libtcc.c#L400
int set_pages_executable(void *ptr, unsigned long length){
// according to https://github.com/LuaDist/tcc/blob/255ba0e8e34f999ee840407ce4e9c444dfd312bf/libtcc.c#L400
int set_pages_executable(void* ptr, unsigned long length) {
#ifdef _WIN32
unsigned long old_protect;
return VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
Expand All @@ -59,17 +55,18 @@ int set_pages_executable(void *ptr, unsigned long length){
start = (unsigned long)ptr & ~(PAGESIZE - 1);
end = (unsigned long)ptr + length;
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
return mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
#endif
return mprotect((void*)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
#endif
};
class MyErrorHandler : public ErrorHandler {
public:
void handleError(Error err, const char* message, BaseEmitter* origin) override {
throw std::runtime_error(fmt::format("AsmJit error: {}", message));
}
void handleError(Error err, const char* message, BaseEmitter* origin) override {
throw std::runtime_error(fmt::format("AsmJit error: {}", message));
}
};

translation_block getPointerToFunction(unsigned cluster_id, uint64_t phys_addr, std::function<void(jit_holder&)>& generator, bool dumpEnabled) {
translation_block getPointerToFunction(unsigned cluster_id, uint64_t phys_addr, std::function<void(jit_holder&)>& generator,
bool dumpEnabled) {
#ifndef NDEBUG
LOG(TRACE) << "Compiling and executing code for 0x" << std::hex << phys_addr << std::dec;
#endif
Expand All @@ -78,36 +75,39 @@ translation_block getPointerToFunction(unsigned cluster_id, uint64_t phys_addr,
FileLogger logger(stdout);
MyErrorHandler myErrorHandler;
code.init(rt.environment(), rt.cpuFeatures());
if(dumpEnabled){
if(dumpEnabled) {
code.setLogger(&logger);
}
code.setErrorHandler(&myErrorHandler);
x86::Compiler cc(&code);
FuncNode* funcNode = cc.addFunc(FuncSignatureT<uint64_t, uint8_t*, void*, void *>());
FuncNode* funcNode = cc.addFunc(FuncSignatureT<uint64_t, uint8_t*, void*, void*>());
x86::Gp regs_base_ptr = cc.newUIntPtr("regs_base_ptr");
x86::Gp arch_if_ptr = cc.newIntPtr("arch_if_ptr");
x86::Gp vm_if_ptr = cc.newIntPtr("vm_if_ptr");
funcNode->setArg(0,regs_base_ptr);
funcNode->setArg(1,arch_if_ptr);
funcNode->setArg(2,vm_if_ptr);
funcNode->setArg(0, regs_base_ptr);
funcNode->setArg(1, arch_if_ptr);
funcNode->setArg(2, vm_if_ptr);
Label trap_entry = cc.newNamedLabel("\ntrap_entry");
jit_holder jh{cc,regs_base_ptr, arch_if_ptr, vm_if_ptr, trap_entry };
jit_holder jh{cc, regs_base_ptr, arch_if_ptr, vm_if_ptr, trap_entry};
generator(jh);

cc.endFunc();
cc.endFunc();
cc.finalize();
code.flatten();
//allocate memory and make it executable
// allocate memory and make it executable
auto size = code.codeSize();
auto* fmem = malloc(size);
int err = code.relocateToBase(uintptr_t(fmem));
if(err) throw std::runtime_error("could not relocate compiled code");
if(err)
throw std::runtime_error("could not relocate compiled code");
err = code.copyFlattenedData(fmem, size);
if(err) throw std::runtime_error("could not copy compiled code");
if(err)
throw std::runtime_error("could not copy compiled code");
err = set_pages_executable(fmem, size);
if(err) throw std::runtime_error("could not set memory as executable");
//abort();
if(err)
throw std::runtime_error("could not set memory as executable");
// abort();
return translation_block(fmem, {nullptr, nullptr}, fmem);
}
}
}
} // namespace asmjit
} // namespace iss
56 changes: 30 additions & 26 deletions src/iss/asmjit/jit_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,60 @@
#include <asmjit/asmjit.h>
#include <functional>

namespace iss{
namespace asmjit{
namespace iss {
namespace asmjit {

struct alignas(4 * sizeof(void *)) translation_block {
struct alignas(4 * sizeof(void*)) translation_block {
uintptr_t f_ptr = 0;
std::array<translation_block *, 2> cont;
std::array<translation_block*, 2> cont;
void* f_mem;

explicit translation_block(void* f_ptr_, std::array<translation_block *, 2> cont_, void* mem_ptr = nullptr )
explicit translation_block(void* f_ptr_, std::array<translation_block*, 2> cont_, void* mem_ptr = nullptr)
: f_ptr(reinterpret_cast<uintptr_t>(f_ptr_))
, cont(cont_)
, f_mem(mem_ptr)
{}
, f_mem(mem_ptr) {}

translation_block() = delete;

translation_block(translation_block const&) = delete;

translation_block& operator=(translation_block const& other) = delete;

translation_block(translation_block && o){
f_ptr=o.f_ptr,o.f_ptr=0;
cont=o.cont; o.cont[0]=nullptr; o.cont[1]=nullptr;
f_mem=o.f_mem; o.f_mem=nullptr;
translation_block(translation_block&& o) {
f_ptr = o.f_ptr, o.f_ptr = 0;
cont = o.cont;
o.cont[0] = nullptr;
o.cont[1] = nullptr;
f_mem = o.f_mem;
o.f_mem = nullptr;
}

translation_block& operator=(translation_block && o){
f_ptr=o.f_ptr,o.f_ptr=0;
cont=o.cont; o.cont[0]=nullptr; o.cont[1]=nullptr;
f_mem=o.f_mem; o.f_mem=nullptr;
translation_block& operator=(translation_block&& o) {
f_ptr = o.f_ptr, o.f_ptr = 0;
cont = o.cont;
o.cont[0] = nullptr;
o.cont[1] = nullptr;
f_mem = o.f_mem;
o.f_mem = nullptr;
return *this;
}

~translation_block(){
free(f_mem);
}
~translation_block() { free(f_mem); }
};

struct jit_holder{
struct jit_holder {
::asmjit::x86::Compiler& cc;
::asmjit::x86::Gp& regs_base_ptr ;
::asmjit::x86::Gp& arch_if_ptr ;
::asmjit::x86::Gp& regs_base_ptr;
::asmjit::x86::Gp& arch_if_ptr;
::asmjit::x86::Gp& vm_if_ptr;
::asmjit::Label trap_entry;
::asmjit::x86::Gp trap_state;
::asmjit::x86::Gp pc;
::asmjit::x86::Gp next_pc;
};
translation_block getPointerToFunction(unsigned cluster_id, uint64_t phys_addr, std::function<void(jit_holder&)>& generator, bool dumpEnabled);
int set_pages_executable(void *ptr, unsigned long length);
}//namespace asmjit
}//namespace iss
#endif //ISS_ASMJIT_JIT__HELPER_H
translation_block getPointerToFunction(unsigned cluster_id, uint64_t phys_addr, std::function<void(jit_holder&)>& generator,
bool dumpEnabled);
int set_pages_executable(void* ptr, unsigned long length);
} // namespace asmjit
} // namespace iss
#endif // ISS_ASMJIT_JIT__HELPER_H
Loading

0 comments on commit 95e3ccb

Please sign in to comment.