diff --git a/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s b/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s deleted file mode 100644 index da5d72c4..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s +++ /dev/null @@ -1,73 +0,0 @@ -glabel osDestroyThread -/* 0D7200 800D6600 27BDFFC8 */ addiu $sp, $sp, -0x38 -/* 0D7204 800D6604 AFBF0024 */ sw $ra, 0x24($sp) -/* 0D7208 800D6608 AFA40038 */ sw $a0, 0x38($sp) -/* 0D720C 800D660C AFB20020 */ sw $s2, 0x20($sp) -/* 0D7210 800D6610 AFB1001C */ sw $s1, 0x1c($sp) -/* 0D7214 800D6614 0C034958 */ jal __osDisableInt -/* 0D7218 800D6618 AFB00018 */ sw $s0, 0x18($sp) -/* 0D721C 800D661C 8FAE0038 */ lw $t6, 0x38($sp) -/* 0D7220 800D6620 00408025 */ move $s0, $v0 -/* 0D7224 800D6624 15C00005 */ bnez $t6, .L800D663C -/* 0D7228 800D6628 00000000 */ nop -/* 0D722C 800D662C 3C0F800E */ lui $t7, %hi(__osRunningThread) # $t7, 0x800e -/* 0D7230 800D6630 8DEF4890 */ lw $t7, %lo(__osRunningThread)($t7) -/* 0D7234 800D6634 10000009 */ b .L800D665C -/* 0D7238 800D6638 AFAF0038 */ sw $t7, 0x38($sp) -.L800D663C: -/* 0D723C 800D663C 8FB80038 */ lw $t8, 0x38($sp) -/* 0D7240 800D6640 24010001 */ li $at, 1 -/* 0D7244 800D6644 97190010 */ lhu $t9, 0x10($t8) -/* 0D7248 800D6648 13210004 */ beq $t9, $at, .L800D665C -/* 0D724C 800D664C 00000000 */ nop -/* 0D7250 800D6650 8F040008 */ lw $a0, 8($t8) -/* 0D7254 800D6654 0C034B1C */ jal __osDequeueThread -/* 0D7258 800D6658 03002825 */ move $a1, $t8 -.L800D665C: -/* 0D725C 800D665C 3C08800E */ lui $t0, %hi(__osActiveQueue) # $t0, 0x800e -/* 0D7260 800D6660 8D08488C */ lw $t0, %lo(__osActiveQueue)($t0) -/* 0D7264 800D6664 8FA90038 */ lw $t1, 0x38($sp) -/* 0D7268 800D6668 15090005 */ bne $t0, $t1, .L800D6680 -/* 0D726C 800D666C 00000000 */ nop -/* 0D7270 800D6670 8D0A000C */ lw $t2, 0xc($t0) -/* 0D7274 800D6674 3C01800E */ lui $at, %hi(__osActiveQueue) # $at, 0x800e -/* 0D7278 800D6678 10000010 */ b .L800D66BC -/* 0D727C 800D667C AC2A488C */ sw $t2, %lo(__osActiveQueue)($at) -.L800D6680: -/* 0D7280 800D6680 3C11800E */ lui $s1, %hi(__osActiveQueue) # $s1, 0x800e -/* 0D7284 800D6684 8E31488C */ lw $s1, %lo(__osActiveQueue)($s1) -/* 0D7288 800D6688 8E32000C */ lw $s2, 0xc($s1) -/* 0D728C 800D668C 1240000B */ beqz $s2, .L800D66BC -/* 0D7290 800D6690 00000000 */ nop -.L800D6694: -/* 0D7294 800D6694 8FAB0038 */ lw $t3, 0x38($sp) -/* 0D7298 800D6698 164B0004 */ bne $s2, $t3, .L800D66AC -/* 0D729C 800D669C 00000000 */ nop -/* 0D72A0 800D66A0 8D6C000C */ lw $t4, 0xc($t3) -/* 0D72A4 800D66A4 10000005 */ b .L800D66BC -/* 0D72A8 800D66A8 AE2C000C */ sw $t4, 0xc($s1) -.L800D66AC: -/* 0D72AC 800D66AC 02408825 */ move $s1, $s2 -/* 0D72B0 800D66B0 8E32000C */ lw $s2, 0xc($s1) -/* 0D72B4 800D66B4 1640FFF7 */ bnez $s2, .L800D6694 -/* 0D72B8 800D66B8 00000000 */ nop -.L800D66BC: -/* 0D72BC 800D66BC 3C0E800E */ lui $t6, %hi(__osRunningThread) # $t6, 0x800e -/* 0D72C0 800D66C0 8DCE4890 */ lw $t6, %lo(__osRunningThread)($t6) -/* 0D72C4 800D66C4 8FAD0038 */ lw $t5, 0x38($sp) -/* 0D72C8 800D66C8 15AE0003 */ bne $t5, $t6, .L800D66D8 -/* 0D72CC 800D66CC 00000000 */ nop -/* 0D72D0 800D66D0 0C034D09 */ jal __osDispatchThread -/* 0D72D4 800D66D4 00000000 */ nop -.L800D66D8: -/* 0D72D8 800D66D8 0C034960 */ jal __osRestoreInt -/* 0D72DC 800D66DC 02002025 */ move $a0, $s0 -/* 0D72E0 800D66E0 8FBF0024 */ lw $ra, 0x24($sp) -/* 0D72E4 800D66E4 8FB00018 */ lw $s0, 0x18($sp) -/* 0D72E8 800D66E8 8FB1001C */ lw $s1, 0x1c($sp) -/* 0D72EC 800D66EC 8FB20020 */ lw $s2, 0x20($sp) -/* 0D72F0 800D66F0 03E00008 */ jr $ra -/* 0D72F4 800D66F4 27BD0038 */ addiu $sp, $sp, 0x38 - -/* 0D72F8 800D66F8 00000000 */ nop -/* 0D72FC 800D66FC 00000000 */ nop diff --git a/lib/asm/non_matchings/unknown_0D3020/osYieldThread.s b/lib/asm/non_matchings/unknown_0D3020/osYieldThread.s deleted file mode 100644 index c3469326..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/osYieldThread.s +++ /dev/null @@ -1,22 +0,0 @@ -glabel osYieldThread -/* 0D71B0 800D65B0 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0D71B4 800D65B4 AFBF001C */ sw $ra, 0x1c($sp) -/* 0D71B8 800D65B8 0C034958 */ jal __osDisableInt -/* 0D71BC 800D65BC AFB00018 */ sw $s0, 0x18($sp) -/* 0D71C0 800D65C0 3C0F800E */ lui $t7, %hi(__osRunningThread) # $t7, 0x800e -/* 0D71C4 800D65C4 8DEF4890 */ lw $t7, %lo(__osRunningThread)($t7) -/* 0D71C8 800D65C8 240E0002 */ li $t6, 2 -/* 0D71CC 800D65CC 3C04800E */ lui $a0, %hi(__osRunQueue) # $a0, 0x800e -/* 0D71D0 800D65D0 00408025 */ move $s0, $v0 -/* 0D71D4 800D65D4 24844888 */ addiu $a0, %lo(__osRunQueue) # addiu $a0, $a0, 0x4888 -/* 0D71D8 800D65D8 0C034CB3 */ jal __osEnqueueAndYield -/* 0D71DC 800D65DC A5EE0010 */ sh $t6, 0x10($t7) -/* 0D71E0 800D65E0 0C034960 */ jal __osRestoreInt -/* 0D71E4 800D65E4 02002025 */ move $a0, $s0 -/* 0D71E8 800D65E8 8FBF001C */ lw $ra, 0x1c($sp) -/* 0D71EC 800D65EC 8FB00018 */ lw $s0, 0x18($sp) -/* 0D71F0 800D65F0 27BD0028 */ addiu $sp, $sp, 0x28 -/* 0D71F4 800D65F4 03E00008 */ jr $ra -/* 0D71F8 800D65F8 00000000 */ nop - -/* 0D71FC 800D65FC 00000000 */ nop diff --git a/lib/src/os/contreaddata.c b/lib/src/os/contreaddata.c index 717e1e62..4d7ced8e 100644 --- a/lib/src/os/contreaddata.c +++ b/lib/src/os/contreaddata.c @@ -21,7 +21,7 @@ s32 osContStartReadData(OSMesgQueue *mq) { } for (i = 0; i <= ARRLEN(__osContPifRam.ramarray); i++) { - __osContPifRam.ramarray[i] = 255; + __osContPifRam.ramarray[i] = CONT_CMD_RESET; } __osContPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; diff --git a/lib/src/os/osDestroyThread.c b/lib/src/os/osDestroyThread.c new file mode 100644 index 00000000..a7b98d01 --- /dev/null +++ b/lib/src/os/osDestroyThread.c @@ -0,0 +1,42 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D6600 */ + +#include "macros.h" +#include "libultra_internal.h" +#include "osint.h" + +void osDestroyThread(OSThread *t) { + register u32 saveMask; + register OSThread *pred; + register OSThread *succ; + + saveMask = __osDisableInt(); + + if (t == NULL) { + t = __osRunningThread; + } else if (t->state != OS_STATE_STOPPED) { + __osDequeueThread(t->queue, t); + } + + if (__osActiveQueue == t) { + __osActiveQueue = __osActiveQueue->tlnext; + } else { + pred = __osActiveQueue; + succ = pred->tlnext; + while (succ != NULL) { + if (succ == t) { + pred->tlnext = t->tlnext; + break; + } + + pred = succ; + succ = pred->tlnext; + } + } + + if (t == __osRunningThread) { + __osDispatchThread(); + } + + __osRestoreInt(saveMask); +} diff --git a/lib/src/os/osEepromProbe.c b/lib/src/os/osEepromProbe.c index ab4ca30a..20c176c0 100644 --- a/lib/src/os/osEepromProbe.c +++ b/lib/src/os/osEepromProbe.c @@ -12,7 +12,7 @@ s32 osEepromProbe(OSMesgQueue *mq) { __osSiGetAccess(); ret = __osEepStatus(mq, &sdata); if (ret == 0 && (sdata.type & CONT_EEPROM) != 0) { - ret = 1; + ret = EEPROM_TYPE_4K; } else { ret = 0; } diff --git a/lib/src/os/osEepromRead.c b/lib/src/os/osEepromRead.c index 7aec2526..69077d33 100644 --- a/lib/src/os/osEepromRead.c +++ b/lib/src/os/osEepromRead.c @@ -23,7 +23,7 @@ s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer) { i = 0; ptr = (u8 *)&__osEepPifRam.ramarray; - if (address > 0x40) { + if (address > EEPROM_MAXBLOCKS) { return -1; } @@ -54,7 +54,7 @@ s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer) { osRecvMesg(mq, NULL, OS_MESG_BLOCK); //skip the first 4 bytes - for (i = 0; i < 4; i++) { + for (i = 0; i < MAXCONTROLLERS; i++) { ptr++; } @@ -92,7 +92,7 @@ s32 __osPackEepReadData(u8 address) { eepromformat.data[i] = 0; } //skip the first 4 bytes - for (i = 0; i < 4; i++) { + for (i = 0; i < MAXCONTROLLERS; i++) { *ptr++ = 0; } *(__OSContEepromFormat *)ptr = eepromformat; diff --git a/lib/src/os/osEepromWrite.c b/lib/src/os/osEepromWrite.c index a7d902ad..94288775 100644 --- a/lib/src/os/osEepromWrite.c +++ b/lib/src/os/osEepromWrite.c @@ -16,16 +16,14 @@ s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer) { ret = 0; ptr = (u8 *)&__osEepPifRam.ramarray; - - if (address > 0x40) - { + + if (address > EEPROM_MAXBLOCKS) { return -1; } - + __osSiGetAccess(); ret = __osEepStatus(mq, &sdata); - if (ret != 0 || sdata.type != CONT_EEPROM) { return CONT_NO_RESPONSE_ERROR; } @@ -35,17 +33,17 @@ s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer) { __osPackEepWriteData(address, buffer); ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); //send command to pif osRecvMesg(mq, NULL, OS_MESG_BLOCK); - + for (i = 0; i <= ARRLEN(__osEepPifRam.ramarray); i++) { __osEepPifRam.ramarray[i] = 255; } - + __osEepPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); //recv response __osContLastCmd = CONT_CMD_WRITE_EEPROM; osRecvMesg(mq, NULL, OS_MESG_BLOCK); //skip the first 4 bytes - for (i = 0; i < 4; i++) { + for (i = 0; i < MAXCONTROLLERS; i++) { ptr++; } eepromformat = *(__OSContEepromFormat *)ptr; @@ -75,7 +73,7 @@ void __osPackEepWriteData(u8 address, u8 *buffer) { eepromformat.data[i] = *buffer++; } //skip the first 4 bytes - for (i = 0; i < 4; i++) { + for (i = 0; i < MAXCONTROLLERS; i++) { *ptr++ = 0; } *(__OSContEepromFormat *)(ptr) = eepromformat; @@ -96,7 +94,7 @@ s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data) { } __osEepPifRam.pifstatus = CONT_CMD_EXE; ptr = (u8 *)__osEepPifRam.ramarray; - for (i = 0; i < 4; i++) //zero 4 bytes? + for (i = 0; i < MAXCONTROLLERS; i++) //zero 4 bytes? *ptr++ = 0; requestformat.dummy = CONT_CMD_NOP; requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; @@ -120,7 +118,7 @@ s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data) { return ret; ptr = (u8 *)&__osEepPifRam; - for (i = 0; i < 4; i++) + for (i = 0; i < MAXCONTROLLERS; i++) *ptr++ = 0; requestformat = *(__OSContRequesFormat *)ptr; diff --git a/lib/src/os/osMotor.c b/lib/src/os/osMotor.c index 454d5884..4056ed14 100644 --- a/lib/src/os/osMotor.c +++ b/lib/src/os/osMotor.c @@ -5,12 +5,16 @@ #include "controller.h" #include "siint.h" +#define MOTOR_RAM_ADDRESS 0x400 +#define MOTOR_DATA_ADDRESS 0x600 +#define MOTOR_DEFAULT_BANK 128 + static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata); //TODO: These should really be declared here instead of somewhere else extern OSPifRam _MotorStopData[MAXCONTROLLERS]; extern OSPifRam _MotorStartData[MAXCONTROLLERS]; -extern u8 _motorstopbuf[32]; -extern u8 _motorstartbuf[32]; +extern u8 _motorstopbuf[BLOCKSIZE]; +extern u8 _motorstartbuf[BLOCKSIZE]; s32 osMotorStop(OSPfs *pfs) { int i; s32 ret; @@ -97,29 +101,29 @@ static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel) { int i; s32 ret; - u8 temp[32]; + u8 temp[BLOCKSIZE]; pfs->queue = mq; pfs->channel = channel; pfs->status = 0; - pfs->activebank = 128; + pfs->activebank = MOTOR_DEFAULT_BANK; for (i = 0; i < ARRLEN(temp); i++) - temp[i] = 128; + temp[i] = MOTOR_DEFAULT_BANK; - ret = __osContRamWrite(mq, channel, 1024, temp, FALSE); + ret = __osContRamWrite(mq, channel, MOTOR_RAM_ADDRESS, temp, FALSE); if (ret == PFS_ERR_NEW_PACK) - ret = __osContRamWrite(mq, channel, 1024, temp, FALSE); + ret = __osContRamWrite(mq, channel, MOTOR_RAM_ADDRESS, temp, FALSE); if (ret != 0) return ret; - ret = __osContRamRead(mq, channel, 1024, temp); + ret = __osContRamRead(mq, channel, MOTOR_RAM_ADDRESS, temp); if (ret != 0) return ret; - if (temp[31] != 128) { + if (temp[ARRLEN(temp) - 1] != MOTOR_DEFAULT_BANK) { return PFS_ERR_DEVICE; } @@ -128,8 +132,8 @@ s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel) { _motorstopbuf[i] = 0; } - _MakeMotorData(channel, 1536, _motorstartbuf, &_MotorStartData[channel]); - _MakeMotorData(channel, 1536, _motorstopbuf, &_MotorStopData[channel]); + _MakeMotorData(channel, MOTOR_DATA_ADDRESS, _motorstartbuf, &_MotorStartData[channel]); + _MakeMotorData(channel, MOTOR_DATA_ADDRESS, _motorstopbuf, &_MotorStopData[channel]); return 0; } diff --git a/lib/src/os/osPfsFreeBlocks.c b/lib/src/os/osPfsFreeBlocks.c index 8245226c..fb1a77e7 100644 --- a/lib/src/os/osPfsFreeBlocks.c +++ b/lib/src/os/osPfsFreeBlocks.c @@ -26,6 +26,6 @@ s32 osPfsFreeBlocks(OSPfs *pfs, s32 *bytes_not_used) { pages++; } } - *bytes_not_used = pages * 8 * 32; + *bytes_not_used = pages * PFS_ONE_PAGE * BLOCKSIZE; return 0; } diff --git a/lib/src/os/osPiStartDma.c b/lib/src/os/osPiStartDma.c index 46ce2aaa..63c354c4 100644 --- a/lib/src/os/osPiStartDma.c +++ b/lib/src/os/osPiStartDma.c @@ -10,21 +10,18 @@ s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, u32 devAddr, void *d if (!__osPiDevMgr.active) return -1; if (direction == OS_READ) - mb->hdr.type = 11; + mb->hdr.type = OS_MESG_TYPE_DMAREAD; else - mb->hdr.type = 12; + mb->hdr.type = OS_MESG_TYPE_DMAWRITE; mb->hdr.pri = priority; mb->hdr.retQueue = mq; mb->dramAddr = dramAddr; mb->devAddr = devAddr; mb->size = size; mb->piHandle = NULL; - if (priority == OS_MESG_PRI_HIGH) - { + if (priority == OS_MESG_PRI_HIGH) { ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); - } - else - { + } else { ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); } return ret; diff --git a/lib/src/os/osYieldThread.c b/lib/src/os/osYieldThread.c new file mode 100644 index 00000000..7ac4e986 --- /dev/null +++ b/lib/src/os/osYieldThread.c @@ -0,0 +1,19 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D65B0 */ + +#include "macros.h" +#include "libultra_internal.h" +#include "viint.h" + +extern OSThread *__osRunningThread; +extern OSThread *__osRunQueue; + +extern void __osEnqueueAndYield(OSThread **); +extern void __osRestoreInt(u32); + +void osYieldThread(void) { + register u32 saveMask = __osDisableInt(); + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + __osRestoreInt(saveMask); +} diff --git a/lib/src/os/osint.h b/lib/src/os/osint.h new file mode 100644 index 00000000..124b6b03 --- /dev/null +++ b/lib/src/os/osint.h @@ -0,0 +1,46 @@ +#ifndef _OSINT_H +#define _OSINT_H +#include + +typedef struct __OSEventState { + OSMesgQueue *messageQueue; + OSMesg message; +} __OSEventState; +extern struct __osThreadTail { + OSThread *next; + OSPri priority; +} __osThreadTail; + +//maybe should be in exceptasm.h? +extern void __osEnqueueAndYield(OSThread **); +extern void __osDequeueThread(OSThread **, OSThread *); +extern void __osEnqueueThread(OSThread **, OSThread *); +extern OSThread *__osPopThread(OSThread **); +extern void __osDispatchThread(void); + +extern void __osSetTimerIntr(OSTime); +extern OSTime __osInsertTimer(OSTimer *); +extern void __osTimerInterrupt(void); +extern u32 __osProbeTLB(void *); +extern int __osSpDeviceBusy(void); + +extern OSThread *__osRunningThread; +extern OSThread *__osActiveQueue; +extern OSThread *__osFaultedThread; +extern OSThread *__osRunQueue; + +extern OSTimer *__osTimerList; +extern OSTimer __osBaseTimer; +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; +extern u32 __osViIntrCount; +extern u32 __osTimerCounter; + +extern __OSEventState __osEventStateTab[OS_NUM_EVENTS]; + +//not sure if this should be here +extern s32 osViClock; +extern void __osTimerServicesInit(void); +extern s32 __osAiDeviceBusy(void); +extern int __osDpDeviceBusy(void); +#endif diff --git a/lib/src/os/siacs.c b/lib/src/os/siacs.c index 00e5bb71..a499b237 100644 --- a/lib/src/os/siacs.c +++ b/lib/src/os/siacs.c @@ -40,12 +40,14 @@ void __osSiCreateAccessQueue(void) { osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, SI_Q_BUF_LEN); osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); } + void __osSiGetAccess(void) { OSMesg dummyMesg; if (!__osSiAccessQueueEnabled) __osSiCreateAccessQueue(); osRecvMesg(&__osSiAccessQueue, &dummyMesg, OS_MESG_BLOCK); } + void __osSiRelAccess(void) { osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); } diff --git a/lib/src/os/unknown_0D6C90.c b/lib/src/os/unknown_0D6C90.c index 1954a0b0..d24c18e1 100644 --- a/lib/src/os/unknown_0D6C90.c +++ b/lib/src/os/unknown_0D6C90.c @@ -25,14 +25,3 @@ GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpRawStartDma.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpDeviceBusy.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osResetGlobalIntMask.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osEPiRawWriteIo.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osYieldThread.s") -/*extern void __osEnqueueAndYield(OSThread **); -extern void __osRestoreInt(u32); -void osYieldThread(void){ - register u32 saveMask = __osDisableInt(); - __osRunningThread->state = OS_STATE_RUNNABLE; - __osEnqueueAndYield(&__osRunQueue); - __osRestoreInt(saveMask); -}*/ - -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s") diff --git a/src/memory.c b/src/memory.c index 5a6ee72e..2ad66e00 100644 --- a/src/memory.c +++ b/src/memory.c @@ -40,8 +40,8 @@ s32 gFreeQueueCount; s32 gFreeQueueState; OSPifRam _MotorStopData[MAXCONTROLLERS]; OSPifRam _MotorStartData[MAXCONTROLLERS]; -u8 _motorstopbuf[32]; -u8 _motorstartbuf[32]; +u8 _motorstopbuf[BLOCKSIZE]; +u8 _motorstartbuf[BLOCKSIZE]; extern MemoryPoolSlot gMainMemoryPool;