Skip to content

Commit

Permalink
ñmatch malloc,link memtrk
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakxo committed Mar 6, 2023
1 parent e6af76e commit 771ffca
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 123 deletions.
183 changes: 93 additions & 90 deletions config/dol_slices.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,93 @@
#dolphin/os/__start.c:
# .init: [0x80003100, 0x80003354] can't link because there's two mains
#dolphin/os/__ppc_eabi_init.cpp:
# .init: [0x80003354, 0x800033a8]
# .text: [0x8007FDFC, 0x8007fe90]
runtime/__mem.c:
.init: [0x800033a8, 0x800034e0]
#TRK/mem_TRK.c:
# .init: [0x800034e0, 0x80003510]
asm/__exception.s:
.init: [0x80003534, 0x80005468]
jaudio_NES/dummyprobe.c:
.text: [0x800083f8, 0x80008400]
#jaudio_NES/verysimple.c:
# .text: [0x80008400, 0x80008480]
# .sdata: [0x80217b80, 0x80217b88]
libforest/ReconfigBATs.c:
.text: [0x8005adac, 0x8005aed4]
#libu64/debug.c: //not match
# .text: [0x8005aed4, 0x8005af30]
# .data: [0x800dc7c8, 0x800dc7f0]
#libu64/gfxprint.c: specify ranges later
libc64/aprintf.c:
.text: [0x8005cbdc, 0x8005cc14]
#libc64/math64.c: //not match
# .text: [0x8005cc14, 0x8005cccc]
# .sdata2: [0x80219118, 0x80219130]
libc64/qrand.c:
.text: [0x8005cccc, 0x8005cd64]
.sdata: [0x80217de8, 0x80217df0]
.sbss: [0x80218640, 0x80218648]
.sdata2: [0x80219130, 0x80219138]
#libultra/ultra.c: won't link
# .text: [0x8005d01c, 0x8005d15c]
# .bss: [0x80206f60, 0x80206fa0]
#libultra/gu/scale.c:
# .text: [0x8005e7d4, 0x8005e860]
# .sdata2: [0x80219208, 0x80219210]
#libultra/gu/translate.c:
# .text: [0x8005e8ac, 0x8005e918]
libultra/gu/sins.c:
.text: [0x8005e860, 0x8005e8ac]
.data: [0x800dd360, 0x800ddb60]
#libultra/xldtob.c:
# .text: [0x8005e918, 0x8005f2a0]
# .rodata: [0x800ab110, 0x800ab158]
# .sdata: [0x80217df8, 0x80217e08]
# .sdata2: [0x80219210, 0x80219230]
#libultra/xlitob.c:
# .text: [0x8005f2a0, 0x8005f4cc]
# .data: [0x800ddb60, 0x800ddb88]
#libultra/xprintf.c:
# .text: [0x8005f4cc, 0x8005ff74]
# .rodata: [0x800ab158, 0x800ab170]
# .data: [0x800ddb88, 0x800ddd20]
# .sdata: [0x80217e08, 0x80217e10]
# .sdata2: [0x80219230, 0x80219238]
JSystem/JKernel/JKRHeap.cpp:
.text: [0x80063748, 0x80064028]
.data: [0x800ddf20, 0x800ddf98]
.sdata: [0x80217e58, 0x80217e80]
.sbss: [0x802186d8, 0x80218700]
JSystem/JKernel/JKRDisposer.cpp:
.text: [0x80065aa0, 0x80065b8c]
.data: [0x800de3a8, 0x800de3c0]
.sdata: [0x80217ec0, 0x80217ec8]
dolphin/BASE/ppcarch.c:
.text: [0x8007867c, 0x80078718]
dolphin/os/OSArena.c:
.text: [0x8007988c, 0x800798ac]
.sdata: [0x80218178, 0x80218180]
.sbss: [0x802188f8, 0x80218900]
#dolphin/os/OSCache.c:
# .text: [0x80079b40, 0x8007a01c]
# .data: [0x800dfa00, 0x800dfc30]
#dolphin/os/OSDisableInterrupts.c:
# .text: [0x8007ac24, 0x8007ac38]
dolphin/os/OSEnableInterrupts.c:
.text: [0x8007ac38, 0x8007ac4c]
dolphin/os/OSRestoreInterrupts.c:
.text: [0x8007ac4c, 0x8007ac70]
MSL_C/rand.c:
.text: [0x8009f46c, 0x8009f494]
.sdata: [0x80218260, 0x80218268]
dolphin/odenotstub/odenotstub.c:
.text: [0x800a9770, 0x800a9780]
dolphin/amcstubs/AmcExi2Stubs.c:
.text: [0x800a8cc0, 0x800a8cf0]
dolphin/gx/GXStubs.c:
.text: [0x800998d4, 0x800998d8]
#dolphin/os/__start.c:
# .init: [0x80003100, 0x80003354]
#dolphin/os/__ppc_eabi_init.cpp:
# .init: [0x80003354, 0x800033a8]
# .text: [0x8007FDFC, 0x8007fe90]
runtime/__mem.c:
.init: [0x800033a8, 0x800034e0]
TRK/mem_TRK.c:
.init: [0x800034e0, 0x80003534]
asm/__exception.s:
.init: [0x80003534, 0x80005468]
jaudio_NES/dummyprobe.c:
.text: [0x800083f8, 0x80008400]
#jaudio_NES/verysimple.c:
# .text: [0x80008400, 0x80008480]
# .sdata: [0x80217b80, 0x80217b88]
libforest/ReconfigBATs.c:
.text: [0x8005adac, 0x8005aed4]
#libu64/debug.c: //not match
# .text: [0x8005aed4, 0x8005af30]
# .data: [0x800dc7c8, 0x800dc7f0]
#libu64/gfxprint.c: specify ranges later
libc64/aprintf.c:
.text: [0x8005cbdc, 0x8005cc14]
#libc64/math64.c: //not match
# .text: [0x8005cc14, 0x8005cccc]
# .sdata2: [0x80219118, 0x80219130]
libc64/qrand.c:
.text: [0x8005cccc, 0x8005cd64]
.sdata: [0x80217de8, 0x80217df0]
.sbss: [0x80218640, 0x80218648]
.sdata2: [0x80219130, 0x80219138]
#libc64/malloc.c:
# .text: [0x8005cf08, 0x8005d01c]
# .bss: [0x80206F30, 0x80206F60]
#libultra/ultra.c: won't link
# .text: [0x8005d01c, 0x8005d15c]
# .bss: [0x80206f60, 0x80206fa0]
#libultra/gu/scale.c:
# .text: [0x8005e7d4, 0x8005e860]
# .sdata2: [0x80219208, 0x80219210]
#libultra/gu/translate.c:
# .text: [0x8005e8ac, 0x8005e918]
libultra/gu/sins.c:
.text: [0x8005e860, 0x8005e8ac]
.data: [0x800dd360, 0x800ddb60]
#libultra/xldtob.c:
# .text: [0x8005e918, 0x8005f2a0]
# .rodata: [0x800ab110, 0x800ab158]
# .sdata: [0x80217df8, 0x80217e08]
# .sdata2: [0x80219210, 0x80219230]
#libultra/xlitob.c:
# .text: [0x8005f2a0, 0x8005f4cc]
# .data: [0x800ddb60, 0x800ddb88]
#libultra/xprintf.c:
# .text: [0x8005f4cc, 0x8005ff74]
# .rodata: [0x800ab158, 0x800ab170]
# .data: [0x800ddb88, 0x800ddd20]
# .sdata: [0x80217e08, 0x80217e10]
# .sdata2: [0x80219230, 0x80219238]
JSystem/JKernel/JKRHeap.cpp:
.text: [0x80063748, 0x80064028]
.data: [0x800ddf20, 0x800ddf98]
.sdata: [0x80217e58, 0x80217e80]
.sbss: [0x802186d8, 0x80218700]
JSystem/JKernel/JKRDisposer.cpp:
.text: [0x80065aa0, 0x80065b8c]
.data: [0x800de3a8, 0x800de3c0]
.sdata: [0x80217ec0, 0x80217ec8]
dolphin/BASE/ppcarch.c:
.text: [0x8007867c, 0x80078718]
dolphin/os/OSArena.c:
.text: [0x8007988c, 0x800798ac]
.sdata: [0x80218178, 0x80218180]
.sbss: [0x802188f8, 0x80218900]
#dolphin/os/OSCache.c:
# .text: [0x80079b40, 0x8007a01c]
# .data: [0x800dfa00, 0x800dfc30]
#dolphin/os/OSDisableInterrupts.c:
# .text: [0x8007ac24, 0x8007ac38]
dolphin/os/OSEnableInterrupts.c:
.text: [0x8007ac38, 0x8007ac4c]
dolphin/os/OSRestoreInterrupts.c:
.text: [0x8007ac4c, 0x8007ac70]
MSL_C/rand.c:
.text: [0x8009f46c, 0x8009f494]
.sdata: [0x80218260, 0x80218268]
dolphin/odenotstub/odenotstub.c:
.text: [0x800a9770, 0x800a9780]
dolphin/amcstubs/AmcExi2Stubs.c:
.text: [0x800a8cc0, 0x800a8cf0]
dolphin/gx/GXStubs.c:
.text: [0x800998d4, 0x800998d8]
12 changes: 7 additions & 5 deletions config/symbols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ global:
0x80005cf0: fault_callback_vimode
0x80005dc0: fault_callback_scroll
0x80006004: adjustOSArena
0x800060f8: main
0x8000663c: ReportDiskID__Fv
0x8000665c: JW_UpdateVideoMode
0x800067b4: JW_SetProgressiveMode
Expand Down Expand Up @@ -7895,6 +7896,7 @@ global:
0x80407A78: lbRk_HarvestMoonDay
0x80407AE8: mainproc
0x80407C70: entry
0x80407CB9: foresta_main
0x80407CF4: padmgr_LockSerialMesgQ
0x80407D30: padmgr_UnlockSerialMesgQ
0x80407D64: padmgr_LockContData
Expand Down Expand Up @@ -52864,10 +52866,10 @@ src/dvdfs.c:
0x802189d8: BootInfo
src/OSResetSW.c:
0x80218938: LastState
src/boot.c:
0x800060f8: main
rel/main.c:
0x80407CB9: main
#src/boot.c:
# 0x800060f8: main
#rel/main.c:
# 0x80407CB9: main
rel/ac_quest_talk_island.c:
0x8048D769: aQMgr_init_normal_info
0x8048D7A5: aQMgr_set_number_free_str
Expand Down Expand Up @@ -58146,4 +58148,4 @@ rel/irqmgr.c:
0x812F357C: this
foresta.rel:
0x80641254: _ctors
0x80641258: _dtors
0x80641258: _dtors
8 changes: 4 additions & 4 deletions include/dolphin/os/__ppc_eabi_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ typedef struct ExtabIndexInfo {
u32 codeSize; // at 0x10
} ExtabIndexInfo;

__declspec(section ".init") extern const RomSection _rom_copy_info[];
__declspec(section ".init") extern const BssSection _bss_init_info[];
__declspec(section ".init") extern const ExtabIndexInfo _eti_init_info[];
__declspec(section ".init") extern RomSection _rom_copy_info[];
__declspec(section ".init") extern BssSection _bss_init_info[];
__declspec(section ".init") extern ExtabIndexInfo _eti_init_info[];

#ifdef __cplusplus
}
#endif
#endif
#endif
40 changes: 40 additions & 0 deletions include/libc64/osmalloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef OS_MALLOC_H
#define OS_MALLOC_H
#include "types.h"
#include "libultra/osThread.h"
#include "libultra/osMesg.h"
#include "libultra/u64types.h"

struct ArenaNode;

typedef struct Arena {
/* 0x00 */ struct ArenaNode* head;
/* 0x04 */ void* start;
/* 0x08 */ OSMesgQueue lockQueue;
/* 0x20 */ u8 unk_20;
/* 0x21 */ u8 isInit;
/* 0x22 */ u8 flag;
} Arena; // size = 0x24

typedef struct ArenaNode {
/* 0x00 */ s16 magic;
/* 0x02 */ s16 isFree;
/* 0x04 */ u32 size;
/* 0x08 */ struct ArenaNode* next;
/* 0x0C */ struct ArenaNode* prev;
/* 0x10 */ const char* filename;
/* 0x14 */ s32 line;
/* 0x18 */ OSId threadId;
/* 0x1C */ Arena* arena;
/* 0x20 */ OSTime time;
/* 0x28 */ u8 unk_28[0x30-0x28]; // probably padding
} ArenaNode; // size = 0x30

void* __osMalloc(Arena*, size_t);
void __osFree(Arena*, void*);
void __osDisplayArena(Arena*);
void __osGetFreeArena(Arena*, u32*, u32*, u32*);
void __osMallocInit(Arena*, void*, u32);
void __osMallocCleanup(Arena*);

#endif
18 changes: 18 additions & 0 deletions include/libultra/osMesg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef OS_MESG_H
#define OS_MESG_H

#include "types.h"
#include "dolphin/os/OSThread.h"

typedef void* OSMesg;

typedef struct OSMesgQueue {
/* 0x00 */ OSThread* mtqueue;
/* 0x04 */ OSThread* fullqueue;
/* 0x08 */ s32 validCount;
/* 0x0C */ s32 first;
/* 0x10 */ s32 msgCount;
/* 0x14 */ OSMesg* msg;
} OSMesgQueue; // size = 0x18

#endif
5 changes: 3 additions & 2 deletions include/libultra/osThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define LOS_THREAD_H

#include "types.h"
#include "dolphin/OSThread.h"
#include "dolphin/os/OSThread.h"

typedef s32 OSPri;
typedef s32 OSId;



OSId osGetThreadId(OSThread*);

#endif
#endif
2 changes: 2 additions & 0 deletions include/libultra/u64types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "types.h"

typedef u64 OSTime;

typedef struct {
u32 r:8;
u32 g:8;
Expand Down
14 changes: 7 additions & 7 deletions src/TRK/mem_TRK.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ __declspec(section ".init") void* TRK_memset(void* dst, int val, size_t size){
return dst;
}

__declspec(section ".init") void* TRK_memcpy(void* dst, const void* src, size_t size){
const u8* s = (const u8*)src -1;
u8* d = (u8*)dst -1;
__declspec(section ".init") void *TRK_memcpy(void *dst, const void *src, size_t n)
{
const unsigned char *s = (const unsigned char *)src - 1;
unsigned char *d = (unsigned char *)dst - 1;

size++;
while(--size != 0){
n++;
while (--n != 0)
*++d = *++s;
return dst;
}
}
}
26 changes: 12 additions & 14 deletions src/dolphin/os/__start.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
__declspec(section ".init")void __init_registers(void);
__declspec(section ".init")void __init_data(void);

int main(int argc, char **argv);

__declspec(section ".init") void __check_pad3(void){
if((*(u16*)0x800030E4 & 0xEEF) == 0xEEF){
OSResetSystem(0,0,0);
Expand Down Expand Up @@ -117,26 +119,22 @@ __declspec(section ".init") asm void __init_registers(void){
ori r13, r13, 0xFB80
blr
}

__declspec(section ".init") static void __copy_rom_section(void* dst, const void* src, size_t size){
if (size == 0 || dst == src){
return;
}

void __copy_rom_section(void* dst, const void* src, size_t size){
if (size && (dst != src)) {
memcpy(dst, src, size);
(dst, size);
__flush_cache(dst, size);
}
}

__declspec(section ".init") static void __init_bss_section(void* dst, size_t size){
if(size == 0){
return;
}
void __init_bss_section(void* dst, size_t size){
if (size) {
memset(dst, 0, size);
}
}

__declspec(section ".init") static void __init_data(void){
const RomSection* rs;
const BssSection* bs;
RomSection* rs;
BssSection* bs;

rs = _rom_copy_info;
while (1) {
Expand All @@ -157,4 +155,4 @@ __declspec(section ".init") static void __init_data(void){
__init_bss_section(bs->virtualOfs, bs->size);
bs++;
}
}
}
Loading

0 comments on commit 771ffca

Please sign in to comment.