DataBlock, MemBlock and Mutex

This commit is contained in:
Charlotte Delenk 2021-10-20 17:40:24 +02:00
parent 7144e7f1da
commit 9f3eae615a
Signed by: darkkirb
GPG key ID: 015E3768A70AFBC5
10 changed files with 76 additions and 5 deletions

View file

@ -18,6 +18,9 @@
,,,,,,8019607c,801961fc,,,,,,,,,,,,,8055d1b4,8055d1b9,,,,,donut/gfx/GXFifoMemoryManager.o
,,,,,,801962a8,80196404,,,,,,,,,,,,,,,8055f720,8055f730,,,donut/gfx/RenderSetting.o
,,,,,,80197d50,80197ef4,,,,,,,,,,,,,,,,,,,donut/gfx/XFBManager.o
,,,,,,801bd2a4,801bd370,,,,,,,,,,,,,,,,,,,donut/mem/DataBlock.o
,,,,,,801bf1b4,801bf1f8,,,,,,,,,,,,,,,,,,,donut/mem/MemBlock.o
,,,,,,801bf250,801bf2bc,,,,,,,,,80545bf8,80545ed0,,,8055d2a0,8055d2a1,,,,,donut/mem/Memory.o
,,,,,,80405a9c,80405b68,,,,,,,,,,,,,,,,,,,donut/util/Mutex.o
80006684,80006728,,,,,,,8040652c,80406530,80406548,8040654c,,,,,,,,,,,,,,,
80006728,80006728,800068cc,800068cc,800069e4,800069e4,80406244,80406244,80406530,80406530,8040654c,8040654c,80421030,80421030,804966fc,804966fc,8055640c,8055640c,8055c6d0,8055c6d0,8055df74,8055df74,805643b0,805643b0,805643fc,805643fc,
1 .init start .init end extab start extab end extabindex start extabindex end .text start .text end .ctors start .ctors end .dtors start .dtors end .rodata start .rodata end .data start .data end .bss start .bss end .sdata start .sdata end .sbss start .sbss end .sdata2 start .sdata2 end .sbss2 start .sbss2 end File
18 8019607c 801961fc 8055d1b4 8055d1b9 donut/gfx/GXFifoMemoryManager.o
19 801962a8 80196404 8055f720 8055f730 donut/gfx/RenderSetting.o
20 80197d50 80197ef4 donut/gfx/XFBManager.o
21 801bd2a4 801bd370 donut/mem/DataBlock.o
22 801bf1b4 801bf1f8 donut/mem/MemBlock.o
23 801bf250 801bf2bc 80545bf8 80545ed0 8055d2a0 8055d2a1 donut/mem/Memory.o
24 80405a9c 80405b68 donut/util/Mutex.o
25 80006684 80006728 8040652c 80406530 80406548 8040654c
26 80006728 80006728 800068cc 800068cc 800069e4 800069e4 80406244 80406244 80406530 80406530 8040654c 8040654c 80421030 80421030 804966fc 804966fc 8055640c 8055640c 8055c6d0 8055c6d0 8055df74 8055df74 805643b0 805643b0 805643fc 805643fc

View file

@ -17,6 +17,9 @@ Address,SymbolName
80021820,__RAS_OSDisableInterrupts_begin
8002182c,__RAS_OSDisableInterrupts_end
80021860,OSRestoreInterrupts
80022b60,OSInitMutex
80022ba0,OSLockMutex
80022c80,OSUnlockMutex
80023820,OSResetSystem
80028530,__init_user
800285a0,exit
@ -46,7 +49,6 @@ Address,SymbolName
80197b90,set__Q23gfx9VISettingFUl
801a38b0,__ct__Q23hid14LibInitializerFv
801a39f8,__dt__Q23hid14LibInitializerFv
801bd2a4,__ct__Q23mem9DataBlockFUllRQ23mem10IAllocator
801be5a0,free__Q23mem7HeapExpFPv
801bf2bc,__ct__Q23mem6MemoryFv
801bf520,__dt__Q23mem6MemoryFv
@ -55,5 +57,4 @@ Address,SymbolName
801bf714,__dl__FPv
80402ee8,__ct__Q23snd12SoundManagerFv
80403150,__dt__Q23snd12SoundManagerFv
80405a9c,__ct__Q24util5MutexFv
8055c878,Debug_BBA

1 Address SymbolName
17 80021820 __RAS_OSDisableInterrupts_begin
18 8002182c __RAS_OSDisableInterrupts_end
19 80021860 OSRestoreInterrupts
20 80022b60 OSInitMutex
21 80022ba0 OSLockMutex
22 80022c80 OSUnlockMutex
23 80023820 OSResetSystem
24 80028530 __init_user
25 800285a0 exit
49 80197b90 set__Q23gfx9VISettingFUl
50 801a38b0 __ct__Q23hid14LibInitializerFv
51 801a39f8 __dt__Q23hid14LibInitializerFv
801bd2a4 __ct__Q23mem9DataBlockFUllRQ23mem10IAllocator
52 801be5a0 free__Q23mem7HeapExpFPv
53 801bf2bc __ct__Q23mem6MemoryFv
54 801bf520 __dt__Q23mem6MemoryFv
57 801bf714 __dl__FPv
58 80402ee8 __ct__Q23snd12SoundManagerFv
59 80403150 __dt__Q23snd12SoundManagerFv
80405a9c __ct__Q24util5MutexFv
60 8055c878 Debug_BBA

View file

@ -1,3 +1,4 @@
#define MEM_BLOCK_CONSTRUCTOR_HACK
#include <gfx/XFBManager.hpp>
#include <mem/Memory.hpp>
#include <vi.h>

7
donut/mem/DataBlock.cpp Normal file
View file

@ -0,0 +1,7 @@
#include <mem/DataBlock.hpp>
namespace mem {
DataBlock::DataBlock(u32 size, s32 align, IAllocator &alloc)
: alloc_(alloc), block_(alloc.allocatorAlloc(size, align), size) {}
DataBlock::~DataBlock() { alloc_.allocatorFree(block_.ptr_); }
} // namespace mem

6
donut/mem/MemBlock.cpp Normal file
View file

@ -0,0 +1,6 @@
#include <mem/MemBlock.hpp>
namespace mem {
MemBlock MemBlock::EmptyBlock() { return MemBlock(0, 0); }
MemBlock::MemBlock(void *ptr, u32 size) : size_(size), ptr_(ptr) {}
} // namespace mem

14
donut/util/Mutex.cpp Normal file
View file

@ -0,0 +1,14 @@
#include <util/Mutex.hpp>
#ifdef __CWCC__
#pragma dont_inline on
#endif
namespace util {
Mutex::Mutex() { OSInitMutex(&inner_); }
void Mutex::lock() { OSLockMutex(&inner_); }
void Mutex::unlock() { OSUnlockMutex(&inner_); }
ScopedMutex::ScopedMutex(Mutex &mutex) : mutex_(mutex) { mutex.lock(); }
ScopedMutex::~ScopedMutex() { mutex_.unlock(); }
} // namespace util

View file

@ -4,9 +4,14 @@
namespace mem {
struct MemBlock {
u32 size;
void *ptr;
u32 size_;
void *ptr_;
// terrible hack that hopefully makes the code compile correctly
#ifndef MEM_BLOCK_CONSTRUCTOR_HACK
MemBlock(void *ptr, u32 size);
#endif
void *startAddress() const;
static MemBlock EmptyBlock();
};
} // namespace mem

20
include/os/osMutex.h Normal file
View file

@ -0,0 +1,20 @@
#pragma once
#include <defines.h>
#include <types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSMutex {
int unk[6];
} OSMutex;
void OSInitMutex(OSMutex *mutex);
void OSLockMutex(OSMutex *mutex);
void OSUnlockMutex(OSMutex *mutex);
#ifdef __cplusplus
}
#endif

View file

@ -1,8 +1,19 @@
#pragma once
#include <os/osMutex.h>
namespace util {
struct Mutex {
int unk[6];
OSMutex inner_;
Mutex();
void lock();
void unlock();
};
struct ScopedMutex {
Mutex &mutex_;
ScopedMutex(Mutex &mutex);
~ScopedMutex();
};
} // namespace util

View file

@ -29,7 +29,10 @@ const SOURCES: &[(&str, &str)] = &[
("donut/gfx/GXFifoMemoryManager.cpp", "donut"),
("donut/gfx/RenderSetting.cpp", "donut"),
("donut/gfx/XFBManager.cpp", "donut"),
("donut/mem/DataBlock.cpp", "donut"),
("donut/mem/MemBlock.cpp", "donut"),
("donut/mem/Memory.cpp", "donut"),
("donut/util/Mutex.cpp", "donut"),
];
const ASM_SOURCES: &[&str] = &["sdk/trk/__exception.S"];