PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
reboot.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2009, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "irx_imports.h"
12
13#ifdef _IOP
14IRX_ID("RebootByEE", 1, 1);
15#endif
16// Mostly based on the module from SCE SDK 1.3.4
17
18extern void reboot_handler_thread(void *userdata);
19
20int _start(int argc, char *argv[])
21{
22 int *BootMode;
23 int v3;
24 iop_thread_t v4;
25
26 FlushDcache();
27 BootMode = QueryBootMode(3);
28 if (BootMode) {
29 int v1;
30
31 v1 = BootMode[1];
32 if ((v1 & 1) != 0) {
33 printf(" No SIF service(reboot)\n");
34 return 1;
35 }
36 if ((v1 & 2) != 0) {
37 printf(" No Reboot by EE service\n");
38 return 1;
39 }
40 }
42 v4.attr = 0x2000000;
43 v4.thread = reboot_handler_thread;
44 v4.priority = 10;
45 v4.stacksize = 2048;
46 v4.option = 0;
47 v3 = CreateThread(&v4);
48 if (v3 <= 0) {
49 return 1;
50 }
51 StartThread(v3, 0);
52 return 0;
53}
54
55typedef struct reboot_variables_
56{
57 int system_status_flag;
58 int mode;
59 char arg[80];
61
62reboot_variables_t reboot_variables;
63
64typedef struct iop_reset_pkt_
65{
66 char not_used[16]; // SifCmdHeader_t contents would go here
67 int arglen;
68 int mode;
69 char arg[80];
71
72void reboot_sif_handler(iop_reset_pkt_t *data, reboot_variables_t *harg)
73{
74 int i;
75
76 for (i = 0; i < data->arglen; i += 1) {
77 harg->arg[i] = data->arg[i];
78 }
79 harg->mode = data->mode;
80 iSetEventFlag(harg->system_status_flag, 0x400u);
81}
82
83void reboot_handler_thread(void *userdata)
84{
85 (void)userdata;
86
87 if (!sceSifCheckInit()) {
88 sceSifInit();
89 }
90 printf("Reboot service module.(99/11/10)\n");
91 reboot_variables.system_status_flag = GetSystemStatusFlag();
92 sceSifInitCmd();
93 sceSifAddCmdHandler(0x80000003, (SifCmdHandler_t)reboot_sif_handler, &reboot_variables);
94 WaitEventFlag(reboot_variables.system_status_flag, 0x400u, 0, 0);
95 printf("Get Reboot Request From EE\n");
96 sceSifSetMSFlag(0x20000u);
97 *((vu32 *)0xBF801538) = 0;
98 ReBootStart(reboot_variables.arg, reboot_variables.mode);
99}
int CpuEnableIntr()
Definition intrman.c:250