sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
main.c
1
#include <
kernel.h
>
2
#include <
stdio.h
>
3
#include <
string.h
>
4
5
#include <sifrpc.h>
6
#include <
loadfile.h
>
7
#include <
sbv_patches.h
>
8
9
#define NEWLIB_PORT_AWARE
10
#include <
fileXio_rpc.h
>
11
#include <
fileXio.h
>
12
#include <
io_common.h
>
13
14
#include "iomanx_irx.h"
15
#include "filexio_irx.h"
16
#include "rtty_irx.h"
17
#include "rtty.h"
18
19
extern
int
kputs(
char
*s);
20
21
/* fileXioIoctl always copies IOCTL_BUF_SIZE bytes from its argument, so it cannot be NULL. */
22
static
char
ioctl_arg[IOCTL_BUF_SIZE];
23
static
int
failures;
24
25
static
void
expect(
const
char
*name,
int
ok)
26
{
27
printf(
"driver-tty: [%s] %s\n"
, ok ?
"PASS"
:
"FAIL"
, name);
28
if
(!ok)
29
failures++;
30
}
31
32
static
int
load(
const
char
*name,
void
*buf,
unsigned
int
size)
33
{
34
int
ret = -1;
35
int
id
=
SifExecModuleBuffer
(buf, size, 0, NULL, &ret);
36
37
printf(
"driver-tty: %s id=%d ret=%d\n"
, name,
id
, ret);
38
return
id
> 0 && ret != 1;
39
}
40
41
static
int
drain(
int
fd,
char
*buf,
int
size)
42
{
43
int
total = 0, n;
44
45
while
(total < size - 1 && (n = fileXioRead(fd, buf + total, size - 1 - total)) > 0)
46
total += n;
47
buf[total] =
'\0'
;
48
return
total;
49
}
50
51
int
main(
void
)
52
{
53
static
const
char
ping[] =
"ping from the EE\n"
;
54
static
char
buf[2048];
55
int
fd, n;
56
57
SifInitRpc(0);
58
sbv_patch_enable_lmb
();
59
sbv_patch_disable_prefix_check
();
60
load(
"iomanx"
, iomanx_irx, size_iomanx_irx);
61
load(
"filexio"
, filexio_irx, size_filexio_irx);
62
fileXioInit();
63
expect(
"rtty loads and stays resident"
, load(
"rtty"
, rtty_irx, size_rtty_irx));
64
65
fd = fileXioOpen(
"rtty:"
, FIO_O_RDWR);
66
expect(
"rtty: opens"
, fd >= 0);
67
if
(fd < 0)
68
goto
done;
69
70
expect(
"read on an empty buffer returns 0"
, fileXioRead(fd, buf,
sizeof
(buf)) == 0);
71
72
n = fileXioWrite(fd, (
void
*)ping, strlen(ping));
73
expect(
"write accepts every byte"
, n == (
int
)strlen(ping));
74
n = drain(fd, buf,
sizeof
(buf));
75
expect(
"read returns what was written"
, n == (
int
)strlen(ping) && strcmp(buf, ping) == 0);
76
77
fileXioWrite(fd, (
void
*)ping, strlen(ping));
78
expect(
"ioctl clear succeeds"
, fileXioIoctl(fd, RTTY_IOCTL_CLEAR, ioctl_arg) == 0);
79
expect(
"nothing left after clear"
, fileXioRead(fd, buf,
sizeof
(buf)) == 0);
80
expect(
"unknown ioctl is rejected"
, fileXioIoctl(fd, 0x1234, ioctl_arg) < 0);
81
expect(
"a unit name after the colon is rejected"
, fileXioOpen(
"rtty:other"
, FIO_O_RDONLY) < 0);
82
83
/* Last: once rtty: is the console it also captures this program's own printf output. */
84
expect(
"IOP stdout reopened on rtty: as fd 1"
, fileXioIoctl(fd, RTTY_IOCTL_ATTACH_CONSOLE, ioctl_arg) == 1);
85
n = drain(fd, buf,
sizeof
(buf));
86
printf(
"driver-tty: captured %d bytes of console output\n"
, n);
87
if
(strstr(buf,
"rtty: console attached"
) != NULL)
88
expect(
"IOP printf went to rtty:"
, 1);
89
else
90
printf(
"driver-tty: [SKIP] IOP printf went to rtty: (PCSX2 logs IOP stdout writes itself)\n"
);
91
fileXioClose(fd);
92
93
done:
94
kputs(failures ?
"driver-tty: FAIL\n"
:
"driver-tty: PASS\n"
);
95
printf(
"[ps2rig] exit=%d\n"
, failures ? 1 : 0);
96
SleepThread();
97
return
0;
98
}
fileXio.h
fileXio_rpc.h
SifExecModuleBuffer
int SifExecModuleBuffer(void *ptr, u32 size, u32 arg_len, const char *args, int *mod_res)
Definition
loadfile.c:314
io_common.h
kernel.h
loadfile.h
sbv_patches.h
sbv_patch_disable_prefix_check
int sbv_patch_disable_prefix_check(void)
Definition
patch_disable_prefix_check.c:29
sbv_patch_enable_lmb
int sbv_patch_enable_lmb(void)
Definition
patch_enable_lmb.c:68
stdio.h
string.h
tests
driver-tty
src
ee
main.c
Generated by
1.18.0