1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_Memory.h
4 
5   Copyright (C)2009 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: 24156 $
14  *---------------------------------------------------------------------------*/
15 
16 /*! @file
17     @brief    OS からメモリを確保するための API の宣言
18 
19     :include nn/os.h
20 */
21 
22 #ifndef NN_OS_OS_MEMORY_H_
23 #define NN_OS_OS_MEMORY_H_
24 
25 #include <nn/types.h>
26 #include <nn/Handle.h>
27 #include <nn/svc.h>
28 #include <nn/os/CTR/os_MemoryConfig.h>
29 
30 #ifdef __cplusplus
31 
32 #include <nn/util/util_NonCopyable.h>
33 #include <nn/os/os_SvcTypes.autogen.h>
34 #include <nn/util/util_Result.h>
35 
36 #define NN_OS_DEVICE_MEMORY_SIZE (32 * 1024 * 1024) // 32MB
37 
38 namespace nn{ namespace os{
39 
40 /*!
41     @brief この定数は廃止されます。
42 
43            デバイスメモリサイズはプログラムで設定できるようになりました。
44            @ref SetDeviceMemorySize を参照してください
45            この定数は将来のリリースで削除される予定です。
46 */
47 const size_t DEVICE_MEMORY_SIZE NN_ATTRIBUTE_DEPRECATED = NN_OS_DEVICE_MEMORY_SIZE;
48 
49 /*!
50     @brief この関数は廃止されます。
51 
52            この関数は @ref SetDeviceMemorySize で置き換えられました。
53            この関数は将来のリリースで削除される予定です。
54 */
55 void InitializeDeviceMemory() NN_ATTRIBUTE_DEPRECATED;
56 
57 /*!--------------------------------------------------------------------------*
58   @brief        この関数は SDK 0.9 以前と同様のメモリ環境を
59                 エミュレーションするように OS を設定します。
60 
61                 この関数を呼び出すと以下のようにメモリ環境がセットアップされます。
62                 @li MemoryBlock クラスを使用できるようになります。
63                 @li プログラムで使用できる残りのメモリ全領域が
64                     ヒープに設定されます。
65                 @li ヒープから 8 MB の MemoryBlock が作成され C の malloc、
66                     C++ の new が、その MemoryBlock からメモリを
67                     確保するように初期化されます。
68 
69   @return       なし
70 
71  *---------------------------------------------------------------------------*/
72 void SetupHeapForMemoryBlock(size_t heapSize);
73 
74 
75 
76 
77 /*!--------------------------------------------------------------------------*
78   @brief        デバイスメモリの開始アドレスを取得します。
79 
80                 あらかじめ @ref SetDeviceMemorySize で
81                 0 より大きい値を指定しておく必要があります。
82 
83   @return       デバイスメモリの開始アドレスを返します。
84 
85  *---------------------------------------------------------------------------*/
86 uptr GetDeviceMemoryAddress();
87 
88 
89 
90 /*!--------------------------------------------------------------------------*
91   @brief        デバイスメモリのサイズを変更します。
92 
93   @param[in]    size    新しいデバイスメモリのサイズを指定します。
94                         size は 4096 の倍数でなければなりません。
95 
96   @return
97 
98  *---------------------------------------------------------------------------*/
99 Result SetDeviceMemorySize(size_t size);
100 
101 
102 
103 /*!--------------------------------------------------------------------------*
104   @brief        デバイスメモリのサイズを取得します。
105 
106   @return       現在のデバイスメモリのサイズを返します。
107 
108  *---------------------------------------------------------------------------*/
109 size_t GetDeviceMemorySize();
110 
111 
112 
113 /*!--------------------------------------------------------------------------*
114   @brief        ヒープの開始アドレスを取得します。
115 
116                 あらかじめ @ref SetHeapSize で
117                 0 より大きい値を指定しておく必要があります。
118 
119   @return       ヒープの開始アドレスを返します。
120 
121  *---------------------------------------------------------------------------*/
GetHeapAddress()122 inline uptr GetHeapAddress() { return NN_OS_ADDR_HEAP_BEGIN; }
123 
124 
125 
126 /*!--------------------------------------------------------------------------*
127   @brief        ヒープのサイズを変更します。
128 
129   @param[in]    size    新しいヒープのサイズを指定します。
130                         size は 4096 の倍数でなければなりません。
131 
132   @return
133 
134  *---------------------------------------------------------------------------*/
135 Result SetHeapSize(size_t size);
136 
137 
138 
139 /*!--------------------------------------------------------------------------*
140   @brief        ヒープのサイズを取得します。
141 
142   @return       現在のヒープのサイズを返します。
143 
144  *---------------------------------------------------------------------------*/
145 size_t GetHeapSize();
146 
147 
148 
149 }} // namespace nn::os
150 
151 #endif // __cplusplus
152 
153 // 以下、C 用宣言
154 
155 #include <nn/util/detail/util_CLibImpl.h>
156 
157 /*!
158   @addtogroup   nn_os                   os
159   @{
160 */
161 
162 /*!
163   @brief 対応する C++ 関数 @ref nn::os::InitializeDeviceMemory を参照してください。
164 */
165 NN_EXTERN_C void nnosInitializeDeviceMemory(void);
166 
167 /*!
168   @brief 対応する C++ 関数 @ref nn::os::GetDeviceMemoryAddress を参照してください。
169 */
170 NN_EXTERN_C uptr nnosGetDeviceMemoryAddress(void);
171 
172 /*!
173   @}
174 */
175 
176 /* NN_OS_MEMORY_H_ */
177 #endif /* NN_OS_OS_MEMORY_H_ */
178