coff binary support (experimental).

git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@57729 e17a0e51-4ae3-4d35-97c3-1a29b211df97
This commit is contained in:
SND\weimingzhi_cp 2010-09-26 01:39:01 +00:00
parent 60cf0fcf61
commit 2ac114fd69
2 changed files with 89 additions and 37 deletions

View File

@ -1,38 +1,69 @@
/***************************************************************************
* Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
***************************************************************************/
/*
* Copyright (c) 1995
* Ted Lemon (hereinafter referred to as the author)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __COFF_H__
#define __COFF_H__
#ifndef __ECOFF_H__
#define __ECOFF_H__
/********************** FILE HEADER **********************/
/*
* Some ECOFF definitions.
*/
typedef struct filehdr {
u16 f_magic; /* magic number */
u16 f_nscns; /* number of sections */
u32 f_timdat; /* time & date stamp */
u32 f_symptr; /* file pointer to symbolic header */
u32 f_nsyms; /* sizeof(symbolic hdr) */
u16 f_opthdr; /* sizeof(optional hdr) */
u16 f_flags; /* flags */
} FILHDR;
struct external_filehdr {
unsigned short f_magic; /* magic number */
unsigned short f_nscns; /* number of sections */
unsigned long f_timdat; /* time & date stamp */
unsigned long f_symptr; /* file pointer to symtab */
unsigned long f_nsyms; /* number of symtab entries */
unsigned short f_opthdr; /* sizeof(optional hdr) */
unsigned short f_flags; /* flags */
};
typedef struct scnhdr {
char s_name[8]; /* section name */
u32 s_paddr; /* physical address, aliased s_nlib */
u32 s_vaddr; /* virtual address */
u32 s_size; /* section size */
u32 s_scnptr; /* file ptr to raw data for section */
u32 s_relptr; /* file ptr to relocation */
u32 s_lnnoptr; /* file ptr to gp histogram */
u16 s_nreloc; /* number of relocation entries */
u16 s_nlnno; /* number of gp histogram entries */
u32 s_flags; /* flags */
} SCNHDR;
#define FILHDR struct external_filehdr
#define FILHSZ sizeof(FILHDR)
typedef struct aouthdr {
u16 magic; /* magic */
u16 vstamp; /* version stamp */
u32 tsize; /* text size in bytes, padded to DW bdry */
u32 dsize; /* initialized data */
u32 bsize; /* uninitialized data */
u32 entry; /* entry pt. */
u32 text_start; /* base of text used for this file */
u32 data_start; /* base of data used for this file */
} AOUTHDR;
#endif

View File

@ -390,7 +390,10 @@ static void LoadLibPS() {
int Load(const char *ExePath) {
FILE *tmpFile;
EXE_HEADER tmpHead;
int type;
FILHDR coffHead;
AOUTHDR optHead;
SCNHDR section;
int type, i;
int retval = 0;
u8 opcode;
u32 section_address, section_size;
@ -408,9 +411,9 @@ int Load(const char *ExePath) {
type = PSXGetFileType(tmpFile);
switch (type) {
case PSX_EXE:
fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile);
fread(&tmpHead, sizeof(EXE_HEADER), 1, tmpFile);
fseek(tmpFile, 0x800, SEEK_SET);
fread((void *)PSXM(SWAP32(tmpHead.t_addr)), SWAP32(tmpHead.t_size),1,tmpFile);
fread(PSXM(SWAP32(tmpHead.t_addr)), SWAP32(tmpHead.t_size), 1, tmpFile);
fclose(tmpFile);
psxRegs.pc = SWAP32(tmpHead.pc0);
psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0);
@ -419,6 +422,7 @@ int Load(const char *ExePath) {
psxRegs.GPR.n.sp = 0x801fff00;
retval = 0;
break;
case CPE_EXE:
fseek(tmpFile, 6, SEEK_SET); /* Something tells me we should go to 4 and read the "08 00" here... */
do {
@ -448,10 +452,27 @@ int Load(const char *ExePath) {
}
} while (opcode != 0 && retval == 0);
break;
case COFF_EXE:
SysPrintf(_("COFF files not supported.\n"));
retval = -1;
fread(&coffHead, sizeof(coffHead), 1, tmpFile);
fread(&optHead, sizeof(optHead), 1, tmpFile);
psxRegs.pc = SWAP32(optHead.entry);
psxRegs.GPR.n.sp = 0x801fff00;
for (i = 0; i < SWAP16(coffHead.f_nscns); i++) {
fseek(tmpFile, sizeof(FILHDR) + SWAP16(coffHead.f_opthdr) + sizeof(section) * i, SEEK_SET);
fread(&section, sizeof(section), 1, tmpFile);
if (section.s_scnptr != 0) {
fseek(tmpFile, SWAP32(section.s_scnptr), SEEK_SET);
fread(PSXM(SWAP32(section.s_paddr)), SWAP32(section.s_size), 1, tmpFile);
} else {
memset(PSXM(SWAP32(section.s_paddr)), 0, SWAP32(section.s_size));
}
}
break;
case INVALID_EXE:
SysPrintf(_("This file does not appear to be a valid PSX file.\n"));
retval = -1;