1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     fnd_FrameHeap.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: 46347 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/fnd/fnd_FrameHeap.h>
17 
18 namespace nn { namespace fnd {
19 
20 /*
21 FrameHeapBase* FrameHeapBase::Create(HeapBase* parent, void* addr, size_t size, bit32 option)
22 {
23     if ( parent->FindHeap(addr) != parent ) return 0;
24     FrameHeap* frameheap = new (addr) FrameHeap(reinterpret_cast<uptr>(addr)+sizeof(FrameHeap), static_cast<size_t>(size - sizeof(FrameHeap)), option);
25     frameheap->SetParent(parent);
26     return frameheap;
27 }
28 */
29 
Initialize(uptr addr,size_t size,bit32 option)30 void FrameHeapBase::Initialize(uptr addr, size_t size, bit32 option)
31 {
32     NN_TASSERT_(size >= 0);
33     HeapBase::Initialize(option);
34     this->m_Addr = this->m_CurrentHead = addr;
35     this->m_Size = size;
36     this->m_CurrentTail = this->m_Addr + this->m_Size;
37 
38     DebugFillMemory(addr, size, HEAP_FILL_TYPE_NOUSE);
39 }
40 
Dump() const41 void FrameHeapBase::Dump() const
42 {
43 #if ! defined(NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK)
44 
45     NN_TLOG_("     attr  address(from - to):     size\n");   // wb_[s
46 
47     // ---------------- UsedBlock ?_v ----------------
48     NN_TLOG_("    (Used Blocks)\n" );
49     if(this->m_Addr == this->m_CurrentHead)
50     {
51         NN_TLOG_("    front NONE\n");
52     }
53     else
54     {
55         NN_TLOG_("    front %08x - %08x: %8d\n",
56             this->m_Addr, this->m_CurrentHead, this->m_CurrentHead - this->m_Addr);
57     }
58 
59     if(this->m_Addr + this->m_Size == this->m_CurrentTail)
60     {
61         NN_TLOG_("     rear NONE\n");
62     }
63     else
64     {
65         NN_TLOG_("     rear %08x - %08x: %8d\n",
66             this->m_CurrentTail, this->m_Addr + this->m_Size, this->m_Addr + this->m_Size - this->m_CurrentTail);
67     }
68 
69     // ---------------- FreeBlock ?_v ----------------
70     NN_TLOG_("    (Free Blocks)\n" );
71     if(this->m_CurrentHead == this->m_CurrentTail)
72     {
73         NN_TLOG_("     free NONE\n");
74     }
75     else
76     {
77         NN_TLOG_("     free %08x - %08x: %8d\n",
78             this->m_CurrentHead, this->m_CurrentTail, this->m_CurrentTail - this->m_CurrentHead);
79     }
80 
81     u32 usedSize = this->m_Size - (this->m_CurrentTail - this->m_CurrentHead);
82     NN_TLOG_("\n");
83     NN_TLOG_("    %d / %d bytes (%d%%) used\n",
84         usedSize, this->m_Size, 100 * usedSize / this->m_Size);
85     NN_TLOG_("\n");
86 
87 #endif
88 }
89 
90 }}
91