/*---------------------------------------------------------------------------* Project: CtrBrom - libraries - OS File: os_system.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 osTPrintf(...) ((void)0) //============================================================================ // PROCESSER MODE //============================================================================ /*---------------------------------------------------------------------------* Name: osGetProcMode Description: Get processor mode from CPSR Arguments: None. Returns: CPU processor mode (field 0x10-0x1f) *---------------------------------------------------------------------------*/ #include ASM OSProcMode osGetProcMode( void ) { mrs r0, cpsr and r0, r0, #HW_PSR_CPU_MODE_MASK bx lr } #include //============================================================================ // WAIT //============================================================================ /*---------------------------------------------------------------------------* Name: i_osWaitCpuCycles Description: Loop and Wait for specified CPU cycles at least Arguments: cycles waiting CPU cycle Returns: None *---------------------------------------------------------------------------*/ #include ASM void i_osWaitCpuCycles( OSCpuCycle cycle ) { sub r0, r0, #(6-2) // subtract call-return overhead and add the margin of 2 cycles LSYM(1) subs r0, r0, #4 // 1 cycle bcs BSYM(1) // 3 cycle bx lr } #include //============================================================================ // TERMINATE and HALT //============================================================================ /*---------------------------------------------------------------------------* Name: osTerminate Description: Halt CPU and loop Arguments: None Returns: -- (Never return) *---------------------------------------------------------------------------*/ void osTerminate(void) { while (1) { (void)osDisableInterrupts(); osHalt(); } } /*---------------------------------------------------------------------------* Name: osHalt Description: Halt CPU Arguments: None Returns: None *---------------------------------------------------------------------------*/ #include ASM void osHalt( void ) { mov r0, #0 mcr p15, 0, r0, c7, c0, 4 bx lr } #include /*---------------------------------------------------------------------------* Name: osExit Description: Display exit string and Terminate. This is useful for 'loadrun' tool command. Arguments: status : exit status Returns: -- (Never return) *---------------------------------------------------------------------------*/ void osExit(int status) { #ifdef SDK_FINALROM #pragma unused( status ) #endif (void)osDisableInterrupts(); osTPrintf("\n" OS_EXIT_STRING, status); osTerminate(); }