diff --git a/.gitignore b/.gitignore index 4779f16..9e3ac65 100644 --- a/.gitignore +++ b/.gitignore @@ -20,22 +20,10 @@ build/ /sdk/bin/fartool /sdk/bin/fpkgtool /sdk/bin/fmantool -/sdk/source/FEOSBASE/* -!/sdk/source/FEOSBASE/Makefile -/sdk/source/FEOSSTDIO/* -!/sdk/source/FEOSSTDIO/Makefile -/sdk/source/FEOSPOSIXEMU/* -!/sdk/source/FEOSPOSIXEMU/Makefile -/sdk/source/FEOSMATH/* -!/sdk/source/FEOSMATH/Makefile -/sdk/source/FEOSDSAPI/* -!/sdk/source/FEOSDSAPI/Makefile -/sdk/source/FEOSDSSPR/* -!/sdk/source/FEOSDSSPR/Makefile -/sdk/source/FEOSDSBG/* -!/sdk/source/FEOSDSBG/Makefile -/sdk/source/FEOSARM7/* -!/sdk/source/FEOSARM7/Makefile +/sdk/source/FEOSKRNL/* +!/sdk/source/FEOSKRNL/Makefile +/sdk/source/FEOSDSHW/* +!/sdk/source/FEOSDSHW/Makefile /sdk/source7/FEOS7/* !/sdk/source7/FEOS7/Makefile /sdk/userlib/* diff --git a/arm7/source/feos.h b/arm7/source/feos.h index eb039b2..579f813 100644 --- a/arm7/source/feos.h +++ b/arm7/source/feos.h @@ -1,10 +1,10 @@ #pragma once #include #include "../../kernel/source/feos.h" -#include "../../kernel/source/fxe.h" +#include "../../kernel/source/loader.h" #include "../../kernel/source/feosfifo.h" -void FeOS_VBlankFunc(); +void Ke7VBlankISR(); void coopFifoSetDatamsgHandler(int channel, FifoDatamsgHandlerFunc handler, void* userdata); void coopFifoSetValue32Handler(int channel, FifoValue32HandlerFunc handler, void* userdata); diff --git a/arm7/source/feosirq.arm.c b/arm7/source/feosirq.arm.c deleted file mode 100644 index 7767f9e..0000000 --- a/arm7/source/feosirq.arm.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../kernel/source/feosirq.arm.c" diff --git a/arm7/source/interrupt.arm.c b/arm7/source/interrupt.arm.c new file mode 100644 index 0000000..99ddc05 --- /dev/null +++ b/arm7/source/interrupt.arm.c @@ -0,0 +1 @@ +#include "../../kernel/source/interrupt.arm.c" diff --git a/arm7/source/feos.c b/arm7/source/kernel7.c similarity index 94% rename from arm7/source/feos.c rename to arm7/source/kernel7.c index 72e34a2..d6cd0a1 100644 --- a/arm7/source/feos.c +++ b/arm7/source/kernel7.c @@ -30,7 +30,7 @@ void installFeOSFIFO() } static FeOSLoadStruct* ldSt = NULL; -static instance_t freeMod = NULL; +static module_t freeMod = NULL; static int freeChn; static volatile int oldPower; @@ -102,13 +102,13 @@ void __wrap_systemSleep() __real_systemSleep(); } -static void FeOS_LoadModule(); +static void Ke7LoadModule(); -void FeOS_VBlankFunc() +void Ke7VBlankISR() { if (ldSt) { - FeOS_LoadModule(); + Ke7LoadModule(); ldSt = NULL; } if (freeMod) @@ -121,9 +121,9 @@ void FeOS_VBlankFunc() } } -bool FeOS_ResolveImp(word_t* addr, const char* name); +bool Ke7ResolveImp(word_t* addr, const char* name); -void FeOS_LoadModule() +void Ke7LoadModule() { FeOSFifoMsg msg; msg.type = FEOS_ARM7_RETURN_MODULE; @@ -166,7 +166,7 @@ void FeOS_LoadModule() word_t* addr = (word_t*)(imps[i].address + (word_t)hModule); const char* name = (const char*)(imps[i].nameoffset + (word_t) imps); - if (!FeOS_ResolveImp(addr, name)) + if (!Ke7ResolveImp(addr, name)) { free(hModule); freeFifoChannel(msg.fifoCh); diff --git a/arm7/source/lib.c b/arm7/source/lib.c index 7072cdc..4573638 100644 --- a/arm7/source/lib.c +++ b/arm7/source/lib.c @@ -12,8 +12,8 @@ unsigned long long __aeabi_uldivmod(unsigned long long, unsigned long long); long long __aeabi_lmul(long long, long long); -#define ADD_FUNC(FUNC) {{(word_t)#FUNC}, {(word_t)FUNC}} -#define ADD_FUNC_ALIAS(FUNC, NAME) {{(word_t)#NAME}, {(word_t)FUNC}} +#define ADD_FUNC_(FUNC) {{(word_t)#FUNC}, {(word_t)FUNC}} +#define ADD_ALIAS(NAME, FUNC) {{(word_t)#NAME}, {(word_t)FUNC}} #define arm7_func_count (sizeof(arm7_funcs) / sizeof(fxe2_export_t)) @@ -32,61 +32,61 @@ void coopTimerStart(int timer, ClockDivider divider, u16 ticks, VoidFn callback) static const fxe2_export_t arm7_funcs[] = { - ADD_FUNC_ALIAS(coopWaitForVBlank, swiWaitForVBlank), - ADD_FUNC(irqSet), - ADD_FUNC(irqClear), - ADD_FUNC(irqEnable), - ADD_FUNC(irqDisable), - ADD_FUNC(writePowerManagement), - ADD_FUNC(timerStart), - ADD_FUNC(timerPause), - ADD_FUNC(timerStop), - ADD_FUNC(timerElapsed), - ADD_FUNC(micSetAmp), - ADD_FUNC(micReadData8), - ADD_FUNC(micReadData12), - ADD_FUNC(fifoSendAddress), - ADD_FUNC(fifoSendValue32), - ADD_FUNC(fifoSendDatamsg), - ADD_FUNC(fifoSetAddressHandler), - ADD_FUNC(fifoSetValue32Handler), - ADD_FUNC(fifoSetDatamsgHandler), - ADD_FUNC(fifoCheckAddress), - ADD_FUNC(fifoCheckValue32), - ADD_FUNC(fifoCheckDatamsg), - ADD_FUNC(fifoCheckDatamsgLength), - ADD_FUNC(fifoGetAddress), - ADD_FUNC(fifoGetValue32), - ADD_FUNC(fifoGetDatamsg), - ADD_FUNC(swiDelay), - ADD_FUNC_ALIAS(coop_swiIntrWaitCompat, swiIntrWait), - ADD_FUNC(memcpy), - ADD_FUNC(memcmp), - ADD_FUNC(memset), - ADD_FUNC(strcpy), - ADD_FUNC(strcmp), - ADD_FUNC(strncpy), - ADD_FUNC(strncmp), - ADD_FUNC(malloc), - ADD_FUNC(free), - ADD_FUNC(__aeabi_idiv), - ADD_FUNC(__aeabi_idivmod), - ADD_FUNC(__aeabi_uidiv), - ADD_FUNC(__aeabi_uidivmod), - ADD_FUNC(__aeabi_ldivmod), - ADD_FUNC(__aeabi_uldivmod), - ADD_FUNC(__aeabi_lmul), + ADD_ALIAS(swiWaitForVBlank, coopWaitForVBlank), + ADD_FUNC_(irqSet), + ADD_FUNC_(irqClear), + ADD_FUNC_(irqEnable), + ADD_FUNC_(irqDisable), + ADD_FUNC_(writePowerManagement), + ADD_FUNC_(timerStart), + ADD_FUNC_(timerPause), + ADD_FUNC_(timerStop), + ADD_FUNC_(timerElapsed), + ADD_FUNC_(micSetAmp), + ADD_FUNC_(micReadData8), + ADD_FUNC_(micReadData12), + ADD_FUNC_(fifoSendAddress), + ADD_FUNC_(fifoSendValue32), + ADD_FUNC_(fifoSendDatamsg), + ADD_FUNC_(fifoSetAddressHandler), + ADD_FUNC_(fifoSetValue32Handler), + ADD_FUNC_(fifoSetDatamsgHandler), + ADD_FUNC_(fifoCheckAddress), + ADD_FUNC_(fifoCheckValue32), + ADD_FUNC_(fifoCheckDatamsg), + ADD_FUNC_(fifoCheckDatamsgLength), + ADD_FUNC_(fifoGetAddress), + ADD_FUNC_(fifoGetValue32), + ADD_FUNC_(fifoGetDatamsg), + ADD_FUNC_(swiDelay), + ADD_ALIAS(swiIntrWait, coop_swiIntrWaitCompat), + ADD_FUNC_(memcpy), + ADD_FUNC_(memcmp), + ADD_FUNC_(memset), + ADD_FUNC_(strcpy), + ADD_FUNC_(strcmp), + ADD_FUNC_(strncpy), + ADD_FUNC_(strncmp), + ADD_FUNC_(malloc), + ADD_FUNC_(free), + ADD_FUNC_(__aeabi_idiv), + ADD_FUNC_(__aeabi_idivmod), + ADD_FUNC_(__aeabi_uidiv), + ADD_FUNC_(__aeabi_uidivmod), + ADD_FUNC_(__aeabi_ldivmod), + ADD_FUNC_(__aeabi_uldivmod), + ADD_FUNC_(__aeabi_lmul), - ADD_FUNC(coopFifoSetDatamsgHandler), - ADD_FUNC(coopFifoSetValue32Handler), - ADD_FUNC(coopFifoSetAddressHandler), - ADD_FUNC(coopIrqSet), - ADD_FUNC(coopIrqCheck), - ADD_FUNC(coopIrqNext), - ADD_FUNC(coopTimerStart) + ADD_FUNC_(coopFifoSetDatamsgHandler), + ADD_FUNC_(coopFifoSetValue32Handler), + ADD_FUNC_(coopFifoSetAddressHandler), + ADD_FUNC_(coopIrqSet), + ADD_FUNC_(coopIrqCheck), + ADD_FUNC_(coopIrqNext), + ADD_FUNC_(coopTimerStart) }; -bool FeOS_ResolveImp(word_t* addr, const char* name) +bool Ke7ResolveImp(word_t* addr, const char* name) { register int i; for (i = 0; i < arm7_func_count; i ++) diff --git a/arm7/source/main.c b/arm7/source/main.c index 25e99a5..a4832cd 100644 --- a/arm7/source/main.c +++ b/arm7/source/main.c @@ -95,7 +95,7 @@ int main() while (!exitflag) { coopWaitForVBlank(); - FeOS_VBlankFunc(); + Ke7VBlankISR(); if (!(REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) break; Wifi_Update(); diff --git a/kernel/source/swihook.s b/kernel/source/cpu.s similarity index 60% rename from kernel/source/swihook.s rename to kernel/source/cpu.s index 7981304..03c06bc 100644 --- a/kernel/source/swihook.s +++ b/kernel/source/cpu.s @@ -50,25 +50,25 @@ __SWIHandler: __SVCTable: @ Public functions (0x0Z) .word 0 - .word LoadModule_ARM7 - .word FreeModule_ARM7 - .word keyboardUpdate - .word __FeOS_IRQPoll + .word 0 + .word 0 + .word 0 + .word _DSIRQPoll .word DC_FlushRange .word DC_FlushAll .word IC_InvalidateRange .word IC_InvalidateAll - .word irqEnable - .word irqDisable - .word InitConMode - .word InitFreeMode + .word 0 + .word 0 + .word 0 + .word 0 .word __SetExcptHandler - .word _SetValue32Handler - .word _SetAddressHandler + .word 0 + .word 0 @ Kernel functions (0x1Z) .word 0 - .word FeOS_SetSuspendMode + .word 0 #ifdef DEBUG .word __sassert #else @@ -78,10 +78,10 @@ __SVCTable: writehook conerr .word 0 .word 0 - .word __FeOS_DrainWriteBuffer - .word __FeOS_WaitForMemAddr - .word _TimerWrite - .word _TimerTick + .word _DC_DrainWriteBuffer + .word _DSWaitForMemAddr + .word 0 + .word 0 .space 4*5 @ FAT hooks (0x2Z ~ 0x3Z) @@ -107,31 +107,7 @@ __SVCTable: writehook fatfsync .space 4*13 - @ FIFO functions (0x4Z) - .word fifoSendAddress - .word fifoSendValue32 - .word fifoSendDatamsg - .word fifoCheckAddress - .word fifoCheckValue32 - .word fifoCheckDatamsg - .word fifoGetAddress - .word fifoGetValue32 - .word fifoGetDatamsg - .word fifoCheckDatamsgLength - .space 4*6 - - @ Math functions (0x5Z) - .word FeOS_div3232 - .word FeOS_mod3232 - .word FeOS_div6432 - .word FeOS_mod6432 - .word FeOS_div6464 - .word FeOS_mod6464 - .word FeOS_sqrt32 - .word FeOS_sqrt64 - .space 4*8 - - .space 4*160 + .space 4*192 .align 2 @@ -146,7 +122,7 @@ __ResetHandler: .word 0xE7F000F0 .align 2 -__FeOS_IRQPoll: +_DSIRQPoll: @ savedIME = REG_IME, REG_IME = 1 mov r2, #1 mov r12, #0x4000000 @@ -164,12 +140,12 @@ __FeOS_IRQPoll: bx lr .align 2 -__FeOS_DrainWriteBuffer: +_DC_DrainWriteBuffer: mcr p15, 0, r0, c7, c10, 4 bx lr .align 2 -__FeOS_WaitForMemAddr: +_DSWaitForMemAddr: bic r3, r0, #0x1F .Lwait_addr: mcr p15, 0, r3, c7, c14, 1 // invalidate line @@ -180,9 +156,9 @@ __FeOS_WaitForMemAddr: .text .align 2 -.global PrepareUserMode -.type PrepareUserMode, %function -PrepareUserMode: +.global KeInitUserMode +.type KeInitUserMode, %function +KeInitUserMode: @ Copy ITCM MPU section to GBA ROM section mrc p15, 0, r0, c6, c4, 0 mcr p15, 0, r0, c6, c3, 0 @@ -198,49 +174,25 @@ PrepareUserMode: bx lr AccessSettings: - .word 0x33313151 - @.word 0x33311151 - @.word 0x31113151 - @.word 0x32113551 - @.word 0x32313551 - -AccessSettings2: .word 0x33313153 - @.word 0x33311153 - -.align 2 -.global UnblockIORegion -.type UnblockIORegion, %function -UnblockIORegion: - ldr r0, AccessSettings2 - mcr p15, 0, r0, c5, c0, 2 @ data - bx lr - -.align 2 -.global BlockIORegion -.type BlockIORegion, %function -BlockIORegion: - ldr r0, AccessSettings - mcr p15, 0, r0, c5, c0, 2 @ data - bx lr .align 2 -.global FeOS_IRQPoll -.type FeOS_IRQPoll, %function -FeOS_IRQPoll: +.global DSIRQPoll +.type DSIRQPoll, %function +DSIRQPoll: mrs r0, cpsr tst r0, #0xF beq .Lpoll_from_user_mode - ldr pc, =__FeOS_IRQPoll + ldr pc, =_DSIRQPoll .Lpoll_from_user_mode: swi 0x040000 bx lr .align 2 -.global DoTheUserMode -.type DoTheUserMode, %function -DoTheUserMode: +.global KeEnterUserMode +.type KeEnterUserMode, %function +KeEnterUserMode: @ Switch to user mode mrs r0, cpsr bic r0, r0, #0xF @@ -335,57 +287,21 @@ __isEmulator: @ Only to be called once! .macro swiimp name num .align 2 -.global FeOS_swi_\name -.type FeOS_swi_\name, %function +.global \name +.type \name, %function .thumb_func -FeOS_swi_\name\(): +\name\(): swi \num bx lr .endm -swiimp LoadModule_ARM7 0x01 -swiimp FreeModule_ARM7 0x02 -swiimp keyboardUpdate 0x03 -swiimp DebugPrint 0x10 -swiimp SetSuspendMode 0x11 #ifdef DEBUG -swiimp assertfail 0x12 +swiimp __assert2 0x12 #endif -swiimp DataCacheFlush 0x05 -swiimp DataCacheFlushAll 0x06 -swiimp InstrCacheInvalidate 0x07 -swiimp InstrCacheInvalidateAll 0x08 -swiimp DrainWriteBuffer 0x17 -swiimp IrqEnable 0x09 -swiimp IrqDisable 0x0A -swiimp ConsoleMode 0x0B -swiimp DirectMode 0x0C -swiimp SetExcptHandler 0x0D -swiimp SetValue32Handler 0x0E -swiimp SetAddressHandler 0x0F - -swiimp SuspendIRQ_t 0x15 -swiimp RestoreIRQ_t 0x16 -swiimp WaitForMemAddr 0x18 -swiimp TimerWrite 0x19 -swiimp TimerTick 0x1A - -swiimp FifoSendAddress 0x40 -swiimp FifoSendValue32 0x41 -swiimp FifoSendDatamsg 0x42 -swiimp FifoCheckAddress 0x43 -swiimp FifoCheckValue32 0x44 -swiimp FifoCheckDatamsg 0x45 -swiimp FifoGetAddress 0x46 -swiimp FifoGetValue32 0x47 -swiimp FifoGetDatamsg 0x48 -swiimp FifoCheckDatamsgLength 0x49 - -swiimp div3232 0x50 -swiimp mod3232 0x51 -swiimp div6432 0x52 -swiimp mod6432 0x53 -swiimp div6464 0x54 -swiimp mod6464 0x55 -swiimp sqrt32 0x56 -swiimp sqrt64 0x57 +swiimp KeDataCacheFlush 0x05 +swiimp KeDataCacheFlushAll 0x06 +swiimp KeInstrCacheInvalidate 0x07 +swiimp KeInstrCacheInvalidateAll 0x08 +swiimp DC_DrainWriteBuffer 0x17 +swiimp KeSetExcptHandler 0x0D +swiimp KeWaitForMemAddr 0x18 diff --git a/kernel/source/dsapi.c b/kernel/source/dsapi.c deleted file mode 100644 index 7c39716..0000000 --- a/kernel/source/dsapi.c +++ /dev/null @@ -1,271 +0,0 @@ -#include "feos.h" -#include "fxe.h" - -typedef struct { int x, y; } styluspos_t; - -extern volatile touchPosition touchPos; - -void FeOS_GetStylusPos(styluspos_t* pos) -{ - pos->x = touchPos.px; - pos->y = touchPos.py; -} - -void FeOS_swi_ConsoleMode(); -void FeOS_swi_DirectMode(); -int GetCurMode(); -void videoReset(); - -static OamState* FeOS_GetMainOAM() -{ - return &oamMain; -} - -static OamState* FeOS_GetSubOAM() -{ - return &oamSub; -} - -static SpriteEntry* FeOS_GetOAMMemory(OamState* oam) -{ - sassert(oam == &oamMain || oam == &oamSub, "Invalid parameter"); - return oam->oamMemory; -} - -// A custom version must be used because of the usage of swiWaitForVBlank and DC_FlushRange -static void _FeOS_oamInit(OamState* oam, SpriteMapping mapping, bool extPalette) -{ - int i; - int extPaletteFlag = extPalette ? DISPLAY_SPR_EXT_PALETTE : 0; - - sassert(oam == &oamMain || oam == &oamSub, "Invalid parameter"); - - oam->gfxOffsetStep = (mapping & 3) + 5; - - oam->spriteMapping = mapping; - - dmaFillWords(0, oam->oamMemory, 128*sizeof(SpriteEntry)); - - for(i = 0; i < 128; i ++) - oam->oamMemory[i].isHidden = true; - - for(i = 0; i < 32; i ++) - { - oam->oamRotationMemory[i].hdx = (1<<8); - oam->oamRotationMemory[i].vdy = (1<<8); - } - - FeOS_WaitForVBlankRaw(); - - FeOS_swi_DataCacheFlush(oam->oamMemory, 128*sizeof(SpriteEntry)); - - if(oam == &oamMain) - { - dmaCopy(oam->oamMemory, OAM, 128*sizeof(SpriteEntry)); - - REG_DISPCNT &= ~DISPLAY_SPRITE_ATTR_MASK; - REG_DISPCNT |= DISPLAY_SPR_ACTIVE | (mapping & 0xffffff0) | extPaletteFlag; - }else - { - dmaCopy(oam->oamMemory, OAM_SUB, 128*sizeof(SpriteEntry)); - - REG_DISPCNT_SUB &= ~DISPLAY_SPRITE_ATTR_MASK; - REG_DISPCNT_SUB |= DISPLAY_SPR_ACTIVE | (mapping & 0xffffff0) | extPaletteFlag; - } - - oamAllocReset(oam); -} - -#define TIMER_CR_32(n) (*(vu32*)(0x04000100+((n)<<2))) - -void FeOS_swi_TimerWrite(int timer, word_t v); -void _TimerWrite(int timer, word_t v) -{ - TIMER_CR_32(timer&3) = v; -} - -u16 FeOS_swi_TimerTick(int timer); -u16 _TimerTick(int timer) -{ - return TIMER_DATA(timer&3); -} - -void FeOS_KeysUpdate() -{ - if (!bKeyUpd) scanKeys(); -} - -// A custom version must be used because of the usage of DC_FlushRange -void _FeOS_oamUpdate(OamState* oam) -{ - sassert(oam == &oamMain || oam == &oamSub, "Invalid parameter"); - - if (bOAMUpd) return; - - FeOS_swi_DataCacheFlush(oam->oamMemory, 128*sizeof(SpriteEntry)); - - if (oam == &oamMain) - dmaCopy(oam->oamMemory, OAM, 128*sizeof(SpriteEntry)); - else - dmaCopy(oam->oamMemory, OAM_SUB, 128*sizeof(SpriteEntry)); -} - -void _FeOS_bgUpdate() -{ - if (!bBgUpd) bgUpdate(); -} - -typedef struct -{ - void (* directMode)(); - void (* consoleMode)(); - int (* getMode)(); -} modeshim_t; - -static modeshim_t* pModeShim = NULL; - -static void directModeShim() -{ - pModeShim ? pModeShim->directMode() : FeOS_swi_DirectMode(); -} - -static void consoleModeShim() -{ - pModeShim ? pModeShim->consoleMode() : FeOS_swi_ConsoleMode(); -} - -static int getModeShim() -{ - return pModeShim ? pModeShim->getMode() : GetCurMode(); -} - -static modeshim_t* installModeShim(modeshim_t* pNewShim) -{ - modeshim_t* pOldShim = pModeShim; - if (pNewShim != (modeshim_t*)~0) - pModeShim = pNewShim; - return pOldShim; -} - -static void FeOS_VideoReset() -{ - if (GetCurMode()) return; - - videoReset(); -} - -BEGIN_TABLE(FEOSDSAPI) - ADD_FUNC(keysDown), - ADD_FUNC(keysHeld), - ADD_FUNC(keysUp), - ADD_FUNC(keysDownRepeat), - ADD_FUNC(keysSetRepeat), - ADD_FUNC_ALIAS(FeOS_KeysUpdate, scanKeys), - ADD_FUNC(FeOS_GetStylusPos), - ADD_FUNC_ALIAS(FeOS_SetInterrupt, irqSet), - ADD_FUNC(FeOS_CheckPendingIRQs), - ADD_FUNC(FeOS_WaitForIRQ), - ADD_FUNC(FeOS_SetIRQWaitFunc), - ADD_FUNC(FeOS_NextIRQ), - ADD_FUNC_ALIAS(FeOS_swi_IrqDisable, irqDisable), - ADD_FUNC_ALIAS(FeOS_swi_IrqEnable, irqEnable), - ADD_FUNC_ALIAS(consoleModeShim, FeOS_ConsoleMode), - ADD_FUNC_ALIAS(directModeShim, FeOS_DirectMode), - ADD_FUNC_ALIAS(FeOS_swi_TimerWrite, FeOS_TimerWrite), - ADD_FUNC_ALIAS(FeOS_swi_TimerTick, FeOS_TimerTick), - ADD_FUNC_ALIAS(getModeShim, FeOS_GetMode), - ADD_FUNC_ALIAS(installModeShim, FeOS_ModeShim), - ADD_FUNC(FeOS_VideoReset), - ADD_FUNC(dmaCopyWords), - ADD_FUNC(dmaCopyHalfWords), - ADD_FUNC(dmaFillWords), - ADD_FUNC(dmaFillHalfWords), - ADD_FUNC(memUncached), - ADD_FUNC(memCached), - ADD_FUNC(vramSetPrimaryBanks), - ADD_FUNC(vramSetBanks_EFG), - ADD_FUNC(vramRestorePrimaryBanks), - ADD_FUNC(vramRestoreBanks_EFG), - ADD_FUNC(vramSetBankA), - ADD_FUNC(vramSetBankB), - ADD_FUNC(vramSetBankC), - ADD_FUNC(vramSetBankD), - ADD_FUNC(vramSetBankE), - ADD_FUNC(vramSetBankF), - ADD_FUNC(vramSetBankG), - ADD_FUNC(vramSetBankH), - ADD_FUNC(vramSetBankI), - ADD_FUNC(videoSetMode), - ADD_FUNC(videoSetModeSub), - ADD_FUNC(videoGetMode), - ADD_FUNC(videoGetModeSub), - ADD_FUNC(video3DEnabled), - ADD_FUNC(setBrightness), - ADD_FUNC(lcdSwap), - ADD_FUNC(lcdMainOnTop), - ADD_FUNC(lcdMainOnBottom), - ADD_FUNC(powerOn), - ADD_FUNC(powerOff) -END_TABLE(FEOSDSAPI) - -MAKE_FAKEMODULE(FEOSDSAPI) - -BEGIN_TABLE(FEOSDSSPR) - ADD_FUNC(FeOS_GetMainOAM), - ADD_FUNC(FeOS_GetSubOAM), - ADD_FUNC(FeOS_GetOAMMemory), - ADD_FUNC_ALIAS(_FeOS_oamInit, oamInit), - ADD_FUNC_ALIAS(_FeOS_oamUpdate, oamUpdate), - ADD_FUNC(oamDisable), - ADD_FUNC(oamEnable), - ADD_FUNC(oamGetGfxPtr), - ADD_FUNC(oamAllocateGfx), - ADD_FUNC(oamFreeGfx), - ADD_FUNC(oamSetMosaic), - ADD_FUNC(oamSetMosaicSub), - ADD_FUNC(oamSet), - ADD_FUNC(oamClear), - ADD_FUNC(oamClearSprite), - ADD_FUNC(oamRotateScale), - ADD_FUNC(oamAffineTransformation), - ADD_FUNC(oamGfxPtrToOffset) -END_TABLE(FEOSDSSPR) - -MAKE_FAKEMODULE(FEOSDSSPR) - -BEGIN_TABLE(FEOSDSBG) - ADD_FUNC(bgSetRotate), - ADD_FUNC(bgRotate), - ADD_FUNC(bgSet), - ADD_FUNC(bgSetRotateScale), - ADD_FUNC(bgSetScale), - ADD_FUNC(bgInit), - ADD_FUNC(bgInitSub), - ADD_FUNC_ALIAS(_FeOS_bgUpdate, bgUpdate), - ADD_FUNC(bgSetControlBits), - ADD_FUNC(bgClearControlBits), - ADD_FUNC(bgSetPriority), - ADD_FUNC(bgSetMapBase), - ADD_FUNC(bgSetTileBase), - ADD_FUNC(bgSetScrollf), - ADD_FUNC(bgMosaicEnable), - ADD_FUNC(bgMosaicDisable), - ADD_FUNC(bgSetMosaic), - ADD_FUNC(bgSetMosaicSub), - ADD_FUNC(bgGetMapPtr), - ADD_FUNC(bgGetGfxPtr), - ADD_FUNC(bgGetPriority), - ADD_FUNC(bgGetMapBase), - ADD_FUNC(bgGetTileBase), - ADD_FUNC(bgScrollf), - ADD_FUNC(bgShow), - ADD_FUNC(bgHide), - ADD_FUNC(bgSetCenterf), - ADD_FUNC(bgSetAffineMatrixScroll), - ADD_FUNC(bgExtPaletteEnable), - ADD_FUNC(bgExtPaletteEnableSub), - ADD_FUNC(bgExtPaletteDisable), - ADD_FUNC(bgExtPaletteDisableSub) -END_TABLE(FEOSDSBG) - -MAKE_FAKEMODULE(FEOSDSBG) diff --git a/kernel/source/dshw.c b/kernel/source/dshw.c new file mode 100644 index 0000000..31be338 --- /dev/null +++ b/kernel/source/dshw.c @@ -0,0 +1,272 @@ +#include "feos.h" +#include "loader.h" + +typedef struct { int x, y; } styluspos_t; + +extern volatile touchPosition touchPos; + +void DSTouchRead(styluspos_t* pos) +{ + pos->x = touchPos.px; + pos->y = touchPos.py; +} + +void DSConsoleMode(); +void DSDirectMode(); +int DSGetCurMode(); +void DSVideoReset(); + +static OamState* DSGetMainOAM() +{ + return &oamMain; +} + +static OamState* DSGetSubOAM() +{ + return &oamSub; +} + +static SpriteEntry* DSGetOAMMemory(OamState* oam) +{ + sassert(oam == &oamMain || oam == &oamSub, "Invalid parameter"); + return oam->oamMemory; +} + +// A custom version must be used because of the usage of swiWaitForVBlank and DC_FlushRange +static void oamInit2(OamState* oam, SpriteMapping mapping, bool extPalette) +{ + int i; + int extPaletteFlag = extPalette ? DISPLAY_SPR_EXT_PALETTE : 0; + + sassert(oam == &oamMain || oam == &oamSub, "Invalid parameter"); + + oam->gfxOffsetStep = (mapping & 3) + 5; + + oam->spriteMapping = mapping; + + dmaFillWords(0, oam->oamMemory, 128*sizeof(SpriteEntry)); + + for(i = 0; i < 128; i ++) + oam->oamMemory[i].isHidden = true; + + for(i = 0; i < 32; i ++) + { + oam->oamRotationMemory[i].hdx = (1<<8); + oam->oamRotationMemory[i].vdy = (1<<8); + } + + DSWaitForVBlankRaw(); + + KeDataCacheFlush(oam->oamMemory, 128*sizeof(SpriteEntry)); + + if(oam == &oamMain) + { + dmaCopy(oam->oamMemory, OAM, 128*sizeof(SpriteEntry)); + + REG_DISPCNT &= ~DISPLAY_SPRITE_ATTR_MASK; + REG_DISPCNT |= DISPLAY_SPR_ACTIVE | (mapping & 0xffffff0) | extPaletteFlag; + }else + { + dmaCopy(oam->oamMemory, OAM_SUB, 128*sizeof(SpriteEntry)); + + REG_DISPCNT_SUB &= ~DISPLAY_SPRITE_ATTR_MASK; + REG_DISPCNT_SUB |= DISPLAY_SPR_ACTIVE | (mapping & 0xffffff0) | extPaletteFlag; + } + + oamAllocReset(oam); +} + +#define TIMER_CR_32(n) (*(vu32*)(0x04000100+((n)<<2))) + +void DSTimerWrite(int timer, word_t v) +{ + TIMER_CR_32(timer&3) = v; +} + +u16 DSTimerTick(int timer) +{ + return TIMER_DATA(timer&3); +} + +void DSScanKeys() +{ + if (!bKeyUpd) scanKeys(); +} + +// A custom version must be used because of the usage of DC_FlushRange +void oamUpdate2(OamState* oam) +{ + sassert(oam == &oamMain || oam == &oamSub, "Invalid parameter"); + + if (bOAMUpd) return; + + KeDataCacheFlush(oam->oamMemory, 128*sizeof(SpriteEntry)); + + if (oam == &oamMain) + dmaCopy(oam->oamMemory, OAM, 128*sizeof(SpriteEntry)); + else + dmaCopy(oam->oamMemory, OAM_SUB, 128*sizeof(SpriteEntry)); +} + +void DSBgUpdate() +{ + if (!bBgUpd) bgUpdate(); +} + +typedef struct +{ + void (* directMode)(); + void (* consoleMode)(); + int (* getMode)(); +} modeshim_t; + +static modeshim_t* pModeShim = NULL; + +static void directModeShim() +{ + pModeShim ? pModeShim->directMode() : DSDirectMode(); +} + +static void consoleModeShim() +{ + pModeShim ? pModeShim->consoleMode() : DSConsoleMode(); +} + +static int getModeShim() +{ + return pModeShim ? pModeShim->getMode() : DSGetCurMode(); +} + +static modeshim_t* DSModeShim(modeshim_t* pNewShim) +{ + modeshim_t* pOldShim = pModeShim; + if (pNewShim != (modeshim_t*)~0) + pModeShim = pNewShim; + return pOldShim; +} + +module_t DSLoadARM7(const char*, int*); +void DSFreeARM7(module_t, int); + +BEGIN_TABLE(FEOSDSHW) + ADD_ALIAS(DSConsoleMode, consoleModeShim), + ADD_ALIAS(DSDirectMode, directModeShim), + ADD_FUNC_(DSFreeARM7), + ADD_FUNC_(DSGetMainOAM), + ADD_ALIAS(DSGetMode, getModeShim), + ADD_FUNC_(DSGetOAMMemory), + ADD_FUNC_(DSGetSubOAM), + ADD_FUNC_(DSLoadARM7), + ADD_FUNC_(DSModeShim), + ADD_FUNC_(DSProcessIRQs), + ADD_FUNC_(DSSetIRQWaitFunc), + ADD_FUNC_(DSSetSuspendMode), + ADD_FUNC_(DSTimerTick), + ADD_FUNC_(DSTimerWrite), + ADD_FUNC_(DSVideoReset), + ADD_FUNC_(DSWaitForIRQ), + ADD_ALIAS(DSWaitForNextIRQ, DSWaitForNextIRQRaw), + ADD_FUNC_(bgClearControlBits), + ADD_FUNC_(bgExtPaletteDisable), + ADD_FUNC_(bgExtPaletteDisableSub), + ADD_FUNC_(bgExtPaletteEnable), + ADD_FUNC_(bgExtPaletteEnableSub), + ADD_FUNC_(bgGetGfxPtr), + ADD_FUNC_(bgGetMapBase), + ADD_FUNC_(bgGetMapPtr), + ADD_FUNC_(bgGetPriority), + ADD_FUNC_(bgGetTileBase), + ADD_FUNC_(bgHide), + ADD_FUNC_(bgInit), + ADD_FUNC_(bgInitSub), + ADD_FUNC_(bgMosaicDisable), + ADD_FUNC_(bgMosaicEnable), + ADD_FUNC_(bgRotate), + ADD_FUNC_(bgScrollf), + ADD_FUNC_(bgSet), + ADD_FUNC_(bgSetAffineMatrixScroll), + ADD_FUNC_(bgSetCenterf), + ADD_FUNC_(bgSetControlBits), + ADD_FUNC_(bgSetMapBase), + ADD_FUNC_(bgSetMosaic), + ADD_FUNC_(bgSetMosaicSub), + ADD_FUNC_(bgSetPriority), + ADD_FUNC_(bgSetRotate), + ADD_FUNC_(bgSetRotateScale), + ADD_FUNC_(bgSetScale), + ADD_FUNC_(bgSetScrollf), + ADD_FUNC_(bgSetTileBase), + ADD_FUNC_(bgShow), + ADD_ALIAS(bgUpdate, DSBgUpdate), + ADD_FUNC_(dmaCopyHalfWords), + ADD_FUNC_(dmaCopyWords), + ADD_FUNC_(dmaFillHalfWords), + ADD_FUNC_(dmaFillWords), + ADD_FUNC_(fifoCheckAddress), + ADD_FUNC_(fifoCheckDatamsg), + ADD_FUNC_(fifoCheckDatamsgLength), + ADD_FUNC_(fifoCheckValue32), + ADD_FUNC_(fifoGetAddress), + ADD_FUNC_(fifoGetDatamsg), + ADD_ALIAS(fifoGetRetValue32, DSFifoGetRetValue32), + ADD_FUNC_(fifoGetValue32), + ADD_FUNC_(fifoSendAddress), + ADD_FUNC_(fifoSendDatamsg), + ADD_FUNC_(fifoSendValue32), + ADD_ALIAS(fifoSetAddressHandler, DSFifoSetAddressHandler), + ADD_ALIAS(fifoSetDatamsgHandler, DSFifoSetDatamsgHandler), + ADD_ALIAS(fifoSetValue32Handler, DSFifoSetValue32Handler), + ADD_FUNC_(irqDisable), + ADD_FUNC_(irqEnable), + ADD_ALIAS(irqSet, DSIrqSet), + ADD_FUNC_(keysDown), + ADD_FUNC_(keysDownRepeat), + ADD_FUNC_(keysHeld), + ADD_FUNC_(keysSetRepeat), + ADD_FUNC_(keysUp), + ADD_FUNC_(lcdMainOnBottom), + ADD_FUNC_(lcdMainOnTop), + ADD_FUNC_(lcdSwap), + ADD_FUNC_(memCached), + ADD_FUNC_(memUncached), + ADD_FUNC_(oamAffineTransformation), + ADD_FUNC_(oamAllocateGfx), + ADD_FUNC_(oamClear), + ADD_FUNC_(oamClearSprite), + ADD_FUNC_(oamDisable), + ADD_FUNC_(oamEnable), + ADD_FUNC_(oamFreeGfx), + ADD_FUNC_(oamGetGfxPtr), + ADD_FUNC_(oamGfxPtrToOffset), + ADD_ALIAS(oamInit, oamInit2), + ADD_FUNC_(oamRotateScale), + ADD_FUNC_(oamSet), + ADD_FUNC_(oamSetMosaic), + ADD_FUNC_(oamSetMosaicSub), + ADD_ALIAS(oamUpdate, oamUpdate2), + ADD_FUNC_(powerOff), + ADD_FUNC_(powerOn), + ADD_ALIAS(scanKeys, DSScanKeys), + ADD_FUNC_(setBrightness), + ADD_ALIAS(touchRead, DSTouchRead), + ADD_FUNC_(video3DEnabled), + ADD_FUNC_(videoGetMode), + ADD_FUNC_(videoGetModeSub), + ADD_FUNC_(videoSetMode), + ADD_FUNC_(videoSetModeSub), + ADD_FUNC_(vramRestoreBanks_EFG), + ADD_FUNC_(vramRestorePrimaryBanks), + ADD_FUNC_(vramSetBankA), + ADD_FUNC_(vramSetBankB), + ADD_FUNC_(vramSetBankC), + ADD_FUNC_(vramSetBankD), + ADD_FUNC_(vramSetBankE), + ADD_FUNC_(vramSetBankF), + ADD_FUNC_(vramSetBankG), + ADD_FUNC_(vramSetBankH), + ADD_FUNC_(vramSetBankI), + ADD_FUNC_(vramSetBanks_EFG), + ADD_FUNC_(vramSetPrimaryBanks), +END_TABLE(FEOSDSHW) + +MAKE_FAKEMODULE(FEOSDSHW) diff --git a/kernel/source/excptstub.s b/kernel/source/excpt.s similarity index 99% rename from kernel/source/excptstub.s rename to kernel/source/excpt.s index fa4f4aa..6c357ad 100644 --- a/kernel/source/excptstub.s +++ b/kernel/source/excpt.s @@ -136,7 +136,7 @@ __SetExcptHandler: cmp r0, #0 bne .LnoRestore mov r0, r4 - bl FeOS_swi_SetExcptHandler + bl KeSetExcptHandler .LnoRestore: @ Resume execution diff --git a/kernel/source/feos.h b/kernel/source/feos.h index c8dfa9b..decf5aa 100644 --- a/kernel/source/feos.h +++ b/kernel/source/feos.h @@ -7,12 +7,12 @@ #define ITCM_DATA __attribute__((section(".itcm"))) #endif -#define FeOS_AllocStack(a) __builtin_alloca(a) +#define KeAllocStack(a) __builtin_alloca(a) #ifdef ARM9 #define BEGIN_TABLE(_NAME_) static const fxe2_export_t _exp_##_NAME_##_tbl[] = { -#define ADD_FUNC(FUNC) {{(word_t)#FUNC}, {(word_t)FUNC}} -#define ADD_FUNC_ALIAS(FUNC, NAME) {{(word_t)#NAME}, {(word_t)FUNC}} +#define ADD_FUNC_(FUNC) {{(word_t)#FUNC}, {(word_t)FUNC}} +#define ADD_ALIAS(NAME, FUNC) {{(word_t)#NAME}, {(word_t)FUNC}} #define END_TABLE(_NAME_) }; #define MAKE_EXPORTSTRUCT(_NAME_) { sizeof(_exp_##_NAME_##_tbl) / sizeof(fxe2_export_t), (fxe2_export_t*) _exp_##_NAME_##_tbl } @@ -43,13 +43,13 @@ typedef unsigned int word_t; typedef unsigned short hword_t; typedef unsigned char byte_t; typedef word_t bool_t; -typedef void* instance_t; +typedef void* module_t; #ifdef ARM9 #include "feos_setjmp.h" -void DoTheUserMode(); -void PrepareUserMode(); +void KeEnterUserMode(); +void KeInitUserMode(); word_t __ARMSWP(word_t value, volatile word_t* addr); @@ -66,61 +66,58 @@ static inline bool AddressCheckMainRAM(const void* addr) typedef void (*irqWaitFunc_t)(word_t); -void FeOS_RunFifoQueue(); -void FeOS_FifoSetDatamsgHandler(int channel, FifoDatamsgHandlerFunc handler, void* userdata); -void FeOS_FifoSetValue32Handler(int channel, FifoValue32HandlerFunc handler, void* userdata); -void FeOS_FifoSetAddressHandler(int channel, FifoAddressHandlerFunc handler, void* userdata); -VoidFn FeOS_SetInterrupt(word_t mask, VoidFn fn); -word_t FeOS_CheckPendingIRQs(); -void FeOS_WaitForIRQ(word_t mask); -void _FeOS_WaitForIRQ(word_t mask); -word_t FeOS_NextIRQ(); - -static inline void FeOS_WaitForVBlank() +void DSRunFifoQueue(); +void DSFifoSetDatamsgHandler(int channel, FifoDatamsgHandlerFunc handler, void* userdata); +void DSFifoSetValue32Handler(int channel, FifoValue32HandlerFunc handler, void* userdata); +void DSFifoSetAddressHandler(int channel, FifoAddressHandlerFunc handler, void* userdata); +word_t DSFifoGetRetValue32(int); +VoidFn DSIrqSet(word_t mask, VoidFn fn); +word_t DSProcessIRQs(); +void DSWaitForIRQ(word_t mask); +void DSWaitForIRQRaw(word_t mask); +word_t DSWaitForNextIRQRaw(); + +static inline void DSWaitForVBlank() { - FeOS_WaitForIRQ(IRQ_VBLANK); + DSWaitForIRQ(IRQ_VBLANK); } -static inline void FeOS_WaitForVBlankRaw() +static inline void DSWaitForVBlankRaw() { - _FeOS_WaitForIRQ(IRQ_VBLANK); + DSWaitForIRQRaw(IRQ_VBLANK); } #define GET_IRQFUNC ((irqWaitFunc_t)0xFFFFFFFF) -irqWaitFunc_t FeOS_SetIRQWaitFunc(irqWaitFunc_t newFunc); +irqWaitFunc_t DSSetIRQWaitFunc(irqWaitFunc_t newFunc); int __getMode(); #define isUserMode() (__getMode() == 0x10) enum { MODE_GET = -1, MODE_DISABLED = 0, MODE_NORMAL, MODE_HEADPHONES, MODE_COUNT }; -int FeOS_swi_SetSuspendMode(int mode); +int DSSetSuspendMode(int mode); #define ERRSTR_INVALIDPARAM "Invalid parameter" -#define CHK_HINST(hInst) sassert(AddressCheckMainRAM(hInst), ERRSTR_INVALIDPARAM); +#define CHK_HMOD(hMod) sassert(AddressCheckMainRAM(hMod), ERRSTR_INVALIDPARAM); #define tell(fd) lseek(fd, 0, SEEK_CUR) extern bool bOAMUpd, bBgUpd, bKeyUpd; enum { AUTOUPD_OAM = 1, AUTOUPD_BG, AUTOUPD_KEYS }; -void FeOS_SetAutoUpdate(int which, bool enable); -bool FeOS_GetAutoUpdate(int which); - -void FeOS_swi_DataCacheFlush(const void* mem, size_t size); -void FeOS_swi_DataCacheFlushAll(); -void FeOS_swi_InstrCacheInvalidate(const void* mem, size_t size); -void FeOS_swi_InstrCacheInvalidateAll(); -void FeOS_swi_IrqEnable(word_t mask); -void FeOS_swi_IrqDisable(word_t mask); -//void FeOS_swi_SetDatamsgHandler(int, bool); -int FeOS_swi_FifoCheckDatamsgLength(int ch); -void FeOS_swi_SetValue32Handler(int, bool); -void FeOS_swi_SetAddressHandler(int, bool); +void DSSetAutoUpdate(int which, bool enable); +bool DSGetAutoUpdate(int which); + +void KeDataCacheFlush(const void* mem, size_t size); +void KeDataCacheFlushAll(); +void KeInstrCacheInvalidate(const void* mem, size_t size); +void KeInstrCacheInvalidateAll(); +void DSSetValue32Handler(int, bool); +void DSSetAddressHandler(int, bool); typedef struct { word_t refcount; - instance_t curInstance; + module_t curModule; word_t* exitBuf; bool exitDone; void *stdin_hook; @@ -144,7 +141,7 @@ extern vu32* g_fatCwdClusterPtr; // Hidden libfat function that gets a pointer to the cwd cluster variable uint32_t* _FAT_getCwdClusterPtr(const char* name); -void FeOS_InitDefaultExecStatus(); +void KeInitDefaultExecStatus(); #endif #endif diff --git a/kernel/source/feosarm7.c b/kernel/source/feosarm7.c deleted file mode 100644 index 73d5290..0000000 --- a/kernel/source/feosarm7.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "feos.h" -#include "fxe.h" - -instance_t FeOS_swi_LoadModule_ARM7(const char*, int*); -void FeOS_swi_FreeModule_ARM7(instance_t, int); - -bool FeOS_swi_FifoSendAddress(int, void*); -bool FeOS_swi_FifoSendValue32(int, word_t); -bool FeOS_swi_FifoSendDatamsg(int, word_t, void*); -bool FeOS_swi_FifoCheckAddress(int); -bool FeOS_swi_FifoCheckValue32(int); -bool FeOS_swi_FifoCheckDatamsg(int); -void* FeOS_swi_FifoGetAddress(int); -word_t FeOS_swi_FifoGetValue32(int); -int FeOS_swi_FifoGetDatamsg(int, word_t, void*); - -word_t FeOS_FifoGetRetValue32(int); - -#define ADD_FUNC2(fn) ADD_FUNC_ALIAS(FeOS_swi_Fifo##fn, fifo##fn) - -BEGIN_TABLE(FEOSARM7) - ADD_FUNC_ALIAS(FeOS_swi_LoadModule_ARM7, FeOS_LoadARM7), - ADD_FUNC_ALIAS(FeOS_swi_FreeModule_ARM7, FeOS_FreeARM7), - ADD_FUNC2(SendAddress), - ADD_FUNC2(SendValue32), - ADD_FUNC2(SendDatamsg), - ADD_FUNC2(CheckAddress), - ADD_FUNC2(CheckValue32), - ADD_FUNC2(CheckDatamsg), - ADD_FUNC2(CheckDatamsgLength), - ADD_FUNC2(GetAddress), - ADD_FUNC2(GetValue32), - ADD_FUNC2(GetDatamsg), - ADD_FUNC_ALIAS(FeOS_FifoSetDatamsgHandler, fifoSetDatamsgHandler), - ADD_FUNC_ALIAS(FeOS_FifoSetValue32Handler, fifoSetValue32Handler), - ADD_FUNC_ALIAS(FeOS_FifoSetAddressHandler, fifoSetAddressHandler), - ADD_FUNC_ALIAS(FeOS_FifoGetRetValue32, fifoGetRetValue32), -END_TABLE(FEOSARM7) - -MAKE_FAKEMODULE(FEOSARM7) \ No newline at end of file diff --git a/kernel/source/feosbase.c b/kernel/source/feosbase.c deleted file mode 100644 index 9db1e8a..0000000 --- a/kernel/source/feosbase.c +++ /dev/null @@ -1,528 +0,0 @@ -#include "feos.h" -#include "fxe.h" -#include "feosfifo.h" -#include -#include -#include -#include -#include -#include - -#include -#include - -void* FeOS_FindSymbol(instance_t hinst, const char* sym) -{ - CHK_HINST(hinst); - return FindInTbl(&GetRuntimeData(hinst)->exp, sym); -} - -int __aeabi_idiv(int, int); -int __aeabi_idivmod(int, int); -unsigned int __aeabi_uidiv(unsigned int, unsigned int); -unsigned int __aeabi_uidivmod(unsigned int, unsigned int); - -long long __aeabi_ldivmod(long long, long long); -unsigned long long __aeabi_uldivmod(unsigned long long, unsigned long long); - -int FeOS_swi_SuspendIRQ_t(); -void FeOS_swi_RestoreIRQ_t(int); -void FeOS_swi_DrainWriteBuffer(); -void FeOS_swi_WaitForMemAddr(volatile byte_t*, byte_t); - -void FeOS_swi_SetExcptHandler(void*); - -// Execution status functions - -typedef void* execstat_t; - -execstat_t FeOS_ExecStatusCreate(); -void FeOS_ExecStatusAddRef(execstat_t hSt); -void FeOS_ExecStatusRelease(execstat_t hSt); -void FeOS_SetCurExecStatus(execstat_t hSt); -execstat_t FeOS_GetCurExecStatus(); - -typedef int (* systemfunc_t)(const char* command); - -systemfunc_t __system; - -int system(const char* command) -{ - if (command == NULL) return !!__system; - return __system(command); -} - -const char* FeOS_GetModuleName(instance_t hInst) -{ - CHK_HINST(hInst); - return GetRuntimeData(hInst)->name; -} - -instance_t FeOS_GetModule(const char* name) -{ - sassert(name, ERRSTR_INVALIDPARAM); - fxe_runtime_header* rh = FeOS_ModuleListFind(name); - return rh ? rh->hThis : NULL; -} - -// Memory/disk usage functions - -typedef struct -{ - word_t total, free, used; -} usagestats_t; - -typedef struct -{ - u64 total, free, used; -} usagestats64_t; - -bool FeOS_GetDiskStats(usagestats_t* pStats) -{ - struct statvfs fiData; - if (pStats && statvfs("/", &fiData) >= 0) - { - pStats->total = fiData.f_frsize * fiData.f_blocks; - pStats->free = fiData.f_bsize * fiData.f_bfree; - pStats->used = pStats->total - pStats->free; - return true; - } - return false; -} - -bool FeOS_GetDiskStats64(usagestats64_t* pStats) -{ - struct statvfs fiData; - if (pStats && statvfs("/", &fiData) >= 0) - { - pStats->total = (u64)fiData.f_frsize * fiData.f_blocks; - pStats->free = (u64)fiData.f_bsize * fiData.f_bfree; - pStats->used = pStats->total - pStats->free; - return true; - } - return false; -} - -void FeOS_GetMemStats(usagestats_t* pStats) -{ - if (!pStats) return; - - u8 *heapLimit = getHeapLimit(), *heapStart = getHeapStart(), *heapEnd = getHeapEnd(); - struct mallinfo mi = mallinfo(); - pStats->used = mi.uordblks; - pStats->free = mi.fordblks + (heapLimit - heapEnd); - pStats->total = heapLimit - heapStart; -} - -int FeOS_GetTickCount() -{ - extern volatile int vblankCounter; - return vblankCounter; -} - -int FeOS_GetVersion() -{ - return FEOS_VERSION_PACK; -} - -static systeminfo_t sysInfo = -{ - FEOS_VERSION_PACK, - FEOS_VERSION_TEXT, -#ifndef DEBUG - 0, -#else - SYSTEM_FLAGS_DEBUG, -#endif - SYSTEM_TYPE_DS, - NULL, - SYSTEM_MODE_DS, - NULL, -}; - -void FeOS_InitSystemInfo() -{ - extern bool __dsimode; - -#define SYSTYPE sysInfo.systemType -#define SYSFLAGS sysInfo.systemFlags - - // DSi mode detection - if (__dsimode) - { - sysInfo.systemMode = SYSTEM_MODE_DSi; - sysInfo.systemType = SYSTEM_TYPE_DSi; - } - - byte_t fw1D, fw2F, pm4; - // Retrieve some bits from ARM7 - { - FeOSFifoMsg msg; - msg.type = FEOS_ARM7_GET_SYSTEM_INFO; - - fifoSendDatamsg(FIFO_FEOS, sizeof(msg), (void*) &msg); - while (!fifoCheckValue32(FIFO_FEOS)); - - word_t ret = fifoGetValue32(FIFO_FEOS); - fw1D = ret; - fw2F = ret >> 8; - pm4 = ret >> 16; - } - - // Detect system type - // Based on http://adshomebrewersdiary.blogspot.com.es/2012/01/telling-ds-models-apart.html - - if (SYSTYPE == SYSTEM_TYPE_DS) do - { - if (swiIsDebugger()) - { - SYSTYPE = SYSTEM_TYPE_DSDebug; - break; - } - - if (pm4 & 0x80) - { - SYSTYPE = SYSTEM_TYPE_DSLite; - break; - } - - if (fw1D != 0xFF && fw1D & 3) - SYSFLAGS |= SYSTEM_FLAGS_CHINESE; - } while(0); - - if (SYSTYPE == SYSTEM_TYPE_DSLite) do - { - if (fw1D & 4) - { - SYSTYPE = SYSTEM_TYPE_DSi; - break; - } - - if (fw1D & 3) - SYSFLAGS |= SYSTEM_FLAGS_CHINESE; - } while(0); - - if (SYSTYPE == SYSTEM_TYPE_DSi) do - { - if (fw2F >= 0x18) - { - SYSTYPE = SYSTEM_TYPE_DSi_XL; - break; - } - - // TODO: chinese DSi detection - } while(0); - - if (SYSTYPE == SYSTEM_TYPE_DSi_XL) do - { - if (fw2F >= 0x1C) - { - SYSTYPE = SYSTEM_TYPE_3DS; - break; - } - - // TODO: chinese DSi XL detection - } while(0); - - // TODO: 3DS XL detection - // TODO: chinese 3DS XL detection (does that even exist??) - - // Emulator detection - bool __isEmulator(); - if (__isEmulator()) - SYSFLAGS |= SYSTEM_FLAGS_EMULATOR; - -#undef SYSTYPE -#undef SYSFLAGS - - switch (sysInfo.systemType) - { -#define _TEXT(_x,_y) case _x: sysInfo.systemTypeText = _y; break - _TEXT(SYSTEM_TYPE_DS, "Nintendo DS (Original)"); - _TEXT(SYSTEM_TYPE_DSDebug, "Nintendo DS (Debug)"); - _TEXT(SYSTEM_TYPE_DSLite, "Nintendo DS Lite"); - _TEXT(SYSTEM_TYPE_DSi, "Nintendo DSi"); - _TEXT(SYSTEM_TYPE_DSi_XL, "Nintendo DSi XL"); - _TEXT(SYSTEM_TYPE_3DS, "Nintendo 3DS"); - _TEXT(SYSTEM_TYPE_3DS_XL, "Nintendo 3DS XL"); -#undef _TEXT - } - - switch (sysInfo.systemMode) - { -#define _TEXT(_x,_y) case _x: sysInfo.systemModeText = _y; break - _TEXT(SYSTEM_MODE_DS, "Standard DS Mode (67.03 MHz)"); - _TEXT(SYSTEM_MODE_DSi, "Enhanced DSi Mode (134.06 MHz)"); -#undef _TEXT - } -} - -const systeminfo_t* FeOS_GetSystemInfo() -{ - return &sysInfo; -} - -BEGIN_TABLE(FEOSBASE) - ADD_FUNC_ALIAS(LoadModule, FeOS_LoadModule), - ADD_FUNC(FeOS_FindSymbol), - ADD_FUNC_ALIAS(FreeModule, FeOS_FreeModule), - ADD_FUNC_ALIAS(ModuleLock, FeOS_LockModule), - ADD_FUNC_ALIAS(ModuleUnlock, FeOS_UnlockModule), - ADD_FUNC_ALIAS(ModuleExtraGetSize, FeOS_ModuleGetExtraSize), - ADD_FUNC_ALIAS(ModuleExtraRead, FeOS_ModuleExtraRead), - ADD_FUNC_ALIAS(ModuleExtraSeek, FeOS_ModuleExtraSeek), - ADD_FUNC_ALIAS(ModuleExtraTell, FeOS_ModuleExtraTell), - ADD_FUNC(FeOS_EnumModules), - ADD_FUNC(FeOS_GetModule), - ADD_FUNC(FeOS_GetModuleName), - ADD_FUNC(FeOS_Execute), - ADD_FUNC_ALIAS(FeOS_swi_DataCacheFlush, DC_FlushRange), - ADD_FUNC_ALIAS(FeOS_swi_DataCacheFlushAll, DC_FlushAll), - ADD_FUNC_ALIAS(FeOS_swi_InstrCacheInvalidate, IC_InvalidateRange), - ADD_FUNC_ALIAS(FeOS_swi_InstrCacheInvalidateAll, IC_InvalidateAll), - ADD_FUNC_ALIAS(FeOS_swi_DrainWriteBuffer, FeOS_DrainWriteBuffer), - ADD_FUNC_ALIAS(FeOS_swi_WaitForMemAddr, FeOS_WaitForMemAddr), - ADD_FUNC_ALIAS(FeOS_swi_SetSuspendMode, FeOS_SetSuspendMode), - ADD_FUNC_ALIAS(FeOS_swi_SetExcptHandler, FeOS_SetExcptHandler), - ADD_FUNC_ALIAS(FeOS_ModuleExit, exit), - ADD_FUNC_ALIAS(__errno, FeOS_GetErrnoPtr), - ADD_FUNC(FeOS_GetModuleExidxTbl), - ADD_FUNC(FeOS_ModuleFromAddress), - ADD_FUNC(FeOS_ExecStatusCreate), - ADD_FUNC(FeOS_ExecStatusAddRef), - ADD_FUNC(FeOS_ExecStatusRelease), - ADD_FUNC(FeOS_SetCurExecStatus), - ADD_FUNC(FeOS_GetCurExecStatus), - ADD_FUNC(FeOS_SetAutoUpdate), - ADD_FUNC(FeOS_GetAutoUpdate), - ADD_FUNC(FeOS_GetDiskStats), - ADD_FUNC(FeOS_GetDiskStats64), - ADD_FUNC(FeOS_GetMemStats), - ADD_FUNC(FeOS_GetTickCount), - ADD_FUNC(FeOS_GetVersion), - ADD_FUNC(FeOS_GetSystemInfo), - ADD_FUNC(__aeabi_idiv), - ADD_FUNC(__aeabi_idivmod), - ADD_FUNC(__aeabi_uidiv), - ADD_FUNC(__aeabi_uidivmod), - ADD_FUNC(__aeabi_ldivmod), - ADD_FUNC(__aeabi_uldivmod), - - // setjmp.h - ADD_FUNC(setjmp), - ADD_FUNC(longjmp), - - // stdlib.h - ADD_FUNC(atoi), - ADD_FUNC(strtol), - ADD_FUNC(strtoul), - ADD_FUNC(rand), - ADD_FUNC(srand), - ADD_FUNC(malloc), - ADD_FUNC(memalign), - ADD_FUNC(calloc), - ADD_FUNC(free), - ADD_FUNC(realloc), - ADD_FUNC(bsearch), - ADD_FUNC(qsort), - ADD_FUNC(abs), - ADD_FUNC(div), // to be replaced with native div hardware - ADD_FUNC(system), - - // string.h - ADD_FUNC(strlen), - ADD_FUNC(strcpy), - ADD_FUNC(strcat), - ADD_FUNC(strcmp), -#undef stricmp - ADD_FUNC_ALIAS(strcasecmp, stricmp), -#define stricmp strcasecmp - ADD_FUNC(strncpy), - ADD_FUNC(strncat), - ADD_FUNC(strncmp), -#undef strnicmp - ADD_FUNC_ALIAS(strncasecmp, strnicmp), -#define strnicmp strncasecmp - ADD_FUNC(memcpy), - ADD_FUNC(memmove), - ADD_FUNC(memset), - ADD_FUNC(memcmp), - ADD_FUNC(memchr), - ADD_FUNC(strchr), - ADD_FUNC(strcspn), - ADD_FUNC(strpbrk), - ADD_FUNC(strrchr), - ADD_FUNC(strspn), - ADD_FUNC(strstr), - ADD_FUNC(strtok), - ADD_FUNC(strerror), - - // ctype.h - ADD_FUNC(isalnum), - ADD_FUNC(isalpha), - ADD_FUNC(iscntrl), - ADD_FUNC(isdigit), - ADD_FUNC(isgraph), - ADD_FUNC(islower), - ADD_FUNC(isprint), - ADD_FUNC(ispunct), - ADD_FUNC(isspace), - ADD_FUNC(isupper), - ADD_FUNC(isxdigit), - ADD_FUNC(tolower), - ADD_FUNC(toupper), - - // time.h - ADD_FUNC(mktime), - ADD_FUNC(time), - ADD_FUNC(asctime), - ADD_FUNC(ctime), - ADD_FUNC(gmtime), - ADD_FUNC(localtime), - ADD_FUNC(strftime) -END_TABLE(FEOSBASE) - -MAKE_FAKEMODULE(FEOSBASE) - -static word_t dummy_entrypoint(word_t a, word_t b, word_t c, word_t d) -{ - return FEOS_RC_OK; -} - -static executeStatus_t defaultExecStatus; -executeStatus_t* curExecStatus = &defaultExecStatus; - -#ifdef LIBFAT_FEOS_MULTICWD -void FeOS_InitDefaultExecStatus() -{ - defaultExecStatus.cwdBuffer = _getCwdBuf(); -} - -#define EXECSTAT_ADDENDUM 256 -#else -#define EXECSTAT_ADDENDUM 0 -#endif - -#define GET_ADDENDUM(x) ((char*)(x) + sizeof(executeStatus_t)); - -execstat_t FeOS_ExecStatusCreate() -{ - executeStatus_t* pSt = (executeStatus_t*) malloc(sizeof(executeStatus_t) + EXECSTAT_ADDENDUM); - if (!pSt) return NULL; - - memset(pSt, 0, sizeof(executeStatus_t)); - pSt->refcount = 1; - - // Inherit standard stream hooks - pSt->stdin_hook = curExecStatus->stdin_hook; - pSt->stdout_hook = curExecStatus->stdout_hook; - pSt->stderr_hook = curExecStatus->stderr_hook; - -#ifdef LIBFAT_FEOS_MULTICWD - // Inherit current working directory - pSt->cwdCluster = g_fatCwdCluster; - pSt->cwdBuffer = GET_ADDENDUM(pSt); - memcpy(pSt->cwdBuffer, curExecStatus->cwdBuffer, EXECSTAT_ADDENDUM); -#endif - - return pSt; -} - -void FeOS_ExecStatusAddRef(execstat_t hSt) -{ - if (hSt == (execstat_t) &defaultExecStatus) return; - ((executeStatus_t*)hSt)->refcount ++; -} - -void FeOS_ExecStatusRelease(execstat_t hSt) -{ - if (hSt == (execstat_t) &defaultExecStatus) return; - word_t r = --((executeStatus_t*)hSt)->refcount; - if (r == 0) - free(hSt); -} - -void FeOS_SetCurExecStatus(execstat_t hSt) -{ -#ifdef LIBFAT_FEOS_MULTICWD - curExecStatus->cwdCluster = g_fatCwdCluster; -#endif - curExecStatus = (executeStatus_t*) hSt; -#ifdef LIBFAT_FEOS_MULTICWD - g_fatCwdCluster = curExecStatus->cwdCluster; - _setCwdBuf(curExecStatus->cwdBuffer); -#endif -} - -execstat_t FeOS_GetCurExecStatus() -{ - return (execstat_t) curExecStatus; -} - -#define FeOS_CurInstance curExecStatus->curInstance -#define FeOS_ExitBuf curExecStatus->exitBuf -#define FeOS_ExitDone curExecStatus->exitDone - -int FeOS_Execute(int argc, const char* argv[]) -{ - if (argc == 0) return E_INVALIDARG; - instance_t hInst = LoadModule(argv[0]); - if (!hInst) return E_FILENOTFOUND; - - if (!__system) - __system = (systemfunc_t) FeOS_FindSymbol(hInst, "__system"); - - fxe_runtime_header* rh = GetRuntimeData(hInst); - - int rc = E_INVALIDARG; - if (rh->entrypoint) - { - instance_t instbak = FeOS_CurInstance; - FeOS_CurInstance = hInst; - - jmp_buf exitbuf; - word_t* exitbufbak = FeOS_ExitBuf; - FeOS_ExitBuf = exitbuf; - rc = setjmp(exitbuf); - if (!FeOS_ExitDone) - rc = rh->entrypoint(FEOS_EP_MAIN, (word_t)argc, (word_t)argv, 0); - else - FeOS_ExitDone = false; - - FeOS_ExitBuf = exitbufbak; - FeOS_CurInstance = instbak; - } - - // If the app was forcefully killed we don't want FreeModule() to run the destructors - if ((int)rc == E_APPKILLED) rh->entrypoint = dummy_entrypoint; - - FreeModule(hInst); - return rc; -} - -void FeOS_ModuleExit(int rc) -{ - FeOS_ExitDone = true; - longjmp0(FeOS_ExitBuf, rc); -} - -void* FeOS_GetModuleExidxTbl(instance_t hInst, int* count) -{ - if (hInst == (instance_t)(~0)) - { - // get exidx for kernel itself - typedef struct { word_t offset, size; } exidx_entry_t; - extern exidx_entry_t __exidx_start; - extern exidx_entry_t __exidx_end; - *count = &__exidx_end - &__exidx_start; - return &__exidx_start; - } - - CHK_HINST(hInst); - fxe_runtime_header* rh = GetRuntimeData(hInst); - - if (!rh->exidx.nentries) return NULL; - if (count) *count = rh->exidx.nentries; - - return rh->exidx.table; -} diff --git a/kernel/source/feosfifo.h b/kernel/source/feosfifo.h index 5a49b60..873dbb4 100644 --- a/kernel/source/feosfifo.h +++ b/kernel/source/feosfifo.h @@ -1,6 +1,6 @@ #pragma once #include "feos.h" -#include "fxe.h" +#include "loader.h" #define FIFO_BASE_CH FIFO_USER_01 #define FIFO_FEOS (FIFO_USER_01) @@ -36,7 +36,7 @@ typedef struct FeOSLoadStruct* loadStruct; struct { - instance_t hModule; + module_t hModule; int fifoCh; }; }; diff --git a/kernel/source/feosmath.arm.c b/kernel/source/feosmath.arm.c deleted file mode 100644 index 95e55a5..0000000 --- a/kernel/source/feosmath.arm.c +++ /dev/null @@ -1,128 +0,0 @@ -#include "feos.h" -#include "fxe.h" - -extern bool conMode; - -static inline void divmod3232(int a, int b) -{ - REG_DIVCNT = DIV_32_32; - while(REG_DIVCNT & DIV_BUSY); - - REG_DIV_NUMER_L = a; - REG_DIV_DENOM_L = b; - while(REG_DIVCNT & DIV_BUSY); -} - -static inline void divmod6432(long long a, int b) -{ - REG_DIVCNT = DIV_64_32; - while(REG_DIVCNT & DIV_BUSY); - - REG_DIV_NUMER = a; - REG_DIV_DENOM_L = b; - while(REG_DIVCNT & DIV_BUSY); -} - -static inline void divmod6464(long long a, long long b) -{ - REG_DIVCNT = DIV_64_64; - while(REG_DIVCNT & DIV_BUSY); - - REG_DIV_NUMER = a; - REG_DIV_DENOM = b; - while(REG_DIVCNT & DIV_BUSY); -} - -int FeOS_swi_div3232(int, int); -int FeOS_div3232(int a, int b) -{ - if (conMode && isUserMode()) return FeOS_swi_div3232(a, b); - divmod3232(a, b); - return REG_DIV_RESULT_L; -} - -int FeOS_swi_mod3232(int, int); -int FeOS_mod3232(int a, int b) -{ - if (conMode && isUserMode()) return FeOS_swi_mod3232(a, b); - divmod3232(a, b); - return REG_DIVREM_RESULT_L; -} - -int FeOS_swi_div6432(long long, int); -int FeOS_div6432(long long a, int b) -{ - if (conMode && isUserMode()) return FeOS_swi_div6432(a, b); - divmod6432(a, b); - return REG_DIV_RESULT_L; -} - -int FeOS_swi_mod6432(long long, int); -int FeOS_mod6432(long long a, int b) -{ - if (conMode && isUserMode()) return FeOS_swi_mod6432(a, b); - divmod6432(a, b); - return REG_DIVREM_RESULT_L; -} - -long long FeOS_swi_div6464(long long, long long); -long long FeOS_div6464(long long a, long long b) -{ - if (conMode && isUserMode()) return FeOS_swi_div6464(a, b); - divmod6464(a, b); - return REG_DIV_RESULT; -} - -long long FeOS_swi_mod6464(long long, long long); -long long FeOS_mod6464(long long a, long long b) -{ - if (conMode && isUserMode()) return FeOS_swi_mod6464(a, b); - divmod6464(a, b); - return REG_DIVREM_RESULT; -} - -unsigned int FeOS_swi_sqrt32(unsigned int); -unsigned int FeOS_sqrt32(unsigned int a) -{ - if (conMode && isUserMode()) return FeOS_swi_sqrt32(a); - - REG_SQRTCNT = SQRT_32; - while(REG_SQRTCNT & SQRT_BUSY); - - REG_SQRT_PARAM_L = a; - while(REG_SQRTCNT & SQRT_BUSY); - - return REG_SQRT_RESULT; -} - -unsigned int FeOS_swi_sqrt64(long long); -unsigned int FeOS_sqrt64(long long a) -{ - if (conMode && isUserMode()) return FeOS_swi_sqrt64(a); - - REG_SQRTCNT = SQRT_64; - while(REG_SQRTCNT & SQRT_BUSY); - - REG_SQRT_PARAM = a; - while(REG_SQRTCNT & SQRT_BUSY); - - return REG_SQRT_RESULT; -} - -BEGIN_TABLE(FEOSMATH) - ADD_FUNC(sinLerp), - ADD_FUNC(cosLerp), - ADD_FUNC(tanLerp), - ADD_FUNC(asinLerp), - ADD_FUNC(acosLerp), - ADD_FUNC(FeOS_div3232), - ADD_FUNC(FeOS_mod3232), - ADD_FUNC(FeOS_div6432), - ADD_FUNC(FeOS_mod6432), - ADD_FUNC(FeOS_div6464), - ADD_FUNC(FeOS_mod6464), - ADD_FUNC(FeOS_sqrt32), - ADD_FUNC(FeOS_sqrt64) -END_TABLE(FEOSMATH) - -MAKE_FAKEMODULE(FEOSMATH) diff --git a/kernel/source/feosstdio.c b/kernel/source/feosstdio.c deleted file mode 100644 index 3b8045b..0000000 --- a/kernel/source/feosstdio.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "feos.h" -#include "fxe.h" -#include -#include -#include -#include -#include - -#define stdin_hook curExecStatus->stdin_hook -#define stdout_hook curExecStatus->stdout_hook -#define stderr_hook curExecStatus->stderr_hook - -FILE* FeOS_GetStdin() -{ - return !stdin_hook ? stdin : (FILE*)stdin_hook; -} - -FILE* FeOS_GetStdout() -{ - return !stdout_hook ? stdout : (FILE*)stdout_hook; -} - -FILE* FeOS_GetStderr() -{ - return !stderr_hook ? stderr : (FILE*)stderr_hook; -} - -FILE* FeOS_SetStdin(FILE* newstdin) -{ - FILE* oldstdin = (FILE*)stdin_hook; - stdin_hook = newstdin; - return oldstdin; -} - -FILE* FeOS_SetStdout(FILE* newstdout) -{ - FILE* oldstdout = (FILE*)stdout_hook; - stdout_hook = newstdout; - return oldstdout; -} - -FILE* FeOS_SetStderr(FILE* newstderr) -{ - FILE* oldstderr = (FILE*)stderr_hook; - stderr_hook = newstderr; - return oldstderr; -} - -FILE* FeOS_OpenStream(const void*); - -BEGIN_TABLE(FEOSSTDIO) - ADD_FUNC(FeOS_GetStdin), - ADD_FUNC(FeOS_GetStdout), - ADD_FUNC(FeOS_GetStderr), - ADD_FUNC(FeOS_SetStdin), - ADD_FUNC(FeOS_SetStdout), - ADD_FUNC(FeOS_SetStderr), - ADD_FUNC(FeOS_OpenStream), - - // Basic I/O - ADD_FUNC(fopen), - ADD_FUNC(freopen), - ADD_FUNC(fclose), - ADD_FUNC(fwrite), - ADD_FUNC(fread), - ADD_FUNC(feof), - ADD_FUNC(fseek), - ADD_FUNC(ftell), - ADD_FUNC(fflush), - ADD_FUNC(ferror), - ADD_FUNC(clearerr), - ADD_FUNC(setvbuf), - - // Formatting - ADD_FUNC_ALIAS(vfiprintf, vfprintf), - ADD_FUNC_ALIAS(vsiprintf, vsprintf), - ADD_FUNC_ALIAS(vsniprintf, vsnprintf), - ADD_FUNC_ALIAS(vfiscanf, vfscanf), - ADD_FUNC_ALIAS(vsiscanf, vsscanf), - - // Strings and chars - ADD_FUNC(fgetc), ADD_FUNC(fputc), - ADD_FUNC(fgets), ADD_FUNC(fputs), - ADD_FUNC(ungetc), - - // Misc - ADD_FUNC(remove), - ADD_FUNC(rename), - ADD_FUNC_ALIAS(__getdelim, getdelim) -END_TABLE(FEOSSTDIO) - -MAKE_FAKEMODULE(FEOSSTDIO) diff --git a/kernel/source/installthunk.c b/kernel/source/installthunk.c index 79ae885..6989040 100644 --- a/kernel/source/installthunk.c +++ b/kernel/source/installthunk.c @@ -37,7 +37,7 @@ DECLAREHOOK(int, fatstatvfs, (struct _reent*, const char*, struct statvfs*)); DECLAREHOOK(int, fatftruncate, (struct _reent*, int, off_t)); DECLAREHOOK(int, fatfsync, (struct _reent*, int)); -ssize_t FeOS_KeybdRead(struct _reent*, int, char*, size_t); +ssize_t DSKeybdRead(struct _reent*, int, char*, size_t); static ssize_t DummyRead(struct _reent* r, int fd, char* buf, size_t count) { @@ -55,7 +55,7 @@ void InstallConThunks() { devoptab_t** dotabs = (devoptab_t**) devoptab_list; // force non-constness dotabs[STD_OUT]->write_r = _conwritehook; - dotabs[STD_IN]->read_r = FeOS_KeybdRead; + dotabs[STD_IN]->read_r = DSKeybdRead; dotabs[STD_ERR]->write_r = _conerrhook; } @@ -71,7 +71,7 @@ void InstallThunks() { devoptab_t** dotabs = (devoptab_t**) devoptab_list; // force non-constness HOOK(dotabs[STD_OUT]->write_r, conwrite); - dotabs[STD_IN]->read_r = FeOS_KeybdRead; + dotabs[STD_IN]->read_r = DSKeybdRead; HOOK(dotabs[STD_ERR]->write_r, conerr); devoptab_t* dotab = (devoptab_t*) GetDeviceOpTab("/"); // force non-constness diff --git a/kernel/source/feosirq.arm.c b/kernel/source/interrupt.arm.c similarity index 68% rename from kernel/source/feosirq.arm.c rename to kernel/source/interrupt.arm.c index 3ac0e52..da0c19a 100644 --- a/kernel/source/feosirq.arm.c +++ b/kernel/source/interrupt.arm.c @@ -3,9 +3,9 @@ #include #ifndef ARM7 -void FeOS_IRQPoll(); +void DSIRQPoll(); #else -static void FeOS_IRQPoll() { swiSetHaltCR(0x80); } +static void DSIRQPoll() { swiSetHaltCR(0x80); } #endif #ifdef ARM7 @@ -58,7 +58,7 @@ static FifoAddressHandlerFunc addresshnd_array[FIFO_PROG_CH_NUM]; enum { - /*QUEUE_DATAMSG, */ QUEUE_VALUE32, QUEUE_ADDRESS + QUEUE_VALUE32, QUEUE_ADDRESS }; typedef struct tagFifoMsgQueueEntry @@ -67,7 +67,6 @@ typedef struct tagFifoMsgQueueEntry u16 type, channel; union { - //int datamsgSize; word_t value32; void* address; }; @@ -84,7 +83,7 @@ typedef struct tagFifoMsgQueueEntry static byte_t fifoMsgStack[FIFOMSGSTACK_SIZE]; static int fifoMsgStackPos = FIFOMSGSTACK_SIZE; -static FifoMsgQueueEntry* FeOS_AllocFifoMsg() +static FifoMsgQueueEntry* DSAllocFifoMsg() { FifoMsgQueueEntry* ret = NULL; int cs = enterCriticalSection(); @@ -129,7 +128,7 @@ extern FifoMsgQueueEntry* __fifoMsgQueueTail; void __clearFifoMsgQueue(); -static void FeOS_AddFifoMsgToQueue(FifoMsgQueueEntry* msg) +static void DSAddFifoMsgToQueue(FifoMsgQueueEntry* msg) { int cs = enterCriticalSection(); @@ -145,9 +144,7 @@ static void FeOS_AddFifoMsgToQueue(FifoMsgQueueEntry* msg) leaveCriticalSection(cs); } -//int FeOS_swi_FifoGetDatamsg(int, word_t, void*); - -void FeOS_RunFifoQueue() +void DSRunFifoQueue() { FifoMsgQueueEntry* ent; @@ -157,14 +154,6 @@ void FeOS_RunFifoQueue() void* userdata = userdata_array[chn]; switch(ent->type) { - /* - case QUEUE_DATAMSG: - if (datamsghnd_array[chn]) - datamsghnd_array[chn](ent->datamsgSize, userdata); - else - FeOS_swi_FifoGetDatamsg(ent->channel, 0, NULL); // delete the data msg - break; - */ case QUEUE_VALUE32: if (value32hnd_array[chn]) value32hnd_array[chn](ent->value32, userdata); @@ -180,34 +169,19 @@ void FeOS_RunFifoQueue() fifoMsgStackPos = FIFOMSGSTACK_SIZE; } -#ifdef ARM7 -#define FeOS_swi_FifoCheckDatamsgLength fifoCheckDatamsgLength -#endif - -void FeOS_HandleDatamsgs() +void DSHandleDatamsgs() { int i, length; for (i = 0; i < FIFO_PROG_CH_NUM; i ++) if (datamsghnd_array[i]) - while ((length = FeOS_swi_FifoCheckDatamsgLength(FIFO_PROG_CH + i)) != -1) + while ((length = fifoCheckDatamsgLength(FIFO_PROG_CH + i)) != -1) datamsghnd_array[i](length, userdata_array[i]); } -/* -static void StubFifoDatamsgHandler(int datamsgSize, void* userdata) -{ - FifoMsgQueueEntry* msg = FeOS_AllocFifoMsg(); - FeOS_AddFifoMsgToQueue(msg); - msg->type = QUEUE_DATAMSG; - msg->channel = (u16) (word_t) userdata; - msg->datamsgSize = datamsgSize; -} -*/ - static void StubFifoValue32Handler(word_t value32, void* userdata) { - FifoMsgQueueEntry* msg = FeOS_AllocFifoMsg(); - FeOS_AddFifoMsgToQueue(msg); + FifoMsgQueueEntry* msg = DSAllocFifoMsg(); + DSAddFifoMsgToQueue(msg); msg->type = QUEUE_VALUE32; msg->channel = (u16) (word_t) userdata; msg->value32 = value32; @@ -215,24 +189,14 @@ static void StubFifoValue32Handler(word_t value32, void* userdata) static void StubFifoAddressHandler(void* address, void* userdata) { - FifoMsgQueueEntry* msg = FeOS_AllocFifoMsg(); - FeOS_AddFifoMsgToQueue(msg); + FifoMsgQueueEntry* msg = DSAllocFifoMsg(); + DSAddFifoMsgToQueue(msg); msg->type = QUEUE_ADDRESS; msg->channel = (u16) (word_t) userdata; msg->address = address; } -/* -void _SetDatamsgHandler(int channel, bool set) -{ - if (set) - fifoSetDatamsgHandler(channel, StubFifoDatamsgHandler, (void*) channel); - else - fifoSetDatamsgHandler(channel, NULL, NULL); -} -*/ - -void _SetValue32Handler(int channel, bool set) +void DSSetValue32Handler(int channel, bool set) { if (set) fifoSetValue32Handler(channel, StubFifoValue32Handler, (void*) channel); @@ -240,7 +204,7 @@ void _SetValue32Handler(int channel, bool set) fifoSetValue32Handler(channel, NULL, NULL); } -void _SetAddressHandler(int channel, bool set) +void DSSetAddressHandler(int channel, bool set) { if (set) fifoSetAddressHandler(channel, StubFifoAddressHandler, (void*) channel); @@ -249,51 +213,45 @@ void _SetAddressHandler(int channel, bool set) } #ifdef ARM7 -#define FeOS_FifoSetDatamsgHandler coopFifoSetDatamsgHandler -#define FeOS_FifoSetValue32Handler coopFifoSetValue32Handler -#define FeOS_FifoSetAddressHandler coopFifoSetAddressHandler -#define FeOS_SetInterrupt coopIrqSet -#define FeOS_CheckPendingIRQs coopIrqCheck -#define _FeOS_WaitForIRQ coopIrqWait -#define FeOS_NextIRQ coopIrqNext +#define DSFifoSetDatamsgHandler coopFifoSetDatamsgHandler +#define DSFifoSetValue32Handler coopFifoSetValue32Handler +#define DSFifoSetAddressHandler coopFifoSetAddressHandler +#define DSIrqSet coopIrqSet +#define DSProcessIRQs coopIrqCheck +#define DSWaitForIRQRaw coopIrqWait +#define DSWaitForNextIRQRaw coopIrqNext #endif -void FeOS_FifoSetDatamsgHandler(int channel, FifoDatamsgHandlerFunc handler, void* userdata) +void DSFifoSetDatamsgHandler(int channel, FifoDatamsgHandlerFunc handler, void* userdata) { int ch = channel - FIFO_PROG_CH; userdata_array[ch] = userdata; datamsghnd_array[ch] = handler; - //FeOS_swi_SetDatamsgHandler(channel, !!handler); if (handler) { int l = 0; - while ((l = FeOS_swi_FifoCheckDatamsgLength(channel)) != -1) + while ((l = fifoCheckDatamsgLength(channel)) != -1) handler(l, userdata); } - FeOS_RunFifoQueue(); + DSRunFifoQueue(); } -#ifdef ARM7 -#define FeOS_swi_SetValue32Handler _SetValue32Handler -#define FeOS_swi_SetAddressHandler _SetAddressHandler -#endif - -void FeOS_FifoSetValue32Handler(int channel, FifoValue32HandlerFunc handler, void* userdata) +void DSFifoSetValue32Handler(int channel, FifoValue32HandlerFunc handler, void* userdata) { int ch = channel - FIFO_PROG_CH; userdata_array[ch] = userdata; value32hnd_array[ch] = handler; - FeOS_swi_SetValue32Handler(channel, !!handler); - FeOS_RunFifoQueue(); + DSSetValue32Handler(channel, !!handler); + DSRunFifoQueue(); } -void FeOS_FifoSetAddressHandler(int channel, FifoAddressHandlerFunc handler, void* userdata) +void DSFifoSetAddressHandler(int channel, FifoAddressHandlerFunc handler, void* userdata) { int ch = channel - FIFO_PROG_CH; userdata_array[ch] = userdata; addresshnd_array[ch] = handler; - FeOS_swi_SetAddressHandler(channel, !!handler); - FeOS_RunFifoQueue(); + DSSetAddressHandler(channel, !!handler); + DSRunFifoQueue(); } //----------------------------------------------------------------------------- @@ -306,7 +264,7 @@ void FeOS_FifoSetAddressHandler(int channel, FifoAddressHandlerFunc handler, voi static struct IntTable irqTable[MAX_IRQS]; -VoidFn FeOS_SetInterrupt(word_t mask, VoidFn fn) +VoidFn DSIrqSet(word_t mask, VoidFn fn) { if (!mask) return NULL; @@ -328,13 +286,13 @@ VoidFn FeOS_SetInterrupt(word_t mask, VoidFn fn) return oldFn; } -static void FeOS_ProcessIRQ(word_t flags) +static void DSProcessIRQ(word_t flags) { // Check for FIFO recv IRQ before everything else if (flags & IRQ_FIFO_NOT_EMPTY) { - FeOS_RunFifoQueue(); - FeOS_HandleDatamsgs(); + DSRunFifoQueue(); + DSHandleDatamsgs(); // We don't want user code responding to this IRQ flags &= ~IRQ_FIFO_NOT_EMPTY; @@ -345,8 +303,8 @@ static void FeOS_ProcessIRQ(word_t flags) { extern volatile bool inHeadphoneSleep; extern bool bKeyUpd, bBgUpd, bOAMUpd, conMode; - void _FeOS_oamUpdate(OamState* oam); - void _FeOS_bgUpdate(); + void oamUpdate2(OamState* oam); + void DSBgUpdate(); if (!conMode) do { @@ -358,15 +316,15 @@ static void FeOS_ProcessIRQ(word_t flags) if (bBgUpd) { bBgUpd = false; - _FeOS_bgUpdate(); + DSBgUpdate(); bBgUpd = true; } if (bOAMUpd) { bOAMUpd = false; - _FeOS_oamUpdate(&oamMain); - _FeOS_oamUpdate(&oamSub); + oamUpdate2(&oamMain); + oamUpdate2(&oamSub); bOAMUpd = true; } } while(0); @@ -382,14 +340,14 @@ static void FeOS_ProcessIRQ(word_t flags) } } -word_t FeOS_CheckPendingIRQs() +word_t DSProcessIRQs() { word_t totalflags = 0; for(;;) // IRQ/FIFO might fire while the handlers are executing { word_t flags = __ARMSWP(0, &INTR_WAIT_FLAGS); if (flags) - FeOS_ProcessIRQ(flags); + DSProcessIRQ(flags); else break; totalflags |= flags; @@ -397,13 +355,13 @@ word_t FeOS_CheckPendingIRQs() return totalflags; }; -void _FeOS_WaitForIRQ(word_t mask) +void DSWaitForIRQRaw(word_t mask) { - FeOS_CheckPendingIRQs(); + DSProcessIRQs(); for(;;) { - FeOS_IRQPoll(); - if (FeOS_CheckPendingIRQs() & mask) + DSIRQPoll(); + if (DSProcessIRQs() & mask) break; } } @@ -420,12 +378,12 @@ void coop_swiIntrWaitCompat(word_t how, word_t what) #ifdef ARM9 static irqWaitFunc_t irqWaitFunc = NULL; -void FeOS_WaitForIRQ(word_t mask) +void DSWaitForIRQ(word_t mask) { - (irqWaitFunc ? irqWaitFunc : &_FeOS_WaitForIRQ)(mask); + irqWaitFunc ? irqWaitFunc(mask) : DSWaitForIRQRaw(mask); } -irqWaitFunc_t FeOS_SetIRQWaitFunc(irqWaitFunc_t newFunc) +irqWaitFunc_t DSSetIRQWaitFunc(irqWaitFunc_t newFunc) { irqWaitFunc_t oldFunc = irqWaitFunc; if (newFunc != GET_IRQFUNC) @@ -434,14 +392,14 @@ irqWaitFunc_t FeOS_SetIRQWaitFunc(irqWaitFunc_t newFunc) } #endif -word_t FeOS_NextIRQ() +word_t DSWaitForNextIRQRaw() { word_t flags = 0; for(;;) { - flags = FeOS_CheckPendingIRQs(); + flags = DSProcessIRQs(); if (flags == 0) - FeOS_IRQPoll(); // wait for *any* IRQs to happen + DSIRQPoll(); // wait for *any* IRQs to happen else break; } @@ -449,12 +407,9 @@ word_t FeOS_NextIRQ() } #ifdef ARM9 -word_t FeOS_FifoGetRetValue32(int ch) +word_t DSFifoGetRetValue32(int ch) { static volatile byte_t counters[FIFO_PROG_CH_NUM]; - bool FeOS_swi_FifoCheckValue32(int); - word_t FeOS_swi_FifoGetValue32(int); - volatile byte_t* pCounter = counters + ch - FIFO_PROG_CH; #define WAIT_COUNTER (*pCounter) @@ -469,16 +424,16 @@ word_t FeOS_FifoGetRetValue32(int ch) // Decrement queue position queuePos -= prevCnt - curCnt; prevCnt = curCnt; - FeOS_WaitForIRQ(~0); + DSWaitForIRQ(~0); } // Wait for the return value - while (!FeOS_swi_FifoCheckValue32(ch)) - FeOS_WaitForIRQ(~0); + while (!fifoCheckValue32(ch)) + DSWaitForIRQ(~0); // Return WAIT_COUNTER --; - return FeOS_swi_FifoGetValue32(ch); + return fifoGetValue32(ch); #undef WAIT_COUNTER } diff --git a/kernel/source/kernel.c b/kernel/source/kernel.c new file mode 100644 index 0000000..ff184c4 --- /dev/null +++ b/kernel/source/kernel.c @@ -0,0 +1,703 @@ +#include "feos.h" +#include "loader.h" +#include "feosfifo.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static inline int _fileno_helper(FILE* f) { return fileno(f); } + +void* LdrFindSymbol(module_t hMod, const char* sym) +{ + CHK_HMOD(hMod); + return LdrFindInTbl(&GetRuntimeData(hMod)->exp, sym); +} + +int __aeabi_idiv(int, int); +int __aeabi_idivmod(int, int); +unsigned int __aeabi_uidiv(unsigned int, unsigned int); +unsigned int __aeabi_uidivmod(unsigned int, unsigned int); + +long long __aeabi_ldivmod(long long, long long); +unsigned long long __aeabi_uldivmod(unsigned long long, unsigned long long); + +void DC_DrainWriteBuffer(); +void KeWaitForMemAddr(volatile byte_t*, byte_t); + +void KeSetExcptHandler(void*); + +// Execution status functions + +typedef void* execstat_t; + +execstat_t KeExecStatusCreate(); +void KeExecStatusAddRef(execstat_t hSt); +void KeExecStatusRelease(execstat_t hSt); +void KeSetCurExecStatus(execstat_t hSt); +execstat_t KeGetCurExecStatus(); + +typedef int (* systemfunc_t)(const char* command); + +systemfunc_t __system; + +int system(const char* command) +{ + if (command == NULL) return !!__system; + return __system(command); +} + +const char* LdrGetModuleName(module_t hMod) +{ + CHK_HMOD(hMod); + return GetRuntimeData(hMod)->name; +} + +module_t LdrGetModule(const char* name) +{ + sassert(name, ERRSTR_INVALIDPARAM); + fxe_runtime_header* rh = LdrModuleListFind(name); + return rh ? rh->hThis : NULL; +} + +// Memory/disk usage functions + +typedef struct +{ + word_t total, free, used; +} usagestats_t; + +typedef struct +{ + u64 total, free, used; +} usagestats64_t; + +bool KeGetDiskStats(usagestats64_t* pStats) +{ + struct statvfs fiData; + if (pStats && statvfs("/", &fiData) >= 0) + { + pStats->total = (u64)fiData.f_frsize * fiData.f_blocks; + pStats->free = (u64)fiData.f_bsize * fiData.f_bfree; + pStats->used = pStats->total - pStats->free; + return true; + } + return false; +} + +void KeGetMemStats(usagestats_t* pStats) +{ + if (!pStats) return; + + u8 *heapLimit = getHeapLimit(), *heapStart = getHeapStart(), *heapEnd = getHeapEnd(); + struct mallinfo mi = mallinfo(); + pStats->used = mi.uordblks; + pStats->free = mi.fordblks + (heapLimit - heapEnd); + pStats->total = heapLimit - heapStart; +} + +int KeGetTickCount() +{ + extern volatile int vblankCounter; + return vblankCounter; +} + +int KeGetOSVersion() +{ + return FEOS_VERSION_PACK; +} + +static systeminfo_t sysInfo = +{ + FEOS_VERSION_PACK, + FEOS_VERSION_TEXT, +#ifndef DEBUG + 0, +#else + SYSTEM_FLAGS_DEBUG, +#endif + SYSTEM_TYPE_DS, + NULL, + SYSTEM_MODE_DS, + NULL, +}; + +void KeInitSystemInfo() +{ + extern bool __dsimode; + +#define SYSTYPE sysInfo.systemType +#define SYSFLAGS sysInfo.systemFlags + + // DSi mode detection + if (__dsimode) + { + sysInfo.systemMode = SYSTEM_MODE_DSi; + sysInfo.systemType = SYSTEM_TYPE_DSi; + } + + byte_t fw1D, fw2F, pm4; + // Retrieve some bits from ARM7 + { + FeOSFifoMsg msg; + msg.type = FEOS_ARM7_GET_SYSTEM_INFO; + + fifoSendDatamsg(FIFO_FEOS, sizeof(msg), (void*) &msg); + while (!fifoCheckValue32(FIFO_FEOS)); + + word_t ret = fifoGetValue32(FIFO_FEOS); + fw1D = ret; + fw2F = ret >> 8; + pm4 = ret >> 16; + } + + // Detect system type + // Based on http://adshomebrewersdiary.blogspot.com.es/2012/01/telling-ds-models-apart.html + + if (SYSTYPE == SYSTEM_TYPE_DS) do + { + if (swiIsDebugger()) + { + SYSTYPE = SYSTEM_TYPE_DSDebug; + break; + } + + if (pm4 & 0x80) + { + SYSTYPE = SYSTEM_TYPE_DSLite; + break; + } + + if (fw1D != 0xFF && fw1D & 3) + SYSFLAGS |= SYSTEM_FLAGS_CHINESE; + } while(0); + + if (SYSTYPE == SYSTEM_TYPE_DSLite) do + { + if (fw1D & 4) + { + SYSTYPE = SYSTEM_TYPE_DSi; + break; + } + + if (fw1D & 3) + SYSFLAGS |= SYSTEM_FLAGS_CHINESE; + } while(0); + + if (SYSTYPE == SYSTEM_TYPE_DSi) do + { + if (fw2F >= 0x18) + { + SYSTYPE = SYSTEM_TYPE_DSi_XL; + break; + } + + // TODO: chinese DSi detection + } while(0); + + if (SYSTYPE == SYSTEM_TYPE_DSi_XL) do + { + if (fw2F >= 0x1C) + { + SYSTYPE = SYSTEM_TYPE_3DS; + break; + } + + // TODO: chinese DSi XL detection + } while(0); + + // TODO: 3DS XL detection + // TODO: chinese 3DS XL detection (does that even exist??) + + // Emulator detection + bool __isEmulator(); + if (__isEmulator()) + SYSFLAGS |= SYSTEM_FLAGS_EMULATOR; + +#undef SYSTYPE +#undef SYSFLAGS + + switch (sysInfo.systemType) + { +#define _TEXT(_x,_y) case _x: sysInfo.systemTypeText = _y; break + _TEXT(SYSTEM_TYPE_DS, "Nintendo DS (Original)"); + _TEXT(SYSTEM_TYPE_DSDebug, "Nintendo DS (Debug)"); + _TEXT(SYSTEM_TYPE_DSLite, "Nintendo DS Lite"); + _TEXT(SYSTEM_TYPE_DSi, "Nintendo DSi"); + _TEXT(SYSTEM_TYPE_DSi_XL, "Nintendo DSi XL"); + _TEXT(SYSTEM_TYPE_3DS, "Nintendo 3DS"); + _TEXT(SYSTEM_TYPE_3DS_XL, "Nintendo 3DS XL"); +#undef _TEXT + } + + switch (sysInfo.systemMode) + { +#define _TEXT(_x,_y) case _x: sysInfo.systemModeText = _y; break + _TEXT(SYSTEM_MODE_DS, "Standard DS Mode (67.03 MHz)"); + _TEXT(SYSTEM_MODE_DSi, "Enhanced DSi Mode (134.06 MHz)"); +#undef _TEXT + } +} + +const systeminfo_t* KeGetSysInfo() +{ + return &sysInfo; +} + +static inline void divmod3232(int a, int b) +{ + REG_DIVCNT = DIV_32_32; + while(REG_DIVCNT & DIV_BUSY); + + REG_DIV_NUMER_L = a; + REG_DIV_DENOM_L = b; + while(REG_DIVCNT & DIV_BUSY); +} + +static inline void divmod6432(long long a, int b) +{ + REG_DIVCNT = DIV_64_32; + while(REG_DIVCNT & DIV_BUSY); + + REG_DIV_NUMER = a; + REG_DIV_DENOM_L = b; + while(REG_DIVCNT & DIV_BUSY); +} + +static inline void divmod6464(long long a, long long b) +{ + REG_DIVCNT = DIV_64_64; + while(REG_DIVCNT & DIV_BUSY); + + REG_DIV_NUMER = a; + REG_DIV_DENOM = b; + while(REG_DIVCNT & DIV_BUSY); +} + +int KeDiv3232(int a, int b) +{ + divmod3232(a, b); + return REG_DIV_RESULT_L; +} + +int KeMod3232(int a, int b) +{ + divmod3232(a, b); + return REG_DIVREM_RESULT_L; +} + +int KeDiv6432(long long a, int b) +{ + divmod6432(a, b); + return REG_DIV_RESULT_L; +} + +int KeMod6432(long long a, int b) +{ + divmod6432(a, b); + return REG_DIVREM_RESULT_L; +} + +long long KeDiv6464(long long a, long long b) +{ + divmod6464(a, b); + return REG_DIV_RESULT; +} + +long long KeMod6464(long long a, long long b) +{ + divmod6464(a, b); + return REG_DIVREM_RESULT; +} + +unsigned int KeSqrt32(unsigned int a) +{ + REG_SQRTCNT = SQRT_32; + while(REG_SQRTCNT & SQRT_BUSY); + + REG_SQRT_PARAM_L = a; + while(REG_SQRTCNT & SQRT_BUSY); + + return REG_SQRT_RESULT; +} + +unsigned int KeSqrt64(long long a) +{ + REG_SQRTCNT = SQRT_64; + while(REG_SQRTCNT & SQRT_BUSY); + + REG_SQRT_PARAM = a; + while(REG_SQRTCNT & SQRT_BUSY); + + return REG_SQRT_RESULT; +} + +#define IoStdinHook curExecStatus->stdin_hook +#define IoStdoutHook curExecStatus->stdout_hook +#define IoStderrHook curExecStatus->stderr_hook + +FILE* IoGetStdin() +{ + return !IoStdinHook ? stdin : (FILE*)IoStdinHook; +} + +FILE* IoGetStdout() +{ + return !IoStdoutHook ? stdout : (FILE*)IoStdoutHook; +} + +FILE* IoGetStderr() +{ + return !IoStderrHook ? stderr : (FILE*)IoStderrHook; +} + +FILE* IoSetStdin(FILE* newstdin) +{ + FILE* oldstdin = (FILE*)IoStdinHook; + IoStdinHook = newstdin; + return oldstdin; +} + +FILE* IoSetStdout(FILE* newstdout) +{ + FILE* oldstdout = (FILE*)IoStdoutHook; + IoStdoutHook = newstdout; + return oldstdout; +} + +FILE* IoSetStderr(FILE* newstderr) +{ + FILE* oldstderr = (FILE*)IoStderrHook; + IoStderrHook = newstderr; + return oldstderr; +} + +FILE* IoOpenStream(const void*); + +#undef stricmp +#undef strnicmp + +BEGIN_TABLE(FEOSKRNL) + ADD_FUNC_(DC_DrainWriteBuffer), + ADD_ALIAS(DC_FlushAll, KeDataCacheFlushAll), + ADD_ALIAS(DC_FlushRange, KeDataCacheFlush), + ADD_FUNC_(DSGetAutoUpdate), + ADD_FUNC_(DSSetAutoUpdate), + ADD_ALIAS(IC_InvalidateAll, KeInstrCacheInvalidateAll), + ADD_ALIAS(IC_InvalidateRange, KeInstrCacheInvalidate), + ADD_FUNC_(IoGetStderr), + ADD_FUNC_(IoGetStdin), + ADD_FUNC_(IoGetStdout), + ADD_FUNC_(IoOpenStream), + ADD_FUNC_(IoSetStderr), + ADD_FUNC_(IoSetStdin), + ADD_FUNC_(IoSetStdout), + ADD_FUNC_(KeDiv3232), + ADD_FUNC_(KeDiv6432), + ADD_FUNC_(KeDiv6464), + ADD_FUNC_(KeExecStatusAddRef), + ADD_FUNC_(KeExecStatusCreate), + ADD_FUNC_(KeExecStatusRelease), + ADD_FUNC_(KeGetCurExecStatus), + ADD_FUNC_(KeGetDiskStats), + ADD_ALIAS(KeGetErrnoPtr, __errno), + ADD_FUNC_(KeGetMemStats), + ADD_FUNC_(KeGetOSVersion), + ADD_FUNC_(KeGetSysInfo), + ADD_FUNC_(KeGetTickCount), + ADD_FUNC_(KeMod3232), + ADD_FUNC_(KeMod6432), + ADD_FUNC_(KeMod6464), + ADD_FUNC_(KeSetCurExecStatus), + ADD_FUNC_(KeSetExcptHandler), + ADD_FUNC_(KeSqrt32), + ADD_FUNC_(KeSqrt64), + ADD_FUNC_(KeWaitForMemAddr), + ADD_FUNC_(LdrEnumModules), + ADD_FUNC_(LdrExecuteArgv), + ADD_FUNC_(LdrFindSymbol), + ADD_FUNC_(LdrFreeModule), + ADD_FUNC_(LdrGetExidxTbl), + ADD_FUNC_(LdrGetModule), + ADD_FUNC_(LdrGetModuleName), + ADD_FUNC_(LdrLoadModule), + ADD_FUNC_(LdrLockModule), + ADD_FUNC_(LdrResGetSize), + ADD_FUNC_(LdrResolveAddr), + ADD_FUNC_(LdrResRead), + ADD_FUNC_(LdrResSeek), + ADD_FUNC_(LdrResTell), + ADD_FUNC_(LdrUnlockModule), + ADD_FUNC_(__aeabi_idiv), + ADD_FUNC_(__aeabi_idivmod), + ADD_FUNC_(__aeabi_ldivmod), + ADD_FUNC_(__aeabi_uidiv), + ADD_FUNC_(__aeabi_uidivmod), + ADD_FUNC_(__aeabi_uldivmod), + ADD_FUNC_(abs), + ADD_FUNC_(acosLerp), + ADD_FUNC_(asctime), + ADD_FUNC_(asinLerp), + ADD_FUNC_(atoi), + ADD_FUNC_(bsearch), + ADD_FUNC_(calloc), + ADD_FUNC_(chdir), + ADD_FUNC_(clearerr), + ADD_FUNC_(close), + ADD_FUNC_(closedir), + ADD_FUNC_(cosLerp), + ADD_FUNC_(ctime), + ADD_FUNC_(div), + ADD_ALIAS(exit, LdrModuleExit), + ADD_FUNC_(fclose), + ADD_FUNC_(fdopen), + ADD_FUNC_(feof), + ADD_FUNC_(ferror), + ADD_FUNC_(fflush), + ADD_FUNC_(fgetc), + ADD_FUNC_(fgets), + ADD_ALIAS(fileno, _fileno_helper), + ADD_FUNC_(fopen), + ADD_FUNC_(fputc), + ADD_FUNC_(fputs), + ADD_FUNC_(fread), + ADD_FUNC_(free), + ADD_FUNC_(freopen), + ADD_FUNC_(fseek), + ADD_FUNC_(fstat), + ADD_FUNC_(ftell), + ADD_FUNC_(ftruncate), + ADD_FUNC_(fwrite), + ADD_FUNC_(getcwd), + ADD_ALIAS(getdelim, __getdelim), + ADD_FUNC_(gmtime), + ADD_FUNC_(isalnum), + ADD_FUNC_(isalpha), + ADD_FUNC_(iscntrl), + ADD_FUNC_(isdigit), + ADD_FUNC_(isgraph), + ADD_FUNC_(islower), + ADD_FUNC_(isprint), + ADD_FUNC_(ispunct), + ADD_FUNC_(isspace), + ADD_FUNC_(isupper), + ADD_FUNC_(isxdigit), + ADD_FUNC_(localtime), + ADD_FUNC_(longjmp), + ADD_FUNC_(lseek), + ADD_FUNC_(malloc), + ADD_FUNC_(memalign), + ADD_FUNC_(memchr), + ADD_FUNC_(memcmp), + ADD_FUNC_(memcpy), + ADD_FUNC_(memmove), + ADD_FUNC_(memset), + ADD_FUNC_(mkdir), + ADD_FUNC_(mktime), + ADD_FUNC_(open), + ADD_FUNC_(opendir), + ADD_FUNC_(qsort), + ADD_FUNC_(rand), + ADD_FUNC_(read), + ADD_FUNC_(readdir), + ADD_FUNC_(realloc), + ADD_FUNC_(remove), + ADD_FUNC_(rename), + ADD_FUNC_(rewinddir), + ADD_FUNC_(seekdir), + ADD_FUNC_(setjmp), + ADD_FUNC_(setvbuf), + ADD_FUNC_(sinLerp), + ADD_FUNC_(srand), + ADD_FUNC_(stat), + ADD_FUNC_(strcat), + ADD_FUNC_(strchr), + ADD_FUNC_(strcmp), + ADD_FUNC_(strcpy), + ADD_FUNC_(strcspn), + ADD_FUNC_(strerror), + ADD_FUNC_(strftime), + ADD_ALIAS(stricmp, strcasecmp), + ADD_FUNC_(strlen), + ADD_FUNC_(strncat), + ADD_FUNC_(strncmp), + ADD_FUNC_(strncpy), + ADD_ALIAS(strnicmp, strncasecmp), + ADD_FUNC_(strpbrk), + ADD_FUNC_(strrchr), + ADD_FUNC_(strspn), + ADD_FUNC_(strstr), + ADD_FUNC_(strtok), + ADD_FUNC_(strtol), + ADD_FUNC_(strtoul), + ADD_FUNC_(system), + ADD_FUNC_(tanLerp), + ADD_FUNC_(telldir), + ADD_FUNC_(time), + ADD_FUNC_(tolower), + ADD_FUNC_(toupper), + ADD_FUNC_(ungetc), + ADD_ALIAS(vfprintf, vfiprintf), + ADD_ALIAS(vfscanf, vfiscanf), + ADD_ALIAS(vsnprintf, vsniprintf), + ADD_ALIAS(vsprintf, vsiprintf), + ADD_ALIAS(vsscanf, vsiscanf), + ADD_FUNC_(write), +END_TABLE(FEOSKRNL) + +MAKE_FAKEMODULE(FEOSKRNL) + +#define stricmp strcasecmp +#define strnicmp strncasecmp + +static word_t dummy_entrypoint(word_t a, word_t b, word_t c, word_t d) +{ + return FEOS_RC_OK; +} + +static executeStatus_t defaultExecStatus; +executeStatus_t* curExecStatus = &defaultExecStatus; + +#ifdef LIBFAT_FEOS_MULTICWD +void KeInitDefaultExecStatus() +{ + defaultExecStatus.cwdBuffer = _getCwdBuf(); +} + +#define EXECSTAT_ADDENDUM 256 +#else +#define EXECSTAT_ADDENDUM 0 +#endif + +#define GET_ADDENDUM(x) ((char*)(x) + sizeof(executeStatus_t)); + +execstat_t KeExecStatusCreate() +{ + executeStatus_t* pSt = (executeStatus_t*) malloc(sizeof(executeStatus_t) + EXECSTAT_ADDENDUM); + if (!pSt) return NULL; + + memset(pSt, 0, sizeof(executeStatus_t)); + pSt->refcount = 1; + + // Inherit standard stream hooks + pSt->stdin_hook = curExecStatus->stdin_hook; + pSt->stdout_hook = curExecStatus->stdout_hook; + pSt->stderr_hook = curExecStatus->stderr_hook; + +#ifdef LIBFAT_FEOS_MULTICWD + // Inherit current working directory + pSt->cwdCluster = g_fatCwdCluster; + pSt->cwdBuffer = GET_ADDENDUM(pSt); + memcpy(pSt->cwdBuffer, curExecStatus->cwdBuffer, EXECSTAT_ADDENDUM); +#endif + + return pSt; +} + +void KeExecStatusAddRef(execstat_t hSt) +{ + if (hSt == (execstat_t) &defaultExecStatus) return; + ((executeStatus_t*)hSt)->refcount ++; +} + +void KeExecStatusRelease(execstat_t hSt) +{ + if (hSt == (execstat_t) &defaultExecStatus) return; + word_t r = --((executeStatus_t*)hSt)->refcount; + if (r == 0) + free(hSt); +} + +void KeSetCurExecStatus(execstat_t hSt) +{ +#ifdef LIBFAT_FEOS_MULTICWD + curExecStatus->cwdCluster = g_fatCwdCluster; +#endif + curExecStatus = (executeStatus_t*) hSt; +#ifdef LIBFAT_FEOS_MULTICWD + g_fatCwdCluster = curExecStatus->cwdCluster; + _setCwdBuf(curExecStatus->cwdBuffer); +#endif +} + +execstat_t KeGetCurExecStatus() +{ + return (execstat_t) curExecStatus; +} + +#define LdrCurModule curExecStatus->curModule +#define LdrExitBuf curExecStatus->exitBuf +#define LdrExitDone curExecStatus->exitDone + +int LdrExecuteArgv(int argc, const char* argv[]) +{ + if (argc == 0) return E_INVALIDARG; + module_t hMod = LdrLoadModule(argv[0]); + if (!hMod) return E_FILENOTFOUND; + + if (!__system) + __system = (systemfunc_t) LdrFindSymbol(hMod, "__system"); + + fxe_runtime_header* rh = GetRuntimeData(hMod); + + int rc = E_INVALIDARG; + if (rh->entrypoint) + { + module_t hPrevMod = LdrCurModule; + LdrCurModule = hMod; + + jmp_buf exitbuf; + word_t* pPrevBuf = LdrExitBuf; + LdrExitBuf = exitbuf; + rc = setjmp(exitbuf); + if (!LdrExitDone) + rc = rh->entrypoint(FEOS_EP_MAIN, (word_t)argc, (word_t)argv, 0); + else + LdrExitDone = false; + + LdrExitBuf = pPrevBuf; + LdrCurModule = hPrevMod; + } + + // If the app was forcefully killed we don't want FreeModule() to run the destructors + if ((int)rc == E_APPKILLED) rh->entrypoint = dummy_entrypoint; + + LdrFreeModule(hMod); + return rc; +} + +void LdrModuleExit(int rc) +{ + LdrExitDone = true; + longjmp0(LdrExitBuf, rc); +} + +void* LdrGetExidxTbl(module_t hMod, int* count) +{ + if (hMod == (module_t)(~0)) + { + // get exidx for kernel itself + typedef struct { word_t offset, size; } exidx_entry_t; + extern exidx_entry_t __exidx_start; + extern exidx_entry_t __exidx_end; + *count = &__exidx_end - &__exidx_start; + return &__exidx_start; + } + + CHK_HMOD(hMod); + fxe_runtime_header* rh = GetRuntimeData(hMod); + + if (!rh->exidx.nentries) return NULL; + if (count) *count = rh->exidx.nentries; + + return rh->exidx.table; +} diff --git a/kernel/source/excpt.c b/kernel/source/kernelerror.c similarity index 96% rename from kernel/source/excpt.c rename to kernel/source/kernelerror.c index 26bcc00..e1179a5 100644 --- a/kernel/source/excpt.c +++ b/kernel/source/kernelerror.c @@ -1,11 +1,11 @@ #include "feos.h" -#include "fxe.h" +#include "loader.h" #include #include #include #include -void videoReset(); +void DSVideoReset(); void InstallConThunks(); void InstallConDummy(); @@ -28,7 +28,7 @@ PrintConsole oConSub; typedef struct { const char* name; - instance_t module; + module_t module; word_t offset; } part_t; @@ -43,7 +43,7 @@ static bool resolveAddr(part_t* pPart, void* addr) pPart->offset = (word_t)addr; return true; } - instance_t module = FeOS_ModuleFromAddress(addr); + module_t module = LdrResolveAddr(addr); if (!module) return false; pPart->name = GetRuntimeData(module)->name; @@ -89,12 +89,12 @@ static int stCallback(void* address, int depth /* 0-based */, void* user_data); static void showStacktrace() { iprintf("\x1b[2J\x1b[5CStacktrace\n\n"); - instance_t cxxInst = FeOS_GetModule("feoscxx"); - if (!cxxInst) + module_t hCxxMod = LdrGetModule("feoscxx"); + if (!hCxxMod) iprintf("Unavailable: feoscxx not loaded\n\n"); else { - btDumpFunc btDump = (btDumpFunc) FeOS_FindSymbol(cxxInst, "FeOS_BacktraceDump"); + btDumpFunc btDump = (btDumpFunc) LdrFindSymbol(hCxxMod, "CxxBacktraceDump"); btDump((word_t*)exceptionRegisters, stCallback, NULL); iprintf("\n"); } @@ -214,10 +214,12 @@ static word_t resolveErrorAddress(void* pOpcode, bool isThumb) return resolveErrorAddress_ARM(*(word_t*)pOpcode); } -void ExcptHandler_C() +void KeSystemError() { REG_IME = 0; - videoReset(); + extern bool conMode; + conMode = false; + DSVideoReset(); videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); PrintConsole* conmain = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 0, 1, true, true); diff --git a/kernel/source/keybdread.c b/kernel/source/keybdread.c index e2f01d1..d7740b6 100644 --- a/kernel/source/keybdread.c +++ b/kernel/source/keybdread.c @@ -14,32 +14,20 @@ extern bool stdioRead; extern char keyBuffer[KEY_BUFFER_SIZE]; extern Keyboard* curKeyboard; -int FeOS_swi_keyboardUpdate(); - -ssize_t FeOS_KeybdRead(struct _reent *r, int unused, char *ptr, size_t len) +ssize_t DSKeybdRead(struct _reent *r, int unused, char *ptr, size_t len) { - //int wasHidden = 0; int tempLen; int c = NOKEY; stdioRead = true; - // FeOS: this never happens - /* - if (!curKeyboard->visible) - { - wasHidden = 1; - keyboardShow(); - } - */ - do { // FeOS: wait for VBlank. // - It avoids unnecessarily killing the CPU // - It allows user IRQs to run - FeOS_WaitForVBlank(); - FeOS_swi_keyboardUpdate(); + DSWaitForVBlank(); + keyboardUpdate(); } while(keyBufferLength <= 0 || (keyBufferLength < KEY_BUFFER_SIZE && lastKey != DVK_ENTER)); tempLen = keyBufferLength; @@ -54,12 +42,6 @@ ssize_t FeOS_KeybdRead(struct _reent *r, int unused, char *ptr, size_t len) len--; } - // FeOS: this never happens - /* - if (wasHidden) - keyboardHide(); - */ - stdioRead = false; return tempLen; diff --git a/kernel/source/fxeload.arm.c b/kernel/source/loader.arm.c similarity index 80% rename from kernel/source/fxeload.arm.c rename to kernel/source/loader.arm.c index e8d4d8f..0bb331a 100644 --- a/kernel/source/fxeload.arm.c +++ b/kernel/source/loader.arm.c @@ -1,4 +1,4 @@ -#include "fxe.h" +#include "loader.h" #include "feosfifo.h" #include #include @@ -6,7 +6,7 @@ #include #include -static instance_t _LoadModule_imp(const char* aFilename, const char* aModuleName); +static module_t _LdrLoadModule(const char* aFilename, const char* aModuleName); static const char* moduleSearchPaths[] = { @@ -15,7 +15,7 @@ static const char* moduleSearchPaths[] = NULL }; -instance_t LoadModule(const char* aFilename) +module_t LdrLoadModule(const char* aFilename) { sassert(aFilename, ERRSTR_INVALIDPARAM); if (*aFilename == '/') @@ -48,7 +48,7 @@ instance_t LoadModule(const char* aFilename) // Check if the module is already loaded { - fxe_runtime_header* header = FeOS_ModuleListFind(aModuleName); + fxe_runtime_header* header = LdrModuleListFind(aModuleName); if (header) { header->refcount ++; @@ -57,14 +57,14 @@ instance_t LoadModule(const char* aFilename) } } - instance_t ret = _LoadModule_imp(aFilename, aModuleName); + module_t ret = _LdrLoadModule(aFilename, aModuleName); free(aModuleName); return ret; }else { // Check if the module is already loaded { - fxe_runtime_header* header = FeOS_ModuleListFind(aFilename); + fxe_runtime_header* header = LdrModuleListFind(aFilename); if (header) { header->refcount ++; @@ -89,14 +89,14 @@ instance_t LoadModule(const char* aFilename) } // Load the module - instance_t ret = *aBuf ? _LoadModule_imp(buf, aFilename) : NULL; + module_t ret = *aBuf ? _LdrLoadModule(buf, aFilename) : NULL; free(buf); return ret; } } } -static instance_t _LoadModule_imp(const char* aFilename, const char* aModuleName) +static module_t _LdrLoadModule(const char* aFilename, const char* aModuleName) { int aModuleNameLen = strlen(aModuleName)+1; @@ -240,7 +240,7 @@ static instance_t _LoadModule_imp(const char* aFilename, const char* aModuleName imptbl[i].address += (word_t) pMem; } - if (!ResolveImports(imptbl, nimports)) + if (!LdrResolveImports(imptbl, nimports)) { free(imptbl), free(pMem), close(fd); return NULL; @@ -297,11 +297,11 @@ static instance_t _LoadModule_imp(const char* aFilename, const char* aModuleName *(volatile word_t*)pMem = (word_t) rh; // Update caches - FeOS_swi_DataCacheFlush(pMem, totalsize); - FeOS_swi_InstrCacheInvalidate(pMem, totalsize); + KeDataCacheFlush(pMem, totalsize); + KeInstrCacheInvalidate(pMem, totalsize); // Add this module to the list of loaded modules - FeOS_ModuleListAdd(rh); + LdrModuleListAdd(rh); // Get the start and size of the extra data section rh->extrapos = tell(fd); @@ -322,24 +322,22 @@ static instance_t _LoadModule_imp(const char* aFilename, const char* aModuleName return pMem; } -int ModuleExtraGetSize(instance_t hInst) +int LdrResGetSize(module_t hMod) { - CHK_HINST(hInst); - fxe_runtime_header* rh = GetRuntimeData(hInst); - return rh->extrasize; + CHK_HMOD(hMod); + return GetRuntimeData(hMod)->extrasize; } -int ModuleExtraRead(instance_t hInst, void* buf, size_t size) +int LdrResRead(module_t hMod, void* buf, size_t size) { - CHK_HINST(hInst); - fxe_runtime_header* rh = GetRuntimeData(hInst); - return read(rh->file, buf, size); + CHK_HMOD(hMod); + return read(GetRuntimeData(hMod)->file, buf, size); } -int ModuleExtraSeek(instance_t hInst, int pos, int mode) +int LdrResSeek(module_t hMod, int pos, int mode) { - CHK_HINST(hInst); - fxe_runtime_header* rh = GetRuntimeData(hInst); + CHK_HMOD(hMod); + fxe_runtime_header* rh = GetRuntimeData(hMod); int fd = rh->file; int base = rh->extrapos; switch (mode) @@ -362,19 +360,17 @@ int ModuleExtraSeek(instance_t hInst, int pos, int mode) return -1; } -int ModuleExtraTell(instance_t hInst) +int LdrResTell(module_t hMod) { - CHK_HINST(hInst); - fxe_runtime_header* rh = GetRuntimeData(hInst); + CHK_HMOD(hMod); + fxe_runtime_header* rh = GetRuntimeData(hMod); return tell(rh->file) - rh->extrapos; } static FeOSLoadStruct __ldSt; - -//#define GET_LOADST() ((FeOSLoadStruct*)memUncached(&__ldSt)) #define GET_LOADST() (&__ldSt) -instance_t LoadModule_ARM7(const char* aFilename, int* pFifoCh) +module_t DSLoadARM7(const char* aFilename, int* pFifoCh) { sassert(aFilename, ERRSTR_INVALIDPARAM); sassert(pFifoCh, ERRSTR_INVALIDPARAM); @@ -432,8 +428,8 @@ instance_t LoadModule_ARM7(const char* aFilename, int* pFifoCh) ldSt->nrelocs = head.nrelocs; ldSt->relocs = (fxe2_reloc_t*)((u8*)pMem + head.loadsize); - DC_FlushRange(pMem, readsize + head.simports); - DC_FlushRange(ldSt, sizeof(FeOSLoadStruct)); + KeDataCacheFlush(pMem, readsize + head.simports); + KeDataCacheFlush(ldSt, sizeof(FeOSLoadStruct)); // Tell the ARM7 to load the module fifoSendDatamsg(FIFO_FEOS, sizeof(FeOSFifoMsg), (void*) &msg); @@ -450,24 +446,23 @@ instance_t LoadModule_ARM7(const char* aFilename, int* pFifoCh) return msg.hModule; } -void FreeModule_ARM7(instance_t hModule, int fifoCh) +void DSFreeARM7(module_t hMod, int fifoCh) { - sassert(hModule, ERRSTR_INVALIDPARAM); + sassert(hMod, ERRSTR_INVALIDPARAM); FeOSFifoMsg msg; msg.type = FEOS_ARM7_UNLOAD_MODULE; - msg.hModule = hModule; + msg.hModule = hMod; msg.fifoCh = fifoCh; fifoSendDatamsg(FIFO_FEOS, sizeof(FeOSFifoMsg), (void*) &msg); while(!fifoCheckValue32(FIFO_FEOS)); fifoGetValue32(FIFO_FEOS); } -void FreeModule(instance_t hInst) +void LdrFreeModule(module_t hMod) { - CHK_HINST(hInst); - - fxe_runtime_header* rh = GetRuntimeData(hInst); + CHK_HMOD(hMod); + fxe_runtime_header* rh = GetRuntimeData(hMod); rh->refcount --; if (rh->refcount) return; @@ -476,7 +471,7 @@ void FreeModule(instance_t hInst) rh->entrypoint(FEOS_EP_FINI, 0, 0, 0); // Remove the module from the list of loaded modules - FeOS_ModuleListRemove(rh); + LdrModuleListRemove(rh); // Free the export table if (rh->exp.count) @@ -485,7 +480,7 @@ void FreeModule(instance_t hInst) // Free the import table if (rh->imp.count) { - FreeImports(rh->imp.table, rh->imp.count); + LdrFreeImports(rh->imp.table, rh->imp.count); free(rh->imp.table); } @@ -493,33 +488,49 @@ void FreeModule(instance_t hInst) close(rh->file); // Free the module memory - free(hInst); + free(hMod); } -void ModuleLock(instance_t hInst) +void LdrLockModule(module_t hMod) { - CHK_HINST(hInst); - GetRuntimeData(hInst)->refcount ++; + CHK_HMOD(hMod); + GetRuntimeData(hMod)->refcount ++; } -void ModuleUnlock(instance_t hInst) +void LdrUnlockModule(module_t hMod) { - CHK_HINST(hInst); - GetRuntimeData(hInst)->refcount --; + CHK_HMOD(hMod); + GetRuntimeData(hMod)->refcount --; } -extern const fxe_inmem_exports _exp_FEOSBASE; - -void* FindInTbl(const fxe_inmem_exports* exphdr, const char* name) +void* LdrFindInTbl(const fxe_inmem_exports* exphdr, const char* name) { + /* register int i; for(i = 0; i < exphdr->count; i ++) if (strcmp(exphdr->table[i].name, name) == 0) return exphdr->table[i].addr; + */ + int min = 0, max = exphdr->count; + + while (max >= min) + { + int mid = (min + max) / 2; + int rc = strcmp(exphdr->table[mid].name, name); + if (rc < 0) + min = mid + 1; + else if (rc > 0) + { + if (mid == 0) break; + max = mid - 1; + } else + return exphdr->table[mid].addr; + } + return NULL; } -int ResolveImports(fxe2_import_t* imptbl, int count) +int LdrResolveImports(fxe2_import_t* imptbl, int count) { register int i; fxe_inmem_exports* exptable = NULL; @@ -531,16 +542,16 @@ int ResolveImports(fxe2_import_t* imptbl, int count) if(imp->address == FX2_IMP_SELECT_MODULE) { - instance_t hModule = LoadModule(imp->name); - if (!hModule) return 0; + module_t hMod = LdrLoadModule(imp->name); + if (!hMod) return 0; - exptable = &GetRuntimeData(hModule)->exp; + exptable = &GetRuntimeData(hMod)->exp; continue; } if (!exptable) return 0; - sym = FindInTbl(exptable, imp->name); + sym = LdrFindInTbl(exptable, imp->name); if (!sym) return 0; @@ -549,7 +560,7 @@ int ResolveImports(fxe2_import_t* imptbl, int count) return 1; } -void FreeImports(fxe2_import_t* imptbl, int count) +void LdrFreeImports(fxe2_import_t* imptbl, int count) { register int i; @@ -559,9 +570,9 @@ void FreeImports(fxe2_import_t* imptbl, int count) if(imp->address != FX2_IMP_SELECT_MODULE) continue; - fxe_runtime_header* header = FeOS_ModuleListFind(imp->name); + fxe_runtime_header* header = LdrModuleListFind(imp->name); if (!header) continue; // oops, memory corruption? (shouldn't happen) - FreeModule(header->hThis); + LdrFreeModule(header->hThis); } } diff --git a/kernel/source/fxe.h b/kernel/source/loader.h similarity index 58% rename from kernel/source/fxe.h rename to kernel/source/loader.h index 4539b9f..c507bbb 100644 --- a/kernel/source/fxe.h +++ b/kernel/source/loader.h @@ -124,7 +124,7 @@ typedef struct typedef struct tag_fxe_runtime_header { - instance_t hThis; + module_t hThis; const char* name; int refcount; int file; @@ -138,49 +138,44 @@ typedef struct tag_fxe_runtime_header struct tag_fxe_runtime_header* prev; } fxe_runtime_header; -static inline fxe_runtime_header* GetRuntimeData(instance_t hinst) +static inline fxe_runtime_header* GetRuntimeData(module_t hMod) { - return (fxe_runtime_header*) *(word_t*) hinst; + return (fxe_runtime_header*) *(word_t*) hMod; } -instance_t LoadModule(const char* aFilename); -void FreeModule(instance_t hInst); -instance_t FeOS_GetModule(const char* name); -const char* FeOS_GetModuleName(instance_t hInst); +module_t LdrLoadModule(const char* aFilename); +void LdrFreeModule(module_t hMod); +module_t LdrGetModule(const char* name); +const char* LdrGetModuleName(module_t hMod); -void* FeOS_FindSymbol(instance_t hinst, const char* sym); +void* LdrFindSymbol(module_t hMod, const char* sym); -void ModuleLock(instance_t hInst); -void ModuleUnlock(instance_t hInst); +void LdrLockModule(module_t hMod); +void LdrUnlockModule(module_t hMod); -int ModuleExtraGetSize(instance_t hInst); -int ModuleExtraRead(instance_t hInst, void* buf, size_t size); -int ModuleExtraSeek(instance_t hInst, int pos, int mode); -int ModuleExtraTell(instance_t hInst); +int LdrResGetSize(module_t hMod); +int LdrResRead(module_t hMod, void* buf, size_t size); +int LdrResSeek(module_t hMod, int pos, int mode); +int LdrResTell(module_t hMod); -int FeOS_Execute(int, const char*[]); +int LdrExecuteArgv(int, const char*[]); -int ResolveImports(fxe2_import_t* imptbl, int count); -void FreeImports(fxe2_import_t* imptbl, int count); -void* FindInTbl(const fxe_inmem_exports* exphdr, const char* name); +int LdrResolveImports(fxe2_import_t* imptbl, int count); +void LdrFreeImports(fxe2_import_t* imptbl, int count); +void* LdrFindInTbl(const fxe_inmem_exports* exphdr, const char* name); -void FeOS_ModuleListInit(); -void FeOS_ModuleListAdd(fxe_runtime_header* pModule); -void FeOS_ModuleListRemove(fxe_runtime_header* pModule); -int FeOS_ModuleListCount(); -fxe_runtime_header* FeOS_ModuleListFind(const char* name); +void LdrModuleListInit(); +void LdrModuleListAdd(fxe_runtime_header* pModule); +void LdrModuleListRemove(fxe_runtime_header* pModule); +int LdrModuleListCount(); +fxe_runtime_header* LdrModuleListFind(const char* name); -typedef int (* moduleEnumCb)(instance_t hInst, const char* name, size_t size, void* user_data); +typedef int (* moduleEnumCb)(module_t hMod, const char* name, size_t size, void* user_data); -void FeOS_EnumModules(moduleEnumCb cb, void* user_data); +void LdrEnumModules(moduleEnumCb cb, void* user_data); +void LdrModuleExit(int); -//int FeOS_PushExitFunc(FeOSExitFunc func); -void FeOS_ModuleExit(int); -//void FeOS_PopExitFunc(); - -void* FeOS_GetModuleExidxTbl(instance_t, int*); -void* FeOS_ModuleFromAddress(void*); - -extern instance_t FeOS_CurInstance; +void* LdrGetExidxTbl(module_t, int*); +void* LdrResolveAddr(void*); #endif diff --git a/kernel/source/main.c b/kernel/source/main.c index 7d2ee86..83fe670 100644 --- a/kernel/source/main.c +++ b/kernel/source/main.c @@ -1,13 +1,24 @@ #include "feos.h" #include #include -#include "fxe.h" +#include +#include "loader.h" #include "feosfifo.h" #include #include "hudicons.h" #include "caret.h" +// Replacement for newlib iprintf +ssize_t iprintf(const char* fmt, ...) +{ + va_list va; + va_start(va, fmt); + ssize_t ret = vfiprintf(stdout, fmt, va); + va_end(va); + return ret; +} + void __SWIHandler(); void __ResetHandler(); @@ -30,7 +41,7 @@ int caretBlink = 0; extern volatile bool inHeadphoneSleep; volatile int vblankCounter = 0; // upper bound: ~2.275 years -void irq_vblank() +void KeVBlankISR() { // Done here because it's kernel mode code chk_exit(); @@ -115,7 +126,7 @@ void videoInit() dmaCopyHalfWords(3, hudiconsPal, SPRITE_PALETTE_SUB, hudiconsPalLen); dmaCopyHalfWords(3, caretPal, SPRITE_PALETTE, caretPalLen); - irqSet(IRQ_VBLANK, irq_vblank); + irqSet(IRQ_VBLANK, KeVBlankISR); // Initialize the keyboard Keyboard* kbd = keyboardDemoInit(); @@ -128,11 +139,10 @@ void InstallThunks(); void InstallConThunks(); void InstallConDummy(); -void UnblockIORegion(); -void BlockIORegion(); - -void videoReset() +void DSVideoReset() { + if (conMode) return; + dmaFillWords(0, (void*)0x04000000, 0x56); dmaFillWords(0, (void*)0x04001008, 0x56); videoSetModeSub(0); @@ -150,35 +160,35 @@ void videoReset() irqEnable(IRQ_VBLANK); } -void InitConMode() +void DSConsoleMode() { + if (conMode) return; int cS = enterCriticalSection(); - videoReset(); + DSVideoReset(); videoInit(); InstallConThunks(); - BlockIORegion(); conMode = true; bOAMUpd = true, bBgUpd = true, bKeyUpd = true; leaveCriticalSection(cS); } -void InitFreeMode() +void DSDirectMode() { + if (!conMode) return; int cS = enterCriticalSection(); - videoReset(); - InstallConDummy(); - UnblockIORegion(); conMode = false; + DSVideoReset(); + InstallConDummy(); bOAMUpd = true, bBgUpd = true, bKeyUpd = true; leaveCriticalSection(cS); } -int GetCurMode() +int DSGetCurMode() { return (int)conMode; } -void FeOS_SetAutoUpdate(int which, bool enable) +void DSSetAutoUpdate(int which, bool enable) { if (conMode) return; // can't tweak switch (which) @@ -190,7 +200,7 @@ void FeOS_SetAutoUpdate(int which, bool enable) } } -bool FeOS_GetAutoUpdate(int which) +bool DSGetAutoUpdate(int which) { if (conMode) return true; switch (which) @@ -206,7 +216,7 @@ bool FeOS_GetAutoUpdate(int which) void ForcefulExit() { - FeOS_ModuleExit(E_APPKILLED); + LdrModuleExit(E_APPKILLED); } word_t* __getIRQStack(); @@ -250,7 +260,7 @@ void KillCurrentApp_SWI() __setSWIStack(swistack + 2); // Switch back to User mode - DoTheUserMode(); + KeEnterUserMode(); // Kill the application ForcefulExit(); @@ -298,10 +308,10 @@ void chk_exit() exit(_rc); } -void FeOS_InitStreams(); -void FeOS_InitSystemInfo(); +void IoInitStreams(); +void KeInitSystemInfo(); -void ExcptHandler_C(); +void KeSystemError(); static void error_die() { @@ -310,7 +320,10 @@ static void error_die() { swiWaitForVBlank(); if (keysDown() & KEY_START) - exit(1); + { + _rc = 1; + _hasExited = true; + } } } @@ -333,15 +346,14 @@ int main() videoInit(); consoleDebugInit(DebugDevice_CONSOLE); - setExceptionHandler(ExcptHandler_C); + setExceptionHandler(KeSystemError); SystemVectors.reset = (u32) __ResetHandler; SystemVectors.swi = (u32) __SWIHandler; setVectorBase(0); - FeOS_ModuleListInit(); - FeOS_InitStreams(); + LdrModuleListInit(); + IoInitStreams(); installFeOSFIFO(); - - FeOS_InitSystemInfo(); + KeInitSystemInfo(); iprintf( "\n FeOS kernel v" FEOS_VERSION_TEXT "\n" @@ -354,37 +366,38 @@ int main() iprintf("\nInitializing filesystem... "); if (!fatInitDefault()) { - iprintf(MSG_FAIL); - iprintf("Make sure you have DLDI patched\n"); - iprintf("the kernel binary. If the issue\n"); - iprintf("persists, try using HBMenu.\n\n"); - iprintf(" http://devkitpro.org/hbmenu\n"); - iprintf(" http://feos.mtheall.com/forum\n"); + iprintf( + MSG_FAIL + "Make sure you have DLDI patched\n" + "the kernel binary. If the issue\n" + "persists, try using HBMenu.\n\n" + " http://devkitpro.org/hbmenu\n" + " http://feos.mtheall.com/forum\n"); error_die(); } #ifdef LIBFAT_FEOS_MULTICWD g_fatCwdClusterPtr = (vu32*) _FAT_getCwdClusterPtr("/"); - FeOS_InitDefaultExecStatus(); + KeInitDefaultExecStatus(); #endif InstallThunks(); #ifdef LIBFAT_FEOS_MULTICWD iprintf(MSG_OK); #else - iprintf(MSG_OK2); iprintf( + MSG_OK2 WARNING "Multi-CWD support is\n" "disabled due to the usage of an\n" "old version of libfat.\n\n"); #endif iprintf("Initializing user mode... "); - PrepareUserMode(); - DoTheUserMode(); + KeInitUserMode(); + KeEnterUserMode(); iprintf(MSG_OK); #ifdef DEBUG iprintf("Loading debug library... "); - instance_t hCxxLib = LoadModule("feoscxx"); + module_t hCxxLib = LdrLoadModule("feoscxx"); if (!hCxxLib) { iprintf( @@ -401,8 +414,17 @@ int main() const char* argv[] = { "cmd", ":startup", NULL }; - _rc = FeOS_Execute(2, argv); + _rc = LdrExecuteArgv(2, argv); + if (_rc < 0) + { + iprintf( + MSG_FAIL + "The following file is missing\n" + "or it may have been corrupted:\n" + " /data/FeOS/bin/cmd.fx2\n"); + error_die(); + } _hasExited = true; - for(;;) FeOS_WaitForVBlank(); + for(;;) DSWaitForVBlank(); } diff --git a/kernel/source/modulelist.arm.c b/kernel/source/modulelist.arm.c index 6c11647..e0770e8 100644 --- a/kernel/source/modulelist.arm.c +++ b/kernel/source/modulelist.arm.c @@ -1,27 +1,21 @@ -#include "fxe.h" +#include "loader.h" #define LINK_FAKEMODULE(NAME) \ extern fxe_runtime_header _header_##NAME; \ - FeOS_ModuleListAdd(&_header_##NAME) + LdrModuleListAdd(&_header_##NAME) -extern fxe_runtime_header _header_FEOSBASE; +extern fxe_runtime_header _header_FEOSKRNL; -static fxe_runtime_header* mListHead = &_header_FEOSBASE; -static fxe_runtime_header* mListTail = &_header_FEOSBASE; +static fxe_runtime_header* mListHead = &_header_FEOSKRNL; +static fxe_runtime_header* mListTail = &_header_FEOSKRNL; static int nmodules = 1; -void FeOS_ModuleListInit() +void LdrModuleListInit() { - LINK_FAKEMODULE(FEOSSTDIO); - LINK_FAKEMODULE(FEOSPOSIXEMU); - LINK_FAKEMODULE(FEOSMATH); - LINK_FAKEMODULE(FEOSDSAPI); - LINK_FAKEMODULE(FEOSDSSPR); - LINK_FAKEMODULE(FEOSDSBG); - LINK_FAKEMODULE(FEOSARM7); + LINK_FAKEMODULE(FEOSDSHW); } -void FeOS_ModuleListAdd(fxe_runtime_header* pModule) +void LdrModuleListAdd(fxe_runtime_header* pModule) { mListTail->next = pModule; pModule->next = NULL; @@ -30,7 +24,7 @@ void FeOS_ModuleListAdd(fxe_runtime_header* pModule) nmodules ++; } -void FeOS_ModuleListRemove(fxe_runtime_header* pModule) +void LdrModuleListRemove(fxe_runtime_header* pModule) { if (pModule->file == -1) return; // thwart attempts at doing evil @@ -40,12 +34,12 @@ void FeOS_ModuleListRemove(fxe_runtime_header* pModule) nmodules --; } -int FeOS_ModuleListCount() +int LdrModuleListCount() { return nmodules; } -fxe_runtime_header* FeOS_ModuleListFind(const char* name) +fxe_runtime_header* LdrModuleListFind(const char* name) { fxe_runtime_header* item; for (item = mListHead; item != NULL; item = item->next) @@ -56,7 +50,7 @@ fxe_runtime_header* FeOS_ModuleListFind(const char* name) extern const byte_t __text_start[]; extern const byte_t __end__[]; -void* FeOS_ModuleFromAddress(void* addr) +void* LdrResolveAddr(void* addr) { word_t addrw = (word_t) addr; @@ -78,7 +72,7 @@ void* FeOS_ModuleFromAddress(void* addr) return NULL; } -void FeOS_EnumModules(moduleEnumCb cb, void* user_data) +void LdrEnumModules(moduleEnumCb cb, void* user_data) { sassert(cb, ERRSTR_INVALIDPARAM); diff --git a/kernel/source/posixemu.c b/kernel/source/posixemu.c deleted file mode 100644 index 09ee00c..0000000 --- a/kernel/source/posixemu.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "feos.h" -#include "fxe.h" -#include -#include -#include -#include -#include - -static inline int _fileno_helper(FILE* f) { return fileno(f); } - -BEGIN_TABLE(FEOSPOSIXEMU) - // Directory functions - ADD_FUNC(opendir), - ADD_FUNC(closedir), - ADD_FUNC(readdir), - ADD_FUNC(rewinddir), - ADD_FUNC(seekdir), - ADD_FUNC(telldir), - ADD_FUNC(mkdir), - ADD_FUNC(fstat), - ADD_FUNC_ALIAS(_fileno_helper, fileno), - - // CWD functions - ADD_FUNC(chdir), - ADD_FUNC(getcwd), - - // Misc functions - ADD_FUNC(stat), - ADD_FUNC(ftruncate), - - // POSIX I/O - ADD_FUNC(open), - ADD_FUNC(close), - ADD_FUNC(read), - ADD_FUNC(write), - ADD_FUNC(lseek), - ADD_FUNC(fdopen) -END_TABLE(FEOSPOSIXEMU) - -MAKE_FAKEMODULE(FEOSPOSIXEMU) diff --git a/kernel/source/sassert.c b/kernel/source/sassert.c index 22aaa6c..2a92750 100644 --- a/kernel/source/sassert.c +++ b/kernel/source/sassert.c @@ -1,14 +1,14 @@ #ifdef DEBUG #include "feos.h" -#include "fxe.h" +#include "loader.h" #include #include #include // Replacement for the libnds function -void videoReset(); +void DSVideoReset(); void InstallConThunks(); void InstallConDummy(); @@ -30,13 +30,14 @@ static const char* meow[] = NULL }; -void __attribute__((noreturn)) FeOS_swi_assertfail(const char* file, int line, const char* cond, const char* msg); +void __attribute__((noreturn)) __assert2(const char* file, int line, const char* cond, const char* msg); void __attribute__((noreturn)) __sassert(const char* file, int line, const char* cond, const char* msg) { - if (isUserMode()) FeOS_swi_assertfail(file, line, cond, msg); - - videoReset(); + if (isUserMode()) __assert2(file, line, cond, msg); + extern bool conMode; + conMode = false; + DSVideoReset(); videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); PrintConsole* conmain = consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 0, 1, true, true); diff --git a/kernel/source/feosstream.c b/kernel/source/stream.c similarity index 96% rename from kernel/source/feosstream.c rename to kernel/source/stream.c index 23b5ea4..c8eda64 100644 --- a/kernel/source/feosstream.c +++ b/kernel/source/stream.c @@ -1,5 +1,5 @@ #include "feos.h" -#include "fxe.h" +#include "loader.h" #include #include #include @@ -58,14 +58,14 @@ static const devoptab_t dotab_stm = NULL }; -void FeOS_InitStreams() +void IoInitStreams() { AddDevice(&dotab_stm); } static stmfile_t _stmCtor; -FILE* FeOS_OpenStream(const stream_t* pStm, void* cData) +FILE* IoOpenStream(const stream_t* pStm, void* cData) { if (!pStm) return NULL; diff --git a/kernel/source/suspend.c b/kernel/source/suspend.c index 4307930..641ce2a 100644 --- a/kernel/source/suspend.c +++ b/kernel/source/suspend.c @@ -3,7 +3,7 @@ static int suspendMode = MODE_NORMAL; -int FeOS_SetSuspendMode(int mode) +int DSSetSuspendMode(int mode) { if (mode == MODE_GET) return suspendMode; sassert(mode >= 0 && mode < MODE_COUNT, ERRSTR_INVALIDPARAM); diff --git a/kernel/source/knlthunks.s b/kernel/source/thunks.s similarity index 100% rename from kernel/source/knlthunks.s rename to kernel/source/thunks.s diff --git a/sdk/Makefile b/sdk/Makefile index 138c990..11581e0 100644 --- a/sdk/Makefile +++ b/sdk/Makefile @@ -4,14 +4,8 @@ TOOLS := bin/fxe2tool_src \ bin/fartool_src \ bin/fpkgtool_src \ bin/fmantool_src -FAKES := source/FEOSBASE \ - source/FEOSSTDIO \ - source/FEOSPOSIXEMU \ - source/FEOSMATH \ - source/FEOSDSAPI \ - source/FEOSDSSPR \ - source/FEOSDSBG \ - source/FEOSARM7 \ +FAKES := source/FEOSKRNL \ + source/FEOSDSHW \ source7/FEOS7 .PHONY: all clean $(TOOLS) $(FAKES) diff --git a/sdk/bin/fxe2.ld b/sdk/bin/fxe2.ld index ba300b9..4a39491 100644 --- a/sdk/bin/fxe2.ld +++ b/sdk/bin/fxe2.ld @@ -15,7 +15,7 @@ SECTIONS =========================== */ . = 0; __start__ = . ; - __hinstance = . ; + __modulebase = . ; __load_start = . ; __text_start = . ; diff --git a/sdk/bin/fxe2tool_src/source/main.c b/sdk/bin/fxe2tool_src/source/main.c index 6eea7b0..caf923b 100644 --- a/sdk/bin/fxe2tool_src/source/main.c +++ b/sdk/bin/fxe2tool_src/source/main.c @@ -444,6 +444,13 @@ int SortSymbols(elf2fx2_cnvstruct_t* cs) return 0; } +int cmp_expptr(const void* _a, const void* _b) +{ + const elf2fx2_expimp_t* a = *(const elf2fx2_expimp_t**) _a; + const elf2fx2_expimp_t* b = *(const elf2fx2_expimp_t**) _b; + return strcmp(a->name, b->name); +} + int ProcessSymbols(elf2fx2_cnvstruct_t* cs) { char cmd[1024]; @@ -467,7 +474,7 @@ int ProcessSymbols(elf2fx2_cnvstruct_t* cs) (strncmp(symname, "__load_", 7) == 0) || (strncmp(symname, "__exidx_", 8) == 0) || (strncmp(symname, "__bss_", 6) == 0) || - (strcmp(symname, "__hinstance") == 0) || + (strcmp(symname, "__modulebase") == 0) || (strcmp(symname, "__start__") == 0) || (strcmp(symname, "__end__") == 0) ) continue; @@ -518,11 +525,20 @@ int ProcessSymbols(elf2fx2_cnvstruct_t* cs) fxe2_export_t* expdata_curexp = expdata; char* expdata_cursym = (char*) expdata + expsymoff; - // Walk the exports linked list + elf2fx2_expimp_t** expTbl = (elf2fx2_expimp_t**) malloc(cs->fxe2hdr.nexports*sizeof(elf2fx2_expimp_t*)); + if (!expTbl) + die("Out of memory!"); + + // Walk and sort the exports linked list elf2fx2_expimp_t* exp = exp_list; - while(exp != NULL) + for (i = 0; exp != NULL; exp = exp->next) + expTbl[i++] = exp; + qsort(expTbl, cs->fxe2hdr.nexports, sizeof(elf2fx2_expimp_t*), cmp_expptr); + + // Process the exports + for (i = 0; i < cs->fxe2hdr.nexports; i ++) { - elf2fx2_expimp_t* next = exp->next; + elf2fx2_expimp_t* exp = expTbl[i]; expdata_curexp->address = eswap_word(exp->addr); expdata_curexp->nameoffset = eswap_word(expsymoff); @@ -534,9 +550,10 @@ int ProcessSymbols(elf2fx2_cnvstruct_t* cs) expsymoff += symlen; free(exp); - exp = next; } + free(expTbl); + safe_call(WriteData(cs->outf, expdata, cs->fxe2hdr.sexports)); free(expdata); } diff --git a/sdk/include/backtrace.h b/sdk/include/backtrace.h index 73a274e..208c69c 100644 --- a/sdk/include/backtrace.h +++ b/sdk/include/backtrace.h @@ -22,7 +22,7 @@ extern "C" typedef int (*BacktraceCallback)(void* address, int depth /* 0-based */, void* user_data); //!< Backtrace callback -void FeOS_Backtrace(BacktraceCallback callback, void* user_data); //!< Performs a backtrace. +void CxxBacktrace(BacktraceCallback callback, void* user_data); //!< Performs a backtrace. /** @} */ diff --git a/sdk/include/errno.h b/sdk/include/errno.h index 9a58f8c..9ca5b35 100644 --- a/sdk/include/errno.h +++ b/sdk/include/errno.h @@ -19,9 +19,9 @@ extern "C" * @{ */ -int* FeOS_GetErrnoPtr(); //!< Get the pointer to the errno variable +int* KeGetErrnoPtr(); //!< Get the pointer to the errno variable -#define errno (*FeOS_GetErrnoPtr()) //!< Error variable +#define errno (*KeGetErrnoPtr()) //!< Error variable #define EPERM 1 /* Not super-user */ #define ENOENT 2 /* No such file or directory */ diff --git a/sdk/include/feos.h b/sdk/include/feos.h index 4ac5422..b88d328 100644 --- a/sdk/include/feos.h +++ b/sdk/include/feos.h @@ -59,7 +59,7 @@ extern "C" - \ref sndlock.h "Sound locking library" */ -#include +#include #include #ifndef ARM7 @@ -73,6 +73,10 @@ extern "C" #include #endif +#ifdef FEOS_ALLOW_OLD_NAMES +#include +#endif + #ifdef __cplusplus } #endif diff --git a/sdk/include/feosbase.h b/sdk/include/feosdef.h similarity index 91% rename from sdk/include/feosbase.h rename to sdk/include/feosdef.h index cf0ccff..ed4195d 100644 --- a/sdk/include/feosbase.h +++ b/sdk/include/feosdef.h @@ -1,13 +1,13 @@ // // FeOS Standard Library -// feosbase.h +// feosdef.h // Base definitions for FeOS // #pragma once #include -/** @file feosbase.h +/** @file feosdef.h * \brief Base definitions for FeOS */ @@ -35,8 +35,7 @@ typedef signed char char_t; //!< Signed 8-bit integer. typedef signed short short_t; //!< Signed 16-bit integer. typedef signed int long_t; //!< Signed 32-bit integer. typedef signed long long dlong_t; //!< Signed 64-bit integer. -typedef void* instance_t; //!< Module instance handle. -typedef word_t file_t; +typedef void* module_t; //!< Module handle. typedef word_t bool_t; typedef long_t off_t; //!< Offset datatype. typedef void (* fp_t)(); //!< Function pointer datatype. @@ -46,8 +45,7 @@ typedef void (* fp_t)(); //!< Function pointer datatype. #endif //! \cond -extern char __hinstance[]; -#define FeOS_hInstance ((instance_t) __hinstance) +extern char __modulebase[]; #ifdef __cplusplus #define EXTERNC extern "C" diff --git a/sdk/include/feosdsapi.h b/sdk/include/feosdsapi.h index 75fe843..8e6a4f9 100644 --- a/sdk/include/feosdsapi.h +++ b/sdk/include/feosdsapi.h @@ -21,9 +21,8 @@ */ //! \headerfile feos.h -//! \brief Structure for FeOS_GetStylusPos(). -typedef struct { int x, y; } styluspos_t; -typedef word_t keys_t; +//! \brief Structure for touchRead(). +typedef struct { int px, py; } touchPosition; // libnds-compatible type defines typedef byte_t u8; //!< libnds unsigned 8-bit integer type @@ -63,8 +62,8 @@ typedef volatile dword_t vuint64; //!< libnds volatile unsigned 64-bit integer t typedef volatile dlong_t vint64; //!< libnds volatile signed 64-bit integer type // libnds compatibility defines -#define timerTick FeOS_TimerTick //!< libnds alias for FeOS_TimerTick() -#define timerStop FeOS_TimerStop //!< libnds alias for FeOS_TimerStop() +#define timerTick DSTimerTick //!< libnds alias for DSTimerTick() +#define timerStop DSTimerStop //!< libnds alias for DSTimerStop() //! \brief Screen resolution constants enum @@ -355,36 +354,24 @@ enum }; //! \brief Retrieves a bitmask containing the keys that have just been pressed. -keys_t keysDown(); +word_t keysDown(); //! \brief Retrieves a bitmask containing the keys that are pressed. -keys_t keysHeld(); +word_t keysHeld(); //! \brief Retrieves a bitmask containing the keys that have just been released. -keys_t keysUp(); +word_t keysUp(); //! \brief Retrieves a bitmask containing the keys that have just been pressed, accounting for auto-repeat. -keys_t keysDownRepeat(); +word_t keysDownRepeat(); //! \brief Configures the timing for key auto-repeat. void keysSetRepeat(byte_t, byte_t); //! \brief Retrieves the stylus position. -void FeOS_GetStylusPos(styluspos_t*); +void touchRead(touchPosition*); //! \brief Scans the status of the keypad. Has no effect if AUTOUPD_KEYS is turned on. void scanKeys(); -// libnds-compat stylus access - -//! \headerfile feos.h -//! \brief libnds touch position structure for touchRead(). -typedef struct { int px, py; } touchPosition; - -//! \brief Retrieves the stylus position (libnds-like version). -static inline void touchRead(touchPosition* tp) -{ - FeOS_GetStylusPos((styluspos_t*) tp); -} - //! \brief Registers a function to be called when the specified interrupt(s) is (are) fired. //! \warning FeOS handles interrupt and FIFO callbacks in a cooperative way instead of //! immediately executing the handlers. This means that callbacks will only be called -//! if and when an application uses IRQ waiting functions or FeOS_CheckPendingIRQs(). +//! if and when an application uses IRQ waiting functions or DSProcessIRQs(). //! \returns The previous callback function. fp_t irqSet(word_t, fp_t); @@ -396,22 +383,22 @@ static inline fp_t irqGet(word_t mask) //! \brief Checks for interrupts that may have been fired and runs any necessary callbacks. //! \returns The interrupts that may have been fired. -word_t FeOS_CheckPendingIRQs(); +word_t DSProcessIRQs(); //! \brief Waits for one of the specified interrupts to occur. -void FeOS_WaitForIRQ(word_t); +void DSWaitForIRQ(word_t); //! \brief Enables the specified interrupt(s). void irqEnable(word_t); //! \brief Disables the specified interrupt(s). void irqDisable(word_t); //! \brief Waits for any interrupt to occur. May return immediately if there were pending interrupts. //! \returns The interrupt(s) that occured. -word_t FeOS_NextIRQ(); +word_t DSWaitForNextIRQ(); //! \brief Waits for the next VBlank to occur. static inline void swiWaitForVBlank() { - FeOS_WaitForIRQ(IRQ_VBLANK); + DSWaitForIRQ(IRQ_VBLANK); } #define DEFAULT_IRQFUNC ((irqWaitFunc_t)0) //!< Internal macro not for public consumption. @@ -419,25 +406,25 @@ static inline void swiWaitForVBlank() typedef void (*irqWaitFunc_t)(word_t); //!< Internal data type not for public consumption. //! \brief Internal function not for public consumption. -irqWaitFunc_t FeOS_SetIRQWaitFunc(irqWaitFunc_t newFunc); +irqWaitFunc_t DSSetIRQWaitFunc(irqWaitFunc_t newFunc); //! \brief Writes a value into a timer register. -void FeOS_TimerWrite(int, word_t); +void DSTimerWrite(int, word_t); //! \brief Reads a timer's counting value. -hword_t FeOS_TimerTick(int); +hword_t DSTimerTick(int); //! \brief Stops a timer. -static inline void FeOS_TimerStop(int timer) +static inline void DSTimerStop(int timer) { - FeOS_TimerWrite(timer, 0); + DSTimerWrite(timer, 0); } //! \brief Switches to console mode. This should be the last thing done before exiting a direct mode program. -void FeOS_ConsoleMode(); +void DSConsoleMode(); //! \brief Switches to direct mode. -void FeOS_DirectMode(); +void DSDirectMode(); //! \brief Returns the current operation mode. -int FeOS_GetMode(); +int DSGetMode(); //! \brief Internal data type not for public consumption. typedef struct @@ -450,10 +437,10 @@ typedef struct //! \brief Internal macro not for public consumption. #define FEOS_GET_SHIM ((const modeshim_t*)~0) //! \brief Internal function not for public consumption. -const modeshim_t* FeOS_ModeShim(const modeshim_t* pNewShim); +const modeshim_t* DSModeShim(const modeshim_t* pNewShim); -//! \brief Resets the video hardware to its default state after a FeOS_DirectMode() call. -void FeOS_VideoReset(); +//! \brief Resets the video hardware to its default state after a DSDirectMode() call. +void DSVideoReset(); //! \brief Copies words using the specified DMA channel. void dmaCopyWords(int, const void*, void*, word_t); diff --git a/sdk/include/feosdsspr.h b/sdk/include/feosdsspr.h index 5596e5b..d86a1f9 100644 --- a/sdk/include/feosdsspr.h +++ b/sdk/include/feosdsspr.h @@ -156,9 +156,9 @@ extern SpriteEntry* oamMain_mem; extern SpriteEntry* oamSub_mem; //! \cond -OamState* FeOS_GetMainOAM(); -OamState* FeOS_GetSubOAM(); -SpriteEntry* FeOS_GetOAMMemory(OamState*); +OamState* DSGetMainOAM(); +OamState* DSGetSubOAM(); +SpriteEntry* DSGetOAMMemory(OamState*); //! \endcond //! \brief Initializes the 2D sprite engine. diff --git a/sdk/include/feosmath.h b/sdk/include/feosmath.h index e868aa7..9e13aa4 100644 --- a/sdk/include/feosmath.h +++ b/sdk/include/feosmath.h @@ -34,21 +34,21 @@ int tanLerp(short); //!< Tangent function. Argument is in DS angle units. \retur short asinLerp(short); //!< Arcsine function. Argument is in 12-bit fixed point. \returns Angle in DS angle units. short acosLerp(short); //!< Arccosine function. Argument is in 12-bit fixed point. \returns Angle in DS angle units. -int FeOS_div3232(int, int); //!< Hardware-accelerated 32/32 integer division. -int FeOS_mod3232(int, int); //!< Hardware-accelerated 32/32 integer modulo. -int FeOS_div6432(long long, int); //!< Hardware-accelerated 64/32 integer division. -int FeOS_mod6432(long long, int); //!< Hardware-accelerated 64/32 integer modulo. -long long FeOS_div6464(long long, long long); //!< Hardware-accelerated 64/64 integer division. -long long FeOS_mod6464(long long, long long); //!< Hardware-accelerated 64/64 integer modulo. -int FeOS_sqrt32(int); //!< Hardware-accelerated 32-bit square root. -long long FeOS_sqrt64(long long); //!< \brief Hardware-accelerated 64-bit square root. +int KeDiv3232(int, int); //!< Hardware-accelerated 32/32 integer division. +int KeMod3232(int, int); //!< Hardware-accelerated 32/32 integer modulo. +int KeDiv6432(long long, int); //!< Hardware-accelerated 64/32 integer division. +int KeMod6432(long long, int); //!< Hardware-accelerated 64/32 integer modulo. +long long KeDiv6464(long long, long long); //!< Hardware-accelerated 64/64 integer division. +long long KeMod6464(long long, long long); //!< Hardware-accelerated 64/64 integer modulo. +int KeSqrt32(int); //!< Hardware-accelerated 32-bit square root. +long long KeSqrt64(long long); //!< \brief Hardware-accelerated 64-bit square root. // libnds compatibility functions //! \brief 12-bit fixed point division. static inline int divf32(int a, int b) { - return FeOS_div6432((long long)a << 12, b); + return KeDiv6432((long long)a << 12, b); } //! \brief 12-bit fixed point multiplication. @@ -61,15 +61,15 @@ static inline int mulf32(int a, int b) //! \brief 12-bit fixed point square root. static inline int sqrtf32(int a) { - return FeOS_sqrt64((long long)a << 12); + return KeSqrt64((long long)a << 12); } -#define div32 FeOS_div3232 //!< libnds compatibility alias. -#define mod32 FeOS_mod3232 //!< libnds compatibility alias. -#define div64 FeOS_div6432 //!< libnds compatibility alias. -#define mod64 FeOS_mod6432 //!< libnds compatibility alias. -#define sqrt32 FeOS_sqrt32 //!< libnds compatibility alias. -#define sqrt64 FeOS_sqrt64 //!< libnds compatibility alias. +#define div32 KeDiv3232 //!< libnds compatibility alias. +#define mod32 KeMod3232 //!< libnds compatibility alias. +#define div64 KeDiv6432 //!< libnds compatibility alias. +#define mod64 KeMod6432 //!< libnds compatibility alias. +#define sqrt32 KeSqrt32 //!< libnds compatibility alias. +#define sqrt64 KeSqrt64 //!< libnds compatibility alias. //! \brief 3D 12-bit fixed point vectorial product. static inline void crossf32(int* a, int* b, int* result) diff --git a/sdk/include/feosoldnames.h b/sdk/include/feosoldnames.h new file mode 100644 index 0000000..a775f1f --- /dev/null +++ b/sdk/include/feosoldnames.h @@ -0,0 +1,85 @@ +// +// FeOS Standard Library +// feosoldnames.h +// Old FeOS API names +// + +#pragma once + +typedef module_t instance_t; +typedef exidxinfo_t FeOS_GetExidxTbl_t; +typedef word_t keys_t; + +#define FeOS_GetVersion KeGetOSVersion +#define FeOS_GetSystemInfo KeGetSysInfo + +#define FeOS_GetInstance LdrGetSelf +#define FeOS_LoadModule LdrLoadModule +#define FeOS_FindSymbol LdrFindSymbol +#define FeOS_FreeModule LdrFreeModule +#define FeOS_LockModule LdrLockModule +#define FeOS_UnlockModule LdrUnlockModule + +#define FeOS_ModuleGetExtraSize LdrResGetSize +#define FeOS_ModuleExtraRead LdrResRead +#define FeOS_ModuleExtraSeek LdrResSeek +#define FeOS_ModuleExtraTell LdrResTell + +#define FeOS_GetModule LdrGetModule +#define FeOS_GetModuleName LdrGetModuleName +#define FeOS_EnumModules LdrEnumModules + +#define FeOS_StayResident LdrBeginResidency +#define FeOS_EndResident LdrEndResidency + +#define FeOS_Execute LdrExecuteArgv + +#define FeOS_GetModuleExidxTbl LdrGetExidxTbl +#define FeOS_ModuleFromAddress LdrResolveAddr + +#define FeOS_LoadARM7 DSLoadARM7 +#define FeOS_FreeARM7 DSFreeARM7 + +#define FeOS_DrainWriteBuffer DC_DrainWriteBuffer +#define FeOS_WaitForMemAddr KeWaitForMemAddr + +// WILL BE REMOVED +#define FeOS_SetAutoUpdate DSSetAutoUpdate +#define FeOS_GetAutoUpdate DSGetAutoUpdate +// END REMOVE + +#define FeOS_SetSuspendMode DSSetSuspendMode +#define FeOS_GetSuspendMode DSGetSuspendMode + +#define FeOS_GetDiskStats64 KeGetDiskStats +#define FeOS_GetMemStats KeGetMemStats + +#define FeOS_GetTickCount KeGetTickCount + +#define FeOS_div3232 KeDiv3232 +#define FeOS_mod3232 KeMod3232 +#define FeOS_div6432 KeDiv6432 +#define FeOS_mod6432 KeMod6432 +#define FeOS_div6464 KeDiv6464 +#define FeOS_mod6464 KeMod6464 +#define FeOS_sqrt32 KeSqrt32 +#define FeOS_sqrt64 KeSqrt64 + +#define FeOS_CheckPendingIRQs DSProcessIRQs +#define FeOS_WaitForIRQ DSWaitForIRQ +#define FeOS_NextIRQ DSWaitForNextIRQ + +#define FeOS_TimerWrite DSTimerWrite +#define FeOS_TimerTick DSTimerTick +#define FeOS_TimerStop DSTimerStop + +#define FeOS_ConsoleMode DSConsoleMode +#define FeOS_DirectMode DSDirectMode +#define FeOS_GetMode DSGetMode + +#define FeOS_VideoReset DSVideoReset + +#define FeOS_SetStdin IoSetStdin +#define FeOS_SetStdout IoSetStdout +#define FeOS_SetStderr IoSetStderr +#define FeOS_OpenStream IoOpenStream diff --git a/sdk/include/feosuser.h b/sdk/include/feosuser.h index d01cbb0..210c439 100644 --- a/sdk/include/feosuser.h +++ b/sdk/include/feosuser.h @@ -15,16 +15,16 @@ * @{ */ -//! \brief Get the instance handle of the caller's module -#define FeOS_GetInstance() FeOS_hInstance +//! \brief Get the handle of the caller's module +#define LdrGetSelf() ((module_t) __modulebase) -//! \brief Exception index table datatype +//! \brief Exception index table information datatype //! \headerfile feos.h typedef struct { void* table; int nentries; -} FeOS_GetExidxTbl_t; +} exidxinfo_t; //! \brief Execution status handle typedef void* execstat_t; @@ -34,50 +34,50 @@ typedef void (*FifoValue32HandlerFunc)(word_t, void*); //!< FIFO 32-bit value ha typedef void (*FifoDatamsgHandlerFunc)(int, void*); //!< FIFO datamsg handler callback //! \brief Loads a module of the specified name. Pathless extensionless module names are recommended. -instance_t FeOS_LoadModule(const char*); +module_t LdrLoadModule(const char*); //! \brief Finds a symbol in a module. -void* FeOS_FindSymbol(instance_t, const char*); +void* LdrFindSymbol(module_t, const char*); //! \brief Frees a module. -void FeOS_FreeModule(instance_t); +void LdrFreeModule(module_t); //! \brief Increases a module's reference count. -void FeOS_LockModule(instance_t); +void LdrLockModule(module_t); //! \brief Decreases a module's reference count. -void FeOS_UnlockModule(instance_t); +void LdrUnlockModule(module_t); //! \brief (Low-level) Gets the size of any extra data appended to the module file. -int FeOS_ModuleGetExtraSize(instance_t); +int LdrResGetSize(module_t); //! \brief (Low-level) Reads data appended to the module file. -int FeOS_ModuleExtraRead(instance_t, void*, word_t); +int LdrResRead(module_t, void*, word_t); //! \brief (Low-level) Changes the reading pointer in the module file extra data. -int FeOS_ModuleExtraSeek(instance_t, int, int); +int LdrResSeek(module_t, int, int); //! \brief (Low-level) Gets the position of the reading pointer of the module file extra data. -int FeOS_ModuleExtraTell(instance_t); +int LdrResTell(module_t); //! \brief Return value of ModuleEnumCallback enum { ENUM_BREAK = 0, ENUM_CONTINUE = 1 }; //! \brief Module enumeration callback -typedef int (* ModuleEnumCallback)(instance_t, const char*, word_t, void*); +typedef int (* ModuleEnumCallback)(module_t, const char*, word_t, void*); //! \brief Gets the handle of a module by name. \returns Null pointer if the module is not loaded -instance_t FeOS_GetModule(const char*); +module_t LdrGetModule(const char*); //! \brief Gets the name of a module. -const char* FeOS_GetModuleName(instance_t); +const char* LdrGetModuleName(module_t); //! \brief Enumerates all modules. -void FeOS_EnumModules(ModuleEnumCallback, void*); +void LdrEnumModules(ModuleEnumCallback, void*); //! \brief Increases the reference count of the callers' module. -#define FeOS_StayResident() FeOS_LockModule(FeOS_hInstance) +#define LdrBeginResidency() LdrLockModule(LdrGetSelf()) //! \brief Decreases the reference count of the callers' module. -#define FeOS_EndStayResident() FeOS_UnlockModule(FeOS_hInstance) +#define LdrEndResidency() LdrUnlockModule(LdrGetSelf()) -execstat_t FeOS_ExecStatusCreate(); //!< (Low-level) Creates a new execution status object. -void FeOS_ExecStatusAddRef(execstat_t); //!< (Low-level) Increases the reference count of an execstat object. -void FeOS_ExecStatusRelease(execstat_t); //!< (Low-level) Decreases the reference count of an execstat object. -void FeOS_SetCurExecStatus(execstat_t); //!< (Low-level) Sets the current execution status. -execstat_t FeOS_GetCurExecStatus(); //!< (Low-level) Gets the current execution status. +execstat_t KeExecStatusCreate(); //!< (Low-level) Creates a new execution status object. +void KeExecStatusAddRef(execstat_t); //!< (Low-level) Increases the reference count of an execstat object. +void KeExecStatusRelease(execstat_t); //!< (Low-level) Decreases the reference count of an execstat object. +void KeSetCurExecStatus(execstat_t); //!< (Low-level) Sets the current execution status. +execstat_t KeGetCurExecStatus(); //!< (Low-level) Gets the current execution status. //! \brief Executes the specified argc and argv. -int FeOS_Execute(int, const char*[]); +int LdrExecuteArgv(int, const char*[]); //! \brief Flushes a range of memory in the data cache. void DC_FlushRange(const void*, word_t); @@ -89,14 +89,14 @@ void IC_InvalidateRange(const void*, word_t); void IC_InvalidateAll(); //! \brief Extracts the exception index table of a module. The number of entries is passed back through the `int*` parameter. -void* FeOS_GetModuleExidxTbl(instance_t, int*); +void* LdrGetExidxTbl(module_t, int*); //! \brief Gets the module that a certain address belongs to. -instance_t FeOS_ModuleFromAddress(void*); +module_t LdrResolveAddr(void*); //! \brief Loads an ARM7-side module. Full path should be supplied. A FIFO channel number is returned through the `int*` parameter. -instance_t FeOS_LoadARM7(const char*, int*); +module_t DSLoadARM7(const char*, int*); //! \brief Unloads an ARM7-side module. The FIFO channel number must also be passed. -void FeOS_FreeARM7(instance_t, int); +void DSFreeARM7(module_t, int); //! \brief Sends a main RAM address to the ARM7 using a specified FIFO channel. bool fifoSendAddress(int, void*); @@ -130,9 +130,9 @@ word_t fifoGetRetValue32(int); // Misc functions //! \brief Drains the CPU's writte buffer. -void FeOS_DrainWriteBuffer(); +void DC_DrainWriteBuffer(); //! \brief Waits for a certain memory addresses to hold a certain value. -void FeOS_WaitForMemAddr(volatile byte_t*, byte_t); +void KeWaitForMemAddr(volatile byte_t*, byte_t); //! \brief Auto-update modes. enum { AUTOUPD_OAM = 1, AUTOUPD_BG, AUTOUPD_KEYS }; @@ -140,16 +140,16 @@ enum { AUTOUPD_OAM = 1, AUTOUPD_BG, AUTOUPD_KEYS }; //! //! Auto-updates is a mechanism that automatically issues calls to scanKeys(), bgUpdate() and oamUpdate() //! at each VBlank. They are always on in console mode, so this function only has effect in direct mode. -void FeOS_SetAutoUpdate(int which, bool enable); +void DSSetAutoUpdate(int which, bool enable); //! \brief Retrieves whether a certain auto-update mode is on. -bool FeOS_GetAutoUpdate(int which); +bool DSGetAutoUpdate(int which); //! \brief Suspend modes. enum { SuspendMode_Get = -1, SuspendMode_Disable = 0, SuspendMode_Normal, SuspendMode_Headphones }; //! \brief Changes FeOS' behaviour when the lid is closed. -int FeOS_SetSuspendMode(int mode); +int DSSetSuspendMode(int mode); //! \brief Retrieves the current lid closing behaviour. -#define FeOS_GetSuspendMode() FeOS_SetSuspendMode(SuspendMode_Get) +#define DSGetSuspendMode() DSSetSuspendMode(SuspendMode_Get) //! \headerfile feos.h typedef struct @@ -163,12 +163,10 @@ typedef struct dword_t total, free, used; } usagestats64_t; -//! \deprecated \brief Returns disk space stats. -bool FeOS_GetDiskStats(usagestats_t*) FEOS_DEPRECATED; //! \brief Returns disk space stats. -bool FeOS_GetDiskStats64(usagestats64_t*); +bool KeGetDiskStats(usagestats64_t*); //! \brief Returns RAM stats. -void FeOS_GetMemStats(usagestats_t*); +void KeGetMemStats(usagestats_t*); //! \cond #define memBarrier() asm volatile("":::"memory") @@ -176,6 +174,6 @@ void FeOS_GetMemStats(usagestats_t*); //! \endcond //! \brief Returns the number of 59.8261 Hz (VBlank) cycles passed since FeOS was booted. -int FeOS_GetTickCount(); +int KeGetTickCount(); /** @} */ diff --git a/sdk/include/feosver.h b/sdk/include/feosver.h index a3bdf0c..1353605 100644 --- a/sdk/include/feosver.h +++ b/sdk/include/feosver.h @@ -74,33 +74,33 @@ typedef struct } systeminfo_t; //! \brief Gets the currently running FeOS version -int FeOS_GetVersion(); +int KeGetOSVersion(); //! \brief Gets information about the system -const systeminfo_t* FeOS_GetSystemInfo(); +const systeminfo_t* KeGetSysInfo(); //! \brief Determines whether the application is running under the specified FeOS version or later -static inline int FeOS_VersionAtLeast(int minorVer, int majorVer) +static inline int KeOSVersionAtLeast(int minorVer, int majorVer) { - return FeOS_GetVersion() >= FEOS_VPACK_MAKE(minorVer, majorVer); + return KeGetOSVersion() >= FEOS_VPACK_MAKE(minorVer, majorVer); } //! \brief Determines whether the application is running up to the specified FeOS version -static inline int FeOS_VersionUpTo(int minorVer, int majorVer) +static inline int KeOSVersionUpTo(int minorVer, int majorVer) { - return FeOS_GetVersion() <= FEOS_VPACK_MAKE(minorVer, majorVer); + return KeGetOSVersion() <= FEOS_VPACK_MAKE(minorVer, majorVer); } //! \brief Determines whether the application is running under a FeOS version greater than the specified one -static inline int FeOS_VersionLaterThan(int minorVer, int majorVer) +static inline int KeOSVersionLaterThan(int minorVer, int majorVer) { - return FeOS_GetVersion() > FEOS_VPACK_MAKE(minorVer, majorVer); + return KeGetOSVersion() > FEOS_VPACK_MAKE(minorVer, majorVer); } //! \brief Determines whether the application is running under a FeOS version earlier than the specified one -static inline int FeOS_VersionEarlierThan(int minorVer, int majorVer) +static inline int KeOSVersionEarlierThan(int minorVer, int majorVer) { - return FeOS_GetVersion() < FEOS_VPACK_MAKE(minorVer, majorVer); + return KeGetOSVersion() < FEOS_VPACK_MAKE(minorVer, majorVer); } #endif diff --git a/sdk/include/stddef.h b/sdk/include/stddef.h index 7d19d0a..3345de1 100644 --- a/sdk/include/stddef.h +++ b/sdk/include/stddef.h @@ -5,7 +5,7 @@ // #pragma once -#include +#include /** @file stddef.h * \brief Standard C definitions diff --git a/sdk/include/stdio.h b/sdk/include/stdio.h index 734a63e..844d060 100644 --- a/sdk/include/stdio.h +++ b/sdk/include/stdio.h @@ -50,17 +50,17 @@ typedef struct off_t (*Seek) (void*, off_t, int); //!< Called when the stream is sought. } stream_t; -FILE* FeOS_GetStdin(); //!< Gets the standard input stream. -FILE* FeOS_GetStdout(); //!< Gets the standard output stream. -FILE* FeOS_GetStderr(); //!< Gets the standard error stream. -FILE* FeOS_SetStdin(FILE*); //!< Hooks the standard input stream. Returns the previous hook. -FILE* FeOS_SetStdout(FILE*); //!< Hooks the standard output stream. Returns the previous hook. -FILE* FeOS_SetStderr(FILE*); //!< Hooks the standard error stream. Returns the previous hook. -FILE* FeOS_OpenStream(const stream_t*, void*); //!< Opens a custom data stream with the specified callbacks and user data. - -#define stdin FeOS_GetStdin() //!< C stdin object. -#define stdout FeOS_GetStdout() //!< C stdout object. -#define stderr FeOS_GetStderr() //!< C stderr object. +FILE* IoGetStdin(); //!< Gets the standard input stream. +FILE* IoGetStdout(); //!< Gets the standard output stream. +FILE* IoGetStderr(); //!< Gets the standard error stream. +FILE* IoSetStdin(FILE*); //!< Hooks the standard input stream. Returns the previous hook. +FILE* IoSetStdout(FILE*); //!< Hooks the standard output stream. Returns the previous hook. +FILE* IoSetStderr(FILE*); //!< Hooks the standard error stream. Returns the previous hook. +FILE* IoOpenStream(const stream_t*, void*); //!< Opens a custom data stream with the specified callbacks and user data. + +#define stdin IoGetStdin() //!< C stdin object. +#define stdout IoGetStdout() //!< C stdout object. +#define stderr IoGetStderr() //!< C stderr object. #define SEEK_SET 0 //!< Specifies seeking from the beginning of the stream. #define SEEK_CUR 1 //!< Specifies seeking from the current position. diff --git a/sdk/libfeos.mk b/sdk/libfeos.mk index 9750ea4..7d5ea68 100644 --- a/sdk/libfeos.mk +++ b/sdk/libfeos.mk @@ -32,10 +32,7 @@ BUILD := build_dbg CONF_DEBUG := 1 EXTRASRC := source/debug endif -SOURCES := source source/stdio source/support \ - source/FEOSBASE source/FEOSSTDIO source/FEOSPOSIXEMU source/FEOSMATH \ - source/FEOSDSAPI source/FEOSDSSPR source/FEOSDSBG source/FEOSARM7 \ - $(EXTRASRC) +SOURCES := source source/stdio source/support source/FEOSKRNL source/FEOSDSHW $(EXTRASRC) DATA := data INCLUDES := include diff --git a/sdk/source/FEOSARM7/Makefile b/sdk/source/FEOSARM7/Makefile deleted file mode 100644 index 7393eda..0000000 --- a/sdk/source/FEOSARM7/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -.SUFFIXES: - -MODULE := $(shell basename $(CURDIR)) - -FUNCS := \ -FeOS_LoadARM7 \ -FeOS_FreeARM7 \ -fifoSendAddress \ -fifoSendValue32 \ -fifoSendDatamsg \ -fifoCheckAddress \ -fifoCheckValue32 \ -fifoCheckDatamsg \ -fifoCheckDatamsgLength \ -fifoGetAddress \ -fifoGetValue32 \ -fifoGetDatamsg \ -fifoSetDatamsgHandler \ -fifoSetValue32Handler \ -fifoSetAddressHandler \ -fifoGetRetValue32 - -SFILES := $(addsuffix .s, $(FUNCS)) - -.PHONY: all clean - -all: $(SFILES) - -%.s: - @echo $@ - @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ - @printf ".global __imp_%b\n" $(@:.s=) >> $@ - @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ - @printf ".global %b\n" $(@:.s=) >> $@ - @printf ".hidden %b\n" $(@:.s=) >> $@ - @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ - @printf "%b:\n" $(@:.s=) >> $@ - @printf "\tldr pc, [pc, #-4]\n" >> $@ - @printf "__imp_%b:\n" $(@:.s=) >> $@ - @printf "\t.word 0" >> $@ - -clean: - @rm -fr $(SFILES) diff --git a/sdk/source/FEOSDSAPI/Makefile b/sdk/source/FEOSDSAPI/Makefile deleted file mode 100644 index 2f49139..0000000 --- a/sdk/source/FEOSDSAPI/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -.SUFFIXES: - -MODULE := $(shell basename $(CURDIR)) - -FUNCS := \ -keysDown \ -keysHeld \ -keysUp \ -keysDownRepeat \ -keysSetRepeat \ -scanKeys \ -FeOS_GetStylusPos \ -irqSet \ -FeOS_CheckPendingIRQs \ -FeOS_WaitForIRQ \ -FeOS_SetIRQWaitFunc \ -FeOS_NextIRQ \ -irqDisable \ -irqEnable \ -FeOS_ConsoleMode \ -FeOS_DirectMode \ -FeOS_TimerWrite \ -FeOS_TimerTick \ -FeOS_GetMode \ -FeOS_ModeShim \ -FeOS_VideoReset \ -dmaCopyWords \ -dmaCopyHalfWords \ -dmaFillWords \ -dmaFillHalfWords \ -memUncached \ -memCached \ -vramSetPrimaryBanks \ -vramSetBanks_EFG \ -vramRestorePrimaryBanks \ -vramRestoreBanks_EFG \ -vramSetBankA \ -vramSetBankB \ -vramSetBankC \ -vramSetBankD \ -vramSetBankE \ -vramSetBankF \ -vramSetBankG \ -vramSetBankH \ -vramSetBankI \ -videoSetMode \ -videoSetModeSub \ -videoGetMode \ -videoGetModeSub \ -video3DEnabled \ -setBrightness \ -lcdSwap \ -lcdMainOnTop \ -lcdMainOnBottom \ -powerOn \ -powerOff - -SFILES := $(addsuffix .s, $(FUNCS)) - -.PHONY: all clean - -all: $(SFILES) - -%.s: - @echo $@ - @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ - @printf ".global __imp_%b\n" $(@:.s=) >> $@ - @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ - @printf ".global %b\n" $(@:.s=) >> $@ - @printf ".hidden %b\n" $(@:.s=) >> $@ - @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ - @printf "%b:\n" $(@:.s=) >> $@ - @printf "\tldr pc, [pc, #-4]\n" >> $@ - @printf "__imp_%b:\n" $(@:.s=) >> $@ - @printf "\t.word 0" >> $@ - -clean: - @rm -fr $(SFILES) diff --git a/sdk/source/FEOSDSBG/Makefile b/sdk/source/FEOSDSBG/Makefile deleted file mode 100644 index e6d4f64..0000000 --- a/sdk/source/FEOSDSBG/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -.SUFFIXES: - -MODULE := $(shell basename $(CURDIR)) - -FUNCS := \ -bgSetRotate \ -bgRotate \ -bgSet \ -bgSetRotateScale \ -bgSetScale \ -bgInit \ -bgInitSub \ -bgUpdate \ -bgSetControlBits \ -bgClearControlBits \ -bgSetPriority \ -bgSetMapBase \ -bgSetTileBase \ -bgSetScrollf \ -bgMosaicEnable \ -bgMosaicDisable \ -bgSetMosaic \ -bgSetMosaicSub \ -bgGetMapPtr \ -bgGetGfxPtr \ -bgGetPriority \ -bgGetMapBase \ -bgGetTileBase \ -bgScrollf \ -bgShow \ -bgHide \ -bgSetCenterf \ -bgSetAffineMatrixScroll \ -bgExtPaletteEnable \ -bgExtPaletteEnableSub \ -bgExtPaletteDisable \ -bgExtPaletteDisableSub - -SFILES := $(addsuffix .s, $(FUNCS)) - -.PHONY: all clean - -all: $(SFILES) - -%.s: - @echo $@ - @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ - @printf ".global __imp_%b\n" $(@:.s=) >> $@ - @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ - @printf ".global %b\n" $(@:.s=) >> $@ - @printf ".hidden %b\n" $(@:.s=) >> $@ - @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ - @printf "%b:\n" $(@:.s=) >> $@ - @printf "\tldr pc, [pc, #-4]\n" >> $@ - @printf "__imp_%b:\n" $(@:.s=) >> $@ - @printf "\t.word 0" >> $@ - -clean: - @rm -fr $(SFILES) diff --git a/sdk/source/FEOSDSHW/Makefile b/sdk/source/FEOSDSHW/Makefile new file mode 100644 index 0000000..8147c49 --- /dev/null +++ b/sdk/source/FEOSDSHW/Makefile @@ -0,0 +1,145 @@ +.SUFFIXES: + +MODULE := $(shell basename $(CURDIR)) + +FUNCS := \ +DSConsoleMode \ +DSDirectMode \ +DSFreeARM7 \ +DSGetMainOAM \ +DSGetMode \ +DSGetOAMMemory \ +DSGetSubOAM \ +DSLoadARM7 \ +DSModeShim \ +DSProcessIRQs \ +DSSetIRQWaitFunc \ +DSSetSuspendMode \ +DSTimerTick \ +DSTimerWrite \ +DSVideoReset \ +DSWaitForIRQ \ +DSWaitForNextIRQ \ +bgClearControlBits \ +bgExtPaletteDisable \ +bgExtPaletteDisableSub \ +bgExtPaletteEnable \ +bgExtPaletteEnableSub \ +bgGetGfxPtr \ +bgGetMapBase \ +bgGetMapPtr \ +bgGetPriority \ +bgGetTileBase \ +bgHide \ +bgInit \ +bgInitSub \ +bgMosaicDisable \ +bgMosaicEnable \ +bgRotate \ +bgScrollf \ +bgSet \ +bgSetAffineMatrixScroll \ +bgSetCenterf \ +bgSetControlBits \ +bgSetMapBase \ +bgSetMosaic \ +bgSetMosaicSub \ +bgSetPriority \ +bgSetRotate \ +bgSetRotateScale \ +bgSetScale \ +bgSetScrollf \ +bgSetTileBase \ +bgShow \ +bgUpdate \ +dmaCopyHalfWords \ +dmaCopyWords \ +dmaFillHalfWords \ +dmaFillWords \ +fifoCheckAddress \ +fifoCheckDatamsg \ +fifoCheckDatamsgLength \ +fifoCheckValue32 \ +fifoGetAddress \ +fifoGetDatamsg \ +fifoGetRetValue32 \ +fifoGetValue32 \ +fifoSendAddress \ +fifoSendDatamsg \ +fifoSendValue32 \ +fifoSetAddressHandler \ +fifoSetDatamsgHandler \ +fifoSetValue32Handler \ +irqDisable \ +irqEnable \ +irqSet \ +keysDown \ +keysDownRepeat \ +keysHeld \ +keysSetRepeat \ +keysUp \ +lcdMainOnBottom \ +lcdMainOnTop \ +lcdSwap \ +memCached \ +memUncached \ +oamAffineTransformation \ +oamAllocateGfx \ +oamClear \ +oamClearSprite \ +oamDisable \ +oamEnable \ +oamFreeGfx \ +oamGetGfxPtr \ +oamGfxPtrToOffset \ +oamInit \ +oamRotateScale \ +oamSet \ +oamSetMosaic \ +oamSetMosaicSub \ +oamUpdate \ +powerOff \ +powerOn \ +scanKeys \ +setBrightness \ +touchRead \ +video3DEnabled \ +videoGetMode \ +videoGetModeSub \ +videoSetMode \ +videoSetModeSub \ +vramRestoreBanks_EFG \ +vramRestorePrimaryBanks \ +vramSetBankA \ +vramSetBankB \ +vramSetBankC \ +vramSetBankD \ +vramSetBankE \ +vramSetBankF \ +vramSetBankG \ +vramSetBankH \ +vramSetBankI \ +vramSetBanks_EFG \ +vramSetPrimaryBanks + +SFILES := $(addsuffix .s, $(FUNCS)) + +.PHONY: all clean + +all: $(SFILES) + +%.s: + @echo $@ + @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ + @printf ".global __imp_%b\n" $(@:.s=) >> $@ + @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ + @printf ".global %b\n" $(@:.s=) >> $@ + @printf ".hidden %b\n" $(@:.s=) >> $@ + @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ + @printf "%b:\n" $(@:.s=) >> $@ + @printf "\tldr pc, [pc, #-4]\n" >> $@ + @printf "__imp_%b:\n" $(@:.s=) >> $@ + @printf "\t.word 0" >> $@ + +clean: + @rm -fr $(SFILES) diff --git a/sdk/source/FEOSDSSPR/Makefile b/sdk/source/FEOSDSSPR/Makefile deleted file mode 100644 index 1f507de..0000000 --- a/sdk/source/FEOSDSSPR/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -.SUFFIXES: - -MODULE := $(shell basename $(CURDIR)) - -FUNCS := \ -FeOS_GetMainOAM \ -FeOS_GetSubOAM \ -FeOS_GetOAMMemory \ -oamInit \ -oamUpdate \ -oamDisable \ -oamEnable \ -oamGetGfxPtr \ -oamAllocateGfx \ -oamFreeGfx \ -oamSetMosaic \ -oamSetMosaicSub \ -oamSet \ -oamClear \ -oamClearSprite \ -oamRotateScale \ -oamAffineTransformation \ -oamGfxPtrToOffset - -SFILES := $(addsuffix .s, $(FUNCS)) - -.PHONY: all clean - -all: $(SFILES) - -%.s: - @echo $@ - @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ - @printf ".global __imp_%b\n" $(@:.s=) >> $@ - @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ - @printf ".global %b\n" $(@:.s=) >> $@ - @printf ".hidden %b\n" $(@:.s=) >> $@ - @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ - @printf "%b:\n" $(@:.s=) >> $@ - @printf "\tldr pc, [pc, #-4]\n" >> $@ - @printf "__imp_%b:\n" $(@:.s=) >> $@ - @printf "\t.word 0" >> $@ - -clean: - @rm -fr $(SFILES) diff --git a/sdk/source/FEOSBASE/Makefile b/sdk/source/FEOSKRNL/Makefile similarity index 52% rename from sdk/source/FEOSBASE/Makefile rename to sdk/source/FEOSKRNL/Makefile index 5b613a2..4f92848 100644 --- a/sdk/source/FEOSBASE/Makefile +++ b/sdk/source/FEOSKRNL/Makefile @@ -3,110 +3,171 @@ MODULE := $(shell basename $(CURDIR)) FUNCS := \ -FeOS_LoadModule \ -FeOS_FindSymbol \ -FeOS_FreeModule \ -FeOS_LockModule \ -FeOS_UnlockModule \ -FeOS_ModuleGetExtraSize \ -FeOS_ModuleExtraRead \ -FeOS_ModuleExtraSeek \ -FeOS_ModuleExtraTell \ -FeOS_EnumModules \ -FeOS_GetModule \ -FeOS_GetModuleName \ -FeOS_Execute \ -DC_FlushRange \ +DC_DrainWriteBuffer \ DC_FlushAll \ -IC_InvalidateRange \ +DC_FlushRange \ +DSGetAutoUpdate \ +DSSetAutoUpdate \ IC_InvalidateAll \ -FeOS_DrainWriteBuffer \ -FeOS_WaitForMemAddr \ -FeOS_SetSuspendMode \ -FeOS_PushExitFunc \ -FeOS_PopExitFunc \ -FeOS_GetErrnoPtr \ -FeOS_GetModuleExidxTbl \ -FeOS_ModuleFromAddress \ -FeOS_ExecStatusCreate \ -FeOS_ExecStatusAddRef \ -FeOS_ExecStatusRelease \ -FeOS_SetCurExecStatus \ -FeOS_GetCurExecStatus \ -FeOS_SetAutoUpdate \ -FeOS_GetAutoUpdate \ -FeOS_GetDiskStats \ -FeOS_GetDiskStats64 \ -FeOS_GetMemStats \ -FeOS_GetTickCount \ -FeOS_GetVersion \ -FeOS_GetSystemInfo \ +IC_InvalidateRange \ +IoGetStderr \ +IoGetStdin \ +IoGetStdout \ +IoOpenStream \ +IoSetStderr \ +IoSetStdin \ +IoSetStdout \ +KeDiv3232 \ +KeDiv6432 \ +KeDiv6464 \ +KeExecStatusAddRef \ +KeExecStatusCreate \ +KeExecStatusRelease \ +KeGetCurExecStatus \ +KeGetDiskStats \ +KeGetErrnoPtr \ +KeGetMemStats \ +KeGetOSVersion \ +KeGetSysInfo \ +KeGetTickCount \ +KeMod3232 \ +KeMod6432 \ +KeMod6464 \ +KeSetCurExecStatus \ +KeSetExcptHandler \ +KeSqrt32 \ +KeSqrt64 \ +KeWaitForMemAddr \ +LdrEnumModules \ +LdrExecuteArgv \ +LdrFindSymbol \ +LdrFreeModule \ +LdrGetExidxTbl \ +LdrGetModule \ +LdrGetModuleName \ +LdrLoadModule \ +LdrLockModule \ +LdrResGetSize \ +LdrResolveAddr \ +LdrResRead \ +LdrResSeek \ +LdrResTell \ +LdrUnlockModule \ __aeabi_idiv \ __aeabi_idivmod \ +__aeabi_ldivmod \ __aeabi_uidiv \ __aeabi_uidivmod \ -__aeabi_ldivmod \ __aeabi_uldivmod \ -setjmp \ -longjmp \ +abs \ +acosLerp \ +asctime \ +asinLerp \ atoi \ -strtol \ -strtoul \ -rand \ -srand \ -malloc \ -memalign \ +bsearch \ calloc \ -free \ -realloc \ +chdir \ +clearerr \ +close \ +closedir \ +cosLerp \ +ctime \ +div \ exit \ -bsearch \ +fclose \ +fdopen \ +feof \ +ferror \ +fflush \ +fgetc \ +fgets \ +fileno \ +fopen \ +fputc \ +fputs \ +fread \ +free \ +freopen \ +fseek \ +fstat \ +ftell \ +ftruncate \ +fwrite \ +getcwd \ +getdelim \ +gmtime \ +isalnum \ +isalpha \ +iscntrl \ +isdigit \ +isgraph \ +islower \ +isprint \ +ispunct \ +isspace \ +isupper \ +isxdigit \ +localtime \ +longjmp \ +lseek \ +malloc \ +memalign \ +memchr \ +memcmp \ +memcpy \ +memmove \ +memset \ +mkdir \ +mktime \ +open \ +opendir \ qsort \ -abs \ -div \ -system \ -strlen \ -strcpy \ +rand \ +read \ +readdir \ +realloc \ +remove \ +rename \ +rewinddir \ +seekdir \ +setjmp \ +setvbuf \ +sinLerp \ +srand \ +stat \ strcat \ +strchr \ strcmp \ +strcpy \ +strcspn \ +strerror \ +strftime \ stricmp \ -strncpy \ +strlen \ strncat \ strncmp \ +strncpy \ strnicmp \ -memcpy \ -memmove \ -memset \ -memcmp \ -memchr \ -strchr \ -strcspn \ strpbrk \ strrchr \ strspn \ strstr \ strtok \ -strerror \ -isalnum \ -isalpha \ -iscntrl \ -isdigit \ -isgraph \ -islower \ -isprint \ -ispunct \ -isspace \ -isupper \ -isxdigit \ +strtol \ +strtoul \ +system \ +tanLerp \ +telldir \ +time \ tolower \ toupper \ -mktime \ -time \ -asctime \ -ctime \ -gmtime \ -localtime \ -strftime +ungetc \ +vfprintf \ +vfscanf \ +vsnprintf \ +vsprintf \ +vsscanf \ +write SFILES := $(addsuffix .s, $(FUNCS)) diff --git a/sdk/source/FEOSMATH/Makefile b/sdk/source/FEOSMATH/Makefile deleted file mode 100644 index c7a4087..0000000 --- a/sdk/source/FEOSMATH/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -.SUFFIXES: - -MODULE := $(shell basename $(CURDIR)) - -FUNCS := \ -sinLerp \ -cosLerp \ -tanLerp \ -asinLerp \ -acosLerp \ -FeOS_div3232 \ -FeOS_mod3232 \ -FeOS_div6432 \ -FeOS_mod6432 \ -FeOS_div6464 \ -FeOS_mod6464 \ -FeOS_sqrt32 \ -FeOS_sqrt64 - -SFILES := $(addsuffix .s, $(FUNCS)) - -.PHONY: all clean - -all: $(SFILES) - -%.s: - @echo $@ - @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ - @printf ".global __imp_%b\n" $(@:.s=) >> $@ - @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ - @printf ".global %b\n" $(@:.s=) >> $@ - @printf ".hidden %b\n" $(@:.s=) >> $@ - @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ - @printf "%b:\n" $(@:.s=) >> $@ - @printf "\tldr pc, [pc, #-4]\n" >> $@ - @printf "__imp_%b:\n" $(@:.s=) >> $@ - @printf "\t.word 0" >> $@ - -clean: - @rm -fr $(SFILES) diff --git a/sdk/source/FEOSPOSIXEMU/Makefile b/sdk/source/FEOSPOSIXEMU/Makefile deleted file mode 100644 index 427585c..0000000 --- a/sdk/source/FEOSPOSIXEMU/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -.SUFFIXES: - -MODULE := $(shell basename $(CURDIR)) - -FUNCS := \ -opendir \ -closedir \ -readdir \ -rewinddir \ -seekdir \ -telldir \ -mkdir \ -chdir \ -getcwd \ -stat \ -fstat \ -fileno \ -ftruncate \ -open \ -close \ -read \ -write \ -lseek \ -fdopen - -SFILES := $(addsuffix .s, $(FUNCS)) - -.PHONY: all clean - -all: $(SFILES) - -%.s: - @echo $@ - @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ - @printf ".global __imp_%b\n" $(@:.s=) >> $@ - @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ - @printf ".global %b\n" $(@:.s=) >> $@ - @printf ".hidden %b\n" $(@:.s=) >> $@ - @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ - @printf "%b:\n" $(@:.s=) >> $@ - @printf "\tldr pc, [pc, #-4]\n" >> $@ - @printf "__imp_%b:\n" $(@:.s=) >> $@ - @printf "\t.word 0" >> $@ - -clean: - @rm -fr $(SFILES) diff --git a/sdk/source/FEOSSTDIO/Makefile b/sdk/source/FEOSSTDIO/Makefile deleted file mode 100644 index e2a05d7..0000000 --- a/sdk/source/FEOSSTDIO/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -.SUFFIXES: - -MODULE := $(shell basename $(CURDIR)) - -FUNCS := \ -FeOS_GetStdin \ -FeOS_GetStdout \ -FeOS_GetStderr \ -FeOS_SetStdin \ -FeOS_SetStdout \ -FeOS_SetStderr \ -FeOS_OpenStream \ -fopen \ -freopen \ -fclose \ -fwrite \ -fread \ -feof \ -fseek \ -ftell \ -fflush \ -ferror \ -clearerr \ -setvbuf \ -vfprintf \ -vsprintf \ -vsnprintf \ -vfscanf \ -vsscanf \ -fgetc \ -fputc \ -fgets \ -fputs \ -ungetc \ -remove \ -rename \ -getdelim - -SFILES := $(addsuffix .s, $(FUNCS)) - -.PHONY: all clean - -all: $(SFILES) - -%.s: - @echo $@ - @printf ".section .imp.%b, \"ax\", %%progbits\n" $(MODULE) > $@ - @printf ".global __imp_%b\n" $(@:.s=) >> $@ - @printf ".hidden __imp_%b\n" $(@:.s=) >> $@ - @printf ".global %b\n" $(@:.s=) >> $@ - @printf ".hidden %b\n" $(@:.s=) >> $@ - @printf ".type %b STT_FUNC\n" $(@:.s=) >> $@ - @printf "%b:\n" $(@:.s=) >> $@ - @printf "\tldr pc, [pc, #-4]\n" >> $@ - @printf "__imp_%b:\n" $(@:.s=) >> $@ - @printf "\t.word 0" >> $@ - -clean: - @rm -fr $(SFILES) diff --git a/sdk/source/abort.c b/sdk/source/abort.c index 6d49b3c..8ca44e3 100644 --- a/sdk/source/abort.c +++ b/sdk/source/abort.c @@ -13,11 +13,11 @@ void abort() #ifdef DEBUG // Dynamically load FeOS_Backtrace in order to avoid creating // a dependence on feoscxx - instance_t hCxxLib = FeOS_GetModule("feoscxx"); + module_t hCxxLib = LdrGetModule("feoscxx"); if (hCxxLib) { typedef void (* backtraceFuncType)(BacktraceCallback callback, void* user_data); - backtraceFuncType backtraceFunc = (backtraceFuncType) FeOS_FindSymbol(hCxxLib, "FeOS_Backtrace"); + backtraceFuncType backtraceFunc = (backtraceFuncType) LdrFindSymbol(hCxxLib, "FeOS_Backtrace"); if (backtraceFunc) { fprintf(stderr, "from:\n"); @@ -32,11 +32,11 @@ void abort() static int stackdumpCallback(void* address, int depth /* 0-based */, void* user_data) { if (depth == 0) return 1; // skip call to abort() - instance_t hInst = FeOS_ModuleFromAddress(address); - if (!hInst || !~(word_t)hInst) + module_t hMod = LdrResolveAddr(address); + if (!hMod || !~(word_t)hMod) fprintf(stderr, " -> 0x%08X\n", (word_t) address); else - fprintf(stderr, " -> %s+0x%X\n", FeOS_GetModuleName(hInst), address - hInst); + fprintf(stderr, " -> %s+0x%X\n", LdrGetModuleName(hMod), address - hMod); return 1; } #endif diff --git a/sdk/source/cxx/backtrace.cpp b/sdk/source/cxx/backtrace.cpp index 476c1fe..94bd1be 100644 --- a/sdk/source/cxx/backtrace.cpp +++ b/sdk/source/cxx/backtrace.cpp @@ -26,7 +26,7 @@ typedef struct static _Unwind_Reason_Code backtraceCb(_Unwind_Context*, void*); -extern "C" FEOS_EXPORT void FeOS_Backtrace(bt_func pFunc, void* user_data) +extern "C" FEOS_EXPORT void CxxBacktrace(bt_func pFunc, void* user_data) { bt_context ctx = { pFunc, user_data, -2 }; _Unwind_Backtrace(backtraceCb, &ctx); @@ -35,7 +35,7 @@ extern "C" FEOS_EXPORT void FeOS_Backtrace(bt_func pFunc, void* user_data) static phase2_vrs backtraceCtx; // WARNING: this function may be called by the kernel in a privileged mode. -extern "C" FEOS_EXPORT void FeOS_BacktraceDump(word_t* pCtx, bt_func pFunc, void* user_data) +extern "C" FEOS_EXPORT void CxxBacktraceDump(word_t* pCtx, bt_func pFunc, void* user_data) { bt_context ctx = { pFunc, user_data, -1 }; backtraceCtx.demand_save_flags = 0xDEAD; // see hack in unwind.c @@ -61,6 +61,6 @@ int main(int argc, const char* argv[]) __builtin_printf("Usage: %s [/r]\n /r - Stay resident\n", argv[0]); return 0; } - FeOS_StayResident(); + LdrBeginResidency(); return 0; } diff --git a/sdk/source/cxx/find_exidx.c b/sdk/source/cxx/find_exidx.c index a2e815c..2876cdc 100644 --- a/sdk/source/cxx/find_exidx.c +++ b/sdk/source/cxx/find_exidx.c @@ -2,8 +2,8 @@ void* __attribute__((weak)) __gnu_Unwind_Find_exidx(void* return_address, int* nrec) { - instance_t hInst = FeOS_ModuleFromAddress(return_address); - if (!hInst) return 0; + module_t hMod = LdrResolveAddr(return_address); + if (!hMod) return 0; - return FeOS_GetModuleExidxTbl(hInst, nrec); + return LdrGetExidxTbl(hMod, nrec); } diff --git a/sdk/source/feosmain.c b/sdk/source/feosmain.c index b054aa2..b3144e3 100644 --- a/sdk/source/feosmain.c +++ b/sdk/source/feosmain.c @@ -28,7 +28,7 @@ word_t __FeOSMain(word_t event, word_t prm1, word_t prm2, word_t prm3) extern exidx_entry_t* __exidx_start; extern exidx_entry_t* __exidx_end; - FeOS_GetExidxTbl_t* out = (FeOS_GetExidxTbl_t*) prm1; + exidxinfo_t* out = (exidxinfo_t*) prm1; out->table = &__exidx_start; out->nentries = &__exidx_end - &__exidx_start; return FEOS_RC_OK; diff --git a/sdk/source/oam.c b/sdk/source/oam.c index c8a070a..eb31f90 100644 --- a/sdk/source/oam.c +++ b/sdk/source/oam.c @@ -5,8 +5,8 @@ SpriteEntry *oamMain_mem, *oamSub_mem; FEOSINIT void _oamInit() { - _oamMain = FeOS_GetMainOAM(); - _oamSub = FeOS_GetSubOAM(); - oamMain_mem = FeOS_GetOAMMemory(_oamMain); - oamSub_mem = FeOS_GetOAMMemory(_oamSub); + _oamMain = DSGetMainOAM(); + _oamSub = DSGetSubOAM(); + oamMain_mem = DSGetOAMMemory(_oamMain); + oamSub_mem = DSGetOAMMemory(_oamSub); }