Commit for backup/history purposes. Tried to make "Run ELF file" load the elf through pcsx2hostfs_ldr.elf so that elfs would have host: readily available, but it does not appear to work.

The code is disabled by default.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2595 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gigaherz 2010-02-15 17:18:13 +00:00
parent 9960c24af7
commit 82739f9b60
8 changed files with 719 additions and 24 deletions

View File

@ -24,6 +24,9 @@ extern void InitPatch(const wxString& crc);
u32 ElfCRC;
// uncomment this to enable pcsx2hostfs loading when using "load elf"
//#define USE_HOSTFS
#if 0
// fixme: ELF command line option system.
// It parses a command line and pastes it into PS2 memory, and then points the a0 register at it.
@ -438,11 +441,20 @@ void ElfObject::applyPatches()
//
// Throws exceptions on errors. Not called if not skipping the bios.
//
#ifdef USE_HOSTFS
void loadElfFile(const wxString& _filename)
#else
void loadElfFile(const wxString& filename)
#endif
{
ElfObject *elfptr;
bool iscdvd;
#ifdef USE_HOSTFS
wxString filename = _filename;
wxString parameters = _filename; //
#endif
if (filename.IsEmpty()) return;
Console.WriteLn( L"loadElfFile: " + filename );
@ -464,8 +476,15 @@ void loadElfFile(const wxString& filename)
else
{
// It's an elf file.
DevCon.WriteLn("Loading from a file (or non-cd image)");
DevCon.WriteLn("Loading from a file (or non-cd image).");
#ifdef USE_HOSTFS
parameters = filename;
filename = wxT("PCSX2HOSTFS_LDR.ELF");
#endif
elfptr = new ElfObject(filename, Path::GetFileSize(filename));
#ifdef USE_HOSTFS
filename = wxT("host:PCSX2HOSTFS_LDR.ELF");
#endif
}
if (!elfptr->hasProgramHeaders())
@ -487,6 +506,23 @@ void loadElfFile(const wxString& filename)
cpuRegs.GPR.n.sp.UL[0] = 0x81f00000;
cpuRegs.GPR.n.gp.UL[0] = 0x81f80000; // might not be 100% ok
//cpuRegs.GPR.n.a0.UL[0] = parseCommandLine( filename ); // see #ifdef'd out parseCommendLine for details.
#ifdef USE_HOSTFS
//HACK!!!!!!!!!!!!!
uptr params_addr = 0x1FFFC00; // elf loader will check this address for params
s8* params_ptr = (s8*)PSM(params_addr);
s8* params_magic = params_ptr + 0;
s8* params_argc = params_ptr + 4;
s8* params_argv = params_ptr + 8;
*(u32*)params_magic = 'PS2E';
*(u32*)params_argc = 2;
strcpy(params_argv,filename.ToAscii());
params_argv += strlen(params_argv)+1;
strcpy(params_argv,parameters.ToAscii());
params_argv += strlen(params_argv)+1;
strcpy(params_argv,"");
#endif
for( uint i = 0; i < 0x100000; i++ )
{

View File

@ -20,6 +20,9 @@
#ifndef __LINUX__
#include <io.h>
//#include "dirent.h"
#else
#include <dirent.h>
#endif
#pragma optimize("", off)
@ -56,19 +59,18 @@ u32 returnValue;
int pcsx2fio_open_file(char *path, int flags)
{
path++;
int mode = 0;
int mode = O_BINARY;
switch(flags&IOP_RDWR)
{
case IOP_RDONLY:
mode = O_RDONLY;
mode |= O_RDONLY;
break;
case IOP_WRONLY:
mode = O_WRONLY;
mode |= O_WRONLY;
break;
case IOP_RDWR:
mode = O_RDWR;
mode |= O_RDWR;
break;
}
if(flags&IOP_CREAT)

View File

@ -1,5 +1,5 @@
EE_BIN = pcsx2hostfs_ldr.elf
EE_OBJS = ps2link.o excepHandler.o exceptions.o
EE_OBJS = ps2link.o excepHandler.o exceptions.o cmdHandler.o
EE_INCS += -I../include
# This is for the sbv patch
@ -47,11 +47,6 @@ ifeq ($(DEBUG),1)
EE_CFLAGS += -DDEBUG -g
endif
# Enable screenshot functionality
ifeq ($(SCREENSHOTS),1)
EE_CFLAGS += -DSCREENSHOTS
endif
LDPARAMS := -Wl,--defsym -Wl,_stack_size=0x8000 -Wl,--defsym -Wl,_stack=$(STACKADDR)
EE_LDFLAGS += -Wl,-Ttext -Wl,$(LOADADDR) $(LDPARAMS)

435
pcsx2hostfs/ee/cmdHandler.c Normal file
View File

@ -0,0 +1,435 @@
/*********************************************************************
* Copyright (C) 2003 Tord Lindstrom (pukko@home.se)
* Copyright (C) 2004 adresd (adresd_ps2dev@yahoo.com)
* This file is subject to the terms and conditions of the PS2Link License.
* See the file LICENSE in the main directory of this distribution for more
* details.
*/
#include "stdio.h"
#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <iopcontrol.h>
#include <fileio.h>
#include <string.h>
#include "debug.h"
#include "excepHandler.h"
#include "byteorder.h"
#include "ps2regs.h"
#include "hostlink.h"
//#define scr_printf(args...) printf(args)
//#define init_scr() do { } while(0)
#ifdef DEBUG
#define dbgprintf(args...) printf(args)
#else
#define dbgprintf(args...) do { } while(0)
#endif
#if HOOK_THREADS
extern void KillActiveThreads(void);
#endif
////////////////////////////////////////////////////////////////////////
// Prototypes
static int cmdThread(void);
static int pkoStopVU(pko_pkt_stop_vu *);
static int pkoStartVU(pko_pkt_start_vu *);
static int pkoDumpMem(pko_pkt_mem_io *);
static int pkoDumpReg(pko_pkt_dump_regs *);
void pkoReset(void);
static int pkoLoadElf(char *path);
static int pkoGSExec(pko_pkt_gsexec_req *);
static int pkoWriteMem(pko_pkt_mem_io *);
// Flags for which type of boot (oh crap, make a header file dammit)
#define B_CD 1
#define B_MC 2
#define B_HOST 3
#define B_CC 4
#define B_UNKN 5
////////////////////////////////////////////////////////////////////////
// Globals
extern u32 _start;
extern int _gp;
extern int boot;
extern char elfName[];
int userThreadID = 0;
static int cmdThreadID = 0;
static char userThreadStack[16*1024] __attribute__((aligned(16)));
static char cmdThreadStack[16*1024] __attribute__((aligned(64)));
static char dataBuffer[16384] __attribute__((aligned(16)));
// The 'global' argv string area
static char argvStrings[PKO_MAX_PATH];
////////////////////////////////////////////////////////////////////////
// How about that header file again?
#define MAX_ARGS 16
#define MAX_ARGLEN 256
struct argData
{
int flag; // Contains thread id atm
int argc;
char *argv[MAX_ARGS];
} __attribute__((packed)) userArgs;
////////////////////////////////////////////////////////////////////////
int sifCmdSema;
int sif0HandlerId = 0;
// XXX: Hardcoded address atm.. Should be configurable!!
unsigned int *sifDmaDataPtr =(unsigned int*)(0x20100000-2048);
int excepscrdump = 1;
extern int pkoExecEE(pko_pkt_execee_req *cmd);
////////////////////////////////////////////////////////////////////////
// Create the argument struct to send to the user thread
int
makeArgs(int cmdargc, char *cmdargv, struct argData *arg_data)
{
int i;
int t;
int argc;
argc = 0;
if (cmdargc > MAX_ARGS)
cmdargc = MAX_ARGS;
cmdargv[PKO_MAX_PATH-1] = '\0';
memcpy(argvStrings, cmdargv, PKO_MAX_PATH);
dbgprintf("cmd->argc %d, argv[0]: %s\n", cmdargc, cmdargv);
i = 0;
t = 0;
do {
arg_data->argv[i] = &argvStrings[t];
dbgprintf("arg_data[%d]=%s\n", i, arg_data->argv[i]);
dbgprintf("argvStrings[%d]=%s\n", t, &argvStrings[t]);
t += strlen(&argvStrings[t]);
t++;
i++;
} while ((i < cmdargc) && (t < PKO_MAX_PATH));
arg_data->argc = i;
return 0;
}
////////////////////////////////////////////////////////////////////////
// Load the actual elf, and create a thread for it
// Return the thread id
static int
pkoLoadElf(char *path)
{
ee_thread_t th_attr;
t_ExecData elfdata;
int ret;
int pid;
ret = SifLoadElf(path, &elfdata);
FlushCache(0);
FlushCache(2);
dbgprintf("EE: LoadElf returned %d\n", ret);
dbgprintf("EE: Creating user thread (ent: %x, gp: %x, st: %x)\n",
elfdata.epc, elfdata.gp, elfdata.sp);
if (elfdata.epc == 0) {
dbgprintf("EE: Could not load file\n");
return -1;
}
th_attr.func = (void *)elfdata.epc;
th_attr.stack = userThreadStack;
th_attr.stack_size = sizeof(userThreadStack);
th_attr.gp_reg = (void *)elfdata.gp;
th_attr.initial_priority = 64;
pid = CreateThread(&th_attr);
if (pid < 0) {
printf("EE: Create user thread failed %d\n", pid);
return -1;
}
dbgprintf("EE: Created user thread: %d\n", pid);
return pid;
}
////////////////////////////////////////////////////////////////////////
// Load and start the requested elf
extern int pkoExecEE(pko_pkt_execee_req *cmd)
{
char path[PKO_MAX_PATH];
int ret;
int pid;
if (userThreadID) {
return -1;
}
dbgprintf("EE: Executing file %s...\n", cmd->argv);
memcpy(path, cmd->argv, PKO_MAX_PATH);
scr_printf("Executing file %s...\n", path);
pid = pkoLoadElf(path);
if (pid < 0) {
scr_printf("Could not execute file %s\n", path);
return -1;
}
FlushCache(0);
FlushCache(2);
userThreadID = pid;
makeArgs(ntohl(cmd->argc), path, &userArgs);
// Hack away..
userArgs.flag = (int)&userThreadID;
ret = StartThread(userThreadID, &userArgs);
if (ret < 0) {
printf("EE: Start user thread failed %d\n", ret);
cmdThreadID = 0;
DeleteThread(userThreadID);
return -1;
}
return ret;
}
////////////////////////////////////////////////////////////////////////
// takes cmd->data and sends it to GIF via path1
static int
pkoGSExec(pko_pkt_gsexec_req *cmd) {
int fd;
int len;
fd = fioOpen(cmd->file, O_RDONLY);
if ( fd < 0 ) {
return fd;
}
len = fioRead(fd, dataBuffer, 128);
fioClose(fd);
// stop/reset dma02
// dmasend via GIF channel
asm __volatile__(
"move $10, %0;"
"move $11, %1;"
"lui $8, 0x1001;"
"sw $11, -24544($8);"
"sw $10, -24560($8);"
"ori $9, $0, 0x101;"
"sw $9, -24576($8);"
:: "r" (dataBuffer), "r" ((ntohs(cmd->size))/16) );
// dmawait for GIF channel
asm __volatile__(
"lui $8, 0x1001;"
"dmawait:"
"lw $9, -24576($8);"
"nop;"
"andi $9, $9, 0x100;"
"nop;"
"bnez $9, dmawait;"
"nop;"
);
return 0;
}
////////////////////////////////////////////////////////////////////////
// command to dump cmd->size bytes of memory from cmd->offset
static int
pkoDumpMem(pko_pkt_mem_io *cmd) {
int fd;
int total, len;
unsigned int offset;
unsigned int size;
char path[PKO_MAX_PATH];
int ret = 0;
size = ntohl(cmd->size);
offset = ntohl(cmd->offset);
scr_printf("dump mem from 0x%x, size %d\n",
ntohl(cmd->offset), ntohl(cmd->size)
);
memcpy(path, cmd->argv, PKO_MAX_PATH);
fd = fioOpen(path, O_WRONLY|O_CREAT);
total = 0;
len = 16*1024;
if ( fd > 0 ) {
while(total < size) {
if ( size < len) {
len = size;
} else if ((size - total) < len) {
len = size - total;
}
memcpy(dataBuffer, (void *)offset, len);
if ((ret = fioWrite(fd, (void *)dataBuffer, len)) > 0) {
} else {
printf("EE: pkoDumpMem() fioWrite failed\n");
return fd;
}
offset = offset + len;
total += len;
}
}
fioClose(fd);
return ret;
}
static int
pkoWriteMem(pko_pkt_mem_io *cmd) {
int fd, len, total;
unsigned int offset;
unsigned int size;
char path[PKO_MAX_PATH];
int ret = 0;
size = ntohl(cmd->size);
offset = ntohl(cmd->offset);
scr_printf("write mem to 0x%x, size %d\n",
ntohl(cmd->offset), ntohl(cmd->size)
);
memcpy(path, cmd->argv, PKO_MAX_PATH);
fd = fioOpen(path, O_RDONLY);
total = 0;
len = 16*1024;
if( fd > 0) {
while(total < size) {
if ( size < len) {
len = size;
} else if ((size - total) < len) {
len = size - total;
}
if ((ret = fioRead(fd, (void *)dataBuffer, len)) > 0) {
} else {
printf("EE: pkoDumpMem() fioWrite failed\n");
return fd;
}
memcpy((void *)offset, dataBuffer, len);
offset = offset + len;
total += len;
}
}
fioClose(fd);
return ret;
}
////////////////////////////////////////////////////////////////////////
// command to stop VU0/1 and VIF0/1
static int
pkoStopVU(pko_pkt_stop_vu *cmd) {
if ( ntohs(cmd->vpu) == 0 ) {
asm(
"ori $25, $0, 0x1;"
"ctc2 $25, $28;"
"sync.p;"
"vnop;"
);
VIF0_FBRST = 0x2;
} else if ( ntohs(cmd->vpu) == 1 ) {
asm(
"ori $25, $0, 0x100;"
"ctc2 $25, $28;"
"sync.p;"
"vnop;"
);
VIF1_FBRST = 0x2;
}
return 0;
}
////////////////////////////////////////////////////////////////////////
// command to reset VU0/1 VIF0/1
static int
pkoStartVU(pko_pkt_start_vu *cmd) {
if ( ntohs(cmd->vpu) == 0 ) {
asm(
"ori $25, $0, 0x2;"
"ctc2 $25, $28;"
"sync.p;"
"vnop;"
);
VIF0_FBRST = 0x8;
} else if ( ntohs(cmd->vpu) == 1 ) {
asm(
"ori $25, $0, 0x200;"
"ctc2 $25, $28;"
"sync.p;"
"vnop;"
);
VIF1_FBRST = 0x8;
}
return 0;
}
////////////////////////////////////////////////////////////////////////
void
pkoReset(void)
{
char *argv[1];
// Check if user thread is running, if so kill it
#if 1
#if HOOK_THREADS
KillActiveThreads();
#else
if (userThreadID) {
TerminateThread(userThreadID);
DeleteThread(userThreadID);
}
#endif
#endif
userThreadID = 0;
RemoveDmacHandler(5, sif0HandlerId);
sif0HandlerId = 0;
SifInitRpc(0);
//cdvdInit(CDVD_INIT_NOWAIT);
//cdvdInit(CDVD_EXIT);
SifIopReset(NULL, 0);
SifExitRpc();
while(SifIopSync());
#if 1
SifInitRpc(0);
//cdvdExit();
SifExitRpc();
#endif
FlushCache(0);
#ifdef USE_CACHED_CFG
argv[0] = elfName;
SifLoadFileExit();
ExecPS2(&_start, 0, 1, argv);
return;
#endif
if ((boot == B_MC) || (boot == B_HOST) || (boot == B_UNKN) || (boot == B_CC)) {
argv[0] = elfName;
SifLoadFileExit();
ExecPS2(&_start, 0, 1, argv);
}
else {
LoadExecPS2(elfName, 0, NULL);
}
}

Binary file not shown.

View File

@ -16,7 +16,6 @@
#include <malloc.h>
#include <string.h>
#include "debug.h"
#include "cd.h"
#include "hostlink.h"
#include "excepHandler.h"
#include "stdio.h"
@ -75,6 +74,8 @@ static void loadModules(void);
static void pkoLoadModule(char *path, int argc, char *argv);
static void getIpConfig(void);
extern int pkoExecEE(pko_pkt_execee_req *cmd);
////////////////////////////////////////////////////////////////////////
#define IPCONF_MAX_LEN 1024
@ -788,20 +789,48 @@ main(int argc, char *argv[])
sio_printf("Ready\n");
nprintf("Ready\n");
char test[101];
int fd = open("host:/I:/test_atom.xml", O_RDONLY);
if(fd>=0)
const char elfFile[PS2E_FIO_MAX_PATH];
if(argc<2 || strlen(argv[1]) == 0)
{
int rd = read(fd,test,100);
close(fd);
nprintf("No elf specified. Trying PS2E Hack.\n");
if(rd>0)
test[rd]=0;
test[100]=0;
char* params_ptr = (char*)0x1FFFC00;
int* params_magic = params_ptr + 0;
int* params_argc = params_ptr + 4;
char* params_argv = params_ptr + 8;
nprintf("Reading returned %d: %s",rd,test);
nprintf("Magic = %c%c%c%c, argc=%d, argv[0]=%s\n", params_ptr[0], params_ptr[1], params_ptr[2], params_ptr[3], *params_argc, params_argv );
if(params_ptr[0] == 'E' && params_ptr[1] == '2' && params_ptr[2] == 'S' && params_ptr[3] == 'P')
{
int i;
argc = *params_argc;
for(i=0;i<=argc;i++)
{
argv[i] = params_argv;
params_argv += strlen(params_argv)+1;
}
}
else
{
nprintf("No elf to run. Looping infinitely.\n");
for(;;);
}
}
else printf("Test failed.");
strcpy(elfFile,"host0:");
strcat(elfFile,argv[1]);
nprintf("Loading elf '%s'...", elfFile);
pko_pkt_execee_req cmd;
cmd.argc = 1;
strcpy(cmd.argv, elfFile);
cmd.argv[strlen(cmd.argv)+1] = 0; // second null char to end argv
pkoExecEE(&cmd);
// SleepThread();
ExitDeleteThread();

View File

@ -16,7 +16,201 @@
#define PS2E_FIO_REMOVE_CMD 0xcc2e0109
#define PS2E_FIO_MKDIR_CMD 0xcc2e010a
#define PS2E_FIO_RMDIR_CMD 0xcc2e010b
#define PS2E_FIO_PRINTF_CMD 0xcc2e0201
#define PS2E_FIO_MAX_PATH 256
#define PKO_MAX_PATH 256
// old stuff
typedef struct
{
unsigned int cmd;
unsigned short len;
} __attribute__((packed)) pko_pkt_hdr;
typedef struct
{
unsigned int cmd;
unsigned short len;
unsigned int retval;
} __attribute__((packed)) pko_pkt_file_rly;
typedef struct
{
unsigned int cmd;
unsigned short len;
int flags;
char path[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_open_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int fd;
} __attribute__((packed)) pko_pkt_close_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int fd;
int nbytes;
} __attribute__((packed)) pko_pkt_read_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int retval;
int nbytes;
} __attribute__((packed)) pko_pkt_read_rly;
typedef struct
{
unsigned int cmd;
unsigned short len;
int fd;
int nbytes;
} __attribute__((packed)) pko_pkt_write_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int fd;
int offset;
int whence;
} __attribute__((packed)) pko_pkt_lseek_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
char name[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_remove_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int mode;
char name[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_mkdir_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
char name[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_rmdir_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int fd;
} __attribute__((packed)) pko_pkt_dread_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int retval;
/* from io_common.h (fio_dirent_t) in ps2lib */
unsigned int mode;
unsigned int attr;
unsigned int size;
unsigned char ctime[8];
unsigned char atime[8];
unsigned char mtime[8];
unsigned int hisize;
char name[256];
} __attribute__((packed)) pko_pkt_dread_rly;
////
typedef struct
{
unsigned int cmd;
unsigned short len;
} __attribute__((packed)) pko_pkt_reset_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int argc;
char argv[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_execee_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int argc;
char argv[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_execiop_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
unsigned short size;
unsigned char file[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_gsexec_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
} __attribute__((packed)) pko_pkt_poweroff_req;
typedef struct
{
unsigned int cmd;
unsigned short len;
int vpu;
} __attribute__((packed)) pko_pkt_start_vu;
typedef struct
{
unsigned int cmd;
unsigned short len;
int vpu;
} __attribute__((packed)) pko_pkt_stop_vu;
typedef struct
{
unsigned int cmd;
unsigned short len;
unsigned int offset;
unsigned int size;
char argv[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_mem_io;
typedef struct {
unsigned int cmd;
unsigned short len;
int regs;
char argv[PKO_MAX_PATH];
} __attribute__((packed)) pko_pkt_dump_regs;
typedef struct {
unsigned int cmd;
unsigned short len;
unsigned int regs[79];
} __attribute__((packed)) pko_pkt_send_regs;
typedef struct {
unsigned int cmd;
unsigned short len;
unsigned int base;
unsigned int width;
unsigned int height;
unsigned short psm;
} __attribute__((packed)) pko_pkt_screenshot;
#define PKO_MAX_WRITE_SEGMENT (1460 - sizeof(pko_pkt_write_req))
#define PKO_MAX_READ_SEGMENT (1460 - sizeof(pko_pkt_read_rly))

View File

@ -221,6 +221,10 @@
<Filter
Name="ee"
>
<File
RelativePath=".\ee\cmdHandler.c"
>
</File>
<File
RelativePath=".\ee\excepHandler.c"
>