1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS - include
3   File:     printf.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 
18 #ifndef NITRO_OS_COMMON_PRINTF_H_
19 #define NITRO_OS_COMMON_PRINTF_H_
20 
21 #ifdef __MWEKS__
22 #pragma  warn_padding off
23 #endif
24 #include <stdio.h>                     // Stop the stdio.h PADDING warning
25 #ifdef __MWEKS__
26 #pragma  warn_padding reset
27 #endif
28 #include <stdarg.h>
29 #include <nitro/types.h>
30 
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif  // ifdef __cplusplus
35 
36 
37 //
38 //  Ensata controls
39 //
40 #define REG_EMU_CONSOLE_OUT      0x4fff000
41 #define reg_OS_EMU_CONSOLE_OUT   (*((REGType8v *)REG_EMU_CONSOLE_OUT))
42 
43 
44 // Output window on IS-TWL-DEBUGGER
45 //
46 typedef enum
47 {
48 	OS_PRINT_OUTPUT_PROC_ARM9     = 0,
49 	OS_PRINT_OUTPUT_PROC_ARM7     = 1,
50 	OS_PRINT_OUTPUT_PROC_ARM9ERR  = 2,
51 	OS_PRINT_OUTPUT_PROC_ARM7ERR  = 3
52 }
53 OSPrintOutputProc;
54 
55 #define OS_PRINT_OUTPUT_DEFAULT_ARM9     0
56 #define OS_PRINT_OUTPUT_DEFAULT_ARM7     3
57 #define OS_PRINT_OUTPUT_DEFAULT_ARM9ERR  0
58 #define OS_PRINT_OUTPUT_DEFAULT_ARM7ERR  3
59 #define OS_PRINT_OUTPUT_WINDOW_MAX       3
60 
61 #define OS_PRINT_OUTPUT_NONE             0xff
62 #define OS_PRINT_OUTPUT_CURRENT          0xfe
63 #define OS_PRINT_OUTPUT_ERROR            0xfd
64 
65 
66 #define OS_FPUTSTRING_DUMMY          0
67 #define OS_FPUTSTRING_ARIS           1
68 #define OS_FPUTSTRING_ISD            2
69 #define OS_FPUTSTRING_ISTD           3
70 typedef void (*OSFPutStringHookType)(int type, int console, const char *str);
71 
72 //
73 //  Prototypes
74 //
75 #ifndef SDK_FINALROM
76 extern void (*OS_PutString) (const char *str);
77 extern void (*OS_FPutString) (int console, const char *str);
78 #else   // ifndef SDK_FINALROM
79 #define OS_PutString(x)        ((void)0)
80 #define OS_FPutString(c, x)    ((void)0)
81 #endif  // ifndef SDK_FINALROM else
82 
83 int     OS_SPrintf(char *dst, const char *fmt, ...);
84 int     OS_VSPrintf(char *dst, const char *fmt, va_list vlist);
85 int     OS_SNPrintf(char *dst, size_t len, const char *fmt, ...);
86 int     OS_VSNPrintf(char *dst, size_t len, const char *fmt, va_list vlist);
87 int     OS_VSNPrintfEx(char *dst, size_t len, const char *fmt, va_list vlist);
88 
89 #ifndef SDK_FINALROM
90 void    OS_PutChar(char c);
91 void    OS_VPrintf(const char *fmt, va_list vlist);
92 void    OS_TVPrintf(const char *fmt, va_list vlist);
93 void    OS_TVPrintfEx(const char *fmt, va_list vlist);
94 void    OS_Printf(const char *fmt, ...);
95 void    OS_TPrintf(const char *fmt, ...);
96 void    OS_TPrintfEx(const char *fmt, ...);
97 
98 void    OS_FPutChar(int console, char c);
99 void    OS_VFPrintf(int console, const char *fmt, va_list vlist);
100 void    OS_TVFPrintf(int console, const char *fmt, va_list vlist);
101 void    OS_TVFPrintfEx(int console, const char *fmt, va_list vlist);
102 void    OS_FPrintf(int console, const char *fmt, ...);
103 void    OS_TFPrintf(int console, const char *fmt, ...);
104 void    OS_TFPrintfEx(int console, const char *fmt, ...);
105 #ifndef SDK_NO_MESSAGE
106 void    OSi_FWarning(int console, const char *file, int line, const char *fmt, ...);
107 void    OSi_TFWarning(int console, const char *file, int line, const char *fmt, ...);
108 void    OSi_FPanic(int console, const char *file, int line, const char *fmt, ...);
109 void    OSi_TFPanic(int console, const char *file, int line, const char *fmt, ...);
110 
111 void    OSi_Warning(const char *file, int line, const char *fmt, ...);
112 void    OSi_TWarning(const char *file, int line, const char *fmt, ...);
113 void    OSi_Panic(const char *file, int line, const char *fmt, ...);
114 void    OSi_TPanic(const char *file, int line, const char *fmt, ...);
115 #else   // ifndef SDK_NO_MESSAGE
116 void    OS_Terminate();
117 #define OSi_FWarning( console, file, line, ... )    ((void)0)
118 #define OSi_FPanic( console, file, line, ... )      OS_Terminate()
119 #define OSi_TFWarning( console, file, line, ... )   ((void)0)
120 #define OSi_TFPanic( console, file, line, ... )     OS_Terminate()
121 
122 #define OSi_Warning( file, line, ... )              ((void)0)
123 #define OSi_TWarning( file, line, ... )             ((void)0)
124 #define OSi_Panic( file, line, ... )                OS_Terminate()
125 #define OSi_TPanic( file, line, ... )               OS_Terminate()
126 #endif  // ifndef SDK_NO_MESSAGE else
127 
128 #define OS_Warning( ... )                           OSi_Warning( __FILE__, __LINE__, __VA_ARGS__ );
129 #define OS_Panic( ... )                             OSi_Panic( __FILE__, __LINE__, __VA_ARGS__ );
130 #define OS_TWarning( ... )                          OSi_TWarning( __FILE__, __LINE__, __VA_ARGS__ );
131 #define OS_TPanic( ... )                            OSi_TPanic( __FILE__, __LINE__, __VA_ARGS__ );
132 
133 #define OS_FWarning( console, ... )                 OSi_FWarning(  (console), __FILE__, __LINE__, __VA_ARGS__ );
134 #define OS_FPanic( console, ... )                   OSi_FPanic(    (console), __FILE__, __LINE__, __VA_ARGS__ );
135 #define OS_TFWarning( console, ... )                OSi_TFWarning( (console), __FILE__, __LINE__, __VA_ARGS__ );
136 #define OS_TFPanic( console, ... )                  OSi_TFPanic(   (console), __FILE__, __LINE__, __VA_ARGS__ );
137 
138 #else   // ifndef SDK_FINALROM
139 //---- Invalidate debug functions when FINALROM
140 #define OS_PutChar( ... )                           ((void)0)
141 #define OS_VPrintf( fmt, ... )                      ((void)0)
142 #define OS_TVPrintf( fmt, ... )                     ((void)0)
143 #define OS_TVPrintfEx( fmt, ... )                   ((void)0)
144 #define OS_Printf( ... )                            ((void)0)
145 #define OS_TPrintf( ... )                           ((void)0)
146 #define OS_TPrintfEx( ... )                         ((void)0)
147 
148 #define OS_FPutChar( console, ... )                 ((void)0)
149 #define OS_VFPrintf( console, fmt, ... )            ((void)0)
150 #define OS_TVFPrintf( console, fmt, ... )           ((void)0)
151 #define OS_TVFPrintfEx( console, fmt, ... )         ((void)0)
152 #define OS_FPrintf( console,  ... )                 ((void)0)
153 #define OS_TFPrintf( console,  ... )                ((void)0)
154 #define OS_TFPrintfEx( console, ... )               ((void)0)
155 
156 void    OS_Terminate();
157 #define OSi_FWarning( console, file, line, ... )    ((void)0)
158 #define OSi_FPanic( console, file, line, ... )      OS_Terminate()
159 #define OSi_TFWarning( console, file, line, ... )   ((void)0)
160 #define OSi_TFPanic( console, file, line, ... )     OS_Terminate()
161 
162 #define OSi_Warning( file, line, ... )              ((void)0)
163 #define OSi_Panic( file, line, ... )                OS_Terminate()
164 #define OSi_TWarning( file, line, ... )             ((void)0)
165 #define OSi_TPanic( file, line, ... )               OS_Terminate()
166 
167 #define OS_Warning( ... )                           ((void)0)
168 #define OS_Panic( ... )                             OS_Terminate()
169 #define OS_TWarning( ... )                          ((void)0)
170 #define OS_TPanic( ... )                            OS_Terminate()
171 
172 #define OS_FWarning( console, ... )                 ((void)0)
173 #define OS_FPanic( console, ... )                   OS_Terminate()
174 #define OS_TFWarning( console, ... )                ((void)0)
175 #define OS_TFPanic( console, ... )                  OS_Terminate()
176 
177 #endif  // ifndef SDK_FINALROM else
178 
179 /*---------------------------------------------------------------------------*
180   Name:         OS_SetPrintOutput
181 
182   Description:  Specifies the output window that OS_Printf uses.
183                 This is only for IS-TWL-DEBUGGER.
184 
185   Arguments:    proc: processor
186                          OS_PRINT_OUTPUT_PROC_ARM9: ARM9
187                          OS_PRINT_OUTPUT_PROC_ARM7: ARM7
188                          OS_PRINT_OUTPUT_PROC_ARM9ERR: ARM9 for error
189                          OS_PRINT_OUTPUT_PROC_ARM7ERR: ARM7 for error
190                 num: output window number (0-3)
191 
192   Returns:      None.
193  *---------------------------------------------------------------------------*/
194 void OS_SetPrintOutput( OSPrintOutputProc proc, int num );
195 #define OS_SetPrintOutput_Arm9( num )     OS_SetPrintOutput( OS_PRINT_OUTPUT_PROC_ARM9, (num) )
196 #define OS_SetPrintOutput_Arm7( num )     OS_SetPrintOutput( OS_PRINT_OUTPUT_PROC_ARM7, (num) )
197 #define OS_SetPrintOutput_Arm9Err( num )  OS_SetPrintOutput( OS_PRINT_OUTPUT_PROC_ARM9ERR, (num) )
198 #define OS_SetPrintOutput_Arm7Err( num )  OS_SetPrintOutput( OS_PRINT_OUTPUT_PROC_ARM7ERR, (num) )
199 
200 /*---------------------------------------------------------------------------*
201   Name:         OS_SetFPutStringHook
202 
203   Description:  Sets a hook function in FPutString.
204 
205   Arguments:    func: hook function
206 
207   Returns:      None.
208  *---------------------------------------------------------------------------*/
209 #ifndef SDK_FINALROM
210 void OS_SetFPutStringHook( OSFPutStringHookType func );
211 #else
212 #define OS_SetFPutStringHook( func )         ((void)0)
213 #endif
214 
215 /*---------------------------------------------------------------------------*
216   Name:         OS_GetFPutStringHook
217 
218   Description:  Gets the hook function in FPutString.
219 
220   Arguments:    None.
221 
222   Returns:      Hook function
223  *---------------------------------------------------------------------------*/
224 #ifndef SDK_FINALROM
225 OSFPutStringHookType OS_GetFPutStringHook(void);
226 #else
227 #define OS_GetFPutStringHook()               ((void)0)
228 #endif
229 
230 //================================================================================
231 //  PrintServer
232 //================================================================================
233 typedef union
234 {
235     u16     s;
236     char    c[2];
237 }
238 OSPrintWChar;
239 
240 #define OS_PRINTSRV_BUFFERSIZE  1024
241 #define OS_PRINTSRV_WCHARSIZE   (OS_PRINTSRV_BUFFERSIZE/sizeof(OSPrintWChar))
242 
243 typedef volatile struct
244 {
245     u32     in;
246     u32     out;
247     OSPrintWChar buffer[OS_PRINTSRV_WCHARSIZE];
248 
249 }
250 OSPrintServerBuffer;
251 
252 #ifdef  SDK_ARM9
253 #ifndef SDK_FINALROM
254 void    OS_InitPrintServer(void);
255 void    OS_PrintServer(void);
256 #else   // ifndef SDK_FINALROM
257 #define OS_InitPrintServer()                    ((void)0)
258 #define OS_PrintServer()                        ((void)0)
259 #endif  // ifndef SDK_FINALROM else
260 #endif  // ifdef SDK_ARM9
261 
262 #ifdef __cplusplus
263 } /* extern "C" */
264 #endif  // ifdef __cplusplus
265 
266 /* NITRO_OS_COMMON_PRINTF_H_ */
267 #endif
268