Skip to content

Commit

Permalink
Re-organize and provide .pc file for packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Nov 25, 2023
1 parent 9861c1a commit f4460b4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
6 changes: 3 additions & 3 deletions examples/package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.5)
project(example LANGUAGES CXX)

find_package(PkgConfig)
pkg_check_modules(libriscv REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libriscv REQUIRED IMPORTED_TARGET libriscv)

add_executable(example example.cpp)
target_link_libraries(example riscv)
target_link_libraries(example PkgConfig::libriscv)
16 changes: 15 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ if (RISCV_BINARY_TRANSLATION)
list(APPEND SOURCES libriscv/tr_compiler.cpp)
endif()
endif()
if (RISCV_SUPERVISOR)
list(APPEND SOURCES
libriscv/supervisor/supervisor.cpp
)
endif()

configure_file(libriscv_settings.h.in ${CMAKE_CURRENT_BINARY_DIR}/libriscv_settings.h)
configure_file(libriscv.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libriscv.pc)

add_library(riscv ${SOURCES})
target_compile_features(riscv PUBLIC cxx_std_20)
Expand Down Expand Up @@ -193,12 +199,16 @@ if (${CMAKE_PROJECT_NAME} STREQUAL "libriscv")
libriscv/rvc.hpp
libriscv/rvfd.hpp
libriscv/rsp_server.hpp
libriscv/supervisor.hpp
libriscv/threads.hpp
libriscv/types.hpp

DESTINATION include/${PROJECT_NAME}
)
install(FILES
libriscv/supervisor/supervisor.hpp

DESTINATION include/${PROJECT_NAME}/supervisor
)
install(FILES
libriscv/linux/rsp_server.hpp

Expand All @@ -217,4 +227,8 @@ if (${CMAKE_PROJECT_NAME} STREQUAL "libriscv")

DESTINATION include/${PROJECT_NAME}/util
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libriscv.pc
DESTINATION lib/pkgconfig
)
endif()
6 changes: 6 additions & 0 deletions lib/libriscv.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Name: @CMAKE_PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
URL: https://github.com/fwsGonzo/libriscv
Version: @PROJECT_VERSION@
Cflags: -I/usr/include
Libs: -L/usr/lib -lriscv
4 changes: 3 additions & 1 deletion lib/libriscv/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "common.hpp"
#include "page.hpp"
#include "registers.hpp"
#include "supervisor.hpp"
#ifdef RISCV_SUPERVISOR
#include "supervisor/supervisor.hpp"
#endif
#ifdef RISCV_EXT_ATOMICS
#include "rva.hpp"
#endif
Expand Down
33 changes: 33 additions & 0 deletions lib/libriscv/supervisor/supervisor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "supervisor.hpp"

#include "../machine.hpp"

namespace riscv
{
template <int W>
bool Supervisor<W>::is_privilege_machine() const noexcept {
return false;
}
template <int W>
bool Supervisor<W>::is_privilege_supervisor() const noexcept {
return false;
}

template <int W>
void Supervisor<W>::mret()
{
if (!is_privilege_machine())
throw MachineException(ILLEGAL_OPERATION, "MRET requires machine privilege level");
}

template <int W>
void Supervisor<W>::sret()
{
if (!is_privilege_supervisor())
throw MachineException(ILLEGAL_OPERATION, "SRET requires supervisor privilege level");

}

template struct Supervisor<4>;
template struct Supervisor<8>;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once
#include "types.hpp"
#include "../types.hpp"

namespace riscv
{
template <int W>
struct Supervisor {
using address_t = address_type<W>;

void sret() {}
void sret();
void mret();
bool is_privilege_machine() const noexcept;
bool is_privilege_supervisor() const noexcept;

address_t satp = 0x0;
address_t mie;
Expand Down

0 comments on commit f4460b4

Please sign in to comment.