diff --git a/.vscode/settings.json b/.vscode/settings.json index 93ce7602..7baf837c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,19 @@ "string_view": "c", "initializer_list": "c", "utility": "c", - "types.h": "c" + "types.h": "c", + "*.tcc": "cpp", + "deque": "cpp", + "list": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "memory_resource": "cpp", + "memory": "cpp", + "future": "cpp", + "iosfwd": "cpp", + "sstream": "cpp", + "tuple": "cpp" }, } \ No newline at end of file diff --git a/Doxyfile b/Doxyfile index ef5026dc..b6dede0f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -45,7 +45,7 @@ OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO OPTIMIZE_OUTPUT_SLICE = NO -EXTENSION_MAPPING = +EXTENSION_MAPPING = no_extension=C++ MARKDOWN_SUPPORT = YES TOC_INCLUDE_HEADINGS = 5 AUTOLINK_SUPPORT = YES @@ -119,7 +119,8 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = donut include sdk +INPUT = donut include sdk \ + include/new INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.c \ *.cpp \ diff --git a/data/ranges.csv b/data/ranges.csv index c577480a..ec10e9ea 100644 --- a/data/ranges.csv +++ b/data/ranges.csv @@ -20,7 +20,8 @@ ,,,,,,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 +,,,,,,801bf250,801bf2bc,,,,,,,,,80545bf8,80545ed0,,,8055d2a0,8055d2a8,,,,,donut/mem/Memory.o +,,,,,,801bf618,801bf760,80406338,8040633c,,,,,,,,,,,8055d2a8,8055d2b0,,,,,donut/mem/OperatorNewDelete.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, \ No newline at end of file diff --git a/data/symbols.csv b/data/symbols.csv index 462f5e10..5de4cab7 100644 --- a/data/symbols.csv +++ b/data/symbols.csv @@ -35,6 +35,7 @@ Address,SymbolName 8004b430,SCInit 80075730,size__Q23gfx19GXFifoMemoryManagerCFv 800dc470,SetTMemLayout__Q34nw4r3g3d4tmemFQ44nw4r3g3d4tmem10TMemLayout +800dd3e0,__ct__Q33hel6common34PointerWrapperFv 800f16b0,G3dInit__Q24nw4r3g3dFb 801007e0,startAddress__Q23mem8MemBlockCFv 80175b68,__dt__Q33hel6common11NonCopyableFv @@ -54,7 +55,6 @@ Address,SymbolName 801bf520,__dt__Q23mem6MemoryFv 801bf5e8,mem1FixHeap__Q23mem6MemoryFv 801bf5f8,mem2FixHeap__Q23mem6MemoryFv -801bf714,__dl__FPv 80402ee8,__ct__Q23snd12SoundManagerFv 80403150,__dt__Q23snd12SoundManagerFv 8055c878,Debug_BBA diff --git a/donut/mem/OperatorNewDelete.cpp b/donut/mem/OperatorNewDelete.cpp new file mode 100644 index 00000000..3b6e6a36 --- /dev/null +++ b/donut/mem/OperatorNewDelete.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#ifdef __CWCC__ +#pragma dont_inline on +#endif + +using namespace mem; +using namespace hel::common; + +namespace { + +PointerWrapper t_allocator; +PointerWrapper t_globalNewDeleteAllocator; + +IAllocator &t_allocatorRef(void) { + Memory::SetupIfNotSetup(); + IAllocator *allocatorRef = t_globalNewDeleteAllocator.ptr_; + if (allocatorRef) + return *allocatorRef; + + allocatorRef = t_allocator.ptr_; + if (allocatorRef) + return *allocatorRef; + + allocatorRef = &MEMORY_OBJ->mem1FixHeap(); + return *allocatorRef; +} + +void *t_operatorNew(u32 size) { + return t_allocatorRef().allocatorAlloc(size, 4); +} + +void *t_operatorNew(u32 size, IAllocator &alloc) { + return alloc.allocatorAlloc(size, 4); +} + +void t_operatorDelete(void *ptr) { + if (ptr != 0) { + t_allocatorRef().allocatorFree(ptr); + } +} + +} // namespace + +void *operator new(u32 size, IAllocator &alloc) { + return t_operatorNew(size, alloc); +} + +void *operator new(u32 size) { return t_operatorNew(size); } + +void operator delete(void *ptr) { t_operatorDelete(ptr); } + +namespace mem { +void OperatorNewDelete::SetDefaultAllocator(IAllocator &alloc) { + t_allocator.ptr_ = &alloc; +} +void OperatorNewDelete::SetGlobalNewDeleteAllocator(IAllocator &alloc) { + t_globalNewDeleteAllocator.ptr_ = &alloc; +} +void OperatorNewDelete::UnsetGlobalNewDeleteAllocator(IAllocator &alloc) { + // extraneous argument is not a copy-paste error + t_globalNewDeleteAllocator.ptr_ = 0; +} + +} // namespace mem \ No newline at end of file diff --git a/include/hel/common/PointerWrapper.hpp b/include/hel/common/PointerWrapper.hpp new file mode 100644 index 00000000..96352ce2 --- /dev/null +++ b/include/hel/common/PointerWrapper.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace hel { +namespace common { +template struct PointerWrapper { + T *ptr_; + PointerWrapper(); +}; +} // namespace common +} // namespace hel \ No newline at end of file diff --git a/include/mem/OperatorNewDelete.hpp b/include/mem/OperatorNewDelete.hpp new file mode 100644 index 00000000..2efad687 --- /dev/null +++ b/include/mem/OperatorNewDelete.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace mem { +struct OperatorNewDelete { + static void SetDefaultAllocator(IAllocator &alloc); + static void SetGlobalNewDeleteAllocator(IAllocator &alloc); + static void UnsetGlobalNewDeleteAllocator(IAllocator &alloc); +}; +} // namespace mem \ No newline at end of file diff --git a/include/new b/include/new new file mode 100644 index 00000000..29906e80 --- /dev/null +++ b/include/new @@ -0,0 +1,6 @@ +// vim: set ft=cpp +#pragma once + +namespace std { +struct nothrow_t {}; +} // namespace std diff --git a/src/bin/buildgen.rs b/src/bin/buildgen.rs index fb65bfa0..f0db8766 100644 --- a/src/bin/buildgen.rs +++ b/src/bin/buildgen.rs @@ -32,6 +32,7 @@ const SOURCES: &[(&str, &str)] = &[ ("donut/mem/DataBlock.cpp", "donut"), ("donut/mem/MemBlock.cpp", "donut"), ("donut/mem/Memory.cpp", "donut"), + ("donut/mem/OperatorNewDelete.cpp", "donut"), ("donut/util/Mutex.cpp", "donut"), ]; diff --git a/src/bin/genlcf.rs b/src/bin/genlcf.rs index f7408681..7469f9d8 100644 --- a/src/bin/genlcf.rs +++ b/src/bin/genlcf.rs @@ -66,7 +66,7 @@ MEMORY { let result = result?; out.write_all( format!( - " {} = 0x{:08x};\n", + " \"{}\" = 0x{:08x};\n", result.get(1).unwrap(), parse_hex(result.get(0).unwrap())? )