コード整理

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@324 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2007-12-06 05:11:18 +00:00
parent c026b0a78c
commit 8653228de2
4 changed files with 165 additions and 100 deletions

View File

@ -30,6 +30,8 @@ SRCS = main.c
CRT0_O = crt0_firm.o
ADDRESS_STATIC = 0x037b8000
#LCFILE_TEMPLATE = $(FIRM_SPECDIR)/$(TWL_PROC)-$(TWL_PLATFORM)-PARTNER.lcf.template
#SRCDIR = # using default

View File

@ -33,18 +33,32 @@ static u8 fatfsHeap[FATFS_HEAP_SIZE] __attribute__ ((aligned (32)));
*/
#define PROFILE_ENABLE
#ifdef SDK_FINALROM // FINALROMųŒø‰»
#undef PROFILE_ENABLE
#endif
/*
LEDをFINALROMとは別にOn/Offできます
*/
#define USE_DEBUG_LED
//#ifdef SDK_FINALROM // FINALROMで無効化
//#undef PROFILE_ENABLE
//#undef USE_DEBUG_LED
//#endif
#ifdef PROFILE_ENABLE
#define PROFILE_MAX 16
u32 profile[PROFILE_MAX];
u32 pf_cnt = 0;
#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick()))
#else
#define PUSH_PROFILE() ((void)0)
#endif
#ifndef SDK_FINALROM
#ifdef USE_DEBUG_LED
static u8 step = 0x80;
#define InitDebugLED() I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00)
#define SetDebugLED(pattern) I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (pattern));
#else
#define InitDebugLED() ((void)0)
#define SetDebugLED(pattern) ((void)0)
#endif
/***************************************************************
@ -110,11 +124,9 @@ static BOOL FsInit(void)
OS_SetCurrentHeap(OS_ARENA_MAIN_SUBPRIV, hh);
}
#ifdef PROFILE_ENABLE
// 3: after OS_CreateHeap
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x85
PUSH_PROFILE();
SetDebugLED(++step); // 0x85
SDNandContext = &OSi_GetFromFirmAddr()->SDNandContext;
@ -129,43 +141,57 @@ static BOOL FsInit(void)
return TRUE;
}
static u32 systemId;
static void PxiSystemCallback( PXIFifoTag tag, u32 data, BOOL err )
{
(void)tag;
(void)err;
systemId = data;
}
static void IdleThread(void* arg)
{
OS_EnableInterrupts();
while ( 1 )
{
OS_Halt();
}
}
static OSThread idle;
static u32 idleStack[16] ATTRIBUTE_ALIGN(32);
static void CreateIdleThread( void )
{
OS_CreateThread( &idle, IdleThread, NULL, &idleStack[16], sizeof(idleStack), OS_THREAD_PRIORITY_MAX );
OS_WakeupThreadDirect( &idle );
}
void TwlSpMain( void )
{
int fd; // menu file descriptor
// OS_InitDebugLED and OS_SetDebugLED are able to call after OS_Init
#ifndef SDK_FINALROM
I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00);
I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, ++step); // 0x81
#endif
InitDebugLED();
SetDebugLED(++step); // 0x81
PreInit();
#ifndef SDK_FINALROM
I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, ++step); // 0x82
#endif
#ifdef PROFILE_ENABLE
// 0: before PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
SetDebugLED(++step); // 0x82
OS_InitFIRM();
OS_EnableIrq();
OS_EnableInterrupts();
#ifdef PROFILE_ENABLE
// 1: after PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x83
PUSH_PROFILE();
SetDebugLED(++step); // 0x83
PM_InitFIRM();
#ifdef PROFILE_ENABLE
// 2: after PM_InitFIRM
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x84
PUSH_PROFILE();
SetDebugLED(++step); // 0x84
PM_BackLightOn( FALSE );
if ( !FsInit() )
@ -174,24 +200,34 @@ void TwlSpMain( void )
goto end;
}
#ifdef PROFILE_ENABLE
// 4: after FS_Init
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x86
PUSH_PROFILE();
SetDebugLED(++step); // 0x86
PM_BackLightOn( FALSE );
PXI_RecvID();
SetDebugLED(0x01);
PXI_RecvID();
SetDebugLED(0x02);
PXI_RecvID();
SetDebugLED(0x03);
PXI_RecvID();
SetDebugLED(0x04);
if ( PXI_RecvID() != FIRM_PXI_ID_SET_PATH )
{
OS_TPrintf("PXI_RecvID() was received invalid value (!=FIRM_PXI_ID_SET_PATH).\n");
goto end;
}
#ifdef PROFILE_ENABLE
CreateIdleThread();
// 5: after PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x87
PUSH_PROFILE();
SetDebugLED(++step); // 0x87
PM_BackLightOn( FALSE );
if ( (fd = FS_OpenSrl()) < 0 )
@ -200,11 +236,10 @@ void TwlSpMain( void )
goto end;
}
#ifdef PROFILE_ENABLE
// 6: after FS_OpenSrl
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x88
PUSH_PROFILE();
SetDebugLED(++step); // 0x88
PM_BackLightOn( FALSE );
if ( !FS_LoadHeader( fd ) )
@ -213,11 +248,10 @@ void TwlSpMain( void )
goto end;
}
#ifdef PROFILE_ENABLE
// 7: after FS_LoadHeader
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x89
PUSH_PROFILE();
SetDebugLED(++step); // 0x89
PM_BackLightOn( FALSE );
if ( PXI_RecvID() != FIRM_PXI_ID_DONE_HEADER )
@ -226,11 +260,10 @@ void TwlSpMain( void )
goto end;
}
#ifdef PROFILE_ENABLE
// 8: after PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x8a
PUSH_PROFILE();
SetDebugLED(++step); // 0x8a
PM_BackLightOn( FALSE );
if ( !FS_LoadStatic( fd ) )
@ -239,11 +272,10 @@ void TwlSpMain( void )
goto end;
}
#ifdef PROFILE_ENABLE
// 9: after FS_LoadStatic
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
OS_SetDebugLED(++step); // 0x8b
PUSH_PROFILE();
SetDebugLED(++step); // 0x8b
PM_BackLightOn( FALSE );
if ( PXI_RecvID() != FIRM_PXI_ID_DONE_STATIC )
@ -252,35 +284,46 @@ void TwlSpMain( void )
goto end;
}
// 10: after PXI
PUSH_PROFILE();
#ifdef PROFILE_ENABLE
// 15: after PXI
pf_cnt = PROFILE_MAX-1;
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
{
int i;
MI_CpuCopy8( profile, (void*)0x02000080, sizeof(profile) );
PXI_RecvID();
OS_TPrintf("\n[ARM7] Begin\n");
for (i = 0; i < PROFILE_MAX; i++)
{
OS_TPrintf("0x%08X\n", profile[i]);
// OS_TPrintf("0x%08X\n", profile[i]);
if ( !profile[i] ) break;
OS_TPrintf("%2d: %7d usec", i, profile[i]);
if (i)
{
OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]);
}
else
{
OS_TPrintf("\n");
}
}
OS_TPrintf("\n[ARM7] End\n");
}
#endif
OS_SetDebugLED( 0 );
SetDebugLED( 0 );
PM_BackLightOn( TRUE ); // last chance
OS_BootFromFIRM();
end:
OS_SetDebugLED( (u8)(0xF0 | step));
SetDebugLED( (u8)(0xF0 | step));
EraseAll();
// failed
while (1)
// while (1)
{
PXI_NotifyID( FIRM_PXI_ID_ERR );
}
OS_Terminate();
}

View File

@ -28,6 +28,8 @@ SRCS = main.c
CRT0_O = crt0_firm.o
ADDRESS_STATIC = 0x037c0000
MAKEROM_ARM7 = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/menu_launcher7.tef
MAKEROM_ARM7_BASE = $(basename $(MAKEROM_ARM7))

View File

@ -49,14 +49,17 @@ static SVCSignHeapContext acPool;
*/
#define PROFILE_ENABLE
#ifdef SDK_FINALROM // FINALROMųŒø‰»
#undef PROFILE_ENABLE
#endif
//#ifdef SDK_FINALROM // FINALROMで無効化
//#undef PROFILE_ENABLE
//#endif
#ifdef PROFILE_ENABLE
#define PROFILE_MAX 16
u32 profile[PROFILE_MAX];
u32 pf_cnt = 0;
#define PUSH_PROFILE() (profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick()))
#else
#define PUSH_PROFILE() ((void)0)
#endif
/***************************************************************
@ -78,6 +81,7 @@ static void PreInit(void)
MI_CpuClearFast((void *)HW_WRAM_EX_LOCK_BUF, (HW_WRAM_EX_LOCK_BUF_END - HW_WRAM_EX_LOCK_BUF));
MI_CpuClearFast((void *)HW_BIOS_EXCP_STACK_MAIN, (HW_REAL_TIME_CLOCK_BUF - HW_BIOS_EXCP_STACK_MAIN));
MI_CpuClearFast((void *)HW_PXI_SIGNAL_PARAM_ARM9, (HW_MMEMCHECKER_MAIN - HW_PXI_SIGNAL_PARAM_ARM9));
MI_CpuClearFast((void*)HW_ROM_HEADER_BUF, (HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF));
// FS_MOUNT領域の初期化
MI_CpuCopy8(firmSettings, (char*)HW_TWL_FS_MOUNT_INFO_BUF, sizeof(firmSettings));
@ -124,7 +128,26 @@ static void PostInit(void)
***************************************************************/
static BOOL CheckHeader(void)
{
static ROM_Header_Short* const rhs = (ROM_Header_Short*)HW_TWL_ROM_HEADER_BUF;
// TODO
// イニシャルコード
OS_TPrintf("Initial Code : %08X\n", rhs->game_code);
// エントリポイント
OS_TPrintf("ARM9 Entry point : %08X\n", rhs->main_entry_address);
OS_TPrintf("ARM7 Entry point : %08X\n", rhs->sub_entry_address);
// ロード範囲
OS_TPrintf("ARM9 ROM address : %08X\n", rhs->main_rom_offset);
OS_TPrintf("ARM9 RAM address : %08X\n", rhs->main_ram_address);
OS_TPrintf("ARM9 size : %08X\n", rhs->main_size);
OS_TPrintf("ARM7 ROM address : %08X\n", rhs->sub_rom_offset);
OS_TPrintf("ARM7 RAM address : %08X\n", rhs->sub_ram_address);
OS_TPrintf("ARM7 size : %08X\n", rhs->sub_size);
OS_TPrintf("ARM9 LTD ROM address: %08X\n", rhs->main_ltd_rom_offset);
OS_TPrintf("ARM9 LTD RAM address: %08X\n", rhs->main_ltd_ram_address);
OS_TPrintf("ARM9 LTD size : %08X\n", rhs->main_ltd_size);
OS_TPrintf("ARM7 LTD ROM address: %08X\n", rhs->sub_ltd_rom_offset);
OS_TPrintf("ARM7 LTD RAM address: %08X\n", rhs->sub_ltd_ram_address);
OS_TPrintf("ARM7 LTD size : %08X\n", rhs->sub_ltd_size);
return TRUE;
}
@ -147,10 +170,8 @@ void TwlMain( void )
{
PreInit();
#ifdef PROFILE_ENABLE
// 0: before PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
OS_InitFIRM();
OS_EnableIrq();
@ -158,34 +179,30 @@ void TwlMain( void )
#ifdef PROFILE_ENABLE
OS_InitTick();
#endif
// 1: after PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_NULL );
//PostInit();
PostInit();
#ifdef PROFILE_ENABLE
// 2: after PostInit
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_NULL );
// RSA用ヒープ設定
SVC_InitSignHeap( &acPool, acHeap, sizeof(acHeap) );
// HMAC用鍵準備
FS_SetDigestKey( NULL );
#ifdef PROFILE_ENABLE
// 3: after SVC_InitSignHeap
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_NULL );
FATFS_InitFIRM();
FS_Init(FS_DMA_NOT_USE);
FS_InitFIRM();
#ifdef PROFILE_ENABLE
// 4: after FS_Init
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_NULL );
if ( !FS_ResolveSrl( MENU_TITLE_ID ) )
{
@ -193,35 +210,27 @@ void TwlMain( void )
goto end;
}
#ifdef PROFILE_ENABLE
// 5: after FS_ResolveSrl
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_SET_PATH );
#ifdef PROFILE_ENABLE
// 6: after PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
if ( !FS_LoadHeader(&acPool, RSA_KEY_ADDR ) && CheckHeader() )
if ( !FS_LoadHeader(&acPool, RSA_KEY_ADDR ) || !CheckHeader() )
{
OS_TPrintf("Failed to call FS_LoadHeader() and/or CheckHeader().\n");
goto end;
}
#ifdef PROFILE_ENABLE
// 7: after FS_LoadHeader
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_DONE_HEADER );
#ifdef PROFILE_ENABLE
// 8: after PXI
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
if ( !FS_LoadStatic() )
{
@ -229,25 +238,33 @@ void TwlMain( void )
goto end;
}
#ifdef PROFILE_ENABLE
// 9: after FS_LoadStatic
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC );
// 10: after PXI
PUSH_PROFILE();
#ifdef PROFILE_ENABLE
// 15: after PXI
pf_cnt = PROFILE_MAX-1;
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
{
int i;
OS_TPrintf("\n[ARM9] Begin\n");
for (i = 0; i < PROFILE_MAX; i++)
{
OS_TPrintf("0x%08X\n", profile[i]);
// OS_TPrintf("0x%08X\n", profile[i]);
if ( !profile[i] ) break;
OS_TPrintf("%2d: %7d usec", i, profile[i]);
if (i)
{
OS_TPrintf(" ( %7d usec )\n", profile[i]-profile[i-1]);
}
else
{
OS_TPrintf("\n");
}
}
OS_TPrintf("\n[ARM9] End\n");
MI_CpuCopy8( profile, (void*)0x02000000, sizeof(profile) );
PXI_NotifyID( FIRM_PXI_ID_NULL );
}
#endif
@ -258,9 +275,10 @@ end:
EraseAll();
// failed
while (1)
// while (1)
{
PXI_NotifyID( FIRM_PXI_ID_ERR );
}
OS_Terminate();
}