1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS - include
3   File:     systemWork.h
4 
5   Copyright 2003-2008 Nintendo. 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   $Date:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #ifndef TWL_OS_COMMON_SYSTEMWORK_H_
18 #define TWL_OS_COMMON_SYSTEMWORK_H_
19 
20 
21 /* If included from another environment (for example, VC or BCB), */
22 /* please define SDK_FROM_TOOL                               */
23 #if !(defined(SDK_WIN32) || defined(SDK_FROM_TOOL))
24 //
25 //--------------------------------------------------------------------
26 #ifndef SDK_ASM
27 
28 #include        <twl/types.h>
29 #include        <twl/hw/common/mmap_shared.h>
30 #ifdef SDK_TWL
31 #ifdef SDK_ARM9
32 #include        <twl/hw/ARM9/mmap_global.h>
33 #else //SDK_ARM7
34 #include        <twl/hw/ARM7/mmap_global.h>
35 #endif
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #ifdef SDK_TWL
43 
44 // Mount devices
45 typedef enum OSMountDevice {
46     OS_MOUNT_DEVICE_SD   = 0,
47     OS_MOUNT_DEVICE_NAND = 1,
48     OS_MOUNT_DEVICE_MAX  = 2
49 }OSMountDevice;
50 
51 
52 // Mount targets
53 typedef enum OSMountTarget {
54     OS_MOUNT_TGT_ROOT = 0,
55     OS_MOUNT_TGT_FILE = 1,
56     OS_MOUNT_TGT_DIR  = 2,
57     OS_MOUNT_TGT_MAX  = 3
58 }OSMountTarget;
59 
60 
61 // Permissions
62 typedef enum OSMountPermission {
63     OS_MOUNT_USR_X = 0x01,
64     OS_MOUNT_USR_W = 0x02,
65     OS_MOUNT_USR_R = 0x04
66 }OSMountPermission;
67 
68 
69 // Resource placement
70 typedef enum OSMountResource {
71     OS_MOUNT_RSC_MMEM = 0,
72     OS_MOUNT_RSC_WRAM = 1
73 }OSMountResource;
74 
75 
76 #define OS_MOUNT_PARTITION_MAX_NUM      3           // The maximum number of mountable partitions
77 #define OS_MOUNT_DRIVE_START            'A'         // The first drive name (you can only specify uppercase letters from 'A' to 'Z')
78 #define OS_MOUNT_DRIVE_END              'Z'         // The last drive name
79 #define OS_MOUNT_ARCHIVE_NAME_LEN       16          // The maximum length of an archive name
80 #define OS_MOUNT_PATH_LEN               64          // The maximum length of a path
81 #define OS_MOUNT_INFO_MAX               (size_t)((HW_TWL_FS_BOOT_SRL_PATH_BUF - HW_TWL_FS_MOUNT_INFO_BUF) / sizeof(OSMountInfo))
82 
83 #define OS_TITLEIDLIST_MAX              118         // The maximum number of items retained by the title ID list
84 
85 
86 // Structure with mount information for archives
87 typedef struct OSMountInfo {
88     u8      drive[ 1 ];
89     u8      device : 3;
90     u8      target : 2;
91     u8      partitionIndex : 2;
92     u8      resource : 1;
93     u8      userPermission : 3;                         // Specifies whether this is readable and writable by the user
94     u8      rsv_A : 5;
95     u8      rsv_B;
96     char    archiveName[ OS_MOUNT_ARCHIVE_NAME_LEN ];   // Size with a terminating '\0'
97     char    path[ OS_MOUNT_PATH_LEN ];                  // Size with a terminating '\0'
98 }OSMountInfo;   // 84 bytes
99 
100 
101 // Title ID list structure
102 typedef struct OSTitleIDList {
103 	u8		num;
104 	u8		rsv[ 15 ];
105 	u8		publicFlag [ 16 ];	// Flag indicating whether there is public save data
106 	u8		privateFlag[ 16 ];	// Flag indicating whether there is private save data
107 	u8		appJumpFlag[ 16 ];	// Flag indicating whether an application jump can be performed
108 	u8		sameMakerFlag[ 16 ];	// Flag indicating whether the manufacturer is the same
109 	u64		TitleID[ OS_TITLEIDLIST_MAX ];
110 }OSTitleIDList; // 1024 bytes
111 
112 typedef struct OSHotBootStatus {
113 	u8		isDisable :1;
114 	u8		rsv :7;
115 }OSHotBootStatus;
116 
117 /*---------------------------------------------------------------------------*
118   Name:         OS_GetMountInfo
119 
120   Description:  Gets mount information.
121 
122   Arguments:    None.
123 
124   Returns:      Returns a pointer to the start of the mount information list.
125  *---------------------------------------------------------------------------*/
OS_GetMountInfo(void)126 static inline const OSMountInfo *OS_GetMountInfo( void )
127 {
128     return (const OSMountInfo *)HW_TWL_FS_MOUNT_INFO_BUF;
129 }
130 
131 /*---------------------------------------------------------------------------*
132   Name:         OS_GetBootSRLPath
133 
134   Description:  Gets the SRL path information to this program.
135 
136   Arguments:    None.
137 
138   Returns:      Returns a pointer to the SRL path to this program.
139  *---------------------------------------------------------------------------*/
OS_GetBootSRLPath(void)140 static inline const char *OS_GetBootSRLPath( void )
141 {
142     return (const char *)HW_TWL_FS_BOOT_SRL_PATH_BUF;
143 }
144 
145 /*---------------------------------------------------------------------------*
146   Name:         OS_GetTitleId
147 
148   Description:  Gets the application's title ID.
149 
150   Arguments:    None.
151 
152   Returns:      The title ID as a u64 value.
153  *---------------------------------------------------------------------------*/
OS_GetTitleId(void)154 static inline u64 OS_GetTitleId( void )
155 {
156     return *(u64 *)(HW_TWL_ROM_HEADER_BUF + 0x230);
157 }
158 
159 /*---------------------------------------------------------------------------*
160   Name:         OS_GetMakerCode
161 
162   Description:  Gets the application's manufacturer code.
163 
164   Arguments:    None.
165 
166   Returns:      The manufacturer code as a u16 value.
167  *---------------------------------------------------------------------------*/
OS_GetMakerCode(void)168 static inline u16 OS_GetMakerCode( void )
169 {
170     return *(u16 *)(HW_TWL_ROM_HEADER_BUF + 0x10);
171 }
172 
173 /*---------------------------------------------------------------------------*
174   Name:         OSi_GetSystemMenuVersionInfoContentID
175 
176   Description:  Gets the contentID information for the System Menu version.
177 
178   Arguments:    None.
179 
180   Returns:      Returns a pointer to the start of the contentID. (this includes a null terminator)
181  *---------------------------------------------------------------------------*/
OSi_GetSystemMenuVersionInfoContentID(void)182 static inline const u8 *OSi_GetSystemMenuVersionInfoContentID( void )
183 {
184     return (const u8 *)HW_SYSM_VER_INFO_CONTENT_ID;
185 }
186 
187 /*---------------------------------------------------------------------------*
188   Name:         OSi_GetSystemMenuVersionLastGameCode
189 
190   Description:  Gets the last byte of the System Menu version's game code.
191 
192   Arguments:    None.
193 
194   Returns:      Returns a pointer to the start of the contentID. (this includes a null terminator)
195  *---------------------------------------------------------------------------*/
OSi_GetSystemMenuVersionInfoLastGameCode(void)196 static inline u8 OSi_GetSystemMenuVersionInfoLastGameCode( void )
197 {
198     return *(u8 *)HW_SYSM_VER_INFO_CONTENT_LAST_INITIAL_CODE;
199 }
200 
201 /*---------------------------------------------------------------------------*
202   Name:         OSi_IsEnableHotBoot
203 
204   Description:  Can the HotBoot flag be set?
205 
206   Arguments:    None.
207 
208   Returns:      TRUE: HotBoot cannot be set, FALSE: HotBoot can be set
209  *---------------------------------------------------------------------------*/
OSi_IsEnableHotBoot(void)210 static inline BOOL OSi_IsEnableHotBoot( void )
211 {
212 	return ( (OSHotBootStatus *)HW_SYSM_DISABLE_SET_HOTBOOT )->isDisable ? 0 : 1;
213 }
214 
215 /*---------------------------------------------------------------------------*
216   Name:         OSi_SetEnableHotBoot
217 
218   Description:  Controls whether the HotBoot flag can be set.
219 
220   Arguments:    isEnable -> TRUE: HotBoot can be set, FALSE: HotBoot cannot be set
221 
222   Returns:      None.
223  *---------------------------------------------------------------------------*/
OSi_SetEnableHotBoot(BOOL isEnable)224 static inline void OSi_SetEnableHotBoot( BOOL isEnable )
225 {
226 	( (OSHotBootStatus *)HW_SYSM_DISABLE_SET_HOTBOOT )->isDisable = isEnable ? 0 : 1;
227 }
228 
229 
230 #endif // SDK_TWL
231 
232 #ifdef __cplusplus
233 } /* extern "C" */
234 #endif
235 
236 
237 #endif // SDK_ASM
238 
239 #endif // SDK_FROM_TOOL
240 
241 /* TWL_OS_COMMON_SYSTEMWORK_H_ */
242 #endif
243