From cb4bf1963453880474779944bfae5ff72a03df03 Mon Sep 17 00:00:00 2001 From: nakasima Date: Mon, 8 Dec 2008 11:41:14 +0000 Subject: [PATCH] =?UTF-8?q?OS=E9=96=A2=E9=80=A3=E3=83=98=E3=83=83=E3=83=80?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E8=BF=BD=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@85 b871894f-2f95-9b40-918c-086798483c85 --- .../build/libraries/init/ARM11/crt0_secure.c | 3 +- trunk/bootrom/include/brom/os.h | 15 +- .../bootrom/include/brom/os/ARM11/interrupt.h | 135 +++++++ .../include/brom/os/ARM11/interrupt_types.h | 70 ++++ trunk/bootrom/include/brom/os/ARM11/timer.h | 107 ++++++ .../bootrom/include/brom/os/ARM9/interrupt.h | 353 ++++++++++++++++++ .../include/brom/os/ARM9/interrupt_types.h | 64 ++++ trunk/bootrom/include/brom/os/ARM9/tick.h | 150 ++++++++ trunk/bootrom/include/brom/os/ARM9/timer.h | 182 +++++++++ trunk/bootrom/include/brom/os/common/init.h | 46 +++ .../include/brom/os/common/interrupt_common.h | 183 +++++++++ trunk/bootrom/include/brom/os/common/system.h | 200 ++++++++++ trunk/include/ctr/hw/ARM11/arm11_reg.h | 53 ++- trunk/include/ctr/hw/ARM9/arm9_reg.h | 8 +- 14 files changed, 1556 insertions(+), 13 deletions(-) create mode 100644 trunk/bootrom/include/brom/os/ARM11/interrupt.h create mode 100644 trunk/bootrom/include/brom/os/ARM11/interrupt_types.h create mode 100644 trunk/bootrom/include/brom/os/ARM11/timer.h create mode 100644 trunk/bootrom/include/brom/os/ARM9/interrupt.h create mode 100644 trunk/bootrom/include/brom/os/ARM9/interrupt_types.h create mode 100644 trunk/bootrom/include/brom/os/ARM9/tick.h create mode 100644 trunk/bootrom/include/brom/os/ARM9/timer.h create mode 100644 trunk/bootrom/include/brom/os/common/init.h create mode 100644 trunk/bootrom/include/brom/os/common/interrupt_common.h create mode 100644 trunk/bootrom/include/brom/os/common/system.h diff --git a/trunk/bootrom/build/libraries/init/ARM11/crt0_secure.c b/trunk/bootrom/build/libraries/init/ARM11/crt0_secure.c index cf5d8ad..7058cb9 100644 --- a/trunk/bootrom/build/libraries/init/ARM11/crt0_secure.c +++ b/trunk/bootrom/build/libraries/init/ARM11/crt0_secure.c @@ -106,7 +106,6 @@ ASM void stupDisableCP15( void ) ldr r1, =HW_C1_IC_ENABLE | HW_C1_DC_ENABLE \ | HW_C1_FORCE_AP_BIT \ | HW_C1_TEX_CB_REMAP \ - | HW_C1_NMFI_FIQ \ | HW_C1_EXCEPT_BIG_ENDIAN \ | HW_C1_BR_PREDICT_ENABLE \ | HW_C1_LD_INTERWORK_DISABLE \ @@ -317,7 +316,6 @@ void stupInitMMUTable( void ) HW_MMU6_T1_SHARED, HW_MMU6_T1_XN, 0); -// paddr += HW_MMU6_T1_SEC_SIZE; } table = t2Base; @@ -350,6 +348,7 @@ void stupInitMMUTable( void ) paddr += HW_MMU6_T1_SEC_SIZE; } #ifndef SDK_MG20EMU + // MG20には拡張メインメモリは無い while ( paddr < HW_MAIN_MEM_EX_END ) { diff --git a/trunk/bootrom/include/brom/os.h b/trunk/bootrom/include/brom/os.h index 43e96b8..1bf290c 100644 --- a/trunk/bootrom/include/brom/os.h +++ b/trunk/bootrom/include/brom/os.h @@ -29,17 +29,22 @@ extern "C" { #include #include -#if 0 -#include #include #include +#ifdef SDK_ARM11 +#include +#include +#else // SDK_ARM9 +#include +#include +#include +#endif // SDK_ARM9 +#if 0 +#include #include -#include #include #include #include -#include -#include #include #ifdef SDK_ARM9 diff --git a/trunk/bootrom/include/brom/os/ARM11/interrupt.h b/trunk/bootrom/include/brom/os/ARM11/interrupt.h new file mode 100644 index 0000000..23ed835 --- /dev/null +++ b/trunk/bootrom/include/brom/os/ARM11/interrupt.h @@ -0,0 +1,135 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: interrupt.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_INTERRUPT_H_ +#define BROM_OS_INTERRUPT_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define OS_IDR_CPU0_TARGET_ENABLE HW_IDR_CPU0_TARGET_ENABLE +#define OS_IDR_INTR_PRIO_DEFAULT 8 // Interrupt priority default (0-15) + + +extern OSIntrFunction osIntrDistrTable[OS_INTR_DISTR_ID_LIMIT]; + + +OSIntrID osi_ReadHighestPendingInterruptRegister( void ); +OSIntrID osi_ReadInterruptAcknowledgeRegister( void ); + + +/*---------------------------------------------------------------------------* + Name: osInitInterrupts + + Description: Initialize Interrupts + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osInitInterrupt( void ); + +/*---------------------------------------------------------------------------* + Name: osEnableInterruptID + + Description: set Interrupt Set Enable Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osEnableInterruptID( OSIntrID id ); + +/*---------------------------------------------------------------------------* + Name: osDisableInterruptID + + Description: set Interrupt Clear Enable Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osDisableInterruptID( OSIntrID id ); + +/*---------------------------------------------------------------------------* + Name: osRestoreInterruptID + + Description: set Interrupt Clear Enable Register + + Arguments: id : Interrupt Distributor ID + state : state whether interrupt is enabled + + Returns: TRUE if last state is enabled + *---------------------------------------------------------------------------*/ +BOOL osRestoreInterruptID( OSIntrID id, BOOL state ); + +/*---------------------------------------------------------------------------* + Name: osSetInterruptPending + + Description: set Interrupt Set Pending Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osSetInterruptPending( OSIntrID id ); + +/*---------------------------------------------------------------------------* + Name: osClearInterruptPending + + Description: set Interrupt Clear Pending Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osClearInterruptPending( OSIntrID id ); + +/*---------------------------------------------------------------------------* + Name: osRestoreInterruptPending + + Description: restore Interrupt Pending + + Arguments: id : Interrupt Distributor ID + state : state whether interrupt is enabled + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osRestoreInterruptPending( OSIntrID id, BOOL state ); + +/*---------------------------------------------------------------------------* + Name: osSetEndOfInterruptRegister + + Description: set ID to End of Interrupt Register + + change state to Inactive. + + Arguments: Interrupt Distributor ID + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetEndOfInterruptRegister( OSIntrID id ); + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // BROM_OS_INTERRUPT_H_ diff --git a/trunk/bootrom/include/brom/os/ARM11/interrupt_types.h b/trunk/bootrom/include/brom/os/ARM11/interrupt_types.h new file mode 100644 index 0000000..d59d2d1 --- /dev/null +++ b/trunk/bootrom/include/brom/os/ARM11/interrupt_types.h @@ -0,0 +1,70 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: interrupt_types.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_INTERRUPT_TYPES_H_ +#define BROM_OS_INTERRUPT_TYPES_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef struct +{ + u32 w[3]; +} +OSIntrMask; + +typedef enum +{ + OS_INTR_ID_IPI_0 = 0, + OS_INTR_ID_IPI_1 = 1, + OS_INTR_ID_IPI_2 = 2, + OS_INTR_ID_IPI_3 = 3, + OS_INTR_ID_IPI_4 = 4, + OS_INTR_ID_IPI_5 = 5, + OS_INTR_ID_IPI_6 = 6, + OS_INTR_ID_IPI_7 = 7, + OS_INTR_ID_IPI_8 = 8, + OS_INTR_ID_IPI_9 = 9, + OS_INTR_ID_IPI_10 = 10, + OS_INTR_ID_IPI_11 = 11, + OS_INTR_ID_IPI_12 = 12, + OS_INTR_ID_IPI_13 = 13, + OS_INTR_ID_IPI_14 = 14, + OS_INTR_ID_IPI_15 = 15, + + OS_INTR_ID_IPI_MIN = OS_INTR_ID_IPI_0, + OS_INTR_ID_IPI_MAX = OS_INTR_ID_IPI_15, + + OS_INTR_ID_TIMER = REG_OS_IDR_SET_IE0_TM_SHIFT, // 29 + OS_INTR_ID_WATCHDOG = REG_OS_IDR_SET_IE0_WDOG_SHIFT, // 30 + + OS_INTR_DISTR_ID_MIN = OS_INTR_ID_IPI_MIN, + OS_INTR_DISTR_ID_MAX = (32*5) + REG_OS_IDR_SET_IE5_PMUIRQ7_SHIFT, + OS_INTR_DISTR_ID_LIMIT +} +OSIntrID; + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // BROM_OS_INTERRUPT_TYPES_H_ diff --git a/trunk/bootrom/include/brom/os/ARM11/timer.h b/trunk/bootrom/include/brom/os/ARM11/timer.h new file mode 100644 index 0000000..800c17a --- /dev/null +++ b/trunk/bootrom/include/brom/os/ARM11/timer.h @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: timer.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_TIMER_H_ +#define BROM_OS_TIMER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +//---------------------------------------------------------------------- +//---- timer ID +typedef enum +{ + OS_CPU_TIMER = 0, + OS_CPU_WATCHDOG = 1 +} +OSTimerID; + +typedef enum +{ + OS_WD_WATCHDOG_MODE = HW_CPUWD_WATCHDOG_MODE, + OS_WD_TIMER_MODE = HW_CPUWD_TIMER_MODE +} +OSWatchdogMode; + + +void osInitTimer( void ); + +/*---------------------------------------------------------------------------* + Name: osStartTimerWithUSec + + Description: Start Timer + + Arguments: micro second + + Returns: None + *---------------------------------------------------------------------------*/ + +void osStartTimerWithUSec( u32 usec, u8 preScale ); + +/*---------------------------------------------------------------------------* + Name: osStartTimerWithMSec + + Description: Start Timer + + Arguments: milli second + + Returns: None + *---------------------------------------------------------------------------*/ + +void osStartTimerWithMSec( u32 msec, u8 preScale ); + +/*---------------------------------------------------------------------------* + Name: osStartTimer + + Description: Start Timer + + Arguments: interval + + Returns: None + *---------------------------------------------------------------------------*/ + +void osStartTimer( u32 count, u8 preScale ); + +/*---------------------------------------------------------------------------* + Name: osStopTimer + + Description: Stop Timer + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ + +void osStopTimer( void ); + +BOOL osEnableTimerAndWatchdog( void ); +BOOL osDisableTimerAndWatchdog( void ); +void osStartWatchDog( u32 count, u8 preScale, OSWatchdogMode watchdogMode ); +void osStopWatchDog( void ); +void osResetWatchdog( void ); +void osDisableWatchdog( void ); + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // BROM_OS_TIMER_H_ diff --git a/trunk/bootrom/include/brom/os/ARM9/interrupt.h b/trunk/bootrom/include/brom/os/ARM9/interrupt.h new file mode 100644 index 0000000..5157103 --- /dev/null +++ b/trunk/bootrom/include/brom/os/ARM9/interrupt.h @@ -0,0 +1,353 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: interrupt.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_INTERRUPT_H_ +#define BROM_OS_INTERRUPT_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +//================================================================================ +// INTERRUPT MASK +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osSetInterruptMask + + Description: set irq factor + + Arguments: mask irq factor + + Returns: previous factors + *---------------------------------------------------------------------------*/ +OSIntrMask osSetInterruptMask( OSIntrMask mask ); + +/*---------------------------------------------------------------------------* + Name: osGetInterruptMask + + Description: get irq factor + + Arguments: None + + Returns: irq factor which is set now + *---------------------------------------------------------------------------*/ +static inline OSIntrMask osGetInterruptMask(void) +{ + return reg_OS_IE; +} + +/*---------------------------------------------------------------------------* + Name: osEnableInterruptMask + + Description: set specified irq factor + + Arguments: mask irq factor + + Returns: previous factors + *---------------------------------------------------------------------------*/ +OSIntrMask osEnableInterruptMask( OSIntrMask mask ); + +/*---------------------------------------------------------------------------* + Name: osDisableInterruptMask + + Description: unset specified irq factor + + Arguments: mask irq factor + + Returns: previous factors + *---------------------------------------------------------------------------*/ +OSIntrMask osDisableInterruptMask( OSIntrMask mask ); + +/*---------------------------------------------------------------------------* + Name: osRestoreInterruptMask + + Description: set irq factor + + Arguments: mask irq factor + + Returns: previous factors + *---------------------------------------------------------------------------*/ +static inline OSIntrMask osRestoreInterruptMask( OSIntrMask mask ) +{ + return osSetInterruptMask( mask ); +} + +/*---------------------------------------------------------------------------* + Name: osEnableInterruptID + + Description: set Interrupt Set Enable Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osEnableInterruptID( OSIntrID id ); + +/*---------------------------------------------------------------------------* + Name: osDisableInterruptID + + Description: set Interrupt Clear Enable Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osDisableInterruptID( OSIntrID id ); + +/*---------------------------------------------------------------------------* + Name: osRestoreInterruptID + + Description: set Interrupt Clear Enable Register + + Arguments: id : Interrupt Distributor ID + state : state whether interrupt is enabled + + Returns: TRUE if last state is enabled + *---------------------------------------------------------------------------*/ +BOOL osRestoreInterruptID( OSIntrID id, BOOL state ); + +//================================================================================ +// INTERRUPT PENDING +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osClearInterruptPendingMask + + Description: reset IF bit + (setting bit causes to clear bit for interrupt) + + Arguments: intr irq factor + + Returns: previous factors + *---------------------------------------------------------------------------*/ +OSIntrMask osClearInterruptPendingMask( OSIntrMask mask ); + +/*---------------------------------------------------------------------------* + Name: osGetInterruptPendingMask + + Description: get IF bit + + Arguments: None + + Returns: value of IF + *---------------------------------------------------------------------------*/ +static inline OSIntrMask osGetInterruptPendingMask( void ) +{ +#ifdef SDK_ARM9 + return reg_OS_IF; +#else // MPCORE + return reg_OS_IDR_SET_PENDING_ST; +#endif // MPCORE +} + +/*---------------------------------------------------------------------------* + Name: osClearInterruptPendingID + + Description: set Interrupt Clear Pending Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +BOOL osClearInterruptPendingID( OSIntrID id ); + +/*---------------------------------------------------------------------------* + Name: osIsInterruptIDPending + + Description: set Interrupt Clear Pending Register + + Arguments: Interrupt Distributor ID + + Returns: TRUE if last state is pending + *---------------------------------------------------------------------------*/ +static inline BOOL osIsInterruptPending( OSIntrID id ) +{ +#ifdef SDK_ARM9 + OSIntrMask prep = reg_OS_IF; + BOOL retval; + + retval = TRUE & (BOOL)(prep >> id); +#else // MPCORE + u32 ofs = id/32; + u32 sft = id%32; + BOOL retval; + + retval = TRUE & (reg_OS_IDR_SET_PENDING_WP[ofs] >> sft); +#endif // MPCORE + + return retval; +} + +//================================================================================ +// MULTI INTERRUPT +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osSetMultiInterruptMask + + Description: Set interrupt mask for multi interrupt + + Arguments: interrupt ID + interrupt mask + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetMultiInterruptMask( OSIntrID id, OSIntrMask mask ); + +//================================================================================ +// INTERRUPT HANDLER +//================================================================================ +/*---------------------------------------------------------------------------* + Name: i_osInitInterruptTable + + Description: initialize irq table + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void i_osInitInterruptTable(void); + +/*---------------------------------------------------------------------------* + Name: osSetInterruptHandler + + Description: set irq handler for specified interrupt + + Arguments: intrBit irq factor + function irq handler for specified interrupt + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetInterruptHandler( OSIntrID id, OSIntrFunction function ); + + +/*---------------------------------------------------------------------------* + Name: osGetInterruptHandler + + Description: Get interrupt handler + + Arguments: interrupt ID + interrupt handler + + Returns: None + *---------------------------------------------------------------------------*/ +OSIntrFunction osGetInterruptHandler( OSIntrID id ); + +//================================================================================ +// INTERRUPT CHECK +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osSetInterruptCheckFlag + + Description: set irq flag to check being called + + Arguments: irq factors to be set + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetInterruptCheckFlag( OSIntrMask intr ); + +/*---------------------------------------------------------------------------* + Name: osClearInterruptCheckFlag + + Description: clear irq flag stored in HW_INTR_CHECK_BUF + + Arguments: irq factors to be cleared + + Returns: None + *---------------------------------------------------------------------------*/ +void osClearInterruptCheckFlag( OSIntrMask mask ); + +/*---------------------------------------------------------------------------* + Name: osGetInterruptCheckFlag + + Description: get irq factors stored in HW_INTR_CHECK_BUF + + Arguments: None + + Returns: irq flags factors in HW_INTR_CHECK_BUG + *---------------------------------------------------------------------------*/ +static inline OSIntrMask osGetInterruptCheckFlag( void ) +{ + return *(OSIntrMask *)HW_INTR_CHECK_BUF; +} + +//================================================================================ +// WAIT FOR INTERRUPT +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osWaitInterrupt + + Description: wait specifiled interrupt. + OS_WaitInterrupt doesn't switch thread. + OS_WaitInterrupt wait by using OS_Halt(). + + Arguments: clear TRUE if want to clear interrupt flag before wait. + FALSE if not. + irqFlags bit of interrupts to wait for + + Returns: None + *---------------------------------------------------------------------------*/ +void osWaitInterrupt( BOOL clear, OSIntrMask irqFlags ); + +//================================================================================ +// INTERRUPT FLAG (INCLUDING TO WAIT FOR INTERRUPT) +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osInitIntrFlag + + Description: Initialize eventflag and task for interrupts + + Arguments: None + + Returns: TRUE if success. + *---------------------------------------------------------------------------*/ +BOOL osInitIntrFlag( void ); + +/*---------------------------------------------------------------------------* + Name: osWaitInterruptID + + Description: wait specifiled interrupt. + + Arguments: id interrupt ID to wait + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL osWaitInterruptID( int id ); + +/*---------------------------------------------------------------------------* + Name: osWaitInterruptMask + + Description: wait specifiled mask for interrupts. + supported only 0-31 + + Arguments: mask interrupt mask to wait + + Returns: received interrupt mask, 0 if failed. + NOTE: non-waiting interrupt bits may set + *---------------------------------------------------------------------------*/ +OSIntrMask osWaitInterruptMask( OSIntrMask mask ); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_OS_INTERRUPT_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/os/ARM9/interrupt_types.h b/trunk/bootrom/include/brom/os/ARM9/interrupt_types.h new file mode 100644 index 0000000..c555c0e --- /dev/null +++ b/trunk/bootrom/include/brom/os/ARM9/interrupt_types.h @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: interrupt_types.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_INTERRUPT_TYPES_H_ +#define BROM_OS_INTERRUPT_TYPES_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef u32 OSIntrMask; + +typedef enum +{ + OS_INTR_ID_DMA0 = REG_OS_IE_D0_SHIFT, + OS_INTR_ID_DMA1 = REG_OS_IE_D1_SHIFT, + OS_INTR_ID_DMA2 = REG_OS_IE_D2_SHIFT, + OS_INTR_ID_DMA3 = REG_OS_IE_D3_SHIFT, + OS_INTR_ID_TIMER0 = REG_OS_IE_T0_SHIFT, + OS_INTR_ID_TIMER1 = REG_OS_IE_T1_SHIFT, + OS_INTR_ID_TIMER2 = REG_OS_IE_T2_SHIFT, + OS_INTR_ID_TIMER3 = REG_OS_IE_T3_SHIFT, + + OS_INTR_ID_NUM +} +OSIntrID; + + +//---------------------------------------------------------------------- +// IE/IF flags +//---------------------------------------------------------------------- +#define OS_IE_DMA0 (1UL << REG_OS_IE_D0_SHIFT) // DMA0 +#define OS_IE_DMA1 (1UL << REG_OS_IE_D1_SHIFT) // DMA1 +#define OS_IE_DMA2 (1UL << REG_OS_IE_D2_SHIFT) // DMA2 +#define OS_IE_DMA3 (1UL << REG_OS_IE_D3_SHIFT) // DMA3 +#define OS_IE_TIMER0 (1UL << REG_OS_IE_T0_SHIFT) // timer0 +#define OS_IE_TIMER1 (1UL << REG_OS_IE_T1_SHIFT) // timer1 +#define OS_IE_TIMER2 (1UL << REG_OS_IE_T2_SHIFT) // timer2 +#define OS_IE_TIMER3 (1UL << REG_OS_IE_T3_SHIFT) // timer3 + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // BROM_OS_INTERRUPT_TYPES_H_ diff --git a/trunk/bootrom/include/brom/os/ARM9/tick.h b/trunk/bootrom/include/brom/os/ARM9/tick.h new file mode 100644 index 0000000..23776c4 --- /dev/null +++ b/trunk/bootrom/include/brom/os/ARM9/tick.h @@ -0,0 +1,150 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: tick.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_TICK_H_ +#define BROM_OS_TICK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + + +//---- unit of tick +typedef u64 OSTick; +typedef u32 OSTick32; + + +//---- tick APIs +extern void osInitTick( void ); +extern u64 osGetTick( void ); +extern void osSetTick( u64 ); + + +//---- conversion tick count <-> real time count +#define OS_SYSTEM_CLOCK HW_SYSTEM_CLOCK + +//---- sec to tick +#define OSi_SEC_TO_TICK( sec, prescale ) ((OSTick)( (OS_SYSTEM_CLOCK * (u64)(sec)) / (prescale) )) +#define OSi_SEC_TO_TICK32( sec, prescale ) ((OSTick32)( (OS_SYSTEM_CLOCK * (u32)(sec)) / (prescale) )) + +#define OSi_MSEC_TO_TICK( msec, prescale ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u64)(msec)) / (prescale) )) +#define OSi_MSEC_TO_TICK32( msec, prescale ) ((OSTick32)( ((OS_SYSTEM_CLOCK/1000) * (u32)(msec)) / (prescale) )) + +#define OSi_USEC_TO_TICK( usec, prescale ) ((OSTick)( ((OS_SYSTEM_CLOCK/1000) * (u64)(usec)) / ((prescale) * 1000) )) +#define OSi_USEC_TO_TICK32( usec, prescale ) ((OSTick32)( ((OS_SYSTEM_CLOCK/1000) * (u32)(usec)) / ((prescale) * 1000) )) + +#define OS_SEC_TO_TICK( sec ) OSi_SEC_TO_TICK( sec, 64 ) +#define OS_SEC_TO_TICK32( sec ) OSi_SEC_TO_TICK32( sec, 64 ) + +#define OS_MSEC_TO_TICK( msec ) OSi_MSEC_TO_TICK( msec, 64 ) +#define OS_MSEC_TO_TICK32( msec ) OSi_MSEC_TO_TICK32( msec, 64 ) + +#define OS_USEC_TO_TICK( usec ) OSi_USEC_TO_TICK( usec, 64 ) +#define OS_USEC_TO_TICK32( usec ) OSi_USEC_TO_TICK32( usec, 64 ) + +//---- tick to sec +#define OSi_TICK_TO_SEC( tick, prescale ) ( ((u64)(tick) * (prescale)) / OS_SYSTEM_CLOCK ) +#define OSi_TICK_TO_SEC32( tick, prescale ) ( ((u32)(tick) * (prescale)) / OS_SYSTEM_CLOCK ) + +#define OSi_TICK_TO_MSEC( tick, prescale ) ( ((u64)(tick) * (prescale)) / (OS_SYSTEM_CLOCK/1000) ) +#define OSi_TICK_TO_MSEC32( tick, prescale ) ( ((u32)(tick) * (prescale)) / (OS_SYSTEM_CLOCK/1000) ) + +#define OSi_TICK_TO_USEC( tick, prescale ) ( ((u64)(tick) * (prescale) * 1000) / (OS_SYSTEM_CLOCK/1000) ) +#define OSi_TICK_TO_USEC32( tick, prescale ) ( ((u32)(tick) * (prescale) * 1000) / (OS_SYSTEM_CLOCK/1000) ) + +#define OS_TICK_TO_SEC( tick ) OSi_TICK_TO_SEC( tick, 64 ) +#define OS_TICK_TO_SEC32( tick ) OSi_TICK_TO_SEC32( tick, 64 ) + +#define OS_TICK_TO_MSEC( tick ) OSi_TICK_TO_MSEC( tick, 64 ) +#define OS_TICK_TO_MSEC32( tick ) OSi_TICK_TO_MSEC32( tick, 64 ) + +#define OS_TICK_TO_USEC( tick ) OSi_TICK_TO_USEC( tick, 64 ) +#define OS_TICK_TO_USEC32( tick ) OSi_TICK_TO_USEC32( tick, 64 ) + + +static inline OSTick i_osSecToTick( u64 sec ) +{ + return OS_SEC_TO_TICK( sec ); +} + +static inline OSTick32 i_osSecToTick32( u32 sec ) +{ + return OS_SEC_TO_TICK32( sec ); +} + +static inline OSTick i_osMSecToTick( u64 msec ) +{ + return OS_MSEC_TO_TICK( msec ); +} + +static inline OSTick32 i_osMSecToTick32( u32 msec ) +{ + return OS_MSEC_TO_TICK32( msec ); +} + +static inline OSTick i_osUSecToTick( u64 usec ) +{ + return OS_USEC_TO_TICK( usec ); +} + +static inline OSTick32 i_osUSecToTick32( u32 usec ) +{ + return OS_USEC_TO_TICK32( usec ); +} + +static inline u64 i_osTickToSec( OSTick tick ) +{ + return OS_TICK_TO_SEC( tick ); +} + +static inline u32 i_osTickToSec32( OSTick32 tick ) +{ + return OS_TICK_TO_SEC32( tick ); +} + +static inline u64 i_osTickToMSec( OSTick tick ) +{ + return OS_TICK_TO_MSEC( tick ); +} + +static inline u32 i_osTickToMSec32( OSTick32 tick ) +{ + return OS_TICK_TO_MSEC32( tick ); +} + +static inline u64 i_osTickToUSec( OSTick tick ) +{ + return OS_TICK_TO_USEC( tick ); +} + +static inline u32 i_osTickToUSec32( OSTick32 tick ) +{ + return OS_TICK_TO_USEC32( tick ); +} + + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_OS_TICK_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/os/ARM9/timer.h b/trunk/bootrom/include/brom/os/ARM9/timer.h new file mode 100644 index 0000000..835531a --- /dev/null +++ b/trunk/bootrom/include/brom/os/ARM9/timer.h @@ -0,0 +1,182 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: timer.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_TIMER_H_ +#define BROM_OS_TIMER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#include + + +#ifndef SDK_ARM11 + +//---------------------------------------------------------------------- +//---- pre-scaler +typedef enum +{ + OS_TIMER_PRESCALER_1 = (0UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 1 + OS_TIMER_PRESCALER_64 = (1UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 64 + OS_TIMER_PRESCALER_256 = (2UL << REG_OS_TM0CNT_H_PS_SHIFT), // x 256 + OS_TIMER_PRESCALER_1024 = (3UL << REG_OS_TM0CNT_H_PS_SHIFT) // x 1024 +} +OSTimerPrescaler; + +//---- timer number +typedef enum +{ + OS_TIMER_0 = 0, + OS_TIMER_1 = 1, + OS_TIMER_2 = 2, + OS_TIMER_3 = 3, + OS_TIMER_NUM = 4 +} +OSTimer; + +//---- timer number ( if use 32 bit timer ) +typedef enum +{ + OS_TIMER32_01 = 0, + OS_TIMER32_12 = 1, + OS_TIMER32_23 = 2 +} +OSTimer32; + +//---- timer number ( if use 48 bit timer ) +typedef enum +{ + OS_TIMER48_012 = 0, + OS_TIMER48_123 = 1 +} +OSTimer48; + +//================================================================================ +// TIMER +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osInitTimer + + Description: Initialize Timers + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osInitTimer( void ); + +/*---------------------------------------------------------------------------* + Name: i_osSetTimerCount + + Description: set timer count + + Arguments: id timerNo + count count value to be set to timer + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void i_osSetTimerCount( OSTimer id, u16 count ) +{ + SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3); + *((REGType16 *)((u32)REG_TM0CNT_L_ADDR + id * 4)) = count; +} + +/*---------------------------------------------------------------------------* + Name: i_osSetTimerControl + + Description: set timer control + + Arguments: id timerNo + control control value to be set to timer + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void i_osSetTimerControl( OSTimer id, u16 control ) +{ + SDK_ASSERT(OS_TIMER_0 <= id && id <= OS_TIMER_3); + *((REGType16 *)((u32)REG_TM0CNT_H_ADDR + id * 4)) = control; +} + +/*---------------------------------------------------------------------------* + Name: i_osStartTimer + + Description: set timer(s) and start + + Arguments: id timerNo + count count value to be set to timer + preScale preScale + + Returns: None + *---------------------------------------------------------------------------*/ +// +// use 1 timer, 16bit counter, timer interrupt occurs by overflow +// +void i_osStartTimer( OSTimer id, u16 count, OSTimerPrescaler preScale ); +// +// use 2 timers, 32bit counter, timer interrupt occurs by overflow +// +void i_osStartTimer32( OSTimer32 id, u32 count, OSTimerPrescaler preScale ); +// +// use 3 timers, 48bit counter, timer interrupt occurs by overflow +// +void i_osStartTimer48( OSTimer48 id, u64 count, OSTimerPrescaler preScale ); +// +// use all 4 timers, 64bit counter, timer3 interrupt occurs by overflow +// +void i_osStartTimer64( u64 count, OSTimerPrescaler preScale ); + + +/*---------------------------------------------------------------------------* + Name: i_osStopTimer + + Description: stop timer(s) + + Arguments: id timerNo + + Returns: None + *---------------------------------------------------------------------------*/ +// +// stop a timer +// +void i_osStopTimer( OSTimer id ); +// +// stop 2 timers +// +void i_osStopTimer32( OSTimer32 id ); +// +// stop 3 timers +// +void i_osStopTimer48( OSTimer48 id ); +// +// stop all 4 timers +// +void i_osStopTimer64( void ); + + +#endif // SDK_ARM11 + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_OS_TIMER_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/os/common/init.h b/trunk/bootrom/include/brom/os/common/init.h new file mode 100644 index 0000000..61f94c8 --- /dev/null +++ b/trunk/bootrom/include/brom/os/common/init.h @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: init.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_INIT_H_ +#define BROM_OS_INIT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + +/*---------------------------------------------------------------------------* + Name: osInit + + Description: initialize sdk os + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osInit(void); + + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_OS_INIT_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/os/common/interrupt_common.h b/trunk/bootrom/include/brom/os/common/interrupt_common.h new file mode 100644 index 0000000..e61be4a --- /dev/null +++ b/trunk/bootrom/include/brom/os/common/interrupt_common.h @@ -0,0 +1,183 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: interrupt_common.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_INTERRUPT_COMMON_H_ +#define BROM_OS_INTERRUPT_COMMON_H_ + +#include +#include +#include +#ifdef SDK_ARM11 +#include +#else // SDK_ARM9 +#include +#endif // SDK_ARM9 + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef u32 OSIntrMode; + +typedef enum +{ + OS_IRQ_DISABLE = HW_PSR_IRQ_DISABLE, + OS_IRQ_ENABLE = 0 +} +OSIrqMode; + +typedef enum +{ + OS_FIQ_DISABLE = HW_PSR_FIQ_DISABLE, + OS_FIQ_ENABLE = 0 +} +OSFiqMode; + + +//---- interrupt handler type +//typedef IRQ void (*OSIntrHandler) (void); +typedef void (*OSIntrHandler) (void); +typedef void (*OSIntrFunction) (void); + + + +//IRQ void osInterruptHandler( void ); +void osInterruptHandler( void ); +void osInitInterruptTable( void ); + +OSIntrMode osEnableIrq( void ); +OSIntrMode osDisableIrq( void ); +OSIntrMode osRestoreIrq( OSIntrMode state ); + +OSIntrMode osEnableFiq( void ); +OSIntrMode osDisableFiq( void ); +OSIntrMode osRestoreFiq( OSIntrMode state ); + +OSIntrMode osEnableIrqAndFiq( void ); +OSIntrMode osDisableIrqAndFiq( void ); +OSIntrMode osRestoreIrqAndFiq( OSIntrMode state ); + + +/*---------------------------------------------------------------------------* + Name: osInitInterrupt + + Description: Initialize Interrupts + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osInitInterrupt( void ); + +/*---------------------------------------------------------------------------* + Name: osSetInterruptHandler + + Description: Set interrupt handler + + Arguments: interrupt ID + interrupt handler + + Returns: None + *---------------------------------------------------------------------------*/ + +void osSetInterruptHandler( OSIntrID id, OSIntrFunction handler ); + +/*---------------------------------------------------------------------------* + Name: osSetInterruptMaskForMultiInterrupt + + Description: Set interrupt mask for multi interrupt + + Arguments: interrupt ID + interrupt mask + + Returns: None + *---------------------------------------------------------------------------*/ + +void osSetInterruptMaskForMultiInterrupt( OSIntrID id, OSIntrMask *mask ); + + +/*---------------------------------------------------------------------------* + Name: osHalt + + Description: Halt CPU Core until Interrupt + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ + +void osHalt( void ); + +#ifdef SDK_ARM9 +#else // SDK_MPCORE + +/*---------------------------------------------------------------------------* + Name: osHaltUntilEvent + + Description: Halt CPU Core until Event + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ + +void osHaltUntilEvent( void ); + +#endif // SDK_MPCORE + +/*---------------------------------------------------------------------------* + Name: osEnableInterrupts + + Description: Set CPSR to enable irq and fiq interrupts + + Arguments: None. + + Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE + *---------------------------------------------------------------------------*/ + +OSIntrMode osEnableInterrupts( void ); + +/*---------------------------------------------------------------------------* + Name: osDisableInterrupts + + Description: Set CPSR to disable irq and fiq interrupts + + Arguments: None. + + Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE + *---------------------------------------------------------------------------*/ + +OSIntrMode osDisableInterrupts( void ); + +/*---------------------------------------------------------------------------* + Name: osRestoreInterrupts + + Description: Restore CPSR irq and fiq interrupts + + Arguments: state of irq interrupt bit + + Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE + *---------------------------------------------------------------------------*/ + +OSIntrMode osRestoreInterrupts( OSIntrMode state ); + + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // BROM_OS_INTERRUPT_COMMON_H_ diff --git a/trunk/bootrom/include/brom/os/common/system.h b/trunk/bootrom/include/brom/os/common/system.h new file mode 100644 index 0000000..cfb21f3 --- /dev/null +++ b/trunk/bootrom/include/brom/os/common/system.h @@ -0,0 +1,200 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: system.h + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef BROM_OS_SYSTEM_H_ +#define BROM_OS_SYSTEM_H_ + +#ifndef SDK_ASM +#include +#endif + +#include +#ifdef SDK_ARM11 +#else // SDK_ARM9 +#include +#endif //SDK_ARM9 + +#ifdef __cplusplus +extern "C" { +#endif + +//---------------------------------------------------------------------------- + +typedef u32 OSCpuCycle; + +#define OS_CPU_CLOCK HW_CPU_CLOCK + +//---- sec to cpu cycle +// 150nsec - 30sec +#define OS_SEC_TO_CPUCYC( sec ) ((OSCpuCycle)( ( OS_CPU_CLOCK * (u32)(sec)) )) +#define OS_MSEC_TO_CPUCYC( msec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(msec)) )) +#define OS_USEC_TO_CPUCYC( usec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(usec)) / 1000 )) +#define OS_NSEC_TO_CPUCYC( nsec ) ((OSCpuCycle)( ((OS_CPU_CLOCK/1000) * (u32)(nsec)) / (1000 * 1000) )) + +//---- cpu cycle to sec +// 150nsec - 30sec +#define OS_CPUCYC_TO_SEC( cyc ) ( ((u32)(cyc) ) / OS_CPU_CLOCK ) +#define OS_CPUCYC_TO_MSEC( cyc ) ( ((u32)(cyc) ) / (OS_CPU_CLOCK/1000) ) +#define OS_CPUCYC_TO_USEC( cyc ) ( ((u32)(cyc) * 1000) / (OS_CPU_CLOCK/1000) ) +#define OS_CPUCYC_TO_NSEC( cyc ) ( ((u32)(cyc) * 1000 * 1000) / (OS_CPU_CLOCK/1000) ) + + +#ifndef SDK_ASM + +#define OS_EXIT_STRING_1 "*** Exit ctr program (status=" +#define OS_EXIT_STRING_2 "%d).\n" +#define OS_EXIT_STRING OS_EXIT_STRING_1 OS_EXIT_STRING_2 + +typedef enum +{ + OS_PROCMODE_USR = HW_PSR_USR_MODE, + OS_PROCMODE_FIQ = HW_PSR_FIQ_MODE, + OS_PROCMODE_IRQ = HW_PSR_IRQ_MODE, + OS_PROCMODE_SVC = HW_PSR_SVC_MODE, + OS_PROCMODE_ABORT = HW_PSR_ABORT_MODE, + OS_PROCMODE_UNDEF = HW_PSR_UNDEF_MODE, + OS_PROCMODE_SYS = HW_PSR_SYS_MODE +} +OSProcMode; + +#ifdef SDK_ARM9 +#define OS_SVC_STACK_SIZE 0x1000 +#define OS_IRQ_STACK_SIZE 0x1000 +#else // SDK_MPCORE +#endif // SDK_MPCORE + + +//---- sec to cpu cycle +// 150nsec - 30sec +static inline OSCpuCycle i_osSecToCpuCycle( u32 sec ) +{ + return OS_SEC_TO_CPUCYC( sec ); +} + +static inline OSCpuCycle i_osMSecToCpuCycle( u32 msec ) +{ + return OS_MSEC_TO_CPUCYC( msec ); +} + +static inline OSCpuCycle i_osUSecToCpuCycle( u32 usec ) +{ + return OS_USEC_TO_CPUCYC( usec ); +} + +static inline OSCpuCycle i_osNSecToCpuCycle( u32 nsec ) +{ + return OS_NSEC_TO_CPUCYC( nsec ); +} + +//---- cpu cycle to sec +// 150nsec - 30sec +static inline u32 i_osCpuCycleToSec( OSCpuCycle cyc ) +{ + return OS_CPUCYC_TO_SEC( cyc ); +} + +static inline u32 i_osCpuCycleToMSec( OSCpuCycle cyc ) +{ + return OS_CPUCYC_TO_MSEC( cyc ); +} + +static inline u32 i_osCpuCycleToUSec( OSCpuCycle cyc ) +{ + return OS_CPUCYC_TO_USEC( cyc ); +} + +static inline u32 i_osCpuCycleToNSec( OSCpuCycle cyc ) +{ + return OS_CPUCYC_TO_NSEC( cyc ); +} + + +//============================================================================ +// PROCESSER MODE +//============================================================================ +/*---------------------------------------------------------------------------* + Name: i_osGetProcMode + + Description: Get processor mode from CPSR + + Arguments: None. + + Returns: CPU processor mode (field 0x10-0x1f) + *---------------------------------------------------------------------------*/ +OSProcMode i_osGetProcMode(void); + +//============================================================================ +// WAIT +//============================================================================ +/*---------------------------------------------------------------------------* + Name: i_osWaitCpuCycles + + Description: Loop and Wait for specified CPU cycles at least + + 150nsec - 30sec + + Arguments: cycles waiting CPU cycle + + Returns: None + *---------------------------------------------------------------------------*/ +void i_osWaitCpuCycles( OSCpuCycle cycle ); + +//============================================================================ +// TERMINATE and HALT +//============================================================================ +/*---------------------------------------------------------------------------* + Name: i_osTerminate + + Description: Halt CPU and loop + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +extern void i_osTerminate(void); + +/*---------------------------------------------------------------------------* + Name: i_osHalt + + Description: Halt CPU + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +extern void i_osHalt(void); + +/*---------------------------------------------------------------------------* + Name: i_osExit + + Description: Display exit string and Terminate. + This is useful for 'loadrun' tool command. + + Arguments: status : exit status + + Returns: -- (Never return) + *---------------------------------------------------------------------------*/ +extern void i_osExit(int status); + + +#endif /* SDK_ASM */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_OS_SYSTEM_H_ */ +#endif diff --git a/trunk/include/ctr/hw/ARM11/arm11_reg.h b/trunk/include/ctr/hw/ARM11/arm11_reg.h index 1ad5bf3..8a41877 100644 --- a/trunk/include/ctr/hw/ARM11/arm11_reg.h +++ b/trunk/include/ctr/hw/ARM11/arm11_reg.h @@ -25,8 +25,8 @@ extern "C" { #endif -#define HW_ARM11_CLOCK_MAX ? -#define HW_CPU_CLOCK_MAX HW_ARM11_CLOCK_MAX +#define HW_CPU_CLOCK_ARM11 (67027964 * 4) +#define HW_CPU_CLOCK HW_CPU_CLOCK_ARM11 #define HW_ARM11_IC_SIZE 0x4000 // Inst Cache #define HW_ARM11_DC_SIZE 0x4000 // Data Cache @@ -510,6 +510,55 @@ extern "C" { #define HW_C15_RGT_L1L2C_WB_WA 0x07 // L1C and L2C Write-Back, Allocate on Write +//---------------------------------------------------------------------- +// Timer and Watchdog +//---------------------------------------------------------------------- + +// Timer + +// Timer Control Register + +#define HW_CPUTM_ENABLE 0x00000001 // Global timer enable +#define HW_CPUTM_DISABLE 0x00000000 +#define HW_CPUTM_AUTO_RELOAD 0x00000002 // Auto-reload mode +#define HW_CPUTM_SINGLE_SHOT 0x00000000 // Single shot mode +#define HW_CPUTM_INTR_ENABLE 0x00000004 // Interrupt ID 29 enable +#define HW_CPUTM_PRESCALER_MASK 0x0000ff00 // Interval = (PRESCALER_value+1) x (Load_value+1) / CPU_clock + +#define HW_CPUTM_PRESCALER_SFT 8 + + +// Timer Interrupt Status Register + +#define HW_CPUTM_EVT_FLAG 0x00000001 // Timer Event occured + + +// Watchdog + +// Watchdog Control Register + +#define HW_CPUWD_ENABLE 0x00000001 // Global watchdog enable +#define HW_CPUWD_DISABLE 0x00000000 +#define HW_CPUWD_AUTO_RELOAD 0x00000002 // Auto-reload mode +#define HW_CPUWD_SINGLE_SHOT 0x00000000 // Single shot mode +#define HW_CPUWD_INTR_ENABLE 0x00000004 // Interrupt ID 30 enable +#define HW_CPUWD_WATCHDOG_MODE 0x00000008 // Watchdog mode (default) +#define HW_CPUWD_TIMER_MODE 0x00000000 // Timer mode +#define HW_CPUWD_PRESCALER_MASK 0x0000ff00 // Interval = (PRESCALER_value+1) x (Load_value+1) / CPU_clock + +#define HW_CPUWD_PRESCALER_SFT 8 + + +// Watchdog Interrupt Status Register + +#define HW_CPUWD_EVT_FLAG 0x00000001 // Watchdog Event occured + + +// Watchdog Reset Status Register + +#define HW_CPUWD_RESET 0x00000001 // Watchdog reset + + #ifdef __cplusplus } // extern "C" #endif diff --git a/trunk/include/ctr/hw/ARM9/arm9_reg.h b/trunk/include/ctr/hw/ARM9/arm9_reg.h index c38eff3..92780cc 100644 --- a/trunk/include/ctr/hw/ARM9/arm9_reg.h +++ b/trunk/include/ctr/hw/ARM9/arm9_reg.h @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------* Project: CtrFirm - HW - include - File: armArch.h + File: arm9_reg.h Copyright 2008 Nintendo. All rights reserved. @@ -25,15 +25,15 @@ extern "C" { #endif +#define HW_CPU_CLOCK_ARM9 (67027964 * 2) +#define HW_CPU_CLOCK HW_CPU_CLOCK_ARM9 + #define HW_ICACHE_SIZE 0x2000 // 命令キャッシュ #define HW_DCACHE_SIZE 0x1000 // データキャッシュ #define HW_CACHE_LINE_SIZE 32 #define HW_SYSTEM_CLOCK 33514000 // 正確には33513982? -#define HW_CPU_CLOCK_ARM9 67027964 -#define HW_CPU_CLOCK HW_CPU_CLOCK_ARM9 - //---------------------------------------------------------------------- // システムコントロールコプロセッサ