mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-16 03:57:01 +02:00
backwards relocs
Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
8cfcfaa44c
commit
4efcad3ddd
2 changed files with 20 additions and 6 deletions
11
externals/powah/powah_emit.hpp
vendored
11
externals/powah/powah_emit.hpp
vendored
|
|
@ -138,14 +138,15 @@ struct Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyRelocs() {
|
void ApplyRelocs() {
|
||||||
for (auto const [index, info] : relocs) {
|
for (auto const &[index, info] : relocs) {
|
||||||
assert(labels[index] != 0); //label must have an addr
|
//assert(labels[index] != 0); //label must have an addr
|
||||||
|
int32_t rel = (int32_t)labels[index] - (int32_t)info.offset;
|
||||||
switch (info.kind) {
|
switch (info.kind) {
|
||||||
case RelocKind::FormB:
|
case RelocKind::FormB:
|
||||||
base[info.offset] |= bitExt(labels[index] - info.offset, 16, 14);
|
base[info.offset] |= bitExt(rel, 16, 14);
|
||||||
break;
|
break;
|
||||||
case RelocKind::FormI:
|
case RelocKind::FormI:
|
||||||
base[info.offset] |= bitExt(labels[index] - info.offset, 6, 24);
|
base[info.offset] |= bitExt(rel, 6, 24);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +177,7 @@ struct Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t bitExt(uint32_t value, uint32_t offs, uint32_t n) {
|
uint32_t bitExt(uint32_t value, uint32_t offs, uint32_t n) {
|
||||||
uint32_t mask = (1UL << (n + 1)) - 1;
|
uint32_t mask = (1UL << n) - 1;
|
||||||
return (value & mask) << (32 - (n + offs));
|
return (value & mask) << (32 - (n + offs));
|
||||||
}
|
}
|
||||||
void emit_XO(uint32_t op, GPR const rt, GPR const ra, GPR const rb, bool oe, bool rc) {
|
void emit_XO(uint32_t op, GPR const rt, GPR const ra, GPR const rb, bool oe, bool rc) {
|
||||||
|
|
|
||||||
15
externals/powah/tests.cpp
vendored
15
externals/powah/tests.cpp
vendored
|
|
@ -141,7 +141,19 @@ TEST_CASE("ppc64: rotldi", "[ppc64]") {
|
||||||
REQUIRE(data[12] == EB32(0x7823837c));
|
REQUIRE(data[12] == EB32(0x7823837c));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1 //&& defined(ARCHITECTURE_ppc64)
|
TEST_CASE("ppc64: branch-backwards", "[ppc64]") {
|
||||||
|
std::vector<uint32_t> data(64);
|
||||||
|
powah::Context ctx(data.data(), data.size());
|
||||||
|
powah::Label l_3 = ctx.DefineLabel();
|
||||||
|
ctx.LABEL(l_3);
|
||||||
|
ctx.ADD(powah::R1, powah::R2, powah::R3);
|
||||||
|
ctx.B(l_3);
|
||||||
|
ctx.ApplyRelocs();
|
||||||
|
REQUIRE(data[0] == EB32(0x141a227c));
|
||||||
|
REQUIRE(data[1] == EB32(0xfcffff4b));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(ARCHITECTURE_ppc64)
|
||||||
/*
|
/*
|
||||||
0: d619637c mullw 3, 3, 3
|
0: d619637c mullw 3, 3, 3
|
||||||
4: 20006378 clrldi 3, 3, 32
|
4: 20006378 clrldi 3, 3, 32
|
||||||
|
|
@ -221,6 +233,7 @@ TEST_CASE("ppc64: live-exec xoralu", "[ppc64]") {
|
||||||
};
|
};
|
||||||
auto* fn = (int (*)(int, int, int))data;
|
auto* fn = (int (*)(int, int, int))data;
|
||||||
REQUIRE(fn(0, 1, 2) == orig(0, 1, 2));
|
REQUIRE(fn(0, 1, 2) == orig(0, 1, 2));
|
||||||
|
REQUIRE(fn(6456, 4564, 4564561) == orig(6456, 4564, 4564561));
|
||||||
|
|
||||||
munmap((void*)data, 4096);
|
munmap((void*)data, 4096);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue