From 6ea9b737a859b30b245025ad75f59acb03cc29ff Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Wed, 17 Jun 2026 08:04:13 -0500 Subject: [PATCH] refactor: Make data const or zero-initialized for cleaner (re-)initialization Some functions have const arguments accordingly Initialization has been moved inside functions, or ctors if there is no conveient function Some global variables have been made local, static, or removed Sema, Thread, DmacHandler, IntcHandler, and fd handle 0 as invalid --- ee/debug/src/font.c | 2 +- ee/debug/src/scr_printf.c | 62 +++++++------ ee/draw/include/draw3d.h | 2 +- ee/draw/samples/teapot/teapot.c | 2 +- ee/draw/src/draw3d.c | 2 +- ee/erl/src/erl.c | 8 +- ee/font/include/font.h | 6 +- ee/font/src/fontx.c | 8 +- ee/font/src/fsfont.c | 4 +- ee/graph/include/graph.h | 8 -- ee/graph/src/graph_mode.c | 18 ++-- ee/kernel/src/exit.c | 2 +- ee/kernel/src/fileio.c | 16 +++- ee/kernel/src/osd_config.c | 11 ++- ee/kernel/src/sifcmd.c | 8 +- ee/kernel/src/sifrpc.c | 32 +++---- ee/kernel/src/timer.c | 15 ++-- ee/kernel/src/tlbfunc.c | 5 +- ee/libcglue/src/fdman.c | 5 +- ee/libcglue/src/glue.c | 32 ++++++- ee/libcglue/src/ps2sdkapi.c | 3 +- ee/libcglue/src/sjis.c | 6 +- ee/libgs/src/ResetPath.s | 7 +- ee/libgs/src/libgs.c | 9 +- ee/libpthreadglue/src/osal.c | 4 +- ee/libvux/src/vux.c | 111 +++++++++++++----------- ee/mpeg/src/libmpeg_core.c | 10 +-- ee/network/netman/src/rpc_client.c | 18 ++-- ee/network/netman/src/rpc_server.c | 14 +-- ee/network/tcpip/src/ps2ip.c | 4 +- ee/network/tcpip/src/sys_arch.c | 8 +- ee/rpc/cdvd/src/libcdvd.c | 16 ++-- ee/rpc/cdvd/src/ncmd.c | 2 +- ee/rpc/cdvd/src/scmd.c | 2 +- ee/rpc/filexio/src/fileXio_rpc.c | 24 ++++- ee/rpc/hdd/src/libhdd.c | 4 +- ee/rpc/keyboard/src/libkbd.c | 10 ++- ee/rpc/poweroff/src/poweroff.c | 6 +- ee/rpc/tcpips/src/ps2ipc.c | 6 +- ee/sbv/src/patch_disable_prefix_check.c | 11 ++- ee/sbv/src/patch_enable_lmb.c | 71 +++++++-------- ee/sbv/src/patch_fileio.c | 51 ++++++----- 42 files changed, 366 insertions(+), 279 deletions(-) diff --git a/ee/debug/src/font.c b/ee/debug/src/font.c index a3c16d8b8f09..dd8dcf8a6269 100644 --- a/ee/debug/src/font.c +++ b/ee/debug/src/font.c @@ -15,7 +15,7 @@ #include -u8 msx[]= +const u8 msx[]= "\x00\x00\x00\x00\x00\x00\x00\x00\x3c\x42\xa5\x81\xa5\x99\x42\x3c" "\x3c\x7e\xdb\xff\xff\xdb\x66\x3c\x6c\xfe\xfe\xfe\x7c\x38\x10\x00" "\x10\x38\x7c\xfe\x7c\x38\x10\x00\x10\x38\x54\xfe\x54\x10\x38\x00" diff --git a/ee/debug/src/scr_printf.c b/ee/debug/src/scr_printf.c index bc6e69bba9d4..29a39746dbd8 100644 --- a/ee/debug/src/scr_printf.c +++ b/ee/debug/src/scr_printf.c @@ -22,10 +22,10 @@ #include #include -static short int X = 0, Y = 0; -static short int MX = 80, MY = 40; -static u32 bgcolor = 0, fontcolor = 0xffffff, cursorcolor = 0xffffff; -static short int cursor = 1; +static short int X, Y; +static const short int MX = 80, MY = 40; +static u32 bgcolor, fontcolor, cursorcolor; +static short int cursor; struct t_setupscr { @@ -111,7 +111,7 @@ static void DmaReset(void) * @param size The size (in 16 byte quads) of the data to be transfered. */ -static inline void progdma(void *addr, int size) +static inline void progdma(const void *addr, int size) { *R_EE_D2_QWC = (u32)size; // D2_QWC *R_EE_D2_MADR = (u32)addr; // D2_MADR @@ -133,19 +133,26 @@ void scr_setcursorcolor(u32 color) cursorcolor = color; } +static const struct t_setupscr g_setupscr_template = { + {0x100000000000800E, 0xE, 0xA0000, 0x4C, 0x8C, 0x4E}, // GIFtag (REGS: A+D, NREG 1, FLG PACKED, EOP, NLOOP 14), FRAME_1 (PSM PSMCT32, FBW 10, FBP 0), ZBUF_1 (PSM PSMZ32, ZBP 140) + {27648, 30976}, + {0x18}, // XYOFFSET_1 (OFX 1728.0, OFY 1936.0) + {0, 639, 0, 223}, // SCISSOR_1 (SCAX0 0, SCAX1 639, SCAY0 0, SCAY1 223) + {0x40, 1, 0x1a, 1, 0x46, 0, 0x45, 0x70000, // PRMODECONT (AC PRIM), COLCLAMP (CLAMP 1), DTHE (DTHE 0) + 0x47, 0x30000, 0x47, 6, 0, 0x3F80000000000000, 1, 0x79006C00, 5, // TEST_1 (ZTST GREATER, ZTE 1), TEST_1 (ZTST ALWAYS, ZTE 1), PMODE (CRTMD 1, EN2 1), RGBAQ (Q 1.0, A 0, B 0, G 0, R 0), XYZ2 (Z 0.0, Y 1728.0, X 1936.0) + 0x87009400, 5, 0x70000, 0x47} // XYZ2 (Z 0, Y 2160.0, X 2368.0), TEST_1 (ZTST GREATER, ZTE 1) +}; + void init_scr(void) { - static struct t_setupscr setupscr __attribute__((aligned(16))) = { - {0x100000000000800E, 0xE, 0xA0000, 0x4C, 0x8C, 0x4E}, // GIFtag (REGS: A+D, NREG 1, FLG PACKED, EOP, NLOOP 14), FRAME_1 (PSM PSMCT32, FBW 10, FBP 0), ZBUF_1 (PSM PSMZ32, ZBP 140) - {27648, 30976}, - {0x18}, // XYOFFSET_1 (OFX 1728.0, OFY 1936.0) - {0, 639, 0, 223}, // SCISSOR_1 (SCAX0 0, SCAX1 639, SCAY0 0, SCAY1 223) - {0x40, 1, 0x1a, 1, 0x46, 0, 0x45, 0x70000, // PRMODECONT (AC PRIM), COLCLAMP (CLAMP 1), DTHE (DTHE 0) - 0x47, 0x30000, 0x47, 6, 0, 0x3F80000000000000, 1, 0x79006C00, 5, // TEST_1 (ZTST GREATER, ZTE 1), TEST_1 (ZTST ALWAYS, ZTE 1), PMODE (CRTMD 1, EN2 1), RGBAQ (Q 1.0, A 0, B 0, G 0, R 0), XYZ2 (Z 0.0, Y 1728.0, X 1936.0) - 0x87009400, 5, 0x70000, 0x47} // XYZ2 (Z 0, Y 2160.0, X 2368.0), TEST_1 (ZTST GREATER, ZTE 1) - }; + static struct t_setupscr setupscr __attribute__((aligned(16))); + *((struct t_setupscr *)UNCACHED_SEG(&setupscr)) = g_setupscr_template; X = Y = 0; + scr_setbgcolor(0); + scr_setfontcolor(0xffffff); + scr_setcursorcolor(0xffffff); + scr_setCursor(1); DmaReset(); Init_GS(1, debug_detect_signal() == 1 ? 3 : 2, 0); // Interlaced, NTSC/PAL and FIELD mode @@ -156,25 +163,28 @@ void init_scr(void) Dma02Wait(); } -extern u8 msx[]; +extern const u8 msx[]; + +static const struct t_setupchar g_setupchar_template = { + {0x1000000000000004, 0xE, 0xA000000000000, 0x50}, // GIFtag (REGS: A+D, NREG 1, FLG PACKED, NLOOP 4), BITBLTBUF (DPSM PSMCT32, DBW 10, DBP 0) + {0}, + 100, + 100, + {0x51}, // TRXPOS (DSAX 100, DSAY 100) + {8, 8}, // TRXREG (RRW 8, RRH 8) + {0x52, 0, 0x53, 0x800000000008010, 0} // TRXDIR (XDIR Host -> Local), GIFtag (FLG IMAGE, EOP, NLOOP 16) +}; void scr_putchar(int x, int y, u32 color, int ch) { - static struct t_setupchar setupchar __attribute__((aligned(16))) = { - {0x1000000000000004, 0xE, 0xA000000000000, 0x50}, // GIFtag (REGS: A+D, NREG 1, FLG PACKED, NLOOP 4), BITBLTBUF (DPSM PSMCT32, DBW 10, DBP 0) - {0}, - 100, - 100, - {0x51}, // TRXPOS (DSAX 100, DSAY 100) - {8, 8}, // TRXREG (RRW 8, RRH 8) - {0x52, 0, 0x53, 0x800000000008010, 0} // TRXDIR (XDIR Host -> Local), GIFtag (FLG IMAGE, EOP, NLOOP 16) - }; - /* charmap must be aligned to a 16-bye boundary. */ + static struct t_setupchar setupchar __attribute__((aligned(16))); + /* charmap must be aligned to a 16-byte boundary. */ static u32 charmap[64] __attribute__((aligned(16))); int i, j, l; - u8 *font; + const u8 *font; u32 pixel; + *((struct t_setupchar *)UNCACHED_SEG(&setupchar)) = g_setupchar_template; ((struct t_setupchar *)UNCACHED_SEG(&setupchar))->x = x; ((struct t_setupchar *)UNCACHED_SEG(&setupchar))->y = y; diff --git a/ee/draw/include/draw3d.h b/ee/draw/include/draw3d.h index e30d323c2bf6..936791dbbc78 100644 --- a/ee/draw/include/draw3d.h +++ b/ee/draw/include/draw3d.h @@ -62,7 +62,7 @@ extern "C" { #endif /** Begins a primitive, allowing for vertex data to be filled in the packet directly */ -extern qword_t *draw_prim_start(qword_t *q, int context, prim_t *prim, color_t *color); +extern qword_t *draw_prim_start(qword_t *q, int context, const prim_t *prim, const color_t *color); /** Ends a primitive by calculating the number of qwords used, the number of registers, the register list */ extern qword_t *draw_prim_end(qword_t *q,int nreg, u64 reglist); diff --git a/ee/draw/samples/teapot/teapot.c b/ee/draw/samples/teapot/teapot.c index 884cd8971e0a..f117849691f7 100644 --- a/ee/draw/samples/teapot/teapot.c +++ b/ee/draw/samples/teapot/teapot.c @@ -138,7 +138,7 @@ void flip_buffers(packet_t *flip,framebuffer_t *frame) } -qword_t *render_teapot(qword_t *q,MATRIX view_screen, VECTOR object_position, VECTOR object_rotation, prim_t *prim, color_t *color, framebuffer_t *frame, zbuffer_t *z) +qword_t *render_teapot(qword_t *q,MATRIX view_screen, VECTOR object_position, VECTOR object_rotation, const prim_t *prim, const color_t *color, framebuffer_t *frame, zbuffer_t *z) { int i; diff --git a/ee/draw/src/draw3d.c b/ee/draw/src/draw3d.c index e92301da7262..eff6ffe2d5b7 100644 --- a/ee/draw/src/draw3d.c +++ b/ee/draw/src/draw3d.c @@ -8,7 +8,7 @@ // Starting position of primitive static qword_t *__prim_start = NULL; -qword_t *draw_prim_start(qword_t *q, int context, prim_t *prim, color_t *color) +qword_t *draw_prim_start(qword_t *q, int context, const prim_t *prim, const color_t *color) { // Set the primitive register in packed mode, but don't end the packet diff --git a/ee/erl/src/erl.c b/ee/erl/src/erl.c index b4c4bc052e82..3746a32e36f0 100644 --- a/ee/erl/src/erl.c +++ b/ee/erl/src/erl.c @@ -203,7 +203,7 @@ static char * reloc_types[] = { /* These global names will not be 'exported' to the global space. */ -static const char * local_names[] = { +static const char * const local_names[] = { "_init", "_fini", "erl_id", @@ -538,7 +538,7 @@ static int fix_loosy(struct erl_record_t * provider, const char * symbol, u32 ad } static int is_local(const char * symbol) { - const char ** p; + const char * const * p; for (p = local_names; *p; p++) if (!strcmp(*p, symbol)) @@ -962,7 +962,7 @@ static struct erl_record_t * _init_load_erl_wrapper_from_file(char * erl_id) { return _init_load_erl_from_file(tmpnam, erl_id); } -erl_loader_t _init_load_erl = _init_load_erl_wrapper_from_file; +erl_loader_t _init_load_erl; static struct erl_record_t * load_erl(const char * fname, u8 * elf_mem, u32 addr, int argc, char ** argv) { struct erl_record_t * r; @@ -1007,6 +1007,8 @@ static struct erl_record_t * load_erl(const char * fname, u8 * elf_mem, u32 addr dprintf("erl_dependancies = %08X.\n", r->dependancies); if (r->dependancies) { + if (!_init_load_erl) + _init_load_erl = _init_load_erl_wrapper_from_file; char ** d; for (d = r->dependancies; *d; d++) { dprintf("Loading dependancy: %s.\n", *d); diff --git a/ee/font/include/font.h b/ee/font/include/font.h index 720d0b7df236..b9ea110f6b55 100644 --- a/ee/font/include/font.h +++ b/ee/font/include/font.h @@ -80,10 +80,10 @@ extern int fontx_load(const char *path, fontx_t* fontx, int type, int wmargin, i extern void fontx_unload(fontx_t *fontx); /** Prints an ascii/JISX201 formatted string */ -extern qword_t *fontx_print_ascii(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, color_t *c0, fontx_t *fontx); +extern qword_t *fontx_print_ascii(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, const color_t *c0, fontx_t *fontx); /** Prints a SJIS formatted string */ -extern qword_t *fontx_print_sjis(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, color_t *c0, fontx_t *ascii, fontx_t *kanji); +extern qword_t *fontx_print_sjis(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, const color_t *c0, fontx_t *ascii, fontx_t *kanji); // FontStudio type fonts @@ -105,7 +105,7 @@ extern char *fontstudio_load_ini(const char *path); extern void fontstudio_unload_ini(fsfont_t *font); /** Prints a unicode formatted string (UTF+8) */ -extern qword_t *fontstudio_print_string(qword_t *q, int context, const unsigned char *string, int alignment, const vertex_t *v0, color_t *c0, fsfont_t *font); +extern qword_t *fontstudio_print_string(qword_t *q, int context, const unsigned char *string, int alignment, const vertex_t *v0, const color_t *c0, fsfont_t *font); #ifdef __cplusplus } diff --git a/ee/font/src/fontx.c b/ee/font/src/fontx.c index 8fe359ddbdf0..3a448cbcc699 100644 --- a/ee/font/src/fontx.c +++ b/ee/font/src/fontx.c @@ -37,7 +37,7 @@ typedef struct { } block[]; } fontx_hdr; -static prim_t charprim = +static const prim_t charprim = { PRIM_POINT, PRIM_SHADE_FLAT, DRAW_DISABLE, DRAW_DISABLE, DRAW_ENABLE, DRAW_DISABLE, @@ -45,7 +45,7 @@ static prim_t charprim = }; // These are the SJIS table ranges for character lookup -unsigned short sjis_table[] = { +static const unsigned short sjis_table[] = { 0x8140,0x817e, 0x8180,0x81ac, 0x81b8,0x81bf, @@ -556,7 +556,7 @@ qword_t *draw_fontx_char(qword_t *q, unsigned short c, vertex_t *v0, fontx_t *fo } -qword_t *fontx_print_ascii(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, color_t *c0, fontx_t *fontx) +qword_t *fontx_print_ascii(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, const color_t *c0, fontx_t *fontx) { int i,j; @@ -732,7 +732,7 @@ qword_t *fontx_print_ascii(qword_t *q, int context, const unsigned char *str, in } -qword_t *fontx_print_sjis(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, color_t *c0, fontx_t *ascii, fontx_t *kanji) +qword_t *fontx_print_sjis(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, const color_t *c0, fontx_t *ascii, fontx_t *kanji) { int i,j; diff --git a/ee/font/src/fsfont.c b/ee/font/src/fsfont.c index a1a117f18353..225ba1773281 100644 --- a/ee/font/src/fsfont.c +++ b/ee/font/src/fsfont.c @@ -8,7 +8,7 @@ #include -static prim_t charprim = +static const prim_t charprim = { PRIM_SPRITE, PRIM_SHADE_FLAT, DRAW_ENABLE, DRAW_DISABLE, DRAW_ENABLE, DRAW_DISABLE, @@ -453,7 +453,7 @@ qword_t *draw_fontstudio_char(qword_t *q, unsigned int c, vertex_t *v0, fsfont_t } -qword_t *fontstudio_print_string(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, color_t *c0, fsfont_t *font) +qword_t *fontstudio_print_string(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, const color_t *c0, fsfont_t *font) { int i = 0,j; diff --git a/ee/graph/include/graph.h b/ee/graph/include/graph.h index 366e6f10d892..c320470129af 100644 --- a/ee/graph/include/graph.h +++ b/ee/graph/include/graph.h @@ -86,14 +86,6 @@ #define GRAPH_BLEND_RC2 0 #define GRAPH_BLEND_BGCOLOR 1 -typedef struct { - int x,y; - int width, height; - int mode; -} GRAPH_MODE; - -extern GRAPH_MODE graph_mode[]; - #ifdef __cplusplus extern "C" { #endif diff --git a/ee/graph/src/graph_mode.c b/ee/graph/src/graph_mode.c index 1eae144c356b..6755136138b9 100644 --- a/ee/graph/src/graph_mode.c +++ b/ee/graph/src/graph_mode.c @@ -8,8 +8,14 @@ #include #include +typedef struct { + int x,y; + int width, height; + int mode; +} GRAPH_MODE; + /* y offset is non-interlaced */ -GRAPH_MODE graph_mode[22] = +static const GRAPH_MODE graph_mode[22] = { { 0, 0, 0, 0, 0 }, // AUTO @@ -39,7 +45,6 @@ GRAPH_MODE graph_mode[22] = static float graph_width = 0.0f; static float graph_height = 0.0f; -static float graph_aspect = 1.0f; static int graph_filter = 0; static int graph_crtmode = 0; @@ -53,7 +58,7 @@ static int graph_magv = 0; static u64 graph_pmode = 0; // old bios has GCONT enabled -u64 smode1_values[22] = +static const u64 smode1_values[22] = { 0, @@ -405,6 +410,7 @@ void graph_set_smode1(char cmod, char gcont) float graph_aspect_ratio(void) { + float graph_aspect; // Get the tv screen type as defined in the osd configuration. if (configGetTvScreenType() == TV_SCREEN_169) @@ -421,10 +427,7 @@ float graph_aspect_ratio(void) } // Return the current aspect ratio - graph_aspect = graph_aspect * (graph_height / graph_width); - - return graph_aspect; - + return graph_aspect * (graph_height / graph_width); } int graph_get_config(char *config) @@ -446,7 +449,6 @@ int graph_shutdown(void) *GS_REG_CSR = GS_SET_CSR(0,0,0,0,0,0,0,0,0,0,0,0); // Reset the static variables. - graph_aspect = 1.0f; graph_width = 0.0f; graph_height = 0.0f; graph_filter = 0; diff --git a/ee/kernel/src/exit.c b/ee/kernel/src/exit.c index 9ba16db0f35e..f04600ab8810 100644 --- a/ee/kernel/src/exit.c +++ b/ee/kernel/src/exit.c @@ -29,7 +29,7 @@ struct SyscallData void *function; }; -struct SyscallData SysEntry = { +static const struct SyscallData SysEntry = { 0x5A, &kCopyBytes}; diff --git a/ee/kernel/src/fileio.c b/ee/kernel/src/fileio.c index debe03955b15..a2d957b1fbeb 100644 --- a/ee/kernel/src/fileio.c +++ b/ee/kernel/src/fileio.c @@ -41,8 +41,8 @@ SifRpcClientData_t _fio_cd; int _fio_recv_data[512] __attribute__((aligned(64))); int _fio_intr_data[32] __attribute__((aligned(64))); int _fio_block_mode; -int _fio_io_sema = -1; -int _fio_completion_sema = -1; +int _fio_io_sema; +int _fio_completion_sema; #endif #ifdef F_fio_init @@ -70,7 +70,10 @@ int fioInit(void) sema.option = 0; _fio_completion_sema = CreateSema(&sema); if (_fio_completion_sema < 0) + { + _fio_completion_sema = 0; return -E_LIB_SEMA_CREATE; + } // Unofficial: create a locking semaphore to prevent a thread from overwriting another thread's return status. sema.init_count = 1; @@ -78,7 +81,10 @@ int fioInit(void) sema.option = 0; _fio_io_sema = CreateSema(&sema); if (_fio_io_sema < 0) + { + _fio_io_sema = 0; return -E_LIB_SEMA_CREATE; + } _fio_block_mode = FIO_WAIT; @@ -145,11 +151,13 @@ void fioExit(void) { if (_fio_cd.server) { memset(&_fio_cd, 0, sizeof _fio_cd); - if (_fio_completion_sema >= 0) { + if (_fio_completion_sema > 0) { DeleteSema(_fio_completion_sema); + _fio_completion_sema = 0; } - if (_fio_io_sema >= 0) { + if (_fio_io_sema > 0) { DeleteSema(_fio_io_sema); + _fio_io_sema = 0; } } } diff --git a/ee/kernel/src/osd_config.c b/ee/kernel/src/osd_config.c index 8f56aa189f0c..b4f7a7fc97ca 100644 --- a/ee/kernel/src/osd_config.c +++ b/ee/kernel/src/osd_config.c @@ -43,7 +43,16 @@ typedef struct extern ConfigParamT10K g_t10KConfig; #ifdef F__config_internals -ConfigParamT10K g_t10KConfig = {540, TV_SCREEN_43, DATE_YYYYMMDD, LANGUAGE_JAPANESE, 0, 0, 0}; +ConfigParamT10K g_t10KConfig; + +__attribute__((constructor)) +static void __t10KConfigInitialize(void) +{ + g_t10KConfig.timezoneOffset = 540; + g_t10KConfig.screenType = TV_SCREEN_43; + g_t10KConfig.dateFormat = DATE_YYYYMMDD; + g_t10KConfig.language = LANGUAGE_JAPANESE; +} #endif #ifdef F_converttobcd diff --git a/ee/kernel/src/sifcmd.c b/ee/kernel/src/sifcmd.c index 64b90256cf47..05554f682caf 100644 --- a/ee/kernel/src/sifcmd.c +++ b/ee/kernel/src/sifcmd.c @@ -182,7 +182,7 @@ static SifCmdSysHandlerData_t sys_cmd_handlers[SYS_CMD_HANDLER_MAX]; static int sregs[32]; struct cmd_data _sif_cmd_data; -static int sif0_id = -1; +static int sif0_id; struct ca_pkt { @@ -220,7 +220,7 @@ void sceSifInitCmd(void) if (HasIopRebootedSinceLastCall()) sceSifExitCmd(); - if (sif0_id >= 0) + if (sif0_id > 0) return; DI(); @@ -284,10 +284,10 @@ void sceSifInitCmd(void) void sceSifExitCmd(void) { - if (sif0_id >= 0) { + if (sif0_id > 0) { DisableDmac(DMAC_SIF0); RemoveDmacHandler(DMAC_SIF0, sif0_id); - sif0_id = -1; + sif0_id = 0; } } #endif diff --git a/ee/kernel/src/sifrpc.c b/ee/kernel/src/sifrpc.c index 23ceb81e4587..22e67da102dc 100644 --- a/ee/kernel/src/sifrpc.c +++ b/ee/kernel/src/sifrpc.c @@ -277,21 +277,12 @@ int sceSifGetOtherData(SifRpcReceiveData_t *rd, void *src, void *dest, int size, #ifdef F_SifRpcMain /* The packets sent on EE RPC requests are allocated from this table. */ -static u8 pkt_table[2048] __attribute__((aligned(64))); +static u8 pkt_table[32][RPC_PACKET_SIZE] __attribute__((aligned(64))); /* A ring buffer used to allocate packets sent on IOP requests. */ -static u8 rdata_table[2048] __attribute__((aligned(64))); -static u8 client_table[2048] __attribute__((aligned(64))); - -struct rpc_data _sif_rpc_data = { - pid : 1, - pkt_table : pkt_table, - pkt_table_len : sizeof(pkt_table) / RPC_PACKET_SIZE, - rdata_table : rdata_table, - rdata_table_len : sizeof(rdata_table) / RPC_PACKET_SIZE, - client_table : client_table, - client_table_len : sizeof(client_table) / RPC_PACKET_SIZE, - rdata_table_idx : 0 -}; +static u8 rdata_table[32][RPC_PACKET_SIZE] __attribute__((aligned(64))); +static u8 client_table[32][RPC_PACKET_SIZE] __attribute__((aligned(64))); + +struct rpc_data _sif_rpc_data; static int init = 0; @@ -426,9 +417,14 @@ void sceSifInitRpc(int mode) sceSifInitCmd(); DI(); - _sif_rpc_data.pkt_table = UNCACHED_SEG(_sif_rpc_data.pkt_table); - _sif_rpc_data.rdata_table = UNCACHED_SEG(_sif_rpc_data.rdata_table); - _sif_rpc_data.client_table = UNCACHED_SEG(_sif_rpc_data.client_table); + _sif_rpc_data.pid = 1; + + _sif_rpc_data.pkt_table = UNCACHED_SEG(pkt_table); + _sif_rpc_data.pkt_table_len = sizeof(pkt_table) / sizeof(pkt_table[0]); + _sif_rpc_data.rdata_table = UNCACHED_SEG(rdata_table); + _sif_rpc_data.rdata_table_len = sizeof(rdata_table) / sizeof(rdata_table[0]); + _sif_rpc_data.client_table = UNCACHED_SEG(client_table); + _sif_rpc_data.client_table_len = sizeof(client_table) / sizeof(client_table[0]); _sif_rpc_data.rdata_table_idx = 0; struct rpc_data *rpc_data = (struct rpc_data *)(&_sif_rpc_data); @@ -452,7 +448,7 @@ void sceSifInitRpc(int mode) if (sceSifGetReg(SIF_SYSREG_RPCINIT)) return; - cmdp = (u32 *)&pkt_table[64]; + cmdp = (u32 *)&((u8 *)_sif_rpc_data.pkt_table)[64]; cmdp[3] = 1; sceSifSendCmd(SIF_CMD_INIT_CMD, cmdp, 16, NULL, NULL, 0); diff --git a/ee/kernel/src/timer.c b/ee/kernel/src/timer.c index 548481c4158a..ecae59f1b98c 100644 --- a/ee/kernel/src/timer.c +++ b/ee/kernel/src/timer.c @@ -65,15 +65,7 @@ extern s32 TimerHandler_callback(s32 cause, void *arg, void *addr); #define COUNTER_COUNT 128 #ifdef F_timer_data -timer_ee_global_struct g_Timer = { - .timer_handled_count = 0, - .intc_handler = -1, - .timer_counter_total = 1, - .timer_counter_used = 0, - .timer_counter_buf_free = NULL, - .timer_counter_buf_alarm = NULL, - .current_handling_timer_id = -1, -}; +timer_ee_global_struct g_Timer; counter_struct_t g_CounterBuf[COUNTER_COUNT] __attribute__((aligned(64))); #else extern timer_ee_global_struct g_Timer; @@ -141,12 +133,14 @@ __attribute__((weak)) s32 InitTimer(s32 in_mode) u32 oldintr; u32 mode; - if (g_Timer.intc_handler >= 0) + if (g_Timer.intc_handler > 0) { return 0x80008001; // EINIT } g_Timer.timer_handled_count = 0; g_Timer.timer_counter_used = 0; + g_Timer.timer_counter_total = 1; + g_Timer.current_handling_timer_id = -1; memset(g_CounterBuf, 0, sizeof(g_CounterBuf)); g_Timer.timer_counter_buf_free = &g_CounterBuf[0]; for (u32 i = 0; i < ((sizeof(g_CounterBuf) / sizeof(g_CounterBuf[0])) - 1); i += 1) @@ -154,6 +148,7 @@ __attribute__((weak)) s32 InitTimer(s32 in_mode) g_CounterBuf[i].timer_next = &g_CounterBuf[i + 1]; } g_CounterBuf[(sizeof(g_CounterBuf) / sizeof(g_CounterBuf[0])) - 1].timer_next = NULL; + g_Timer.timer_counter_buf_alarm = NULL; ForTimer_InitAlarm(); handler = AddIntcHandler2(INTC_TIM2, TimerHandler_callback, 0, NULL); if (handler < 0) diff --git a/ee/kernel/src/tlbfunc.c b/ee/kernel/src/tlbfunc.c index 6b74c1757a1a..c80fc7bb7b60 100644 --- a/ee/kernel/src/tlbfunc.c +++ b/ee/kernel/src/tlbfunc.c @@ -140,7 +140,7 @@ static const struct TLBEntry extendTLB[TLB_NUM_EXTENDED_ENTRIES] = { {0x007FE000, 0x31000000, 0x0004003F, 0x0005003F}, {0x007FE000, 0x31800000, 0x0006003F, 0x0007003F}}; -static struct TLBInfo TLBInfo = {TLB_NUM_KERNEL_ENTRIES, TLB_NUM_DEFAULT_ENTRIES, TLB_NUM_EXTENDED_ENTRIES, 0, kernelTLB, defaultTLB, extendTLB}; +static const struct TLBInfo TLBInfo = {TLB_NUM_KERNEL_ENTRIES, TLB_NUM_DEFAULT_ENTRIES, TLB_NUM_EXTENDED_ENTRIES, 0, kernelTLB, defaultTLB, extendTLB}; static int InitTLB32MB(void) { @@ -170,7 +170,8 @@ static int InitTLB32MB(void) _SetTLBEntry(i, TLBEntry->PageMask, TLBEntry->EntryHi, TLBEntry->EntryLo0, TLBEntry->EntryLo1); } - TLBInfo.NumWiredEntries = NumTlbEntries = i; + // Unofficial: do not set TLBInfo.NumWiredEntries + NumTlbEntries = i; set_mips_cop_reg(0, COP0_REG_Wired, NumTlbEntries); EE_SYNCP(); diff --git a/ee/libcglue/src/fdman.c b/ee/libcglue/src/fdman.c index 7bbf7c1f4703..59b8325ed9c5 100644 --- a/ee/libcglue/src/fdman.c +++ b/ee/libcglue/src/fdman.c @@ -24,7 +24,7 @@ #include "fdman.h" #ifdef F___fdman_sema -int __fdman_sema = -1; +int __fdman_sema; #else extern int __fdman_sema; #endif @@ -52,7 +52,8 @@ void __fdman_init() sema.max_count = 1; sema.option = 0; __fdman_sema = CreateSema(&sema); - if (__fdman_sema < 0) { + if (__fdman_sema <= 0) { + __fdman_sema = 0; abort(); } diff --git a/ee/libcglue/src/glue.c b/ee/libcglue/src/glue.c index de6c42362eff..0b8ea18d06e5 100644 --- a/ee/libcglue/src/glue.c +++ b/ee/libcglue/src/glue.c @@ -55,17 +55,41 @@ int __path_absolute(const char *in, char *out, int len); extern void * _end; #ifdef F___dummy_passwd -char __dummy_passwd_loginbuf[16] = "ps2user"; +char __dummy_passwd_loginbuf[16]; /* the present working directory variable. */ -struct passwd __dummy_passwd = { &__dummy_passwd_loginbuf[0], "xxx", 1000, 1000, "", "", "/", "" }; +struct passwd __dummy_passwd; +__attribute__((constructor)) +static void __dummy_passwd_init(void) +{ + strncpy(__dummy_passwd_loginbuf, "ps2user", sizeof(__dummy_passwd_loginbuf)); + __dummy_passwd.pw_name = &__dummy_passwd_loginbuf[0]; + __dummy_passwd.pw_passwd = "xxx"; + __dummy_passwd.pw_uid = 1000; + __dummy_passwd.pw_gid = 1000; + __dummy_passwd.pw_comment = ""; + __dummy_passwd.pw_gecos = ""; + __dummy_passwd.pw_dir = "/"; + __dummy_passwd.pw_shell = ""; +} #else extern char __dummy_passwd_loginbuf[16]; extern struct passwd __dummy_passwd; #endif #ifdef F___dummy_group -static char *__dummy_group_members[2] = {&__dummy_passwd_loginbuf[0], NULL}; -struct group __dummy_group = { "ps2group", "xxx", 1000, &__dummy_group_members[0]}; +static char *__dummy_group_members[2]; +struct group __dummy_group; + +__attribute__((constructor)) +static void __dummy_group_init(void) +{ + __dummy_group.gr_name = "ps2group"; + __dummy_group.gr_passwd = "xxx"; + __dummy_group.gr_gid = 1000; + __dummy_group.gr_mem = &__dummy_group_members[0]; + __dummy_group_members[0] = &__dummy_passwd_loginbuf[0]; + __dummy_group_members[1] = NULL; +} #else extern struct group __dummy_group; #endif diff --git a/ee/libcglue/src/ps2sdkapi.c b/ee/libcglue/src/ps2sdkapi.c index 1e73a9466759..3e8823e9d992 100644 --- a/ee/libcglue/src/ps2sdkapi.c +++ b/ee/libcglue/src/ps2sdkapi.c @@ -474,6 +474,7 @@ void __fioOpsInitializeImpl(void) if (&rmdir) __fio_fdman_path_ops.rmdir = fioRmdir; // cppcheck-suppress knownConditionTrueFalse if ((&_stat) || (&_fstat)) __fio_fdman_path_ops.stat = __fioGetstatHelper; + if (!_libcglue_fdman_path_ops) _libcglue_fdman_path_ops = &__fio_fdman_path_ops; memset(&__fio_fdman_ops_file, 0, sizeof(__fio_fdman_ops_file)); __fio_fdman_ops_file.getfd = __fioGetFdHelper; @@ -502,7 +503,7 @@ void __fioOpsInitializeImpl(void) #endif #ifdef F__libcglue_fdman_path_ops -_libcglue_fdman_path_ops_t *_libcglue_fdman_path_ops = &__fio_fdman_path_ops; +_libcglue_fdman_path_ops_t *_libcglue_fdman_path_ops = NULL; #endif #ifdef F__libcglue_fdman_socket_ops diff --git a/ee/libcglue/src/sjis.c b/ee/libcglue/src/sjis.c index 07ccc5968fb0..0ce3ec6194ce 100644 --- a/ee/libcglue/src/sjis.c +++ b/ee/libcglue/src/sjis.c @@ -22,7 +22,7 @@ struct charmap_t { }; #if defined(F_isSpecialSJIS) || defined(F_isSpecialASCII) -static struct charmap_t sjis_conversion[] = { +static const struct charmap_t sjis_conversion[] = { { 0x4081, ' ' }, { 0x6d81, '[' }, { 0x6e81, ']' }, @@ -62,7 +62,7 @@ static struct charmap_t sjis_conversion[] = { #ifdef F_isSpecialSJIS unsigned char isSpecialSJIS(short sjis) { - struct charmap_t *s = &sjis_conversion[0]; + const struct charmap_t *s = &sjis_conversion[0]; do { if (s->sjis == sjis) return s->ascii; s++; @@ -76,7 +76,7 @@ unsigned char isSpecialSJIS(short sjis); #ifdef F_isSpecialASCII short isSpecialASCII(unsigned char ascii) { - struct charmap_t *s = &sjis_conversion[0]; + const struct charmap_t *s = &sjis_conversion[0]; do { if (s->ascii == ascii) return s->sjis; s++; diff --git a/ee/libgs/src/ResetPath.s b/ee/libgs/src/ResetPath.s index 3c454796f28d..01b0314e787a 100755 --- a/ee/libgs/src/ResetPath.s +++ b/ee/libgs/src/ResetPath.s @@ -1,9 +1,10 @@ -.data +.pushsection .rodata init_vif_regs_12: .word 0x10000404, 0x20000000, 0x00000000, 0x50000000 .word 0x60000000, 0x30000000, 0x20000000, 0x40000000 +.popsection -.text +.pushsection .text .globl GsResetPath .ent GsResetPath @@ -30,3 +31,5 @@ GsResetPath: jr $ra sw $a3, 0($v1) .end GsResetPath + +.popsection diff --git a/ee/libgs/src/libgs.c b/ee/libgs/src/libgs.c index 43447f486985..b3ed7c279adb 100644 --- a/ee/libgs/src/libgs.c +++ b/ee/libgs/src/libgs.c @@ -19,10 +19,17 @@ extern QWORD GsPrimWorkArea[]; /* Initialization functions. */ -static GsGParam_t gp_15={GS_INTERLACED, GS_MODE_NTSC, GS_FFMD_FRAME, 3}; +static GsGParam_t gp_15; GsGParam_t *GsGetGParam(void) { + if (!gp_15.version) + { + gp_15.interlace = GS_INTERLACED; + gp_15.omode = GS_MODE_NTSC; + gp_15.ffmode = GS_FFMD_FRAME; + gp_15.version = 3; + } return &gp_15; } diff --git a/ee/libpthreadglue/src/osal.c b/ee/libpthreadglue/src/osal.c index 6c6aeb9ba61f..6bfdffe02829 100644 --- a/ee/libpthreadglue/src/osal.c +++ b/ee/libpthreadglue/src/osal.c @@ -196,12 +196,12 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint, ee_sema_t sema; struct OsalThreadInfo *threadInfo; void *stack; - static int threadNum = 1; + static int threadNum; void *pTls; s32 threadId; ps2ThreadData *pThreadData; - if (threadNum++ > MAX_PS2_UID) { + if (++threadNum > MAX_PS2_UID) { threadNum = 0; } diff --git a/ee/libvux/src/vux.c b/ee/libvux/src/vux.c index 29d2fb34207f..a0c5513fc2e6 100644 --- a/ee/libvux/src/vux.c +++ b/ee/libvux/src/vux.c @@ -9,6 +9,7 @@ */ #include +#include #include "vux.h" @@ -17,60 +18,45 @@ +static const VU_MATRIX VuInitMatrix = {{ + {1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f} + }}; +VU_MATRIX VuWorldMatrix; +VU_MATRIX VuViewMatrix; +VU_MATRIX VuPrjectionMatrix; +VU_MATRIX VuLocalScreenMatrix; -VU_MATRIX VuWorldMatrix = {{ - {1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f} - }}; - -VU_MATRIX VuViewMatrix = {{ - {1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f} - }}; - -VU_MATRIX VuPrjectionMatrix = {{ - {1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f} - }}; - -VU_MATRIX VuLocalScreenMatrix = {{ - {1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f} - }}; - - - - - -float vu_projection = 500.0f; -int vu_projection_type = 0; //0=vu_projection , 1=VuPrjectionMatrix -unsigned short vu_offset_x = 2048; -unsigned short vu_offset_y = 2048; -VU_FCVECTOR vu_light_ambient = {0.2f, 0.2f, 0.2f, 1.0f}; -float vu_fog_near = 25000.0f; -float vu_fog_far = 45000.0f; -float vu_near_plane_w = 300.0f; -float vu_near_plane_h = 300.0f; - - - - - - +float vu_projection; +int vu_projection_type; //0=vu_projection , 1=VuPrjectionMatrix +unsigned short vu_offset_x; +unsigned short vu_offset_y; +VU_FCVECTOR vu_light_ambient; +float vu_fog_near; +float vu_fog_far; +float vu_near_plane_w; +float vu_near_plane_h; +__attribute__((constructor)) +static void __VuInit_ctor(void) +{ + VuInit(); +} void VuInit(void) { - - + VuSetWorldMatrix(NULL); + VuSetViewMatrix(NULL); + VuSetProjectionMatrix(NULL); + VuSetLocalScreenMatrix(NULL); + VuSetGeometryXYOffset(2048, 2048); + VuSetProjection(500.0f); + VuSetAmbientLight(0.2f, 0.2f, 0.2f); + vu_fog_near = 25000.0f; + vu_fog_far = 45000.0f; + VuSetProjectionNearPlaneWH(300.0f, 300.0f); } @@ -97,7 +83,14 @@ void VuSetProjection(float z) void VuSetProjectionMatrix(const VU_MATRIX *projection) { - VuPrjectionMatrix = *projection; + if (!projection) + { + VuPrjectionMatrix = VuInitMatrix; + } + else + { + VuPrjectionMatrix = *projection; + } vu_projection_type = 1; // use projection matrix } @@ -115,7 +108,11 @@ void VuSetProjectionType(unsigned int type) void VuSetWorldMatrix(const VU_MATRIX *world) { - + if (!world) + { + VuWorldMatrix = VuInitMatrix; + return; + } VuWorldMatrix = *world; } @@ -124,7 +121,11 @@ void VuSetWorldMatrix(const VU_MATRIX *world) void VuSetViewMatrix(const VU_MATRIX *view) { - + if (!view) + { + VuViewMatrix = VuInitMatrix; + return; + } VuViewMatrix = *view; } @@ -134,7 +135,11 @@ void VuSetViewMatrix(const VU_MATRIX *view) void VuSetLocalScreenMatrix(const VU_MATRIX *m) { - + if (!m) + { + VuLocalScreenMatrix = VuInitMatrix; + return; + } VuLocalScreenMatrix = *m; } diff --git a/ee/mpeg/src/libmpeg_core.c b/ee/mpeg/src/libmpeg_core.c index ff095ab44303..78e3380a9795 100644 --- a/ee/mpeg/src/libmpeg_core.c +++ b/ee/mpeg/src/libmpeg_core.c @@ -56,7 +56,7 @@ static u8 s_CSCFlag; static u32 s_BitsBuffered; static u32 s_LocalBits; -static u32 s_QmIntra[16] __attribute__((aligned(16))) = { +static const u32 s_QmIntra[16] __attribute__((aligned(16))) = { 0x13101008, 0x16161310, 0x16161616, @@ -75,7 +75,7 @@ static u32 s_QmIntra[16] __attribute__((aligned(16))) = { 0x5345453A, }; -static u32 s_QmNonIntra[16] __attribute__((aligned(16))) = { +static const u32 s_QmNonIntra[16] __attribute__((aligned(16))) = { 0x10101010, 0x10101010, 0x10101010, @@ -462,7 +462,7 @@ unsigned int _MPEG_NextStartCode(void) void _MPEG_SetDefQM(int arg0) { (void)arg0; - qword_t *q; + const qword_t *q; int i; _ipu_suspend(); @@ -470,7 +470,7 @@ void _MPEG_SetDefQM(int arg0) while (*R_EE_IPU_CTRL & IPU_CTRL_BUSY) ; - q = (qword_t *)s_QmIntra; + q = (const qword_t *)s_QmIntra; for (i = 0; i < 4; i++) { #ifdef _EE __asm__ __volatile__( @@ -488,7 +488,7 @@ void _MPEG_SetDefQM(int arg0) while (*R_EE_IPU_CTRL & IPU_CTRL_BUSY) ; - q = (qword_t *)s_QmNonIntra; + q = (const qword_t *)s_QmNonIntra; for (i = 0; i < 4; i++) { #ifdef _EE __asm__ __volatile__( diff --git a/ee/network/netman/src/rpc_client.c b/ee/network/netman/src/rpc_client.c index e2575ee6aef2..8e4a31f1eab9 100644 --- a/ee/network/netman/src/rpc_client.c +++ b/ee/network/netman/src/rpc_client.c @@ -28,7 +28,7 @@ static union { u8 buffer[128]; }ReceiveBuffer ALIGNED(64); -static int NetManIOSemaID = -1, NETMAN_Tx_threadID = -1; +static int NetManIOSemaID, NETMAN_Tx_threadID; static unsigned char NETMAN_Tx_ThreadStack[0x1000] ALIGNED(16); static unsigned short int IOPFrameBufferWrPtr; @@ -40,16 +40,16 @@ static unsigned char IsProcessingTx; static void deinitCleanup(void) { - if(NetManIOSemaID >= 0) + if(NetManIOSemaID > 0) { DeleteSema(NetManIOSemaID); - NetManIOSemaID = -1; + NetManIOSemaID = 0; } - if(NETMAN_Tx_threadID >= 0) + if(NETMAN_Tx_threadID > 0) { TerminateThread(NETMAN_Tx_threadID); DeleteThread(NETMAN_Tx_threadID); - NETMAN_Tx_threadID = -1; + NETMAN_Tx_threadID = 0; } memset(&NETMAN_rpc_cd, 0, sizeof(NETMAN_rpc_cd)); } @@ -70,10 +70,11 @@ int NetManInitRPCClient(void){ SemaData.init_count=1; SemaData.option=(u32)NetManID; SemaData.attr=0; - if((NetManIOSemaID=CreateSema(&SemaData)) < 0) + if((NetManIOSemaID=CreateSema(&SemaData)) <= 0) { + NetManIOSemaID = 0; deinitCleanup(); - return NetManIOSemaID; + return -1; } thread.func=&NETMAN_TxThread; @@ -83,8 +84,9 @@ int NetManInitRPCClient(void){ thread.initial_priority=0x56; /* Should be given a higher priority than the protocol stack, so that it can dump frames in the EE and return. */ thread.attr=thread.option=0; - if((NETMAN_Tx_threadID=CreateThread(&thread)) < 0) + if((NETMAN_Tx_threadID=CreateThread(&thread)) <= 0) { + NETMAN_Tx_threadID = 0; deinitCleanup(); return NETMAN_Tx_threadID; } diff --git a/ee/network/netman/src/rpc_server.c b/ee/network/netman/src/rpc_server.c index d3f5113d1ce9..4a27fa2c7bc1 100644 --- a/ee/network/netman/src/rpc_server.c +++ b/ee/network/netman/src/rpc_server.c @@ -11,7 +11,7 @@ #include "internal.h" #include "rpc_server.h" -static int NETMAN_RpcSvr_threadID=-1, NETMAN_Rx_threadID=-1, SifHandlerID=-1; +static int NETMAN_RpcSvr_threadID, NETMAN_Rx_threadID, SifHandlerID; static unsigned char NETMAN_RpcSvr_ThreadStack[0x1000] ALIGNED(16); static unsigned char NETMAN_Rx_ThreadStack[0x1000] ALIGNED(16); static unsigned char IsInitialized=0, IsProcessingRx; @@ -114,7 +114,7 @@ static void *NETMAN_EE_RPC_Handler(int fnum, void *buffer, int NumBytes) thread.initial_priority=0x59; /* Should be given a lower priority than the protocol stack, so that the protocol stack can process incoming frames. */ thread.attr=thread.option=0; - if((NETMAN_Rx_threadID=CreateThread(&thread)) >= 0) + if((NETMAN_Rx_threadID=CreateThread(&thread)) > 0) { StartThread(NETMAN_Rx_threadID, NULL); @@ -230,7 +230,7 @@ int NetManInitRPCServer(void) ThreadData.initial_priority=0x57; /* The RPC server thread should be given a higher priority than the protocol stack, so that it can issue commants to the EE and return. */ ThreadData.attr=ThreadData.option=0; - if((NETMAN_RpcSvr_threadID=CreateThread(&ThreadData))>=0) + if((NETMAN_RpcSvr_threadID=CreateThread(&ThreadData))>0) { StartThread(NETMAN_RpcSvr_threadID, NULL); IsInitialized=1; @@ -251,18 +251,18 @@ void NetManDeinitRPCServer(void) sceSifRemoveRpcQueue(&cb_queue); RemoveDmacHandler(DMAC_SIF0, SifHandlerID); - if(NETMAN_RpcSvr_threadID>=0) + if(NETMAN_RpcSvr_threadID>0) { TerminateThread(NETMAN_RpcSvr_threadID); DeleteThread(NETMAN_RpcSvr_threadID); - NETMAN_RpcSvr_threadID = -1; + NETMAN_RpcSvr_threadID = 0; } - if(NETMAN_Rx_threadID>=0) + if(NETMAN_Rx_threadID>0) { TerminateThread(NETMAN_Rx_threadID); DeleteThread(NETMAN_Rx_threadID); - NETMAN_Rx_threadID = -1; + NETMAN_Rx_threadID = 0; } IsInitialized=0; diff --git a/ee/network/tcpip/src/ps2ip.c b/ee/network/tcpip/src/ps2ip.c index e1e7682da40f..dd16fd45ac89 100644 --- a/ee/network/tcpip/src/ps2ip.c +++ b/ee/network/tcpip/src/ps2ip.c @@ -36,8 +36,6 @@ typedef struct ip4_addr IPAddr; static struct netif NIF; static struct pbuf *TxHead, *TxTail; -unsigned short int hsyncTicksPerMSec = 16; - int ps2ip_getconfig(char* pszName, t_ip_info* pInfo) { NetIF* pNetIF=netif_find(pszName); @@ -321,7 +319,7 @@ extern void _ps2sdk_ps2ipee_init(void); extern void _ps2sdk_ps2ipee_deinit(void); int ps2ipInit(struct ip4_addr *ip_address, struct ip4_addr *subnet_mask, struct ip4_addr *gateway){ - static struct NetManNetProtStack stack={ + static const struct NetManNetProtStack stack={ &LinkStateUp, &LinkStateDown, &AllocRxPacket, diff --git a/ee/network/tcpip/src/sys_arch.c b/ee/network/tcpip/src/sys_arch.c index 5f7bdae2fc88..7be61aa79d46 100644 --- a/ee/network/tcpip/src/sys_arch.c +++ b/ee/network/tcpip/src/sys_arch.c @@ -436,9 +436,9 @@ void sys_sem_set_invalid(sys_sem_t *sem){ * track the owning thread + a recursion counter and only Wait/Signal * on the outermost transitions. */ -static int s_protect_sem = -1; +static int s_protect_sem; static int s_protect_count = 0; -static int s_protect_owner = -1; +static int s_protect_owner; sys_prot_t sys_arch_protect(void) { @@ -466,7 +466,7 @@ void sys_arch_unprotect(sys_prot_t level) return; } s_protect_count = 0; - s_protect_owner = -1; + s_protect_owner = 0; SignalSema(s_protect_sem); } @@ -490,7 +490,7 @@ void sys_init(void) sema.max_count = 1; s_protect_sem = CreateSema(&sema); s_protect_count = 0; - s_protect_owner = -1; + s_protect_owner = 0; free_head = &msg_pool[0]; prev = &msg_pool[0]; diff --git a/ee/rpc/cdvd/src/libcdvd.c b/ee/rpc/cdvd/src/libcdvd.c index 7ae6e9b39d3e..1b53d2afbfda 100644 --- a/ee/rpc/cdvd/src/libcdvd.c +++ b/ee/rpc/cdvd/src/libcdvd.c @@ -79,7 +79,7 @@ int CdDebug = 0; // semaphore ids /** callback semaphore id */ -int callbackSemaId = -1; +int callbackSemaId; /** callback semaphore variable (not a real semaphore) */ volatile int cbSema = 0; @@ -158,9 +158,9 @@ s32 sceCdInit(s32 mode) if (CdDebug > 0) printf("Libcdvd Exit\n"); _CdSemaExit(); - nCmdSemaId = -1; - sCmdSemaId = -1; - callbackSemaId = -1; + nCmdSemaId = 0; + sCmdSemaId = 0; + callbackSemaId = 0; } else { _CdSemaInit(); } @@ -293,17 +293,23 @@ void _CdSemaInit(void) struct t_ee_sema semaParam; // return if both semaphores are already inited - if (nCmdSemaId != -1 && sCmdSemaId != -1) + if (nCmdSemaId != 0 && sCmdSemaId != 0) return; semaParam.init_count = 1; semaParam.max_count = 1; semaParam.option = 0; nCmdSemaId = CreateSema(&semaParam); + if (nCmdSemaId < 0) + nCmdSemaId = 0; sCmdSemaId = CreateSema(&semaParam); + if (sCmdSemaId < 0) + sCmdSemaId = 0; semaParam.init_count = 0; callbackSemaId = CreateSema(&semaParam); + if (callbackSemaId < 0) + callbackSemaId = 0; cbSema = 0; } diff --git a/ee/rpc/cdvd/src/ncmd.c b/ee/rpc/cdvd/src/ncmd.c index c8d72faa4716..8c667683c8c8 100644 --- a/ee/rpc/cdvd/src/ncmd.c +++ b/ee/rpc/cdvd/src/ncmd.c @@ -81,7 +81,7 @@ typedef union SifRpcClientData_t clientNCmd __attribute__((aligned(64))); /** n-cmd semaphore id */ -int nCmdSemaId = -1; +int nCmdSemaId; int nCmdNum = 0; diff --git a/ee/rpc/cdvd/src/scmd.c b/ee/rpc/cdvd/src/scmd.c index 3c1269fb6463..e7b538460db5 100644 --- a/ee/rpc/cdvd/src/scmd.c +++ b/ee/rpc/cdvd/src/scmd.c @@ -90,7 +90,7 @@ typedef union #ifdef F__scmd_internals SifRpcClientData_t clientSCmd __attribute__((aligned(64))); -int sCmdSemaId = -1; +int sCmdSemaId; u8 sCmdRecvBuff[0x440] __attribute__((aligned(64))); sCmdSendParams_t sCmdSendBuff __attribute__((aligned(64))); diff --git a/ee/rpc/filexio/src/fileXio_rpc.c b/ee/rpc/filexio/src/fileXio_rpc.c index cdeb9b314e86..1aa2e6885441 100644 --- a/ee/rpc/filexio/src/fileXio_rpc.c +++ b/ee/rpc/filexio/src/fileXio_rpc.c @@ -57,13 +57,13 @@ extern int __fileXioBlockMode; #endif #ifdef F___fileXioCompletionSema -int __fileXioCompletionSema = -1; +int __fileXioCompletionSema; #else extern int __fileXioCompletionSema; #endif #ifdef F___lock_sema_id -int __lock_sema_id = -1; +int __lock_sema_id; #else extern int __lock_sema_id; #endif @@ -101,6 +101,11 @@ int fileXioInit(void) sp.max_count = 1; sp.option = 0; __lock_sema_id = CreateSema(&sp); + if (__lock_sema_id < 0) + { + __lock_sema_id = 0; + return -1; + } while(((res = sceSifBindRpc(&__cd0, FILEXIO_IRX, 0)) >= 0) && (__cd0.server == NULL)) nopdelay(); @@ -113,7 +118,10 @@ int fileXioInit(void) sp.option = 0; __fileXioCompletionSema = CreateSema(&sp); if (__fileXioCompletionSema < 0) + { + __fileXioCompletionSema = 0; return -1; + } __fileXioBlockMode = FXIO_WAIT; @@ -128,8 +136,16 @@ void fileXioExit(void) { if(__cd0.server) { - if(__lock_sema_id >= 0) DeleteSema(__lock_sema_id); - if(__fileXioCompletionSema >= 0) DeleteSema(__fileXioCompletionSema); + if (__lock_sema_id > 0) + { + DeleteSema(__lock_sema_id); + __lock_sema_id = 0; + } + if (__fileXioCompletionSema > 0) + { + DeleteSema(__fileXioCompletionSema); + __fileXioCompletionSema = 0; + } memset(&__cd0, 0, sizeof(__cd0)); diff --git a/ee/rpc/hdd/src/libhdd.c b/ee/rpc/hdd/src/libhdd.c index f947f0c006ba..13357f18ccf7 100644 --- a/ee/rpc/hdd/src/libhdd.c +++ b/ee/rpc/hdd/src/libhdd.c @@ -35,9 +35,9 @@ #define PFS_FRAGMENT 0x00000000 #if (PFS_FRAGMENT != 0) -int pfsFormatArg[3] = { PFS_ZONE_SIZE, PFS_FRAGMENT_OPT, PFS_FRAGMENT }; +static const int pfsFormatArg[3] = { PFS_ZONE_SIZE, PFS_FRAGMENT_OPT, PFS_FRAGMENT }; #else -static int pfsFormatArg[1] = { PFS_ZONE_SIZE }; +static const int pfsFormatArg[1] = { PFS_ZONE_SIZE }; #endif #define _OMIT_SYSTEM_PARTITION diff --git a/ee/rpc/keyboard/src/libkbd.c b/ee/rpc/keyboard/src/libkbd.c index 3cdf0d864ccd..6cc4a5be9059 100644 --- a/ee/rpc/keyboard/src/libkbd.c +++ b/ee/rpc/keyboard/src/libkbd.c @@ -20,16 +20,16 @@ #include #include "libkbd.h" -static int kbd_fd = -1; -static int curr_blockmode = PS2KBD_NONBLOCKING; -static int curr_readmode = PS2KBD_READMODE_NORMAL; +static int kbd_fd; +static int curr_blockmode; +static int curr_readmode; int PS2KbdInit(void) { if (HasIopRebootedSinceLastCall()) kbd_fd = -1; - if(kbd_fd >= 0) /* Already initialised */ + if(kbd_fd > 0) /* Already initialised */ { return 2; } @@ -39,6 +39,8 @@ int PS2KbdInit(void) { return 0; } + curr_blockmode = PS2KBD_NONBLOCKING; + curr_readmode = PS2KBD_READMODE_NORMAL; return 1; } diff --git a/ee/rpc/poweroff/src/poweroff.c b/ee/rpc/poweroff/src/poweroff.c index d112f68a0dbb..0a234656b8e5 100644 --- a/ee/rpc/poweroff/src/poweroff.c +++ b/ee/rpc/poweroff/src/poweroff.c @@ -29,7 +29,7 @@ static u8 poffThreadStack[512 * 16] __attribute__((aligned(16))); static SifRpcClientData_t cd0; static struct t_SifRpcDataQueue cb_queue; static struct t_SifRpcServerData cb_srv; -static int powerOffThreadId = -1; +static int powerOffThreadId; static void *PowerOff_ee_rpc_handler(int fnum, void *buffer, int len) { @@ -76,13 +76,13 @@ int poweroffInit(void) nopdelay(); // Terminate and delete any previously created threads - if (powerOffThreadId >= 0) + if (powerOffThreadId > 0) { TerminateThread(powerOffThreadId); DeleteThread(powerOffThreadId); sceSifRemoveRpc(&cb_srv, &cb_queue); sceSifRemoveRpcQueue(&cb_queue); - powerOffThreadId = -1; + powerOffThreadId = 0; } thread.initial_priority = POWEROFF_THREAD_PRIORITY; diff --git a/ee/rpc/tcpips/src/ps2ipc.c b/ee/rpc/tcpips/src/ps2ipc.c index a722ad0122ab..d51b9b25ce3b 100644 --- a/ee/rpc/tcpips/src/ps2ipc.c +++ b/ee/rpc/tcpips/src/ps2ipc.c @@ -22,7 +22,7 @@ #include #include -static int lock_sema = -1; +static int lock_sema; static SifRpcClientData_t _ps2ip; static struct { union { @@ -96,9 +96,9 @@ void ps2ip_deinit(void) { _ps2sdk_ps2ipc_deinit(); - if (lock_sema >= 0) + if (lock_sema > 0) DeleteSema(lock_sema); - lock_sema = -1; + lock_sema = 0; memset(&_ps2ip, 0, sizeof(_ps2ip)); } diff --git a/ee/sbv/src/patch_disable_prefix_check.c b/ee/sbv/src/patch_disable_prefix_check.c index 857b4c7f6516..a7fd43b84ede 100644 --- a/ee/sbv/src/patch_disable_prefix_check.c +++ b/ee/sbv/src/patch_disable_prefix_check.c @@ -21,19 +21,22 @@ extern slib_exp_lib_list_t _slib_cur_exp_lib_list; +static const u32 g_patch[2] = { + 0x03e00008, /* jr $ra */ + 0x00001021 /* addiu $v0, $0, 0 */ +}; + int sbv_patch_disable_prefix_check(void) { union { u8 buf[256]; slib_exp_lib_t exp_lib; } buf; - static u32 patch[2] ALIGNED(16)={ - 0x03e00008, /* jr $ra */ - 0x00001021 /* addiu $v0, $0, 0 */ - }; + static u32 patch[sizeof(g_patch)/sizeof(g_patch[0])] ALIGNED(16); SifDmaTransfer_t dmat; slib_exp_lib_t *modload_lib = &buf.exp_lib; + memcpy(UNCACHED_SEG(patch), g_patch, sizeof(g_patch)); memset(&_slib_cur_exp_lib_list, 0, sizeof(slib_exp_lib_list_t)); if (!slib_get_exp_lib("modload", modload_lib)) diff --git a/ee/sbv/src/patch_enable_lmb.c b/ee/sbv/src/patch_enable_lmb.c index 60c6dcc728e2..6ff3fd858719 100644 --- a/ee/sbv/src/patch_enable_lmb.c +++ b/ee/sbv/src/patch_enable_lmb.c @@ -35,40 +35,42 @@ extern slib_exp_lib_list_t _slib_cur_exp_lib_list; #define HI16(addr) (0x3c110000 | (((addr) >> 16) & 0xffff)) /* lui $s1, HI(addr) */ #define LO16(addr) (0x36310000 | ((addr) & 0xffff)) /* ori $s1, LO(addr) */ +static const u32 g_lmb_patch[32] = { + 0x27bdffd8, /* addiu $sp, -40 */ + 0xafb00018, /* sw $s0, 0x18($sp) */ + 0xafbf0020, /* sw $ra, 0x20($sp) */ + 0x00808021, /* move $s0, $a0 */ + 0x8c840000, /* lw $a0, 0($a0) */ + 0x0c000000, /* jal [LoadModuleBuffer] */ + 0xafb1001c, /* sw $s1, 0x1c($sp) */ + 0x3c110000, /* lui $s1, [HI16(result)] */ + 0x04400008, /* bltz $v0, 1f */ + 0x36310000, /* ori $s1, [LO16(result)] */ + 0x00402021, /* move $a0, $v0 */ + 0x26250008, /* addiu $a1, $s1, 8 */ + 0x8e060004, /* lw $a2, 4($s0) */ + 0x26070104, /* addiu $a3, $s0, 0x104 */ + 0x26280004, /* addiu $t0, $s1, 4 */ + 0x0c000000, /* jal [StartModule] */ + 0xafa80010, /* sw $t0, 0x10($sp) */ + 0xae220000, /* 1: sw $v0, 0($s1) */ + 0x02201021, /* move $v0, $s1 */ + 0x8fbf0020, /* lw $ra, 0x20($sp) */ + 0x8fb1001c, /* lw $s1, 0x1c($sp) */ + 0x8fb00018, /* lw $s0, 0x18($sp) */ + 0x03e00008, /* jr $ra */ + 0x27bd0028, /* addiu $sp, 40 */ + 0x00000000, 0x00000000, + 0x7962424c, 0x00004545, /* "LBbyEE" */ + 0x00000000, 0x00000000, 0x00000000, 0x00000000 +}; + int sbv_patch_enable_lmb(void) { /* This is the routine called by the loadfile RPC dispatcher for LoadModuleBuffer over RPC (call #6). The bracketed operands are the ones patched by the real locations in IOP memory before being installed onto the IOP. */ - static u32 lmb_patch[32] ALIGNED(64) = { - 0x27bdffd8, /* addiu $sp, -40 */ - 0xafb00018, /* sw $s0, 0x18($sp) */ - 0xafbf0020, /* sw $ra, 0x20($sp) */ - 0x00808021, /* move $s0, $a0 */ - 0x8c840000, /* lw $a0, 0($a0) */ - 0x0c000000, /* jal [LoadModuleBuffer] */ - 0xafb1001c, /* sw $s1, 0x1c($sp) */ - 0x3c110000, /* lui $s1, [HI16(result)] */ - 0x04400008, /* bltz $v0, 1f */ - 0x36310000, /* ori $s1, [LO16(result)] */ - 0x00402021, /* move $a0, $v0 */ - 0x26250008, /* addiu $a1, $s1, 8 */ - 0x8e060004, /* lw $a2, 4($s0) */ - 0x26070104, /* addiu $a3, $s0, 0x104 */ - 0x26280004, /* addiu $t0, $s1, 4 */ - 0x0c000000, /* jal [StartModule] */ - 0xafa80010, /* sw $t0, 0x10($sp) */ - 0xae220000, /* 1: sw $v0, 0($s1) */ - 0x02201021, /* move $v0, $s1 */ - 0x8fbf0020, /* lw $ra, 0x20($sp) */ - 0x8fb1001c, /* lw $s1, 0x1c($sp) */ - 0x8fb00018, /* lw $s0, 0x18($sp) */ - 0x03e00008, /* jr $ra */ - 0x27bd0028, /* addiu $sp, 40 */ - 0x00000000, 0x00000000, - 0x7962424c, 0x00004545, /* "LBbyEE" */ - 0x00000000, 0x00000000, 0x00000000, 0x00000000 - }; + static u32 lmb_patch[sizeof(g_lmb_patch)] ALIGNED(16); u8 buf[256]; SifRpcReceiveData_t RData; slib_exp_lib_t *modload_lib = (slib_exp_lib_t *)buf; @@ -77,6 +79,7 @@ int sbv_patch_enable_lmb(void) u32 result, *data; SifDmaTransfer_t dmat; + memcpy(UNCACHED_SEG(lmb_patch), g_lmb_patch, sizeof(g_lmb_patch)); memset(&_slib_cur_exp_lib_list, 0, sizeof(slib_exp_lib_list_t)); /* Locate the modload export library - it must have at least 16 exports. */ @@ -132,12 +135,10 @@ int sbv_patch_enable_lmb(void) /* result is where the RPC return structure is stored. */ result = (u32)patch_addr + 96; - lmb_patch[5] = JAL((u32)pLoadModuleBuffer); - lmb_patch[7] = HI16(result); - lmb_patch[9] = LO16(result); - lmb_patch[15] = JAL((u32)pStartModule); - - SyncDCache(lmb_patch, (void *)(lmb_patch + 24)); + ((u32 *)(UNCACHED_SEG(lmb_patch)))[5] = JAL((u32)pLoadModuleBuffer); + ((u32 *)(UNCACHED_SEG(lmb_patch)))[7] = HI16(result); + ((u32 *)(UNCACHED_SEG(lmb_patch)))[9] = LO16(result); + ((u32 *)(UNCACHED_SEG(lmb_patch)))[15] = JAL((u32)pStartModule); dmat.src=lmb_patch; dmat.size=sizeof(lmb_patch); diff --git a/ee/sbv/src/patch_fileio.c b/ee/sbv/src/patch_fileio.c index 6f5287c6fc06..647bf32efd50 100644 --- a/ee/sbv/src/patch_fileio.c +++ b/ee/sbv/src/patch_fileio.c @@ -12,6 +12,31 @@ #define JMP(addr) (0x08000000|(0x3ffffff&((addr)>>2))) #define JAL(addr) (0x0c000000 | (0x3ffffff & ((addr) >> 2))) +static const u32 g_new_fileio[20] = { + //sceFioRemove fix + 0x0c0001ce, // jal +0x738 <- jal fio_remove + 0x00000000, // nop + 0x0800033a, // j +0xce8 <- j rpc_handler_exit + 0x00000000, // nop + //sceFioGetstat()/sceFioDread() fix + 0x27bdfff0, // addiu sp,sp,-16 + 0xafbf0000, // sw ra,0(sp) + 0xafa40004, // sw a0,4(sp) + 0xafa50008, // sw a1,8(sp) + 0x0c000423, // jal +0x108c <- jal CpuSuspendIntr + 0x27a4000c, // addiu a0,sp,12 + 0x8fa40004, // lw a0,4(sp) + 0x0c000430, // jal +0x10c0 <- jal sceSifSetDma + 0x8fa50008, // lw a1,8(sp) + 0x8fa4000c, // lw a0,12(sp) + 0x0c000425, // jal +0x1094 <- jal CpuResumeIntr + 0xafa20004, // sw v0,4(sp) + 0x8fbf0000, // lw ra,0(sp) + 0x8fa20004, // lw v0,4(sp) + 0x03e00008, // jr ra + 0x27bd0010, // addiu sp,sp,16 +}; + int sbv_patch_fileio(void) { /* This patch is a fix for FILEIO on the IOP: @@ -28,34 +53,12 @@ int sbv_patch_fileio(void) smod_mod_info_t mod_info; SifDmaTransfer_t dmat; - static u32 new_fileio[20] ALIGNED(16)={ - //sceFioRemove fix - 0x0c0001ce, // jal +0x738 <- jal fio_remove - 0x00000000, // nop - 0x0800033a, // j +0xce8 <- j rpc_handler_exit - 0x00000000, // nop - //sceFioGetstat()/sceFioDread() fix - 0x27bdfff0, // addiu sp,sp,-16 - 0xafbf0000, // sw ra,0(sp) - 0xafa40004, // sw a0,4(sp) - 0xafa50008, // sw a1,8(sp) - 0x0c000423, // jal +0x108c <- jal CpuSuspendIntr - 0x27a4000c, // addiu a0,sp,12 - 0x8fa40004, // lw a0,4(sp) - 0x0c000430, // jal +0x10c0 <- jal sceSifSetDma - 0x8fa50008, // lw a1,8(sp) - 0x8fa4000c, // lw a0,12(sp) - 0x0c000425, // jal +0x1094 <- jal CpuResumeIntr - 0xafa20004, // sw v0,4(sp) - 0x8fbf0000, // lw ra,0(sp) - 0x8fa20004, // lw v0,4(sp) - 0x03e00008, // jr ra - 0x27bd0010, // addiu sp,sp,16 - }; + static u32 new_fileio[sizeof(g_new_fileio)/sizeof(g_new_fileio[0])] ALIGNED(16); u32 *p_new_fileio; u32 new_jump_op; void *patch_addr; + memcpy(UNCACHED_SEG(new_fileio), g_new_fileio, sizeof(g_new_fileio)); memset(&mod_info, 0, sizeof(mod_info)); int ret = smod_get_mod_by_name("FILEIO_service", &mod_info); if ((!ret) || (mod_info.version != 0x101))