Skip to content

Commit c4de45f

Browse files
authored
Merge pull request #26 from fjtrujy/master
Solve Warnings
2 parents 110e794 + caac984 commit c4de45f

7 files changed

Lines changed: 89 additions & 88 deletions

File tree

ee/cmdHandler.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ makeArgs(int cmdargc, char *cmdargv, struct argData *arg_data)
9797
{
9898
int i;
9999
int t;
100-
int argc;
101-
102-
argc = 0;
103100

104101
if (cmdargc > MAX_ARGS)
105102
cmdargc = MAX_ARGS;
@@ -138,6 +135,11 @@ pkoLoadElf(char *path)
138135

139136
ret = SifLoadElf(path, &elfdata);
140137

138+
if (ret < 0) {
139+
dbgprintf("EE: Could not load ELF file\n");
140+
return -1;
141+
}
142+
141143
FlushCache(0);
142144
FlushCache(2);
143145

@@ -219,12 +221,18 @@ static int
219221
pkoGSExec(pko_pkt_gsexec_req *cmd) {
220222
int fd;
221223
int len;
222-
fd = open(cmd->file, O_RDONLY);
224+
fd = open((const char *)cmd->file, O_RDONLY);
223225
if ( fd < 0 ) {
224226
return fd;
225227
}
226228
len = read(fd, dataBuffer, 128);
227229
close(fd);
230+
231+
if (len < 0 ) {
232+
printf("EE: pkoGSExec failed\n");
233+
return -1;
234+
}
235+
228236
// stop/reset dma02
229237

230238
// dmasend via GIF channel
@@ -856,7 +864,7 @@ cmdThread()
856864
}
857865

858866
ExitDeleteThread();
859-
return 0;
867+
return ret;
860868
}
861869

862870
////////////////////////////////////////////////////////////////////////

ee/excepHandler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ extern int userThreadID;
1717
extern int excepscrdump;
1818

1919
////////////////////////////////////////////////////////////////////////
20-
typedef union
20+
typedef union __attribute__((packed))
2121
{
2222
unsigned int uint128 __attribute__(( mode(TI) ));
2323
unsigned long uint64[2];
24-
} eeReg __attribute((packed));
24+
} eeReg;
2525

2626
////////////////////////////////////////////////////////////////////////
2727
// Prototypes

ee/ps2link.c

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ int irx_buffer_addr = 0;
4545
////////////////////////////////////////////////////////////////////////
4646
// Globals
4747
extern int userThreadID;
48+
extern void __start(void);
49+
extern int _end;
4850

4951
// Argv name+path & just path
5052
char elfName[256] __attribute__((aligned(16)));
51-
char elfPath[256];
53+
char elfPath[241]; // It isn't 256 because elfPath will add subpaths
5254

5355
#ifndef BUILTIN_IRXS
5456
char poweroff_path[PKO_MAX_PATH];
@@ -88,17 +90,20 @@ static void getIpConfig(void);
8890
////////////////////////////////////////////////////////////////////////
8991
#define IPCONF_MAX_LEN 1024
9092

93+
#define DEFAULT_IP "192.168.0.10"
94+
#define DEFAULT_NETMASK "255.255.255.0"
95+
#define DEFAULT_GW "192.168.0.1"
96+
#define SEPARATOR " "
97+
// DEFAULT_IP_CONFIG should be something as "192.168.0.10 255.0.0.0 192.168.0.1"
98+
#define DEFAULT_IP_CONFIG DEFAULT_IP SEPARATOR DEFAULT_NETMASK SEPARATOR DEFAULT_GW
99+
91100
// Make sure the "cached config" is in the data section
92101
// To prevent it from being "zeroed" on a restart of ps2link
93102
char if_conf[IPCONF_MAX_LEN] __attribute__ ((section (".data"))) = "";
94103
char fExtraConfig[256] __attribute__ ((section (".data")));
95104
int load_extra_conf __attribute__ ((section (".data"))) = 0;
96105
int if_conf_len __attribute__ ((section (".data"))) = 0;
97106

98-
char ip[16] __attribute__((aligned(16))) = "192.168.0.10";
99-
char netmask[16] __attribute__((aligned(16))) = "255.255.255.0";
100-
char gw[16] __attribute__((aligned(16))) = "192.168.0.1";
101-
102107
////////////////////////////////////////////////////////////////////////
103108
// Parse network configuration from IPCONFIG.DAT
104109
// Note: parsing really should be made more robust...
@@ -196,20 +201,11 @@ getIpConfig(void)
196201
if (fd < 0)
197202
{
198203
scr_printf("Could not find IPCONFIG.DAT, using defaults\n"
199-
"Net config: %s %s %s\n", ip, netmask, gw);
204+
"Net config: %s\n", DEFAULT_IP_CONFIG);
200205
// Set defaults
201206
memset(if_conf, 0x00, IPCONF_MAX_LEN);
202-
i = 0;
203-
strncpy(&if_conf[i], ip, 15);
204-
i += strlen(ip) + 1;
205-
206-
strncpy(&if_conf[i], netmask, 15);
207-
i += strlen(netmask) + 1;
208-
209-
strncpy(&if_conf[i], gw, 15);
210-
i += strlen(gw) + 1;
211-
212-
if_conf_len = i;
207+
strcpy(if_conf, DEFAULT_IP_CONFIG);
208+
i = strlen(DEFAULT_IP_CONFIG);
213209
dbgscr_printf("conf len %d\n", if_conf_len);
214210
return;
215211
}
@@ -279,6 +275,13 @@ getExtraConfig()
279275
lseek(fd, 0, SEEK_SET);
280276
buf = malloc(size + 1);
281277
ret = read(fd, buf, size);
278+
279+
if ( ret < 0 )
280+
{
281+
scr_printf("failed to read extra conf file\n");
282+
return;
283+
}
284+
282285
buf[size] = 0;
283286
close(fd);
284287
ptr = buf;
@@ -521,10 +524,8 @@ setPathInfo(char *path)
521524
{
522525
char *ptr;
523526

524-
strncpy(elfName, path, 255);
525-
strncpy(elfPath, path, 255);
526-
elfName[255] = '\0';
527-
elfPath[255] = '\0';
527+
strcpy(elfName, path);
528+
strcpy(elfPath, path);
528529

529530

530531
ptr = strrchr(elfPath, '/');
@@ -599,6 +600,13 @@ wipeUserMemLoadHigh(void)
599600
}
600601
}
601602

603+
void printWelcomeInfo()
604+
{
605+
scr_printf(WELCOME_STRING, APP_VERSION);
606+
scr_printf("ps2link loaded at 0x%08X-0x%08X\n", ((u32) __start) - 8, (u32) &_end);
607+
scr_printf("Initializing...\n");
608+
}
609+
602610

603611
void
604612
restartIOP()
@@ -615,7 +623,7 @@ restartIOP()
615623
dbgscr_printf("rpc init\n");
616624
SifInitRpc(0);
617625

618-
scr_printf("Initializing...\n");
626+
printWelcomeInfo();
619627
// sio_printf("Initializing...\n");
620628
sbv_patch_enable_lmb();
621629
sbv_patch_disable_prefix_check();
@@ -729,10 +737,11 @@ void ResetActiveThreads(void)
729737
}
730738
#endif
731739

732-
extern void __start(void);
733-
extern int _end;
734-
735740
////////////////////////////////////////////////////////////////////////
741+
742+
// We are not using time zone, so we can safe some KB
743+
void _ps2sdk_timezone_update() {}
744+
736745
int
737746
main(int argc, char *argv[])
738747
{
@@ -743,9 +752,7 @@ main(int argc, char *argv[])
743752
// fioInit();
744753

745754
init_scr();
746-
scr_printf(WELCOME_STRING, APP_VERSION);
747-
748-
scr_printf("ps2link loaded at 0x%08X-0x%08X\n", ((u32) __start) - 8, (u32) &_end);
755+
printWelcomeInfo();
749756

750757
installExceptionHandlers();
751758

iop/cmdHandler.c

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pkoExecIop(char *buf, int len)
7474
args = &cmd->argv[strlen(cmd->argv) + 1];
7575
argc = ntohl(cmd->argc);
7676

77+
printf("IOP binary path: %s\n", path);
78+
7779
arglen = 0;
7880
for (i = 0; i < (argc - 1); i++) {
7981
printf("arg %d: %s (%d)\n", i, &args[arglen], arglen);
@@ -84,31 +86,31 @@ pkoExecIop(char *buf, int len)
8486

8587
if (id < 0) {
8688
printf("Error loading module: ");
87-
switch (-id) {
88-
case E_IOP_INTR_CONTEXT:
89-
printf("IOP is in exception context.\n");
90-
break;
91-
case E_IOP_DEPENDANCY:
92-
printf("Inter IRX dependancy error.\n");
93-
break;
94-
case E_LF_NOT_IRX:
95-
printf("Invalid IRX module.\n");
96-
break;
97-
case E_LF_FILE_NOT_FOUND:
98-
printf("Unable to open executable file.\n");
99-
break;
100-
case E_LF_FILE_IO_ERROR:
101-
printf("Error while accessing file.\n");
102-
break;
103-
case E_IOP_NO_MEMORY:
104-
printf("IOP is out of memory.\n");
105-
break;
106-
default:
107-
printf("Unknow error code: %d\n", -retval);
108-
break;
109-
}
89+
switch (-id) {
90+
case E_IOP_INTR_CONTEXT:
91+
printf("IOP is in exception context.\n");
92+
break;
93+
case E_IOP_DEPENDANCY:
94+
printf("Inter IRX dependancy error.\n");
95+
break;
96+
case E_LF_NOT_IRX:
97+
printf("Invalid IRX module.\n");
98+
break;
99+
case E_LF_FILE_NOT_FOUND:
100+
printf("Unable to open executable file.\n");
101+
break;
102+
case E_LF_FILE_IO_ERROR:
103+
printf("Error while accessing file.\n");
104+
break;
105+
case E_IOP_NO_MEMORY:
106+
printf("IOP is out of memory.\n");
107+
break;
108+
default:
109+
printf("Unknow error code: %d\n", -retval);
110+
break;
111+
}
110112
} else {
111-
printf("loadmodule: id %d, ret %d\n", id, retval);
113+
printf("loadmodule: id %d, ret %d\n", id, retval);
112114
}
113115
}
114116

@@ -159,33 +161,25 @@ pkoSendSifCmd(unsigned int cmd, void *src, unsigned int len)
159161
static void
160162
pkoExecEE(char *buf, int len)
161163
{
162-
int ret;
163-
164-
ret = pkoSendSifCmd(PKO_RPC_EXECEE, buf, len);
164+
pkoSendSifCmd(PKO_RPC_EXECEE, buf, len);
165165
};
166166
//////////////////////////////////////////////////////////////////////////
167167
static void
168168
pkoGSExec(char *buf, int len)
169169
{
170-
int ret;
171-
172-
ret = pkoSendSifCmd(PKO_RPC_GSEXEC, buf, len);
170+
pkoSendSifCmd(PKO_RPC_GSEXEC, buf, len);
173171
};
174172
//////////////////////////////////////////////////////////////////////////
175173
static void
176174
pkoNetDump(char *buf, int len)
177175
{
178-
int ret;
179-
180-
ret = pkoSendSifCmd(PKO_RPC_NETDUMP, buf, len);
176+
pkoSendSifCmd(PKO_RPC_NETDUMP, buf, len);
181177
};
182178
//////////////////////////////////////////////////////////////////////////
183179
static void
184180
pkoScrDump(char *buf, int len)
185181
{
186-
int ret;
187-
188-
ret = pkoSendSifCmd(PKO_RPC_SCRDUMP, buf, len);
182+
pkoSendSifCmd(PKO_RPC_SCRDUMP, buf, len);
189183
};
190184

191185
//////////////////////////////////////////////////////////////////////////
@@ -199,8 +193,6 @@ pkoPowerOff()
199193
static void
200194
pkoReset(char *buf, int len)
201195
{
202-
int ret;
203-
204196
dbgprintf("IOP cmd: RESET\n");
205197

206198
if (len != sizeof(pko_pkt_reset_req)) {
@@ -213,38 +205,32 @@ pkoReset(char *buf, int len)
213205
printf("unmounted\n");
214206
DelDrv("tty");
215207

216-
ret = pkoSendSifCmd(PKO_RPC_RESET, buf, len);
208+
pkoSendSifCmd(PKO_RPC_RESET, buf, len);
217209
};
218210

219211
static void
220212
pkoStopVU(char *buf, int len) {
221-
int ret;
222-
223-
ret = pkoSendSifCmd(PKO_RPC_STOPVU, buf, len);
213+
pkoSendSifCmd(PKO_RPC_STOPVU, buf, len);
224214
};
225215

226216
static void
227217
pkoStartVU(char *buf, int len) {
228-
int ret;
229-
ret = pkoSendSifCmd(PKO_RPC_STARTVU, buf, len);
218+
pkoSendSifCmd(PKO_RPC_STARTVU, buf, len);
230219
};
231220

232221
static void
233222
pkoDumpMem(char *buf, int len) {
234-
int ret;
235-
ret = pkoSendSifCmd(PKO_RPC_DUMPMEM, buf, len);
223+
pkoSendSifCmd(PKO_RPC_DUMPMEM, buf, len);
236224
};
237225

238226
static void
239227
pkoDumpReg(char *buf, int len) {
240-
int ret;
241-
ret = pkoSendSifCmd(PKO_RPC_DUMPREG, buf, len);
228+
pkoSendSifCmd(PKO_RPC_DUMPREG, buf, len);
242229
};
243230

244231
static void
245232
pkoWriteMem(char *buf, int len) {
246-
int ret;
247-
ret = pkoSendSifCmd(PKO_RPC_WRITEMEM, buf, len);
233+
pkoSendSifCmd(PKO_RPC_WRITEMEM, buf, len);
248234
};
249235

250236
//////////////////////////////////////////////////////////////////////////

iop/excepHandler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ char* ExceptionGetModuleName(u32 epc, u32* r_epc)
6262
if(r_epc)
6363
*r_epc = epc - mod_info->text_start;
6464

65-
return mod_info->name;
65+
return (char *)mod_info->name;
6666
}
6767
}
6868

iop/net_fio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ int pko_close_dir(int fd)
650650

651651
//----------------------------------------------------------------------
652652
//
653-
int pko_get_stat(char *name, iox_stat_t *stat)
653+
int pko_get_stat(const char *name, iox_stat_t *stat)
654654
{
655655
pko_pkt_getstat_req *getstatreq;
656656
pko_pkt_getstat_rly *getstatrly;

iop/net_fio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int pko_rmdir(char *name);
2727
int pko_open_dir(char *path);
2828
int pko_read_dir(int fd, void *buf);
2929
int pko_close_dir(int fd);
30-
int pko_get_stat(char *name, iox_stat_t *stat);
30+
int pko_get_stat(const char *name, iox_stat_t *stat);
3131

3232
/*
3333
* Don't want printfs to broadcast in case more than 1 ps2 on the same network, so at

0 commit comments

Comments
 (0)