-
Notifications
You must be signed in to change notification settings - Fork 9
/
SYSMAN_rpc.c
151 lines (123 loc) · 5.27 KB
/
SYSMAN_rpc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <errno.h>
#include <iopheap.h>
#include <kernel.h>
#include <sifrpc.h>
#include <string.h>
#include "sysman/sysinfo.h"
#include "SYSMAN_rpc.h"
static SifRpcClientData_t SYSMAN_rpc_cd;
static unsigned char ReceiveBuffer[256] ALIGNED(64);
static unsigned char TransmitBuffer[64] ALIGNED(64);
void SysmanInit(void)
{
while (SifBindRpc(&SYSMAN_rpc_cd, SYSMAN_RPC_NUM, 0) < 0 || SYSMAN_rpc_cd.server == NULL)
nopdelay();
}
void SysmanDeinit(void)
{
memset(&SYSMAN_rpc_cd, 0, sizeof(SifRpcClientData_t));
}
/* Description: Reads data from the specified region of memory in IOP address space.
Arguments:
const void *MemoryStart -> The address of the region of memory to read from (Must be aligned!).
void *buffer -> A pointer to the buffer for storing the data read.
unsigned int NumBytes -> The number of bytes of data to read.
int mode -> Whether to not block (1 = asynchronous operation).
Returned values:
<0 -> An error code, multiplied by -1.
0 -> The operation completed successfully.
*/
int SysmanReadMemory(const void *MemoryStart, void *buffer, unsigned int NumBytes, int mode)
{
int RPC_res;
((struct MemoryAccessParameters *)TransmitBuffer)->StartAddress = (void *)MemoryStart;
((struct MemoryAccessParameters *)TransmitBuffer)->buffer = buffer;
((struct MemoryAccessParameters *)TransmitBuffer)->NumBytes = NumBytes;
if (mode)
if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_ReadMemory, SIF_RPC_M_NOWAIT, TransmitBuffer, sizeof(struct MemoryAccessParameters), ReceiveBuffer, sizeof(int), NULL, NULL)) >= 0)
RPC_res = 0;
else if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_ReadMemory, 0, TransmitBuffer, sizeof(struct MemoryAccessParameters), ReceiveBuffer, sizeof(int), NULL, NULL)) >= 0)
RPC_res = *(int *)ReceiveBuffer;
return RPC_res;
}
/* Description: Writes data to the specified region of memory in IOP address space.
Arguments:
void *MemoryStart -> The address of the region of memory write to.
const void *buffer -> A pointer to the buffer that contains the data to be written (Must be aligned and flushed!).
unsigned int NumBytes -> The number of bytes of data to write.
int mode -> Whether to not block (1 = asynchronous operation).
Returned values:
<0 -> An error code, multiplied by -1.
0 -> The operation completed successfully.
*/
int SysmanWriteMemory(void *MemoryStart, const void *buffer, unsigned int NumBytes, int mode)
{
int RPC_res;
((struct MemoryAccessParameters *)TransmitBuffer)->StartAddress = MemoryStart;
((struct MemoryAccessParameters *)TransmitBuffer)->buffer = (void *)buffer;
((struct MemoryAccessParameters *)TransmitBuffer)->NumBytes = NumBytes;
if (mode)
if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_WriteMemory, SIF_RPC_M_NOWAIT, TransmitBuffer, sizeof(struct MemoryAccessParameters), ReceiveBuffer, sizeof(int), NULL, NULL)) >= 0)
RPC_res = 0;
else if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_WriteMemory, 0, TransmitBuffer, sizeof(struct MemoryAccessParameters), ReceiveBuffer, sizeof(int), NULL, NULL)) >= 0)
RPC_res = *(int *)ReceiveBuffer;
return RPC_res;
}
int SysmanSync(int mode)
{
if (mode)
return SifCheckStatRpc(&SYSMAN_rpc_cd);
else
while (SifCheckStatRpc(&SYSMAN_rpc_cd) != 0) {};
return 0;
}
/* Description: Calculates the size of the IOPRP image at the specified address in IOP address space.
Arguments:
const void *ROMStart -> The address of the IOPRP image, in IOP address space.
Returned values:
<0 -> An error code, multiplied by -1.
0 -> The operation completed successfully.
*/
int SysmanCalcROMRegionSize(const void *ROMStart)
{
int RPC_res;
*(const void **)TransmitBuffer = ROMStart;
if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_CalcROMRegionSize, 0, TransmitBuffer, sizeof(void *), ReceiveBuffer, sizeof(int), NULL, NULL)) >= 0)
RPC_res = *(int *)ReceiveBuffer;
return RPC_res;
}
/* Description: Calculates the size of the ROM chip containing the specified image.
Arguments:
unsigned int RegionSize -> The size of the image in the ROM chip, to calculate its size of.
Returned values:
<0 -> An error code, multiplied by -1.
0 -> The operation completed successfully.
*/
int SysmanCalcROMChipSize(unsigned int RegionSize)
{
int RPC_res;
*(unsigned int *)TransmitBuffer = RegionSize;
if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_CalcROMChipSize, 0, TransmitBuffer, sizeof(void *), ReceiveBuffer, sizeof(int), NULL, NULL)) >= 0)
RPC_res = *(int *)ReceiveBuffer;
return RPC_res;
}
int SysmanGetHardwareInfo(t_SysmanHardwareInfo *hwinfo)
{
int RPC_res;
if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_GetHardwareInfo, 0, NULL, 0, ReceiveBuffer, sizeof(int) + sizeof(t_SysmanHardwareInfo), NULL, NULL)) >= 0)
{
RPC_res = *(int *)ReceiveBuffer;
memcpy(hwinfo, &ReceiveBuffer[4], sizeof(t_SysmanHardwareInfo));
}
return RPC_res;
}
int SysmanGetMACAddress(unsigned char *MAC_address)
{
int RPC_res;
if ((RPC_res = SifCallRpc(&SYSMAN_rpc_cd, SYSMAN_GetMACAddress, 0, NULL, 0, ReceiveBuffer, sizeof(int) + 6, NULL, NULL)) >= 0)
{
RPC_res = *(int *)ReceiveBuffer;
memcpy(MAC_address, &ReceiveBuffer[4], 6);
}
return RPC_res;
}