sysmem: Make it closer to compiling

This commit is contained in:
Arthur Blot 2013-07-07 01:05:31 +02:00
parent 2f00304510
commit 1b3e149713
28 changed files with 1103 additions and 893 deletions

View File

@ -8,15 +8,15 @@
/* Not sure where this should be put */
/* Accepts addresses with 3 first bits: 000, 010, 100, 101 (first half byte 0x0, 0x1, 0x4, 0x5, 0x8, 0x9, 0xA, 0xB) */
#define VALID_ADDR_SEGMENT(addr) ((0x35 >> ((addr >> 29) & 7)) & 1)
#define VALID_ADDR_SEGMENT(addr) ((0x35 >> (((addr) >> 29) & 7)) & 1)
/* Accepts 0x10000 - 0x14000, with first bits as above */
#define ADDR_IS_SCRATCH(addr) (((addr >> 14) & 0x7FFF) == 4 && VALID_ADDR_SEGMENT(addr))
#define ADDR_IS_SCRATCH(addr) ((((addr) >> 14) & 0x7FFF) == 4 && VALID_ADDR_SEGMENT(addr))
/* Accepts 0x04000000 - 0x047FFFFF, with first bits as above */
#define ADDR_IS_VRAM(addr) (((addr >> 23) & 0x3F) == 8 && VALID_ADDR_SEGMENT(addr))
#define ADDR_IS_VRAM(addr) ((((addr) >> 23) & 0x3F) == 8 && VALID_ADDR_SEGMENT(addr))
/* Accepts 0x08000000 - 0x087FFFFFF, with first bits as above */
#define ADDR_IS_KERNEL_RAM(addr) ((((addr >> 23) & 0x3F) != 0x10) && VALID_ADDR_SEGMENT(addr))
#define ADDR_IS_KERNEL_RAM(addr) (((((addr) >> 23) & 0x3F) != 0x10) && VALID_ADDR_SEGMENT(addr))
/* Accepts 0x08000000 - 0x0FFFFFFF, 0x48000000 - 0x4FFFFFFF, 0x88000000 - 0x8FFFFFFF and 0xA8000000 - 0xAFFFFFFF */
#define ADDR_IS_RAM(addr) ((0x00220202 >> ((addr >> 27) & 0x1F)) & 1)
#define ADDR_IS_RAM(addr) ((0x00220202 >> (((addr) >> 27) & 0x1F)) & 1)
#endif

View File

@ -167,7 +167,7 @@ typedef struct {
int totalfreesize; // 52
int maxfreesize; // 56
int numheaps; // 60
void *heaps[];
SceSysmemHeapBlock *heaps[];
} SceSysmemHeapInfo;
int sceKernelQueryHeapInfo(SceUID id, SceSysmemHeapInfo *info);
@ -192,7 +192,7 @@ int sceKernelDeleteHeap(SceUID id);
typedef struct {
u32 size; // structure size (probably)
u32 addr;
u32 align;
} SceSysmemHeapAllocOption;
void *sceKernelAllocHeapMemoryWithOption(SceUID id, int size, SceSysmemHeapAllocOption *opt);
@ -243,9 +243,9 @@ typedef struct {
s32 size; // Structure size
} SceSysmemMemoryBlockAllocOption;
SceUID sceKernelAllocMemoryBlock(const char *name, u32 type, u32 size, SceSysmemMemoryBlockAllocOption *opt);
SceUID sceKernelAllocMemoryBlock(char *name, u32 type, u32 size, SceSysmemMemoryBlockAllocOption *opt);
s32 sceKernelFreeMemoryBlock(SceUID id);
s32 sceKernelGetMemoryBlockAddr(SceUID id, u32 *addrPtr);
s32 sceKernelGetMemoryBlockAddr(SceUID id, void **addrPtr);
/*
* Memory Main
@ -273,11 +273,11 @@ s32 sceKernelQueryMemoryInfo(u32 address, SceUID *partitionId, SceUID *memoryBlo
void *sceKernelGetBlockHeadAddr(SceUID id);
u32 SysMemForKernel_CC31DEAD(SceUID id);
void *sceKernelGetBlockHeadAddrForUser(SceUID id);
int memset(void *s, int c, int n);
void *sceKernelMemset(void *src, s8 c, u32 size);
void *sceKernelMemset32(void *src, s32 c, u32 size);
void *sceKernelMemmove(void *dst, void *src, u32 size);
void *sceKernelMemmoveWithFill(void *dst, void *src, u32 size, s32 fill);
void *sceKernelMemcpy(void *dst, const void *src, u32 n);
/*
* Memory Operations
@ -308,7 +308,7 @@ u32 sceKernelPartitionTotalFreeMemSize(s32 mpid);
u32 sceKernelPartitionTotalFreeMemSizeForUser(void);
s32 sceKernelFillFreeBlock(s32 mpid, u32 c);
SceUID sceKernelAllocPartitionMemory(s32 mpid, char *name, u32 type, s32 size, s32 addr);
s32 sceKernelAllocPartitionMemoryForUser(s32 mpid, char *name, s32 type, s32 size, s32 addr);
SceUID sceKernelAllocPartitionMemoryForUser(s32 mpid, char *name, u32 type, s32 size, s32 addr);
/*
* UIDs
@ -323,7 +323,7 @@ typedef struct SceSysmemUidCB {
struct SceSysmemUidCB *PARENT0; // 0
struct SceSysmemUidCB *nextChild; // 4
struct SceSysmemUidCB *meta; // 8: the type UID
u32 uid; // 12
SceUID uid; // 12
char *name; // 16
u8 childSize; // 20
u8 size; // 21
@ -338,14 +338,14 @@ typedef struct SceSysmemUidCB {
typedef s32 (*SceSysmemUidFunc)(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, s32 funcId, va_list ap);
typedef struct {
typedef struct SceSysmemUidLookupFunc {
s32 id;
SceSysmemUidFunc func;
} SceSysmemUidLookupFunc;
s32 sceKernelCallUIDFunction(SceUID id, int funcId, ...);
s32 sceKernelCallUIDObjFunction(SceSysmemUidCB *uid, s32 funcId, ...);
int sceKernelLookupUIDFunction(SceSysmemUidCB *uid, int id, void **func, SceSysmemUidCB **parentUidWithFunc);
int sceKernelLookupUIDFunction(SceSysmemUidCB *uid, int id, SceSysmemUidFunc *func, SceSysmemUidCB **parentUidWithFunc);
s32 sceKernelCallUIDObjCommonFunction(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, s32 funcId, va_list ap);
int sceKernelCreateUIDtypeInherit(const char *parentName, const char *name, int size,
SceSysmemUidLookupFunc *funcTable, SceSysmemUidLookupFunc *metaFuncTable,

View File

@ -18,11 +18,11 @@
typedef void (*prnt_callback)(void *ctx, int ch);
int memset(void *s, int c, int n);
void *memset(void *s, int c, u32 n);
int bcmp(void *s1, void *s2, int n);
int bcopy(void *src, void *dst, int n);
int bzero(void *s, int n);
void bcopy(void *src, void *dst, int n);
void bzero(void *s, int n);
int toupper(int c);
int tolower(int c);
int look_ctype_table(int c);
@ -30,7 +30,7 @@ char *index(char *s, int c);
u64 __udivmoddi4(u64 arg01, u64 arg23, u64 *v);
u64 __udivdi3(u64 arg01, u64 arg23);
u64 __umoddi3(u64 arg01, u64 arg23);
const void *memchr(const void *s, int c, int n);
void *memchr(const void *s, int c, int n);
int memcmp(const void *s1, const void *s2, int n);
void *memcpy(void *dst, const void *src, u32 n);
void *memmove(void *dst, const void *src, int n);

View File

@ -10,7 +10,7 @@ enum SceSysEventTypes {
SCE_SPEED_CHANGE_EVENTS = 0x01000000
};
typedef struct {
typedef struct SceSysEventHandler {
s32 size;
char *name;
s32 typeMask;

View File

@ -7,20 +7,23 @@
int UtilsForKernel_6C6887EE(void *outBuf, int outSize, void *inBuf, void **end);
void sceKernelDcacheInvalidateAll(void);
int sceKernelDcacheProbe(void *addr);
int sceKernelDcachePurgeRange(const void *p, u32 size);
void sceKernelDcacheWritebackAll(void);
void sceKernelDcacheWritebackInvalidateAll(void);
void sceKernelDcacheWritebackRange(const void *p, unsigned int size);
void sceKernelDcacheWritebackInvalidateRange(const void *p, unsigned int size);
void sceKernelDcacheInvalidateRange(const void *p, unsigned int size);
int sceKernelDcacheInvalidateRange(const void *p, unsigned int size);
int UtilsForKernel_157A383A(const void *p, unsigned int size);
void sceKernelIcacheInvalidateAll(void);
void sceKernelIcacheInvalidateRange(const void *addr, unsigned int size);
int sceKernelIcacheInvalidateRange(const void *addr, unsigned int size);
int sceKernelIcacheProbe(const void *addr);
int UtilsForKernel_43C9A8DB(const void *p, u32 size);
int sceKernelRtcGetTick(u64 *tick);
int sceKernelUtilsMd5Digest(u8 *data, u32 size, u8 *digest);
int sceKernelGzipDecompress(u8 *dest, u32 destSize, const u8 *src, u32 *unk);
int sceKernelGzipDecompress(u8 *dest, u32 destSize, const void *src, u32 *unk);
int UtilsForKernel_39FFB756(int);

View File

@ -1,4 +1,4 @@
#include <common_imp.h>
#include <sysmem_kdebug.h>
// 143FC
void (*g_assertHandler)(int);

View File

@ -1,3 +1,10 @@
#include <sysmem_sysclib.h>
#include "kdebug.h"
#include "partition.h"
char g_140C8[9]; // 140C8
s32 sceKernelApiEvaluationInit()
{
return 0;
@ -40,8 +47,8 @@ s32 sceKernelCallGprofFunction()
int sceKernelCheckDebugHandler()
{
void *ptr = MpidToCB(3);
return _CheckDebugHandler(*(int*)(ptr + 4), *(int*)(ptr + 8));
SceSysmemMemoryPartition *part = MpidToCB(3);
return _CheckDebugHandler((void *)part->addr, part->size);
}
void sub_A1E8(void)

View File

@ -1,3 +1,24 @@
#include <sysmem_kdebug.h>
#include <sysmem_kernel.h>
#include <sysmem_sysclib.h>
#include "intr.h"
#include "memory.h"
#include "partition.h"
#include "heap.h"
s32 heap_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 heap_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 heap_do_alloc(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 heap_do_free(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 heap_do_totalfreesize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 _TotalFreeSize(SceSysmemHeap *heap);
s32 _DeleteHeap(SceSysmemHeap *heap);
SceSysmemUidCB *g_145A4;
SceUID sceKernelCreateHeap(SceUID mpid, SceSize size, int flag, const char *name)
{
int oldIntr = suspendIntr();
@ -8,16 +29,16 @@ SceUID sceKernelCreateHeap(SceUID mpid, SceSize size, int flag, const char *name
resumeIntr(oldIntr);
return 0x800200D6;
}
SceUID uid = sceKernelCreateUID(g_145A4, name, (k1 >> 31) & 0xFF, &uid);
if (uid != 0) {
s32 ret = sceKernelCreateUID(g_145A4, name, (pspGetK1() >> 31) & 0xFF, &uid);
if (ret != 0) {
// 2FFC
resumeIntr(oldIntr);
return uid;
return ret;
}
int realSize = 0;
if ((flag & 1) != 0)
realSize = (size + 7) & 0xFFFFFFF8;
SceSysmemHeap *heap = (void*)uid + g_145A4->size * 4;
SceSysmemHeap *heap = UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap);
SceSysmemPartitionInfo partInfo;
heap->size = realSize | ((flag >> 1) & 1);
heap->partId = mpid;
@ -38,15 +59,14 @@ SceUID sceKernelCreateHeap(SceUID mpid, SceSize size, int flag, const char *name
initheap((SceSysmemLowheap*)(block + 1), size - 8);
heap->firstBlock = block;
resumeIntr(oldIntr);
return heap->uid;
return uid->uid;
}
void *_AllocHeapMemory(SceSysmemHeap *heap, u32 size, u32 unk)
void *_AllocHeapMemory(SceSysmemHeap *heap, u32 size, u32 align)
{
SceSysmemHeap *curHeap;
if (size > 0x20000000)
return 0;
if (unk != 0 && ((unk & 3) != 0 || unk >= 129 || (unk - 1) & unk != 0))
if (align != 0 && ((align & 3) != 0 || align > 0x80 || ((align - 1) & align) != 0))
return 0;
// 30A8
SceSysmemHeapBlock *block = heap->firstBlock;
@ -57,23 +77,20 @@ void *_AllocHeapMemory(SceSysmemHeap *heap, u32 size, u32 unk)
for (;;) // 321C
;
Kprintf("Heap memory is in illegal memory partition\n");
BREAK(0);
pspBreak(0);
}
// 30F4
int ret = hmalloc(heap, (SceSysmemLowheap*)(block + 1), size, unk);
if (ret != 0)
void *ret = hmalloc(heap, (SceSysmemLowheap*)(block + 1), size, align);
if (ret != NULL)
return ret;
if (block != head->firstBlock)
block = block->next;
else if (heap->size < 4)
return ret;
else
if (block == heap->firstBlock)
break;
block = block->next;
}
else if (heap->size < 4) // 312C
if (heap->size < 4) // 312C
return heap;
u32 newSize = heap->size & 0xFFFFFFFE;
if (unk == 0) {
if (align == 0) {
// 31FC
if (newSize - 40 < size) {
size = UPALIGN8(size);
@ -82,8 +99,8 @@ void *_AllocHeapMemory(SceSysmemHeap *heap, u32 size, u32 unk)
} else {
size = UPALIGN8(size);
// 3160
int shift = unk - (32 % unk);
if ((32 % unk) == 0)
int shift = align - (32 % align);
if ((32 % align) == 0)
shift = 0;
if (newSize - 40 < size + shift)
newSize = size + shift + 40;
@ -99,7 +116,7 @@ void *_AllocHeapMemory(SceSysmemHeap *heap, u32 size, u32 unk)
block->prev = heap->firstBlock->prev;
heap->firstBlock->prev = block;
block->prev->next = block;
return hmalloc(heap, (SceSysmemLowheap*)(block + 1), size, unk);
return hmalloc(heap, (SceSysmemLowheap*)(block + 1), size, align);
}
s32 _FreeHeapMemory(SceSysmemHeap *heap, void *addr)
@ -112,7 +129,7 @@ s32 _FreeHeapMemory(SceSysmemHeap *heap, void *addr)
for (;;) // 3324
;
Kprintf("Heap memory is in illegal memory partition\n");
BREAK(0);
pspBreak(0);
}
SceSysmemLowheap *lowh = (SceSysmemLowheap*)(block + 1);
// 328C
@ -121,7 +138,7 @@ s32 _FreeHeapMemory(SceSysmemHeap *heap, void *addr)
if (block != heap->firstBlock) {
if (checkheapnouse(lowh) != 0) {
// 3300
lowh->next = NULL;
lowh->addr = 0;
block->next->prev = block->prev;
block->prev->next = block->next;
_FreePartitionMemory(block);
@ -147,7 +164,7 @@ int sceKernelQueryHeapInfo(SceUID id, SceSysmemHeapInfo *info)
resumeIntr(oldIntr);
return ret;
}
SceSysmemHeap *heap = (void*)uid + g_145A4->size * 4;
SceSysmemHeap *heap = UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap);
// 33B8
int i;
for (i = 0; i < 6; i++)
@ -176,34 +193,34 @@ int sceKernelQueryHeapInfo(SceUID id, SceSysmemHeapInfo *info)
// 3420
for (;;)
{
if (curBlock - heap->partAddr >= heap->partSize)
if ((u32)curBlock - heap->partAddr >= heap->partSize)
break;
numHeaps++;
totalSize += ((cur->size - 16) & 0xFFFFFFF8) - 8;
totalFreeSize += htotalfreesize(cur);
maxFreeSize = MAX(maxFreeSize, hmaxfreesize(heap, cur));
maxFreeSize = pspMax(maxFreeSize, hmaxfreesize(heap, cur));
if (curBlock == heap->firstBlock)
break;
curBlock = curBlock->next;
}
// 347C
info->totalsize = totalSize;
int size = 64;
u32 size = 64;
info->totalfreesize = totalFreeSize;
info->maxfreesize = maxFreeSize;
info->numheaps = numHeaps;
curBlock = heap->firstBlock->next;
void **heap = &info->heaps;
SceSysmemHeapBlock **heaps = (SceSysmemHeapBlock **)&info->heaps;
if (info->size >= 68)
{
// 34A8
do
{
if (curBlock - heap->partAddr >= heap->partSize)
if ((u32)curBlock - heap->partAddr >= heap->partSize)
break;
size += 4;
*(heap++) = curBlock;
if (curBlock == a1)
*(heaps++) = curBlock;
if (curBlock == heap->firstBlock)
break;
curBlock = curBlock->next;
} while (size + 4 <= info->size);
@ -215,15 +232,15 @@ int sceKernelQueryHeapInfo(SceUID id, SceSysmemHeapInfo *info)
return 0;
}
s32 sceKernelQueryLowheapInfo(SceSysmemHeapBlock *block, SceKernelLowheapInfo *info)
s32 sceKernelQueryLowheapInfo(SceSysmemHeapBlock *block, SceSysmemLowheapInfo *info)
{
u32 maxInfoSize = info->size;
if (maxInfoSize < 24)
return 0x800200D2;
SceSysmemLowheap *lowh = block + 1;
SceSysmemLowheap *lowh = (SceSysmemLowheap *)(block + 1);
if (lowh->addr != (u32)lowh - 1)
return 0x800200DE;
SceSysmemLowheapBlock *cur = lowh + 1;
SceSysmemLowheapBlock *cur = (SceSysmemLowheapBlock *)(lowh + 1);
u32 infoSize = 24;
SceSysmemLowheapBlock *last = (void*)lowh + lowh->size - 8;
u32 blockCount = 0;
@ -239,7 +256,7 @@ s32 sceKernelQueryLowheapInfo(SceSysmemHeapBlock *block, SceKernelLowheapInfo *i
if (infoSize + 8 >= maxInfoSize)
infoBlock = NULL;
SceSysmemLowheapBlock *block;
if (cur->next == lowh) {
if (cur->next == (void *)lowh) {
// 3670
block = (SceSysmemLowheapBlock *)((u32)cur | 0x1);
unkCount1 += cur->count - 1;
@ -270,9 +287,20 @@ s32 sceKernelQueryLowheapInfo(SceSysmemHeapBlock *block, SceKernelLowheapInfo *i
return blockCount;
}
// 13480
SceSysmemUidLookupFunc HeapFuncs[] =
{
{ 0xD310D2D9, heap_do_initialize },
{ 0x87089863, heap_do_delete },
{ 0x0DE3B1BD, heap_do_alloc },
{ 0xA9CE362D, heap_do_free },
{ 0x01DB36E1, heap_do_totalfreesize },
{ 0, NULL}
};
void HeapInit(void)
{
sceKernelCreateUIDtype("SceSysmemHeap", sizeof(SceSysmemHeap), &g_13480, NULL, &g_145A4);
sceKernelCreateUIDtype("SceSysmemHeap", sizeof(SceSysmemHeap), HeapFuncs, NULL, &g_145A4);
}
int _CreateHeap(void *partition, int size, int attr, SceSysmemHeapBlock **out)
@ -300,7 +328,7 @@ int sceKernelDeleteHeap(SceUID id)
return ret;
}
int sceKernelAllocHeapMemoryWithOption(SceUID id, int size, SceSysmemHeapAllocOption *opt)
void *sceKernelAllocHeapMemoryWithOption(SceUID id, int size, SceSysmemHeapAllocOption *opt)
{
int oldIntr = suspendIntr();
SceSysmemUidCB *uid;
@ -310,12 +338,12 @@ int sceKernelAllocHeapMemoryWithOption(SceUID id, int size, SceSysmemHeapAllocOp
return 0;
}
// 37F4
int ret = _AllocHeapMemory(uid + g_145A4->size * 4, size, (opt != NULL) ? opt->addr : 0);
void *ret = _AllocHeapMemory(UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap), size, (opt != NULL) ? opt->align : 0);
resumeIntr(oldIntr);
return ret;
}
int sceKernelAllocHeapMemory(SceUID id, int size)
void *sceKernelAllocHeapMemory(SceUID id, int size)
{
int oldIntr = suspendIntr();
SceSysmemUidCB *uid;
@ -324,7 +352,7 @@ int sceKernelAllocHeapMemory(SceUID id, int size)
return 0;
}
// 38B0
int ret = _AllocHeapMemory((void*)uid + g_145A4->size, size, 0);
void *ret = _AllocHeapMemory(UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap), size, 0);
resumeIntr(oldIntr);
return ret;
}
@ -335,7 +363,7 @@ s32 sceKernelFreeHeapMemory(SceUID id, void *addr)
SceSysmemUidCB *uid;
s32 ret = sceKernelGetUIDcontrolBlockWithType(id, g_145A4, &uid);
if (ret == 0)
ret = _FreeHeapMemory((SceSysmemHeap*)((void*)uid + g_145A4->size * 4), addr);
ret = _FreeHeapMemory(UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap), addr);
// 3948
resumeIntr(oldIntr);
return ret;
@ -347,7 +375,7 @@ s32 sceKernelHeapTotalFreeSize(SceUID id)
SceSysmemUidCB *uid;
s32 ret = sceKernelGetUIDcontrolBlockWithType(id, g_145A4, &uid);
if (ret == 0)
ret = _TotalFreeSize((SceSysmemHeap*)((void*)uid + g_145A4->size * 4));
ret = _TotalFreeSize(UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap));
// 39D0
resumeIntr(oldIntr);
return ret;
@ -356,7 +384,7 @@ s32 sceKernelHeapTotalFreeSize(SceUID id)
s32 heap_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
{
sceKernelCallUIDObjCommonFunction(uid, uidWithFunc, funcId, ap);
SceSysmemHeap *heap = (SceSysmemHeap*)((void*)uid + g_145A4->size * 4);
SceSysmemHeap *heap = UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap);
heap->size = 0;
heap->partId = 0;
heap->firstBlock = NULL;
@ -365,37 +393,35 @@ s32 heap_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int fun
s32 heap_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
{
SceSysmemHeap *heap = (SceSysmemHeap*)((void*)uid + g_145A4->size * 4);
SceSysmemHeap *heap = UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap);
if (heap->firstBlock != NULL)
_DeleteHeap(heap);
sceKernelCallUIDObjCommonFunction(uid, uidWithFunc, funcId, ap);
return uid->uid;
}
s32 heap_do_alloc(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 heap_do_alloc(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
s32 size = va_arg(ap, s32);
s32 *ptr = va_arg(ap, s32*);
s32 *retPtr = va_arg(ap, s32*);
SceSysmemHeap *heap = (void*)uid + g_145A4->size * 4;
if (ptr != NULL)
size = ptr[1];
u32 size = va_arg(ap, u32);
SceSysmemHeapAllocOption *opt = va_arg(ap, SceSysmemHeapAllocOption *);
void **retPtr = va_arg(ap, void**);
SceSysmemHeap *heap = UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap);
// 3B10
*retPtr = _AllocHeapMemory(heap, heap, size);
*retPtr = _AllocHeapMemory(heap, size, (opt != NULL) ? opt->align : 0);
return uid->uid;
}
s32 heap_do_free(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 heap_do_free(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
s32 ret = _FreeHeapMemory((SceSysmemHeap*)((void*)uid + g_145A4->size * 4), va_arg(ap, s32));
s32 ret = _FreeHeapMemory(UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap), va_arg(ap, void*));
if (ret != 0)
return ret;
return uid->uid;
}
s32 heap_do_totalfreesize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 heap_do_totalfreesize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
*va_arg(ap, s32*) = _TotalFreeSize((SceSysmemHeap*)((void*)uid + g_145A4->size * 4));
*va_arg(ap, s32*) = _TotalFreeSize(UID_CB_TO_DATA(uid, g_145A4, SceSysmemHeap));
return uid->uid;
}
@ -411,16 +437,16 @@ s32 _DeleteHeap(SceSysmemHeap *heap)
for (;;) // 3C7C
;
Kprintf("Heap memory is in illegal memory partition\n");
BREAK(0);
pspBreak(0);
}
// 3C38
(SceSysmemLowheap*)(cur + 1)->next = NULL;
((SceSysmemLowheap*)(cur + 1))->addr = 0;
_FreePartitionMemory(cur);
cur = cur->next;
} while (cur != firstBlock);
}
// 3C50
(SceSysmemLowheap*)(firstBlock + 1)->next = NULL;
((SceSysmemLowheap*)(firstBlock + 1))->addr = 0;
return _FreePartitionMemory(firstBlock);
}
@ -434,7 +460,7 @@ s32 _TotalFreeSize(SceSysmemHeap *heap)
for (;;) // 3D20
;
Kprintf("Heap memory is in illegal memory partition\n");
BREAK(0);
pspBreak(0);
}
// 3CE4
size += htotalfreesize((SceSysmemLowheap*)(cur + 1));

28
src/sysmem/heap.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef HEAP_H
#define HEAP_H
typedef struct {
u32 addr; // 0 address of this structure minus 1
u32 size; // 4 size of this structure + the blocks (+ 1 control bit?)
u32 busyBlocks; // 8
SceSysmemLowheapBlock *firstBlock; // 12
// followed by blocks
} SceSysmemLowheap;
typedef struct {
int size; // 0
int partId; // 4
u32 partAddr; // 8
u32 partSize; // 12
SceSysmemHeapBlock *firstBlock; // 16
} SceSysmemHeap;
void HeapInit(void);
int _CreateHeap(void *partition, int size, int attr, SceSysmemHeapBlock **out);
void *_AllocHeapMemory(SceSysmemHeap *heap, u32 size, u32 align);
s32 _FreeHeapMemory(SceSysmemHeap *heap, void *addr);
extern SceSysmemUidCB *g_145A4;
#endif

8
src/sysmem/intr.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef INIT_H
#define INIT_H
s32 suspendIntr();
void resumeIntr(s32 oldIntr);
#endif

View File

@ -1,7 +1,15 @@
#include <stdarg.h>
#include <sysmem_sysclib.h>
#include <common_imp.h>
#include "intr.h"
#include "start.h"
int kprnt(short *arg0, const char *fmt, va_list ap, int userMode);
// 14434
char g_kprintfDefaultParam[260];
// 13BC4
int (*g_kprintfHandler)(short*, const char*, va_list, int) = kprnt;
// 13BC8
@ -29,8 +37,9 @@ void (*g_dbgPutchar)(short*, int);
int (*g_dbgWrite)();
// 14430
int (*g_dbgRead)();
// 14434
char g_kprintfDefaultParam[260];
int DipswSet(int reg, int val);
void SetIsDvdMode(void);
int DipswInit(u32 lo, u32 hi, int cpTime)
{
@ -480,29 +489,29 @@ int kprnt(short *arg0, const char *fmt, va_list ap, int userMode)
case 's': {
// 106C0
char *s = va_arg(ap, char*);
if (s == NULL)
curStr = va_arg(ap, char*);
if (curStr == NULL)
{
// 10748
s = g_null;
curStr = g_null;
}
// 106CC
if (userMode != 0 && !pspK1PtrOk(s))
if (userMode != 0 && !pspK1PtrOk(curStr))
return 0x800200D3;
// 106E4
if (strSize < 0)
{
// 1072C
stringLen = strlen(s);
stringLen = strlen(curStr);
}
else
{
char *s2 = memchr(s, '\0', strSize);
char *s2 = memchr(curStr, '\0', strSize);
stringLen = strSize;
if (s2 != NULL)
{
stringLen = s2 - s;
if (strSize < s2 - s)
stringLen = s2 - curStr;
if (strSize < s2 - curStr)
stringLen = strSize;
}
}
@ -637,7 +646,9 @@ int kprnt(short *arg0, const char *fmt, va_list ap, int userMode)
}
}
int KprintfForUser(const char *fmt, ...) __attribute__((alias("sceKernelPrintf")))
int sceKernelPrintf(const char *fmt, ...) __attribute__((alias("KprintfForUser")));
int KprintfForUser(const char *fmt, ...)
{
va_list ap;
int oldK1 = pspShiftK1();

7
src/sysmem/kdebug.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef KDEBUG_H
#define KDEBUG_H
int _CheckDebugHandler(void *ptr, u32 size);
#endif

View File

@ -1,7 +1,9 @@
SceUID sceKernelAllocMemoryBlock(const char *name, u32 type, u32 size, SceSysmemMemoryBlockAllocOption *opt)
#include <sysmem_kernel.h>
SceUID sceKernelAllocMemoryBlock(char *name, u32 type, u32 size, SceSysmemMemoryBlockAllocOption *opt)
{
s32 oldK1 = pspShiftK1();
if (!pspK1PtrOk(name) || !pspK1StaBufOk(a3, size)) {
if (!pspK1PtrOk(name) || !pspK1StaBufOk(opt, 4)) {
pspSetK1(oldK1);
return 0x800200D3;
}
@ -26,7 +28,8 @@ s32 sceKernelFreeMemoryBlock(SceUID id)
pspSetK1(oldK1);
return ret;
}
s32 sceKernelGetMemoryBlockAddr(SceUID id, u32 *addrPtr)
s32 sceKernelGetMemoryBlockAddr(SceUID id, void **addrPtr)
{
s32 oldK1 = pspShiftK1();
if (!pspK1StaBufOk(addrPtr, sizeof *addrPtr)) {

File diff suppressed because it is too large Load Diff

34
src/sysmem/memory.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef MEMORY_H
#define MEMORY_H
#include "heap.h"
#include "partition.h"
void initheap(SceSysmemLowheap *lowh, u32 size);
void *hmalloc(SceSysmemHeap *heap, SceSysmemLowheap *lowh, u32 size, u32 align);
s32 hfree(SceSysmemHeap *heap, SceSysmemLowheap *lowh, void *ptr);
s32 checkheapnouse(SceSysmemLowheap *lowh);
u32 htotalfreesize(SceSysmemLowheap *lowh);
s32 hmaxfreesize(SceSysmemHeap *heap, SceSysmemLowheap *lowh);
void *_AllocPartitionMemory(SceSysmemMemoryPartition *part, int type, int size, int addr);
s32 _FreePartitionMemory(void *addr);
void _QueryMemoryInfo(u32 address, SceUID *partitionId, SceUID *memoryBlockId);
void *_allocSysMemory(SceSysmemMemoryPartition *part, int type, u32 size, u32 addr, SceSysmemCtlBlk **ctlBlkOut);
s32 _freeSysMemory(SceSysmemMemoryPartition *part, void *addr);
void InitSmemCtlBlk(SceSysmemCtlBlk *ctlBlk);
void updateSmemCtlBlk(SceSysmemMemoryPartition *part, SceSysmemCtlBlk *ctlBlk);
void JointSmemCtlBlk(SceSysmemMemoryPartition *part, SceSysmemCtlBlk *ctlBlk);
void _ReturnSegBlankList(SceSysmemSeg *seg);
void *sceKernelFillBlock64(void *dst, s32 c, u32 size);
void sceKernelProtectMemoryBlock(SceSysmemMemoryPartition *part, void *addr);
extern SceSysmemUidCB *g_MemBlockType;
#endif

View File

@ -1,3 +1,12 @@
#include <sysmem_kernel.h>
#include <sysmem_kdebug.h>
#include <sysmem_utils_kernel.h>
#include "intr.h"
#include "partition.h"
u32 g_140D4; // 140D4
void MemoryProtectInit(u32 size, u32 extSize)
{
if (sceKernelGetModel() == 0 && sceKernelDipsw(10) == 0 && sceKernelDipsw(12) == 0) // A4B8
@ -36,8 +45,7 @@ void MemoryProtectInit(u32 size, u32 extSize)
} else
HW(0xBC000048) = 0;
// A3C8
s32 state;
COP0_STATE_GET(state, 22);
s32 state = pspCop0StateGet(COP0_STATE_CPUID);
if (state != 0) {
// A424
HW(0xBC000030) = 0x300;
@ -88,13 +96,13 @@ void sceKernelMemoryShrinkSize(void)
return;
if (g_140D4 == 1) {
// A614
UtilsForUser_34B9FA9E(g_145C0.extSc2Kernel->addr, g_145C0.extSc2Kernel->size);
sceKernelDcacheWritebackInvalidateRange((void *)g_145C0.extSc2Kernel->addr, g_145C0.extSc2Kernel->size);
}
// A5A4
s32 oldIntr = suspendIntr();
if ((g_140D4--) == 1) {
// A5E0
UtilsForUser_34B9FA9E(g_145C0.extSc2Kernel->addr, g_145C0.extSc2Kernel->size);
sceKernelDcacheWritebackInvalidateRange((void *)g_145C0.extSc2Kernel->addr, g_145C0.extSc2Kernel->size);
HW(0xBC100040) = (HW(0xBC100040) & 0xFFFFFFFC) | 1;
pspSync();
}

View File

@ -1,46 +1,69 @@
#include <sysmem_kernel.h>
#include <sysmem_sysclib.h>
#include "intr.h"
// 13FE4
s32 (*gRebootFunc)(void *arg);
// 13FE8
s32 (*gGetIdFunc)();
// 13FEC
SceKernelGameInfo SystemGameInfo;
// 14538
s32 gSysmemRandomValue;
// 1453C
u32 g_1453C;
// 14540
u32 gSysmemModel;
s32 SysMemForKernel_807179E7(char *gameId, int arg1, char *arg2, char *arg3, int arg4, int arg5, char *arg6)
{
if (gameId == NULL) {
// 90A4
g_13FEC.gameId[0] = '\0';
SystemGameInfo.gameId[0] = '\0';
} else {
strncpy(g_13FEC.gameId, gameId, 13);
g_13FEC.gameId[13] = '\0';
strncpy(SystemGameInfo.gameId, gameId, 13);
SystemGameInfo.gameId[13] = '\0';
}
// 8FB0
g_13FEC.unk84 = arg1;
SystemGameInfo.unk84 = arg1;
if (arg2 == NULL) {
// 909C
g_13FEC.str180[0] = '\0';
SystemGameInfo.str180[0] = '\0';
} else {
strncpy(g_13FEC.str180, arg2, 10);
g_13FEC.str180[10] = '\0';
strncpy(SystemGameInfo.str180, arg2, 10);
SystemGameInfo.str180[10] = '\0';
}
// 8FD0
if (arg3 == NULL) {
// 9090
g_13FEC.str196[0] = '\0';
SystemGameInfo.str196[0] = '\0';
}
else {
strncpy(g_13FEC.str196, arg3, 7);
g_13FEC.str196[7] = '\0';
strncpy(SystemGameInfo.str196, arg3, 7);
SystemGameInfo.str196[7] = '\0';
}
// 8FF0
g_13FEC.unk212 = arg4;
g_13FEC.unk216 = arg5;
SystemGameInfo.unk212 = arg4;
SystemGameInfo.unk216 = arg5;
if (arg6 == NULL) {
// 9088
g_13FEC.str88[0] = '\0';
SystemGameInfo.str88[0] = '\0';
} else {
strncpy(g_13FEC.str88, arg6, 7);
g_13FEC.str88[7] = '\0';
strncpy(SystemGameInfo.str88, arg6, 7);
SystemGameInfo.str88[7] = '\0';
}
// 9014
if (gameId != NULL || arg1 != 0 || arg2 != NULL || arg3 != NULL || arg6 != NULL) {
// 907C
g_13FEC.flags |= 0x100;
SystemGameInfo.flags |= 0x100;
} else
g_13FEC.flags &= (~0x100);
SystemGameInfo.flags &= (~0x100);
// 9044
return 0;
}
@ -49,70 +72,70 @@ s32 sceKernelCopyGameInfo(SceKernelGameInfo *info)
{
if (info == NULL)
return 0x800200D3;
info->flags = g_13FEC.flags & 0xFFFFFFFD;
info->size = g_13FEC.size;
if ((g_13FEC.flags & 1) != 0) {
info->flags = SystemGameInfo.flags & 0xFFFFFFFD;
info->size = SystemGameInfo.size;
if ((SystemGameInfo.flags & 1) != 0) {
// 92A4
strncpy(info->str8, g_13FEC.str8, 10);
strncpy(info->str8, SystemGameInfo.str8, 10);
info->str8[10] = '\0';
} else
info->str8[0] = '\0';
// 9104
if ((g_13FEC.flags & 4) != 0) {
if ((SystemGameInfo.flags & 4) != 0) {
// 9290
memcpy(info->qtgp2, g_13FEC.qtgp2, 8);
memcpy(info->qtgp2, SystemGameInfo.qtgp2, 8);
}
// 9118
if ((g_13FEC.flags & 8) != 0) {
if ((SystemGameInfo.flags & 8) != 0) {
// 927C
memcpy(info->qtgp3, g_13FEC.qtgp3, 16);
memcpy(info->qtgp3, SystemGameInfo.qtgp3, 16);
}
// 9124
if ((g_13FEC.flags & 0x100) != 0) {
if ((SystemGameInfo.flags & 0x100) != 0) {
// 9238
strncpy(info->gameId, g_13FEC.gameId, 13);
strncpy(info->gameId, SystemGameInfo.gameId, 13);
info->gameId[13] = '\0';
info->unk84 = g_13FEC.unk84;
strncpy(info->str180, g_13FEC.str180, 10);
info->unk84 = SystemGameInfo.unk84;
strncpy(info->str180, SystemGameInfo.str180, 10);
info->str180[10] = '\0';
strncpy(info->str88, g_13FEC.str88, 7);
strncpy(info->str88, SystemGameInfo.str88, 7);
info->str88[7] = '\0';
} else {
info->gameId[0] = '\0';
info->unk84 = 0;
info->str180[0] = '\0';
info->unk88 = 0;
info->str88[0] = '\0';
}
// 9140
if ((g_13FEC.flags & 0x200) == 0)
if ((SystemGameInfo.flags & 0x200) == 0)
info->umdCacheOn = 0;
else
info->umdCacheOn = g_13FEC.umdCacheOn;
info->umdCacheOn = SystemGameInfo.umdCacheOn;
// 915C
if ((g_13FEC.flags & 0x20000) == 0)
if ((SystemGameInfo.flags & 0x20000) == 0)
info->unk112 = 0;
else
info->unk112 = g_13FEC.unk112;
info->unk112 = SystemGameInfo.unk112;
// 917C
if ((g_13FEC.status & 0x40000) != 0) {
if ((SystemGameInfo.flags & 0x40000) != 0) {
// 9224
strncpy(info->str116, g_13FEC.str116, 64);
strncpy(info->str116, SystemGameInfo.str116, 64);
} else
info->str116[0] = '\0';
// 9198
if ((g_13FEC.status & 0x80000) == 0) {
if ((SystemGameInfo.flags & 0x80000) == 0) {
// 9210
memset(info->unk204, 0, 8);
} else
memcpy(info->unk204, g_13FEC.unk204, 8);
memcpy(info->unk204, SystemGameInfo.unk204, 8);
// 91BC
if ((g_13FEC.flags & 0x1000) != 0)
info->sdkVersion = g_13FEC.sdkVersion;
if ((SystemGameInfo.flags & 0x1000) != 0)
info->sdkVersion = SystemGameInfo.sdkVersion;
else
info->sdkVersion = 0;
// 91D0
if ((g_13FEC.flags & 0x2000) != 0)
info->compilerVersion = g_13FEC.compilerVersion;
if ((SystemGameInfo.flags & 0x2000) != 0)
info->compilerVersion = SystemGameInfo.compilerVersion;
else
info->compilerVersion = 0;
// 91EC
@ -125,22 +148,22 @@ void CopyGameInfo(SceKernelGameInfo *info)
{
if (info == NULL)
return;
g_13FEC.size = info->size;
SystemGameInfo.size = info->size;
if ((info->flags & 0x1) != 0) {
// 94E0
strncpy(g_13FEC.str24, info->str8, 10);
g_13FEC.str24[10] = '\0';
g_13FEC.flags |= 0x2;
strncpy(SystemGameInfo.str24, info->str8, 10);
SystemGameInfo.str24[10] = '\0';
SystemGameInfo.flags |= 0x2;
}
// 92F4
if ((info->flags & 0x4) != 0) {
if (info->qtgp2 == NULL) {
// 94C4
memset(g_13FEC.qtgp2, 0, 8);
g_13FEC.flags &= (~0x4);
memset(SystemGameInfo.qtgp2, 0, 8);
SystemGameInfo.flags &= (~0x4);
} else {
memcpy(g_13FEC.qtgp2, info->qtgp2, 8);
g_13FEC.flags |= 0x4;
memcpy(SystemGameInfo.qtgp2, info->qtgp2, 8);
SystemGameInfo.flags |= 0x4;
}
// 931C
}
@ -148,11 +171,11 @@ void CopyGameInfo(SceKernelGameInfo *info)
if ((info->flags & 0x8) != 0) {
if (info->qtgp3 == NULL) {
// 949C
memset(g_13FEC.qtgp3, 0, 16);
g_13FEC.flags &= (~0x8);
memset(SystemGameInfo.qtgp3, 0, 16);
SystemGameInfo.flags &= (~0x8);
} else {
memcpy(g_13FEC.qtgp3, info->qtgp3, 16);
g_13FEC.flags |= 0x8;
memcpy(SystemGameInfo.qtgp3, info->qtgp3, 16);
SystemGameInfo.flags |= 0x8;
}
// 9358
}
@ -163,72 +186,72 @@ void CopyGameInfo(SceKernelGameInfo *info)
}
// 936C
if ((info->flags & 0x200) != 0) {
g_13FEC.umdCacheOn = info->umdCacheOn;
g_13FEC.flags |= 0x200;
SystemGameInfo.umdCacheOn = info->umdCacheOn;
SystemGameInfo.flags |= 0x200;
}
// 9394
if ((info->flags & 0x20000) != 0) {
g_13FEC.unk112 = info->unk112;
g_13FEC.flags |= 0x20000;
SystemGameInfo.unk112 = info->unk112;
SystemGameInfo.flags |= 0x20000;
}
// 93C0
if ((info->flags & 0x40000) != 0) {
if (info->str116 == NULL) {
// 946C
g_13FEC.str116[0] = '\0';
SystemGameInfo.str116[0] = '\0';
} else
strncpy(g_13FEC.str116, info->str116, 64);
strncpy(SystemGameInfo.str116, info->str116, 64);
// 93E4
g_13FEC.flags |= 0x40000;
SystemGameInfo.flags |= 0x40000;
}
// 9400
if ((info->flags & 0x80000) != 0) {
if (info->unk204 == NULL) {
// 9450
memset(g_13FEC.unk204, 0, 8);
memset(SystemGameInfo.unk204, 0, 8);
} else
memcpy(g_13FEC.unk204, info->unk204, 8);
memcpy(SystemGameInfo.unk204, info->unk204, 8);
// 9428
g_13FEC.flags |= 0x80000;
SystemGameInfo.flags |= 0x80000;
}
}
void InitGameInfo(void)
{
g_13FEC.size = 220;
g_13FEC.str116[0] = '\0';
g_13FEC.flags = 0;
g_13FEC.str8[0] = '\0';
g_13FEC.str24[0] = '\0';
g_13FEC.allowReplaceUmd = 0;
g_13FEC.gameId[0] = '\0';
g_13FEC.unk84 = 0;
g_13FEC.str88[0] = '\0';
g_13FEC.umdCacheOn = 0;
g_13FEC.sdkVersion = 0;
g_13FEC.compilerVersion = 0;
g_13FEC.dnas = 0;
g_13FEC.unk112 = 0;
SystemGameInfo.size = 220;
SystemGameInfo.str116[0] = '\0';
SystemGameInfo.flags = 0;
SystemGameInfo.str8[0] = '\0';
SystemGameInfo.str24[0] = '\0';
SystemGameInfo.allowReplaceUmd = 0;
SystemGameInfo.gameId[0] = '\0';
SystemGameInfo.unk84 = 0;
SystemGameInfo.str88[0] = '\0';
SystemGameInfo.umdCacheOn = 0;
SystemGameInfo.sdkVersion = 0;
SystemGameInfo.compilerVersion = 0;
SystemGameInfo.dnas = 0;
SystemGameInfo.unk112 = 0;
}
s32 SysMemForKernel_F3BDB718(char *arg0)
{
if (arg0 == NULL) {
// 95B4
memset(g_13FEC.str8, 0, 16);
g_13FEC.flags &= ~0x1;
memset(SystemGameInfo.str8, 0, 16);
SystemGameInfo.flags &= ~0x1;
} else {
strncpy(g_13FEC.str8, arg0, 10);
g_13FEC.str8[10] = '\0';
g_13FEC.flags |= 0x1;
strncpy(SystemGameInfo.str8, arg0, 10);
SystemGameInfo.str8[10] = '\0';
SystemGameInfo.flags |= 0x1;
}
// 9598
return 0;
}
s32 sceKernelGetQTGP2(char *qtgp2)
{
if ((g_13FEC.flags & 0x4) == 0)
if ((SystemGameInfo.flags & 0x4) == 0)
return 0x80020001;
memcpy(qtgp2, g_13FEC.qtgp2, 8);
memcpy(qtgp2, SystemGameInfo.qtgp2, 8);
return 0;
}
@ -236,11 +259,11 @@ s32 sceKernelSetQTGP2(char *qtgp2)
{
if (qtgp2 == NULL) {
// 9670
memset(g_13FEC.qtgp2, 0, 8);
g_13FEC.flags &= ~0x4;
memset(SystemGameInfo.qtgp2, 0, 8);
SystemGameInfo.flags &= ~0x4;
} else {
memcpy(g_13FEC.qtgp2, qtgp2, 8);
g_13FEC.flags |= 0x4;
memcpy(SystemGameInfo.qtgp2, qtgp2, 8);
SystemGameInfo.flags |= 0x4;
}
// 9654
return 0;
@ -248,9 +271,9 @@ s32 sceKernelSetQTGP2(char *qtgp2)
s32 sceKernelGetQTGP3(char *qtgp3)
{
if ((g_13FEC.flags & 0x8) == 0)
if ((SystemGameInfo.flags & 0x8) == 0)
return 0x80020001;
memcpy(qtgp3, g_13FEC.qtgp3, 16);
memcpy(qtgp3, SystemGameInfo.qtgp3, 16);
return 0;
}
@ -258,52 +281,52 @@ s32 sceKernelSetQTGP3(char *qtgp3)
{
if (qtgp3 == NULL) {
// 972C
memset(g_13FEC.qtgp3, 0, 16);
g_13FEC.flags &= ~0x8;
memset(SystemGameInfo.qtgp3, 0, 16);
SystemGameInfo.flags &= ~0x8;
} else {
memcpy(g_13FEC.qtgp3, qtgp3, 16);
g_13FEC.flags |= 0x8;
memcpy(SystemGameInfo.qtgp3, qtgp3, 16);
SystemGameInfo.flags |= 0x8;
}
return 0;
}
s32 sceKernelGetAllowReplaceUmd(u32 *allow)
{
if ((g_13FEC.flags & 0x10) == 0)
if ((SystemGameInfo.flags & 0x10) == 0)
return 0x80020001;
*allow = g_13FEC.allowReplaceUmd;
*allow = SystemGameInfo.allowReplaceUmd;
return 0;
}
s32 sceKernelSetAllowReplaceUmd(u32 allow)
{
g_13FEC.allowReplaceUmd = allow;
g_13FEC.flags |= 0x10;
SystemGameInfo.allowReplaceUmd = allow;
SystemGameInfo.flags |= 0x10;
return 0;
}
s32 sceKernelSetUmdCacheOn(u32 umdCacheOn)
{
g_13FEC.umdCacheOn = umdCacheOn;
g_13FEC.flags |= 0x200;
SystemGameInfo.umdCacheOn = umdCacheOn;
SystemGameInfo.flags |= 0x200;
return 0;
}
s32 SysMemForKernel_40B744A4(u32 unk112)
{
g_13FEC.unk112 = unk112;
g_13FEC.flags |= 0x20000;
SystemGameInfo.unk112 = unk112;
SystemGameInfo.flags |= 0x20000;
return 0;
}
s32 SysMemForKernel_BFE08689(char *str116)
{
if (str116 == NULL)
g_13FEC.str116[0] = '\0';
SystemGameInfo.str116[0] = '\0';
else
strncpy(g_13FEC.str116, str116, 64);
strncpy(SystemGameInfo.str116, str116, 64);
// 980C
g_13FEC.status |= 0x40000;
SystemGameInfo.flags |= 0x40000;
return 0;
}
@ -311,24 +334,24 @@ s32 SysMemForKernel_2A8B8B2D(char *unk204)
{
if (unk204 == NULL) {
// 9888
memset(g_13FEC.unk204, 0, 8);
memset(SystemGameInfo.unk204, 0, 8);
} else
memcpy(g_13FEC.unk204, unk204, 8);
memcpy(SystemGameInfo.unk204, unk204, 8);
// 9864
g_13FEC.flags |= 0x80000;
SystemGameInfo.flags |= 0x80000;
return 0;
}
SceKernelGameInfo sceKernelGetGameInfo(void)
SceKernelGameInfo *sceKernelGetGameInfo(void)
{
return g_13FEC;
return &SystemGameInfo;
}
u32 sceKernelGetCompiledSdkVersion(void)
{
if ((g_13FEC.flags & 0x1000) == 0)
if ((SystemGameInfo.flags & 0x1000) == 0)
return 0;
return g_13FEC.sdkVersion;
return SystemGameInfo.sdkVersion;
}
s32 sceKernelSetCompiledSdkVersion100(u32 ver)
@ -349,11 +372,11 @@ s32 sceKernelSetCompiledSdkVersion100(u32 ver)
case 0x03040000:
case 0x03050000:
case 0x03060000:
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
default:
default: {
s32 oldIntr = suspendIntr();
HW(0xBC100040) = (HW(0xBC100040) & 0xFFFFFFFC) | 1;
sceKernelMemset32((void *)HWPTR(HW_RESET_VECTOR), 0, HW_RESET_VECTOR_SIZE);
@ -361,6 +384,7 @@ s32 sceKernelSetCompiledSdkVersion100(u32 ver)
// 09968
for (;;)
;
}
}
}
@ -368,7 +392,7 @@ s32 sceKernelSetCompiledSdkVersion370(u32 ver)
{
s32 oldK1 = pspShiftK1();
if ((ver & 0xFFFF0000) == 0x03070000) {
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -385,8 +409,8 @@ s32 sceKernelSetCompiledSdkVersion380_390(u32 ver)
{
s32 oldK1 = pspShiftK1();
if ((ver & 0xFFFF0000) == 0x03080000 ||
((ver & 0xFFFF0000) == 0x03090000 && (ver & 0x0000FF00) == 0))
g_13FEC.flags |= 0x1000;
((ver & 0xFFFF0000) == 0x03090000 && (ver & 0x0000FF00) == 0)) {
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -409,7 +433,7 @@ s32 sceKernelSetCompiledSdkVersion395(u32 ver)
case 0x04000000:
case 0x04000100:
case 0x04000500:
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -429,7 +453,7 @@ s32 sceKernelSetCompiledSdkVersion410_420(u32 ver)
{
case 0x04010000:
case 0x04020000:
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -449,7 +473,7 @@ s32 sceKernelSetCompiledSdkVersion500_550(u32 ver)
{
case 0x05000000:
case 0x05050000:
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -465,7 +489,7 @@ s32 sceKernelSetCompiledSdkVersion570(u32 ver)
{
s32 oldK1 = pspShiftK1();
if ((ver & 0xFFFF0000) == 0x05070000) {
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -485,7 +509,7 @@ s32 sceKernelSetCompiledSdkVersion600_620(u32 ver)
case 0x06000000:
case 0x06010000:
case 0x06020000:
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -505,7 +529,7 @@ s32 sceKernelSetCompiledSdkVersion630_650(u32 ver)
case 0x06030000:
case 0x06040000:
case 0x06050000:
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -521,7 +545,7 @@ s32 sceKernelSetCompiledSdkVersion660(u32 ver)
{
s32 oldK1 = pspShiftK1();
if ((ver & 0xFFFF0000) == 0x06060000) {
g_13FEC.flags |= 0x1000;
SystemGameInfo.flags |= 0x1000;
pspSetK1(oldK1);
return 0;
}
@ -535,33 +559,33 @@ s32 sceKernelSetCompiledSdkVersion660(u32 ver)
s32 sceKernelGetCompilerVersion(void)
{
if ((g_13FEC.flags & 0x2000) == 0)
if ((SystemGameInfo.flags & 0x2000) == 0)
return 0;
return g_13FEC.compilerVersion;
return SystemGameInfo.compilerVersion;
}
s32 sceKernelSetCompilerVersion(s32 version)
{
g_13FEC.compilerVersion = version;
SystemGameInfo.compilerVersion = version;
return 0;
}
s32 sceKernelGetDNAS(void)
{
if ((g_13FEC.flags & 0x10000) == 0)
if ((SystemGameInfo.flags & 0x10000) == 0)
return 0;
return g_13FEC.dnas;
return SystemGameInfo.dnas;
}
s32 sceKernelSetDNAS(s32 dnas)
{
g_13FEC.dnas = dnas;
SystemGameInfo.dnas = dnas;
return 0;
}
s32 sceKernelGetInitialRandomValue(void)
{
return g_initialRand;
return gSysmemRandomValue;
}
s32 SysMemForKernel_A0A9185A(void)
@ -578,37 +602,37 @@ u32 SysMemForKernel_13EE28DA(u32 flag)
u32 sceKernelGetModel(void)
{
return g_model;
return gSysmemModel;
}
s32 sceKernelSetRebootKernel(s32 (*rebootKernel)(void*))
{
g_rebootKernel = rebootKernel;
gRebootFunc = rebootKernel;
return 0;
}
s32 sceKernelRebootKernel(void *arg)
{
if (g_rebootKernel == NULL)
if (gRebootFunc == NULL)
return 0x80020001;
return g_rebootKernel(arg);
return gRebootFunc(arg);
}
s32 sceKernelRegisterGetIdFunc(void *func)
{
if (g_13FE8 != NULL)
if (gGetIdFunc != NULL)
return 0x80020001;
g_13FE8 = func;
gGetIdFunc = func;
return 0;
}
s32 sceKernelGetId()
{
if (g_13FE8 == NULL || g_13FE8 == (void*)-1)
if (gGetIdFunc == NULL || gGetIdFunc == (void*)-1)
return 0x80020001;
// A164
s32 ret = g_13FE8();
g_13FE8 = (void*)-1;
s32 ret = gGetIdFunc();
gGetIdFunc = (void*)-1;
return ret;
}

View File

@ -1,4 +1,26 @@
void *MpidToCB(int mpid)
#include <sysmem_kdebug.h>
#include <sysmem_kernel.h>
#include "intr.h"
#include "memory.h"
#include "partition.h"
s32 _CreateMemoryPartition(SceSysmemMemoryPartition *part, u32 attr, u32 addr, u32 size);
s32 partition_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 partition_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 partition_do_resize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 partition_do_querypartinfo(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 partition_do_maxfreememsize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
// 145A8
SceSysmemUidCB *g_145A8;
// 145C0
SceSysmemMemInfo g_145C0;
SceSysmemMemoryPartition *MpidToCB(int mpid)
{
SceSysmemUidCB *uid;
switch (mpid) // jump table at 0x000134E0
@ -45,42 +67,41 @@ void *MpidToCB(int mpid)
// 3E04
if (sceKernelGetUIDcontrolBlockWithType(mpid, g_145A8, &uid) != 0)
return 0;
return (void*)uid + g_145A8->size * 4;
return UID_CB_TO_DATA(uid, g_145A8, SceSysmemMemoryPartition);
}
}
s32 CanoniMpid(s32 mpid)
{
switch (MpidToCB(mpid)) {
case NULL:
SceSysmemMemoryPartition *part = MpidToCB(mpid);
if (part == NULL)
return 0;
case g_145C0.kernel:
else if (part == g_145C0.kernel)
return 1;
case g_145C0.vshell:
else if (part == g_145C0.vshell)
return 5;
case g_145C0.user:
else if (part == g_145C0.user)
return 2;
case g_145C0.extKernel:
else if (part == g_145C0.extKernel)
return 12;
case g_145C0.other1:
else if (part == g_145C0.other1)
return 3;
case g_145C0.other2:
else if (part == g_145C0.other2)
return 4;
case g_145C0.scUser;
else if (part == g_145C0.scUser)
return 6;
case g_145C0.meUser:
else if (part == g_145C0.meUser)
return 7;
case g_145C0.extScKernel:
else if (part == g_145C0.extScKernel)
return 8;
case g_145C0.extSc2Kernel:
else if (part == g_145C0.extSc2Kernel)
return 9;
case g_145C0.extMeKernel:
else if (part == g_145C0.extMeKernel)
return 10;
case g_145C0.extVshell:
else if (part == g_145C0.extVshell)
return 11;
default:
else
return mpid;
}
}
SceSysmemMemoryPartition *AddrToCB(u32 addr)
@ -98,9 +119,25 @@ SceSysmemMemoryPartition *AddrToCB(u32 addr)
return NULL;
}
/*
0x000134B0 - D9 D2 10 D3 | 88 46 00 00 | 63 98 08 87 | E0 46 00 00 - .....F..c....F..
0x000134C0 - 36 01 0E BB | BC 47 00 00 | A0 04 BA E6 | C4 47 00 00 - 6....G.......G..
0x000134D0 - 29 1D 7A 6D | CC 47 00 00 | 00 00 00 00 | 00 00 00 00 - ).zm.G..........
*/
// 134B0
SceSysmemUidLookupFunc PartFuncs[] = {
{ 0xD310D2D9, partition_do_initialize },
{ 0x87089863, partition_do_delete },
{ 0xBB0E0136, partition_do_resize },
{ 0xE6BA04A0, partition_do_querypartinfo},
{ 0x6D7A1D29, partition_do_maxfreememsize },
{ 0, NULL }
};
void PartitionServiceInit(void)
{
sceKernelCreateUIDtype("SceSysmemMemoryPartition", sizeof(SceSysmemMemoryPartition), &g_134B0, 0, &g_145A8);
sceKernelCreateUIDtype("SceSysmemMemoryPartition", sizeof(SceSysmemMemoryPartition), PartFuncs, 0, &g_145A8);
}
s32 sceKernelCreateMemoryPartition(const char *name, u32 unk, u32 addr, u32 size)
@ -113,7 +150,7 @@ s32 sceKernelCreateMemoryPartition(const char *name, u32 unk, u32 addr, u32 size
return ret;
}
// 402C
SceSysmemMemoryPartition *part = (void*)uid + g_145A8->size * 4;
SceSysmemMemoryPartition *part = UID_CB_TO_DATA(uid, g_145A8, SceSysmemMemoryPartition);
ret = _CreateMemoryPartition(part, unk, addr, size);
if (ret != 0) {
// 40E0
@ -135,7 +172,7 @@ s32 sceKernelCreateMemoryPartition(const char *name, u32 unk, u32 addr, u32 size
ctlBlk->firstSeg = 0;
ctlBlk->lastSeg = 0;
ctlBlk->segCount = 1;
ctlBlk->unk4 = 0;
ctlBlk->prev = NULL;
part->unk24 = 1;
ctlBlk->freeSeg = 1;
ctlBlk->unk10 = 0;
@ -158,9 +195,9 @@ s32 sceKernelQueryMemoryPartitionInfo(s32 mpid, SceSysmemPartitionInfo *info)
return 0x800200D2;
}
/* Note: there was unused $sp storing here, probably unoptimized crap */
info->unk12 = part->unk12 & 0xF;
info->addr = part->addr;
info->size = part->size;
info->attr = part->attr & 0xF;
info->startAddr = part->addr;
info->memSize = part->size;
resumeIntr(oldIntr);
return 0;
}
@ -169,7 +206,7 @@ void PartitionInit(SceSysmemMemoryPartition *part)
{
if (part->size != 0) {
SceSysmemCtlBlk *ctlBlk = part->firstCtlBlk;
InitSmemCtlBlk(ptr);
InitSmemCtlBlk(ctlBlk);
ctlBlk->segs[0].used = 0;
ctlBlk->segs[0].next = 0x3F;
ctlBlk->segs[0].offset = 0;
@ -180,7 +217,7 @@ void PartitionInit(SceSysmemMemoryPartition *part)
ctlBlk->firstSeg = 0;
ctlBlk->lastSeg = 0;
ctlBlk->segCount = 1;
ctlBlk->unk4 = 0;
ctlBlk->prev = NULL;
part->unk24 = 1;
ctlBlk->freeSeg = 1;
ctlBlk->unk10 = 0;
@ -329,7 +366,7 @@ s32 sceKernelFillFreeBlock(s32 mpid, u32 c)
for (i = 0; i < curCtlBlk->segCount && curCtlBlk->segCount != curCtlBlk->unk10; i++) {
if (curSeg->used == 0) {
// 4664
sceKernelFillBlock64(part->addr + (curSeg->offset << 8), c, curSeg->size << 8);
sceKernelFillBlock64((void*)part->addr + (curSeg->offset << 8), c, curSeg->size << 8);
}
// 4600
curSeg = &curCtlBlk->segs[curSeg->next];
@ -346,9 +383,9 @@ s32 sceKernelFillFreeBlock(s32 mpid, u32 c)
s32 partition_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
{
sceKernelCallUIDObjCommonFunction(uid, uidWithFunc, funcId, ap);
SceSysmemMemoryPartition *part = (void*)uid + g_145A8->size * 4;
SceSysmemMemoryPartition *part = UID_CB_TO_DATA(uid, g_145A8, SceSysmemMemoryPartition);
part->size = 0;
part->unk12 &= 0xFFFFFFF0;
part->attr &= 0xFFFFFFF0;
part->firstCtlBlk = NULL;
part->next = NULL;
part->addr = 0;
@ -357,7 +394,7 @@ s32 partition_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, in
s32 partition_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
{
SceSysmemMemoryPartition *part = (void*)uid + g_145A8->size * 4;
SceSysmemMemoryPartition *part = UID_CB_TO_DATA(uid, g_145A8, SceSysmemMemoryPartition);
if (part == MpidToCB(1))
return 0x800200D7;
if (part->firstCtlBlk->unk10 != 0)
@ -378,28 +415,28 @@ s32 partition_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int fu
return uid->uid;
}
s32 partition_do_resize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 partition_do_resize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap __attribute__((unused)))
{
return uid->uid;
}
s32 partition_do_querypartinfo(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 partition_do_querypartinfo(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap __attribute__((unused)))
{
return uid->uid;
}
s32 partition_do_maxfreememsize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 partition_do_maxfreememsize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
s32 *size = va_arg(ap, s32*);
SceSysmemMemoryPartition *part = (void*)uid + g_145A8->size * 4;
SceSysmemCtlBlk *curCtlBlk = part->ctlBlk;
SceSysmemMemoryPartition *part = UID_CB_TO_DATA(uid, g_145A8, SceSysmemMemoryPartition);
SceSysmemCtlBlk *curCtlBlk = part->firstCtlBlk;
u32 maxSize = 0;
// 47F4
while (curCtlBlk != NULL) {
SceSysmemSeg *curSeg = &curCtlBlk->segs[curCtlBlk->unk14];
SceSysmemSeg *curSeg = &curCtlBlk->segs[curCtlBlk->firstSeg];
u32 i;
// 4810
for (i = 0; i < curCtlBlk->unk8; i++) {
for (i = 0; i < curCtlBlk->segCount; i++) {
if (curSeg->used == 0 && maxSize < curSeg->size)
maxSize = curSeg->size;
// 4840
@ -413,7 +450,7 @@ s32 partition_do_maxfreememsize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc
return uid->uid;
}
s32 _CreateMemoryPartition(SceSysmemMemoryPartition *part, u32 unk, u32 addr, u32 size)
s32 _CreateMemoryPartition(SceSysmemMemoryPartition *part, u32 attr, u32 addr, u32 size)
{
u32 physAddr = addr & 0x1FFFFFFF;
u32 startAddr = g_145C0.memAddr & 0x1FFFFFFF;
@ -425,8 +462,8 @@ s32 _CreateMemoryPartition(SceSysmemMemoryPartition *part, u32 unk, u32 addr, u3
// 48E0
while (cur != NULL) {
u32 curAddr = cur->addr & 0x1FFFFFFF;
if (physAddr > curAddr && physAddr < curAddr + cur->size || // start of the partition in another partition
physAddr + size > curAddr && physAddr + size < curAddr + cur->size) // end of the partition in another partition
if ((physAddr > curAddr && physAddr < curAddr + cur->size) || // start of the partition in another partition
(physAddr + size > curAddr && physAddr + size < curAddr + cur->size)) // end of the partition in another partition
return 0x800200D5;
cur = cur->next;
// 4924
@ -435,7 +472,7 @@ s32 _CreateMemoryPartition(SceSysmemMemoryPartition *part, u32 unk, u32 addr, u3
// 492C
// 4930
part->addr = addr;
part->unk12 = (part->unk12 & 0xFFFFFFF0) | (unk & 0xF);
part->attr = (part->attr & 0xFFFFFFF0) | (attr & 0xF);
part->next = NULL;
part->size = size;
part->unk24 = 0;
@ -455,10 +492,10 @@ s32 _CreateMemoryPartition(SceSysmemMemoryPartition *part, u32 unk, u32 addr, u3
return 0;
}
SceSysmemSeg *AddrToSeg(SceSysmemMemoryPartition *part, u32 addr)
SceSysmemSeg *AddrToSeg(SceSysmemMemoryPartition *part, void *addr)
{
s32 blockOff = (addr & 0x1FFFFFFF) - (part->addr & 0x1FFFFFFF);
if (addr < part->addr || addr > part->addr + part->size)
s32 blockOff = ((u32)addr & 0x1FFFFFFF) - (part->addr & 0x1FFFFFFF);
if ((u32)addr < part->addr || (u32)addr > part->addr + part->size)
return NULL;
SceSysmemCtlBlk *curCtlBlk = part->firstCtlBlk;
// 49FC
@ -481,7 +518,7 @@ SceSysmemSeg *AddrToSeg(SceSysmemMemoryPartition *part, u32 addr)
return NULL;
}
SceUID sceKernelAllocPartitionMemory(s32 mpid, const s8 *name, u32 type, s32 size, s32 addr)
SceUID sceKernelAllocPartitionMemory(s32 mpid, char *name, u32 type, s32 size, s32 addr)
{
if (type > 4)
return 0x800200D8;
@ -500,20 +537,20 @@ SceUID sceKernelAllocPartitionMemory(s32 mpid, const s8 *name, u32 type, s32 siz
if (!pspK1IsUserMode())
flag = 0;
SceSysmemUidCB *uid;
s32 ret = sceKernelCreateUID(g_13FE0, name, (flag | pspK1IsUserMode()) & 0xFF, &uid);
s32 ret = sceKernelCreateUID(g_MemBlockType, name, (flag | pspK1IsUserMode()) & 0xFF, &uid);
if (ret != 0) {
// 4C9C
resumeIntr(oldIntr);
return ret;
}
SceSysmemMemoryBlock *memBlock = (void*)uid + g_13FE0->size;
u32 outAddr;
SceSysmemMemoryBlock *memBlock = UID_CB_TO_DATA(uid, g_MemBlockType, SceSysmemMemoryBlock);
void *outAddr;
if (type == 2 && (addr & 0xFF) != 0) { // 4C70
outAddr = _allocSysMemory(part, type, ((addr + size + 0xFF) & 0xFFFFFF00) - (addr & 0xFFFFFF00), addr & 0xFFFFFF00, 0);
} else
outAddr = _allocSysMemory(part, type, size, addr, 0);
// 4BDC
if (outAddr == 0) {
if (outAddr == NULL) {
// 4C14
Kprintf("system memory allocation failed\n");
Kprintf("\tmpid 0x%08x, name [%s], request size 0x%x\n", mpid, name, size);
@ -529,7 +566,7 @@ SceUID sceKernelAllocPartitionMemory(s32 mpid, const s8 *name, u32 type, s32 siz
return uid->uid;
}
s32 sceKernelAllocPartitionMemoryForUser(s32 mpid, const s8 *name, s32 type, s32 size, s32 addr)
SceUID sceKernelAllocPartitionMemoryForUser(s32 mpid, char *name, u32 type, s32 size, s32 addr)
{
SceSysmemPartitionInfo info;
s32 oldK1 = pspShiftK1();
@ -539,11 +576,11 @@ s32 sceKernelAllocPartitionMemoryForUser(s32 mpid, const s8 *name, s32 type, s32
pspSetK1(oldK1);
return ret;
}
if ((info.unk12 & 2) == 0) {
if ((info.attr & 2) == 0) {
pspSetK1(oldK1);
return 0x800200D6;
}
if (!pspK1PtrOk(name) || (type == 2 && !pspK1PtrOk(addr))) { // 4D8C
if (!pspK1PtrOk(name) || (type == 2 && !pspK1PtrOk((void *)addr))) { // 4D8C
// 4D94
pspSetK1(oldK1);
return 0x800200D3;

73
src/sysmem/partition.h Normal file
View File

@ -0,0 +1,73 @@
#ifndef PARTITION_H
#define PARTITION_H
#include <sysmem_kernel.h>
typedef struct {
unsigned used : 1; // 0
unsigned next : 6; /* next index */ // 1
unsigned offset : 25; /* offset (from the partition start, divided by 0x100) */ // 7
unsigned unk0_0 : 1; // 0
unsigned sizeLocked : 1; // 1
unsigned prev : 6; // 2
unsigned unk8 : 1; // 8
unsigned size : 23; /* size (divided by 0x100) */ // 9
} SceSysmemSeg; // size: 8
typedef struct SceSysmemCtlBlk {
struct SceSysmemCtlBlk *next; // 0
struct SceSysmemCtlBlk *prev; // 4
u16 segCount;
u16 unk10; // used segments?
u16 freeSeg; // 12 // points to a free segment id
u8 firstSeg; // 14
u8 lastSeg; // 15
SceSysmemSeg segs[30];
} SceSysmemCtlBlk; // size: 0x100 (control blocks are always placed at a 0x100-aligned address)
typedef struct SceSysmemMemoryPartition {
struct SceSysmemMemoryPartition *next; // 0
u32 addr; // 4
u32 size; // 8
u32 attr; // 12
SceSysmemCtlBlk *firstCtlBlk; // 16
SceSysmemCtlBlk *lastCtlBlk; // 20
s32 unk24;
} SceSysmemMemoryPartition;
SceSysmemMemoryPartition *MpidToCB(int mpid);
SceSysmemSeg *AddrToSeg(SceSysmemMemoryPartition *part, void *addr);
SceSysmemMemoryPartition *AddrToCB(u32 addr);
s32 CanoniMpid(s32 mpid);
typedef struct {
u32 memAddr; // 0
u32 memSize; // 4
SceSysmemMemoryPartition *main; // 8
SceSysmemMemoryPartition *other1; // 12
SceSysmemMemoryPartition *other2; // 16
SceSysmemMemoryPartition *vshell; // 20
SceSysmemMemoryPartition *scUser; // 24
SceSysmemMemoryPartition *meUser; // 28
SceSysmemMemoryPartition *extScKernel; // 32
SceSysmemMemoryPartition *extSc2Kernel; // 36
SceSysmemMemoryPartition *extMeKernel; // 40
SceSysmemMemoryPartition *extVshell; // 44
SceSysmemMemoryPartition *kernel; // 48
SceSysmemMemoryPartition *user; // 52
SceSysmemMemoryPartition *extKernel; // 56
u32 realMemSize; // 60
u32 unk64; // 64
} SceSysmemMemInfo;
typedef struct {
void *addr;
u32 size;
SceSysmemMemoryPartition *part;
} SceSysmemMemoryBlock; // size: 12; allocated space in partition
extern SceSysmemUidCB *g_145A8;
extern SceSysmemMemInfo g_145C0;
#endif

View File

@ -1742,7 +1742,8 @@ loc_000016F8:
jr $ra
move $v0, $zr
sub_00001710:
# 0x1710
md5BlockUpdate:
move $at, $ra
lw $t0, 0($a0)
lw $t1, 4($a0)
@ -1836,7 +1837,8 @@ sub_17B0:
jr $ra
sw $t7, 12($a0)
sub_00001870:
# 0x1870
sha1BlockUpdate:
addiu $sp, $sp, -64
sw $ra, 0($sp)
sw $s0, 4($sp)
@ -1968,7 +1970,8 @@ loc_00001A00:
jr $ra
addu $s4, $t4, $s4
sub_00001A40:
# 1A40
sha1Digest:
addiu $sp, $sp, -256
sw $s0, 0($sp)
sw $s1, 4($sp)
@ -2176,7 +2179,8 @@ loc_00001C88:
jr $ra
addiu $sp, $sp, 256
sub_00001CF0:
# 1CF0
mt19937UInt:
lw $a1, 0($a0)
addiu $a3, $a0, 4
sltiu $t4, $a1, 624

44
src/sysmem/start.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef START_H
#define START_H
typedef struct
{
u32 h[4];
u32 pad;
u16 usRemains;
u16 usComputed;
u64 ullTotalLen;
u8 buf[64];
} SceKernelUtilsMd5Context;
void md5BlockUpdate(SceKernelUtilsMd5Context *ctx, u8 *data);
typedef struct
{
u32 h[5];
u16 usRemains;
u16 usComputed;
u64 ullTotalLen;
u8 buf[64];
} SceKernelUtilsSha1Context;
void sha1BlockUpdate(u8 *data, SceKernelUtilsSha1Context *ctx);
void sha1Digest(u8 *data, u32 size, u8 *digest);
typedef struct {
u32 count;
u32 state[624];
} SceKernelUtilsMt19937Context;
u32 mt19937UInt(SceKernelUtilsMt19937Context *ctx);
int sceKernelDeflateDecompress(u8 *dest, u32 destSize, const u8 *src, void **unk);
extern int g_13B40;
extern int g_13B44;
extern int g_13B48;
extern int g_13B80;
extern int g_13B84;
#endif

View File

@ -1,5 +1,7 @@
#include <common_imp.h>
#include "intr.h"
typedef struct
{
int size; // 0

View File

@ -1,8 +1,17 @@
#include <stdarg.h>
#include <common_imp.h>
#include <sysmem_sysclib.h>
#include "sysclib.h"
#define CTYPE_DOWNCASE_LETTER 0x01
#define CTYPE_UPCASE_LETTER 0x02
#define CTYPE_CIPHER 0x04
#define CTYPE_TRANSPARENT 0x08
#define CTYPE_PUNCTUATION 0x10
#define CTYPE_CTRL 0x20
#define CTYPE_HEX_CIPHER 0x40
#define CTYPE_LETTER (CTYPE_DOWNCASE_LETTER | CTYPE_UPCASE_LETTER)
char g_ctypeTbl[] =
{
@ -142,14 +151,14 @@ int bcmp(void *s1, void *s2, int n)
return memcmp(s1, s2, n);
}
int bcopy(void *src, void *dst, int n)
void bcopy(void *src, void *dst, int n)
{
return memmove(dst, src, n);
memmove(dst, src, n);
}
int bzero(void *s, int n)
void bzero(void *s, int n)
{
return memset(s, 0, n);
memset(s, 0, n);
}
int toupper(int c)
@ -300,7 +309,7 @@ u64 __umoddi3(u64 arg01, u64 arg23)
return mod;
}
const void *memchr(const void *s, int c, int n)
void *memchr(const void *s, int c, int n)
{
if (s != NULL)
{
@ -308,7 +317,7 @@ const void *memchr(const void *s, int c, int n)
while ((n--) > 0)
{
if (*(char*)s == (c & 0xFF))
return s;
return (void *)s;
s++;
}
}
@ -338,6 +347,9 @@ void *sceKernelMemcpy(void *dst, const void *src, u32 n)
const char *curSrc = (const char*)src;
char *curDst = (char*)dst;
char *end = (char*)dst + n;
asm(".set noat");
if (dst == src)
return dst;
if (n >= 8)
@ -349,7 +361,7 @@ void *sceKernelMemcpy(void *dst, const void *src, u32 n)
int align = 4 - ((int)dst & 3);
asm("lwl $at, 3(%0)\n \
lwr $at, 0(%0)\n \
swr $at, 0(%1)" : : "r" (src), "r" (dst) : "$at");
swr $at, 0(%1)" : : "r" (src), "r" (dst) : "at");
curSrc = src + align;
curDst = dst + align;
}
@ -366,7 +378,7 @@ void *sceKernelMemcpy(void *dst, const void *src, u32 n)
lwr $at, 0(%0)\n \
addiu %0, %0, 4\n \
addiu %1, %1, 4\n \
sw $at, -4(%1)" : : "r" (curSrc), "r" (curDst) : "$at");
sw $at, -4(%1)" : : "r" (curSrc), "r" (curDst) : "at");
}
// D890
// D894
@ -387,7 +399,7 @@ void *sceKernelMemcpy(void *dst, const void *src, u32 n)
sw $at, 0(%1)\n \
sw $a3, 4(%1)\n \
sw $t0, 8(%1)\n \
sw $t1, 12(%1)" : : "r" (curSrc + i * 16), "r" (curDst + i * 16) : "$at", "$a3", "$t0", "$t1");
sw $t1, 12(%1)" : : "r" (curSrc + i * 16), "r" (curDst + i * 16) : "at", "a3", "t0", "t1");
curSrc += 64;
curDst += 64;
}
@ -401,7 +413,7 @@ void *sceKernelMemcpy(void *dst, const void *src, u32 n)
asm("lw $at, 0(%0)\n \
addiu %0, %0, 4\n \
sw $at, 0(%1)\n \
addiu %1, %1, 4" : : "r" (curSrc), "r" (curDst) : "$at");
addiu %1, %1, 4" : : "r" (curSrc), "r" (curDst) : "at");
}
// D79C
// D7A0
@ -418,7 +430,7 @@ void *sceKernelMemcpy(void *dst, const void *src, u32 n)
sw $at, 0(%1)\n \
sw $a3, 4(%1)\n \
sw $t0, 8(%1)\n \
sw $t1, 12(%1)" : : "r" (curSrc + i * 16), "r" (curDst + i * 16) : "$at", "$a3", "$t0", "$t1");
sw $t1, 12(%1)" : : "r" (curSrc + i * 16), "r" (curDst + i * 16) : "at", "a3", "t0", "t1");
curSrc += 64;
curDst += 64;
}
@ -433,7 +445,8 @@ void *sceKernelMemcpy(void *dst, const void *src, u32 n)
// D84C
while (curDst != (void*)((int)end & 0xFFFFFFFC))
{
*(int*)curDst = UNALIGNED_LW((int*)curSrc);
asm("lwl %0, 3(%1)\n \
lwr %0, 0(%1)" : "=r" (curDst) : "r" (curSrc));
curDst += 4;
curSrc += 4;
}
@ -886,7 +899,7 @@ char *rindex(const char *s, char c)
// E22C
do
if (*(--cur) == c)
return cur;
return (char *)cur;
while (s < cur);
return 0;
}
@ -894,10 +907,10 @@ char *rindex(const char *s, char c)
int sprintf(char *str, const char *format, ...)
{
va_list ap;
char **ctx;
char *ctx[1];
va_start(ap, format);
*ctx = str;
int ret = prnt(sprintf_char, (void*)ctx, format, ap);
ctx[0] = str;
int ret = prnt((prnt_callback)sprintf_char, (void*)ctx, format, ap);
va_end(ap);
return ret;
}
@ -910,7 +923,7 @@ int snprintf(char *str, u32 size, const char *format, ...)
ctx[0] = size - 1;
ctx[1] = 0;
ctx[2] = (int)str;
int ret = prnt(snprintf_char, ctx, format, ap);
int ret = prnt((prnt_callback)snprintf_char, ctx, format, ap);
va_end(ap);
return ret;
}
@ -957,7 +970,7 @@ char *strchr(const char *s, char c)
do
{
if (*s == c)
return s;
return (char *)s;
s++;
} while (*s != '\0');
return NULL;
@ -996,7 +1009,7 @@ char *strcpy(char *dest, const char *src)
return dest;
}
int strtol(char *nptr, char **endptr, int base)
int strtol(const char *nptr, char **endptr, int base)
{
int sign = +1;
int num = 0;
@ -1066,7 +1079,7 @@ int strtol(char *nptr, char **endptr, int base)
{
// E5AC
if (endptr != NULL)
*endptr = nptr - 1;
*endptr = (char*)nptr - 1;
// E5B8
return num * sign;
}

View File

@ -1,4 +1,7 @@
#include <common_imp.h>
#include <sysmem_sysevent.h>
#include "intr.h"
// 140F0
SceSysEventHandler *g_sysEvHandlers;
@ -47,7 +50,7 @@ int sceKernelSysEventDispatch(int ev_type_mask, int ev_id, char* ev_name, void*
// C928
while (cur != NULL)
{
if ((cur->type_mask & ev_type_mask) != 0)
if ((cur->typeMask & ev_type_mask) != 0)
{
// C984
cur->busy = 1;

View File

@ -144,7 +144,7 @@ int SysMemPostInit(void *arg0, SceSysmemPartTable *partTable)
*uidExtScKernel, *uidExtSc2Kernel, *uidExtMe, *uidExtVsh;
PartitionServiceInit();
sceKernelCreateUID(g_145A8, "SceMyKernelPartition", (k1 >> 31) & 0xFF, &uidKernel);
SceSysmemMemoryPartition *kernelPart = (void*)uid + g_145A8->size * 4;
SceSysmemMemoryPartition *kernelPart = UID_CB_TO_DATA(uid, g_145A8, SceSysmemMemoryPartition);
SceSysmemMemoryPartition *part;
*(int*)(kernelPart + 0) = 0;
*(int*)(kernelPart + 4) = *(int*)(arg0 + 4);
@ -157,15 +157,15 @@ int SysMemPostInit(void *arg0, SceSysmemPartTable *partTable)
*(int*)(kernelPart + 20) = *(int*)(arg0 + 16);
g_145C0.main = kernelPart;
MemoryBlockServiceInit();
sceKernelCreateUID(g_13FE0, "SceSystemMemoryManager", (k1 >> 31) & 0xFF, &uidKernel);
SceSysmemMemoryBlock *memBlock = (void*)uidKernel + g_13FE0->size * 4;
sceKernelCreateUID(g_MemBlockType, "SceSystemMemoryManager", (k1 >> 31) & 0xFF, &uidKernel);
SceSysmemMemoryBlock *memBlock = UID_CB_TO_DATA(uidKernel, g_MemBlockType, SceSysmemMemoryBlock);
*(int*)(&g_1455C + 8) = memBlock;
*(int*)(memBlock + 0) = *(int*)(&g_1455C + 0);
*(int*)(memBlock + 4) = *(int*)(&g_1455C + 4);
*(int*)(memBlock + 8) = *(int*)(&g_1455C + 8);
sceKernelProtectMemoryBlock(*(int*)(&g_1455C + 8), *(int*)(&g_1455C + 0));
sceKernelCreateUID(g_13FE0, "SceSystemBlock", (k1 >> 31) & 0xFF, &uidKernel);
memBlock = (void*)uidKernel + g_13FE0->size * 4;
sceKernelCreateUID(g_MemBlockType, "SceSystemBlock", (k1 >> 31) & 0xFF, &uidKernel);
memBlock = UID_CB_TO_DATA(uidKernel, g_MemBlockType, SceSysmemMemoryBlock);
*(int*)(&g_14568 + 8) = memBlock;
*(int*)(memBlock + 0) = *(int*)(&g_14568 + 0);
*(int*)(memBlock + 4) = *(int*)(&g_14568 + 4);
@ -176,7 +176,7 @@ int SysMemPostInit(void *arg0, SceSysmemPartTable *partTable)
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceOtherKernelPartition", 12, info->addr, info->size), g_145A8, &uidOther);
part = NULL;
if (info->size != 0)
part = (void*)uidOther + g_145A8->size * 4;
part = UID_CB_TO_DATA(uidOther, g_145A8, SceSysmemMemoryPartition);
// 11160
if (*(int*)(arg1 + 4) == 3) {
// 11450
@ -191,21 +191,21 @@ int SysMemPostInit(void *arg0, SceSysmemPartTable *partTable)
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceVshellPartition", 15, info->addr, info->size), g_145A8, &uidVsh);
part = NULL;
if (info->size != 0)
part = (void*)uidVsh + g_145A8->size * 4;
UID_CB_TO_DATA(uidVsh, g_145A8, SceSysmemMemoryPartition);
// 111C8
g_145C0.vshell = part;
info = &partTable->scUser;
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceScUserPartition", 15, info->addr, info->size), g_145A8, &uidScUser);
part = NULL;
if (info->size != 0)
part = (void*)uidScUser + g_145A8->size * 4;
part = UID_CB_TO_DATA(uidScUser, g_145A8, SceSysmemMemoryPartition)
// 1121C
g_145C0.scUser = part;
info = &partTable->meUser;
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceMeUserPartition", 15, info->addr, info->size), g_145A8, &uidMeUser);
part = NULL;
if (info->size != 0)
part = (void*)uidMeUser + g_145A8->size * 4;
part = UID_CB_TO_DATA(uidMeUser, g_145A8, SceSysmemMemoryPartition);
// 11270
g_145C0.meUser = part;
if (*(int*)(arg1 + 8) == 6) {
@ -218,21 +218,21 @@ int SysMemPostInit(void *arg0, SceSysmemPartTable *partTable)
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceExtScKernelPartition", 12, info->addr, info->size), g_145A8, &uidExtScKernel);
part = NULL;
if (info->size != 0)
part = (void*)uidExtScKernel + g_145A8->size * 4;
part = UID_CB_TO_DATA(uidExtScKernel, g_145A8, SceSysmemMemoryPartition);
// 112DC
g_145C0.extScKernel = part;
info = &partTable->extSc2Kernel;
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceExtSc2KernelPartition", 12, info->addr, info->size), g_145A8, &uidExtSc2Kernel);
part = NULL;
if (info->size != 0)
part = (void*)uidSc2Kernel + g_145A8->size * 4;
part = UID_CB_TO_DATA(uidSc2Kernel, g_145A8, SceSysmemMemoryPartition);
// 11330
g_145C0.extSc2Kernel = part;
info = &partTable->extMeKernel;
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceExtMeKernelPartition", 12, info->addr, info->size), g_145A8, &uidExtMeKernel);
part = NULL;
if (info->size != 0)
part = (void*)uidExtMeKernel + g_145A8->size * 4;
part = UID_CB_TO_DATA(uidExtMeKernel, g_145A8, SceSysmemMemoryPartition);
// 11384
g_145C0.extMeKernel = part;
if (*(int*)(arg1 + 4) == 3) {
@ -248,7 +248,7 @@ int SysMemPostInit(void *arg0, SceSysmemPartTable *partTable)
sceKernelGetUIDcontrolBlockWithType(sceKernelCreateMemoryPartition("SceExtVshellPartition", 12, info->addr, info->size), g_145A8, &uidExtVsh);
part = NULL;
if (info->size != 0)
part = (void*)uidExtVsh + g_145A8->size * 4;
part = UID_CB_TO_DATA(uidExtVsh, g_145A8, SceSysmemMemoryPartition);
// 11404
g_145C0.extVshell = part;
resumeIntr(oldIntr);

View File

@ -1,108 +1,7 @@
s32 (*g_rebootKernel)(void *arg); // 13FE4
#ifndef SYSMEM_H
#define SYSMEM_H
typedef struct
{
u32 size; // 0
u32 flags; // 4
char str8[16]; // 8
char str24[11]; // 24
// padding?
char qtgp2[8]; // 40
char qtgp3[16]; // 48
u32 allowReplaceUmd; // 64
char gameId[14]; // 68
// padding?
u32 unk84; // 84
char str88[8]; // 88
u32 umdCacheOn; // 96
u32 sdkVersion; // 100
u32 compilerVersion; // 104
u32 dnas; // 108
u32 unk112; // 112
char str116[64]; // 116
char str180[11]; // 180
// padding?
char str196[8]; // 196
char unk204[8]; // 204
int unk212; // 212
int unk216; // 216
} SceKernelGameInfo;
SceKernelGameInfo g_13FEC; // 13FEC
char g_140C8[9]; // 140C8
u32 g_140D4; // 140D4
s32 g_initialRand; // 14538
u32 g_1453C; // 1453C
u32 g_model; // 14540
/*
typedef struct SceSysmemLowheapBlock {
struct SceSysmemLowheapBlock *next;
u32 count;
} SceSysmemLowheapBlock;
*/
typedef struct {
u32 addr; // 0 address of this structure minus 1
u32 size; // 4 size of this structure + the blocks (+ 1 control bit?)
u32 busyBlocks; // 8
SceSysmemLowheapBlock *firstBlock; // 12
// followed by blocks
} SceSysmemLowheap;
/*
typedef struct SceSysmemHeapBlock {
struct SceSysmemHeapBlock *next, *prev; // 0, 4
// followed by lowheap
} SceSysmemHeapBlock;
typedef struct SceSysmemLowheapInfoBlock {
SceSysmemLowheapBlock *block;
u32 offset;
} SceSysmemLowheapInfoBlock;
typedef struct {
u32 size; // 0
u32 heapSize; // 4
u32 unkSize1; // 8
u32 unkSize2; // 12
u32 maxSize; // 16
u32 blockCount; // 20
SceSysmemLowheapInfoBlock infoBlocks[];
} SceSysmemLowheapInfo; // size: 24
*/
typedef struct {
int size; // 0
int partId; // 4
u32 partAddr; // 8
u32 partSize; // 12
SceSysmemHeapBlock *firstBlock; // 16
} SceSysmemHeap;
/*
typedef struct {
u32 size; // 0
char name[32]; // 4
int perm; // 36
int attr; // 40
int heapSize; // 44
int totalsize; // 48
int totalfreesize; // 52
int maxfreesize; // 56
int numheaps; // 60
void *heaps[];
} SceSysmemHeapInfo;
*/
SceSysmemHeap g_140D8;
#include <sysmem_kernel.h>
/*
@ -162,101 +61,15 @@ SceSysmemHeap g_140D8;
| | |
+-------| Block | blocks created through sceKernelAllocPartitionMemory() (SceSysmemMemoryBlock)
| Only holds size & addr | Has an UID, name "SceSysMemMemoryBlock"
+------------------------+ Some kind of "interface" to the SceSysmemBlock, without the internal information
+------------------------+ Some kind of "interface" to the SceSysmemSeg, without the internal information
*/
typedef struct {
unsigned used : 1; // 0
unsigned next : 6; /* next index */ // 1
unsigned offset : 25; /* offset (from the partition start, divided by 0x100) */ // 7
unsigned unk0_0 : 1; // 0
unsigned sizeLocked : 1; // 1
unsigned prev : 6; // 2
unsigned unk8 : 1; // 8
unsigned size : 23; /* size (divided by 0x100) */ // 9
} SceSysmemSeg; // size: 8
typedef struct {
SceSysmemCtlBlk *next; // 0
SceSysmemCtlBlk *prev; // 4
u16 segCount;
u16 unk10; // used segments?
u16 freeSeg; // 12 // points to a free segment id
u8 firstSeg; // 14
u8 lastSeg; // 15
SceSysmemBlock segs[30];
} SceSysmemCtlBlk; // size: 0x100 (control blocks are always placed at a 0x100-aligned address)
typedef struct SceSysmemMemoryPartition {
SceSysmemMemoryPartition *next; // 0
u32 addr; // 4
u32 size; // 8
s32 unk12;
SceSysmemCtlBlk *firstCtlBlk; // 16
SceSysmemCtlBlk *lastCtlBlk; // 20
s32 unk24;
} SceSysmemMemoryPartition;
/*
typedef s32 (*SceSysmemUidFunc)(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, s32 funcId, va_list ap);
typedef struct {
s32 id;
SceSysmemUidFunc func;
} SceSysmemUidLookupFunc;
typedef struct {
SceSysmemUidCB *PARENT0; // 0
SceSysmemUidCB *nextChild; // 4
SceSysmemUidCB *meta; // 8: the type UID
u32 uid; // 12
char *name; // 16
u8 childSize; // 20
u8 size; // 21
u16 attr; // 22
union {
SceSysmemUidCB *next; // 24
s32 numChild; // 24
} next;
SceSysmemUidCB *PARENT1; // 28
SceSysmemUidLookupFunc *funcTable; // 32
} SceSysmemUidCB; // size: 36
typedef struct {
SceSysmemUidCB *root; // 0
SceSysmemUidCB *metaRoot; // 4
SceSysmemUidCB *basic; // 8
s32 count; // 12
} SceSysmemUidList;
*/
SceSysmemUidList g_uidTypeList; // 145B0
typedef struct {
u32 addr;
u32 size;
} SceSysmemPartInfo;
typedef struct SceSysmemHoldElem {
struct SceSysmemHoldElem *next; // 0
struct SceSysmemHoldElem *prev; // 4
} SceSysmemHoldElem;
typedef struct {
SceSysmemHoldElem unk0; // 0
SceSysmemHoldElem unk8; // 8
u32 count1; // 16
u32 count2; // 20
} SceSysmemHoldHead; // size: 24
typedef struct {
SceSysmemHoldElem unk0; // 0
SceSysmemHoldElem unk8; // 8
SceSysmemUidCB *uid1; // 16
SceSysmemUidCB *uid0; // 20
} SceSysmemHoldElement;
typedef struct {
u32 memSize;
u32 unk4;
@ -272,59 +85,9 @@ typedef struct {
SceSysmemPartInfo extVshell; // 76
} SceSysmemPartTable;
typedef struct {
u32 memAddr; // 0
u32 memSize; // 4
SceSysmemMemoryPartition *main; // 8
SceSysmemMemoryPartition *other1; // 12
SceSysmemMemoryPartition *other2; // 16
SceSysmemMemoryPartition *vshell; // 20
SceSysmemMemoryPartition *scUser; // 24
SceSysmemMemoryPartition *meUser; // 28
SceSysmemMemoryPartition *extScKernel; // 32
SceSysmemMemoryPartition *extSc2Kernel; // 36
SceSysmemMemoryPartition *extMeKernel; // 40
SceSysmemMemoryPartition *extVshell; // 44
SceSysmemMemoryPartition *kernel; // 48
SceSysmemMemoryPartition *user; // 52
SceSysmemmemoryPartition *extKernel; // 56
u32 realMemSize; // 60
u32 unk64; // 64
} SceSysmemMemInfo;
SceKernelUsersystemLibWork g_1454C;
/*
typedef struct {
u32 size; // structure size
void *unk4;
void *unk8;
void *unk12;
} SceUsersystemLibWork;
*/
s32 *wmemset(s32 *src, s32 c, u32 n);
SceUsersystemLibWork g_1454C;
SceSysmemMemInfo g_145C0;
typedef struct {
u32 addr;
u32 size;
SceSysmemMemoryPartition *part;
} SceSysmemMemoryBlock; // size: 12; allocated space in partition
/*
typedef struct {
u32 size; // 0
char name[32]; // 4
u32 attr; // 36
u32 addr; // 40
u32 memSize; // 44
u32 sizeLocked; // 48
u32 used; // 52
} SceSysmemMemoryBlockInfo;
*/
typedef struct {
u32 size; // structure size (probably)
u32 addr;
} SceSysmemHeapAllocOption;
#endif

View File

@ -1,8 +1,62 @@
#include <sysmem_kdebug.h>
#include <sysmem_kernel.h>
#include <sysmem_sysclib.h>
#include "heap.h"
#include "intr.h"
#include "memory.h"
#include "partition.h"
typedef struct SceSysmemHoldElem {
struct SceSysmemHoldElem *next; // 0
struct SceSysmemHoldElem *prev; // 4
} SceSysmemHoldElem;
typedef struct {
SceSysmemHoldElem unk0; // 0
SceSysmemHoldElem unk8; // 8
u32 count1; // 16
u32 count2; // 20
} SceSysmemHoldHead; // size: 24
typedef struct {
SceSysmemHoldElem unk0; // 0
SceSysmemHoldElem unk8; // 8
SceSysmemUidCB *uid1; // 16
SceSysmemUidCB *uid0; // 20
} SceSysmemHoldElement;
s32 obj_no_op(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_delete2(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_name(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_type(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_isKindOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_isMemberOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_doseNotRecognize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
s32 obj_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap);
void InitUidBasic(SceSysmemUidCB *root, char *rootName, SceSysmemUidCB *metaRoot, char *metaRootName, SceSysmemUidCB *basic, char *basicName, SceSysmemUidCB *metaBasic, char *metaBasicName);
SceSysmemUidCB *search_UidType_By_Name(const char *name);
SceSysmemUidCB *search_UIDObj_By_Name_With_Type(const char *name, SceSysmemUidCB *type);
// 140D8
SceSysmemHeap g_140D8;
// 140EC
SceSysmemUidCB *HeapCB;
// 145AC
SceUID g_145AC;
// 145B0
SceSysmemUidList g_uidTypeList;
void InitUid(void)
{
SceSysmemHeapBlock *heapBlock = NULL;
int oldIntr = suspendIntr();
g_140EC.PARENT0 = NULL;
HeapCB->PARENT0 = NULL;
g_145AC = 0;
_CreateHeap(MpidToCB(1), 0x2000, 1, &heapBlock);
sceKernelProtectMemoryBlock(MpidToCB(1), heapBlock);
@ -12,8 +66,8 @@ void InitUid(void)
SceSysmemPartitionInfo part;
part.size = 16;
sceKernelQueryMemoryPartitionInfo(1, &part);
g_140D8.partAddr = part.addr;
g_140D8.partSize = part.size;
g_140D8.partAddr = part.startAddr;
g_140D8.partSize = part.memSize;
SceSysmemUidCB *root = _AllocHeapMemory(&g_140D8, sizeof(SceSysmemUidCB), 0);
// A7FC
memset(root, 0, sizeof(SceSysmemUidCB));
@ -32,15 +86,15 @@ void InitUid(void)
char *metaBasicName = _AllocHeapMemory(&g_140D8, strlen("MetaBasic") + 1, 0);
InitUidBasic(root, rootName, metaRoot, metaRootName, basic, basicName, metaBasic, metaBasicName);
HeapInit();
if (sceKernelCreateUID(g_145A4, "SceSystemMemoryManager", 0, &g_140EC) == 0)
if (sceKernelCreateUID(g_145A4, "SceSystemMemoryManager", 0, &HeapCB) == 0)
{
SceSysmemHeap *heap = (void*)&g_140EC + g_145A4->size * 4;
SceSysmemHeap *heap = UID_CB_TO_DATA(HeapCB, g_145A4, SceSysmemHeap);
heap->size = g_140D8.size;
heap->partId = g_140D8.partId;
heap->partSize = g_140D8.partSize;
heap->firstBlock = g_140D8.firstBlock;
heap->partAddr = g_140D8.partAddr;
g_145AC = g_140EC->uid;
g_145AC = HeapCB->uid;
}
// A968
resumeIntr(oldIntr);
@ -80,13 +134,13 @@ s32 FreeSceUIDobjectCB(SceSysmemUidCB *uid)
return 0;
}
u8 *AllocSceUIDnamestr(u8 *str1, u8 *str2)
char *AllocSceUIDnamestr(const char *str1, const char *str2)
{
u32 len1 = strnlen(str1, 31);
u32 len2 = strnlen(str2, 31);
if (len1 + len2 >= 32)
return NULL;
u8 *buf = _AllocHeapMemory(&g_140D8, len1 + len2 + 1, 0);
char *buf = _AllocHeapMemory(&g_140D8, len1 + len2 + 1, 0);
if (buf == NULL)
return buf;
memcpy(buf, str1, len1);
@ -146,7 +200,7 @@ s32 sceKernelCallUIDFunction(SceUID id, int funcId, ...)
return 0x800200CB;
}
// ACD8
SceSysmemUidFunc *func = NULL;
SceSysmemUidFunc func = NULL;
SceSysmemUidCB *parentUid;
sceKernelLookupUIDFunction(uid->meta, funcId, &func, &parentUid);
s32 ret;
@ -164,10 +218,10 @@ s32 sceKernelCallUIDObjFunction(SceSysmemUidCB *uid, s32 funcId, ...)
{
va_list ap;
va_start(ap, funcId);
SceSysmemUidFunc *func = NULL;
SceSysmemUidFunc func = NULL;
SceSysmemUidCB *parentUid;
s32 oldIntr = suspendIntr();
sceKernelLookupUIDFunction(uid->type, funcId, &func, &parentUid);
sceKernelLookupUIDFunction(uid->meta, funcId, &func, &parentUid);
s32 ret;
if (func == NULL) {
// ADCC
@ -180,15 +234,10 @@ s32 sceKernelCallUIDObjFunction(SceSysmemUidCB *uid, s32 funcId, ...)
return ret;
}
int sceKernelLookupUIDFunction(SceSysmemUidCB *uid, int id, void **func, SceSysmemUidCB **parentUidWithFunc)
int sceKernelLookupUIDFunction(SceSysmemUidCB *uid, int id, SceSysmemUidFunc *func, SceSysmemUidCB **parentUidWithFunc)
{
int oldIntr = suspendIntr();
*func = NULL;
if (uid == NULL) {
// AE54
resumeIntr(oldIntr);
return 0x800200CE;
}
// AE18
while (uid != NULL) {
if (uid->funcTable != NULL) {
@ -209,13 +258,16 @@ int sceKernelLookupUIDFunction(SceSysmemUidCB *uid, int id, void **func, SceSysm
uid = uid->PARENT1;
// AE4C
}
// AE54
resumeIntr(oldIntr);
return 0x800200CE;
}
s32 sceKernelCallUIDObjCommonFunction(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, s32 funcId, va_list ap)
{
SceSysmemUidCB *parentWithFunc = uidWithFunc;
s32 oldIntr = suspendIntr();
SceSysmemUidFunc *func;
SceSysmemUidFunc func;
sceKernelLookupUIDFunction(uidWithFunc->PARENT1, funcId, &func, &parentWithFunc);
s32 ret;
if (func == NULL) {
@ -250,20 +302,20 @@ int sceKernelCreateUIDtypeInherit(const char *parentName, const char *name, int
return 0x800200C9;
}
SceSysmemUidCB *uidType = AllocSceUIDtypeCB();
SceSysmemMetaUidType *metaUidType = AllocSceUIDtypeCB();
char *name = AllocSceUIDnamestr(name, "");
SceSysmemUidCB *metaUidType = AllocSceUIDtypeCB();
char *namePtr = AllocSceUIDnamestr(name, "");
char *metaName = AllocSceUIDnamestr("Meta", name);
if (name == NULL || metaName == NULL || uidType == NULL || metaUidType == NULL)
if (namePtr == NULL || metaName == NULL || uidType == NULL || metaUidType == NULL)
{
// B024
if (uidType != NULL)
FreeSceUIDtypeCB(uidType);
// B034
if (metaUidType != NULL)
FreeSceUIDTypeCB(metaUidType);
FreeSceUIDtypeCB(metaUidType);
// B044
if (name != NULL)
FreeSceUIDnamestr(name);
if (namePtr != NULL)
FreeSceUIDnamestr(namePtr);
// B054
if (metaName != NULL)
FreeSceUIDnamestr(metaName);
@ -272,7 +324,7 @@ int sceKernelCreateUIDtypeInherit(const char *parentName, const char *name, int
return 0x80020190;
}
// B0A4
parentUidType->meta->numChild++;
parentUidType->meta->next.numChild++;
uidType->PARENT0 = uidType;
uidType->uid = ((int)uidType << 5) | ((g_uidTypeList.count & 0x3F) << 1) | 1;
uidType->nextChild = uidType;
@ -287,12 +339,12 @@ int sceKernelCreateUIDtypeInherit(const char *parentName, const char *name, int
uidType->size = parentUidType->childSize;
metaUidType->childSize = 6;
metaUidType->size = 0;
uidType->name = name;
uidType->name = namePtr;
metaUidType->name = metaName;
uidType->next = g_uidTypeList.root->next;
uidType->next.next = g_uidTypeList.root->next.next;
uidType->PARENT1 = parentUidType;
g_uidTypeList.root->next = uidType;
metaUidType->numChild = 0;
g_uidTypeList.root->next.next = uidType;
metaUidType->next.numChild = 0;
metaUidType->PARENT1 = parentUidType->meta;
uidType->funcTable = funcTable;
*uidTypeOut = uidType;
@ -301,7 +353,7 @@ int sceKernelCreateUIDtypeInherit(const char *parentName, const char *name, int
return 0;
}
int sceKernelCreateUID(SceSysmemUidType *type, const char *name, char k1, SceSysmemUidCB **outUid)
int sceKernelCreateUID(SceSysmemUidCB *type, const char *name, char k1, SceSysmemUidCB **outUid)
{
if (type == NULL || name == NULL)
return 0x80020001;
@ -352,7 +404,7 @@ SceUID sceKernelSearchUIDbyName(const char *name, SceUID typeId)
uid = search_UIDObj_By_Name_With_Type(name, cur);
if (uid != NULL)
break;
cur = cur->next.next
cur = cur->next.next;
} while (cur != g_uidTypeList.root);
} else {
SceSysmemUidCB *typeUid = (SceSysmemUidCB*)(0x88000000 | (((u32)typeId >> 7) * 4));
@ -363,7 +415,7 @@ SceUID sceKernelSearchUIDbyName(const char *name, SceUID typeId)
return 0x800200CB;
}
// B3D8
if (typeUid->meta->meta != g_uidTypeList->metaRoot || typeUid->meta == g_uidTypeList.root) { // B404
if (typeUid->meta->meta != g_uidTypeList.metaRoot || typeUid->meta == g_uidTypeList.root) { // B404
// B3F4
resumeIntr(oldIntr);
return 0x800200C9;
@ -380,12 +432,12 @@ SceUID sceKernelSearchUIDbyName(const char *name, SceUID typeId)
SceSysmemUidCB *search_UidType_By_Name(const char *name)
{
SceSysmemUidCB *cur = g_uidTypeList->root;
SceSysmemUidCB *cur = g_uidTypeList.root;
// B47C
do
{
char *curStr = cur->name;
char *curName = name;
const char *curName = name;
if (name == curStr)
return cur;
if (name != NULL && curStr != NULL) {
@ -394,9 +446,9 @@ SceSysmemUidCB *search_UidType_By_Name(const char *name)
if (*(curName++) == '\0')
return cur;
}
cur = cur->next;
cur = cur->next.next;
// B4AC
} while (cur != g_uidTypeList->root);
} while (cur != g_uidTypeList.root);
return 0;
}
@ -424,6 +476,27 @@ SceSysmemUidCB *search_UIDObj_By_Name_With_Type(const char *name, SceSysmemUidCB
return 0;
}
// 13570
SceSysmemUidLookupFunc RootFuncs[] = {
{ 0xD310D2D9, obj_no_op },
{ 0x973A5367, obj_no_op },
{ 0x285422D4, obj_no_op },
{ 0x87089863, obj_do_delete },
{ 0x86D94883, obj_no_op },
{ 0xF0ADE1B6, obj_do_name },
{ 0x58D965CE, obj_do_type },
{ 0x9AFB14E2, obj_do_isKindOf },
{ 0xE19A43D1, obj_do_isMemberOf },
{ 0xB9970352, obj_do_doseNotRecognize },
{ 0, NULL }
};
// 135C8
SceSysmemUidLookupFunc MetaRootFuncs[] = {
{ 0x87089863, obj_no_op },
{ 0, NULL }
};
void InitUidRoot(SceSysmemUidCB *root, char *rootName, SceSysmemUidCB *metaRoot, char *metaRootName)
{
int oldIntr = suspendIntr();
@ -452,17 +525,17 @@ void InitUidRoot(SceSysmemUidCB *root, char *rootName, SceSysmemUidCB *metaRoot,
g_uidTypeList.metaRoot->next.numChild = 0;
g_uidTypeList.root->PARENT1 = NULL;
g_uidTypeList.metaRoot->PARENT1 = g_uidTypeList.root;
g_uidTypeList.root->funcTable = &g_13570;
g_uidTypeList.metaRoot->funcTable = &g_135C8;
g_uidTypeList.root->funcTable = RootFuncs;
g_uidTypeList.metaRoot->funcTable = MetaRootFuncs;
resumeIntr(oldIntr);
}
int _sceKernelCreateUIDtypeInherit_sub(SceSysmemUidCB *root, SceSysmemUidCB *basic, SceSysmemUidCB *metaBasic,
char *basicName, char *metaBasicName, int size, SceSysmemLookupFunc *funcTable,
SceSysmemLookupFunc *metaFuncTable, SceSysmemUidCB **outUidType)
char *basicName, char *metaBasicName, int size, SceSysmemUidLookupFunc *funcTable,
SceSysmemUidLookupFunc *metaFuncTable, SceSysmemUidCB **outUidType)
{
basic->meta = metaBasic;
root->metaRoot->numChild++;
root->meta->next.numChild++;
basic->PARENT0 = basic;
basic->uid = ((int)basic << 5) | ((g_uidTypeList.count & 0x3F) << 1) | 1;
basic->nextChild = basic;
@ -478,10 +551,10 @@ int _sceKernelCreateUIDtypeInherit_sub(SceSysmemUidCB *root, SceSysmemUidCB *bas
metaBasic->childSize = 6;
metaBasic->size = 0;
metaBasic->name = metaBasicName;
basic->next = g_uidTypeList.root->next;
basic->next.next = g_uidTypeList.root->next.next;
basic->PARENT1 = root;
g_uidTypeList.root->next = basic;
metaBasic->numChild = 0;
g_uidTypeList.root->next.next = basic;
metaBasic->next.numChild = 0;
metaBasic->PARENT1 = root->meta;
basic->funcTable = funcTable;
*outUidType = basic;
@ -531,9 +604,9 @@ s32 sceKernelGetUIDname(SceUID id, s32 len, char *out)
return 0x800200CB;
}
// B974
u8 *name = uidType->name;
char *name = uidType->name;
if (len >= 2) {
u8 lastChar = *(name++);
char lastChar = *(name++);
while (lastChar != '\0') { // B98C
len--;
*(out++) = lastChar;
@ -575,7 +648,7 @@ s32 sceKernelRenameUID(SceUID id, const char *name)
s32 sceKernelGetUIDtype(SceUID id)
{
SceSysmemUidCB *uid = 0x88000000 | (((u32)id >> 7) * 4);
SceSysmemUidCB *uid = (SceSysmemUidCB *)(0x88000000 | (((u32)id >> 7) * 4));
SceSysmemMemoryPartition *part = g_145C0.kernel;
if ((id & 0x80000001) != 1 || (u32)uid < part->addr ||
(u32)uid >= part->addr + part->size || uid->uid != id)
@ -591,7 +664,7 @@ s32 sceKernelDeleteUID(SceUID id)
s32 sceKernelGetUIDcontrolBlock(SceUID id, SceSysmemUidCB **uidOut)
{
SceSysmemUidCB *uid = 0x88000000 | (((u32)id >> 7) << 2);
SceSysmemUidCB *uid = (SceSysmemUidCB *)(0x88000000 | (((u32)id >> 7) << 2));
SceSysmemMemoryPartition *part = g_145C0.kernel;
if ((id & 0x80000001) != 1 || (u32)uid < part->addr ||
(u32)uid >= part->addr + part->size || uid->uid != id)
@ -600,7 +673,7 @@ s32 sceKernelGetUIDcontrolBlock(SceUID id, SceSysmemUidCB **uidOut)
return 0;
}
s32 sceKernelGetUIDcontrolBlockWithType(SceUID id, SceSysmemUidType *type, SceSysmemUidCB **outUid)
s32 sceKernelGetUIDcontrolBlockWithType(SceUID id, SceSysmemUidCB *type, SceSysmemUidCB **outUid)
{
s32 oldIntr = suspendIntr();
SceSysmemUidCB *uid = (SceSysmemUidCB*)(0x88000000 | (((u32)id >> 7) * 4));
@ -636,12 +709,12 @@ s32 sceKernelPrintUidListAll(void)
{
s32 oldIntr = suspendIntr();
Kprintf("<< UID list >>\n");
SceSysmemUidCB *uid = g_uidTypeList->root->next.next;
SceSysmemUidCB *uid = g_uidTypeList.root->next.next;
while (uid != g_uidTypeList.basic) { // BD4C
Kprintf("\n[%s] UID 0x%08x (attribute 0x%x)\n", uid->name, uid->uid, uid->attr);
if (uid->nextChild == uid) {
// BDE4
Kprinft(" <No UID objects>\n");
Kprintf(" <No UID objects>\n");
}
// BD68
SceSysmemUidCB *curChild = uid->nextChild;
@ -663,12 +736,12 @@ SceSysmemUidList *sceKernelGetUidmanCB(void)
return &g_uidTypeList;
}
s32 obj_no_op(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 obj_no_op(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap __attribute__((unused)))
{
return uid->uid;
}
s32 obj_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 obj_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap __attribute__((unused)))
{
uid->meta = NULL;
uid->PARENT0->nextChild = uid->nextChild;
@ -683,7 +756,7 @@ s32 obj_do_delete(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId,
s32 obj_do_delete2(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
{
SceSysmemHoldHead *head = *(SceSysmemHoldHead**)((void*)uid + g_uidTypeList.basic->size * 4);
SceSysmemHoldHead *head = *UID_CB_TO_DATA(uid, g_uidTypeList.basic, SceSysmemHoldHead *);
if (head != NULL) {
if (head->count1 > 0) {
SceSysmemHoldElem *cur = head->unk0.next;
@ -700,9 +773,9 @@ s32 obj_do_delete2(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId,
SceSysmemHoldElem *formerNext0 = elem->unk0.next;
SceSysmemHoldElem *formerPrev0 = elem->unk0.prev;
formerNext0->prev = formerPrev0;
elem->unk0.prev = elem;
elem->unk0.prev = &elem->unk0;
formerPrev0->next = formerNext0;
elem->unk0.next = elem;
elem->unk0.next = &elem->unk0;
FreeSceUIDHoldElement(elem);
cur = formerNext0;
@ -713,10 +786,10 @@ s32 obj_do_delete2(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId,
SceSysmemHoldElem *cur = head->unk8.next;
while (cur != &head->unk8) {
// BF30
SceSysmemHoldElement *elem = (SceSysmemHoldElement*)(cur - 8);
SceSysmemHoldElement *elem = (SceSysmemHoldElement*)((void*)cur - 8);
SceSysmemHoldElem *formerNext8 = elem->unk8.next;
SceSysmemHoldElem *formerPrev8 = elem->unk8.prev;
formerNext8->prev = elem->unk8.prev;
formerNext8->prev = formerPrev8;
elem->unk8.prev = &elem->unk8;
formerPrev8->next = formerNext8;
elem->unk8.next = &elem->unk8;
@ -739,13 +812,13 @@ s32 obj_do_delete2(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId,
return sceKernelCallUIDObjCommonFunction(uid, uidWithFunc, funcId, ap);
}
s32 obj_do_name(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 obj_do_name(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
s32 length = va_arg(ap, s32);
u8 *str = va_arg(ap, s8*);
u8 *outStr = uid->name;
char *str = va_arg(ap, char*);
char *outStr = uid->name;
if (length >= 2) {
u8 c = *(outStr++);
char c = *(outStr++);
// BFE4
while (c != 0) {
length--;
@ -760,15 +833,15 @@ s32 obj_do_name(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va
return 0;
}
s32 obj_do_type(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 obj_do_type(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap __attribute__((unused)))
{
return uid->meta->uid;
}
s32 obj_do_isKindOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 obj_do_isKindOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
SceUID typeId = va_arg(ap, SceUID);
SceSysmemUidCB *typeUid = (SceSysmemUidCB*)(0x88000000 | (((u32)a3 >> 7) * 4));
SceSysmemUidCB *typeUid = (SceSysmemUidCB*)(0x88000000 | (((u32)typeId >> 7) * 4));
SceSysmemMemoryPartition *part = g_145C0.kernel;
if ((typeId & 0x80000001) != 1 || (u32)typeUid < part->addr ||
(u32)typeUid >= part->addr + part->size || typeUid->uid != typeId)
@ -780,7 +853,7 @@ s32 obj_do_isKindOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId
return (cur == typeUid);
}
s32 obj_do_isMemberOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 obj_do_isMemberOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
SceUID id = va_arg(ap, SceUID);
SceSysmemUidCB *uid2 = (SceSysmemUidCB*)(0x88000000 | (((u32)id >> 7) << 2));
@ -791,7 +864,7 @@ s32 obj_do_isMemberOf(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int func
return (uid->meta == uid2);
}
s32 obj_do_doseNotRecognize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
s32 obj_do_doseNotRecognize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc __attribute__((unused)), int funcId __attribute__((unused)), va_list ap)
{
Kprintf("WARNING: %s of %s not support 0x%x key\n", uid->name, uid->meta->name, va_arg(ap, s32));
return 0x800200CE;
@ -802,15 +875,16 @@ s32 sceKernelIsHold(SceSysmemUidCB *uid0, SceSysmemUidCB *uid1)
s32 oldIntr = suspendIntr();
if (sceKernelIsKindOf(uid1, g_uidTypeList.basic) != 0 &&
sceKernelIsKindOf(uid0, g_uidTypeList.basic) != 0) {
SceSysmemHoldHead *head2 = *(SceSysmemHoldHead**)((void*)uid1 + g_uidTypeList.basic->size * 4);
SceSysmemHoldHead *head1 = *(SceSysmemHoldHead**)((void*)uid0 + g_uidTypeList.basic->size * 4);
SceSysmemHoldElement *cur;
SceSysmemHoldHead *head2 = *UID_CB_TO_DATA(uid1, g_uidTypeList.basic, SceSysmemHoldHead *);
SceSysmemHoldHead *head1 = *UID_CB_TO_DATA(uid0, g_uidTypeList.basic, SceSysmemHoldHead *);
SceSysmemHoldElem *cur;
if (head2->count2 >= head1->count1) {
cur = head1->unk0.next;
// C258
// C264
while (cur != &head1->unk0) {
if (cur->uid1 == uid1) {
SceSysmemHoldElement *elem = (SceSysmemHoldElement*)cur;
if (elem->uid1 == uid1) {
// C248 dup
resumeIntr(oldIntr);
return 1;
@ -819,8 +893,9 @@ s32 sceKernelIsHold(SceSysmemUidCB *uid0, SceSysmemUidCB *uid1)
}
} else {
cur = head2->unk8.next;
while (cur != &head1->unk0) {
if ((SceSysmemHoldElement*)((void*)cur - 8)->uid0 == uid0) {
while (cur != &head1->unk8) {
SceSysmemHoldElement *elem = (SceSysmemHoldElement*)((void*)cur - 8);
if (elem->uid0 == uid0) {
// C248 dup
resumeIntr(oldIntr);
return 1;
@ -859,8 +934,8 @@ s32 sceKernelHoldUID(SceUID id0, SceUID id1)
resumeIntr(oldIntr);
return 0x800200CF;
}
SceSysmemHoldHead **headPtr0 = (void*)uid0 + g_uidTypeList.basic->size * 4;
SceSysmemHoldHead **headPtr1 = (void*)uid1 + g_uidTypeList.basic->size * 4;
SceSysmemHoldHead **headPtr0 = UID_CB_TO_DATA(uid0, g_uidTypeList.basic, SceSysmemHoldHead *);
SceSysmemHoldHead **headPtr1 = UID_CB_TO_DATA(uid1, g_uidTypeList.basic, SceSysmemHoldHead *);
if (*headPtr0 == NULL) {
// C4B4
head0 = AllocSceUIDHoldHead();
@ -929,7 +1004,7 @@ s32 sceKernelReleaseUID(SceUID id0, SceUID id1)
{
s32 oldIntr = suspendIntr();
SceSysmemUidCB *uid0 = (SceSysmemUidCB*)(0x88000000 | (((u32)id0 >> 7) * 4));
SceSysmemUidCB *uid1 = 0x88000000 | (((u32)id1 >> 7) * 4);
SceSysmemUidCB *uid1 = (SceSysmemUidCB*)(0x88000000 | (((u32)id1 >> 7) * 4));
if (id1 < 1 || id0 < 1 || uid1->uid != id1 || uid0->uid != id0) {
// C554
resumeIntr(oldIntr);
@ -942,10 +1017,10 @@ s32 sceKernelReleaseUID(SceUID id0, SceUID id1)
return 0x800200CE;
}
// C5CC
SceSysmemHoldHead **headPtr1 = (void*)uid1 + g_uidTypeList.basic->size * 4;
SceSysmemHoldHead **headPtr1 = UID_CB_TO_DATA(uid1, g_uidTypeList.basic, SceSysmemHoldHead *);
SceSysmemHoldHead *head1 = *headPtr1;
SceSysmemHoldElem *cur = head1->unk8.next;
SceSysmemHoldhead **headPtr0 = (void*)uid0 + g_uidTypeList.basic->size * 4;
SceSysmemHoldHead **headPtr0 = UID_CB_TO_DATA(uid0, g_uidTypeList.basic, SceSysmemHoldHead *);
SceSysmemHoldElement *elem = (void*)cur - 8;
// C5F0
while (cur != &head1->unk8) {
@ -988,20 +1063,27 @@ s32 sceKernelReleaseUID(SceUID id0, SceUID id1)
return 0;
}
// 135D8
SceSysmemUidLookupFunc BasicFuncs[] = {
{ 0xD310D2D9, obj_do_initialize },
{ 0x87089863, obj_do_delete2 },
{ 0, NULL }
};
void InitUidBasic(SceSysmemUidCB *root, char *rootName, SceSysmemUidCB *metaRoot, char *metaRootName, SceSysmemUidCB *basic, char *basicName, SceSysmemUidCB *metaBasic, char *metaBasicName)
{
int oldIntr = suspendIntr();
InitUidRoot(root, rootName, metaRoot, metaRootName);
strcpy(basicName, "Basic");
strcpy(metaBasicName, "MetaBasic");
_sceKernelCreateUIDtypeInherit_sub(g_uidTypeList->root, basic, metaBasic, basicName, metaBasicName, 4, &g_135D8, 0, &g_uidTypeList->basic);
_sceKernelCreateUIDtypeInherit_sub(g_uidTypeList.root, basic, metaBasic, basicName, metaBasicName, 4, BasicFuncs, 0, &g_uidTypeList.basic);
resumeIntr(oldIntr);
}
s32 obj_do_initialize(SceSysmemUidCB *uid, SceSysmemUidCB *uidWithFunc, int funcId, va_list ap)
{
sceKernelCallUIDObjCommonFunction(uid, uidWithFunc, funcId, ap);
*(SceSysmemHoldHead**)((void*)uid + g_uidTypeList.basic->size * 4) = NULL;
*UID_CB_TO_DATA(uid, g_uidTypeList.basic, SceSysmemHoldHead *) = NULL;
return uid->uid;
}

View File

@ -1,28 +1,12 @@
#include <common_imp.h>
typedef struct {
u32 count;
u32 state[624];
} SceKernelUtilsMt19937Context;
#include <sysmem_sysclib.h>
#include <sysmem_utils_kernel.h>
typedef struct
{
u32 h[4];
u32 pad;
u16 usRemains;
u16 usComputed;
u64 ullTotalLen;
u8 buf[64];
} SceKernelUtilsMd5Context;
#include "start.h"
typedef struct
{
u32 h[5];
u16 usRemains;
u16 usComputed;
u64 ullTotalLen;
u8 buf[64];
} SceKernelUtilsSha1Context;
u32 sceKernelUtilsMt19937UInt(SceKernelUtilsMt19937Context *ctx);
const void *sceKernelGzipGetCompressedData(const void *buf);
int sceKernelDcacheInvalidateRangeForUser(const void *p, u32 size)
{
@ -126,7 +110,7 @@ int sceKernelUtilsMd5BlockUpdate(SceKernelUtilsMd5Context *ctx, u8 *data, u32 si
}
// EDD4
numTotal -= 64;
sub_1710(ctx, ctx->buf);
md5BlockUpdate(ctx, ctx->buf);
}
// EDEC
if (numTotal != 0) {
@ -141,7 +125,7 @@ int sceKernelUtilsMd5BlockUpdate(SceKernelUtilsMd5Context *ctx, u8 *data, u32 si
int sceKernelUtilsMd5BlockResult(SceKernelUtilsMd5Context *ctx, u8 *digest)
{
char buf[64];
u8 buf[64];
int oldK1 = pspShiftK1();
if (!pspK1PtrOk(ctx) || !pspK1PtrOk(digest)
|| ctx == NULL || digest == NULL) {
@ -164,7 +148,7 @@ int sceKernelUtilsMd5BlockResult(SceKernelUtilsMd5Context *ctx, u8 *digest)
if (remain >= 56)
{
// EFC0
sub_1710(ctx, buf);
md5BlockUpdate(ctx, buf);
memset(buf, 0, 64);
}
// EF1C
@ -175,7 +159,7 @@ int sceKernelUtilsMd5BlockResult(SceKernelUtilsMd5Context *ctx, u8 *digest)
// EF74
buf[i + 56] = num >> (i * 8);
}
sub_1710(ctx, buf);
md5BlockUpdate(ctx, buf);
ctx->usComputed = 1;
memset(ctx->buf, 0, 64);
}
@ -277,9 +261,9 @@ int sceKernelUtilsSha1BlockUpdate(SceKernelUtilsSha1Context *ctx, u8 *data, u32
// F26C
int i;
for (i = 0; i < 16; i++)
buf[i] = WSBW(buf[i]);
buf[i] = pspWsbw(buf[i]);
total -= 64;
sub_1870(buf, ctx);
sha1BlockUpdate((u8 *)buf, ctx);
}
// F2A4
if (total != 0) {
@ -319,8 +303,8 @@ int sceKernelUtilsSha1BlockResult(SceKernelUtilsSha1Context *ctx, u8 *digest)
{
// F3D8
for (i = 0; i < 16; i++)
buf[i] = WSBW(buf[i]);
sub_1870(buf, ctx->h);
buf[i] = pspWsbw(buf[i]);
sha1BlockUpdate((u8 *)buf, ctx);
memset(buf, 0, 64);
}
// F410
@ -328,11 +312,11 @@ int sceKernelUtilsSha1BlockResult(SceKernelUtilsSha1Context *ctx, u8 *digest)
((char*)buf)[i + 56] = ctx->ullTotalLen >> (56 - i * 8);
// F480
for (i = 0; i < 16; i++)
buf[i] = WSBW(buf[i]);
sub_1870(buf, ctx);
buf[i] = pspWsbw(buf[i]);
sha1BlockUpdate((u8 *)buf, ctx);
// F4B0
for (i = 0; i < 5; i++)
ctx->h[i] = WSBW(ctx->h[i]);
ctx->h[i] = pspWsbw(ctx->h[i]);
ctx->usComputed = 1;
memset(ctx->buf, 0, 64);
}
@ -351,7 +335,7 @@ int sceKernelUtilsSha1Digest(u8 *data, u32 size, u8 *digest)
pspSetK1(oldK1);
return 0x800200D3;
}
sub_1A40(data, size, digest);
sha1Digest(data, size, digest);
pspSetK1(oldK1);
return 0;
}
@ -406,11 +390,17 @@ u32 sceKernelUtilsMt19937UInt(SceKernelUtilsMt19937Context *ctx)
if (!pspK1PtrOk(ctx))
ret = 0x800200D3;
else
ret = sub_1CF0(ctx);
ret = mt19937UInt(ctx);
pspSetK1(oldK1);
return ret;
}
typedef int clock_t;
typedef int time_t;
struct timeval;
struct timezone;
typedef clock_t (*ClockHandler)(void);
typedef time_t (*TimeHandler)(time_t *t);
typedef int (*GettimeofdayHandler)(struct timeval *tp, struct timezone *tzp);
@ -488,29 +478,29 @@ int sceKernelRtcGetTick(u64 *tick)
return g_rtctick(tick);
}
int sceKernelGzipDecompress(u8 *dest, u32 destSize, const u8 *src, u32 *unk)
int sceKernelGzipDecompress(u8 *dest, u32 destSize, const void *src, u32 *crc32)
{
void *buf = sceKernelGzipGetCompressedData(src);
void *unkPtr;
int unkBuf[4];
const void *buf = sceKernelGzipGetCompressedData(src);
void *crcPtr;
int crcBuf[4];
if (buf == NULL)
return 0x80020001;
if (src[2] != 8)
if (((char*)src)[2] != 8)
return 0x80000004;
int ret = sceKernelDeflateDecompress(dest, destSize, buf, &unkPtr);
int ret = sceKernelDeflateDecompress(dest, destSize, buf, &crcPtr);
if (ret < 0)
return ret;
memcpy(unkBuf, unkPtr, 8);
if (ret != unkBuf[1])
memcpy(crcBuf, crcPtr, 8);
if (ret != crcBuf[1])
return 0x80000108;
if (unk != NULL)
*unk = unkBuf[0];
if (crc32 != NULL)
*crc32 = crcBuf[0];
return ret;
}
int sceKernelGzipGetInfo(char *buf, char **extra, char **name, char **comment, short *crc16, char **compressedData)
int sceKernelGzipGetInfo(const void *buf, const void **extra, const char **name, const char **comment, u16 *crc16, const void **compressedData)
{
char *curBuf = buf + 10;
const char *curBuf = buf + 10;
u8 header[10];
if (extra != NULL)
*extra = NULL;
@ -573,32 +563,32 @@ int sceKernelGzipGetInfo(char *buf, char **extra, char **name, char **comment, s
return 0;
}
char *sceKernelGzipGetCompressedData(char *buf)
const void *sceKernelGzipGetCompressedData(const void *buf)
{
char *data;
const void *data;
if (sceKernelGzipGetInfo(buf, NULL, NULL, NULL, NULL, &data) < 0)
return NULL;
return data;
}
int sceKernelGzipIsValid(u8 *buf)
int sceKernelGzipIsValid(const void *buf)
{
if (buf[0] == 0x1F && buf[1] == 0x8B)
if (((u8*)buf)[0] == 0x1F && ((u8*)buf)[1] == 0x8B)
return 1;
return 0;
}
char *sceKernelGzipGetName(char *buf)
const char *sceKernelGzipGetName(const void *buf)
{
char *name;
const char *name;
if (sceKernelGzipGetInfo(buf, NULL, &name, NULL, NULL, NULL) < 0)
return NULL;
return name;
}
char *sceKernelGzipGetComment(char *buf)
const char *sceKernelGzipGetComment(const void *buf)
{
char *comment;
const char *comment;
if (sceKernelGzipGetInfo(buf, NULL, NULL, &comment, NULL, NULL) < 0)
return NULL;
return comment;