mirror of https://github.com/PCSX2/pcsx2.git
clang-format: pcsx2/IopBios.h and pcsx2/IopBios.cpp
This commit is contained in:
parent
4bf3819778
commit
4402bbda55
|
@ -1,5 +1,5 @@
|
||||||
/* PCSX2 - PS2 Emulator for PCs
|
/* PCSX2 - PS2 Emulator for PCs
|
||||||
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
* Copyright (C) 2002-2021 PCSX2 Dev Team
|
||||||
*
|
*
|
||||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||||
|
@ -26,7 +26,8 @@
|
||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
unsigned int mode;
|
unsigned int mode;
|
||||||
unsigned int attr;
|
unsigned int attr;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
|
@ -36,7 +37,8 @@ typedef struct {
|
||||||
unsigned int hisize;
|
unsigned int hisize;
|
||||||
} fio_stat_t;
|
} fio_stat_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
fio_stat_t stat;
|
fio_stat_t stat;
|
||||||
char name[256];
|
char name[256];
|
||||||
unsigned int unknown;
|
unsigned int unknown;
|
||||||
|
@ -61,7 +63,8 @@ void Hle_SetElfPath(const char* elfFileName)
|
||||||
// use %CD%/host/
|
// use %CD%/host/
|
||||||
char* cwd = getcwd(HostRoot, 1000); // save the other 23 chars to append /host/ :P
|
char* cwd = getcwd(HostRoot, 1000); // save the other 23 chars to append /host/ :P
|
||||||
HostRoot[1000] = 0; // Be Safe.
|
HostRoot[1000] = 0; // Be Safe.
|
||||||
if (cwd == nullptr) {
|
if (cwd == nullptr)
|
||||||
|
{
|
||||||
Console.Error("Hle_SetElfPath: getcwd: buffer is too small");
|
Console.Error("Hle_SetElfPath: getcwd: buffer is too small");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +86,8 @@ void Hle_SetElfPath(const char* elfFileName)
|
||||||
Console.WriteLn("HLE Host: Set 'host:' root path to: %s\n", HostRoot);
|
Console.WriteLn("HLE Host: Set 'host:' root path to: %s\n", HostRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace R3000A {
|
namespace R3000A
|
||||||
|
{
|
||||||
|
|
||||||
#define v0 (psxRegs.GPR.n.v0)
|
#define v0 (psxRegs.GPR.n.v0)
|
||||||
#define a0 (psxRegs.GPR.n.a0)
|
#define a0 (psxRegs.GPR.n.a0)
|
||||||
|
@ -130,10 +134,19 @@ static int host_stat(const std::string path, fio_stat_t *host_stats)
|
||||||
// Convert the mode.
|
// Convert the mode.
|
||||||
host_stats->mode = (file_stats.st_mode & (FIO_SO_IROTH | FIO_SO_IWOTH | FIO_SO_IXOTH));
|
host_stats->mode = (file_stats.st_mode & (FIO_SO_IROTH | FIO_SO_IWOTH | FIO_SO_IXOTH));
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (S_ISLNK(file_stats.st_mode)) { host_stats->mode |= FIO_SO_IFLNK; }
|
if (S_ISLNK(file_stats.st_mode))
|
||||||
|
{
|
||||||
|
host_stats->mode |= FIO_SO_IFLNK;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (S_ISREG(file_stats.st_mode)) { host_stats->mode |= FIO_SO_IFREG; }
|
if (S_ISREG(file_stats.st_mode))
|
||||||
if (S_ISDIR(file_stats.st_mode)) { host_stats->mode |= FIO_SO_IFDIR; }
|
{
|
||||||
|
host_stats->mode |= FIO_SO_IFREG;
|
||||||
|
}
|
||||||
|
if (S_ISDIR(file_stats.st_mode))
|
||||||
|
{
|
||||||
|
host_stats->mode |= FIO_SO_IFDIR;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the creation time.
|
// Convert the creation time.
|
||||||
struct tm* loctime;
|
struct tm* loctime;
|
||||||
|
@ -206,14 +219,23 @@ public:
|
||||||
|
|
||||||
switch (flags & IOP_O_RDWR)
|
switch (flags & IOP_O_RDWR)
|
||||||
{
|
{
|
||||||
case IOP_O_RDONLY: native_flags |= O_RDONLY; break;
|
case IOP_O_RDONLY:
|
||||||
case IOP_O_WRONLY: native_flags |= O_WRONLY; break;
|
native_flags |= O_RDONLY;
|
||||||
case IOP_O_RDWR: native_flags |= O_RDWR; break;
|
break;
|
||||||
|
case IOP_O_WRONLY:
|
||||||
|
native_flags |= O_WRONLY;
|
||||||
|
break;
|
||||||
|
case IOP_O_RDWR:
|
||||||
|
native_flags |= O_RDWR;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flags&IOP_O_APPEND) native_flags |= O_APPEND;
|
if (flags & IOP_O_APPEND)
|
||||||
if(flags&IOP_O_CREAT) native_flags |= O_CREAT;
|
native_flags |= O_APPEND;
|
||||||
if(flags&IOP_O_TRUNC) native_flags |= O_TRUNC;
|
if (flags & IOP_O_CREAT)
|
||||||
|
native_flags |= O_CREAT;
|
||||||
|
if (flags & IOP_O_TRUNC)
|
||||||
|
native_flags |= O_TRUNC;
|
||||||
|
|
||||||
int hostfd = ::open(host_path(path).data(), native_flags, native_mode);
|
int hostfd = ::open(host_path(path).data(), native_flags, native_mode);
|
||||||
if (hostfd < 0)
|
if (hostfd < 0)
|
||||||
|
@ -314,10 +336,10 @@ public:
|
||||||
::closedir(dir);
|
::closedir(dir);
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ioman {
|
namespace ioman
|
||||||
|
{
|
||||||
const int firstfd = 0x100;
|
const int firstfd = 0x100;
|
||||||
const int maxfds = 0x100;
|
const int maxfds = 0x100;
|
||||||
int openfds = 0;
|
int openfds = 0;
|
||||||
|
@ -329,22 +351,38 @@ namespace ioman {
|
||||||
|
|
||||||
struct filedesc
|
struct filedesc
|
||||||
{
|
{
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
FILE_FREE,
|
FILE_FREE,
|
||||||
FILE_FILE,
|
FILE_FILE,
|
||||||
FILE_DIR,
|
FILE_DIR,
|
||||||
} type;
|
} type;
|
||||||
union {
|
union
|
||||||
|
{
|
||||||
IOManFile* file;
|
IOManFile* file;
|
||||||
IOManDir* dir;
|
IOManDir* dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr filedesc(): type(FILE_FREE), file(nullptr) {}
|
constexpr filedesc()
|
||||||
|
: type(FILE_FREE)
|
||||||
|
, file(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
operator bool() const { return type != FILE_FREE; }
|
operator bool() const { return type != FILE_FREE; }
|
||||||
operator IOManFile*() const { return type == FILE_FILE ? file : NULL; }
|
operator IOManFile*() const { return type == FILE_FILE ? file : NULL; }
|
||||||
operator IOManDir*() const { return type == FILE_DIR ? dir : NULL; }
|
operator IOManDir*() const { return type == FILE_DIR ? dir : NULL; }
|
||||||
void operator=(IOManFile *f) { type = FILE_FILE; file = f; openfds++; }
|
void operator=(IOManFile* f)
|
||||||
void operator=(IOManDir *d) { type = FILE_DIR; dir = d; openfds++; }
|
{
|
||||||
|
type = FILE_FILE;
|
||||||
|
file = f;
|
||||||
|
openfds++;
|
||||||
|
}
|
||||||
|
void operator=(IOManDir* d)
|
||||||
|
{
|
||||||
|
type = FILE_DIR;
|
||||||
|
dir = d;
|
||||||
|
openfds++;
|
||||||
|
}
|
||||||
|
|
||||||
void close()
|
void close()
|
||||||
{
|
{
|
||||||
|
@ -606,7 +644,8 @@ namespace ioman {
|
||||||
|
|
||||||
if (IOManFile* file = getfd<IOManFile>(fd))
|
if (IOManFile* file = getfd<IOManFile>(fd))
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
std::unique_ptr<char[]> buf(new char[count]);
|
std::unique_ptr<char[]> buf(new char[count]);
|
||||||
|
|
||||||
v0 = file->read(buf.get(), count);
|
v0 = file->read(buf.get(), count);
|
||||||
|
@ -614,7 +653,8 @@ namespace ioman {
|
||||||
for (s32 i = 0; i < (s32)v0; i++)
|
for (s32 i = 0; i < (s32)v0; i++)
|
||||||
iopMemWrite8(data + i, buf[i]);
|
iopMemWrite8(data + i, buf[i]);
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc &) {
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
v0 = -IOP_ENOMEM;
|
v0 = -IOP_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,7 +696,8 @@ namespace ioman {
|
||||||
}
|
}
|
||||||
else if (IOManFile* file = getfd<IOManFile>(fd))
|
else if (IOManFile* file = getfd<IOManFile>(fd))
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
std::unique_ptr<char[]> buf(new char[count]);
|
std::unique_ptr<char[]> buf(new char[count]);
|
||||||
|
|
||||||
for (u32 i = 0; i < count; i++)
|
for (u32 i = 0; i < count; i++)
|
||||||
|
@ -664,7 +705,8 @@ namespace ioman {
|
||||||
|
|
||||||
v0 = file->write(buf.get(), count);
|
v0 = file->write(buf.get(), count);
|
||||||
}
|
}
|
||||||
catch (const std::bad_alloc &) {
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
v0 = -IOP_ENOMEM;
|
v0 = -IOP_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,9 +716,10 @@ namespace ioman {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
} // namespace ioman
|
||||||
|
|
||||||
namespace sysmem {
|
namespace sysmem
|
||||||
|
{
|
||||||
int Kprintf_HLE()
|
int Kprintf_HLE()
|
||||||
{
|
{
|
||||||
// Emulate the expected Kprintf functionality:
|
// Emulate the expected Kprintf functionality:
|
||||||
|
@ -692,7 +735,8 @@ namespace sysmem {
|
||||||
// printf-style formatting processing. This part can be skipped if the user has the
|
// printf-style formatting processing. This part can be skipped if the user has the
|
||||||
// console disabled.
|
// console disabled.
|
||||||
|
|
||||||
if (!SysConsole.iopConsole.IsActive()) return 1;
|
if (!SysConsole.iopConsole.IsActive())
|
||||||
|
return 1;
|
||||||
|
|
||||||
char tmp[1024], tmp2[1024];
|
char tmp[1024], tmp2[1024];
|
||||||
char* ptmp = tmp;
|
char* ptmp = tmp;
|
||||||
|
@ -726,23 +770,30 @@ _start:
|
||||||
|
|
||||||
switch (fmt[i])
|
switch (fmt[i])
|
||||||
{
|
{
|
||||||
case 'f': case 'F':
|
case 'f':
|
||||||
|
case 'F':
|
||||||
ptmp += sprintf(ptmp, tmp2, (float)iopMemRead32(sp + n * 4));
|
ptmp += sprintf(ptmp, tmp2, (float)iopMemRead32(sp + n * 4));
|
||||||
n++;
|
n++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a': case 'A':
|
case 'a':
|
||||||
case 'e': case 'E':
|
case 'A':
|
||||||
case 'g': case 'G':
|
case 'e':
|
||||||
|
case 'E':
|
||||||
|
case 'g':
|
||||||
|
case 'G':
|
||||||
ptmp += sprintf(ptmp, tmp2, (double)iopMemRead32(sp + n * 4));
|
ptmp += sprintf(ptmp, tmp2, (double)iopMemRead32(sp + n * 4));
|
||||||
n++;
|
n++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'd': case 'D':
|
case 'd':
|
||||||
case 'o': case 'O':
|
case 'D':
|
||||||
case 'x': case 'X':
|
case 'o':
|
||||||
|
case 'O':
|
||||||
|
case 'x':
|
||||||
|
case 'X':
|
||||||
ptmp += sprintf(ptmp, tmp2, (u32)iopMemRead32(sp + n * 4));
|
ptmp += sprintf(ptmp, tmp2, (u32)iopMemRead32(sp + n * 4));
|
||||||
n++;
|
n++;
|
||||||
break;
|
break;
|
||||||
|
@ -780,17 +831,20 @@ _start:
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
} // namespace sysmem
|
||||||
|
|
||||||
namespace loadcore {
|
namespace loadcore
|
||||||
|
{
|
||||||
void RegisterLibraryEntries_DEBUG()
|
void RegisterLibraryEntries_DEBUG()
|
||||||
{
|
{
|
||||||
const std::string modname = iopMemReadString(a0 + 12);
|
const std::string modname = iopMemReadString(a0 + 12);
|
||||||
DevCon.WriteLn(Color_Gray, "RegisterLibraryEntries: %8.8s version %x.%02x", modname.data(), (unsigned)iopMemRead8(a0 + 9), (unsigned)iopMemRead8(a0 + 8));
|
DevCon.WriteLn(Color_Gray, "RegisterLibraryEntries: %8.8s version %x.%02x", modname.data(), (unsigned)iopMemRead8(a0 + 9), (unsigned)iopMemRead8(a0 + 8));
|
||||||
}
|
}
|
||||||
}
|
} // namespace loadcore
|
||||||
|
|
||||||
namespace intrman {
|
namespace intrman
|
||||||
|
{
|
||||||
|
// clang-format off
|
||||||
static const char* intrname[] = {
|
static const char* intrname[] = {
|
||||||
"INT_VBLANK", "INT_GM", "INT_CDROM", "INT_DMA", //00
|
"INT_VBLANK", "INT_GM", "INT_CDROM", "INT_DMA", //00
|
||||||
"INT_RTC0", "INT_RTC1", "INT_RTC2", "INT_SIO0", //04
|
"INT_RTC0", "INT_RTC1", "INT_RTC2", "INT_SIO0", //04
|
||||||
|
@ -810,26 +864,29 @@ namespace intrman {
|
||||||
"INT_3C", "INT_3D", "INT_3E", "INT_3F", //3C
|
"INT_3C", "INT_3D", "INT_3E", "INT_3F", //3C
|
||||||
"INT_MAX" //40
|
"INT_MAX" //40
|
||||||
};
|
};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void RegisterIntrHandler_DEBUG()
|
void RegisterIntrHandler_DEBUG()
|
||||||
{
|
{
|
||||||
DevCon.WriteLn(Color_Gray, "RegisterIntrHandler: intr %s, handler %x", intrname[a0], a2);
|
DevCon.WriteLn(Color_Gray, "RegisterIntrHandler: intr %s, handler %x", intrname[a0], a2);
|
||||||
}
|
}
|
||||||
}
|
} // namespace intrman
|
||||||
|
|
||||||
namespace sifcmd {
|
namespace sifcmd
|
||||||
|
{
|
||||||
void sceSifRegisterRpc_DEBUG()
|
void sceSifRegisterRpc_DEBUG()
|
||||||
{
|
{
|
||||||
DevCon.WriteLn(Color_Gray, "sifcmd sceSifRegisterRpc: rpc_id %x", a1);
|
DevCon.WriteLn(Color_Gray, "sifcmd sceSifRegisterRpc: rpc_id %x", a1);
|
||||||
}
|
}
|
||||||
}
|
} // namespace sifcmd
|
||||||
|
|
||||||
u32 irxImportTableAddr(u32 entrypc)
|
u32 irxImportTableAddr(u32 entrypc)
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 i;
|
||||||
|
|
||||||
i = entrypc - 0x18;
|
i = entrypc - 0x18;
|
||||||
while (entrypc - i < 0x2000) {
|
while (entrypc - i < 0x2000)
|
||||||
|
{
|
||||||
if (iopMemRead32(i) == 0x41e00000)
|
if (iopMemRead32(i) == 0x41e00000)
|
||||||
return i;
|
return i;
|
||||||
i -= 4;
|
i -= 4;
|
||||||
|
@ -842,24 +899,41 @@ const char* irxImportFuncname(const std::string &libname, u16 index)
|
||||||
{
|
{
|
||||||
#include "IopModuleNames.cpp"
|
#include "IopModuleNames.cpp"
|
||||||
|
|
||||||
switch (index) {
|
switch (index)
|
||||||
case 0: return "start";
|
{
|
||||||
|
case 0:
|
||||||
|
return "start";
|
||||||
// case 1: reinit?
|
// case 1: reinit?
|
||||||
case 2: return "shutdown";
|
case 2:
|
||||||
|
return "shutdown";
|
||||||
// case 3: ???
|
// case 3: ???
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MODULE(n) if (#n == libname) { using namespace n; switch (index) {
|
// clang-format off
|
||||||
#define END_MODULE }}
|
#define MODULE(n) \
|
||||||
#define EXPORT_D(i, n) case (i): return n ## _DEBUG;
|
if (#n == libname) \
|
||||||
#define EXPORT_H(i, n) case (i): return n ## _HLE;
|
{ \
|
||||||
|
using namespace n; \
|
||||||
|
switch (index) \
|
||||||
|
{
|
||||||
|
#define END_MODULE \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define EXPORT_D(i, n) \
|
||||||
|
case (i): \
|
||||||
|
return n##_DEBUG;
|
||||||
|
#define EXPORT_H(i, n) \
|
||||||
|
case (i): \
|
||||||
|
return n##_HLE;
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
irxHLE irxImportHLE(const std::string& libname, u16 index)
|
irxHLE irxImportHLE(const std::string& libname, u16 index)
|
||||||
{
|
{
|
||||||
// debugging output
|
// debugging output
|
||||||
|
// clang-format off
|
||||||
MODULE(sysmem)
|
MODULE(sysmem)
|
||||||
EXPORT_H( 14, Kprintf)
|
EXPORT_H( 14, Kprintf)
|
||||||
END_MODULE
|
END_MODULE
|
||||||
|
@ -877,12 +951,14 @@ irxHLE irxImportHLE(const std::string &libname, u16 index)
|
||||||
EXPORT_H( 15, dread)
|
EXPORT_H( 15, dread)
|
||||||
EXPORT_H( 16, getStat)
|
EXPORT_H( 16, getStat)
|
||||||
END_MODULE
|
END_MODULE
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
irxDEBUG irxImportDebug(const std::string& libname, u16 index)
|
irxDEBUG irxImportDebug(const std::string& libname, u16 index)
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
MODULE(loadcore)
|
MODULE(loadcore)
|
||||||
EXPORT_D( 6, RegisterLibraryEntries)
|
EXPORT_D( 6, RegisterLibraryEntries)
|
||||||
END_MODULE
|
END_MODULE
|
||||||
|
@ -892,6 +968,7 @@ irxDEBUG irxImportDebug(const std::string &libname, u16 index)
|
||||||
MODULE(sifcmd)
|
MODULE(sifcmd)
|
||||||
EXPORT_D( 17, sceSifRegisterRpc)
|
EXPORT_D( 17, sceSifRegisterRpc)
|
||||||
END_MODULE
|
END_MODULE
|
||||||
|
// clang-format off
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* PCSX2 - PS2 Emulator for PCs
|
/* PCSX2 - PS2 Emulator for PCs
|
||||||
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
* Copyright (C) 2002-2021 PCSX2 Dev Team
|
||||||
*
|
*
|
||||||
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
||||||
* of the GNU Lesser General Public License as published by the Free Software Found-
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
||||||
|
@ -37,7 +37,8 @@
|
||||||
#define IOP_SEEK_CUR 1
|
#define IOP_SEEK_CUR 1
|
||||||
#define IOP_SEEK_END 2
|
#define IOP_SEEK_END 2
|
||||||
|
|
||||||
class IOManFile {
|
class IOManFile
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
static int open(IOManFile** file, const std::string& path, s32 flags, u16 mode)
|
static int open(IOManFile** file, const std::string& path, s32 flags, u16 mode)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +52,8 @@ public:
|
||||||
virtual int write(void* buf, u32 count) { return -IOP_EIO; }
|
virtual int write(void* buf, u32 count) { return -IOP_EIO; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class IOManDir {
|
class IOManDir
|
||||||
|
{
|
||||||
// Don't think about it until we know the loaded ioman version.
|
// Don't think about it until we know the loaded ioman version.
|
||||||
// The dirent structure changed between versions.
|
// The dirent structure changed between versions.
|
||||||
public:
|
public:
|
||||||
|
@ -82,7 +84,7 @@ namespace R3000A
|
||||||
{
|
{
|
||||||
void reset();
|
void reset();
|
||||||
}
|
}
|
||||||
}
|
} // namespace R3000A
|
||||||
|
|
||||||
extern void Hle_SetElfPath(const char* elfFileName);
|
extern void Hle_SetElfPath(const char* elfFileName);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue