1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     init_Default.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: 48011 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/config.h>
17 #include <nn/init.h>
18 #include <nn/os.h>
19 #include <nn/dbg/dbg_Default.h>
20 #include <nn/srv.h>
21 
22 namespace
23 {
24     class ExitHandler : public nn::srv::NotificationHandler
25     {
26     public:
HandleNotification(bit32 message)27         virtual void HandleNotification(bit32 message)
28         {
29             NN_UNUSED_VAR(message);
30 
31             nn::svc::ExitProcess();
32         }
33     };
34 
35 
36 
37 #if NN_PLATFORM_HAS_MMU
38     bool        s_UsingStartUpDefault = false;
39 #endif  // if NN_PLATFORM_HAS_MMU
40     ExitHandler s_ExitHandler;
41 }
42 
nninitStartUpDefault(void)43 extern "C" void nninitStartUpDefault(void)
44 {
45 #if NN_PLATFORM_HAS_MMU
46     const size_t assingment   = nn::os::GetAppMemorySize();
47     const size_t currentUsing = nn::os::GetUsingMemorySize();
48 
49     const size_t DEVICE_MEMORY_SIZE = 32 * 1024 * 1024;
50     const size_t available = assingment - currentUsing;
51     const size_t heapSize  = available - DEVICE_MEMORY_SIZE;
52 
53     nn::os::SetupHeapForMemoryBlock(heapSize);
54     NN_UTIL_PANIC_IF_FAILED( nn::os::SetDeviceMemorySize( DEVICE_MEMORY_SIZE ) );
55 
56     nn::init::InitializeAllocator( 8 * 1024 * 1024 );
57 
58     s_UsingStartUpDefault = true;
59 
60     nn::os::ManagedThread::InitializeEnvironment();
61     nn::dbg::SetDefaultExceptionHandler();
62     nn::dbg::SetDefaultBreakHandler();
63 #endif  // if NN_PLATFORM_HAS_MMU
64 }
65 
nninitIsStartUpDefaultUsing()66 extern "C" bool nninitIsStartUpDefaultUsing()
67 {
68     bool ret = false;
69 #if NN_PLATFORM_HAS_MMU
70     ret = s_UsingStartUpDefault;
71 #endif  // if NN_PLATFORM_HAS_MMU
72     return ret;
73 }
74 
nninitSetupDefault(void)75 extern "C" void nninitSetupDefault(void)
76 {
77 #if NN_PLATFORM_HAS_MMU
78     nn::srv::Initialize();
79     nn::srv::StartNotification();
80 #endif  // if NN_PLATFORM_HAS_MMU
81 }
82 
nninitSetupDefaultWithSettingExitHandler(void)83 extern "C" void nninitSetupDefaultWithSettingExitHandler(void)
84 {
85 #if NN_PLATFORM_HAS_MMU
86     nn::srv::Initialize();
87     nn::srv::StartNotification();
88 
89     nn::srv::RegisterNotificationHandler(&s_ExitHandler, nn::srv::NOTIFICATION_EXIT);
90 #endif  // if NN_PLATFORM_HAS_MMU
91 }
92 
93