From 7404c14df94700b4d887457c06847d7c382da892 Mon Sep 17 00:00:00 2001 From: nakasima Date: Tue, 9 Dec 2008 12:03:57 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=83=AC=E3=83=83=E3=83=89=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA=E6=9A=AB=E5=AE=9A=E7=89=88?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=80=82=E3=81=97=E3=81=8B=E3=81=97?= =?UTF-8?q?=E3=83=87=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E3=81=AF=E3=83=87?= =?UTF-8?q?=E3=82=A3=E3=82=BB=E3=83=BC=E3=83=96=E3=83=AB=E3=81=AB=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@95 b871894f-2f95-9b40-918c-086798483c85 --- .../build/bootrom/ctr_bootrom/ARM11/main.c | 1 + .../build/bootrom/ctr_bootrom/ARM9/main.c | 1 + .../build/bootrom/teg-dev/ARM11/main.c | 1 + .../bootrom/build/bootrom/teg-dev/ARM9/main.c | 1 + trunk/bootrom/build/buildtools/commondefs | 4 +- trunk/bootrom/build/libraries/Makefile | 3 +- .../bootrom/build/libraries/os/ARM11/Makefile | 5 +- .../build/libraries/os/ARM11/os_interrupt.c | 5 +- .../build/libraries/os/ARM11/os_irqHandler.c | 9 +- .../bootrom/build/libraries/os/ARM9/Makefile | 5 +- .../build/libraries/os/ARM9/os_interrupt.c | 5 +- .../build/libraries/os/ARM9/os_irqHandler.c | 17 +- .../build/libraries/os/common/os_context.c | 240 ++ .../build/libraries/os/common/os_init.c | 38 +- .../build/libraries/os/common/os_system.c | 20 +- .../build/libraries/os/common/os_thread.c | 2077 +++++++++++++++++ trunk/bootrom/include/brom.h | 3 +- trunk/bootrom/include/brom/mi.h | 32 + trunk/bootrom/include/brom/mi/memory.h | 716 ++++++ trunk/bootrom/include/brom/os.h | 6 +- trunk/bootrom/include/brom/os/common/alarm.h | 231 ++ .../bootrom/include/brom/os/common/context.h | 8 +- trunk/bootrom/include/brom/os/common/init.h | 16 +- .../include/brom/os/common/interrupt_common.h | 2 +- trunk/bootrom/include/brom/os/common/mutex.h | 275 +++ trunk/bootrom/include/brom/os/common/system.h | 22 +- trunk/bootrom/include/brom/os/common/thread.h | 205 +- .../include/brom/os/{ARM9 => common}/tick.h | 6 +- .../brom/specfiles/ARM11.ldscript.template | 8 +- trunk/build/buildtools/commondefs.cctype.RVCT | 3 +- 30 files changed, 3777 insertions(+), 188 deletions(-) create mode 100644 trunk/bootrom/build/libraries/os/common/os_context.c create mode 100644 trunk/bootrom/build/libraries/os/common/os_thread.c create mode 100644 trunk/bootrom/include/brom/mi.h create mode 100644 trunk/bootrom/include/brom/mi/memory.h create mode 100644 trunk/bootrom/include/brom/os/common/alarm.h create mode 100644 trunk/bootrom/include/brom/os/common/mutex.h rename trunk/bootrom/include/brom/os/{ARM9 => common}/tick.h (93%) diff --git a/trunk/bootrom/build/bootrom/ctr_bootrom/ARM11/main.c b/trunk/bootrom/build/bootrom/ctr_bootrom/ARM11/main.c index 3ab6944..f2b63db 100644 --- a/trunk/bootrom/build/bootrom/ctr_bootrom/ARM11/main.c +++ b/trunk/bootrom/build/bootrom/ctr_bootrom/ARM11/main.c @@ -18,5 +18,6 @@ void BromMain( void ) { + osInitBROM(); } diff --git a/trunk/bootrom/build/bootrom/ctr_bootrom/ARM9/main.c b/trunk/bootrom/build/bootrom/ctr_bootrom/ARM9/main.c index b0f5c3d..54559b3 100644 --- a/trunk/bootrom/build/bootrom/ctr_bootrom/ARM9/main.c +++ b/trunk/bootrom/build/bootrom/ctr_bootrom/ARM9/main.c @@ -18,5 +18,6 @@ void BromSpMain( void ) { + osInitBROM(); } diff --git a/trunk/bootrom/build/bootrom/teg-dev/ARM11/main.c b/trunk/bootrom/build/bootrom/teg-dev/ARM11/main.c index e3b8e95..cb8864c 100644 --- a/trunk/bootrom/build/bootrom/teg-dev/ARM11/main.c +++ b/trunk/bootrom/build/bootrom/teg-dev/ARM11/main.c @@ -18,5 +18,6 @@ void BromMain( void ) { + osInitBROM(); } diff --git a/trunk/bootrom/build/bootrom/teg-dev/ARM9/main.c b/trunk/bootrom/build/bootrom/teg-dev/ARM9/main.c index e27d066..da560b3 100644 --- a/trunk/bootrom/build/bootrom/teg-dev/ARM9/main.c +++ b/trunk/bootrom/build/bootrom/teg-dev/ARM9/main.c @@ -18,5 +18,6 @@ void BromSpMain( void ) { + osInitBROM(); } diff --git a/trunk/bootrom/build/buildtools/commondefs b/trunk/bootrom/build/buildtools/commondefs index 14020e2..35bdfec 100644 --- a/trunk/bootrom/build/buildtools/commondefs +++ b/trunk/bootrom/build/buildtools/commondefs @@ -240,7 +240,7 @@ LDEPENDS_RES += $(BROM_BUILDTOOLSDIR)/commondefs ifeq ($(CODEGEN_PROC),ARM11) BROM_LIBS_BASE ?= \ -# libos \ + libos \ ifdef BROM_PROFILE_TYPE BROM_LIBS_BASE += libos.$(BROM_PROFILE_TYPE) @@ -249,7 +249,7 @@ endif else # ($(CODEGEN_PROC),ARM9) BROM_LIBS_BASE ?= \ -# libos_sp \ + libos_sp \ ifdef BROM_PROFILE_TYPE BROM_LIBS_BASE += libos_sp.$(BROM_PROFILE_TYPE) diff --git a/trunk/bootrom/build/libraries/Makefile b/trunk/bootrom/build/libraries/Makefile index 973826e..d06f63a 100644 --- a/trunk/bootrom/build/libraries/Makefile +++ b/trunk/bootrom/build/libraries/Makefile @@ -21,7 +21,8 @@ include $(CTRBROM_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- SUBDIRS = \ - init \ + init \ + os \ #---------------------------------------------------------------------------- diff --git a/trunk/bootrom/build/libraries/os/ARM11/Makefile b/trunk/bootrom/build/libraries/os/ARM11/Makefile index 4d8caf7..8247231 100644 --- a/trunk/bootrom/build/libraries/os/ARM11/Makefile +++ b/trunk/bootrom/build/libraries/os/ARM11/Makefile @@ -28,14 +28,15 @@ BROM_CODEGEN_ALL ?= TRUE SRCDIR = . ../common SRCS = \ + os_thread.c \ + os_context.c \ + os_init.c \ os_system.c \ os_timer.c \ os_irqHandler.c \ os_interrupt.c \ os_interrupt_common.c \ -# os_init.c \ - TARGET_LIB = libos$(BROM_LIBSUFFIX).a include $(CTRBROM_ROOT)/build/buildtools/commondefs diff --git a/trunk/bootrom/build/libraries/os/ARM11/os_interrupt.c b/trunk/bootrom/build/libraries/os/ARM11/os_interrupt.c index 6c201a5..2292e17 100644 --- a/trunk/bootrom/build/libraries/os/ARM11/os_interrupt.c +++ b/trunk/bootrom/build/libraries/os/ARM11/os_interrupt.c @@ -39,9 +39,10 @@ void osInitInterrupt( void ) (void)osDisableIrqAndFiq(); - osInitInterruptTable(); + i_osInitInterruptTable(); - *(u64*)HW_INTR_VENEER_BUF = *(u64*)i_osIrqVeneer; + ((u32*)HW_INTR_VENEER_BUF)[0] = ((u32*)i_osIrqVeneer)[0]; + ((u32*)HW_INTR_VENEER_BUF)[1] = ((u32*)i_osIrqVeneer)[1]; { u32 num = OS_INTR_ID_NUM; diff --git a/trunk/bootrom/build/libraries/os/ARM11/os_irqHandler.c b/trunk/bootrom/build/libraries/os/ARM11/os_irqHandler.c index b4f29ce..af874a5 100644 --- a/trunk/bootrom/build/libraries/os/ARM11/os_irqHandler.c +++ b/trunk/bootrom/build/libraries/os/ARM11/os_irqHandler.c @@ -17,6 +17,8 @@ #include #include +//#define BROM_ENABLE_THREAD + extern OSIntrFunction osIntrTable[OS_INTR_ID_NUM]; //---- thread queue for interrupt @@ -54,7 +56,7 @@ asm void osIrqHandler( void ) // get jump vector ldr r1, =osIntrTable ldr r0, [ r1, r0, LSL #2 ] - + adr lr, irq_return bx r0 // set return address for thread rescheduling @@ -63,13 +65,17 @@ irq_return ldr lr, =REG_CPUI_EOI_ADDR str r4, [lr] +#ifdef BROM_ENABLE_THREAD bl osIrqHandler_ThreadSwitch +#endif // BROM_ENABLE_THREAD my_undefined_interrupt_1 ldmfd sp!, { lr } ldmfd sp!, { r0-r3,r12,pc } // return to interrupted address } +#ifdef BROM_ENABLE_THREAD + /*---------------------------------------------------------------------------* Name: OS_IRQHandler_ThreadSwitch @@ -225,3 +231,4 @@ LSYM(13) ldmfd sp!, { pc } // return to irq master handler } +#endif // BROM_ENABLE_THREAD diff --git a/trunk/bootrom/build/libraries/os/ARM9/Makefile b/trunk/bootrom/build/libraries/os/ARM9/Makefile index 8c699f7..6ef0aae 100644 --- a/trunk/bootrom/build/libraries/os/ARM9/Makefile +++ b/trunk/bootrom/build/libraries/os/ARM9/Makefile @@ -31,6 +31,9 @@ BROM_PROC = ARM9 SRCDIR = . ../common SRCS = \ + os_thread.c \ + os_context.c \ + os_init.c \ os_system.c \ os_timer.c \ os_tick.c \ @@ -38,8 +41,6 @@ SRCS = \ os_interrupt.c \ os_interrupt_common.c \ -# os_init.c \ - TARGET_LIB = libos_sp$(BROM_LIBSUFFIX).a diff --git a/trunk/bootrom/build/libraries/os/ARM9/os_interrupt.c b/trunk/bootrom/build/libraries/os/ARM9/os_interrupt.c index eef8648..0ecf6c8 100644 --- a/trunk/bootrom/build/libraries/os/ARM9/os_interrupt.c +++ b/trunk/bootrom/build/libraries/os/ARM9/os_interrupt.c @@ -41,7 +41,8 @@ void osInitInterrupt( void ) i_osInitInterruptTable(); - *(u64*)HW_INTR_VENEER_BUF = *(u64*)i_osIrqVeneer; + ((u32*)HW_INTR_VENEER_BUF)[0] = ((u32*)i_osIrqVeneer)[0]; + ((u32*)HW_INTR_VENEER_BUF)[1] = ((u32*)i_osIrqVeneer)[1]; reg_OS_IE = 0; @@ -387,7 +388,7 @@ void osWaitInterrupt( BOOL clear, OSIntrMask irqFlags ) while (!(osGetInterruptCheckFlag() & irqFlags)) { - i_osHalt(); + osHalt(); (void)osEnableInterrupts(); (void)osDisableInterrupts(); } diff --git a/trunk/bootrom/build/libraries/os/ARM9/os_irqHandler.c b/trunk/bootrom/build/libraries/os/ARM9/os_irqHandler.c index 6e3ef71..ff245ec 100644 --- a/trunk/bootrom/build/libraries/os/ARM9/os_irqHandler.c +++ b/trunk/bootrom/build/libraries/os/ARM9/os_irqHandler.c @@ -17,6 +17,7 @@ #include #include +//#define BROM_ENABLE_THREAD #ifdef SDK_ARM9 #include @@ -83,11 +84,21 @@ LSYM(1) clz r0, r1 // count zero of high bit // get jump vector ldr r1, =osIntrTable ldr r0, [ r1, r0, LSL #2 ] - - ldr lr, =osIrqHandler_ThreadSwitch + + adr lr, irq_return bx r0 // set return address for thread rescheduling + +irq_return +#ifdef BROM_ENABLE_THREAD + bl osIrqHandler_ThreadSwitch +#endif // BROM_ENABLE_THREAD + + ldmfd sp!, { lr } + ldmfd sp!, { r0-r3,r12,pc } // return to interrupted address } +#ifdef BROM_ENABLE_THREAD + /*---------------------------------------------------------------------------* Name: OS_IRQHandler_ThreadSwitch @@ -244,6 +255,8 @@ LSYM(13) ldmfd sp!, { pc } // return to irq master handler } +#endif // BROM_ENABLE_THREAD + #ifdef SDK_ARM9 #include #endif diff --git a/trunk/bootrom/build/libraries/os/common/os_context.c b/trunk/bootrom/build/libraries/os/common/os_context.c new file mode 100644 index 0000000..faf7101 --- /dev/null +++ b/trunk/bootrom/build/libraries/os/common/os_context.c @@ -0,0 +1,240 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - libraries - OS + File: os_context.c + + 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$ + *---------------------------------------------------------------------------*/ +#include + +#define osPrintf(...) ((void)0) + +/*---------------------------------------------------------------------------* + Name: osInitContext + + Description: Initialize context + + Arguments: context context to be initialized + newpc program counter + newsp stack pointer + + Returns: none + *---------------------------------------------------------------------------*/ +#include +asm void osInitContext( + register OSContext* context, + register u32 newpc, + register u32 newsp + ) +{ +#define context r0 +#define newpc r1 +#define newsp r2 + + // ---- 実行位置保存 (r0 = context) + add newpc, newpc, #4 + str newpc, [ context, #OS_CONTEXT_PC_PLUS4 ] + + // ---- スタック保存 +#ifdef SDK_CONTEXT_HAS_SP_SVC + str newsp, [ context, #OS_CONTEXT_SP_SVC ] + sub newsp, newsp, #HW_BROM_SVC_STACK_SIZE +#endif + tst newsp, #4 + subne newsp, newsp, #4 // for 8byte-alignment + str newsp, [ context, #OS_CONTEXT_SP ] + + // ---- ステータス作成 + ands r1, newpc, #1 + movne r1, #HW_PSR_SYS_MODE|HW_PSR_THUMB_STATE + moveq r1, #HW_PSR_SYS_MODE|HW_PSR_ARM_STATE + str r1, [ context, #OS_CONTEXT_CPSR ] + + // ---- 他のレジスタをクリア + mov r1, #0 + str r1, [ context, #OS_CONTEXT_R0 ] + str r1, [ context, #OS_CONTEXT_R1 ] + str r1, [ context, #OS_CONTEXT_R2 ] + str r1, [ context, #OS_CONTEXT_R3 ] + str r1, [ context, #OS_CONTEXT_R4 ] + str r1, [ context, #OS_CONTEXT_R5 ] + str r1, [ context, #OS_CONTEXT_R6 ] + str r1, [ context, #OS_CONTEXT_R7 ] + str r1, [ context, #OS_CONTEXT_R8 ] + str r1, [ context, #OS_CONTEXT_R9 ] + str r1, [ context, #OS_CONTEXT_R10 ] + str r1, [ context, #OS_CONTEXT_R11 ] + str r1, [ context, #OS_CONTEXT_R12 ] + str r1, [ context, #OS_CONTEXT_LR ] + + bx lr // start here and swicth arm/thumb mode + +#undef context +#undef newpc +#undef newsp +} + +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif +/*---------------------------------------------------------------------------* + Name: osSaveContext + + Description: Save current context into specified memory + + Arguments: context pointer to the memory to be stored the current context + + Returns: 0 saving a context (normal) + 1 if context are reloaded via osLoadContext + *---------------------------------------------------------------------------*/ +asm BOOL osSaveContext( register OSContext* context ) +{ +#if 0 // defined(SDK_ARM9) + stmfd sp!, { lr, r0 } + add r0, r0, #OS_CONTEXT_CP_CONTEXT + ldr r1, =CP_SaveContext + blx r1 + ldmfd sp!, { lr, r0 } +#endif + + add r1, r0, #OS_CONTEXT_CPSR + + //---- Save CPSR + mrs r2, cpsr + str r2, [ r1 ], #OS_CONTEXT_R0-OS_CONTEXT_CPSR // r1 moved to context.r0 + +#ifdef SDK_CONTEXT_HAS_SP_SVC + //---- Save SP_svc + mov r0, #HW_PSR_SVC_MODE|HW_PSR_IRQ_DISABLE|HW_PSR_FIQ_DISABLE|HW_PSR_ARM_STATE + msr cpsr_c, r0 + str sp, [ r1, #OS_CONTEXT_SP_SVC - OS_CONTEXT_R0 ] + msr cpsr_c, r2 +#endif + + //---- Save others + mov r0, #1 // return value via osLoadContext + stmia r1, {r0-r14} // save R0-R14 + add r0, pc, #8 // set PC_plus4 to do ("bx lr" + 4) + str r0, [r1, #OS_CONTEXT_PC_PLUS4 - OS_CONTEXT_R0 ] + + mov r0, #0 // regular return value + bx lr +} + + +#define OFFSETOF(x,y) (int)(&(((x*)0)->y)) + +/*---------------------------------------------------------------------------* + Name: osLoadContext + + Description: Reload specified context as current context + + Arguments: context pointer to the memory to switch to the context + + Returns: None + *---------------------------------------------------------------------------*/ +asm void osLoadContext( register OSContext* context ) +{ +#if OS_CONTEXT_CPSR != 0 +#pragma message(has changed!!!) + add r0, r0, #OS_CONTEXT_CPSR +#endif + +#if 0 // defined(SDK_ARM9) + // call CPi_RestoreContext + stmfd sp!, { lr, r0 } + add r0, r0, #OS_CONTEXT_CP_CONTEXT + + ldr r1, =CPi_RestoreContext + blx r1 + ldmfd sp!, { lr, r0 } +#endif + + //---- モードを svc に + mrs r1, cpsr + bic r1, r1, #HW_PSR_CPU_MODE_MASK + orr r1, r1, #HW_PSR_SVC_MODE|HW_PSR_IRQ_DISABLE|HW_PSR_FIQ_DISABLE + msr cpsr_c, r1 + + //---- Load cpcr to spsr + ldr r1, [ r0 ], #OS_CONTEXT_R0-OS_CONTEXT_CPSR + msr spsr_fsxc, r1 + +#ifdef SDK_CONTEXT_HAS_SP_SVC + //---- Load SP_svc + ldr sp, [ r0, #OS_CONTEXT_SP_SVC - OS_CONTEXT_R0 ] +#endif + + //---- Load r0-r14 + ldr lr, [ r0, #OS_CONTEXT_PC_PLUS4 - OS_CONTEXT_R0 ] + ldmia r0, { r0 - r14 }^ + nop + +#if defined(SDK_ARM9) +#if 0 // don't need, because still spend more than 34 cycle for divider. + //---- CP_WaitDiv + stmfd sp!, { r0-r1 } + ldr r0, =REG_DIVCNT_ADDR +@00: + ldr r1, [r0] + and r1, r1, #REG_CP_DIVCNT_BUSY_MASK + bne @00 + ldmfd sp!, { r0-r1 } +#endif +#endif + + //---- Switch cpsr and Jump to (context->pc_plus4 - 4) + subs pc, lr, #4 +} +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif + +#include + + +/*---------------------------------------------------------------------------* + Name: osDumpContext + + Description: Performs exception initialization. + - installs the first level exception handlers + - set up exception table and common exception handler + + Arguments: installDBIntegrator if TRUE, copy OSDBIntegrator into + low memory. + + Returns: None. + *---------------------------------------------------------------------------*/ +void osDumpContext(OSContext *context) +{ +#ifndef SDK_FINALROM + s32 i; + + osPrintf("context=%08x\n", context); + if (context) + { + osPrintf("CPSR %08x\n", context->cpsr); + for (i = 0; i < 13; i++) + { + osPrintf("R%02d %08x\n", i, context->r[i]); + } + osPrintf("SP %08x\n", context->sp); + osPrintf("LR %08x\n", context->lr); + osPrintf("PC+4 %08x\n", context->pc_plus4); +#ifdef SDK_CONTEXT_HAS_SP_SVC + osPrintf("SPsvc %08x\n", context->sp_svc); +#endif + } +#else + (void)context; // avoiding to unused warning +#endif +} diff --git a/trunk/bootrom/build/libraries/os/common/os_init.c b/trunk/bootrom/build/libraries/os/common/os_init.c index 2ba86c0..f7eca23 100644 --- a/trunk/bootrom/build/libraries/os/common/os_init.c +++ b/trunk/bootrom/build/libraries/os/common/os_init.c @@ -17,7 +17,7 @@ #include //#define BROM_DEBUG_ITCM -#define FIRM_ENABLE_JTAG_AT_INIT +//#define FIRM_ENABLE_JTAG_AT_INIT /*---------------------------------------------------------------------------* @@ -41,7 +41,7 @@ void osInitBROM(void) //---- Init Exception System // the exception vecter of ARM9 is in the noninitialized main memory. - osInitException(); +// osInitException(); #endif // SDK_ARM7 @@ -71,41 +71,9 @@ void osInit(void) #endif // SDK_ARM7 //---- Init Exception System - osInitException(); +// osInitException(); //---- Init Interrupt osInitInterrupt(); } -#ifdef SDK_ARM9 - -/*---------------------------------------------------------------------------* - Name: OSi_EnableCpuJTAG - - Description: enable jtag of cpu - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void OSi_EnableCpuJTAG(void) -{ - reg_CFG_CPU_JTAG = REG_CFG_CPU_JTAG_E_MASK | REG_CFG_CPU_JTAG_A7_MASK; -} - -/*---------------------------------------------------------------------------* - Name: OSi_EnableDspJTAG - - Description: enable jtag of dsp - - Arguments: None - - Returns: None - *---------------------------------------------------------------------------*/ -void OSi_EnableDspJTAG(void) -{ - reg_CFG_DSP_JTAG = REG_CFG_DSP_JTAG_E_MASK; -} - -#endif // SDK_ARM9 - diff --git a/trunk/bootrom/build/libraries/os/common/os_system.c b/trunk/bootrom/build/libraries/os/common/os_system.c index 4b6d892..a99c37b 100644 --- a/trunk/bootrom/build/libraries/os/common/os_system.c +++ b/trunk/bootrom/build/libraries/os/common/os_system.c @@ -23,7 +23,7 @@ // PROCESSER MODE //============================================================================ /*---------------------------------------------------------------------------* - Name: i_osGetProcMode + Name: osGetProcMode Description: Get processor mode from CPSR @@ -32,7 +32,7 @@ Returns: CPU processor mode (field 0x10-0x1f) *---------------------------------------------------------------------------*/ #include -ASM OSProcMode i_osGetProcMode( void ) +ASM OSProcMode osGetProcMode( void ) { mrs r0, cpsr and r0, r0, #HW_PSR_CPU_MODE_MASK @@ -68,7 +68,7 @@ LSYM(1) // TERMINATE and HALT //============================================================================ /*---------------------------------------------------------------------------* - Name: i_osTerminate + Name: osTerminate Description: Halt CPU and loop @@ -76,17 +76,17 @@ LSYM(1) Returns: -- (Never return) *---------------------------------------------------------------------------*/ -void i_osTerminate(void) +void osTerminate(void) { while (1) { (void)osDisableInterrupts(); - i_osHalt(); + osHalt(); } } /*---------------------------------------------------------------------------* - Name: i_osHalt + Name: osHalt Description: Halt CPU @@ -95,7 +95,7 @@ void i_osTerminate(void) Returns: None *---------------------------------------------------------------------------*/ #include -ASM void i_osHalt( void ) +ASM void osHalt( void ) { mov r0, #0 mcr p15, 0, r0, c7, c0, 4 @@ -104,7 +104,7 @@ ASM void i_osHalt( void ) #include /*---------------------------------------------------------------------------* - Name: i_osExit + Name: osExit Description: Display exit string and Terminate. This is useful for 'loadrun' tool command. @@ -113,12 +113,12 @@ ASM void i_osHalt( void ) Returns: -- (Never return) *---------------------------------------------------------------------------*/ -void i_osExit(int status) +void osExit(int status) { #ifdef SDK_FINALROM #pragma unused( status ) #endif (void)osDisableInterrupts(); osTPrintf("\n" OS_EXIT_STRING, status); - i_osTerminate(); + osTerminate(); } diff --git a/trunk/bootrom/build/libraries/os/common/os_thread.c b/trunk/bootrom/build/libraries/os/common/os_thread.c new file mode 100644 index 0000000..8e32576 --- /dev/null +++ b/trunk/bootrom/build/libraries/os/common/os_thread.c @@ -0,0 +1,2077 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - libraries - OS + File: os_init.c + + 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$ + *---------------------------------------------------------------------------*/ +#include + +#define osPrintf(...) ((void)0) +#define osTPrintf(...) ((void)0) +#define OSi_Panic(...) ((void)0) + +//--------------------------------------------------------------------------- + +extern unsigned long SDK_SYS_STACKSIZE[]; +extern unsigned long SDK_IRQ_STACKSIZE[]; +#define OSi_SYS_STACKSIZE ((s32)SDK_SYS_STACKSIZE) +#define OSi_IRQ_STACKSIZE ((s32)SDK_IRQ_STACKSIZE) + +//---- Stack CheckNumber +#ifdef SDK_ARM9 +# define OSi_STACK_CHECKNUM_BOTTOM 0xfddb597dUL +# define OSi_STACK_CHECKNUM_TOP 0x7bf9dd5bUL +# define OSi_STACK_CHECKNUM_WARN 0x597dfbd9UL +#else // SDK_ARM11 +# define OSi_STACK_CHECKNUM_BOTTOM 0xd73bfdf7UL +# define OSi_STACK_CHECKNUM_TOP 0xfbdd37bbUL +# define OSi_STACK_CHECKNUM_WARN 0xbdf7db3dUL +#endif + +//---- defs for launcher thread stack +#ifdef SDK_ARM9 +extern void *Load$$DTCM$$Base; +# define OSi_LAUNCHER_STACK_LO_DEFAULT (Load$$DTCM$$Base) +#else // SDK_ARM11 +# define OSi_LAUNCHER_STACK_LO_DEFAULT HW_AXI_WRAM +#endif +# define OSi_LAUNCHER_STACK_HI_MAX (HW_BROM_SVC_STACK - OSi_IRQ_STACKSIZE) +# define OSi_LAUNCHER_STACK_BOTTOM (HW_BROM_SVC_STACK - OSi_IRQ_STACKSIZE) + +//---- defs for idle thread +// for checkNumber and SVC stack (if defined) +#ifdef SDK_CONTEXT_HAS_SP_SVC +#define OSi_IDLE_CHECKNUM_SIZE ( sizeof(u32)*2 + HW_BROM_SVC_STACK_SIZE ) +#else +#define OSi_IDLE_CHECKNUM_SIZE ( sizeof(u32)*2 ) +#endif +// for SVC to stack out registers +#ifdef SDK_ARM9 +#define OSi_IDLE_SVC_SIZE ( sizeof(u32)*32 ) // arm9 svc stacks 14 words and makes in 8byte-alignment +#else // SDK_ARM11 +#define OSi_IDLE_SVC_SIZE ( sizeof(u32)*16 ) // arm7 svc stacks 14 words +#endif +// stack size of idle thread +#define OSi_IDLE_THREAD_STACK_SIZE ( OSi_IDLE_CHECKNUM_SIZE + OSi_IDLE_SVC_SIZE ) + +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif +//---- threads +OSThread OSi_LauncherThread; +OSThread OSi_IdleThread; + +//---- thread information +OSThreadInfo OSi_ThreadInfo; + +//---- current thread pointer (for quick reference) +OSThread **OSi_CurrentThreadPtr; +#define OSi_GetCurrentThread() (*OSi_CurrentThreadPtr) + +//---- thread initialization flag +BOOL OSi_IsThreadInitialized = FALSE; + +//---- idle thread stack +u32 OSi_IdleThreadStack[OSi_IDLE_THREAD_STACK_SIZE / sizeof(u32)]; + +//---- system callback in switch thread ( maybe for profile ) +void *OSi_SystemCallbackInSwitchThread = NULL; + +//---- reschedule counter. if value>=0, do not reschedule. +u32 OSi_RescheduleCount = 0; +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif + +#ifdef SDK_THREAD_INFINITY +//---- thread id count +static int OSi_ThreadIdCount = 0; +#endif + +void *OSi_StackForDestructor = NULL; + + +#ifndef SDK_THREAD_INFINITY +static int OSi_SearchFreeEntry(void); +#endif +static void OSi_CancelThreadAlarmForSleep(OSThread *thread); +static void OSi_InsertThreadToList(OSThread *thread); +static void OSi_RemoveThreadFromList(OSThread *thread); +static void OSi_SleepAlarmCallback(void *arg); +static void OSi_IdleThreadProc(void *); +void OSi_SetSystemCallbackInSwitchThread(void *callback); + +static void OSi_ExitThread_ArgSpecified(OSThread *thread, void *arg); +static void OSi_ExitThread(void *arg); +static void OSi_ExitThread_Destroy(void); + +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif +static void OSi_RescheduleThread(void); + +#ifdef SDK_THREAD_INFINITY +/*---------------------------------------------------------------------------* + Name: OSi_GetUnusedThreadId + + Description: get unused thread id + + Arguments: None + + Returns: thread id (0-0x7fffffff) which is never used. + *---------------------------------------------------------------------------*/ +static int OSi_GetUnusedThreadId(void) +{ + ++OSi_ThreadIdCount; + SDK_ASSERT(OSi_ThreadIdCount > 0); // overflow check + return OSi_ThreadIdCount; +} +#endif /* ; */ + +/*---------------------------------------------------------------------------* + Name: OSi_InsertLinkToQueue + + Description: insert thread to thread queue + + Arguments: queue : thread queue + thread : thread to insert + + Returns: None + *---------------------------------------------------------------------------*/ +static void OSi_InsertLinkToQueue(OSThreadQueue *queue, OSThread *thread) +{ + OSThread *next = queue->head; + + while (next && next->priority <= thread->priority) + { + if (next == thread) + { + return; + } + next = next->link.next; + } + + if (!next) + { + OSThread *prev = queue->tail; + + if (!prev) + { + queue->head = thread; + } + else + { + prev->link.next = thread; + } + + thread->link.prev = prev; + thread->link.next = NULL; + queue->tail = thread; + } + else + { + OSThread *prev = next->link.prev; + + if (!prev) + { + queue->head = thread; + } + else + { + prev->link.next = thread; + } + + thread->link.prev = prev; + thread->link.next = next; + next->link.prev = thread; + } +} + +/*---------------------------------------------------------------------------* + Name: OSi_RemoveLinkFromQueue + + Description: remove head thread from thread queue + + Arguments: queue : thread queue + + Returns: thread pointer which is removed + *---------------------------------------------------------------------------*/ +static OSThread *OSi_RemoveLinkFromQueue(OSThreadQueue *queue) +{ + OSThread *t = queue->head; + + if (t) + { + OSThread *next = t->link.next; + + queue->head = next; + + if (next) + { + next->link.prev = NULL; + } + else + { + queue->tail = NULL; + t->queue = NULL; + } + } + + return t; +} + +/*---------------------------------------------------------------------------* + Name: OSi_RemoveSpecifiedLinkFromQueue + + Description: remove specified thread from thread queue + + Arguments: queue : thread queue + + Returns: thread pointer which is removed + *---------------------------------------------------------------------------*/ +static OSThread *OSi_RemoveSpecifiedLinkFromQueue(OSThreadQueue *queue, OSThread *thread) +{ + OSThread *t = queue->head; + OSThread *next; + OSThread *prev; + + while (t) + { + next = t->link.next; + + if (t == thread) + { + prev = t->link.prev; + + //---- whether if head link + if (queue->head == t) + { + queue->head = next; + } + else + { + prev->link.next = next; + } + + //---- whether if tail link + if (queue->tail == t) + { + queue->tail = prev; + } + else + { + next->link.prev = prev; + } + + break; + } + + t = next; + } + + return t; +} + +/*---------------------------------------------------------------------------* + Name: OSi_RemoveMutexLinkFromQueue + + Description: remove mutex from mutex queue + + Arguments: queue : mutex queue + + Returns: mutex pointer which is removed + *---------------------------------------------------------------------------*/ +OSMutex *OSi_RemoveMutexLinkFromQueue(OSMutexQueue * queue) +{ + OSMutex *t = queue->head; + + if (t) + { + OSMutex *next = t->link.next; + + queue->head = next; + + if (next) + { + next->link.prev = NULL; + } + else + { + queue->tail = NULL; + } + } + + return t; +} + +/*---------------------------------------------------------------------------* + Name: OSi_SetSystemCallbackInSwitchThread + + Description: set system callback in switching thread + + Arguments: callback + + Returns: None + *---------------------------------------------------------------------------*/ +void OSi_SetSystemCallbackInSwitchThread(void *callback) +{ + OSi_SystemCallbackInSwitchThread = callback; +} + +#ifndef SDK_THREAD_INFINITY +/*---------------------------------------------------------------------------* + Name: OSi_SearchFreeEntry + + Description: search free thread entry area + + Arguments: None + + Returns: 0 - OS_THREAD_MAX_NUM-1 ... entry index + -1 ... not found + *---------------------------------------------------------------------------*/ +static int OSi_SearchFreeEntry(void) +{ + int i; + + for (i = 0; i < OS_THREAD_MAX_NUM; i++) + { + if (!OSi_ThreadInfo.entry[i]) + { + return i; + } + } + return -1; // not found +} +#endif + +/*---------------------------------------------------------------------------* + Name: OSi_InsertThreadToList + + Description: insert thread to thread list which is arranged by priority + + Arguments: pointer of thread + + Returns: None + *---------------------------------------------------------------------------*/ +static void OSi_InsertThreadToList(OSThread *thread) +{ + OSThread *t = OSi_ThreadInfo.list; + OSThread *pre = NULL; + + while (t && t->priority < thread->priority) + { + pre = t; + t = t->next; + } + + if (!pre) + { + thread->next = OSi_ThreadInfo.list; + OSi_ThreadInfo.list = thread; + } + else + { + thread->next = pre->next; + pre->next = thread; + } +} + +/*---------------------------------------------------------------------------* + Name: OSi_RemoveThreadFromList + + Description: remove thread from thread list + + Arguments: pointer of thread + + Returns: None + *---------------------------------------------------------------------------*/ +static void OSi_RemoveThreadFromList(OSThread *thread) +{ + OSThread *t = OSi_ThreadInfo.list; + OSThread *pre = NULL; + + while (t && t != thread) + { + pre = t; + t = t->next; + } + + SDK_ASSERTMSG(t, "Cannot remove thread from list."); + + if (!pre) + { + OSi_ThreadInfo.list = thread->next; + } + else + { + pre->next = thread->next; + } +} + +/*---------------------------------------------------------------------------* + Name: OSi_RescheduleThread + + Description: Switch to the runnable thread highest priority + without interrupts disabled. + + Arguments: None + + Returns: None or Never return + *---------------------------------------------------------------------------*/ +static void OSi_RescheduleThread(void) +{ + //---- if scheduler is set to be disabled, do nothing. + if (OSi_RescheduleCount <= 0) + { + OSThreadInfo *info = &OSi_ThreadInfo; + if (info->irqDepth > 0 || osGetProcMode() == OS_PROCMODE_IRQ) + { + // If in IRQ, do rescheduling at end of IRQ handler + info->isNeedRescheduling = TRUE; + } + else + { + OSThread *currentThread, *nextThread; + currentThread = OSi_GetCurrentThread(); + nextThread = osSelectThread(); + + if (currentThread == nextThread || !nextThread) // maybe nextThread != NULL + { + return; // Don't have to switch the current context + } + + if (currentThread->state != OS_THREAD_STATE_TERMINATED + && osSaveContext(¤tThread->context)) + { + return; // Return if go back via osLoadContext + } + + //---- call thread switch callback for system + if (OSi_SystemCallbackInSwitchThread) + { + ((OSSwitchThreadCallback)OSi_SystemCallbackInSwitchThread) (currentThread, + nextThread); + } + + //---- call thread switch callback for user + if (info->switchCallback) + { + ((OSSwitchThreadCallback)info->switchCallback) (currentThread, nextThread); + } + + osSetCurrentThread(nextThread); + + osLoadContext(&nextThread->context); + // Never reached + } + } +} + +/*---------------------------------------------------------------------------* + Name: osInitThread + + Description: Initialize thread system + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osInitThread(void) +{ + void *stackLo; +#ifndef SDK_THREAD_INFINITY + int i; +#endif + + if (OSi_IsThreadInitialized) + { + return; + } + OSi_IsThreadInitialized = TRUE; + +#ifndef SDK_THREAD_INFINITY + //---- Set thread info + for (i = 0; i < OS_THREAD_MAX_NUM; i++) + { + OSi_ThreadInfo.entry[i] = NULL; + } +#endif + + //---- set pointer to current thread buffer + // (for quick reference) + OSi_CurrentThreadPtr = &(OSi_ThreadInfo.current); + + //---- Setup launcher thread + OSi_LauncherThread.priority = OS_THREAD_LAUNCHER_PRIORITY; + OSi_LauncherThread.id = 0; + OSi_LauncherThread.state = OS_THREAD_STATE_READY; + OSi_LauncherThread.next = NULL; + + //---- clear profile pointer + OSi_LauncherThread.profiler = NULL; + + //---- clear thread entry and listPtr +#ifndef SDK_THREAD_INFINITY + OSi_ThreadInfo.entry[0] = &OSi_LauncherThread; +#endif + OSi_ThreadInfo.list = &OSi_LauncherThread; + + //---- let launch thread be current + osSetCurrentThread(&OSi_LauncherThread); + + //---- StackLo + stackLo = (OSi_SYS_STACKSIZE <= 0) ? + (void *)((u32)OSi_LAUNCHER_STACK_LO_DEFAULT - OSi_SYS_STACKSIZE) : + (void *)((u32)OSi_LAUNCHER_STACK_HI_MAX - OSi_SYS_STACKSIZE); + SDK_ASSERT((u32)OSi_LAUNCHER_STACK_LO_DEFAULT <= (u32)stackLo + && (u32)stackLo <= (u32)OSi_LAUNCHER_STACK_HI_MAX); + + //---- set Stack Bottom & Top + OSi_LauncherThread.stackBottom = (u32)OSi_LAUNCHER_STACK_BOTTOM; + OSi_LauncherThread.stackTop = (u32)stackLo; + OSi_LauncherThread.stackWarningOffset = 0; + + //---- Set Stack CheckNumber + *(u32 *)(OSi_LauncherThread.stackBottom - sizeof(u32)*2) = OSi_STACK_CHECKNUM_BOTTOM; + *(u32 *)OSi_LauncherThread.stackTop = OSi_STACK_CHECKNUM_TOP; + + //---- clear join queue + osInitThreadQueue(&OSi_LauncherThread.joinQueue); + +#ifndef SDK_THREAD_INFINITY + //---- max number of thread + OSi_ThreadInfo.max_entry = OS_THREAD_MAX_NUM; +#endif + + //---- around IRQ + OSi_ThreadInfo.isNeedRescheduling = FALSE; + OSi_ThreadInfo.irqDepth = 0; + SDK_ASSERTMSG(OSi_IRQ_STACKSIZE > 0, "IRQ STACKSIZE must be >0"); + + //---- store thread info pointer +#if 0 // for ISD +#ifdef SDK_ARM9 + osGetSystemWork()->threadinfo_mainp = &OSi_ThreadInfo; +#else + osGetSystemWork()->threadinfo_subp = &OSi_ThreadInfo; +#endif +#endif + + //---- set thread switch callback + (void)osSetSwitchThreadCallback(NULL); + + //---- idle thread + osCreateThread(&OSi_IdleThread, + OSi_IdleThreadProc, + (void *)NULL, + OSi_IdleThreadStack + OSi_IDLE_THREAD_STACK_SIZE / sizeof(u32), + OSi_IDLE_THREAD_STACK_SIZE, + OS_THREAD_PRIORITY_MAX /*pseudo. change at next line. */ ); + OSi_IdleThread.priority = OS_THREAD_PRIORITY_MAX + 1; // lower priority than the lowest (=OS_THREAD_PRIORITY_MAX) + OSi_IdleThread.state = OS_THREAD_STATE_READY; +} + +/*---------------------------------------------------------------------------* + Name: osIsThreadAvailable + + Description: check if thread system is available + + Arguments: None + + Returns: TRUE if available, FALSE if not + *---------------------------------------------------------------------------*/ +#include +asm BOOL osIsThreadAvailable( void ) +{ + INASM_EXTERN( OSi_IsThreadInitialized ) + + ldr r0, =OSi_IsThreadInitialized + ldr r0, [r0, #0] + bx lr +} +#include + +/*---------------------------------------------------------------------------* + Name: osCreateThread + + Description: Creates a new thread + + Arguments: thread pointer of thread structure + func function to start thread + arg argument for func + stack stack bottom address + stackSize stack size (byte. must be aligned by 4) + prio thread priority + + Returns: None + *---------------------------------------------------------------------------*/ +void osCreateThread(OSThread *thread, + void (*func) (void *), void *arg, void *stack, u32 stackSize, u32 prio) +{ +#define STACK_ALIGN 4 + + OSIntrMode enable; + int index; + + SDK_ASSERTMSG(OSi_GetCurrentThread(), "thread system were not initialized"); + SDK_ASSERTMSG(OS_THREAD_PRIORITY_MIN <= prio + && prio <= OS_THREAD_PRIORITY_MAX, "invalid priority"); + SDK_ASSERTMSG(stackSize % STACK_ALIGN == 0, "stack size must be aligned by %d", STACK_ALIGN); + SDK_ASSERTMSG((u32)stack % STACK_ALIGN == 0, "stack must be aligned by %d", STACK_ALIGN); + + enable = osDisableInterrupts(); + +#ifndef SDK_THREAD_INFINITY + //---- search free entry + if ((index = OSi_SearchFreeEntry()) < 0) + { + SDK_ASSERTMSG(index >= 0, "osCreateThread: thread entry not allocated"); + (void)osRestoreInterrupts(enable); + return; + } +#else + index = OSi_GetUnusedThreadId(); +#endif + + //---- setup thread + thread->priority = prio; + thread->id = (u32)index; + thread->state = OS_THREAD_STATE_WAITING; + + //---- clear profile pointer + thread->profiler = NULL; + + //---- set thread entry and listPtr +#ifndef SDK_THREAD_INFINITY + OSi_ThreadInfo.entry[index] = thread; +#endif + OSi_InsertThreadToList(thread); + + //---- set Stack Bottom & Top + thread->stackBottom = (u32)stack; + thread->stackTop = (u32)stack - stackSize; + thread->stackWarningOffset = 0; + + //---- Set Stack CheckNumber + *(u32 *)(thread->stackBottom - sizeof(u32)*2) = OSi_STACK_CHECKNUM_BOTTOM; // minus for stack CheckNumber and padding + *(u32 *)thread->stackTop = OSi_STACK_CHECKNUM_TOP; + + //---- clear join queue + osInitThreadQueue(&thread->joinQueue); + + //---- Init context + osInitContext(&thread->context, (u32)func, (u32)stack - sizeof(u32)*2); // minus for stack CheckNumber and padding + + thread->context.r[0] = (u32)arg; // argument for func + thread->context.lr = (u32)osExitThread; + + //---- clear Stack (except check code (=sizeof(u32)*2) and padding(sizeof(u32)) + MI_CpuClear32((void *)((u32)stack - stackSize + sizeof(u32)), stackSize - sizeof(u32) * 2 - sizeof(u32) ); + + //---- clear mutex + thread->mutex = NULL; +#ifndef SDK_THREAD_INFINITY + thread->mutexQueueHead = NULL; + thread->mutexQueueTail = NULL; +#else + thread->mutexQueue.head = NULL; + thread->mutexQueue.tail = NULL; +#endif + + //---- clear destructor +#ifdef SDK_THREAD_INFINITY + osSetThreadDestructor(thread, NULL); +#endif + + //---- clear queue +#ifdef SDK_THREAD_INFINITY + thread->queue = NULL; + thread->link.prev = thread->link.next = NULL; + + //---- clear specific member + MI_CpuClear32(&thread->specific[0], sizeof(void *) * OS_THREAD_SPECIFIC_MAX); +#endif + + //---- clear alarm pointer for sleep + thread->alarmForSleep = NULL; + + (void)osRestoreInterrupts(enable); +} + + +/*---------------------------------------------------------------------------* + Name: osExitThread + + Description: Terminates the current thread + + Arguments: none + + Returns: none + *---------------------------------------------------------------------------*/ +void osExitThread(void) +{ + (void)osDisableInterrupts(); + +#ifdef SDK_THREAD_INFINITY + OSi_ExitThread_ArgSpecified(osGetCurrentThread(), 0); +#else + OSi_ExitThread_Destroy(); +#endif +} + + +#ifdef SDK_THREAD_INFINITY +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// デストラクタスタックを考慮する OSi_ExitThread +// 割込み禁止状態で呼び出すこと +static void OSi_ExitThread_ArgSpecified(OSThread *thread, void *arg) +{ + if (OSi_StackForDestructor) + { + osInitContext(&thread->context, (u32)OSi_ExitThread, (u32)OSi_StackForDestructor); + thread->context.r[0] = (u32)arg; + thread->context.cpsr |= HW_PSR_IRQ_DISABLE; + thread->state = OS_THREAD_STATE_READY; + osLoadContext(&thread->context); + // Never Returns + } + else + { + OSi_ExitThread(arg); + // Never Returns + } +} +#endif + + +#ifdef SDK_THREAD_INFINITY +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// osKillThread において参照されるコンテキストスイッチ先 +// 割り込み禁止状態で呼び出すこと +static void OSi_ExitThread(void *arg) +{ + OSThread *currentThread = OSi_GetCurrentThread(); + OSThreadDestructor destructor; + + SDK_ASSERT(currentThread); + + // デストラクタの処理 + destructor = currentThread->destructor; + if (destructor) + { + currentThread->destructor = NULL; + destructor(arg); + (void)osDisableInterrupts(); // 再び割り込み禁止へ + } + + OSi_ExitThread_Destroy(); // Never return +} +#endif + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// osDestroyThread からカレントスレッドを destroy するときに呼び出される +// 割り込み禁止状態で呼び出すこと +static void OSi_ExitThread_Destroy(void) +{ + OSThread *currentThread = OSi_GetCurrentThread(); + SDK_ASSERT(currentThread); + +#ifdef SDK_THREAD_INFINITY + (void)osDisableScheduler(); +#endif + +#ifndef SDK_THREAD_INFINITY + //---- current thread check + SDK_ASSERT(OSi_ThreadInfo.entry[currentThread->id] == currentThread); +#endif + + //---- Release all the locked mutexes by current thread + OSi_UnlockAllMutex(currentThread); + + + //---- remove from thread queue list + if (currentThread->queue) + { + (void)OSi_RemoveSpecifiedLinkFromQueue(currentThread->queue, currentThread); + } + + //---- remove from thread list + OSi_RemoveThreadFromList(currentThread); + + //---- delete this thread +#ifndef SDK_THREAD_INFINITY + OSi_ThreadInfo.entry[currentThread->id] = NULL; +#endif + currentThread->state = OS_THREAD_STATE_TERMINATED; + + //---- wakeup thread waiting currentThread terminated +#ifndef SDK_THREAD_INFINITY + osWakeupThread(¤tThread->joinQueue); // possible to never return +#else + osWakeupThread(¤tThread->joinQueue); +#endif + +#ifdef SDK_THREAD_INFINITY + (void)osEnableScheduler(); +#endif + + osRescheduleThread(); // never return + + osTerminate(); +} + +// TEST --------------------------------------------------------------------- +#ifdef NITRO_UTEST_H__ +static vu32 exitThreadStatus = 0; + +static void exitThreadFunc(void *arg) +{ + exitThreadStatus = 1; + (void)arg; +} + +void UTEST_osExitThread(void); +void UTEST_osExitThread(void) +{ + OSThread thread; + u32 stack[1024]; + + osInit(); + osInitThread(); + + osCreateThread(&thread, + exitThreadFunc, + NULL, + stack + 1024, sizeof(stack), osGetThreadPriority(osGetCurrentThread()) - 1); + osWakeupThreadDirect(&thread); + osJoinThread(&thread); + UT_AssertEq(exitThreadStatus, 1); +} +#endif // ifdef NITRO_UTEST_H__ + +/*---------------------------------------------------------------------------* + Name: osDestroyThread + + Description: destroy specified thread. + + Arguments: thread: thread to be destroyed + + Returns: None + *---------------------------------------------------------------------------*/ +void osDestroyThread(OSThread *thread) +{ + OSIntrMode enabled = osDisableInterrupts(); + + SDK_ASSERT(thread); + + //---- check current thread + if (osGetCurrentThread() == thread) + { + OSi_ExitThread_Destroy(); + // not reached + } + +#ifdef SDK_THREAD_INFINITY + (void)osDisableScheduler(); +#endif + + //---- Release all the locked mutexed by specified thread + OSi_UnlockAllMutex(thread); + + //---- cancel alarm for sleep + OSi_CancelThreadAlarmForSleep(thread); + + //---- remove from thread queue list + if (thread->queue) + { + (void)OSi_RemoveSpecifiedLinkFromQueue(thread->queue, thread); + } + + //---- remove from thread list + OSi_RemoveThreadFromList(thread); + + //---- delete thread +#ifndef SDK_THREAD_INFINITY + OSi_ThreadInfo.entry[thread->id] = NULL; +#endif + thread->state = OS_THREAD_STATE_TERMINATED; + + //---- wakeup thread waiting this thread terminated + osWakeupThread(&thread->joinQueue); + +#ifdef SDK_THREAD_INFINITY + (void)osEnableScheduler(); +#endif + (void)osRestoreInterrupts(enabled); + + osRescheduleThread(); +} + +/*---------------------------------------------------------------------------* + Name: osKillThread + + Description: switch PC to thread destructor to finalize thread + + Arguments: thread : thread to wait to finish + flag : argument for destructor + + Returns: None + *---------------------------------------------------------------------------*/ +#ifdef SDK_THREAD_INFINITY +// TESTEE +static inline void OSi_KillThreadWithPriority(OSThread *thread, void *arg, u32 prio); +static inline void OSi_KillThreadWithPriority(OSThread *thread, void *arg, u32 prio) +{ + SDK_ASSERT(thread); + + { + u32 stack = (OSi_StackForDestructor) ? (u32)OSi_StackForDestructor : thread->stackBottom - sizeof(u32)*2; // minus for stack CheckNumber and padding + + osInitContext(&thread->context, (u32)OSi_ExitThread, stack); + } + thread->context.r[0] = (u32)arg; + thread->context.cpsr |= HW_PSR_IRQ_DISABLE; // デストラクタ内では IRQ 割り込みを禁止する + + thread->state = OS_THREAD_STATE_READY; + + (void)osDisableScheduler(); + (void)osSetThreadPriority(thread, prio); + (void)osEnableScheduler(); +} + +// BODY +void osKillThread(OSThread *thread, void *arg) +{ + osKillThreadWithPriority(thread, arg, osGetThreadPriority(thread)); +} + +void osKillThreadWithPriority(OSThread *thread, void *arg, u32 prio) +{ + OSIntrMode enabled = osDisableInterrupts(); + + if (thread == osGetCurrentThread()) + { + OSi_ExitThread_ArgSpecified(thread, arg); + // Never returns + } + + //---- cancel alarm for sleep + OSi_CancelThreadAlarmForSleep(thread); + + OSi_KillThreadWithPriority(thread, arg, prio); + + OSi_RescheduleThread(); + (void)osRestoreInterrupts(enabled); +} + +// TEST --------------------------------------------------------------------- +#ifdef NITRO_UTEST_H__ +// test1 +void UTEST_osKillThread_1(void); +void UTEST_osKillThread_1(void) +{ + OSThread thread; + OSThread *t = &thread; + u32 flag; + + osInit(); + osInitThread(); + + t->stackBottom = 0x6789abcd; + t->state = OS_THREAD_STATE_TERMINATED; + OSi_KillThreadWithPriority(t, (void *)0x12345678, 16); + + // コンテクスト内の主要レジスタチェック + UT_AssertEq(t->context.pc_plus4, (u32)OSi_ExitThread + 4); // osExitThread + UT_AssertEq(t->context.r[0], (u32)0x12345678); // arg + flag = ((u32)osExitThread & 1) ? (u32)HW_PSR_THUMB_STATE : (u32)HW_PSR_ARM_STATE; + UT_AssertEq(t->context.cpsr, (u32)HW_PSR_IRQ_DISABLE | HW_PSR_SYS_MODE | flag); + UT_AssertEq(t->context.sp, (u32)0x6789abcd - HW_SVC_STACK_SIZE); + + // ステートチェック + UT_AssertEq(t->state, OS_THREAD_STATE_READY); + UT_AssertAsserted(OSi_KillThreadWithPriority(0, 0, 16)); +} + +// test2 +static vu32 killThreadStatus = 0; + +static void killThreadDtor(void *arg) +{ + killThreadStatus = 666; + (void)arg; +} + +static void killThreadFunc(void *arg) +{ + osSetThreadDestructor(osGetCurrentThread(), killThreadDtor); + + killThreadStatus = 1; + while (1) + { + osSleepThread(NULL); + killThreadStatus++; + } + (void)arg; +} + +void UTEST_osKillThread_2(void); +void UTEST_osKillThread_2(void) +{ + OSThread thread; + u32 stack[1024]; + + osInit(); + osInitThread(); + + osCreateThread(&thread, + killThreadFunc, + NULL, + stack + 1024, sizeof(stack), osGetThreadPriority(osGetCurrentThread()) - 1); + UT_AssertEq(killThreadStatus, 0); + + osWakeupThreadDirect(&thread); + UT_AssertEq(killThreadStatus, 1); + UT_AssertEq(thread.destructor, killThreadDtor); + + osWakeupThreadDirect(&thread); + UT_AssertEq(killThreadStatus, 2); + + osKillThread(&thread, 0); + osJoinThread(&thread); + UT_AssertEq(killThreadStatus, 666); +} +#endif // ifdef NITRO_UTEST_H__ +#endif // ifdef SDK_THREAD_INFINITY + +/*---------------------------------------------------------------------------* + Name: OSi_CancelThreadAlarmForSleep + + Description: Cancel alarm used to sleep thread. + If sleeping alarm is not set, do nothing. + + Arguments: thread : thread to calcel alarm + + Returns: None + *---------------------------------------------------------------------------*/ +static void OSi_CancelThreadAlarmForSleep(OSThread *thread) +{ + OSAlarm *alarm = thread->alarmForSleep; + + if (alarm) + { + osCancelAlarm(alarm); + } +} + +/*---------------------------------------------------------------------------* + Name: osJoinThread + + Description: wait for specified thread to terminated + + Arguments: thread : thread to wait to finish + + Returns: None + *---------------------------------------------------------------------------*/ +void osJoinThread(OSThread *thread) +{ + OSIntrMode enabled = osDisableInterrupts(); + + SDK_ASSERT(thread); + + //---- skip if thread is terminated already + while(thread->state != OS_THREAD_STATE_TERMINATED) + { + osSleepThread(&thread->joinQueue); + } + + (void)osRestoreInterrupts(enabled); +} + +/*---------------------------------------------------------------------------* + Name: osIsThreadTerminated + + Description: check thread status whether it's terminated + + Arguments: thread : pointer to thread to be examined + + Returns: TRUE if the thread is terminated. FALSE if not + *---------------------------------------------------------------------------*/ +BOOL osIsThreadTerminated(const OSThread *thread) +{ + SDK_ASSERT(thread); + return (thread->state == OS_THREAD_STATE_TERMINATED) ? TRUE : FALSE; +} + +/*---------------------------------------------------------------------------* + Name: osGetThreadStatus + + Description: get thread status + + Arguments: thread : pointer to thread + + Returns: + *---------------------------------------------------------------------------*/ +OSThreadState osGetThreadStatus(const OSThread *thread) +{ + SDK_ASSERT(thread); + return thread->state; +} + +/*---------------------------------------------------------------------------* + Name: osSleepThreadDirect + + Description: Gets the thread into sleep status directly + + Arguments: thread thread to sleep + queue waiting list queue (or NULL) + + Returns: none + *---------------------------------------------------------------------------*/ +void osSleepThreadDirect(OSThread *thread, OSThreadQueue *queue) +{ + SDK_ASSERT(thread); + SDK_ASSERT(thread->state != OS_THREAD_STATE_TERMINATED); + + { + OSIntrMode bak_intr = osDisableInterrupts(); + + if ( thread->state == OS_THREAD_STATE_READY ) + { + if (queue) + { +#ifndef SDK_THREAD_INFINITY + *queue |= (OSThreadQueue)(1UL << thread->id); +#else + thread->queue = queue; + OSi_InsertLinkToQueue(queue, thread); +#endif + } + thread->state = OS_THREAD_STATE_WAITING; + OSi_RescheduleThread(); + } + (void)osRestoreInterrupts(bak_intr); + } +} + +/*---------------------------------------------------------------------------* + Name: osSleepThread + + Description: Gets the current thread into sleep status + + Arguments: waiting list queue + + Returns: none + *---------------------------------------------------------------------------*/ +void osSleepThread(OSThreadQueue *queue) +{ + OSIntrMode enable; + OSThread *currentThread; + + enable = osDisableInterrupts(); +#ifndef SDK_THREAD_INFINITY + { + currentThread = OSi_GetCurrentThread(); + SDK_ASSERT(currentThread); + + if (queue) + { + *queue |= (OSThreadQueue)(1UL << currentThread->id); + } + + currentThread->state = OS_THREAD_STATE_WAITING; + OSi_RescheduleThread(); + } +#else + { + currentThread = OSi_GetCurrentThread(); + SDK_ASSERT(currentThread); + + if (queue) + { + currentThread->queue = queue; + OSi_InsertLinkToQueue(queue, currentThread); + } + + currentThread->state = OS_THREAD_STATE_WAITING; + OSi_RescheduleThread(); + } +#endif + (void)osRestoreInterrupts(enable); +} + +/*---------------------------------------------------------------------------* + Name: osWakeupThread + + Description: Gets the threads out of sleep status + + Arguments: none + + Returns: none + *---------------------------------------------------------------------------*/ +void osWakeupThread(OSThreadQueue *queue) +{ + OSIntrMode enable; +#ifndef SDK_THREAD_INFINITY + u32 mask; +#else + BOOL isNeedRescheduling = FALSE; +#endif + SDK_ASSERT(queue); + enable = osDisableInterrupts(); + +#ifndef SDK_THREAD_INFINITY + mask = (u32)*queue; + if (mask) + { + //---- wakeup threads + OSThread *t = OSi_ThreadInfo.list; + while (t) + { + if (mask & (1UL << t->id)) + { + t->state = OS_THREAD_STATE_READY; + } + + t = t->next; + } + + osInitThreadQueue(queue); + OSi_RescheduleThread(); + } +#else + if (queue->head) + { + while (queue->head) + { + OSThread *thread = OSi_RemoveLinkFromQueue(queue); + + thread->state = OS_THREAD_STATE_READY; + thread->queue = NULL; + thread->link.prev = thread->link.next = NULL; + } + + osInitThreadQueue(queue); + OSi_RescheduleThread(); + } +#endif + + (void)osRestoreInterrupts(enable); +} + + +/*---------------------------------------------------------------------------* + Name: osWakeupThreadDirect + + Description: Gets the threads out of sleep status directly + + Arguments: none + + Returns: none + *---------------------------------------------------------------------------*/ +void osWakeupThreadDirect(OSThread *thread) +{ + OSIntrMode enable; + + SDK_ASSERT(thread); + SDK_ASSERT(thread->state != OS_THREAD_STATE_TERMINATED); + enable = osDisableInterrupts(); + { + thread->state = OS_THREAD_STATE_READY; + OSi_RescheduleThread(); + + } + (void)osRestoreInterrupts(enable); +} + + +/*---------------------------------------------------------------------------* + Name: osSelectThread + + Description: Select the runnable thread highest priority + + Arguments: None + + Returns: Pointer to thread must run + NULL if no thread candidate to run + *---------------------------------------------------------------------------*/ +OSThread *osSelectThread(void) +{ + OSThread *t = OSi_ThreadInfo.list; + + while (t && !osIsThreadRunnable(t)) + { + t = t->next; + } + + return t; +} + +/*---------------------------------------------------------------------------* + Name: osRescheduleThread + + Description: Switch to the runnable thread highest priority + + Arguments: None + + Returns: None or Never return + *---------------------------------------------------------------------------*/ +void osRescheduleThread(void) +{ + OSIntrMode bak_intr = osDisableInterrupts(); + OSi_RescheduleThread(); + (void)osRestoreInterrupts(bak_intr); +} + +/*---------------------------------------------------------------------------* + Name: osYieldThread + + Description: do thread rescheduling. current thread relinquish CPU + to give chance of running to other threads which has same + priority. + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osYieldThread(void) +{ + OSThread *current = osGetCurrentThread(); + OSThread *pre = NULL; + OSThread *lastThread = NULL; + int samePriorityThread = 0; + OSIntrMode enable = osDisableInterrupts(); + + { + OSThread *t = OSi_ThreadInfo.list; + OSThread *tPre = NULL; + + while (t) + { + if (t == current) + { + pre = tPre; + } + + if (current->priority == t->priority) + { + lastThread = t; + samePriorityThread++; + } + + tPre = t; + t = t->next; + } + } + + //---- no thread of same priority with current or needless to arrange list + if (samePriorityThread <= 1 || lastThread == current) + { + (void)osRestoreInterrupts(enable); + return; + } + + //---- remove thread from list + if (!pre) + { + OSi_ThreadInfo.list = current->next; + } + else + { + pre->next = current->next; + } + + //---- insert thread after 'lastThread' + current->next = lastThread->next; + lastThread->next = current; + + //---- re-schedule + OSi_RescheduleThread(); + + (void)osRestoreInterrupts(enable); +} + + +/*---------------------------------------------------------------------------* + Name: osDumpThreadList + + Description: Dump thread list + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osDumpThreadList(void) +{ +#ifndef SDK_FINALROM +#ifndef SDK_THREAD_INFINITY + int i; +#endif + + osPrintf("thread list top %08x\n", OSi_ThreadInfo.list); + +#ifndef SDK_THREAD_INFINITY + osPrintf("No: address prio next\n"); + for (i = 0; i < OS_THREAD_MAX_NUM; i++) + { + OSThread *thread = OSi_ThreadInfo.entry[i]; + osPrintf("%02d: %08x %5d %08x\n", i, thread, (thread) ? thread->priority : 0, + (thread) ? thread->next : 0); + } +#else + // osPrintf("Id: address prio next\n"); + osPrintf("Id: address prio next st queue.h queue.t link.p link.n\n"); + { + OSThread *thread = OSi_ThreadInfo.list; + while (thread) + { + // osPrintf("%02d: %08x %5d %08x\n", thread->id, thread, thread->priority, thread->next ); + osPrintf("%02d: %08x %5d %08x %d %8x %8x %8x %8x\n", thread->id, thread, + thread->priority, thread->next, thread->state, + (thread->queue) ? thread->queue->head : (OSThread *)1, + (thread->queue) ? thread->queue->tail : (OSThread *)1, thread->link.prev, + thread->link.next); + thread = thread->next; + + } + } +#endif +#endif +} + +/*---------------------------------------------------------------------------* + Name: osGetNumberOfThread + + Description: get number of thread whch exists in system + + Arguments: None + + Returns: number of thread which exists in system + *---------------------------------------------------------------------------*/ +int osGetNumberOfThread(void) +{ + OSIntrMode enabled = osDisableInterrupts(); + int threads = 0; + +#ifndef SDK_THREAD_INFINITY + int i; + + for (i = 0; i < OS_THREAD_MAX_NUM; i++) + { + if (OSi_ThreadInfo.entry[i]) + { + threads++; + } + } +#else + OSThread *thread = OSi_ThreadInfo.list; + while (thread) + { + threads++; + thread = thread->next; + } +#endif + + (void)osRestoreInterrupts(enabled); + return threads; +} + +/*---------------------------------------------------------------------------* + Name: osGetStackStatus + + Description: check thread stack. check each CheckNUM. + return result. + + Arguments: thread thread checked + + Returns: 0 (OS_STACK_NO_ERROR) no error + OS_STACK_OVERFLOW overflow + OS_STACK_ABOUT_TO_OVERFLOW about to overflow + OS_STACK_UNDERFLOW underflow + *---------------------------------------------------------------------------*/ +OSStackStatus osGetStackStatus(const OSThread *thread) +{ + //---- Check if overflow + if (*(u32 *)(thread->stackTop) != OSi_STACK_CHECKNUM_TOP) + { + return OS_STACK_OVERFLOW; + } + //---- Check if about to overflow + else if (thread->stackWarningOffset + && *(u32 *)(thread->stackTop + thread->stackWarningOffset) != OSi_STACK_CHECKNUM_WARN) + { + return OS_STACK_ABOUT_TO_OVERFLOW; + } + //---- Check if underFlow + else if (*(u32 *)(thread->stackBottom - sizeof(u32)*2) != OSi_STACK_CHECKNUM_BOTTOM) + { + return OS_STACK_UNDERFLOW; + } + //---- No Error, return. + else + { + return OS_STACK_NO_ERROR; + } +} + +/*---------------------------------------------------------------------------* + Name: OSi_CheckStack + + Description: check thread stack. check each CheckNUM. + if changed, display warning and halt. + + Arguments: file file name displayed when stack overflow + line line number displayed when stack overflow + thread thread checked + + Returns: None + ( if error occurred, never return ) + *---------------------------------------------------------------------------*/ +static char *OSi_CheckStack_mesg[] = { + "overflow", "about to overflow", "underflow" +}; + +#ifndef SDK_FINALROM +#ifndef SDK_NO_MESSAGE +void OSi_CheckStack(const char *file, int line, const OSThread *thread) +{ + OSStackStatus st = osGetStackStatus(thread); + + if (st == OS_STACK_NO_ERROR) + { + return; + } + + OSi_Panic(file, line, " stack %x(id:%d) %s.\nstack area: %08x-%08x, warning offset: %x", + thread, + thread->id, + OSi_CheckStack_mesg[(int)st - 1], + thread->stackTop, thread->stackBottom, thread->stackWarningOffset); + // Never return +} +#endif +#endif + +/*---------------------------------------------------------------------------* + Name: OSi_GetSystemStackPointer + + Description: Get system mode stack pointer at svc/irq mode + + Arguments: None + + Returns: Stack Pointer + *---------------------------------------------------------------------------*/ +static u32 OSi_SystemStackBuffer; + +#include +asm u32 OSi_GetSystemStackPointer( void ) +{ + INASM_EXTERN( OSi_SystemStackBuffer ) + + ldr r0, =OSi_SystemStackBuffer + stmia r0, { sp }^ + ldr r0, [ r0 ] + bx lr +} +#include + +/*---------------------------------------------------------------------------* + Name: OSi_GetCurrentStackPointer + + Description: Get current mode stack pointer + + Arguments: None + + Returns: Stack Pointer + *---------------------------------------------------------------------------*/ +asm u32 OSi_GetCurrentStackPointer( void ) +{ + mov r0, sp + bx lr +} + +/*---------------------------------------------------------------------------* + Name: osSetThreadStackWarningOffset + + Description: Set warning level for stack checker + + Arguments: thread thread to set + offset offset from stack top. must be multiple of 4 + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetThreadStackWarningOffset(OSThread *thread, u32 offset) +{ + SDK_ASSERTMSG((offset & 3) == 0, "Offset must be aligned by 4"); + SDK_ASSERTMSG(osGetThreadContext(thread)->sp > thread->stackTop + offset, + "Cannot set warning level below current sp."); + + //---- remember warning offset + thread->stackWarningOffset = offset; + + //---- set Stack CheckNum + if (offset != 0) + { + *(u32 *)(thread->stackTop + offset) = OSi_STACK_CHECKNUM_WARN; + } +} + +/*---------------------------------------------------------------------------* + Name: osSetThreadPriority + + Description: change priority of thread + + Arguments: thread thread to set priority + prio new priority to be set + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL osSetThreadPriority(OSThread *thread, u32 prio) +{ + OSThread *t = OSi_ThreadInfo.list; + OSThread *pre = NULL; + OSIntrMode enable; + + SDK_ASSERTMSG(OS_THREAD_PRIORITY_MIN <= prio + && prio <= OS_THREAD_PRIORITY_MAX, "invalid priority"); + SDK_ASSERTMSG(thread != &OSi_IdleThread, "cannot change idle thread priority."); + + enable = osDisableInterrupts(); + + while (t && t != thread) + { + pre = t; + t = t->next; + } + + //---- thread not found or thread is idle + if (!t || t == &OSi_IdleThread) + { + (void)osRestoreInterrupts(enable); + return FALSE; + } + + if (t->priority != prio) + { + //---- remove thread from list + if (!pre) + { + OSi_ThreadInfo.list = thread->next; + } + else + { + pre->next = thread->next; + } + + //---- set priority and insert proper position + thread->priority = prio; + OSi_InsertThreadToList(thread); + + //---- re-schedule + OSi_RescheduleThread(); + } + + (void)osRestoreInterrupts(enable); + + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: osGetThreadPriority + + Description: get priority of thread + + Arguments: thread thread to get priority + + Returns: priority + *---------------------------------------------------------------------------*/ +u32 osGetThreadPriority(const OSThread *thread) +{ + SDK_ASSERTMSG(thread, "osGetThreadPriority: bad thread"); + + return thread->priority; +} + + +/*---------------------------------------------------------------------------* + Name: osSleep + + Description: sleep specified period + + Arguments: msec sleeping period. ( milliseconds ) + + Returns: None. + *---------------------------------------------------------------------------*/ +void osSleep(u32 msec) +{ + OSAlarm alarm; + + SDK_ASSERTMSG(osIsTickAvailable() + && osIsAlarmAvailable(), "osSleep: need to start Tick and Alarm beforehand."); + SDK_ASSERTMSG(OSi_IsThreadInitialized, "osSleep: thread system not initialized."); + + osCreateAlarm(&alarm); + { + OSThread *volatile p_thread = OSi_GetCurrentThread(); + OSIntrMode bak_cpsr = osDisableInterrupts(); + + // ---- remember alarm + p_thread->alarmForSleep = &alarm; + + osSetAlarm(&alarm, OS_MSEC_TO_TICK(msec), &OSi_SleepAlarmCallback, + (void *)&p_thread); + while (p_thread != NULL) + { + osSleepThread(NULL); + } + (void)osRestoreInterrupts(bak_cpsr); + } +} + +//---------------- callback to wakeup sleeping thread +static void OSi_SleepAlarmCallback(void *arg) +{ + OSThread **pp_thread = (OSThread **)arg; + OSThread *p_thread = *pp_thread; + *pp_thread = NULL; + + //---- clear remembrance of alarm + p_thread->alarmForSleep = NULL; + + osWakeupThreadDirect(p_thread); +} + + +/*---------------------------------------------------------------------------* + Name: osSetSwitchThreadCallback + + Description: set callback called at switching thread + + Arguments: callback callback function + + Returns: previous callback function before set callback now + *---------------------------------------------------------------------------*/ +OSSwitchThreadCallback osSetSwitchThreadCallback(OSSwitchThreadCallback callback) +{ + OSSwitchThreadCallback prev; + OSIntrMode enabled; + + enabled = osDisableInterrupts(); + prev = (OSSwitchThreadCallback)OSi_ThreadInfo.switchCallback; + OSi_ThreadInfo.switchCallback = (void*)callback; + + (void)osRestoreInterrupts(enabled); + return prev; +} + +/*---------------------------------------------------------------------------* + Name: OSi_IdleThreadProc + + Description: procedure of idle thread which system creates + + Arguments: None + + Returns: None (never return) + *---------------------------------------------------------------------------*/ +static void OSi_IdleThreadProc(void *arg) +{ + (void)osEnableInterrupts(); + while (1) + { + osHalt(); + } + // never return +} + +/*---------------------------------------------------------------------------* + Name: OSi_GetIdleThread + + Description: get pointer to idle thread structure + + Arguments: None + + Returns: pointer to idle thread structure + *---------------------------------------------------------------------------*/ +OSThread *OSi_GetIdleThread(void) +{ + OSThread *t = NULL; + if (OSi_IsThreadInitialized) + { + t = &OSi_IdleThread; + } + return t; +} + +/*---------------------------------------------------------------------------* + Name: osDisableScheduler + + Description: disable scheduler + + Arguments: None + + Returns: Previous scheduler suspend count. + Suspended if value >= 0. + *---------------------------------------------------------------------------*/ +u32 osDisableScheduler(void) +{ + OSIntrMode enabled = osDisableInterrupts(); + u32 count = 0; + + if (OSi_RescheduleCount < (u32)(0 - 1) /* u32 max value -1 */ ) + { + count = OSi_RescheduleCount++; + } + (void)osRestoreInterrupts(enabled); + + return count; +} + +/*---------------------------------------------------------------------------* + Name: osEnableScheduler + + Description: enable scheduler + + Arguments: None + + Returns: Previous scheduler suspend count. + Suspended if value >= 0. + *---------------------------------------------------------------------------*/ +u32 osEnableScheduler(void) +{ + OSIntrMode enabled = osDisableInterrupts(); + u32 count = 0; + + if (OSi_RescheduleCount > 0) + { + count = OSi_RescheduleCount--; + } + (void)osRestoreInterrupts(enabled); + + return count; +} + +#ifdef SDK_THREAD_INFINITY +/*---------------------------------------------------------------------------* + Name: osGetThread + + Description: Gets pointer to thread which id is specified + + Arguments: id : thread id to get thread + + Returns: pointer to thread which id is specified + *---------------------------------------------------------------------------*/ +OSThread *osGetThread(u32 id) +{ + OSThread *retval = NULL; + OSThread *t = OSi_ThreadInfo.list; + + while (t) + { + if (t->id == id) + { + retval = t; + break; + } + + t = t->next; + } + + return retval; +} +#endif + + +#ifdef SDK_THREAD_INFINITY +/*---------------------------------------------------------------------------* + Name: osSetThreadDestructor + + Description: set thread destructor, which is called when that thread exits. + + Arguments: thread : thread pointer + dtor : destructor function + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetThreadDestructor(OSThread *thread, OSThreadDestructor dtor) +{ + SDK_ASSERT(thread); + thread->destructor = dtor; +} + +/*---------------------------------------------------------------------------* + Name: osGetThreadDestructor + + Description: get thread destructor which is set + + Arguments: thread : thread pointer + + Returns: destructor function + *---------------------------------------------------------------------------*/ +OSThreadDestructor osGetThreadDestructor(const OSThread *thread) +{ + SDK_ASSERT(thread); + return thread->destructor; +} + +/*---------------------------------------------------------------------------* + Name: osSetThreadParameter + + Description: set user parameter which is allowed to use freely. + + Arguments: thread : thread pointer + parameter : user parameter + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetThreadParameter(OSThread *thread, void *parameter) +{ + SDK_ASSERT(thread); + thread->userParameter = parameter; +} + +/*---------------------------------------------------------------------------* + Name: osGetThreadParameter + + Description: get user parameter which is set + + Arguments: thread : thread pointer + + Returns: user parameter which is set + *---------------------------------------------------------------------------*/ +void *osGetThreadParameter(const OSThread *thread) +{ + SDK_ASSERT(thread); + return thread->userParameter; +} + + + +/*---------------------------------------------------------------------------* + Name: OSi_SetSystemErrno + + Description: set system error number. + + Arguments: thread : thread to set error number + errno : error number to set + + Returns: None + *---------------------------------------------------------------------------*/ +void OSi_SetSystemErrno(OSThread *thread, int errno) +{ + SDK_ASSERT(thread); + thread->systemErrno = errno; +} + +/*---------------------------------------------------------------------------* + Name: OSi_GetSystemErrno + + Description: get system error number. + + Arguments: thread : thread to set error number + + Returns: error number + *---------------------------------------------------------------------------*/ +int OSi_GetSystemErrno(const OSThread *thread) +{ + SDK_ASSERT(thread); + return thread->systemErrno; +} + +/*---------------------------------------------------------------------------* + Name: osGetErrno + + Description: get system error number. + + Arguments: None. + + Returns: error number + *---------------------------------------------------------------------------*/ +int osGetErrno(void) +{ + OSThread *thread = OSi_GetCurrentThread(); + return OSi_GetSystemErrno(thread); +} +#endif + +/*---------------------------------------------------------------------------* + Name: osIsThreadInList + + Description: check if the specified thread is in the thread list + + Arguments: thread : thread + + Returns: TRUE if thread is in the thread list + *---------------------------------------------------------------------------*/ +BOOL osIsThreadInList(const OSThread *thread) +{ + BOOL r = FALSE; + OSThread *t = OSi_ThreadInfo.list; + OSIntrMode enabled = osDisableInterrupts(); + + while (t) + { + if (t == thread) + { + r = TRUE; + break; + } + + t = t->next; + } + + (void)osRestoreInterrupts(enabled); + return r; +} + +/*---------------------------------------------------------------------------* + Name: osSetThreadDestructorStack + + Description: specify stack area to call thread destructor + + Arguments: stack stack bottom address + stackSize stack size (byte. must be aligned by 4) + + Returns: None + *---------------------------------------------------------------------------*/ +void osSetThreadDestructorStack(void *stack) +{ + SDK_ASSERT(stack); + SDK_ASSERT((u32)stack % STACK_ALIGN == 0); + + OSi_StackForDestructor = stack; +} + +//================================================================================ +// for DEBUG +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osGetThreadResource + + Description: store resources of thread to specified pointer + + Arguments: resource pointer to store thread resources + + Returns: TRUE ... success (always return this now) + FALSE ... fail + *---------------------------------------------------------------------------*/ +BOOL osGetThreadResource(OSThreadResource *resource) +{ + resource->num = osGetNumberOfThread(); + + return TRUE; +} + + +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif diff --git a/trunk/bootrom/include/brom.h b/trunk/bootrom/include/brom.h index 9d2027a..02da9a4 100644 --- a/trunk/bootrom/include/brom.h +++ b/trunk/bootrom/include/brom.h @@ -23,7 +23,8 @@ #include #include -//#include +#include +#include /* BROM_H_ */ #endif diff --git a/trunk/bootrom/include/brom/mi.h b/trunk/bootrom/include/brom/mi.h new file mode 100644 index 0000000..65bce99 --- /dev/null +++ b/trunk/bootrom/include/brom/mi.h @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS + File: mi.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_MI_H_ +#define BROM_MI_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_MI_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/mi/memory.h b/trunk/bootrom/include/brom/mi/memory.h new file mode 100644 index 0000000..7424792 --- /dev/null +++ b/trunk/bootrom/include/brom/mi/memory.h @@ -0,0 +1,716 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - MI - include + File: memory.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_MI_MEMORY_H_ +#define BROM_MI_MEMORY_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +//====================================================================== +void MIi_CpuClear16(u16 data, void *destp, u32 size); +void MIi_CpuCopy16(const void *srcp, void *destp, u32 size); +void MIi_CpuSend16(const void *srcp, volatile void *destp, u32 size); +void MIi_CpuRecv16(volatile const void *srcp, void *destp, u32 size); +void MIi_CpuPipe16(volatile const void *srcp, volatile void *destp, u32 size); +void MIi_CpuMove16(const void *src, void *dest, u32 size); +void* MIi_CpuFind16(const void *src, u16 data, u32 size); +int MIi_CpuComp16(const void *mem1, const void *mem2, u32 size); + +void MIi_CpuClear32(u32 data, void *destp, u32 size); +void MIi_CpuCopy32(const void *srcp, void *destp, u32 size); +void MIi_CpuSend32(const void *srcp, volatile void *destp, u32 size); +void MIi_CpuRecv32(volatile const void *srcp, void *destp, u32 size); +void MIi_CpuPipe32(volatile const void *srcp, volatile void *destp, u32 size); +void MIi_CpuMove32(const void *src, void *dest, u32 size); +void* MIi_CpuFind32(const void *src, u32 data, u32 size); +int MIi_CpuComp32(const void *mem1, const void *mem2, u32 size); + +void MIi_CpuClearFast(u32 data, void *destp, u32 size); +void MIi_CpuCopyFast(const void *srcp, void *destp, u32 size); +void MIi_CpuSendFast(const void *srcp, volatile void *destp, u32 size); +void MIi_CpuRecvFast(volatile const void *srcp, void *destp, u32 size); +void MIi_CpuMoveFast(const void *src, void *dest, u32 size); + + +//================================================================================ +// 32 bit version +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MI_CpuFill32 + + Description: fill memory with specified data. (32 bit version) + + Arguments: dest : destination address to fill data, must be in 4 byte alignment + data : data to fill + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuFill32(void *dest, u32 data, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuClear32(data, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuCopy32 + + Description: copy memory data (32 bit version) + + Arguments: src : source address, must be in 4 byte alignment + dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuCopy32(const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuCopy32(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuClear32 + + Description: fill memory with 0 (32 bit version) + + Arguments: dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuClear32(void *dest, u32 size) +{ + MI_CpuFill32(dest, 0, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuSend32 + + Description: write some data to fixed address (32 bit version) + + Arguments: src : source address, must be in 4 byte alignment + dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuSend32(const void *src, volatile void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuSend32(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuRecv32 + + Description: receive u32 data from fixed address + 32bit version + + Arguments: src : source address. not incremented + dest : data buffer to receive + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuRecv32(volatile const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuRecv32(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuPipe32 + + Description: pipe data from fixed address to fixed address. + 32bit version + + Arguments: src : source address. not incremented + dest : destination address. not incremented + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuPipe32(volatile const void *src, volatile void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuPipe32(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuMove32 + + Description: move memory data (32 bit version) + + Arguments: src : source address, must be in 4 byte alignment + dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuMove32(const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuMove32(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuFind32 + + Description: find memory data (32 bit version) + + Arguments: src : source address, must be in 4 byte alignment + data : target data + size : size (byte), must be in 4 byte alignment + + Returns: pointer to found data or NULL. + *---------------------------------------------------------------------------*/ +static inline void* MI_CpuFind32(const void *src, u32 data, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + + return MIi_CpuFind32(src, data, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuComp32 + + Description: compare memory data (32 bit version) + + Arguments: mem1 : target address 1, must be in 4 byte alignment + mem2 : target address 2, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: < 0 : mem1 smaller than mem2 + = 0 : mem1 equals mem2 + > 0 : mem1 larger than mem2 + *---------------------------------------------------------------------------*/ +static inline int MI_CpuComp32(const void *mem1, const void *mem2, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)mem1 & 3) == 0, "target address 1 must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)mem2 & 3) == 0, "target address 2 must be in 4-byte alignment"); + + return MIi_CpuComp32(mem1, mem2, size); +} + +//================================================================================ +// 16 bit version +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MI_CpuFill16 + + Description: fill memory with specified data. (16 bit version) + + Arguments: dest : destination address to fill data, must be in 2 byte alignment + data : data to fill + size : size (byte), must be in 2 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuFill16(void *dest, u16 data, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)dest & 1) == 0, "source address must be in 2-byte alignment"); + + MIi_CpuClear16(data, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuCopy16 + + Description: copy memory data (16 bit version) + + Arguments: src : source address, must be in 2 byte alignment + dest : destination address, must be in 2 byte alignment + size : size (byte), must be in 2 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuCopy16(const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment"); + + MIi_CpuCopy16(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuClear16 + + Description: fill memory with 0 (16 bit version) + + Arguments: dest : destination address, must be in 2 byte alignment + size : size (byte), must be in 2 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuClear16(void *dest, u32 size) +{ + MI_CpuFill16(dest, 0, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuSend16 + + Description: write some data to fixed address (16 bit version) + + Arguments: src : source address, must be in 2 byte alignment + dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 2 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuSend16(const void *src, volatile void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment"); + + MIi_CpuSend16(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuRecv16 + + Description: receive u16 data from fixed address + 16bit version + + Arguments: src : source address. not incremented + dest : data buffer to receive + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuRecv16(volatile const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment"); + + MIi_CpuRecv16(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuRecv16 + + Description: pipe data from fixed address to fixed address. + 16bit version + + Arguments: src : source address. not incremented + dest : destination address. not incremented + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuPipe16(volatile const void *src, volatile void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment"); + + MIi_CpuPipe16(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuMove16 + + Description: move memory data (16 bit version) + + Arguments: src : source address, must be in 2 byte alignment + dest : destination address, must be in 2 byte alignment + size : size (byte), must be in 2 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuMove16(const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 1) == 0, "destination address must be in 2-byte alignment"); + + MIi_CpuMove16(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuFind16 + + Description: find memory data (16 bit version) + + Arguments: src : source address, must be in 2 byte alignment + data : target data + size : size (byte), must be in 2 byte alignment + + Returns: pointer to found data or NULL. + *---------------------------------------------------------------------------*/ +static inline void* MI_CpuFind16(const void *src, u16 data, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)src & 1) == 0, "source address must be in 2-byte alignment"); + + return MIi_CpuFind16(src, data, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuComp16 + + Description: compare memory data (16 bit version) + + Arguments: mem1 : target address 1, must be in 2 byte alignment + mem2 : target address 2, must be in 2 byte alignment + size : size (byte), must be in 2 byte alignment + + Returns: < 0 : mem1 smaller than mem2 + = 0 : mem1 equals mem2 + > 0 : mem1 larger than mem2 + *---------------------------------------------------------------------------*/ +static inline int MI_CpuComp16(const void *mem1, const void *mem2, u32 size) +{ + SDK_ASSERTMSG((size & 1) == 0, "size & 1 must be 0"); + SDK_ASSERTMSG(((u32)mem1 & 1) == 0, "target address 1 must be in 2-byte alignment"); + SDK_ASSERTMSG(((u32)mem2 & 1) == 0, "target address 2 must be in 2-byte alignment"); + + return MIi_CpuComp16(mem1, mem2, size); +} + +//================================================================================ +// 32 byte unit version +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MI_CpuFillFast + + Description: fill memory with specified data quickly. (32 byte unit version) + + Arguments: dest : destination address to fill data + data : data to fill + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuFillFast(void *dest, u32 data, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "source address must be in 4-byte alignment"); + + MIi_CpuClearFast(data, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuCopyFast + + Description: copy memory data quickly (32 byte unit version) + + Arguments: src : source address, must be in 4 byte alignment + dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuCopyFast(const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuCopyFast(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuClearFast + + Description: fill memory with 0 quickly (32 byte unit version) + + Arguments: dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4-byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuClearFast(void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MI_CpuFillFast(dest, 0, size); +} +/*---------------------------------------------------------------------------* + Name: MI_CpuSendFast + + Description: move memory data (32 byte unit version) + + Arguments: src : data stream to send + dest : destination address, not incremented + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuSendFast( register const void *src, register volatile void *dest, register u32 size ) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuSendFast(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuRecvFast + + Description: move memory data (32 byte unit version) + + Arguments: src : source address. not incremented + dest : data buffer to receive + size : size (byte) + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuRecvFast(volatile const void *src, register void *dest, register u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuRecvFast(src, dest, size); +} + +/*---------------------------------------------------------------------------* + Name: MI_CpuMoveFast + + Description: move memory data (32 byte unit version) + + Arguments: src : source address, must be in 4 byte alignment + dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuMoveFast(const void *src, void *dest, u32 size) +{ + SDK_ASSERTMSG((size & 3) == 0, "size & 3 must be 0"); + SDK_ASSERTMSG(((u32)src & 3) == 0, "source address must be in 4-byte alignment"); + SDK_ASSERTMSG(((u32)dest & 3) == 0, "destination address must be in 4-byte alignment"); + + MIi_CpuMoveFast(src, dest, size); +} + + +//================================================================================ +// 8 bit version +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MI_CpuFill8 + + Description: fill memory with specified data. (8 bit version) + + Arguments: dest : destination address to fill data, no limitation for alignment + data : data to fill + size : size (byte), no limitation for alignment + + Returns: None + *---------------------------------------------------------------------------*/ +void MI_CpuFill8(void *dest, u8 data, u32 size); + +/*---------------------------------------------------------------------------* + Name: MI_CpuCopy8 + + Description: copy memory data (8 bit version) + + Arguments: src : source address, no limitation for alignment + dest : destination address, no limitation for alignment + size : size (byte), no limitation for alignment + + Returns: None + *---------------------------------------------------------------------------*/ +void MI_CpuCopy8(const void *src, void *dest, u32 size); + +/*---------------------------------------------------------------------------* + Name: MI_CpuFind8 + + Description: find memory data (8 bit version) + + Arguments: src : source address, no limitation for alignment + data : target data + size : size (byte), no limitation for alignment + + Returns: pointer to found data or NULL. + *---------------------------------------------------------------------------*/ +void* MI_CpuFind8(const void *src, u8 data, u32 size); + +/*---------------------------------------------------------------------------* + Name: MI_CpuComp8 + + Description: compare memory data (8 bit version) + + Arguments: mem1 : target address 1, no limitation for alignment + mem2 : target address 2, no limitation for alignment + size : size (byte), no limitation for alignment + + Returns: < 0 : mem1 smaller than mem2 + = 0 : mem1 equals mem2 + > 0 : mem1 larger than mem2 + *---------------------------------------------------------------------------*/ +int MI_CpuComp8(const void *mem1, const void *mem2, u32 size); + +/*---------------------------------------------------------------------------* + Name: MI_CpuClear8 + + Description: fill memory with 0 (8 bit version) + + Arguments: dest : destination address, no limitation for alignment + size : size (byte), no limitation for alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuClear8(void *dest, u32 size) +{ + MI_CpuFill8(dest, 0, size); +} + +//================================================================================ +// 32 bit version +//================================================================================ +/*---------------------------------------------------------------------------* + Name: MI_ReadWord + + Description: read 32 bit data from specified address + + Arguments: adrs : address to read + + Returns: data which is read + *---------------------------------------------------------------------------*/ +#ifndef SDK_ASM +#define MI_ReadWord( adrs ) (*(vu32 *)(adrs)) +#endif + +/*---------------------------------------------------------------------------* + Name: MI_WriteWord + + Description: write 32 bit data to specified adress + + Arguments: adrs : address to write + val : data to write + + Returns: None + *---------------------------------------------------------------------------*/ +#ifndef SDK_ASM +#define MI_WriteWord( adrs, val ) do { (*(vu32 *)(adrs)) = (u32)(val); } while(0) +#endif + + +//================================================================================ +// mixed version +//================================================================================ + +/*---------------------------------------------------------------------------* + Name: MI_CpuFill + + Description: fill memory with specified data. (mixed version) + + Arguments: dest : destination address to fill data, no limitation for alignment + data : data to fill + size : size (byte), no limitation for alignment + + Returns: None + *---------------------------------------------------------------------------*/ +void MI_CpuFill(void *dest, u8 data, u32 size); + +/*---------------------------------------------------------------------------* + Name: MI_CpuCopy + + Description: copy memory data (mixed version) + + Arguments: src : source address, no limitation for alignment + dest : destination address, no limitation for alignment + size : size (byte), no limitation for alignment + + Returns: None + *---------------------------------------------------------------------------*/ +void MI_CpuCopy(const void *srcp, void *destp, u32 size); + +/*---------------------------------------------------------------------------* + Name: MI_CpuMove + + Description: move memory data (mixed version) + + Arguments: src : source address, must be in 4 byte alignment + dest : destination address, must be in 4 byte alignment + size : size (byte), must be in 4 byte alignment + + Returns: None + *---------------------------------------------------------------------------*/ +void MI_CpuMove(const void *srcp, void *destp, u32 size); + +/*---------------------------------------------------------------------------* + Name: MI_CpuClear + + Description: fill memory with 0 (mixed version) + + Arguments: dest : destination address, no limitation for alignment + size : size (byte), no limitation for alignment + + Returns: None + *---------------------------------------------------------------------------*/ +static inline void MI_CpuClear(void *dest, u32 size) +{ + MI_CpuFill(dest, 0, size); +} + +//================================================================================ +// the following functions are prepared for SDK private use. +// don't use in application thoughtlessly +//================================================================================ +void MI_Copy16B(register const void *pSrc, register void *pDest); +void MI_Copy32B(register const void *pSrc, register void *pDest); +void MI_Copy36B(register const void *pSrc, register void *pDest); +void MI_Copy48B(register const void *pSrc, register void *pDest); +void MI_Copy64B(register const void *pSrc, register void *pDest); +void MI_Copy128B(register const void *pSrc, register void *pDest); + +void MI_Zero32B(register void *pDest); +void MI_Zero36B(register void *pDest); +void MI_Zero48B(register void *pDest); +void MI_Zero64B(register void *pDest); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_MI_MEMORY_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/os.h b/trunk/bootrom/include/brom/os.h index 55c612a..9cfbe2f 100644 --- a/trunk/bootrom/include/brom/os.h +++ b/trunk/bootrom/include/brom/os.h @@ -14,7 +14,6 @@ $Rev$ $Author$ *---------------------------------------------------------------------------*/ - #ifndef BROM_OS_H_ #define BROM_OS_H_ @@ -29,8 +28,12 @@ extern "C" { #include #include +#include #include #include +#include +#include +#include #include #ifdef SDK_ARM11 #include @@ -38,7 +41,6 @@ extern "C" { #else // SDK_ARM9 #include #include -#include #endif // SDK_ARM9 #if 0 #include diff --git a/trunk/bootrom/include/brom/os/common/alarm.h b/trunk/bootrom/include/brom/os/common/alarm.h new file mode 100644 index 0000000..9432329 --- /dev/null +++ b/trunk/bootrom/include/brom/os/common/alarm.h @@ -0,0 +1,231 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: alarm.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_ALARM_H_ +#define BROM_OS_ALARM_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//-------------------------------------------------------------------------------- +//---- Alarm Handler +typedef void (*OSAlarmHandler) (void *); + + +//---- struct of Alarm +//typedef struct OSiAlarm OSAlarm; // this is decleared in thread.h +struct OSiAlarm +{ + OSAlarmHandler handler; + void *arg; + + u32 tag; + OSTick fire; + OSAlarm *prev; + OSAlarm *next; + + //---- for periodic alarm + OSTick period; + OSTick start; +}; + +//---- Alarm resource +typedef struct OSAlarmResource +{ + int num; +} +OSAlarmResource; + +//-------------------------------------------------------------------------------- +/*---------------------------------------------------------------------------* + Name: osInitAlarm + + Description: initalize alarm system + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void osInitAlarm(void); + + +/*---------------------------------------------------------------------------* + Name: osEndAlarm + + Description: end alarm system + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osEndAlarm(void); + + +/*---------------------------------------------------------------------------* + Name: osIsAlarmAvailable + + Description: check alarm system is available + + Arguments: None + + Returns: if available, TRUE. + *---------------------------------------------------------------------------*/ +BOOL osIsAlarmAvailable(void); + + +/*---------------------------------------------------------------------------* + Name: osCreateAlarm + + Description: Create alarm + + Arguments: alarm pointer to alarm to be initialized + + Returns: None. + *---------------------------------------------------------------------------*/ +void osCreateAlarm(OSAlarm *alarm); + + +/*---------------------------------------------------------------------------* + Name: osSetAlarm + + Description: Set alarm as a relative time + + Arguments: alarm pointer to alarm to be set + tick ticks to count before firing + handler alarm handler to be called + arg argument of handler + + Returns: None. + *---------------------------------------------------------------------------*/ +void osSetAlarm(OSAlarm *alarm, OSTick tick, OSAlarmHandler handler, void *arg); + + +/*---------------------------------------------------------------------------* + Name: osSetPeriodicAlarm + + Description: set periodic alarm + + Arguments: alarm pointer to alarm to be set + start origin of the period in absolute time + period ticks to count for each period + handler alarm handler to be called + arg argument of handler + + Returns: None. + *---------------------------------------------------------------------------*/ +void osSetPeriodicAlarm(OSAlarm *alarm, OSTick start, OSTick period, OSAlarmHandler handler, + void *arg); + + +/*---------------------------------------------------------------------------* + Name: osSetAlarmTag + + Description: set tag which is used osCancelAlarms + + Arguments: alarm alarm to be set tag + tag tagNo + + Returns: None. + *---------------------------------------------------------------------------*/ +void osSetAlarmTag(OSAlarm *alarm, u32 tag); + + +/*---------------------------------------------------------------------------* + Name: osCancelAlarm + + Description: Cancel alarm + + Arguments: alarm pointer to alarm to be canceled + + Returns: None. + *---------------------------------------------------------------------------*/ +void osCancelAlarm(OSAlarm *alarm); + + +/*---------------------------------------------------------------------------* + Name: osCancelAlarms + + Description: cancel alarms which have specified tag + + Arguments: tag tagNo. to be cancelled. not 0 + + Returns: None. + *---------------------------------------------------------------------------*/ +void osCancelAlarms(u32 tag); + + +/*---------------------------------------------------------------------------* + Name: osCancelAllAlarms + + Description: cancel all alarms + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void osCancelAllAlarms(void); + + +//================================================================================ +// FOR DEBUG +//================================================================================ +/*---------------------------------------------------------------------------* + Name: osGetNumberOfAlarm + + Description: get number of alarm + + Arguments: None + + Returns: number of alarm + *---------------------------------------------------------------------------*/ +int osGetNumberOfAlarm(void); + +/*---------------------------------------------------------------------------* + Name: osGetAlarmResource + + Description: store resources of alarm to specified pointer + + Arguments: resource pointer to store alarm resources + + Returns: TRUE ... success (always return this now) + FALSE ... fail + *---------------------------------------------------------------------------*/ +BOOL osGetAlarmResource(OSAlarmResource *resource); + + +//================================================================================ +// The following definitions or declarations are for internal use. +// Don't call these from use program. +struct OSiAlarmQueue +{ + OSAlarm *head; + OSAlarm *tail; +}; +struct OSiAlarmQueue *OSi_GetAlarmQueue(void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_OS_ALARM_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/os/common/context.h b/trunk/bootrom/include/brom/os/common/context.h index 729a09f..2bf16c1 100644 --- a/trunk/bootrom/include/brom/os/common/context.h +++ b/trunk/bootrom/include/brom/os/common/context.h @@ -82,10 +82,10 @@ OSContext; //---------------------------------------------------------------------------- -void OS_InitContext(OSContext *context, u32 newpc, u32 newsp); -BOOL OS_SaveContext(OSContext *context); -void OS_LoadContext(OSContext *context); -void OS_DumpContext(OSContext *context); +void osInitContext(OSContext *context, u32 newpc, u32 newsp); +BOOL osSaveContext(OSContext *context); +void osLoadContext(OSContext *context); +void osDumpContext(OSContext *context); #ifdef __cplusplus } /* extern "C" */ diff --git a/trunk/bootrom/include/brom/os/common/init.h b/trunk/bootrom/include/brom/os/common/init.h index 61f94c8..6ec99fb 100644 --- a/trunk/bootrom/include/brom/os/common/init.h +++ b/trunk/bootrom/include/brom/os/common/init.h @@ -17,13 +17,23 @@ #ifndef BROM_OS_INIT_H_ #define BROM_OS_INIT_H_ +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include +/*---------------------------------------------------------------------------* + Name: osInitBROM + Description: initialize sdk os for bootrom + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void osInitBROM(void); /*---------------------------------------------------------------------------* Name: osInit @@ -34,7 +44,7 @@ extern "C" { Returns: None *---------------------------------------------------------------------------*/ -void osInit(void); +void osInit(void); diff --git a/trunk/bootrom/include/brom/os/common/interrupt_common.h b/trunk/bootrom/include/brom/os/common/interrupt_common.h index 92b5711..97418fd 100644 --- a/trunk/bootrom/include/brom/os/common/interrupt_common.h +++ b/trunk/bootrom/include/brom/os/common/interrupt_common.h @@ -57,7 +57,7 @@ typedef void (*OSIntrFunction) (void); //IRQ void osInterruptHandler( void ); void osInterruptHandler( void ); -void osInitInterruptTable( void ); +void i_osInitInterruptTable( void ); OSIntrMode osEnableIrq( void ); OSIntrMode osDisableIrq( void ); diff --git a/trunk/bootrom/include/brom/os/common/mutex.h b/trunk/bootrom/include/brom/os/common/mutex.h new file mode 100644 index 0000000..de82dd7 --- /dev/null +++ b/trunk/bootrom/include/brom/os/common/mutex.h @@ -0,0 +1,275 @@ +/*---------------------------------------------------------------------------* + Project: CtrBrom - OS - include + File: mutex.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_MUTEX_H_ +#define BROM_OS_MUTEX_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//---------------------------------------------------------------- +//---- mutex type +#define OSi_MUTEX_TYPE_SHIFT 24 +#define OSi_MUTEX_TYPE_MASK (0xff << OSi_MUTEX_TYPE_SHIFT) +#define OS_MUTEX_TYPE_NONE (0x00 << OSi_MUTEX_TYPE_SHIFT) +#define OS_MUTEX_TYPE_STD (0x10 << OSi_MUTEX_TYPE_SHIFT) +#define OS_MUTEX_TYPE_R (0x20 << OSi_MUTEX_TYPE_SHIFT) +#define OS_MUTEX_TYPE_W (0x30 << OSi_MUTEX_TYPE_SHIFT) + +#define OSi_MUTEX_COUNT_MASK 0xffffff + +#ifndef SDK_THREAD_INFINITY +typedef struct OSMutex OSMutex; +#endif + +//#pragma warn_padding off +struct OSMutex +{ + OSThreadQueue queue; + OSThread *thread; // current owner + s32 count; // lock count (notice: use upper 1byte as mutex type) + +#ifndef SDK_THREAD_INFINITY + OSMutex *prev; // link for OSThread.queueMutex + OSMutex *next; // link for OSThread.queueMutex +#else + OSMutexLink link; +#endif +}; +//#pragma warn_padding reset + + +static inline void OS_SetMutexCount( OSMutex* mutex, s32 count ) +{ + mutex->count = (s32)( (mutex->count & OSi_MUTEX_TYPE_MASK) | (count & OSi_MUTEX_COUNT_MASK) ); +} +static inline s32 OS_GetMutexCount( OSMutex* mutex ) +{ + return (s32)( mutex->count & OSi_MUTEX_COUNT_MASK); +} +static inline void OS_IncreaseMutexCount( OSMutex* mutex ) +{ + u32 type = (u32)(mutex->count & OSi_MUTEX_TYPE_MASK); + mutex->count ++; + mutex->count = (s32)( type | (mutex->count & OSi_MUTEX_COUNT_MASK) ); +} +static inline void OS_DecreaseMutexCount( OSMutex* mutex ) +{ + u32 type = (u32)(mutex->count & OSi_MUTEX_TYPE_MASK); + mutex->count --; + mutex->count = (s32)( type | (mutex->count & OSi_MUTEX_COUNT_MASK) ); +} +static inline void OS_SetMutexType( OSMutex* mutex, u32 type ) +{ + mutex->count = (s32)( type | (mutex->count & OSi_MUTEX_COUNT_MASK) ); +} +static inline u32 OS_GetMutexType( OSMutex* mutex ) +{ + return (u32)( mutex->count & OSi_MUTEX_TYPE_MASK ); +} + + +/*---------------------------------------------------------------------------* + Name: OS_InitMutex + + Description: initialize mutex + + Arguments: mutex pointer to mutex structure + to be initialized + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_InitMutex(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_LockMutex + + Description: lock mutex + + Arguments: mutex pointer to mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_LockMutex(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_UnlockMutex + + Description: unlock mutex + + Arguments: mutex pointer to mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_UnlockMutex(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_TryLockMutex + + Description: try to lock mutex + + Arguments: mutex pointer to mutex structure + + Returns: True if lock + *---------------------------------------------------------------------------*/ +BOOL OS_TryLockMutex(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OSi_UnlockAllMutex + + Description: unlocks all the mutexes locked by the thread + + Arguments: mutex pointer to mutex structure + + Returns: None. + *---------------------------------------------------------------------------*/ +void OSi_UnlockAllMutex(OSThread *thread); + + +/*---------------------------------------------------------------------------* + Name: OS_LockMutexR + + Description: lock RW mutex as READ access + + Arguments: mutex pointer to RW mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_LockMutexR(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_LockMutexW + + Description: lock RW mutex as WRITE access + + Arguments: mutex pointer to RW mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_LockMutexW(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_TryLockMutexR + + Description: try to lock RW mutex as READ access + + Arguments: mutex pointer to RW mutex structure + + Returns: TRUE if locked + *---------------------------------------------------------------------------*/ +BOOL OS_TryLockMutexR(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_TryLockMutexW + + Description: try to lock RW mutex as WRITE access + + Arguments: mutex pointer to RW mutex structure + + Returns: TRUE if locked + *---------------------------------------------------------------------------*/ +BOOL OS_TryLockMutexW(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_UnlockMutexR + + Description: unlock mutex locked as READ access + + Arguments: mutex pointer to mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_UnlockMutexR(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_UnlockMutexW + + Description: unlock mutex locked as WRITE access + + Arguments: mutex pointer to mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_UnlockMutexW(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_UnlockMutexRW + + Description: unlock mutex locked as READ/WRITE access + + Arguments: mutex pointer to mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_UnlockMutexRW(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_LockMutexFromRToW + + Description: Promote mutexR lock to mutexW lock without unlock. + Wait till success. + + Arguments: mutex pointer to mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_LockMutexFromRToW(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_TryLockMutexFromRToW + + Description: Try to promote mutexR lock to mutexW lock without unlock. + + Arguments: mutex pointer to mutex structure + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL OS_TryLockMutexFromRToW(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_LockMutexFromWToR + + Description: Demote mutexW lock to mutexR lock without unlock. + Wait till success. + + Arguments: mutex pointer to mutex structure + + Returns: None + *---------------------------------------------------------------------------*/ +void OS_LockMutexFromWToR(OSMutex *mutex); + +/*---------------------------------------------------------------------------* + Name: OS_TryLockMutexFromWToR + + Description: Try to demote mutexW lock to mutexR lock without unlock. + + Arguments: mutex pointer to mutex structure + + Returns: TRUE if success + *---------------------------------------------------------------------------*/ +BOOL OS_TryLockMutexFromWToR(OSMutex *mutex); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* BROM_OS_MUTEX_H_ */ +#endif diff --git a/trunk/bootrom/include/brom/os/common/system.h b/trunk/bootrom/include/brom/os/common/system.h index cfb21f3..4a82695 100644 --- a/trunk/bootrom/include/brom/os/common/system.h +++ b/trunk/bootrom/include/brom/os/common/system.h @@ -22,10 +22,8 @@ #endif #include -#ifdef SDK_ARM11 -#else // SDK_ARM9 -#include -#endif //SDK_ARM9 +#include + #ifdef __cplusplus extern "C" { @@ -126,7 +124,7 @@ static inline u32 i_osCpuCycleToNSec( OSCpuCycle cyc ) // PROCESSER MODE //============================================================================ /*---------------------------------------------------------------------------* - Name: i_osGetProcMode + Name: osGetProcMode Description: Get processor mode from CPSR @@ -134,7 +132,7 @@ static inline u32 i_osCpuCycleToNSec( OSCpuCycle cyc ) Returns: CPU processor mode (field 0x10-0x1f) *---------------------------------------------------------------------------*/ -OSProcMode i_osGetProcMode(void); +OSProcMode osGetProcMode(void); //============================================================================ // WAIT @@ -156,7 +154,7 @@ void i_osWaitCpuCycles( OSCpuCycle cycle ); // TERMINATE and HALT //============================================================================ /*---------------------------------------------------------------------------* - Name: i_osTerminate + Name: osTerminate Description: Halt CPU and loop @@ -164,10 +162,10 @@ void i_osWaitCpuCycles( OSCpuCycle cycle ); Returns: None *---------------------------------------------------------------------------*/ -extern void i_osTerminate(void); +extern void osTerminate(void); /*---------------------------------------------------------------------------* - Name: i_osHalt + Name: osHalt Description: Halt CPU @@ -175,10 +173,10 @@ extern void i_osTerminate(void); Returns: None *---------------------------------------------------------------------------*/ -extern void i_osHalt(void); +extern void osHalt(void); /*---------------------------------------------------------------------------* - Name: i_osExit + Name: osExit Description: Display exit string and Terminate. This is useful for 'loadrun' tool command. @@ -187,7 +185,7 @@ extern void i_osHalt(void); Returns: -- (Never return) *---------------------------------------------------------------------------*/ -extern void i_osExit(int status); +extern void osExit(int status); #endif /* SDK_ASM */ diff --git a/trunk/bootrom/include/brom/os/common/thread.h b/trunk/bootrom/include/brom/os/common/thread.h index 8994c71..a9ce0d2 100644 --- a/trunk/bootrom/include/brom/os/common/thread.h +++ b/trunk/bootrom/include/brom/os/common/thread.h @@ -42,7 +42,7 @@ extern "C" { #define OS_THREAD_MAX_NUM 16 // changed 8 to 16 (2004/5/26) #endif -//---- priority of thread that calls OS_InitThread() +//---- priority of thread that calls osInitThread() #define OS_THREAD_LAUNCHER_PRIORITY 16 //---- range of thread priority @@ -216,6 +216,13 @@ OSStackStatus; //---------------- thread switch callback typedef void (*OSSwitchThreadCallback) (OSThread *from, OSThread *to); +//---------------- thread resource +typedef struct OSThreadResource +{ + int num; +} +OSThreadResource; + //---------------------------------------------------------------------------- //---- private function ( don't use these OSi_* function ) void OSi_CheckStack(const char *file, int line, const OSThread *thread); @@ -224,7 +231,7 @@ u32 OSi_GetCurrentStackPointer(void); OSThread *OSi_GetIdleThread(void); /*---------------------------------------------------------------------------* - Name: OS_InitThread + Name: osInitThread Description: Initialize Thread System @@ -232,10 +239,10 @@ OSThread *OSi_GetIdleThread(void); Returns: None *---------------------------------------------------------------------------*/ -void OS_InitThread(void); +void osInitThread(void); /*---------------------------------------------------------------------------* - Name: OS_IsThreadAvailable + Name: osIsThreadAvailable Description: check if thread system is available @@ -243,10 +250,10 @@ void OS_InitThread(void); Returns: TRUE if available, FALSE if not *---------------------------------------------------------------------------*/ -BOOL OS_IsThreadAvailable(void); +BOOL osIsThreadAvailable(void); /*---------------------------------------------------------------------------* - Name: OS_CreateThread + Name: osCreateThread Description: Create a new Thread @@ -259,12 +266,12 @@ BOOL OS_IsThreadAvailable(void); Returns: None *---------------------------------------------------------------------------*/ -void OS_CreateThread(OSThread *thread, +void osCreateThread(OSThread *thread, void (*func) (void *), void *arg, void *stack, u32 stackSize, u32 prio); /*---------------------------------------------------------------------------* - Name: OS_ExitThread + Name: osExitThread Description: Exit thread @@ -272,11 +279,11 @@ void OS_CreateThread(OSThread *thread, Returns: None *---------------------------------------------------------------------------*/ -void OS_ExitThread(void); +void osExitThread(void); /*---------------------------------------------------------------------------* - Name: OS_DestroyThread + Name: osDestroyThread Description: destroy specified thread. @@ -284,11 +291,11 @@ void OS_ExitThread(void); Returns: None *---------------------------------------------------------------------------*/ -void OS_DestroyThread(OSThread *thread); +void osDestroyThread(OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_KillThread + Name: osKillThread Description: switch PC to thread destructor to finalize thread @@ -298,13 +305,13 @@ void OS_DestroyThread(OSThread *thread); Returns: None *---------------------------------------------------------------------------*/ #ifdef SDK_THREAD_INFINITY -void OS_KillThread(OSThread *thread, void *arg); -void OS_KillThreadWithPriority(OSThread *thread, void *arg, u32 prio); +void osKillThread(OSThread *thread, void *arg); +void osKillThreadWithPriority(OSThread *thread, void *arg, u32 prio); #endif /*---------------------------------------------------------------------------* - Name: OS_JoinThread + Name: osJoinThread Description: wait for specified thread to terminated @@ -312,11 +319,11 @@ void OS_KillThreadWithPriority(OSThread *thread, void *arg, u32 prio); Returns: None *---------------------------------------------------------------------------*/ -void OS_JoinThread(OSThread *thread); +void osJoinThread(OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_IsThreadTeminated + Name: osIsThreadTeminated Description: check thread status whether it's terminated @@ -324,11 +331,11 @@ void OS_JoinThread(OSThread *thread); Returns: TRUE if the thread is terminated. FALSE if not *---------------------------------------------------------------------------*/ -BOOL OS_IsThreadTerminated(const OSThread *thread); +BOOL osIsThreadTerminated(const OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_SelectThread + Name: osSelectThread Description: Select thread to execute @@ -336,11 +343,11 @@ BOOL OS_IsThreadTerminated(const OSThread *thread); Returns: thread to execute *---------------------------------------------------------------------------*/ -OSThread *OS_SelectThread(void); +OSThread *osSelectThread(void); /*---------------------------------------------------------------------------* - Name: OS_RescheduleThread + Name: osRescheduleThread Description: do rescheduling threads @@ -348,10 +355,10 @@ OSThread *OS_SelectThread(void); Returns: None *---------------------------------------------------------------------------*/ -void OS_RescheduleThread(void); +void osRescheduleThread(void); /*---------------------------------------------------------------------------* - Name: OS_YieldThread + Name: osYieldThread Description: do thread rescheduling. current thread relinquish CPU to give chance of running to other threads which has same @@ -361,11 +368,11 @@ void OS_RescheduleThread(void); Returns: None *---------------------------------------------------------------------------*/ -extern void OS_YieldThread(void); +extern void osYieldThread(void); /*---------------------------------------------------------------------------* - Name: OS_SleepThread + Name: osSleepThread Description: sleep current thread @@ -373,11 +380,11 @@ extern void OS_YieldThread(void); Returns: None *---------------------------------------------------------------------------*/ -void OS_SleepThread(OSThreadQueue *queue); +void osSleepThread(OSThreadQueue *queue); /*---------------------------------------------------------------------------* - Name: OS_WakeupThread + Name: osWakeupThread Description: wake up threads by queue @@ -385,11 +392,11 @@ void OS_SleepThread(OSThreadQueue *queue); Returns: None *---------------------------------------------------------------------------*/ -void OS_WakeupThread(OSThreadQueue *queue); +void osWakeupThread(OSThreadQueue *queue); /*---------------------------------------------------------------------------* - Name: OS_WakeupThreadDirect + Name: osWakeupThreadDirect Description: wake up thread by specifying thread directly @@ -397,11 +404,11 @@ void OS_WakeupThread(OSThreadQueue *queue); Returns: None *---------------------------------------------------------------------------*/ -void OS_WakeupThreadDirect(OSThread *thread); +void osWakeupThreadDirect(OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_DumpThreadList + Name: osDumpThreadList Description: Dump All Thread Infomation (for DEBUG) @@ -409,11 +416,11 @@ void OS_WakeupThreadDirect(OSThread *thread); Returns: None *---------------------------------------------------------------------------*/ -void OS_DumpThreadList(void); +void osDumpThreadList(void); /*---------------------------------------------------------------------------* - Name: OS_GetNumberOfThread + Name: osGetNumberOfThread Description: Get number of thread which exists in system @@ -421,11 +428,11 @@ void OS_DumpThreadList(void); Returns: number of thread which exists in system *---------------------------------------------------------------------------*/ -int OS_GetNumberOfThread(void); +int osGetNumberOfThread(void); /*==== static inlie functions ====*/ /*---------------------------------------------------------------------------* - Name: OS_GetThreadInfo + Name: osGetThreadInfo Description: Get pointer of system thread info structure. @@ -435,13 +442,13 @@ int OS_GetNumberOfThread(void); *---------------------------------------------------------------------------*/ extern OSThreadInfo OSi_ThreadInfo; -static inline OSThreadInfo *OS_GetThreadInfo(void) +static inline OSThreadInfo *osGetThreadInfo(void) { return &OSi_ThreadInfo; } /*---------------------------------------------------------------------------* - Name: OS_GetMaxThreadId + Name: osGetMaxThreadId Description: Gets Max id number of available thread number @@ -449,17 +456,17 @@ static inline OSThreadInfo *OS_GetThreadInfo(void) Returns: Max id of available thread number *---------------------------------------------------------------------------*/ -static inline u32 OS_GetMaxThreadId(void) +static inline u32 osGetMaxThreadId(void) { #ifndef SDK_THREAD_INFINITY - return OS_GetThreadInfo()->max_entry; + return osGetThreadInfo()->max_entry; #else return 0x7fffffff; // (=maximin number of int) #endif } /*---------------------------------------------------------------------------* - Name: OS_GetThread + Name: osGetThread Description: Gets pointer to thread which id is specified @@ -468,17 +475,17 @@ static inline u32 OS_GetMaxThreadId(void) Returns: pointer to thread which id is specified *---------------------------------------------------------------------------*/ #ifndef SDK_THREAD_INFINITY -static inline OSThread *OS_GetThread(u32 id) +static inline OSThread *osGetThread(u32 id) { SDK_ASSERTMSG(id < OS_THREAD_MAX_NUM, "Thread id illegal\n"); - return OS_GetThreadInfo()->entry[id]; + return osGetThreadInfo()->entry[id]; } #else -extern OSThread *OS_GetThread(u32 id); +extern OSThread *osGetThread(u32 id); #endif /*---------------------------------------------------------------------------* - Name: OS_GetThreadId + Name: osGetThreadId Description: Gets id of specified thread @@ -486,14 +493,14 @@ extern OSThread *OS_GetThread(u32 id); Returns: id of specified thread *---------------------------------------------------------------------------*/ -static inline u32 OS_GetThreadId(const OSThread *thread) +static inline u32 osGetThreadId(const OSThread *thread) { SDK_ASSERTMSG(thread, "null thread pointer."); return thread->id; } /*---------------------------------------------------------------------------* - Name: OS_GetThreadState + Name: osGetThreadState Description: Gets state of specified thread @@ -501,14 +508,14 @@ static inline u32 OS_GetThreadId(const OSThread *thread) Returns: state of specified thead *---------------------------------------------------------------------------*/ -static inline OSThreadState OS_GetThreadState(const OSThread *thread) +static inline OSThreadState osGetThreadState(const OSThread *thread) { SDK_ASSERTMSG(thread, "null thread pointer."); return thread->state; } /*---------------------------------------------------------------------------* - Name: OS_GetThreadContext + Name: osGetThreadContext Description: Gets pointer to context of specified thread @@ -516,14 +523,14 @@ static inline OSThreadState OS_GetThreadState(const OSThread *thread) Returns: pointer to context of specified thread *---------------------------------------------------------------------------*/ -static inline OSContext *OS_GetThreadContext(const OSThread *thread) +static inline OSContext *osGetThreadContext(const OSThread *thread) { SDK_ASSERTMSG(thread, "null thread pointer."); return (OSContext *)&thread->context; } /*---------------------------------------------------------------------------* - Name: OS_IsThreadRunnable + Name: osIsThreadRunnable Description: Check if thread is runnable @@ -531,13 +538,13 @@ static inline OSContext *OS_GetThreadContext(const OSThread *thread) Returns: non zero if thread is runnable *---------------------------------------------------------------------------*/ -static inline BOOL OS_IsThreadRunnable(const OSThread *thread) +static inline BOOL osIsThreadRunnable(const OSThread *thread) { return thread->state == OS_THREAD_STATE_READY; } /*---------------------------------------------------------------------------* - Name: OS_InitThreadQueue + Name: osInitThreadQueue Description: Initialize thread queue @@ -545,7 +552,7 @@ static inline BOOL OS_IsThreadRunnable(const OSThread *thread) Returns: None *---------------------------------------------------------------------------*/ -static inline void OS_InitThreadQueue(OSThreadQueue *queue) +static inline void osInitThreadQueue(OSThreadQueue *queue) { #ifndef SDK_THREAD_INFINITY *queue = 0; @@ -555,7 +562,7 @@ static inline void OS_InitThreadQueue(OSThreadQueue *queue) } /*---------------------------------------------------------------------------* - Name: OS_GetCurrentThread + Name: osGetCurrentThread Description: Gets pointer to the current thread @@ -563,13 +570,13 @@ static inline void OS_InitThreadQueue(OSThreadQueue *queue) Returns: Pointer to the current thread *---------------------------------------------------------------------------*/ -static inline OSThread *OS_GetCurrentThread(void) +static inline OSThread *osGetCurrentThread(void) { - return OS_GetThreadInfo()->current; + return osGetThreadInfo()->current; } /*---------------------------------------------------------------------------* - Name: OS_SetCurrentThread + Name: osSetCurrentThread Description: Saves pointer to the current thread @@ -577,14 +584,14 @@ static inline OSThread *OS_GetCurrentThread(void) Returns: Pointer to the current thread *---------------------------------------------------------------------------*/ -static inline void OS_SetCurrentThread(OSThread *thread) +static inline void osSetCurrentThread(OSThread *thread) { - OS_GetThreadInfo()->current = thread; + osGetThreadInfo()->current = thread; } /*==== stack check ====*/ /*---------------------------------------------------------------------------* - Name: OS_SetThreadStackWarningOffset + Name: osSetThreadStackWarningOffset Description: Set warning level for stack checker @@ -593,11 +600,11 @@ static inline void OS_SetCurrentThread(OSThread *thread) Returns: None *---------------------------------------------------------------------------*/ -void OS_SetThreadStackWarningOffset(OSThread *thread, u32 offset); +void osSetThreadStackWarningOffset(OSThread *thread, u32 offset); /*---------------------------------------------------------------------------* - Name: OS_GetStackStatus + Name: osGetStackStatus Description: check thread stack. check each CheckNUM. return result. @@ -609,10 +616,10 @@ void OS_SetThreadStackWarningOffset(OSThread *thread, u32 offset); OS_STACK_ABOUT_TO_OVERFLOW about to overflow OS_STACK_UNDERFLOW underflow *---------------------------------------------------------------------------*/ -OSStackStatus OS_GetStackStatus(const OSThread *thread); +OSStackStatus osGetStackStatus(const OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_CheckStack + Name: osCheckStack Description: check thread stack. check each CheckNum. if changed, display warning and halt. @@ -623,13 +630,13 @@ OSStackStatus OS_GetStackStatus(const OSThread *thread); ( if error occurred, never return ) *---------------------------------------------------------------------------*/ #if !defined(SDK_FINALROM) && !defined(SDK_NO_MESSAGE) -#define OS_CheckStack( thread ) OSi_CheckStack( __FILE__, __LINE__, (const OSThread*)thread ); +#define osCheckStack( thread ) OSi_CheckStack( __FILE__, __LINE__, (const OSThread*)thread ); #else -#define OS_CheckStack( thread ) ((void)0) +#define osCheckStack( thread ) ((void)0) #endif /*---------------------------------------------------------------------------* - Name: OS_SetThreadPriority + Name: osSetThreadPriority Description: change priority of thread @@ -638,11 +645,11 @@ OSStackStatus OS_GetStackStatus(const OSThread *thread); Returns: TRUE if success *---------------------------------------------------------------------------*/ -BOOL OS_SetThreadPriority(OSThread *thread, u32 prio); +BOOL osSetThreadPriority(OSThread *thread, u32 prio); /*---------------------------------------------------------------------------* - Name: OS_GetThreadPriority + Name: osGetThreadPriority Description: get priority of thread @@ -650,11 +657,11 @@ BOOL OS_SetThreadPriority(OSThread *thread, u32 prio); Returns: priority *---------------------------------------------------------------------------*/ -u32 OS_GetThreadPriority(const OSThread *thread); +u32 osGetThreadPriority(const OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_Sleep + Name: osSleep Description: sleep specified period @@ -662,11 +669,11 @@ u32 OS_GetThreadPriority(const OSThread *thread); Returns: None. *---------------------------------------------------------------------------*/ -void OS_Sleep(u32 msec); +void osSleep(u32 msec); /*---------------------------------------------------------------------------* - Name: OS_SetSwitchThreadCallback + Name: osSetSwitchThreadCallback Description: set callback called at switching thread @@ -674,13 +681,13 @@ void OS_Sleep(u32 msec); Returns: previous callback function before set callback now *---------------------------------------------------------------------------*/ -OSSwitchThreadCallback OS_SetSwitchThreadCallback(OSSwitchThreadCallback callback); +OSSwitchThreadCallback osSetSwitchThreadCallback(OSSwitchThreadCallback callback); // notice: substans is in os_callTrace.c. // define here because of OSThread declaration. /*---------------------------------------------------------------------------* - Name: OS_DumpThreadCallTrace + Name: osDumpThreadCallTrace Description: dump callStack of thread @@ -688,12 +695,12 @@ OSSwitchThreadCallback OS_SetSwitchThreadCallback(OSSwitchThreadCallback callbac Returns: None *---------------------------------------------------------------------------*/ -void OS_DumpThreadCallTrace(const OSThread *thread); +void osDumpThreadCallTrace(const OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_DisableScheduler + Name: osDisableScheduler Description: disable scheduler @@ -702,10 +709,10 @@ void OS_DumpThreadCallTrace(const OSThread *thread); Returns: Previous scheduler suspend count. Suspended if value >= 0. *---------------------------------------------------------------------------*/ -u32 OS_DisableScheduler(void); +u32 osDisableScheduler(void); /*---------------------------------------------------------------------------* - Name: OS_EnableScheduler + Name: osEnableScheduler Description: enable scheduler @@ -714,12 +721,12 @@ u32 OS_DisableScheduler(void); Returns: Previous scheduler suspend count. Suspended if value >= 0. *---------------------------------------------------------------------------*/ -u32 OS_EnableScheduler(void); +u32 osEnableScheduler(void); #ifdef SDK_THREAD_INFINITY /*---------------------------------------------------------------------------* - Name: OS_SetThreadDestructor + Name: osSetThreadDestructor Description: set thread destructor, which is called when that thread exits. @@ -728,10 +735,10 @@ u32 OS_EnableScheduler(void); Returns: None *---------------------------------------------------------------------------*/ -void OS_SetThreadDestructor(OSThread *thread, OSThreadDestructor dtor); +void osSetThreadDestructor(OSThread *thread, OSThreadDestructor dtor); /*---------------------------------------------------------------------------* - Name: OS_GetThreadDestructor + Name: osGetThreadDestructor Description: get thread destructor which is set @@ -739,10 +746,10 @@ void OS_SetThreadDestructor(OSThread *thread, OSThreadDestructor dtor); Returns: destructor function *---------------------------------------------------------------------------*/ -OSThreadDestructor OS_GetThreadDestructor(const OSThread *thread); +OSThreadDestructor osGetThreadDestructor(const OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_SetThreadParameter + Name: osSetThreadParameter Description: set user parameter which is allowed to use freely. @@ -751,10 +758,10 @@ OSThreadDestructor OS_GetThreadDestructor(const OSThread *thread); Returns: None *---------------------------------------------------------------------------*/ -void OS_SetThreadParameter(OSThread *thread, void *parameter); +void osSetThreadParameter(OSThread *thread, void *parameter); /*---------------------------------------------------------------------------* - Name: OS_GetThreadParameter + Name: osGetThreadParameter Description: get user parameter which is set @@ -762,10 +769,10 @@ void OS_SetThreadParameter(OSThread *thread, void *parameter); Returns: user parameter which is set *---------------------------------------------------------------------------*/ -void *OS_GetThreadParameter(const OSThread *thread); +void *osGetThreadParameter(const OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_GetErrno + Name: osGetErrno Description: get system error number. @@ -773,11 +780,11 @@ void *OS_GetThreadParameter(const OSThread *thread); Returns: error number *---------------------------------------------------------------------------*/ -int OS_GetErrno(void); +int osGetErrno(void); #endif /*---------------------------------------------------------------------------* - Name: OS_IsThreadInList + Name: osIsThreadInList Description: check if the specified thread is in the thread list @@ -785,10 +792,10 @@ int OS_GetErrno(void); Returns: TRUE if thread is in the thread list *---------------------------------------------------------------------------*/ -BOOL OS_IsThreadInList(const OSThread *thread); +BOOL osIsThreadInList(const OSThread *thread); /*---------------------------------------------------------------------------* - Name: OS_SetThreadDestructorStack + Name: osSetThreadDestructorStack Description: specify stack area to call thread destructor @@ -796,7 +803,7 @@ BOOL OS_IsThreadInList(const OSThread *thread); Returns: None *---------------------------------------------------------------------------*/ -void OS_SetThreadDestructorStack(void *stack); +void osSetThreadDestructorStack(void *stack); #ifdef SDK_THREAD_INFINITY @@ -880,7 +887,7 @@ static inline void *OSi_GetSpecificData(const OSThread *thread, int index) // use carefully. //================================================================================ /*---------------------------------------------------------------------------* - Name: OS_GetThreadList + Name: osGetThreadList Description: get first thread of thread list. @@ -888,14 +895,14 @@ static inline void *OSi_GetSpecificData(const OSThread *thread, int index) Returns: first thread of thread list *---------------------------------------------------------------------------*/ -static inline OSThread *OS_GetThreadList(void) +static inline OSThread *osGetThreadList(void) { - return OS_GetThreadInfo()->list; + return osGetThreadInfo()->list; } /*---------------------------------------------------------------------------* - Name: OS_GetNextThread + Name: osGetNextThread Description: get thread which is linked next in thread list @@ -903,7 +910,7 @@ static inline OSThread *OS_GetThreadList(void) Returns: next thread. NULL means no next thread ( specified thread may be last ) *---------------------------------------------------------------------------*/ -static inline OSThread *OS_GetNextThread(const OSThread *thread) +static inline OSThread *osGetNextThread(const OSThread *thread) { SDK_ASSERT(thread); return thread->next; diff --git a/trunk/bootrom/include/brom/os/ARM9/tick.h b/trunk/bootrom/include/brom/os/common/tick.h similarity index 93% rename from trunk/bootrom/include/brom/os/ARM9/tick.h rename to trunk/bootrom/include/brom/os/common/tick.h index 23776c4..3f4acde 100644 --- a/trunk/bootrom/include/brom/os/ARM9/tick.h +++ b/trunk/bootrom/include/brom/os/common/tick.h @@ -24,7 +24,7 @@ extern "C" { #include #include #include -#include +//#include //---- unit of tick @@ -39,7 +39,11 @@ extern void osSetTick( u64 ); //---- conversion tick count <-> real time count +#ifdef SDK_ARM11 +#define OS_SYSTEM_CLOCK HW_CPU_CLOCK +#else // SDK_ARM9 #define OS_SYSTEM_CLOCK HW_SYSTEM_CLOCK +#endif // SDK_ARM9 //---- sec to tick #define OSi_SEC_TO_TICK( sec, prescale ) ((OSTick)( (OS_SYSTEM_CLOCK * (u64)(sec)) / (prescale) )) diff --git a/trunk/bootrom/include/brom/specfiles/ARM11.ldscript.template b/trunk/bootrom/include/brom/specfiles/ARM11.ldscript.template index b2f87fb..44bbf94 100644 --- a/trunk/bootrom/include/brom/specfiles/ARM11.ldscript.template +++ b/trunk/bootrom/include/brom/specfiles/ARM11.ldscript.template @@ -35,11 +35,9 @@ LOAD_UNABORT HW_BROM_NML_ABT_END (HW_BROM_NML_SIZE - HW_BROM_NML_ABT_SIZE) NML_RO +0 { *crt0_excp.o (.emb_text, +FIRST) - *libos*.brom*.a (:gdef:OSi_Boot) - *libos*.brom*.a (:gdef:OSi_BootCore) - *libos*.brom*.a (:gdef:OSi_ClearWorkArea) - *libos*.brom*.a (:gdef:OS_DisableInterrupts) - *libos*.brom*.a (:gdef:OS_RestoreInterrupts) + *libos*.brom*.a (:gdef:osBoot) + *libos*.brom*.a (:gdef:osDisableInterrupts) + *libos*.brom*.a (:gdef:osRestoreInterrupts) *libmi*.brom*.a (+RO) *libswi*.brom*.a (+RO) *libpxi*.brom*.a (+RO) diff --git a/trunk/build/buildtools/commondefs.cctype.RVCT b/trunk/build/buildtools/commondefs.cctype.RVCT index 22ef0af..0403a6c 100644 --- a/trunk/build/buildtools/commondefs.cctype.RVCT +++ b/trunk/build/buildtools/commondefs.cctype.RVCT @@ -212,6 +212,7 @@ MACRO_FLAGS += $(LMACRO_FLAGS) #---------------------------------------------------------------------------- # Demote the following compiler warnings to remarks: # +# 61: integer operation result is out of range # 66: enumeration value is out of "int" range # 108: signed bit field of length 1 # 177: variable was declared but never referenced @@ -221,7 +222,7 @@ MACRO_FLAGS += $(LMACRO_FLAGS) #A1329W: Unsafe instruction (forced user mode transfer with write-back to base) #A1581W: Added 2 bytes of padding at address 0x3e2 T_CFLAGS_WARN += --diag_remark 236,177 -T_CFLAGS_WARN += --diag_suppress 66,108,1256,A1329W,A1581W +T_CFLAGS_WARN += --diag_suppress 61,66,108,1256,A1329W,A1581W # Promote the following compiler warnings to errors: #