Skip to content

Commit

Permalink
modules/SceIpmi: Adding module and stub few functions.
Browse files Browse the repository at this point in the history
modules/module parent: Adding create vtable fonction.
  • Loading branch information
Macdu authored and bookmist committed Nov 4, 2024
1 parent 6f110b4 commit e78b375
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 0 deletions.
1 change: 1 addition & 0 deletions vita3k/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ set(SOURCE_LIST
SceHid/SceHid.cpp
SceHttp/SceHttp.cpp
SceIme/SceIme.cpp
SceIpmi/SceIpmi.cpp
SceIncomingDialog/SceIncomingDialog.cpp
SceIofilemgr/SceIofilemgr.cpp
SceJpeg/SceJpegUser.cpp
Expand Down
153 changes: 153 additions & 0 deletions vita3k/modules/SceIpmi/SceIpmi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Vita3K emulator project
// Copyright (C) 2024 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <module/module.h>

#include "modules/module_parent.h"

#include <util/tracy.h>

TRACY_MODULE_NAME(SceIpmi);

static Ptr<void> client_vtable = Ptr<void>();

EXPORT(int, _ZN4IPMI6Client10disconnectEv) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client11getUserDataEv) {
return UNIMPLEMENTED();
}

struct BufferInfo {
Ptr<void> pBuffer;
SceSize bufferSize;
SceSize bufferWrittenSize; // size written by method
};

EXPORT(int, _ZN4IPMI6Client12tryGetResultEjPiPvPmm, unsigned int a1, int *a2, void *a3, unsigned long *a4, unsigned long a5) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client12tryGetResultEjjPiPNS_10BufferInfoEj) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client13pollEventFlagEjjjPj) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client13waitEventFlagEjjjPjS1_) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client16invokeSyncMethodEjPKNS_8DataInfoEjPiPNS_10BufferInfoEj) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client16invokeSyncMethodEjPKvjPiPvPjj) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client17invokeAsyncMethodEjPKNS_8DataInfoEjPjPKNS0_12EventNotifeeE) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client17invokeAsyncMethodEjPKvjPiPKNS0_12EventNotifeeE) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client19terminateConnectionEv) {
return UNIMPLEMENTED();
}

// IPMI::Client::Config::estimateClientMemorySize()
EXPORT(int, _ZN4IPMI6Client6Config24estimateClientMemorySizeEv) {
TRACY_FUNC(_ZN4IPMI6Client6Config24estimateClientMemorySizeEv);
STUBBED("stubbed");
return 0x100;
}

// IPMI::Client::create(IPMI::Client**, IPMI::Client::Config const*, void*, void*)
EXPORT(int, _ZN4IPMI6Client6createEPPS0_PKNS0_6ConfigEPvS6_, Ptr<void> *client, void const *config, Ptr<void> user_data, Ptr<void> client_memory) {
TRACY_FUNC(_ZN4IPMI6Client6createEPPS0_PKNS0_6ConfigEPvS6_, client, config, user_data, client_memory);
if (!client_vtable) {
// initialize the vtable
client_vtable = create_vtable({
0x101C93F8, // destroy
0xA22C3E01, // connect
0xEC73331C, // disconnect
0xD484D36D, // terminateConnection
0x28BD5F19, // invokeSyncMethod
0x73C72FBB, // invokeSyncMethod
0xAFD10F3B, // invokeAsyncMethod
0x387AFA3F, // invokeAsyncMethod
0xF8C2B8BA, // tryGetResult
0x4EBB01A2, // tryGetResult
0x8FF23C3C, // pollEventFlag
0x45C32034, // waitEventFlag
0x004F48ED, // getUserData
0xA3E650B0, // getMsg
0x60EFADE7, // tryGetMsg
0xA5AA193C, // ~Client
},
emuenv.mem);
}

*client_memory.cast<Ptr<void>>().get(emuenv.mem) = client_vtable;
*client = client_memory;
STUBBED("Stubed");
return 0;
}

EXPORT(int, _ZN4IPMI6Client6getMsgEjPvPjjS2_) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client7connectEPKvjPi, void *client, void const *params, SceSize params_size, SceInt32 *error) {
TRACY_FUNC(_ZN4IPMI6Client7connectEPKvjPi, client, error);
*error = 0;
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client7destroyEv) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6Client9tryGetMsgEjPvPmm) {
return UNIMPLEMENTED();
}

EXPORT(int, _ZN4IPMI6ClientD1Ev) {
return UNIMPLEMENTED();
}

EXPORT(int, SceIpmi_296D44D4) {
return UNIMPLEMENTED();
}

EXPORT(int, SceIpmi_BC3A3031) {
return UNIMPLEMENTED();
}

EXPORT(int, SceIpmi_2C6DB642) {
return UNIMPLEMENTED();
}

EXPORT(int, SceIpmi_006EFA9D) {
return UNIMPLEMENTED();
}
1 change: 1 addition & 0 deletions vita3k/modules/include/modules/module_parent.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ bool load_sys_module_internal_with_arg(EmuEnvState &emuenv, SceUID thread_id, Sc

Address resolve_export(KernelState &kernel, uint32_t nid);
uint32_t resolve_nid(KernelState &kernel, Address addr);
Ptr<void> create_vtable(const std::vector<uint32_t> &nids, MemState &mem);

struct VarExport {
uint32_t nid;
Expand Down
21 changes: 21 additions & 0 deletions vita3k/modules/module_parent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ Address resolve_export(KernelState &kernel, uint32_t nid) {
return export_address->second;
}

Ptr<void> create_vtable(const std::vector<uint32_t> &nids, MemState &mem) {
// we need 4 bytes for the function pointer and 12 bytes for the syscall
const uint32_t vtable_size = nids.size() * 4 * sizeof(uint32_t);
Ptr<void> vtable = Ptr<void>(alloc(mem, vtable_size, "vtable"));
uint32_t *function_pointer = vtable.cast<uint32_t>().get(mem);
uint32_t *function_svc = function_pointer + nids.size();
uint32_t function_location = vtable.address() + nids.size() * sizeof(uint32_t);
for (uint32_t nid : nids) {
*function_pointer = function_location;
// encode svc call
function_svc[0] = 0xef000000; // svc #0 - Call our interrupt hook.
function_svc[1] = 0xe1a0f00e; // mov pc, lr - Return to the caller.
function_svc[2] = nid; // Our interrupt hook will read this.

function_pointer++;
function_svc += 3;
function_location += 3 * sizeof(uint32_t);
}
return vtable;
}

static void log_import_call(char emulation_level, uint32_t nid, SceUID thread_id, const std::unordered_set<uint32_t> &nid_blacklist, Address lr) {
if (!nid_blacklist.contains(nid)) {
const char *const name = import_name(nid);
Expand Down
19 changes: 19 additions & 0 deletions vita3k/nids/include/nids/nids.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,25 @@ NID(sceImeSetCaret, 0xD8342D2A)
NID(sceImeSetPreeditGeometry, 0x7B1EFAA5)
NID(sceImeSetText, 0xF3BD9A76)
NID(sceImeUpdate, 0x71D6898A)
// Library "SceIpmi" // Some nids are fake
NID(_ZN4IPMI6Client10disconnectEv, 0xEC73331C)
NID(_ZN4IPMI6Client11getUserDataEv, 0x004F48ED)
NID(_ZN4IPMI6Client12tryGetResultEjPiPvPmm, 0xF8C2B8BA)
NID(_ZN4IPMI6Client12tryGetResultEjjPiPNS_10BufferInfoEj, 0x4EBB01A2)
NID(_ZN4IPMI6Client13pollEventFlagEjjjPj, 0x8FF23C3C)
NID(_ZN4IPMI6Client13waitEventFlagEjjjPjS1_, 0x45C32034)
NID(_ZN4IPMI6Client16invokeSyncMethodEjPKNS_8DataInfoEjPiPNS_10BufferInfoEj, 0x73C72FBB)
NID(_ZN4IPMI6Client16invokeSyncMethodEjPKvjPiPvPjj, 0x28BD5F19)
NID(_ZN4IPMI6Client17invokeAsyncMethodEjPKNS_8DataInfoEjPjPKNS0_12EventNotifeeE, 0x387AFA3F)
NID(_ZN4IPMI6Client17invokeAsyncMethodEjPKvjPiPKNS0_12EventNotifeeE, 0xAFD10F3B)
NID(_ZN4IPMI6Client19terminateConnectionEv, 0xD484D36D)
NID(_ZN4IPMI6Client6Config24estimateClientMemorySizeEv, 0x4E255C31)
NID(_ZN4IPMI6Client6createEPPS0_PKNS0_6ConfigEPvS6_, 0xB282B430)
NID(_ZN4IPMI6Client6getMsgEjPvPjjS2_, 0xA3E650B0)
NID(_ZN4IPMI6Client7connectEPKvjPi, 0xA22C3E01)
NID(_ZN4IPMI6Client7destroyEv, 0x101C93F8)
NID(_ZN4IPMI6Client9tryGetMsgEjPvPmm, 0x60EFADE7)
NID(_ZN4IPMI6ClientD1Ev, 0xA5AA193C)
// Module "SceIncomingDialog"
// Library "SceIncomingDialog"
NID(sceIncomingDialogClose, 0x126BD15E)
Expand Down

0 comments on commit e78b375

Please sign in to comment.