PS2SDK
PS2 Homebrew Libraries
iopcontrol.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # (C)2001, Gustavo Scotti (gustavo@scotti.com)
7 # (c) 2003 Marcus R. Brown (mrbrown@0xd6.org)
8 # Licenced under Academic Free License version 2.0
9 # Review ps2sdk README & LICENSE files for further details.
10 */
11 
17 #include <tamtypes.h>
18 #include <kernel.h>
19 #include <sifcmd.h>
20 #include <sifrpc.h>
21 #include <string.h>
22 #include <stdio.h>
23 
24 #include <iopcontrol.h>
25 
26 #ifdef F___iop_control_internals
27 int _iop_reboot_count = 0;
28 #endif
29 
30 extern int _iop_reboot_count;
31 
32 #ifdef F_SifIopReset
33 
34 int SifIopReset(const char *arg, int mode)
35 {
36  static SifCmdResetData_t reset_pkt __attribute__((aligned(64)));
37  struct t_SifDmaTransfer dmat;
38  int arglen;
39 
40  _iop_reboot_count++; // increment reboot counter to allow RPC clients to detect unbinding!
41 
42  sceSifStopDma(); // Stop DMA transfers across SIF0 (IOP -> EE).
43 
44  /* The original did not null-terminate, had no bounds-checking and counted the characters as it copied.
45  The IOP side will only copy up to arglen characters. */
46  if (arg != NULL) {
47  for (arglen = 0; arg[arglen] != '\0'; arglen++)
48  reset_pkt.arg[arglen] = arg[arglen];
49  } else { // While NULL was not officially supported, do this for backward-compatibility with old homebrew projects.
50  arglen = 0;
51  }
52 
53  reset_pkt.header.psize = sizeof reset_pkt; // dsize is not initialized (and not processed, even on the IOP).
54  reset_pkt.header.cid = SIF_CMD_RESET_CMD;
55  reset_pkt.arglen = arglen;
56  reset_pkt.mode = mode;
57 
58  dmat.src = &reset_pkt;
59  dmat.dest = (void *)sceSifGetReg(SIF_SYSREG_SUBADDR);
60  dmat.size = sizeof(reset_pkt);
61  dmat.attr = SIF_DMA_ERT | SIF_DMA_INT_O;
62  sceSifWriteBackDCache(&reset_pkt, sizeof(reset_pkt));
63 
64  sceSifSetReg(SIF_REG_SMFLAG, SIF_STAT_BOOTEND);
65 
66  if (!sceSifSetDma(&dmat, 1))
67  return 0;
68 
69  sceSifSetReg(SIF_REG_SMFLAG, SIF_STAT_SIFINIT);
70  sceSifSetReg(SIF_REG_SMFLAG, SIF_STAT_CMDINIT);
71  sceSifSetReg(SIF_SYSREG_RPCINIT, 0);
72  sceSifSetReg(SIF_SYSREG_SUBADDR, (int)NULL);
73 
74  return 1;
75 }
76 #endif
77 
78 #ifdef F_SifIopReboot
79 int SifIopReboot(const char *arg)
80 {
81  char param_str[RESET_ARG_MAX + 1];
82 
83  if (strlen(arg) + 11 > RESET_ARG_MAX) {
84  printf("too long parameter \'%s\'\n", arg);
85  return 0;
86  }
87 
88  sceSifInitRpc(0);
89  sceSifExitRpc();
90 
91  strcpy(param_str, "rom0:UDNL ");
92  strcat(param_str, arg);
93 
94  return SifIopReset(param_str, 0);
95 }
96 #endif
97 
98 #ifdef F_SifIopIsAlive
99 int SifIopIsAlive(void)
100 {
101  return ((sceSifGetReg(SIF_REG_SMFLAG) & SIF_STAT_SIFINIT) != 0);
102 }
103 #endif
104 
105 #ifdef F_SifIopSync
106 int SifIopSync()
107 {
108  return ((sceSifGetReg(SIF_REG_SMFLAG) & SIF_STAT_BOOTEND) != 0);
109 }
110 #endif
kernel.h
SIF_STAT_CMDINIT
#define SIF_STAT_CMDINIT
Definition: sifdma.h:48
SifIopSync
int SifIopSync(void)
SifIopReboot
int SifIopReboot(const char *arg)
iopcontrol.h
SIF_REG_SMFLAG
@ SIF_REG_SMFLAG
Definition: sifdma.h:36
RESET_ARG_MAX
#define RESET_ARG_MAX
Definition: sifcmd-common.h:80
__attribute__
typedef __attribute__
Definition: tlbfunc.c:60
_iop_reboot_count
int _iop_reboot_count
tamtypes.h
stdio.h
t_SifDmaTransfer
Definition: sifdma.h:52
SifIopReset
int SifIopReset(const char *arg, int mode)
SIF_STAT_BOOTEND
#define SIF_STAT_BOOTEND
Definition: sifdma.h:50
_iop_reset_pkt
Definition: sifcmd-common.h:82
SIF_STAT_SIFINIT
#define SIF_STAT_SIFINIT
Definition: sifdma.h:46
__attribute__
Definition: gif_registers.h:38
SifIopIsAlive
int SifIopIsAlive(void)