Skip to content

Commit 167ba58

Browse files
authored
add support for Dolphin debug messages (#164)
* add support for Dolphin debug messages * Adds SYS_Report to print directly to uart and SYS_STDIO_Report to redirect stderr/stdout
1 parent dab81d8 commit 167ba58

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ OGCOBJ := \
149149
console_font_8x16.o timesupp.o lock_supp.o usbgecko.o usbmouse.o \
150150
sbrk.o malloc_lock.o kprintf.o stm.o aes.o sha.o ios.o es.o isfs.o usb.o network_common.o \
151151
sdgecko_io.o sdgecko_buf.o gcsd.o argv.o network_wii.o wiisd.o conf.o usbstorage.o \
152-
texconv.o wiilaunch.o
152+
texconv.o wiilaunch.o sys_report.o
153153

154154
#---------------------------------------------------------------------------------
155155
MODOBJ := freqtab.o mixer.o modplay.o semitonetab.o gcmodplay.o

gc/ogc/system.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ s32 SYS_SetPeriodicAlarm(syswd_t thealarm,const struct timespec *tp_start,const
322322
*/
323323
s32 SYS_RemoveAlarm(syswd_t thealarm);
324324

325-
326325
/*! \fn s32 SYS_CancelAlarm(syswd_t thealarm)
327326
\brief Cancel the alarm, but do not remove from the list of contexts.
328327
\param[in] thealarm identifier to the alram context to be canceled
@@ -331,6 +330,22 @@ s32 SYS_RemoveAlarm(syswd_t thealarm);
331330
*/
332331
s32 SYS_CancelAlarm(syswd_t thealarm);
333332

333+
/* \fn void SYS_STDIO_Report(bool use_stdout)
334+
\brief redirect stderr to Dolphin OSReport uart
335+
\param[in] use_stdout also redirect stdout for use of printf
336+
337+
*/
338+
void SYS_STDIO_Report(bool use_stdout);
339+
340+
/*! \fn void SYS_Report (char const *const fmt_, ...)
341+
\brief write formatted string to Dolphin OSReport uart
342+
343+
*/
344+
345+
void SYS_Report (char const *const fmt_, ...);
346+
347+
348+
334349
u32 SYS_GetCounterBias(void);
335350
void SYS_SetCounterBias(u32 bias);
336351
s8 SYS_GetDisplayOffsetH(void);

libogc/sys_report.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*-------------------------------------------------------------
2+
3+
sys_report.c -- Support for printing to Dolphin debug UART
4+
5+
Copyright (C) 2023
6+
Dave Murphy (WinterMute) <[email protected]>
7+
8+
This software is provided 'as-is', without any express or implied
9+
warranty. In no event will the authors be held liable for any
10+
damages arising from the use of this software.
11+
12+
Permission is granted to anyone to use this software for any
13+
purpose, including commercial applications, and to alter it and
14+
redistribute it freely, subject to the following restrictions:
15+
16+
1. The origin of this software must not be misrepresented; you
17+
must not claim that you wrote the original software. If you use
18+
this software in a product, an acknowledgment in the product
19+
documentation would be appreciated but is not required.
20+
21+
2. Altered source versions must be plainly marked as such, and
22+
must not be misrepresented as being the original software.
23+
24+
3. This notice may not be removed or altered from any source
25+
distribution.
26+
27+
-------------------------------------------------------------*/
28+
29+
#include <sys/iosupport.h>
30+
#include <stdio.h>
31+
#include <stdarg.h>
32+
33+
#include "exi.h"
34+
35+
static ssize_t __uart_write(const char *buffer,size_t len)
36+
{
37+
u32 cmd,ret;
38+
39+
if(EXI_Lock(EXI_CHANNEL_0,EXI_DEVICE_1,NULL)==0) return 0;
40+
if(EXI_Select(EXI_CHANNEL_0,EXI_DEVICE_1,EXI_SPEED8MHZ)==0) {
41+
EXI_Unlock(EXI_CHANNEL_0);
42+
return len;
43+
}
44+
45+
ret = 0;
46+
cmd = 0xa0010000;
47+
if(EXI_Imm(EXI_CHANNEL_0,&cmd,4,EXI_WRITE,NULL)==0) ret |= 0x01;
48+
if(EXI_Sync(EXI_CHANNEL_0)==0) ret |= 0x02;
49+
if(EXI_ImmEx(EXI_CHANNEL_0,(void *)buffer,len,EXI_WRITE)==0) ret |= 0x04;
50+
if(EXI_Deselect(EXI_CHANNEL_0)==0) ret |= 0x08;
51+
if(EXI_Unlock(EXI_CHANNEL_0)==0) ret |= 0x10;
52+
53+
return len;
54+
}
55+
56+
static ssize_t __uart_stdio_write(struct _reent *r, void *fd, const char *ptr, size_t len)
57+
{
58+
__uart_write(ptr,len);
59+
return len;
60+
}
61+
static const devoptab_t dotab_uart = {
62+
.name = "uart",
63+
.write_r = __uart_stdio_write,
64+
};
65+
66+
void SYS_STDIO_Report(bool use_stdout)
67+
{
68+
fflush(stderr);
69+
devoptab_list[STD_ERR] = &dotab_uart;
70+
setvbuf(stderr, NULL, _IONBF, 0);
71+
if(use_stdout)
72+
{
73+
fflush(stdout);
74+
devoptab_list[STD_OUT] = &dotab_uart;
75+
setvbuf(stdout, NULL, _IONBF, 0);
76+
}
77+
}
78+
79+
static char __outstr[256];
80+
81+
void SYS_Report (char const *const fmt_, ...)
82+
{
83+
84+
int len;
85+
86+
va_list args;
87+
88+
va_start(args, fmt_);
89+
len=vsnprintf(__outstr,256,fmt_,args);
90+
va_end(args);
91+
92+
__uart_write(__outstr, len);
93+
94+
}
95+

0 commit comments

Comments
 (0)