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-10-31#$
14   $Rev: 9171 $
15   $Author: yada $
16  *---------------------------------------------------------------------------*/
17 #ifndef NITRO_OS_COMMON_SYSTEMWORK_H_
18 #define NITRO_OS_COMMON_SYSTEMWORK_H_
19 
20 
21 /* If included from other 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 #include        <nitro/types.h>
28 
29 #ifdef SDK_NITRO
30 #include        <nitro/hw/common/mmap_shared.h>
31 #else //SDK_TWL
32 #include        <twl/hw/common/mmap_shared.h>
33 #endif
34 
35 #include        <nitro/os/common/thread.h>
36 #include        <nitro/os/common/spinLock.h>
37 #include        <nitro/os/common/arena.h>
38 
39 typedef union
40 {
41     u32     b32;
42     u16     b16;
43 }
44 OSDmaClearSrc;
45 typedef struct
46 {
47     u8      bootCheckInfo[0x20];       // 000-01f:   32-byte boot check info
48     u32     resetParameter;            // 020-023:    4-byte reset parameter
49 #ifdef SDK_TWL
50     u8      bootSync[0x8];             // 024-02c:    8-byte boot sync
51 #else
52     u8      padding5[0x8];             // 024-02c:   (8-byte)
53 #endif
54     u32     romBaseOffset;             // 02c-02f:    4-byte ROM offset of own program
55     u8      cartridgeModuleInfo[12];   // 030-03b:   12-byte cartridge module info
56     u32     vblankCount;               // 03c-03f:    4-byte V-Blank Count
57     u8      wmBootBuf[0x40];           // 040-07f:   64-byte WM multiboot buffer
58 #ifdef SDK_TWL
59     u8      nvramUserInfo[0xe8];       // 080-168: 232 bytes NVRAM user info
60 	u8		HW_secure_info[0x18];      // 18b-17f:  24 bytes NAND secure system information (flags, validLangBitmap, region, serialNo)
61 #else
62     u8      nvramUserInfo[0x100];      // 080-17f: 256 bytes NVRAM user info
63 #endif
64     u8      isd_reserved1[0x20];       // 180-19f:  32 bytes ISDebugger reservation
65     u8      arenaInfo[0x48];           // 1a0-1e7:  72 byte Arena information
66     u8      real_time_clock[8];        // 1e8-1ef:   8 bytes RTC
67     u8      sys_conf[6];               // 1f0-1f5:   6 bytes System config
68     u8      printWindowArm9;           // 1f6-1f6:    1 byte debug print window for ARM9
69     u8      printWindowArm7;           // 1f7-1f7:    1 byte debug print window for ARM7
70     u8      printWindowArm9Err;        // 1f8-1f8:    1 byte debug print window for ARM9 error
71     u8      printWindowArm7Err;        // 1f9-1f9:    1 byte debug print window for ARM7 error
72 #ifdef SDK_TWL
73     u8      nandFirmHotStartFlag;      // 1fa-1fa:    1 byte HotStartFlag from NAND firmware
74     u8      REDLauncherVersion;        // 1fb-1fb:    1 byte RED launcher version
75     u32     preloadParameterAddr;      // 1fc-1ff:   4 bytes preload Parameter Address
76 #else
77     u8      padding1[6];               // 1fa-1ff:   (6-byte)
78 #endif
79     u8      rom_header[0x160];         // 200-35f: 352 bytes ROM internal registration area info storage buffer
80     u8      isd_reserved2[32];         // 360-37f:  32 bytes ISDebugger reservation
81     u32     pxiSignalParam[2];         // 380-387:   8 bytes Param for PXI Signal
82     u32     pxiHandleChecker[2];       // 388-38f:   8 bytes Flag  for PXI Command Handler Installed
83     u32     mic_last_address;          // 390-393:   4 bytes MIC latest samppling result storage address
84     u16     mic_sampling_data;         // 394-395:   2 bytes MIC individual sampling result
85     u16     wm_callback_control;       // 396-397:   2 bytes Parameter for WM callback synchronization
86     u16     wm_rssi_pool;              // 398-399:   2 bytes Random number source depending on WM received signal intensity
87     u8      ctrdg_SetModuleInfoFlag;   // 39a-39a:   1 byte set ctrdg module info flag
88     u8      ctrdg_IsExisting;          // 39b-39b:   1 byte ctrdg exist flag
89     u32     component_param;           // 39c-39f:   4 bytes Parameter for Component synchronization
90     OSThreadInfo *threadinfo_mainp;    // 3a0-3a3:   4 bytes Pointer to ARM9 thread information; ensure its initial value is 0
91     OSThreadInfo *threadinfo_subp;     // 3a4-3a7:   4 bytes Pointer to ARM9 thread information; ensure its initial value is 0
92     u16     button_XY;                 // 3a8-3a9:   2 bytes XY button information storage location
93     u8      touch_panel[4];            // 3aa-3ad:   4 bytes Touch Screen information storage location
94     u16     autoloadSync;              // 3ae-3af:   2 bytes autoload sync between processors
95     u32     lockIDFlag_mainp[2];       // 3b0-3b7:   8 bytes lockID management flag (for ARM9)
96     u32     lockIDFlag_subp[2];        // 3b8-3bf:   8 bytes lockID management flag (for ARM7)
97     struct OSLockWord lock_VRAM_C;     // 3c0-3c7:   8 bytes           VRAM-C - lock buffer
98     struct OSLockWord lock_VRAM_D;     // 3c8-3cf:   8 bytes VRAM-D - lock buffer
99     struct OSLockWord lock_WRAM_BLOCK0; // 3d0-3d7:   8 bytes   Block0 - lock buffer
100     struct OSLockWord lock_WRAM_BLOCK1; // 3d8-3df:   8 bytes CPU internal work RAM - Block1 - lock buffer
101     struct OSLockWord lock_CARD;       // 3e0-3e7:   8 bytes Game Card - lock buffer
102     struct OSLockWord lock_CARTRIDGE;  // 3e8-3ef:   8 bytes Game Pak - lock buffer
103     struct OSLockWord lock_INIT;       // 3f0-3f7:   8 bytes Initialization lock buffer
104     u16     mmem_checker_mainp;        // 3f8-3f9:   2 bytes MainMemory Size Checker for Main processor
105     u16     mmem_checker_subp;         // 3fa-3fb:   2 bytes MainMemory Size Checker for Sub processor
106     u8      padding4[2];               // 3fc-3fd: (2 bytes)
107     u16     command_area;              // 3fe-3ff:   2 bytes Command Area
108 }
109 OSSystemWork;
110 
111 #define OS_GetSystemWork()      ((OSSystemWork *)HW_MAIN_MEM_SYSTEM)
112 
113 
114 #ifdef SDK_TWL
115 typedef struct
116 {
117     struct OSLockWord lock_WRAM_ex;   // 000-003:   4 bytes: Lock buffer for WRAM-A, B, and C
118     u32    reset_flag;                // 004-007:   4 bytes: Reset flags (hardware reset)
119     u8     padding[0x178];            // 008-17f:  (376 bytes)
120 }
121 OSSystemWork2;
122 
123 #define OS_GetSystemWork2()      ((OSSystemWork2 *)HW_PSEG1_RESERVED_0)
124 #endif // SDK_TWL
125 
126 #ifndef SDK_TWL
127 #define OS_IsCodecTwlMode()      (FALSE)
128 // (refer to include/twl/os/common/codecmode.h)
129 #endif
130 
131 /* Boot type */
132 typedef u16 OSBootType;
133 #define OS_BOOTTYPE_ILLEGAL      0        // Illegal status
134 #define OS_BOOTTYPE_ROM          1        // Boot from ROM
135 #define OS_BOOTTYPE_DOWNLOAD_MB  2        // Start a downloaded application
136 #define OS_BOOTTYPE_NAND         3        // Start an application in NAND memory
137 #define OS_BOOTTYPE_MEMORY       4        //
138 
139 /* Structure that combines other information, as well */
140 typedef struct OSBootInfo
141 {
142     OSBootType boot_type;              // 2
143 
144     // Information from WMBssDesc, without gameInfo
145     u16     length;                    // 4
146     u16     rssi;                      // 6
147     u16     bssid[3];                  // 12
148     u16     ssidLength;                // 14
149     u8      ssid[32];                  // 46
150     u16     capaInfo;                  // 48
151     struct
152     {
153         u16     basic;                 // 50
154         u16     support;               // 52
155     }
156     rateSet;
157     u16     beaconPeriod;              // 54
158     u16     dtimPeriod;                // 56
159     u16     channel;                   // 58
160     u16     cfpPeriod;                 // 60
161     u16     cfpMaxDuration;            // 62
162     u16     rsv1;                      // 64
163 }
164 OSBootInfo;
165 
166 
167 /*---------------------------------------------------------------------------*
168   Name:         OS_GetBootType
169 
170   Description:  Gets own boot type.
171 
172   Arguments:    None.
173 
174   Returns:      Returns an OSBootType value indicating own boot type.
175  *---------------------------------------------------------------------------*/
176 OSBootType OS_GetBootType(void);
177 
178 /*---------------------------------------------------------------------------*
179   Name:         OS_GetBootInfo
180 
181   Description:  Gets information related to own boot type.
182 
183   Arguments:    None.
184 
185   Returns:      Indicates information related to own boot type.
186  *---------------------------------------------------------------------------*/
187 const OSBootInfo *OS_GetBootInfo(void);
188 
189 #endif // SDK_ASM
190 
191 #endif // SDK_FROM_TOOL
192 
193 /* NITRO_OS_COMMON_SYSTEMWORK_H_ */
194 #endif
195