1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: os_SimpleAutoStackManager.cpp 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev:$ 14 *---------------------------------------------------------------------------*/ 15 16 #include <nn/config.h> 17 #if NN_PLATFORM_HAS_MMU 18 19 #include <nn/os.h> 20 #include <nn/fnd.h> 21 #include <nn/math.h> 22 23 namespace nn { namespace os { 24 25 namespace 26 { 27 struct DataOnStack 28 { 29 void* pHead; 30 }; 31 } 32 Construct(size_t stackSize)33 void* SimpleAutoStackManager::Construct(size_t stackSize) 34 { 35 NN_TASSERT_(IsInitialized()); 36 37 void* const pMemory = GetAllocator()->Allocate(stackSize, 4); 38 NN_POINTER_TASSERT_(pMemory); 39 40 uptr stackBottom = reinterpret_cast<uptr>(pMemory) + stackSize; 41 stackBottom = math::RoundDown(stackBottom - sizeof(DataOnStack), 8); 42 DataOnStack* const pStackBottom = reinterpret_cast<DataOnStack*>(stackBottom); 43 44 pStackBottom->pHead = pMemory; 45 46 return pStackBottom; 47 } 48 FreeStack(void * pStackBottom)49 void SimpleAutoStackManager::FreeStack(void* pStackBottom) 50 { 51 DataOnStack& dos = *reinterpret_cast<DataOnStack*>(pStackBottom); 52 GetAllocator()->Free(dos.pHead); 53 } 54 55 56 }} // namespace nn::os 57 58 #endif // if NN_PLATFORM_HAS_MMU 59