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
30 changes: 29 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,37 @@ build_system_target_list() {

build_system_lib_list() {
local arch
local target
local lib
local libs=()

IFS=',' read -ra split_arches <<< "$PENGUIN_SYSTEM_ARCHES"
for arch in "${split_arches[@]}"; do
printf "libqemu-system-%s.so\n" "$arch"
target="$(penguin_system_arch_to_qemu_target "$arch")"
lib="libqemu-system-${target%-softmmu}.so"
if append_unique "$lib" "${libs[@]}"; then
libs+=("$lib")
fi
done

printf "%s\n" "${libs[@]}"
}

stage_system_lib_aliases() {
local arch
local target
local source
local alias

IFS=',' read -ra split_arches <<< "$PENGUIN_SYSTEM_ARCHES"
for arch in "${split_arches[@]}"; do
target="$(penguin_system_arch_to_qemu_target "$arch")"
source="build-system/libqemu-system-${target%-softmmu}.so"
alias="build-system/libqemu-system-${arch}.so"

if [ "$source" != "$alias" ]; then
cp -f "$source" "$alias"
fi
done
}

Expand All @@ -148,6 +175,7 @@ configure_build_dir build-system \

mapfile -t system_libs < <(build_system_lib_list)
ninja -C build-system "${system_libs[@]}" qemu-img
stage_system_lib_aliases
python3 scripts/penguin-cffi-gen.py \
--mode system \
--build-dir build-system \
Expand Down
4 changes: 4 additions & 0 deletions include/system/penguin.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ typedef void (*penguin_mmio_write_cb_t)(uint64_t addr, uint64_t data,

void set_penguin_guest_hypercall_callback(penguin_guest_hypercall_cb_t cb,
void *opaque);
void penguin_register_guest_hypercall(uint64_t nr);
void penguin_unregister_guest_hypercall(uint64_t nr);
void penguin_clear_guest_hypercalls(void);
bool penguin_guest_hypercall_registered(uint64_t nr);
void set_kvm_penguin_hypercall_callback(kvm_penguin_hypercall_cb_t cb);

bool penguin_handle_guest_hypercall(CPUState *cs, uint64_t nr,
Expand Down
4 changes: 4 additions & 0 deletions scripts/penguin-cffi-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@

void set_penguin_guest_hypercall_callback(penguin_guest_hypercall_cb_t cb,
void *opaque);
void penguin_register_guest_hypercall(uint64_t nr);
void penguin_unregister_guest_hypercall(uint64_t nr);
void penguin_clear_guest_hypercalls(void);
bool penguin_guest_hypercall_registered(uint64_t nr);
void set_kvm_penguin_hypercall_callback(kvm_penguin_hypercall_cb_t cb);
void set_kvm_penguin_after_guest_init_callback(
kvm_penguin_after_guest_init_cb_t cb, void *opaque);
Expand Down
51 changes: 50 additions & 1 deletion system/penguin.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,54 @@ typedef struct PenguinMmioRegion {
static penguin_guest_hypercall_cb_t penguin_guest_hypercall_cb;
static void *penguin_guest_hypercall_opaque;
static kvm_penguin_hypercall_cb_t kvm_penguin_hypercall_cb;
static GHashTable *penguin_guest_hypercall_numbers;

static void penguin_guest_hypercalls_init(void)
{
if (!penguin_guest_hypercall_numbers) {
penguin_guest_hypercall_numbers = g_hash_table_new_full(g_int64_hash,
g_int64_equal,
g_free, NULL);
}
}

void __attribute__((visibility("default")))
penguin_register_guest_hypercall(uint64_t nr)
{
uint64_t *key;

penguin_guest_hypercalls_init();
if (g_hash_table_contains(penguin_guest_hypercall_numbers, &nr)) {
return;
}

key = g_new(uint64_t, 1);
*key = nr;
g_hash_table_add(penguin_guest_hypercall_numbers, key);
}

void __attribute__((visibility("default")))
penguin_unregister_guest_hypercall(uint64_t nr)
{
if (penguin_guest_hypercall_numbers) {
g_hash_table_remove(penguin_guest_hypercall_numbers, &nr);
}
}

void __attribute__((visibility("default")))
penguin_clear_guest_hypercalls(void)
{
if (penguin_guest_hypercall_numbers) {
g_hash_table_remove_all(penguin_guest_hypercall_numbers);
}
}

bool __attribute__((visibility("default")))
penguin_guest_hypercall_registered(uint64_t nr)
{
return penguin_guest_hypercall_numbers &&
g_hash_table_contains(penguin_guest_hypercall_numbers, &nr);
}

void __attribute__((visibility("default")))
set_penguin_guest_hypercall_callback(penguin_guest_hypercall_cb_t cb,
Expand All @@ -36,7 +84,8 @@ bool penguin_handle_guest_hypercall(CPUState *cs, uint64_t nr,
uint64_t a4, uint64_t a5,
uint64_t *ret)
{
if (penguin_guest_hypercall_cb) {
if (penguin_guest_hypercall_cb &&
penguin_guest_hypercall_registered(nr)) {
return penguin_guest_hypercall_cb(cs, nr, a0, a1, a2, a3, a4, a5,
ret,
penguin_guest_hypercall_opaque) == 0;
Expand Down
2 changes: 1 addition & 1 deletion target/arm/tcg/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ uint64_t HELPER(penguin_guest_hypercall)(CPUARMState *env, uint64_t nr,
if (penguin_handle_guest_hypercall(cs, nr, a0, a1, a2, a3, a4, 0, &ret)) {
return ret;
}
return 0;
return a0;
}

uint64_t HELPER(neon_tbl)(CPUARMState *env, uint32_t desc,
Expand Down
2 changes: 1 addition & 1 deletion target/loongarch/tcg/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ target_ulong helper_penguin_guest_hypercall(CPULoongArchState *env,
if (penguin_handle_guest_hypercall(cs, nr, a0, a1, a2, a3, a4, 0, &ret)) {
return ret;
}
return 0;
return a0;
}

target_ulong helper_bitrev_w(target_ulong rj)
Expand Down
2 changes: 1 addition & 1 deletion target/mips/tcg/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ target_ulong helper_penguin_guest_hypercall(CPUMIPSState *env, target_ulong nr,
if (penguin_handle_guest_hypercall(cs, nr, a0, a1, a2, a3, a4, 0, &ret)) {
return ret;
}
return 0;
return nr;
}

target_ulong helper_rotx(target_ulong rs, uint32_t shift, uint32_t shiftx,
Expand Down
2 changes: 1 addition & 1 deletion target/ppc/misc_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ target_ulong helper_penguin_guest_hypercall(CPUPPCState *env, target_ulong nr,
if (penguin_handle_guest_hypercall(cs, nr, a0, a1, a2, a3, a4, 0, &ret)) {
return ret;
}
return 0;
return a0;
}

void helper_spr_core_write_generic(CPUPPCState *env, uint32_t sprn,
Expand Down
2 changes: 1 addition & 1 deletion target/riscv/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ target_ulong helper_penguin_guest_hypercall(CPURISCVState *env, target_ulong nr,
if (penguin_handle_guest_hypercall(cs, nr, a0, a1, a2, a3, a4, 0, &ret)) {
return ret;
}
return 0;
return a0;
}

target_ulong helper_csrr(CPURISCVState *env, int csr)
Expand Down
Loading