-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,327 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,4 +176,4 @@ namespace NrvBigFan { | |
|
||
BigFan::~BigFan() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
extern void OSReport(const char *, ...); | ||
extern void* OSGetArenaLo(); | ||
extern void* OSGetArenaHi(); | ||
extern void* OSInitAlloc(void *, void *, int); | ||
extern volatile int __OSCurrHeap; | ||
|
||
#define OSRoundUp32B(x) (((unsigned int)(x) + 32 - 1) & ~(32 - 1)) | ||
#define OSRoundDown32B(x) (((unsigned int)(x)) & ~(32 - 1)) | ||
|
||
static void InitDefaultHeap() | ||
{ | ||
void* arenaLo; | ||
void* arenaHi; | ||
|
||
OSReport("GCN_Mem_Alloc.c : InitDefaultHeap. No Heap Available\n"); | ||
OSReport("Metrowerks CW runtime library initializing default heap\n"); | ||
|
||
arenaLo = OSGetArenaLo(); | ||
arenaHi = OSGetArenaHi(); | ||
|
||
arenaLo = OSInitAlloc(arenaLo, arenaHi, 1); | ||
OSSetArenaLo(arenaLo); | ||
|
||
arenaLo = (void*)OSRoundUp32B(arenaLo); | ||
arenaHi = (void*)OSRoundDown32B(arenaHi); | ||
|
||
OSSetCurrentHeap(OSCreateHeap(arenaLo, arenaHi)); | ||
OSSetArenaLo(arenaLo = arenaHi); | ||
} | ||
|
||
// unused | ||
void __sys_alloc() | ||
{ | ||
} | ||
|
||
__declspec(weak) extern void __sys_free(void* ptr) | ||
{ | ||
if (__OSCurrHeap == -1) { | ||
InitDefaultHeap(); | ||
} | ||
OSFreeToHeap(__OSCurrHeap, ptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <NMWException.h> | ||
|
||
typedef struct ProcessInfo { | ||
__eti_init_info* exception_info; | ||
char* TOC; | ||
int active; | ||
} ProcessInfo; | ||
|
||
static ProcessInfo fragmentinfo[1]; | ||
|
||
int __register_fragment(struct __eti_init_info *pInfo, char *pTOC) { | ||
ProcessInfo* info; | ||
int i; | ||
|
||
for (i = 0, info = fragmentinfo; i < 1; ++i, ++info) { | ||
if (info->active == 0) { | ||
info->exception_info = pInfo; | ||
info->TOC = pTOC; | ||
info->active = 1; | ||
return i; | ||
} | ||
} | ||
|
||
|
||
return -1; | ||
} | ||
|
||
void __unregister_fragment(int id) { | ||
ProcessInfo* info; | ||
|
||
if (id >= 0 && id < 1) { | ||
info = &fragmentinfo[id]; | ||
info->exception_info = 0; | ||
info->TOC = 0; | ||
info->active = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <NMWException.h> | ||
#include <new> | ||
|
||
class __partial_array_destructor { | ||
public: | ||
void* mArrayStart; // 0x0 | ||
size_t mElemSize; // 0x4 | ||
size_t mArraySize; // 0x8 | ||
ctor_dtor_ptr mDtorPtr; // 0xC | ||
size_t mCurElement; // 0x10 | ||
|
||
__partial_array_destructor(void *arr, unsigned int size, unsigned int count, ctor_dtor_ptr ptr) { | ||
mArrayStart = arr; | ||
mElemSize = size; | ||
mArraySize = count; | ||
mDtorPtr = ptr; | ||
mCurElement = mArraySize; | ||
} | ||
|
||
~__partial_array_destructor() { | ||
if (mCurElement < mArraySize && mDtorPtr) { | ||
for (char* cur = (char*)mArrayStart + (mElemSize * mCurElement); mCurElement > 0; mCurElement--) { | ||
cur -= mElemSize; | ||
((void (*)(void *, short))mDtorPtr)(cur,-1); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
extern "C" { | ||
|
||
void __construct_array(void *pBlock, ctor_dtor_ptr ctor, ctor_dtor_ptr dtor, size_t size, size_t n) { | ||
__partial_array_destructor pad(pBlock, size, n, dtor); | ||
|
||
char* p = (char*)pBlock; | ||
for (pad.mCurElement = 0; pad.mCurElement < n; p += size, pad.mCurElement++) { | ||
((void (*)(void *, short))ctor)(p,1); | ||
} | ||
} | ||
|
||
void *__construct_new_array(void *block, ctor_dtor_ptr ctor, ctor_dtor_ptr dtor, size_t size, size_t n) { | ||
char *ptr = (char *)block; | ||
|
||
if (ptr != 0){ | ||
*(size_t *)ptr = size; | ||
*(size_t *)(ptr + 4) = n; | ||
ptr += 0x10; | ||
|
||
if (ctor) { | ||
|
||
__partial_array_destructor pad(ptr, size, n, dtor); | ||
|
||
char* p; | ||
for (pad.mCurElement = 0, p = ptr; pad.mCurElement < n; pad.mCurElement++, p += size) { | ||
((void (*)(void *, short))ctor)(p,1); | ||
} | ||
} | ||
} | ||
return ptr; | ||
} | ||
|
||
void __destroy_arr(void *pArraySource, ctor_dtor_ptr dtor, size_t size, size_t num) { | ||
char* cur; | ||
|
||
for (cur = (char*)pArraySource + (size * num); num > 0; num--) { | ||
cur -= size; | ||
((void (*)(void *, short))dtor)(cur,-1); | ||
} | ||
} | ||
|
||
void __destroy_new_array(void *pArraySource, ctor_dtor_ptr dtor) { | ||
if (pArraySource != 0) { | ||
if (dtor != 0) { | ||
size_t i, objs, obj_size; | ||
char* cur; | ||
|
||
// why are the 8 and 12 important to match? | ||
obj_size = *(size_t*)((char*)pArraySource - 2 * 8); | ||
objs = *(size_t*)((char *)pArraySource - 12); | ||
cur = (char*)pArraySource + obj_size * objs; | ||
|
||
for (i = 0; i < objs; i++) { | ||
cur -= obj_size; | ||
((void (*)(void *, short))dtor)(cur,-1); | ||
} | ||
} | ||
|
||
::operator delete[] ((char *)pArraySource-2*8); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <__ppc_eabi_linker.h> | ||
#include <NMWException.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern void __init_cpp_exceptions(void); | ||
extern void __fini_cpp_exceptions(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
static int fragmentID = -2; | ||
|
||
void __init_cpp_exceptions(void) { | ||
if (fragmentID == -2) { | ||
register char *temp; | ||
asm { | ||
mr temp,r2 | ||
} | ||
|
||
fragmentID = __register_fragment(_eti_init_info, (char*)temp); | ||
} | ||
} | ||
|
||
void __fini_cpp_exceptions(void) { | ||
if (fragmentID != -2) { | ||
__unregister_fragment(fragmentID); | ||
fragmentID = -2; | ||
} | ||
} | ||
|
||
__declspec(section ".ctors") | ||
extern void * const __init_cpp_exceptions_reference = __init_cpp_exceptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <__mem.h> | ||
|
||
void* memcpy(void *pDest, const void *pSrc, size_t len) { | ||
const char *p; | ||
char* q; | ||
int rev = pDest < pSrc; | ||
|
||
if (!rev) { | ||
for (p = (const char*)pSrc - 1, q = (char*)pDest - 1, len++; --len;) { | ||
*++q = *++p; | ||
} | ||
} | ||
else { | ||
for (p = (const char*)pSrc + len, q = (char*)pDest + len, len++; --len;) { | ||
*--q = *--p; | ||
} | ||
} | ||
|
||
return pDest; | ||
} | ||
|
||
// I really wish I could tell you what's going on here but I can't | ||
void __fill_mem(void *pDest, int val, unsigned long n) { | ||
unsigned long v = (unsigned char) val; | ||
unsigned long i; | ||
|
||
((unsigned char*)pDest) = ((unsigned char*)pDest) - 1; | ||
|
||
if (n >= 32) { | ||
i = (~(unsigned long)pDest) & 3; | ||
|
||
if (i) { | ||
n -= i; | ||
|
||
do { | ||
*++(((unsigned char*)pDest)) = v; | ||
} | ||
while (--i); | ||
} | ||
|
||
if (v != 0) { | ||
v |= v << 24 | v << 16 | v << 8; | ||
} | ||
|
||
((unsigned long*)pDest) = ((unsigned long*) (((unsigned char*)pDest) + 1)) - 1; | ||
i = n >> 5; | ||
|
||
if (i != 0) { | ||
do { | ||
*++(((unsigned long*)pDest)) = v; | ||
*++(((unsigned long*)pDest)) = v; | ||
*++(((unsigned long*)pDest)) = v; | ||
*++(((unsigned long*)pDest)) = v; | ||
*++(((unsigned long*)pDest)) = v; | ||
*++(((unsigned long*)pDest)) = v; | ||
*++(((unsigned long*)pDest)) = v; | ||
*++(((unsigned long*)pDest)) = v; | ||
} | ||
while (--i); | ||
} | ||
|
||
i = (n & 31) >> 2; | ||
|
||
if (i) { | ||
do { | ||
*++(((unsigned long*)pDest)) = v; | ||
} | ||
while (--i); | ||
} | ||
|
||
((unsigned char*)pDest) = ((unsigned char*) (((unsigned long*)pDest) + 1)) - 1; | ||
n &= 3; | ||
} | ||
|
||
if (n) { | ||
do { | ||
*++(((unsigned char*)pDest)) = v; | ||
} | ||
while (--n); | ||
} | ||
} | ||
|
||
void* memset(void *pDest, int val, size_t num) { | ||
__fill_mem(pDest, val, num); | ||
return pDest; | ||
} |
Oops, something went wrong.