Skip to content

Commit

Permalink
vsh
Browse files Browse the repository at this point in the history
  • Loading branch information
Zangetsu38 committed Oct 30, 2024
1 parent f978c94 commit e73732a
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 25 deletions.
5 changes: 3 additions & 2 deletions vita3k/kernel/src/load_self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,9 @@ SceUID load_self(KernelState &kernel, MemState &mem, const void *self, const std
unsigned long dest_bytes = seg_header.p_filesz;
const uint8_t *const compressed_segment_bytes = self_bytes + seg_infos[seg_index].offset;

int res = mz_uncompress(seg_ptr.get(mem), &dest_bytes, compressed_segment_bytes, static_cast<mz_ulong>(seg_infos[seg_index].length));
assert(res == MZ_OK);
int res = MZ_OK;
if (seg_infos[seg_index].length > 0)
res = mz_uncompress(seg_ptr.get(mem), &dest_bytes, compressed_segment_bytes, static_cast<mz_ulong>(seg_infos[seg_index].length));
} else {
memcpy(seg_ptr.get(mem), seg_bytes, seg_header.p_filesz);
}
Expand Down
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
93 changes: 84 additions & 9 deletions vita3k/modules/SceAppMgr/SceSharedFb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,108 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <module/module.h>
#include "../SceDisplay/SceDisplay.h"

EXPORT(int, _sceSharedFbOpen) {
return UNIMPLEMENTED();
#include <gxm/types.h>

#include <kernel/state.h>


#include <modules/module_parent.h>

typedef struct SceSharedFbInfo { // size is 0x58
Ptr<void> base1; // cdram base
int memsize;
Ptr<void> base2; // cdram base
int unk_0C;
Ptr<void> unk_10;
int unk_14;
int unk_18;
int unk_1C;
int unk_20;
int pitch; // 960
int width; // 960
int height; // 544
SceGxmColorFormat color_format; // SCE_GXM_COLOR_FORMAT_U8U8U8U8_ABGR
int curbuf;
int unk_38;
int unk_3C;
int unk_40;
int unk_44;
int vsync;
int unk_4C;
int unk_50;
int unk_54;
} SceSharedFbInfo;

struct SharedFbState {
SceSharedFbInfo info;
};

LIBRARY_INIT(SceSharedFb) {
emuenv.kernel.obj_store.create<SharedFbState>();
}

EXPORT(int, sceSharedFbBegin) {
return UNIMPLEMENTED();
DECL_EXPORT(int, sceSharedFbCreate, int smth);

EXPORT(int, _sceSharedFbOpen, int smth) {
STUBBED("sceSharedFbCreate");
return CALL_EXPORT(sceSharedFbCreate, smth);
}

EXPORT(int, sceSharedFbBegin, int id, SceSharedFbInfo *info) {
SharedFbState *state = emuenv.kernel.obj_store.get<SharedFbState>();
state->info.curbuf = 1;
*info = state->info;
return 0;
}

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

EXPORT(int, sceSharedFbCreate) {
return UNIMPLEMENTED();
EXPORT(int, sceSharedFbCreate, int smth) {
SharedFbState *state = emuenv.kernel.obj_store.get<SharedFbState>();
if (state->info.memsize == 0) {
// enough memory for 2 956x544 buffers
constexpr uint32_t alloc_size = 4 * 1024 * 512 * 2;
Ptr<uint8_t> data = Ptr<uint8_t>(alloc(emuenv.mem, alloc_size, "sharedFB"));
state->info = SceSharedFbInfo{
.base1 = data,
.memsize = alloc_size,
.base2 = data + alloc_size / 2,
.pitch = 960,
.width = 960,
.height = 544,
.color_format = SCE_GXM_COLOR_FORMAT_U8U8U8U8_ABGR,
.curbuf = 1,
};
}
return 1;
}

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

EXPORT(int, sceSharedFbEnd) {
return UNIMPLEMENTED();
SharedFbState *state = emuenv.kernel.obj_store.get<SharedFbState>();
Ptr<void> data = (state->info.curbuf == 0) ? state->info.base2 : state->info.base1;
// tell the display a new buffer is ready
SceDisplayFrameBuf frame_buf{
.size = sizeof(SceDisplayFrameBuf),
.base = data,
.pitch = 960,
.width = 960,
.height = 544
};
return CALL_EXPORT(_sceDisplaySetFrameBuf, &frame_buf, SCE_DISPLAY_SETBUF_NEXTFRAME, nullptr);
}

EXPORT(int, sceSharedFbGetInfo) {
return UNIMPLEMENTED();
EXPORT(int, sceSharedFbGetInfo, int id, SceSharedFbInfo *info) {
SharedFbState *state = emuenv.kernel.obj_store.get<SharedFbState>();
*info = state->info;
return 0;
}

EXPORT(int, sceSharedFbGetRenderingInfo) {
Expand Down
1 change: 1 addition & 0 deletions vita3k/modules/SceDisplay/SceDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ struct SceDisplayFrameBuf2 : public SceDisplayFrameBuf {

DECL_EXPORT(SceInt32, _sceDisplayGetFrameBuf, SceDisplayFrameBuf *pFrameBuf, SceDisplaySetBufSync sync, uint32_t *pFrameBuf_size);
DECL_EXPORT(SceInt32, _sceDisplaySetFrameBuf, const SceDisplayFrameBuf *pFrameBuf, SceDisplaySetBufSync sync, uint32_t *pFrameBuf_size);
DECL_EXPORT(SceInt32, sceDisplayRegisterVblankStartCallback, SceUID uid);
DECL_EXPORT(int, _sceDisplayGetMaximumFrameBufResolution, int *width, int *height);
16 changes: 15 additions & 1 deletion vita3k/modules/SceDriverUser/SceAppMgrUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,22 @@ EXPORT(int, sceAppMgrGetCurrentBgmState) {
return UNIMPLEMENTED();
}

EXPORT(int, sceAppMgrGetCurrentBgmState2) {
struct BgmState {
uint32_t unk_0;
uint32_t unk2;
int unk3;
int unk4;
int unk5;
int unk6;
int unk7;
int unk8;
};

EXPORT(int, sceAppMgrGetCurrentBgmState2, BgmState *state) {
TRACY_FUNC(sceAppMgrGetCurrentBgmState2);
memset(state, 0, sizeof(BgmState));
state->unk_0 = 130;
// state->unk2 = 130;
return UNIMPLEMENTED();
}

Expand Down
5 changes: 3 additions & 2 deletions vita3k/modules/SceDriverUser/SceErrorUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

#include <module/module.h>

EXPORT(int, sceErrorGetExternalString) {
return UNIMPLEMENTED();
EXPORT(int, sceErrorGetExternalString, char *result, int err) {
sprintf(result, "0x%08X", err);
return 0;
}

EXPORT(int, sceErrorHistoryClearError) {
Expand Down
6 changes: 3 additions & 3 deletions vita3k/modules/SceKernelModulemgr/SceModulemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ EXPORT(SceUID, _sceKernelLoadStartModule, const char *moduleFileName, SceSize ar
return kernel_start_module(emuenv, module_id, args, argp, pRes);
}

EXPORT(int, _sceKernelOpenModule) {
TRACY_FUNC(_sceKernelOpenModule);
return UNIMPLEMENTED();
EXPORT(SceUID, _sceKernelOpenModule, const char *moduleFileName, SceSize args, const Ptr<void> argp, SceUInt32 flags, const SceKernelLMOption *pOpt, int *pRes) {
TRACY_FUNC(_sceKernelOpenModule, moduleFileName, args, argp, flags, pOpt, pRes);
return CALL_EXPORT(_sceKernelLoadStartModule, moduleFileName, args, argp, flags, pOpt, pRes);
}

EXPORT(int, _sceKernelStartModule, SceUID uid, SceSize args, Ptr<const void> argp, SceUInt32 flags, const SceKernelStartModuleOpt *pOpt, int *pRes) {
Expand Down
2 changes: 1 addition & 1 deletion vita3k/modules/SceKernelThreadMgr/SceThreadmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ EXPORT(SceUID, sceKernelCreateCallback, char *name, SceUInt32 attr, Ptr<SceKerne

EXPORT(int, sceKernelCreateThreadForUser, const char *name, SceKernelThreadEntry entry, int init_priority, SceKernelCreateThread_opt *options) {
TRACY_FUNC(sceKernelCreateThreadForUser, name, entry, init_priority, options);
if (options->cpu_affinity_mask & ~SCE_KERNEL_CPU_MASK_USER_ALL) {
if (options->cpu_affinity_mask & ~SCE_KERNEL_CPU_MASK_USER_ALL | 0x80000) {
return RET_ERROR(SCE_KERNEL_ERROR_INVALID_CPU_AFFINITY);
}

Expand Down
6 changes: 3 additions & 3 deletions vita3k/modules/SceLibKernel/SceLibKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,9 @@ EXPORT(SceInt32, sceKernelLockWriteRWLockCB, SceUID lock_id, SceUInt32 *timeout)
return CALL_EXPORT(_sceKernelLockWriteRWLockCB, lock_id, timeout);
}

EXPORT(int, sceKernelOpenModule) {
TRACY_FUNC(sceKernelOpenModule);
return UNIMPLEMENTED();
EXPORT(SceUID, sceKernelOpenModule, const char *moduleFileName, SceSize args, const Ptr<void> argp, SceUInt32 flags, const SceKernelLMOption *pOpt, int *pRes) {
TRACY_FUNC(sceKernelOpenModule, moduleFileName, args, argp, flags, pOpt, pRes);
return CALL_EXPORT(_sceKernelLoadStartModule, moduleFileName, args, argp, flags, pOpt, pRes);
}

EXPORT(int, sceKernelPMonThreadGetCounter) {
Expand Down
9 changes: 6 additions & 3 deletions vita3k/modules/SceVshBridge/SceVshBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <module/module.h>

#include "../SceDisplay/SceDisplay.h"

EXPORT(int, _vshAppMgrAcInstGetAcdirParam) {
return UNIMPLEMENTED();
}
Expand Down Expand Up @@ -421,8 +423,8 @@ EXPORT(int, vshCtrlUnregisterNotifyCallBack) {
return UNIMPLEMENTED();
}

EXPORT(int, vshDisplayRegisterFrameBufCallback) {
return UNIMPLEMENTED();
EXPORT(SceInt32, vshDisplayRegisterFrameBufCallback, SceUID uid) {
return CALL_EXPORT(sceDisplayRegisterVblankStartCallback, uid);
}

EXPORT(int, vshDisplaySetInvertColors) {
Expand Down Expand Up @@ -746,7 +748,8 @@ EXPORT(int, vshSblSsIsDevelopmentMode) {
}

EXPORT(int, vshSblUtMgrHasComTestFlag) {
return UNIMPLEMENTED();
STUBBED("");
return 1;
}

EXPORT(int, vshSblUtMgrHasNpTestFlag) {
Expand Down
3 changes: 2 additions & 1 deletion vita3k/modules/include/modules/library_init_list.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

LIBRARY(SceAudiodec)
LIBRARY(SceFiber)
LIBRARY(SceSysmem)
LIBRARY(SceSysmem)
LIBRARY(SceSharedFb)
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
29 changes: 29 additions & 0 deletions vita3k/modules/module_parent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ 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 All @@ -106,6 +128,13 @@ static void log_import_call(char emulation_level, uint32_t nid, SceUID thread_id
}

void call_import(EmuEnvState &emuenv, CPUState &cpu, uint32_t nid, SceUID thread_id) {
if (nid == 0xF3917021) {
static Ptr<char> rep = Ptr<char>(alloc(emuenv.mem, 0x10, "ip_field"));
strcpy(rep.get(emuenv.mem), "127.0.0.1");
write_reg(cpu, 0, rep.address());
return;
}

Address export_pc = resolve_export(emuenv.kernel, nid);

if (!export_pc) {
Expand Down
23 changes: 23 additions & 0 deletions vita3k/nids/include/nids/nids.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2044,6 +2044,29 @@ NID(sceImeSetCaret, 0xD8342D2A)
NID(sceImeSetPreeditGeometry, 0x7B1EFAA5)
NID(sceImeSetText, 0xF3BD9A76)
NID(sceImeUpdate, 0x71D6898A)
// Library "SceIpmi"
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)
NID(SceIpmi_296D44D4, 0x296D44D4)
NID(SceIpmi_BC3A3031, 0xBC3A3031)
NID(SceIpmi_2C6DB642, 0x2C6DB642)
NID(SceIpmi_006EFA9D, 0x006EFA9D)
// Module "SceIncomingDialog"
// Library "SceIncomingDialog"
NID(sceIncomingDialogClose, 0x126BD15E)
Expand Down

0 comments on commit e73732a

Please sign in to comment.