/*---------------------------------------------------------------------------* Project: Horizon File: os_StackMemoryBlock.cpp Copyright (C)2009 Nintendo Co., Ltd. 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. $Rev: 17558 $ *---------------------------------------------------------------------------*/ #include #if NN_PLATFORM_HAS_MMU #include #include #include #include #include #include #include #include #include #include #include "os_AddressSpaceManager.h" //--------------------------------------------------------------------------- using namespace nn; using namespace nn::svc; namespace nn{ namespace os{ namespace { size_t GetPageAlignedSize(size_t size) { return (size + NN_OS_MEMORY_PAGE_SIZE - 1) & ~(NN_OS_MEMORY_PAGE_SIZE - 1); } } namespace detail { void Switch(StackMemoryBlock* pTo, StackMemoryBlock* pFrom) { Switch( reinterpret_cast(pTo), reinterpret_cast(pFrom) ); } } // スタック領域からメモリブロックを確保します。 void StackMemoryBlock::Initialize(size_t size) { NN_TASSERT_(detail::IsMemoryBlockEnabled()); // 未初期化であることをチェックします。 NN_TASSERT_( GetAddress() == NULL ); size = GetPageAlignedSize(size); // 仮想アドレス空間からメモリを取得します。 uptr addr = detail::AllocateFromMemoryBlockSpace(this, size); if (addr == NULL) { NN_TPANIC_("failed to allocate address space."); } } void StackMemoryBlock::Finalize() { if ( GetAddress() != NULL ) { detail::FreeToMemoryBlockSpace(this); } } }} // namespace nn::os #include using namespace nn::os; extern "C" { // StackMemoryBlock void nnosStackMemoryBlockInitialize(nnosStackMemoryBlock* p) { new (p) StackMemoryBlock(); } void nnosStackMemoryBlockAllocate(nnosStackMemoryBlock* p, size_t size) { NN_TASSERT_(detail::IsMemoryBlockEnabled()); new (p) StackMemoryBlock(size); } void nnosStackMemoryBlockFree(nnosStackMemoryBlock* p) { StackMemoryBlock* pStackMemoryBlock = reinterpret_cast(p); pStackMemoryBlock->~StackMemoryBlock(); } uptr nnosStackMemoryBlockGetAddress(nnosStackMemoryBlock* p) { StackMemoryBlock* pStackMemoryBlock = reinterpret_cast(p); return pStackMemoryBlock->GetAddress(); } size_t nnosStackMemoryBlockGetSize(nnosStackMemoryBlock* p) { StackMemoryBlock* pStackMemoryBlock = reinterpret_cast(p); return pStackMemoryBlock->GetSize(); } uptr nnosStackMemoryBlockGetStackBottom(nnosStackMemoryBlock* p) { StackMemoryBlock* pStackMemoryBlock = reinterpret_cast(p); return pStackMemoryBlock->GetStackBottom(); } } #endif // if NN_PLATFORM_HAS_MMU