From dc4b29ac0c713182bacd71c0fcb77188d3b50081 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 15 May 2026 07:12:34 -0500 Subject: [PATCH 1/4] cleanup: make asm block declarations consistent --- common/sbus/src/ps2_sbus.c | 2 +- ee/debug/src/screenshot.c | 6 +++--- ee/dma/src/dma.c | 2 +- ee/elf-loader/src/elf.c | 2 +- ee/elf-loader/src/loader/src/loader.c | 2 +- ee/graph/src/graph_mode.c | 8 +++---- ee/kernel/include/kernel.h | 18 ++++++++-------- ee/kernel/src/glue.c | 30 +++++++++++++-------------- ee/kernel/src/timer.c | 2 +- ee/kernel/src/tlbfunc.c | 4 ++-- ee/kernel/src/tlbsrc/src/tlbsrc.c | 16 +++++++------- ee/libgs/src/dma.c | 6 +++--- ee/libgs/src/lowlevel.c | 2 +- ee/libvux/src/vuhw.c | 16 +++++++------- ee/math3d/src/math3d.c | 16 +++++++------- ee/mpeg/src/libmpeg_core.c | 4 ++-- ee/startup/src/crt0.c | 2 +- iop/cdvd/cdvdman/src/cdvdman.c | 2 +- iop/sound/ahx/src/spu2.c | 2 +- iop/sound/libsd/src/freesd.c | 2 +- iop/system/excepman/src/excepman.c | 4 ++-- iop/system/igreeting/src/igreeting.c | 2 +- iop/system/intrman/src/intrman.c | 2 +- iop/system/modload/src/modload.c | 2 +- iop/system/sifman/src/sifman.c | 2 +- iop/system/threadman/src/thbase.c | 2 +- iop/system/threadman/src/thcommon.c | 6 +++--- iop/system/timrman/src/timrman.c | 2 +- iop/system/udnl/src/udnl.c | 2 +- 29 files changed, 84 insertions(+), 84 deletions(-) diff --git a/common/sbus/src/ps2_sbus.c b/common/sbus/src/ps2_sbus.c index edf52c3804ea..e732567978e1 100644 --- a/common/sbus/src/ps2_sbus.c +++ b/common/sbus/src/ps2_sbus.c @@ -26,7 +26,7 @@ static u32 _get_reg(u32 *reg) #ifdef _EE // EE needs 20 NOPs! - __asm__ volatile("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"); + __asm__ __volatile__("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n"); #endif v2 = *(vu32 *)reg; diff --git a/ee/debug/src/screenshot.c b/ee/debug/src/screenshot.c index 5af289e3ad94..70c1f43e666e 100644 --- a/ee/debug/src/screenshot.c +++ b/ee/debug/src/screenshot.c @@ -250,7 +250,7 @@ int ps2_screenshot( void *pDest, unsigned int VramAdress, unsigned int x, *PS2SS_D1_MADR = (u32)p_dma32; *PS2SS_D1_CHCR = 0x101; - asm __volatile__("sync.l\n"); + __asm__ __volatile__("sync.l\n"); // check if DMA is complete (STR=0) @@ -272,13 +272,13 @@ int ps2_screenshot( void *pDest, unsigned int VramAdress, unsigned int x, *PS2SS_D1_MADR = (u32)pDest; *PS2SS_D1_CHCR = 0x100; - asm __volatile__(" sync.l\n"); + __asm__ __volatile__(" sync.l\n"); // check if DMA is complete (STR=0) while ( *PS2SS_D1_CHCR & 0x0100 ); *PS2SS_D1_CHCR = prev_chcr; - asm __volatile__(" sync.l\n"); + __asm__ __volatile__(" sync.l\n"); *PS2SS_VIF1_STAT = 0; *PS2SS_GS_BUSDIR = (u64)0; diff --git a/ee/dma/src/dma.c b/ee/dma/src/dma.c index 1ba0c191e214..fa6637e2d75f 100644 --- a/ee/dma/src/dma.c +++ b/ee/dma/src/dma.c @@ -115,7 +115,7 @@ void dma_channel_fast_waits(int channel) void dma_wait_fast(void) { - asm volatile ( + __asm__ __volatile__ ( "sync.l; sync.p;" \ "0:" \ "bc0t 0f; nop;" \ diff --git a/ee/elf-loader/src/elf.c b/ee/elf-loader/src/elf.c index a24439e52351..630b73e79d50 100644 --- a/ee/elf-loader/src/elf.c +++ b/ee/elf-loader/src/elf.c @@ -42,7 +42,7 @@ MEMORY { static void wipe_bramMem(void) { int i; for (i = 0x00084000; i < 0x100000; i += 64) { - asm volatile( + __asm__ __volatile__( "\tsq $0, 0(%0) \n" "\tsq $0, 16(%0) \n" "\tsq $0, 32(%0) \n" diff --git a/ee/elf-loader/src/loader/src/loader.c b/ee/elf-loader/src/loader/src/loader.c index 79355dc43baa..6ea68d3d5670 100644 --- a/ee/elf-loader/src/loader/src/loader.c +++ b/ee/elf-loader/src/loader/src/loader.c @@ -62,7 +62,7 @@ static void wipeUserMem(void) { int i; for (i = 0x100000; i < GetMemorySize(); i += 64) { - asm volatile( + __asm__ __volatile__( "\tsq $0, 0(%0) \n" "\tsq $0, 16(%0) \n" "\tsq $0, 32(%0) \n" diff --git a/ee/graph/src/graph_mode.c b/ee/graph/src/graph_mode.c index cd53c4dddd08..126eb309d5e9 100644 --- a/ee/graph/src/graph_mode.c +++ b/ee/graph/src/graph_mode.c @@ -94,7 +94,7 @@ static inline int __udelay(unsigned int usecs) } - asm volatile ( + __asm__ __volatile__ ( ".set push\n\t" ".set noreorder\n\t" "0:\n\t" @@ -141,7 +141,7 @@ int graph_set_mode(int interlace, int mode, int ffmd, int flicker_filter) GsPutIMR(0x00007700); // Ensure registers are written prior to setting another mode. - asm volatile ("sync.p\n\t" + __asm__ __volatile__ ("sync.p\n\t" "nop\n\t"); // If 576P is requested, check if bios supports it. @@ -376,7 +376,7 @@ void graph_set_smode1(char cmod, char gcont) // Disable PRST for TV modes and enable for all other modes. *GS_REG_SMODE1 = smode1_val | (u64)1 << 16; - asm volatile ("sync.l; sync.p;"); + __asm__ __volatile__ ("sync.l; sync.p;"); // If VESA, 1080I, or 720P, disable bit PRST now and delay 2.5ms. if ((graph_crtmode >= 0x1A) && (graph_crtmode != 0x50) && (graph_crtmode != 0x53)) @@ -393,7 +393,7 @@ void graph_set_smode1(char cmod, char gcont) // Now enable read circuits. *GS_REG_PMODE = pmode_val; - asm volatile ("sync.l; sync.p;"); + __asm__ __volatile__ ("sync.l; sync.p;"); } diff --git a/ee/kernel/include/kernel.h b/ee/kernel/include/kernel.h index 9e2d70661cae..7c8766857300 100644 --- a/ee/kernel/include/kernel.h +++ b/ee/kernel/include/kernel.h @@ -25,12 +25,12 @@ #define EI EIntr // Workaround for EE kernel bug: call this immediately before returning from any interrupt handler. -#define ExitHandler() asm volatile("sync\nei\n") +#define ExitHandler() __asm__ __volatile__("sync\nei\n") // note: 'sync' is the same as 'sync.l' -#define EE_SYNC() __asm__ volatile("sync") -#define EE_SYNCL() __asm__ volatile("sync.l") -#define EE_SYNCP() __asm__ volatile("sync.p") +#define EE_SYNC() __asm__ __volatile__("sync") +#define EE_SYNCL() __asm__ __volatile__("sync.l") +#define EE_SYNCP() __asm__ __volatile__("sync.p") #define UNCACHED_SEG(x) \ ((void *)(((u32)(x)) | 0x20000000)) @@ -143,7 +143,7 @@ static inline void nopdelay(void) int i = 0xfffff; do { - __asm__("nop\nnop\nnop\nnop\nnop\n"); + __asm__ __volatile__("nop\nnop\nnop\nnop\nnop\n"); } while (i-- != -1); } @@ -151,7 +151,7 @@ static inline int ee_get_opmode(void) { u32 status; - __asm__ volatile( + __asm__ __volatile__( ".set\tpush\n\t" ".set\tnoreorder\n\t" "mfc0\t%0, $12\n\t" @@ -165,7 +165,7 @@ static inline int ee_set_opmode(u32 opmode) { u32 status, mask; - __asm__ volatile( + __asm__ __volatile__( ".set\tpush\n\t" ".set\tnoreorder\n\t" "mfc0\t%0, $12\n\t" @@ -185,7 +185,7 @@ static inline int ee_kmode_enter() { u32 status, mask; - __asm__ volatile( + __asm__ __volatile__( ".set\tpush\n\t" ".set\tnoreorder\n\t" "mfc0\t%0, $12\n\t" @@ -203,7 +203,7 @@ static inline int ee_kmode_exit() { int status; - __asm__ volatile( + __asm__ __volatile__( ".set\tpush\n\t" ".set\tnoreorder\n\t" "mfc0\t%0, $12\n\t" diff --git a/ee/kernel/src/glue.c b/ee/kernel/src/glue.c index 56f983077c05..051d8614a002 100644 --- a/ee/kernel/src/glue.c +++ b/ee/kernel/src/glue.c @@ -20,7 +20,7 @@ int DIntr() { int eie, res; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; res = eie != 0; @@ -28,11 +28,11 @@ int DIntr() if (!eie) return 0; - asm(".p2align 3"); + __asm__ (".p2align 3"); do { - asm volatile("di"); - asm volatile("sync.p"); - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("di"); + __asm__ __volatile__("sync.p"); + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; } while (eie); @@ -46,10 +46,10 @@ int EIntr() { int eie; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; - asm volatile("ei"); + __asm__ __volatile__("ei"); return eie != 0; } @@ -60,7 +60,7 @@ int EnableIntc(int intc) { int eie, res; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; @@ -82,7 +82,7 @@ int DisableIntc(int intc) { int eie, res; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; @@ -104,7 +104,7 @@ int EnableDmac(int dmac) { int eie, res; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; @@ -126,7 +126,7 @@ int DisableDmac(int dmac) { int eie, res; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; @@ -148,7 +148,7 @@ int SetAlarm(u16 time, void (*callback)(s32 alarm_id, u16 time, void *common), v { int eie, res; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; @@ -170,7 +170,7 @@ int ReleaseAlarm(int alarm_id) { int eie, res; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; @@ -252,7 +252,7 @@ void SyncDCache(void *start, void *end) { int eie; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; @@ -278,7 +278,7 @@ void InvalidDCache(void *start, void *end) { int eie; - asm volatile("mfc0\t%0, $12" + __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; diff --git a/ee/kernel/src/timer.c b/ee/kernel/src/timer.c index c4e7e003fc85..7e1298e3de41 100644 --- a/ee/kernel/src/timer.c +++ b/ee/kernel/src/timer.c @@ -956,7 +956,7 @@ u32 cpu_ticks(void) { u32 out; - asm("mfc0\t%0, $9\n" + __asm__ __volatile__("mfc0\t%0, $9\n" : "=r"(out)); return out; } diff --git a/ee/kernel/src/tlbfunc.c b/ee/kernel/src/tlbfunc.c index 891183812c80..f6c554995b66 100644 --- a/ee/kernel/src/tlbfunc.c +++ b/ee/kernel/src/tlbfunc.c @@ -149,7 +149,7 @@ static int InitTLB32MB(void) kprintf("# TLB spad=0 kernel=1:%d default=%d:%d extended=%d:%d\n", TLBInfo.NumKernelTLBEntries - 1, TLBInfo.NumKernelTLBEntries, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries - 1, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries + TLBInfo.NumExtendedTLBEntries - 1); - __asm volatile("mtc0 $zero, $6\n" + __asm__ __volatile__("mtc0 $zero, $6\n" "sync.p\n"); if (TLBInfo.NumKernelTLBEntries >= 0x31) { @@ -171,7 +171,7 @@ static int InitTLB32MB(void) } TLBInfo.NumWiredEntries = NumTlbEntries = i; - __asm volatile("mtc0 %0, $6\n" + __asm__ __volatile__("mtc0 %0, $6\n" "sync.p\n" ::"r"(NumTlbEntries)); if (TLBInfo.NumExtendedTLBEntries > 0) { diff --git a/ee/kernel/src/tlbsrc/src/tlbsrc.c b/ee/kernel/src/tlbsrc/src/tlbsrc.c index 5ce899866bed..1441ec5775c6 100644 --- a/ee/kernel/src/tlbsrc/src/tlbsrc.c +++ b/ee/kernel/src/tlbsrc/src/tlbsrc.c @@ -69,7 +69,7 @@ int PutTLBEntry(unsigned int PageMask, unsigned int EntryHi, unsigned int EntryL case 0x30: case 0x20: case 0x00: - __asm volatile("mtc0 %1, $5\n" + __asm__ __volatile__("mtc0 %1, $5\n" "mtc0 %2, $10\n" "mtc0 %3, $2\n" "mtc0 %4, $3\n" @@ -97,7 +97,7 @@ int SetTLBEntry(unsigned int index, unsigned int PageMask, unsigned int EntryHi, int result; if (index < 0x30) { - __asm volatile("mtc0 %0, $0\n" + __asm__ __volatile__("mtc0 %0, $0\n" "mtc0 %1, $5\n" "mtc0 %2, $10\n" "mtc0 %3, $2\n" @@ -120,7 +120,7 @@ int GetTLBEntry(unsigned int index, unsigned int *PageMask, unsigned int *EntryH int result; if (index < 0x30) { - __asm volatile("mtc0 %0, $0\n" + __asm__ __volatile__("mtc0 %0, $0\n" "sync.p\n" "tlbr\n" "sync.p\n" @@ -146,7 +146,7 @@ int ProbeTLBEntry(unsigned int EntryHi, unsigned int *PageMask, unsigned int *En { int result, index; - __asm volatile("mtc0 %1, $10\n" + __asm__ __volatile__("mtc0 %1, $10\n" "sync.p\n" "tlbp\n" "sync.p\n" @@ -155,7 +155,7 @@ int ProbeTLBEntry(unsigned int EntryHi, unsigned int *PageMask, unsigned int *En : "r"(EntryHi)); if (index >= 0) { - __asm volatile("tlbr\n" + __asm__ __volatile__("tlbr\n" "sync.p\n" "mfc0 $v0, $5\n" "sw $v0, (%0)\n" @@ -187,7 +187,7 @@ int ExpandScratchPad(unsigned int page) if (page == 0) { EntryHi = 0xE0010000 + ((index - 1) << 13); - __asm volatile("mfc0 $v0, $6\n" + __asm__ __volatile__("mfc0 $v0, $6\n" "addiu $v0, $v0, 0xFFFF\n" "mtc0 $v0, $6\n" "mtc0 %0, $0\n" @@ -202,7 +202,7 @@ int ExpandScratchPad(unsigned int page) } else #endif { - __asm volatile("mfc0 %0, $6\n" + __asm__ __volatile__("mfc0 %0, $6\n" "addiu $v0, %0, 1\n" "mtc0 $v0, $6\n" ::"r"(index)); } @@ -219,7 +219,7 @@ int ExpandScratchPad(unsigned int page) EntryLo0 = ((page + 0x1000) & 0xFFFFF000) >> 6 | 0x1F; EntryLo1 = (page & 0xFFFFF000) >> 6 | 0x1F; - __asm volatile("mtc0 %0, $0\n" + __asm__ __volatile__("mtc0 %0, $0\n" "daddu $v1, $zero, $zero\n" "mtc0 $v1, $5\n" "mtc0 %1, $10\n" diff --git a/ee/libgs/src/dma.c b/ee/libgs/src/dma.c index 525635da307f..9ac90d923919 100644 --- a/ee/libgs/src/dma.c +++ b/ee/libgs/src/dma.c @@ -106,7 +106,7 @@ void GsDmaSend(const void *addr, u32 qwords) // This prevents the compiler from assuming the values in addr are unused, // and that the writes to addr can be delayed until after this function call - asm("":::"memory"); + __asm__ ("":::"memory"); *((volatile DMA_CHCR *)(gif_chcr)) = chcr; } @@ -141,7 +141,7 @@ void GsDmaSend_tag(const void *addr, u32 qwords, const GS_GIF_DMACHAIN_TAG *tag) // This prevents the compiler from assuming the values in addr are unused, // and that the writes to addr can be delayed until after this function call - asm("":::"memory"); + __asm__ ("":::"memory"); *((volatile DMA_CHCR *)(gif_chcr)) = chcr; } @@ -149,5 +149,5 @@ void GsDmaSend_tag(const void *addr, u32 qwords, const GS_GIF_DMACHAIN_TAG *tag) void GsDmaWait(void) { while(*R_EE_D2_CHCR & ((u32)1<<8)); - asm("":::"memory"); + __asm__ ("":::"memory"); } diff --git a/ee/libgs/src/lowlevel.c b/ee/libgs/src/lowlevel.c index fda1e5b1c5d5..8946a5066d1a 100644 --- a/ee/libgs/src/lowlevel.c +++ b/ee/libgs/src/lowlevel.c @@ -23,7 +23,7 @@ static s8 twh(s16 val) { s8 res; - asm volatile ("plzcw %0, %1\n": "=r" (res) : "r" (val)); + __asm__ __volatile__ ("plzcw %0, %1\n": "=r" (res) : "r" (val)); res = 31 - (res + 1); if(val > res) res++; diff --git a/ee/libvux/src/vuhw.c b/ee/libvux/src/vuhw.c index 86835c70dd07..689243dd1955 100644 --- a/ee/libvux/src/vuhw.c +++ b/ee/libvux/src/vuhw.c @@ -17,7 +17,7 @@ void Vu0IdMatrix(VU_MATRIX *m) void Vu0ResetMatrix(VU_MATRIX *m) { - asm __volatile__( + __asm__ __volatile__( #if __GNUC__ > 3 "vmr32.xyzw $vf18, $vf0 \n" "sqc2 $vf0, 0x30(%0) \n" @@ -61,7 +61,7 @@ void VuxRotMatrix(VU_MATRIX *m, VU_VECTOR *r) void Vu0TransMatrix(VU_MATRIX *m, VU_VECTOR *t) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0(%1) \n" // load 1 qword from 't' to vu's vf1 "sqc2 $vf1, 48(%0) \n" // store vf1 data in 'm' with 48 bytes offset which is m[3][0] @@ -93,7 +93,7 @@ void Vu0TransMatrixXYZ(VU_MATRIX *m,float x, float y, float z) void Vu0ScaleMatrix(VU_MATRIX *m, VU_VECTOR *s) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0(%1) \n" // load 1 qword from 't' to vu's vf1 "lqc2 $vf10, 0(%0) \n" // load m[0][0] @@ -148,7 +148,7 @@ void Vu0ScaleMatrixXYZ(VU_MATRIX *m, float x, float y, float z) void Vu0MulMatrix(VU_MATRIX *m0, VU_MATRIX *m1, VU_MATRIX *out) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%0) \n" "lqc2 $vf2, 0x10(%0) \n" @@ -227,7 +227,7 @@ void Vu0ApplyMatrix(VU_MATRIX *m, VU_VECTOR *v0, VU_VECTOR *out) out->w = m->m[0][3]*v0->x + m->m[1][3]*v0->y + m->m[2][3]*v0->z + m->m[3][3]*v0->w; */ - asm __volatile__( + __asm__ __volatile__( #if __GNUC__ > 3 "lqc2 $vf20, 0x00(%1) \n" "lqc2 $vf16, 0x00(%0) \n" @@ -264,7 +264,7 @@ void Vu0ApplyRotMatrix(VU_MATRIX *m, VU_VECTOR *v0, VU_VECTOR *out) out->z = m->m[0][2]*v0->x + m->m[1][2]*v0->y + m->m[2][2]*v0->z; */ - asm __volatile__( + __asm__ __volatile__( #if __GNUC__ > 3 "lqc2 $vf20, 0x00(%1) \n" "lqc2 $vf16, 0x00(%0) \n" @@ -294,7 +294,7 @@ void Vu0ApplyRotMatrix(VU_MATRIX *m, VU_VECTOR *v0, VU_VECTOR *out) void Vu0CopyMatrix(VU_MATRIX *dest, VU_MATRIX *src) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0(%1) \n" // load 1 qword from ee "lqc2 $vf2, 16(%1) \n" // load 1 qword from ee @@ -327,7 +327,7 @@ float Vu0DotProduct(VU_VECTOR *v0, VU_VECTOR *v1) /* ret = (v0.x*v1.x + v0.y*v1.y + v0.z*v1.z);*/ - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0(%1) \n" // load 1 qword from ee "lqc2 $vf2, 0(%2) \n" // load 1 qword from ee diff --git a/ee/math3d/src/math3d.c b/ee/math3d/src/math3d.c index 3240272a6244..1e8b66e765ba 100644 --- a/ee/math3d/src/math3d.c +++ b/ee/math3d/src/math3d.c @@ -18,7 +18,7 @@ /* VECTOR FUNCTIONS */ void vector_apply(VECTOR output, VECTOR input0, MATRIX input1) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%2) \n" "lqc2 $vf2, 0x10(%2) \n" @@ -71,7 +71,7 @@ } void vector_copy(VECTOR output, VECTOR input0) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%1) \n" "sqc2 $vf1, 0x00(%0) \n" @@ -119,7 +119,7 @@ } void vector_normalize(VECTOR output, VECTOR input0) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%1) \n" "vmul.xyz $vf2, $vf1, $vf1\n" @@ -149,7 +149,7 @@ } void vector_outerproduct(VECTOR output, VECTOR input0, VECTOR input1) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%1) \n" "lqc2 $vf2, 0x00(%2) \n" @@ -205,7 +205,7 @@ void vector_triangle_normal(VECTOR output, VECTOR a, VECTOR b, VECTOR c) { /* MATRIX FUNCTIONS */ void matrix_copy(MATRIX output, MATRIX input0) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%1) \n" "lqc2 $vf2, 0x10(%1) \n" @@ -249,7 +249,7 @@ void vector_triangle_normal(VECTOR output, VECTOR a, VECTOR b, VECTOR c) { } void matrix_multiply(MATRIX output, MATRIX input0, MATRIX input1) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%1) \n" "lqc2 $vf2, 0x10(%1) \n" @@ -476,7 +476,7 @@ void vector_triangle_normal(VECTOR output, VECTOR a, VECTOR b, VECTOR c) { /* CALCULATE FUNCTIONS */ void calculate_normals(VECTOR *output, int count, VECTOR *normals, MATRIX local_light) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%3) \n" "lqc2 $vf2, 0x10(%3) \n" @@ -587,7 +587,7 @@ void vector_triangle_normal(VECTOR output, VECTOR a, VECTOR b, VECTOR c) { } void calculate_vertices(VECTOR *output, int count, VECTOR *vertices, MATRIX local_screen) { - asm __volatile__ ( + __asm__ __volatile__ ( #if __GNUC__ > 3 "lqc2 $vf1, 0x00(%3) \n" "lqc2 $vf2, 0x10(%3) \n" diff --git a/ee/mpeg/src/libmpeg_core.c b/ee/mpeg/src/libmpeg_core.c index 89de2e778f31..8fe566018508 100644 --- a/ee/mpeg/src/libmpeg_core.c +++ b/ee/mpeg/src/libmpeg_core.c @@ -472,7 +472,7 @@ void _MPEG_SetDefQM(int arg0) q = (qword_t *)s_QmIntra; for (i = 0; i < 4; i++) { - __asm__ volatile( + __asm__ __volatile__( "lq $2, 0(%0) \n" "sq $2, 0(%1) \n" : @@ -486,7 +486,7 @@ void _MPEG_SetDefQM(int arg0) q = (qword_t *)s_QmNonIntra; for (i = 0; i < 4; i++) { - __asm__ volatile( + __asm__ __volatile__( "lq $2, 0(%0) \n" "sq $2, 0(%1) \n" : diff --git a/ee/startup/src/crt0.c b/ee/startup/src/crt0.c index 67dc9b15b1b7..cc8430fca8ff 100644 --- a/ee/startup/src/crt0.c +++ b/ee/startup/src/crt0.c @@ -42,7 +42,7 @@ static struct sargs_start *args_start; */ void __start(struct sargs_start *pargs) { - asm volatile( + __asm__ __volatile__( "# Clear bss area \n" ".set noat \n" "la $2, _fbss \n" diff --git a/iop/cdvd/cdvdman/src/cdvdman.c b/iop/cdvd/cdvdman/src/cdvdman.c index 3d52a71987cf..23f9a217b846 100644 --- a/iop/cdvd/cdvdman/src/cdvdman.c +++ b/iop/cdvd/cdvdman/src/cdvdman.c @@ -32,7 +32,7 @@ extern struct irx_export_table _exp_cdvdman; #define _mfc0(reg) \ ({ \ u32 val; \ - __asm__ volatile("mfc0 %0, " #reg : "=r"(val)); \ + __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ val; \ }) diff --git a/iop/sound/ahx/src/spu2.c b/iop/sound/ahx/src/spu2.c index d0b47089e35d..e6def9224479 100644 --- a/iop/sound/ahx/src/spu2.c +++ b/iop/sound/ahx/src/spu2.c @@ -155,7 +155,7 @@ void nopdelay() s32 i; for (i = 0; i < 0x10000; i++) - asm volatile("nop\nnop\nnop\nnop\nnop"); + __asm__ __volatile__("nop\nnop\nnop\nnop\nnop"); } void InitSpu2() diff --git a/iop/sound/libsd/src/freesd.c b/iop/sound/libsd/src/freesd.c index 0d510a91e6ab..d8c3c2b8a5ff 100644 --- a/iop/sound/libsd/src/freesd.c +++ b/iop/sound/libsd/src/freesd.c @@ -107,7 +107,7 @@ void nopdelay() s32 i; for(i=0; i < 0x10000; i++) - asm volatile("nop\nnop\nnop\nnop\nnop"); + __asm__ __volatile__("nop\nnop\nnop\nnop\nnop"); } void InitSpu2() diff --git a/iop/system/excepman/src/excepman.c b/iop/system/excepman/src/excepman.c index c67294a374ce..5eeb81833e3e 100644 --- a/iop/system/excepman/src/excepman.c +++ b/iop/system/excepman/src/excepman.c @@ -228,7 +228,7 @@ static void allocate_list(void) } // clang-format off -__asm__( +__asm__ ( "\t" ".set push" "\n" "\t" ".set noat" "\n" "\t" ".set noreorder" "\n" @@ -289,7 +289,7 @@ __asm__( "\t" ".set pop" "\n" ); -__asm__( +__asm__ ( "\t" ".set push" "\n" "\t" ".set noat" "\n" "\t" ".set noreorder" "\n" diff --git a/iop/system/igreeting/src/igreeting.c b/iop/system/igreeting/src/igreeting.c index c44b6da16761..54650b1f1260 100644 --- a/iop/system/igreeting/src/igreeting.c +++ b/iop/system/igreeting/src/igreeting.c @@ -78,7 +78,7 @@ struct romflash_sigcheck_res #define _mfc0(reg) \ ({ \ u32 val; \ - __asm__ volatile("mfc0 %0, " #reg : "=r"(val)); \ + __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ val; \ }) diff --git a/iop/system/intrman/src/intrman.c b/iop/system/intrman/src/intrman.c index 7db2050bf71a..70ab4391006c 100644 --- a/iop/system/intrman/src/intrman.c +++ b/iop/system/intrman/src/intrman.c @@ -27,7 +27,7 @@ IRX_ID("Interrupt_Manager", 1, 1); #define _mfc0(reg) \ ({ \ u32 val; \ - __asm__ volatile("mfc0 %0, " #reg : "=r"(val)); \ + __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ val; \ }) diff --git a/iop/system/modload/src/modload.c b/iop/system/modload/src/modload.c index 41f8b5b97b99..27f9fd4cb998 100644 --- a/iop/system/modload/src/modload.c +++ b/iop/system/modload/src/modload.c @@ -2035,7 +2035,7 @@ static void TerminateResidentEntriesDI(const char *command, unsigned int options TerminateResidentLibraries(" ReBootStart:di: Terminate resident Libraries\n", options, 0); - asm volatile("mfc0 %0, $15" : "=r"(prid) :); + __asm__ __volatile__("mfc0 %0, $15" : "=r"(prid) :); if ( !(options & 1) ) { diff --git a/iop/system/sifman/src/sifman.c b/iop/system/sifman/src/sifman.c index 2b65f5837b60..145a44b9fa62 100644 --- a/iop/system/sifman/src/sifman.c +++ b/iop/system/sifman/src/sifman.c @@ -72,7 +72,7 @@ static u32 sif_inited = 0; #define _mfc0(reg) \ ({ \ u32 val; \ - __asm__ volatile("mfc0 %0, " #reg : "=r"(val)); \ + __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ val; \ }) diff --git a/iop/system/threadman/src/thbase.c b/iop/system/threadman/src/thbase.c index 71cb1174d887..1e0e77a759bf 100644 --- a/iop/system/threadman/src/thbase.c +++ b/iop/system/threadman/src/thbase.c @@ -74,7 +74,7 @@ int CreateThread(iop_thread_t *thparam) thread->option = thparam->option; thread->status = THS_DORMANT; - asm __volatile__("sw $gp, %0\n" + __asm__ __volatile__("sw $gp, %0\n" : "=m"(thread->gp)::); list_insert(&thctx.thread_list, &thread->thread_list); diff --git a/iop/system/threadman/src/thcommon.c b/iop/system/threadman/src/thcommon.c index 465a78f7cea4..8da2bc960c01 100644 --- a/iop/system/threadman/src/thcommon.c +++ b/iop/system/threadman/src/thcommon.c @@ -168,7 +168,7 @@ int thread_leave(int ret1, int ret2, int intr_state, int release) thctx.current_thread->reason_counter = &thctx.current_thread->release_count; } - asm __volatile__("li $v0, 0x20\n" + __asm__ __volatile__("li $v0, 0x20\n" "syscall\n" : "=r"(result) : "r"(a0), "r"(a1), "r"(a2) @@ -651,7 +651,7 @@ int _start(int argc, char **argv) idle->saved_regs = idle->stack_top + (((idle->stack_size << 2) >> 2) - RESERVED_REGCTX_SIZE); memset(idle->saved_regs, 0, RESERVED_REGCTX_SIZE); - asm __volatile__("sw $gp, %0\n" + __asm__ __volatile__("sw $gp, %0\n" : "=m"(idle->gp)::); idle->saved_regs->unk = -2; @@ -680,7 +680,7 @@ int _start(int argc, char **argv) current->attr = TH_C; current->status = THS_RUN; - asm __volatile__("sw $gp, %0\n" + __asm__ __volatile__("sw $gp, %0\n" : "=m"(current->gp)::); list_insert(&thctx.thread_list, ¤t->thread_list); diff --git a/iop/system/timrman/src/timrman.c b/iop/system/timrman/src/timrman.c index fd358daa0f05..86ec612264b4 100644 --- a/iop/system/timrman/src/timrman.c +++ b/iop/system/timrman/src/timrman.c @@ -14,7 +14,7 @@ extern struct irx_export_table _exp_timrman; #define _mfc0(reg) \ ({ \ u32 val; \ - __asm__ volatile("mfc0 %0, " #reg \ + __asm__ __volatile__("mfc0 %0, " #reg \ : "=r"(val)); \ val; \ }) diff --git a/iop/system/udnl/src/udnl.c b/iop/system/udnl/src/udnl.c index f9ccdd7ee65a..3366bdaf27a4 100644 --- a/iop/system/udnl/src/udnl.c +++ b/iop/system/udnl/src/udnl.c @@ -376,7 +376,7 @@ static void TerminateResidentEntriesDI(unsigned int options) TerminateResidentLibraries(" kupdate:di: Terminate resident Libraries\n", options, 0); - asm volatile("mfc0 %0, $15" + __asm__ __volatile__("mfc0 %0, $15" : "=r"(prid) :); From 4f3dfdd8e9bacadfd87e05bfe55ca63783f807d7 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 15 May 2026 07:12:34 -0500 Subject: [PATCH 2/4] cleanup: use macros for EE sync --- ee/debug/src/screenshot.c | 6 +++--- ee/dma/src/dma.c | 3 ++- ee/graph/src/graph_mode.c | 10 ++++++---- ee/kernel/src/glue.c | 2 +- ee/kernel/src/tlbfunc.c | 7 ++++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ee/debug/src/screenshot.c b/ee/debug/src/screenshot.c index 70c1f43e666e..b7d9c0db035b 100644 --- a/ee/debug/src/screenshot.c +++ b/ee/debug/src/screenshot.c @@ -250,7 +250,7 @@ int ps2_screenshot( void *pDest, unsigned int VramAdress, unsigned int x, *PS2SS_D1_MADR = (u32)p_dma32; *PS2SS_D1_CHCR = 0x101; - __asm__ __volatile__("sync.l\n"); + EE_SYNCL(); // check if DMA is complete (STR=0) @@ -272,13 +272,13 @@ int ps2_screenshot( void *pDest, unsigned int VramAdress, unsigned int x, *PS2SS_D1_MADR = (u32)pDest; *PS2SS_D1_CHCR = 0x100; - __asm__ __volatile__(" sync.l\n"); + EE_SYNCL(); // check if DMA is complete (STR=0) while ( *PS2SS_D1_CHCR & 0x0100 ); *PS2SS_D1_CHCR = prev_chcr; - __asm__ __volatile__(" sync.l\n"); + EE_SYNCL(); *PS2SS_VIF1_STAT = 0; *PS2SS_GS_BUSDIR = (u64)0; diff --git a/ee/dma/src/dma.c b/ee/dma/src/dma.c index fa6637e2d75f..6fb6d44820a9 100644 --- a/ee/dma/src/dma.c +++ b/ee/dma/src/dma.c @@ -115,8 +115,9 @@ void dma_channel_fast_waits(int channel) void dma_wait_fast(void) { + EE_SYNCL(); + EE_SYNCP(); __asm__ __volatile__ ( - "sync.l; sync.p;" \ "0:" \ "bc0t 0f; nop;" \ "bc0t 0f; nop;" \ diff --git a/ee/graph/src/graph_mode.c b/ee/graph/src/graph_mode.c index 126eb309d5e9..e2289e1412a3 100644 --- a/ee/graph/src/graph_mode.c +++ b/ee/graph/src/graph_mode.c @@ -141,8 +141,8 @@ int graph_set_mode(int interlace, int mode, int ffmd, int flicker_filter) GsPutIMR(0x00007700); // Ensure registers are written prior to setting another mode. - __asm__ __volatile__ ("sync.p\n\t" - "nop\n\t"); + EE_SYNCP(); + __asm__ __volatile__ ("nop\n\t"); // If 576P is requested, check if bios supports it. if (mode == GRAPH_MODE_HDTV_576P) @@ -376,7 +376,8 @@ void graph_set_smode1(char cmod, char gcont) // Disable PRST for TV modes and enable for all other modes. *GS_REG_SMODE1 = smode1_val | (u64)1 << 16; - __asm__ __volatile__ ("sync.l; sync.p;"); + EE_SYNCL(); + EE_SYNCP(); // If VESA, 1080I, or 720P, disable bit PRST now and delay 2.5ms. if ((graph_crtmode >= 0x1A) && (graph_crtmode != 0x50) && (graph_crtmode != 0x53)) @@ -393,7 +394,8 @@ void graph_set_smode1(char cmod, char gcont) // Now enable read circuits. *GS_REG_PMODE = pmode_val; - __asm__ __volatile__ ("sync.l; sync.p;"); + EE_SYNCL(); + EE_SYNCP(); } diff --git a/ee/kernel/src/glue.c b/ee/kernel/src/glue.c index 051d8614a002..3ae352d51ff4 100644 --- a/ee/kernel/src/glue.c +++ b/ee/kernel/src/glue.c @@ -31,7 +31,7 @@ int DIntr() __asm__ (".p2align 3"); do { __asm__ __volatile__("di"); - __asm__ __volatile__("sync.p"); + EE_SYNCP(); __asm__ __volatile__("mfc0\t%0, $12" : "=r"(eie)); eie &= 0x10000; diff --git a/ee/kernel/src/tlbfunc.c b/ee/kernel/src/tlbfunc.c index f6c554995b66..64df23edf3ce 100644 --- a/ee/kernel/src/tlbfunc.c +++ b/ee/kernel/src/tlbfunc.c @@ -149,8 +149,8 @@ static int InitTLB32MB(void) kprintf("# TLB spad=0 kernel=1:%d default=%d:%d extended=%d:%d\n", TLBInfo.NumKernelTLBEntries - 1, TLBInfo.NumKernelTLBEntries, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries - 1, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries + TLBInfo.NumExtendedTLBEntries - 1); - __asm__ __volatile__("mtc0 $zero, $6\n" - "sync.p\n"); + __asm__ __volatile__("mtc0 $zero, $6\n"); + EE_SYNCP(); if (TLBInfo.NumKernelTLBEntries >= 0x31) { kprintf("# TLB over flow (1)"); @@ -172,7 +172,8 @@ static int InitTLB32MB(void) TLBInfo.NumWiredEntries = NumTlbEntries = i; __asm__ __volatile__("mtc0 %0, $6\n" - "sync.p\n" ::"r"(NumTlbEntries)); + ::"r"(NumTlbEntries)); + EE_SYNCP(); if (TLBInfo.NumExtendedTLBEntries > 0) { if (TLBInfo.NumExtendedTLBEntries + i >= 0x31) { From 57d60f4bbde84697652cf316276a3564db549d11 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 15 May 2026 07:12:34 -0500 Subject: [PATCH 3/4] cleanup: Cleanup cop0 access using inline function --- common/include/mipscopaccess.h | 72 +++++++++++++++ ee/kernel/include/kernel.h | 56 ++++-------- ee/kernel/src/delaythread.c | 3 +- ee/kernel/src/glue.c | 34 +++---- ee/kernel/src/timer.c | 4 +- ee/kernel/src/tlbfunc.c | 5 +- ee/kernel/src/tlbsrc/src/tlbsrc.c | 130 ++++++++++++--------------- ee/libcglue/src/sleep.c | 2 +- iop/cdvd/cdvdman/src/cdvdman.c | 22 ++--- iop/debug/ioptrap/src/breakpoint.c | 22 ++--- iop/system/igreeting/src/igreeting.c | 12 +-- iop/system/intrman/src/intrman.c | 14 +-- iop/system/modload/src/modload.c | 3 +- iop/system/sifman/src/sifman.c | 14 +-- iop/system/timrman/src/timrman.c | 15 +--- iop/system/udnl/src/udnl.c | 5 +- 16 files changed, 185 insertions(+), 228 deletions(-) create mode 100644 common/include/mipscopaccess.h diff --git a/common/include/mipscopaccess.h b/common/include/mipscopaccess.h new file mode 100644 index 000000000000..fca73291d2a7 --- /dev/null +++ b/common/include/mipscopaccess.h @@ -0,0 +1,72 @@ +/** + * @file + * MIPS COP coprocessor access + */ + +#ifndef __MIPSCOPACCESS_H__ +#define __MIPSCOPACCESS_H__ + +#include + +enum mips_cop0_reg +{ + /** Programmable register to select TLB entry for reading or writing (purpose: MMU) */ + COP0_REG_Index = 0, + /** Pseudo-random counter for TLB replacement (purpose: MMU) */ + COP0_REG_Random = 1, + /** Low half of TLB entry for even PFN (Physical page number) (purpose: MMU) */ + COP0_REG_EntryLo0 = 2, + /** Low half of TLB entry for odd PFN (Physical page number) (purpose: MMU) */ + COP0_REG_EntryLo1 = 3, + /** Pointer to kernel virtual PTE table (purpose: Exception) */ + COP0_REG_Context = 4, + /** Mask that sets the TLB page size (purpose: MMU) */ + COP0_REG_PageMask = 5, + /** Number of wired TLB entries (purpose: MMU) */ + COP0_REG_Wired = 6, + /** Bad virtual address (purpose: Exception) */ + COP0_REG_BadVAddr = 8, + /** Timer compare (purpose: Exception) */ + COP0_REG_Count = 9, + /** High half of TLB entry(Virtual page number and ASID) (purpose: MMU) */ + COP0_REG_EntryHi = 10, + /** Timer compare (purpose: Exception) */ + COP0_REG_Compare = 11, + /** Processor Status Register (purpose: Exception) */ + COP0_REG_Status = 12, + /** Cause of the last exception taken (purpose: Exception) */ + COP0_REG_Cause = 13, + /** Exception Program Counter (purpose: Exception) */ + COP0_REG_EPC = 14, + /** Processor Revision Identifier (purpose: MMU) */ + COP0_REG_PRId = 15, + /** Configuration Register (purpose: MMU) */ + COP0_REG_Config = 16, + /** Bad Physical Address (purpose: Exception) */ + COP0_REG_BadPAddr = 23, + /** This is used for Debug function (purpose: Debug) */ + COP0_REG_Debug = 24, + /** Performance Counter and Control Register (purpose: Exception) */ + COP0_REG_Perf = 25, + /** Cache Tag register(low bits) (purpose: MMU) */ + COP0_REG_TagLo = 28, + /** Cache Tag register(high bits) (purpose: MMU) */ + COP0_REG_TagHi = 29, + /** Error Exception Program Counter (purpose: Exception) */ + COP0_REG_ErrorPC = 30, +}; + +static inline __attribute__((__always_inline__)) u32 get_mips_cop_reg(const u32 cop, const u32 idx) +{ + u32 val; + + __asm__ __volatile__("mfc%[cop]\t%[val], $%[idx]\n" : [val] "=r"(val) : [cop] "i"(cop), [idx] "i"(idx)); + return val; +} + +static inline __attribute__((__always_inline__)) void set_mips_cop_reg(const u32 cop, const u32 idx, u32 val) +{ + __asm__ __volatile__("mtc%[cop]\t%[val], $%[idx]\n" :: [val] "r"(val), [cop] "i"(cop), [idx] "i"(idx)); +} + +#endif /* __MIPSCOPACCESS_H__ */ diff --git a/ee/kernel/include/kernel.h b/ee/kernel/include/kernel.h index 7c8766857300..17232d8534f2 100644 --- a/ee/kernel/include/kernel.h +++ b/ee/kernel/include/kernel.h @@ -20,6 +20,7 @@ #include #include #include +#include #define DI DIntr #define EI EIntr @@ -151,50 +152,29 @@ static inline int ee_get_opmode(void) { u32 status; - __asm__ __volatile__( - ".set\tpush\n\t" - ".set\tnoreorder\n\t" - "mfc0\t%0, $12\n\t" - ".set\tpop\n\t" - : "=r"(status)); + status = get_mips_cop_reg(0, COP0_REG_Status); return ((status >> 3) & 3); } static inline int ee_set_opmode(u32 opmode) { - u32 status, mask; - - __asm__ __volatile__( - ".set\tpush\n\t" - ".set\tnoreorder\n\t" - "mfc0\t%0, $12\n\t" - "li\t%1, 0xffffffe7\n\t" - "and\t%0, %1\n\t" - "or\t%0, %2\n\t" - "mtc0\t%0, $12\n\t" - "sync.p\n\t" - ".set\tpop\n\t" - : "=r"(status), "=r"(mask) - : "r"(opmode)); + u32 status; + + status = (get_mips_cop_reg(0, COP0_REG_Status) & ~0x18) | opmode; + set_mips_cop_reg(0, COP0_REG_Status, status); + EE_SYNCP(); return ((status >> 3) & 3); } static inline int ee_kmode_enter() { - u32 status, mask; - - __asm__ __volatile__( - ".set\tpush\n\t" - ".set\tnoreorder\n\t" - "mfc0\t%0, $12\n\t" - "li\t%1, 0xffffffe7\n\t" - "and\t%0, %1\n\t" - "mtc0\t%0, $12\n\t" - "sync.p\n\t" - ".set\tpop\n\t" - : "=r"(status), "=r"(mask)); + u32 status; + + status = (get_mips_cop_reg(0, COP0_REG_Status) & ~0x18); + set_mips_cop_reg(0, COP0_REG_Status, status); + EE_SYNCP(); return status; } @@ -203,15 +183,9 @@ static inline int ee_kmode_exit() { int status; - __asm__ __volatile__( - ".set\tpush\n\t" - ".set\tnoreorder\n\t" - "mfc0\t%0, $12\n\t" - "ori\t%0, 0x10\n\t" - "mtc0\t%0, $12\n\t" - "sync.p\n\t" - ".set\tpop\n\t" - : "=r"(status)); + status = get_mips_cop_reg(0, COP0_REG_Status) | 0x10; + set_mips_cop_reg(0, COP0_REG_Status, status); + EE_SYNCP(); return status; } diff --git a/ee/kernel/src/delaythread.c b/ee/kernel/src/delaythread.c index 348557482559..0717c8b4150a 100644 --- a/ee/kernel/src/delaythread.c +++ b/ee/kernel/src/delaythread.c @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef F_DelayThread static u64 DelayThreadWakeup_callback(s32 alarm_id, u64 scheduled_time, u64 actual_time, void *arg, void *pc_value) @@ -38,7 +39,7 @@ s32 DelayThread(s32 microseconds) s32 timer_alarm_id; ee_sema_t sema; - __asm__ __volatile__ ("mfc0\t%0, $12" : "=r" (eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); if ((eie & 0x10000) == 0) { return 0x80008008; // ECPUDI diff --git a/ee/kernel/src/glue.c b/ee/kernel/src/glue.c index 3ae352d51ff4..a3758122473c 100644 --- a/ee/kernel/src/glue.c +++ b/ee/kernel/src/glue.c @@ -14,14 +14,14 @@ */ #include "kernel.h" +#include #ifdef F_DIntr int DIntr() { int eie, res; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; res = eie != 0; @@ -32,8 +32,7 @@ int DIntr() do { __asm__ __volatile__("di"); EE_SYNCP(); - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; } while (eie); @@ -46,8 +45,7 @@ int EIntr() { int eie; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; __asm__ __volatile__("ei"); @@ -60,8 +58,7 @@ int EnableIntc(int intc) { int eie, res; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) @@ -82,8 +79,7 @@ int DisableIntc(int intc) { int eie, res; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) @@ -104,8 +100,7 @@ int EnableDmac(int dmac) { int eie, res; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) @@ -126,8 +121,7 @@ int DisableDmac(int dmac) { int eie, res; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) @@ -148,8 +142,7 @@ int SetAlarm(u16 time, void (*callback)(s32 alarm_id, u16 time, void *common), v { int eie, res; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) @@ -170,8 +163,7 @@ int ReleaseAlarm(int alarm_id) { int eie, res; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) @@ -252,8 +244,7 @@ void SyncDCache(void *start, void *end) { int eie; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) @@ -278,8 +269,7 @@ void InvalidDCache(void *start, void *end) { int eie; - __asm__ __volatile__("mfc0\t%0, $12" - : "=r"(eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); eie &= 0x10000; if (eie) diff --git a/ee/kernel/src/timer.c b/ee/kernel/src/timer.c index 7e1298e3de41..548481c4158a 100644 --- a/ee/kernel/src/timer.c +++ b/ee/kernel/src/timer.c @@ -16,6 +16,7 @@ #include #include #include +#include #define TIMER_MODE_START 0x00000001 #define TIMER_MODE_HANDLER 0x00000002 @@ -956,8 +957,7 @@ u32 cpu_ticks(void) { u32 out; - __asm__ __volatile__("mfc0\t%0, $9\n" - : "=r"(out)); + out = get_mips_cop_reg(0, COP0_REG_Count); return out; } #endif diff --git a/ee/kernel/src/tlbfunc.c b/ee/kernel/src/tlbfunc.c index 64df23edf3ce..6b74c1757a1a 100644 --- a/ee/kernel/src/tlbfunc.c +++ b/ee/kernel/src/tlbfunc.c @@ -149,7 +149,7 @@ static int InitTLB32MB(void) kprintf("# TLB spad=0 kernel=1:%d default=%d:%d extended=%d:%d\n", TLBInfo.NumKernelTLBEntries - 1, TLBInfo.NumKernelTLBEntries, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries - 1, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries, TLBInfo.NumKernelTLBEntries + TLBInfo.NumDefaultTLBEntries + TLBInfo.NumExtendedTLBEntries - 1); - __asm__ __volatile__("mtc0 $zero, $6\n"); + set_mips_cop_reg(0, COP0_REG_Wired, 0); EE_SYNCP(); if (TLBInfo.NumKernelTLBEntries >= 0x31) { @@ -171,8 +171,7 @@ static int InitTLB32MB(void) } TLBInfo.NumWiredEntries = NumTlbEntries = i; - __asm__ __volatile__("mtc0 %0, $6\n" - ::"r"(NumTlbEntries)); + set_mips_cop_reg(0, COP0_REG_Wired, NumTlbEntries); EE_SYNCP(); if (TLBInfo.NumExtendedTLBEntries > 0) { diff --git a/ee/kernel/src/tlbsrc/src/tlbsrc.c b/ee/kernel/src/tlbsrc/src/tlbsrc.c index 1441ec5775c6..2e11fc8350a5 100644 --- a/ee/kernel/src/tlbsrc/src/tlbsrc.c +++ b/ee/kernel/src/tlbsrc/src/tlbsrc.c @@ -9,6 +9,7 @@ #include #include +#include /* // Doesn't work, but here are the COP0 register definitions: #define Index $0 @@ -69,18 +70,16 @@ int PutTLBEntry(unsigned int PageMask, unsigned int EntryHi, unsigned int EntryL case 0x30: case 0x20: case 0x00: - __asm__ __volatile__("mtc0 %1, $5\n" - "mtc0 %2, $10\n" - "mtc0 %3, $2\n" - "mtc0 %4, $3\n" - "sync.p\n" - "tlbwr\n" - "sync.p\n" - "tlbp\n" - "sync.p\n" - "mfc0 %0, $0\n" - : "=r"(result) - : "r"(PageMask), "r"(EntryHi), "r"(EntryLo0), "r"(EntryLo1)); + set_mips_cop_reg(0, COP0_REG_PageMask, PageMask); + set_mips_cop_reg(0, COP0_REG_EntryHi, EntryHi); + set_mips_cop_reg(0, COP0_REG_EntryLo0, EntryLo0); + set_mips_cop_reg(0, COP0_REG_EntryLo1, EntryLo1); + EE_SYNCP(); + __asm__ __volatile__("tlbwr\n"); + EE_SYNCP(); + __asm__ __volatile__("tlbp\n"); + EE_SYNCP(); + result = get_mips_cop_reg(0, COP0_REG_Index); break; case 0x50: case 0x10: @@ -97,15 +96,14 @@ int SetTLBEntry(unsigned int index, unsigned int PageMask, unsigned int EntryHi, int result; if (index < 0x30) { - __asm__ __volatile__("mtc0 %0, $0\n" - "mtc0 %1, $5\n" - "mtc0 %2, $10\n" - "mtc0 %3, $2\n" - "mtc0 %4, $3\n" - "sync.p\n" - "tlbwi\n" - "sync.p\n" ::"r"(index), - "r"(PageMask), "r"(EntryHi), "r"(EntryLo0), "r"(EntryLo1)); + set_mips_cop_reg(0, COP0_REG_Index, index); + set_mips_cop_reg(0, COP0_REG_PageMask, PageMask); + set_mips_cop_reg(0, COP0_REG_EntryHi, EntryHi); + set_mips_cop_reg(0, COP0_REG_EntryLo0, EntryLo0); + set_mips_cop_reg(0, COP0_REG_EntryLo1, EntryLo1); + EE_SYNCP(); + __asm__ __volatile__("tlbwi\n"); + EE_SYNCP(); result = index; } else @@ -120,19 +118,14 @@ int GetTLBEntry(unsigned int index, unsigned int *PageMask, unsigned int *EntryH int result; if (index < 0x30) { - __asm__ __volatile__("mtc0 %0, $0\n" - "sync.p\n" - "tlbr\n" - "sync.p\n" - "mfc0 $v0, $5\n" - "sw $v0, (%1)\n" - "mfc0 $v0, $10\n" - "sw $v0, (%2)\n" - "mfc0 $v0, $2\n" - "sw $v0, (%3)\n" - "mfc0 $v0, $3\n" - "sw $v0, (%4)\n" ::"r"(index), - "r"(PageMask), "r"(EntryHi), "r"(EntryLo0), "r"(EntryLo1)); + set_mips_cop_reg(0, COP0_REG_Index, index); + EE_SYNCP(); + __asm__ __volatile__("tlbr\n"); + EE_SYNCP(); + *PageMask = get_mips_cop_reg(0, COP0_REG_PageMask); + *EntryHi = get_mips_cop_reg(0, COP0_REG_EntryHi); + *EntryLo0 = get_mips_cop_reg(0, COP0_REG_EntryLo0); + *EntryLo1 = get_mips_cop_reg(0, COP0_REG_EntryLo1); result = index; } else @@ -146,24 +139,18 @@ int ProbeTLBEntry(unsigned int EntryHi, unsigned int *PageMask, unsigned int *En { int result, index; - __asm__ __volatile__("mtc0 %1, $10\n" - "sync.p\n" - "tlbp\n" - "sync.p\n" - "mfc0 %0, $0\n" - : "=r"(index) - : "r"(EntryHi)); + set_mips_cop_reg(0, COP0_REG_EntryHi, EntryHi); + EE_SYNCP(); + __asm__ __volatile__("tlbp\n"); + EE_SYNCP(); + index = get_mips_cop_reg(0, COP0_REG_Index); if (index >= 0) { - __asm__ __volatile__("tlbr\n" - "sync.p\n" - "mfc0 $v0, $5\n" - "sw $v0, (%0)\n" - "mfc0 $v1, $2\n" - "sw $v1, (%1)\n" - "mfc0 $v0, $3\n" - "sw $v0, (%2)\n" ::"r"(PageMask), - "r"(EntryLo0), "r"(EntryLo1)); + __asm__ __volatile__("tlbr\n"); + EE_SYNCP(); + *PageMask = get_mips_cop_reg(0, COP0_REG_PageMask); + *EntryLo0 = get_mips_cop_reg(0, COP0_REG_EntryLo0); + *EntryLo1 = get_mips_cop_reg(0, COP0_REG_EntryLo1); result = index; } else @@ -187,24 +174,19 @@ int ExpandScratchPad(unsigned int page) if (page == 0) { EntryHi = 0xE0010000 + ((index - 1) << 13); - __asm__ __volatile__("mfc0 $v0, $6\n" - "addiu $v0, $v0, 0xFFFF\n" - "mtc0 $v0, $6\n" - "mtc0 %0, $0\n" - "mtc0 $zero, $5\n" - "mtc0 %1, $10\n" - "mtc0 $zero, $2\n" - "mtc0 $zero, $3\n" - "sync.p\n" - "tlbwi\n" - "sync.p\n" ::"r"(index), - "r"(EntryHi)); + set_mips_cop_reg(0, COP0_REG_Wired, get_mips_cop_reg(0, COP0_REG_Wired) + 0xFFFF); + set_mips_cop_reg(0, COP0_REG_Index, index); + set_mips_cop_reg(0, COP0_REG_PageMask, 0); + set_mips_cop_reg(0, COP0_REG_EntryHi, EntryHi); + set_mips_cop_reg(0, COP0_REG_EntryLo0, 0); + set_mips_cop_reg(0, COP0_REG_EntryLo1, 0); + EE_SYNCP(); + __asm__ __volatile__("tlbwi\n"); + EE_SYNCP(); } else #endif { - __asm__ __volatile__("mfc0 %0, $6\n" - "addiu $v0, %0, 1\n" - "mtc0 $v0, $6\n" ::"r"(index)); + set_mips_cop_reg(0, COP0_REG_Wired, get_mips_cop_reg(0, COP0_REG_Wired) + 1); } } @@ -219,16 +201,14 @@ int ExpandScratchPad(unsigned int page) EntryLo0 = ((page + 0x1000) & 0xFFFFF000) >> 6 | 0x1F; EntryLo1 = (page & 0xFFFFF000) >> 6 | 0x1F; - __asm__ __volatile__("mtc0 %0, $0\n" - "daddu $v1, $zero, $zero\n" - "mtc0 $v1, $5\n" - "mtc0 %1, $10\n" - "mtc0 %2, $2\n" - "mtc0 %3, $3\n" - "sync.p\n" - "tlbwi\n" - "sync.p\n" ::"r"(index), - "r"(EntryHi), "r"(EntryLo0), "r"(EntryLo1)); + set_mips_cop_reg(0, COP0_REG_Index, index); + set_mips_cop_reg(0, COP0_REG_PageMask, 0); + set_mips_cop_reg(0, COP0_REG_EntryHi, EntryHi); + set_mips_cop_reg(0, COP0_REG_EntryLo0, EntryLo0); + set_mips_cop_reg(0, COP0_REG_EntryLo1, EntryLo1); + EE_SYNCP(); + __asm__ __volatile__("tlbwi\n"); + EE_SYNCP(); result = index; } else diff --git a/ee/libcglue/src/sleep.c b/ee/libcglue/src/sleep.c index 5e5c7726e316..602d8b26c681 100755 --- a/ee/libcglue/src/sleep.c +++ b/ee/libcglue/src/sleep.c @@ -40,7 +40,7 @@ int nanosleep(const struct timespec *req, struct timespec *rem) s32 timer_alarm_id; ee_sema_t sema; - __asm__ __volatile__ ("mfc0\t%0, $12" : "=r" (eie)); + eie = get_mips_cop_reg(0, COP0_REG_Status); if ((eie & 0x10000) == 0) { errno = ENOSYS; // Functionality not available diff --git a/iop/cdvd/cdvdman/src/cdvdman.c b/iop/cdvd/cdvdman/src/cdvdman.c index 23f9a217b846..b3fb46de2e4c 100644 --- a/iop/cdvd/cdvdman/src/cdvdman.c +++ b/iop/cdvd/cdvdman/src/cdvdman.c @@ -20,25 +20,13 @@ #include #include #include +#include IRX_ID("cdvd_driver", 2, 38); // Based on the module from SCE SDK 3.1.0. extern struct irx_export_table _exp_cdvdman; -#ifdef CDVD_VARIANT_OSD -#define PRID $15 - -#define _mfc0(reg) \ - ({ \ - u32 val; \ - __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ - val; \ - }) - -#define mfc0(reg) _mfc0(reg) -#endif - typedef struct cdvdman_dirtbl_entry_ { int m_number; @@ -1732,9 +1720,9 @@ static int cdrom_ioctl(iop_file_t *f, int arg, void *param) { #ifdef CDVD_VARIANT_OSD case 0x6310: - return mfc0(PRID); + return get_mips_cop_reg(0, COP0_REG_PRId); case 0x6311: - if ( mfc0(PRID) < 35 ) + if ( get_mips_cop_reg(0, COP0_REG_PRId) < 35 ) { return -22; } @@ -1748,7 +1736,7 @@ static int cdrom_ioctl(iop_file_t *f, int arg, void *param) } return 0; case 0x6312: - return mfc0(PRID) >= 35 ? (int)(/* 0xBF808284 */ *(u32 *)&iop_mmio_hwport->sio2.unused[0] & 1) : -22; + return get_mips_cop_reg(0, COP0_REG_PRId) >= 35 ? (int)(/* 0xBF808284 */ *(u32 *)&iop_mmio_hwport->sio2.unused[0] & 1) : -22; #endif case 0x10000: g_cdvdman_spinnom = -1; @@ -7863,7 +7851,7 @@ int sceCdRcBypassCtl(int mode, u32 *status) char wdata[1]; USE_IOP_MMIO_HWPORT(); - if ( mfc0(PRID) >= 0x23 ) + if ( get_mips_cop_reg(0, COP0_REG_PRId) >= 0x23 ) { if ( mode & 0xFF ) { diff --git a/iop/debug/ioptrap/src/breakpoint.c b/iop/debug/ioptrap/src/breakpoint.c index 21219906aa47..137240499e9f 100644 --- a/iop/debug/ioptrap/src/breakpoint.c +++ b/iop/debug/ioptrap/src/breakpoint.c @@ -9,48 +9,40 @@ */ #include "ioptrap.h" +#include void set_dba(u32 v) { - __asm__ __volatile__("mtc0 %0, $5" - : - : "r"(v)); + set_mips_cop_reg(0, 5, v); } void set_dbam(u32 v) { - __asm__ __volatile__("mtc0 %0, $9" - : - : "r"(v)); + set_mips_cop_reg(0, 9, v); } void set_dcic(u32 v) { - __asm__ __volatile__("mtc0 %0, $7" - : - : "r"(v)); + set_mips_cop_reg(0, 7, v); } u32 get_dba() { u32 v; - __asm__ __volatile__("mfc0 %0, $5" - : "=&r"(v)); + v = get_mips_cop_reg(0, 5); return v; } u32 get_dbam() { u32 v; - __asm__ __volatile__("mfc0 %0, $9" - : "=&r"(v)); + v = get_mips_cop_reg(0, 9); return v; } u32 get_dcic() { u32 v; - __asm__ __volatile__("mfc0 %0, $7" - : "=&r"(v)); + v = get_mips_cop_reg(0, 7); return v; } diff --git a/iop/system/igreeting/src/igreeting.c b/iop/system/igreeting/src/igreeting.c index 54650b1f1260..dfa09e3ba5f9 100644 --- a/iop/system/igreeting/src/igreeting.c +++ b/iop/system/igreeting/src/igreeting.c @@ -12,6 +12,7 @@ #include #include +#include struct RomImgData { @@ -75,15 +76,6 @@ struct romflash_sigcheck_res }; #endif -#define _mfc0(reg) \ - ({ \ - u32 val; \ - __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ - val; \ - }) - -#define mfc0(reg) _mfc0(reg) - #ifdef IGREETING_DTL_T static void do_get_dip_switch_values_chr(char *str, int val, int count); #endif @@ -243,7 +235,7 @@ int _start(int ac, char **av) } if ( !boot_mode_4 || !*(u16 *)boot_mode_4 ) { - cop0_processor_mode = mfc0($15); + cop0_processor_mode = get_mips_cop_reg(0, COP0_REG_PRId); #ifdef IGREETING_DTL_T board_type_str = ""; boardtype_int = iop_mmio_hwport->exp2_r2[4612]; diff --git a/iop/system/intrman/src/intrman.c b/iop/system/intrman/src/intrman.c index 70ab4391006c..9eb81d42459e 100644 --- a/iop/system/intrman/src/intrman.c +++ b/iop/system/intrman/src/intrman.c @@ -11,6 +11,7 @@ #include "intrman.h" #include "irx_imports.h" #include "kerr.h" +#include #include "iop_low_memory_globals.h" #include "iop_mmio_hwport.h" @@ -22,17 +23,6 @@ IRX_ID("Interrupt_Manager", 1, 1); #endif // Based on the module from SCE SDK 1.3.4. -#define PRID $15 - -#define _mfc0(reg) \ - ({ \ - u32 val; \ - __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ - val; \ - }) - -#define mfc0(reg) _mfc0(reg) - extern int CpuGetICTRL(); extern void CpuEnableICTRL(); extern int dma_interrupt_handler(void *userdata); @@ -53,7 +43,7 @@ int _start(int ac, char **av) (void)ac; (void)av; - prid = mfc0(PRID); + prid = get_mips_cop_reg(0, COP0_REG_PRId); #ifdef BUILDING_INTRMANP if ( prid >= 16 ) diff --git a/iop/system/modload/src/modload.c b/iop/system/modload/src/modload.c index 27f9fd4cb998..d2081a5aa7ab 100644 --- a/iop/system/modload/src/modload.c +++ b/iop/system/modload/src/modload.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef _IOP IRX_ID("Moldule_File_loader", 2, 9); @@ -2035,7 +2036,7 @@ static void TerminateResidentEntriesDI(const char *command, unsigned int options TerminateResidentLibraries(" ReBootStart:di: Terminate resident Libraries\n", options, 0); - __asm__ __volatile__("mfc0 %0, $15" : "=r"(prid) :); + prid = get_mips_cop_reg(0, COP0_REG_PRId); if ( !(options & 1) ) { diff --git a/iop/system/sifman/src/sifman.c b/iop/system/sifman/src/sifman.c index 145a44b9fa62..f60c03da50ca 100644 --- a/iop/system/sifman/src/sifman.c +++ b/iop/system/sifman/src/sifman.c @@ -10,6 +10,7 @@ #include "irx_imports.h" #include "sifman.h" +#include #include "iop_mmio_hwport.h" #include "sif_mmio_hwport.h" @@ -67,17 +68,6 @@ static sifman_internals_t sifman_internals; static u32 sif_dma2_inited = 0; static u32 sif_inited = 0; -#define PRID $15 - -#define _mfc0(reg) \ - ({ \ - u32 val; \ - __asm__ __volatile__("mfc0 %0, " #reg : "=r"(val)); \ - val; \ - }) - -#define mfc0(reg) _mfc0(reg) - int _start(int ac, char **av) { s32 prid; @@ -87,7 +77,7 @@ int _start(int ac, char **av) (void)ac; (void)av; - prid = mfc0(PRID); + prid = get_mips_cop_reg(0, COP0_REG_PRId); if ( prid >= 16 ) { if ( (iop_mmio_hwport->iop_sbus_ctrl[0] & 8) == 0 ) diff --git a/iop/system/timrman/src/timrman.c b/iop/system/timrman/src/timrman.c index 86ec612264b4..132f97fe4039 100644 --- a/iop/system/timrman/src/timrman.c +++ b/iop/system/timrman/src/timrman.c @@ -1,6 +1,7 @@ #include "timrman.h" #include "kerr.h" #include "xtimrman.h" +#include #include "irx_imports.h" @@ -9,18 +10,6 @@ IRX_ID("Timer_Manager", 2, 2); extern struct irx_export_table _exp_timrman; -#define PRID $15 - -#define _mfc0(reg) \ - ({ \ - u32 val; \ - __asm__ __volatile__("mfc0 %0, " #reg \ - : "=r"(val)); \ - val; \ - }) - -#define mfc0(reg) _mfc0(reg) - #ifdef BUILDING_TIMRMANP #define NUM_TIMERS 3 #else @@ -162,7 +151,7 @@ static u32 (*sTimerCountFun[NUM_TIMERS])() = { int _start(int argc, char **argv) { int prid, ret; - prid = mfc0(PRID); + prid = get_mips_cop_reg(0, COP0_REG_PRId); #ifdef BUILDING_TIMRMANP if (prid >= 16) { diff --git a/iop/system/udnl/src/udnl.c b/iop/system/udnl/src/udnl.c index 3366bdaf27a4..ad5cdc3f7ffe 100644 --- a/iop/system/udnl/src/udnl.c +++ b/iop/system/udnl/src/udnl.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "ELF.h" #include "COFF.h" @@ -376,9 +377,7 @@ static void TerminateResidentEntriesDI(unsigned int options) TerminateResidentLibraries(" kupdate:di: Terminate resident Libraries\n", options, 0); - __asm__ __volatile__("mfc0 %0, $15" - : "=r"(prid) - :); + prid = get_mips_cop_reg(0, COP0_REG_PRId); if (!(options & 1)) { pReg = (prid < 0x10 || ((*(volatile unsigned int *)0xbf801450) & 8)) ? *(volatile unsigned int ***)0xbfc02008 : *(volatile unsigned int ***)0xbfc0200C; From 89b9d8cf249f927192c57804ce5e55e99e34002d Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 15 May 2026 07:12:34 -0500 Subject: [PATCH 4/4] cleanup: use macro for gp register get/set --- iop/kernel/include/defs.h | 2 ++ iop/system/loadcore/src/loadcore.c | 10 +++++----- iop/system/threadman/src/include/thcommon.h | 5 ++++- iop/system/threadman/src/thbase.c | 5 ++--- iop/system/threadman/src/thcommon.c | 13 +++++-------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/iop/kernel/include/defs.h b/iop/kernel/include/defs.h index fc5e86f5cd55..f5fe9dfcc1d6 100644 --- a/iop/kernel/include/defs.h +++ b/iop/kernel/include/defs.h @@ -26,7 +26,9 @@ extern "C" { #define NULL ((void *)0) #endif +#ifndef ALIGN #define ALIGN(x, align) (((x)+((align)-1))&~((align)-1)) +#endif #define PHYSADDR(a) (((u32)(a)) & 0x1fffffff) diff --git a/iop/system/loadcore/src/loadcore.c b/iop/system/loadcore/src/loadcore.c index 86bc15310c27..4a2c22d831a1 100644 --- a/iop/system/loadcore/src/loadcore.c +++ b/iop/system/loadcore/src/loadcore.c @@ -12,6 +12,7 @@ #include "irx_imports.h" #include "kerr.h" #include "xloadcore.h" +#include extern struct irx_export_table _exp_loadcore; @@ -432,7 +433,7 @@ void loadcore_init(boot_params *in_params) next.callback = (void *)*stack_reboot_handlers; if ( i == 3 ) next.callback = (void *)*reboot_handler_ptr; - __asm__ __volatile__("\tmove $gp, %0\n" : : "r"(reboot_handler_ptr[1])); + SetGP((void *)reboot_handler_ptr[1]); ((BootupCallback_t)(*reboot_handler_ptr & (~3)))(&next, 1); } reboot_handler_ptr += 2; @@ -565,12 +566,11 @@ int *QueryBootMode(int mode) int AddRebootNotifyHandler(BootupCallback_t func, int priority, int *stat) { - u32 gp_val; + void *gp_val; iop_init_entry_t next; next.callback = (void *)1; - gp_val = 0; - __asm__ __volatile__("\tmove %0, $gp\n" : "=r"(gp_val) :); + gp_val = GetGP(); if ( !reboot_handlers ) { @@ -583,7 +583,7 @@ int AddRebootNotifyHandler(BootupCallback_t func, int priority, int *stat) } reboot_handlers[0] = (u32)func + (priority & 3); - reboot_handlers[1] = gp_val; + reboot_handlers[1] = (u32)gp_val; reboot_handlers += 2; reboot_handlers[0] = 0; return 1; diff --git a/iop/system/threadman/src/include/thcommon.h b/iop/system/threadman/src/include/thcommon.h index 374ef932a3b4..ae9e05c0afe1 100644 --- a/iop/system/threadman/src/include/thcommon.h +++ b/iop/system/threadman/src/include/thcommon.h @@ -24,6 +24,9 @@ #define HANDLE_VERIFY(handle, t) (((struct heaptag *)(HANDLE_PTR(handle)))->tag == (t) && \ HANDLE_ID(handle) == ((struct heaptag *)(HANDLE_PTR(handle)))->id) +#ifdef ALIGN +#undef ALIGN +#endif #define ALIGN(i) (((i) + 3) & (~3)) #define ALIGN_256(i) (((i) + 0xff) & (~0xff)) @@ -164,7 +167,7 @@ struct thread void *entry; void *stack_top; u32 stack_size; - u32 gp; + void *gp; u32 attr; u32 option; // nothing seems to use wait_return, would be $ra diff --git a/iop/system/threadman/src/thbase.c b/iop/system/threadman/src/thbase.c index 1e0e77a759bf..bf301c682a9b 100644 --- a/iop/system/threadman/src/thbase.c +++ b/iop/system/threadman/src/thbase.c @@ -7,6 +7,7 @@ #include "thsemap.h" #include "xthbase.h" #include "xtimrman.h" +#include #include "thcommon.h" @@ -73,9 +74,7 @@ int CreateThread(iop_thread_t *thparam) thread->attr = thparam->attr; thread->option = thparam->option; thread->status = THS_DORMANT; - - __asm__ __volatile__("sw $gp, %0\n" - : "=m"(thread->gp)::); + thread->gp = GetGP(); list_insert(&thctx.thread_list, &thread->thread_list); diff --git a/iop/system/threadman/src/thcommon.c b/iop/system/threadman/src/thcommon.c index 8da2bc960c01..c23521bbc1d4 100644 --- a/iop/system/threadman/src/thcommon.c +++ b/iop/system/threadman/src/thcommon.c @@ -8,6 +8,7 @@ #include "loadcore.h" #include "sysclib.h" #include "stdio.h" +#include #include @@ -205,7 +206,7 @@ int thread_init_and_start(struct thread *thread, int intr_state) thread->saved_regs->sp = (u32)&thread->saved_regs[1]; thread->saved_regs->fp = thread->saved_regs->sp; thread->saved_regs->ra = (u32)ExitThread; - thread->saved_regs->gp = thread->gp; + thread->saved_regs->gp = (u32)thread->gp; thread->saved_regs->sr = 0x404; thread->saved_regs->sr |= thread->attr & 8; thread->saved_regs->pc = (u32)thread->entry; @@ -650,13 +651,11 @@ int _start(int argc, char **argv) idle->entry = idle_thread; idle->saved_regs = idle->stack_top + (((idle->stack_size << 2) >> 2) - RESERVED_REGCTX_SIZE); memset(idle->saved_regs, 0, RESERVED_REGCTX_SIZE); - - __asm__ __volatile__("sw $gp, %0\n" - : "=m"(idle->gp)::); + idle->gp = GetGP(); idle->saved_regs->unk = -2; idle->saved_regs->sp = (u32)&idle->saved_regs[1]; - idle->saved_regs->gp = idle->gp; + idle->saved_regs->gp = (u32)idle->gp; idle->saved_regs->fp = idle->saved_regs->sp; idle->saved_regs->ra = (u32)ExitThread; idle->saved_regs->sr = (idle->attr & 0xF0000000) | 0x404; @@ -679,9 +678,7 @@ int _start(int argc, char **argv) current->priority = 1; current->attr = TH_C; current->status = THS_RUN; - - __asm__ __volatile__("sw $gp, %0\n" - : "=m"(current->gp)::); + current->gp = GetGP(); list_insert(&thctx.thread_list, ¤t->thread_list); thctx.current_thread = current;