Skip to content

Commit

Permalink
Make use of lswx/stswx where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Jun 25, 2024
1 parent cb23a1c commit bf67b31
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
8 changes: 8 additions & 0 deletions gc/ogc/machine/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@
__asm__ __volatile__ ("lwbrx %0,%1,%2" : "=r"(res) : "b%"(index), "r"(base) : "memory"); \
res; })

#define __lswx(base,bytes) \
({ register u32 res; \
__asm__ __volatile__ ("mtxer %2; lswx %0,%y1" : "=&r"(res) : "Z"(*(u32*)(base)), "r"(bytes) : "xer"); \
res; })

#define __sthbrx(base,index,value) \
__asm__ __volatile__ ("sthbrx %0,%1,%2" : : "r"(value), "b%"(index), "r"(base) : "memory")

#define __stwbrx(base,index,value) \
__asm__ __volatile__ ("stwbrx %0,%1,%2" : : "r"(value), "b%"(index), "r"(base) : "memory")

#define __stswx(base,bytes,value) \
__asm__ __volatile__ ("mtxer %2; stswx %1,%y0" : "=Z"(*(u32*)(base)) : "r"(value), "r"(bytes) : "xer");

#define cntlzw(_val) ({register u32 _rval; \
__asm__ __volatile__("cntlzw %0, %1" : "=r"((_rval)) : "r"((_val))); _rval;})

Expand Down
26 changes: 12 additions & 14 deletions libogc/exi.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ s32 EXI_Sync(s32 nChn)
{
u8 *buf;
s32 ret;
u32 level,i,cnt,val;
u32 level,len,val;
exibus_priv *exi = &eximap[nChn];
#ifdef _EXI_DEBUG
printf("EXI_Sync(%d)\n",nChn);
Expand All @@ -447,11 +447,11 @@ s32 EXI_Sync(s32 nChn)
ret = 0;
if(exi->flags&EXI_FLAG_SELECT && exi->flags&(EXI_FLAG_DMA|EXI_FLAG_IMM)) {
if(exi->flags&EXI_FLAG_IMM) {
cnt = exi->imm_len;
buf = exi->imm_buff;
if(buf && cnt>0) {
len = exi->imm_len;
if(len>0) {
val = _exiReg[nChn*5+4];
for(i=0;i<cnt;i++) ((u8*)buf)[i] = (val>>((3-i)*8))&0xFF;
__stswx(buf,len,val);
}
}
exi->flags &= ~(EXI_FLAG_DMA|EXI_FLAG_IMM);
Expand All @@ -463,8 +463,8 @@ s32 EXI_Sync(s32 nChn)

s32 EXI_Imm(s32 nChn,void *pData,u32 nLen,u32 nMode,EXICallback tc_cb)
{
u32 val;
u32 level;
u32 value,i;
exibus_priv *exi = &eximap[nChn];
#ifdef _EXI_DEBUG
printf("EXI_Imm(%d,%p,%d,%d,%p)\n",nChn,pData,nLen,nMode,tc_cb);
Expand All @@ -486,8 +486,8 @@ s32 EXI_Imm(s32 nChn,void *pData,u32 nLen,u32 nMode,EXICallback tc_cb)
exi->imm_buff = pData;
exi->imm_len = nLen;
if(nMode!=EXI_READ) {
for(i=0,value=0;i<nLen;i++) value |= (((u8*)pData)[i])<<((3-i)*8);
_exiReg[nChn*5+4] = value;
val = __lswx(pData,nLen);
_exiReg[nChn*5+4] = val;
}
if(nMode==EXI_WRITE) exi->imm_len = 0;

Expand Down Expand Up @@ -934,7 +934,7 @@ void __exi_irq_handler(u32 nIrq,frame_context *pCtx)

void __tc_irq_handler(u32 nIrq,frame_context *pCtx)
{
u32 cnt,len,d,chan,dev;
u32 len,val,chan,dev;
EXICallback tccb;
void *buf = NULL;
exibus_priv *exi = NULL;
Expand All @@ -956,13 +956,11 @@ void __tc_irq_handler(u32 nIrq,frame_context *pCtx)
exi->CallbackTC = NULL;
if(exi->flags&(EXI_FLAG_DMA|EXI_FLAG_IMM)) {
if(exi->flags&EXI_FLAG_IMM) {
len = exi->imm_len;
buf = exi->imm_buff;
if(len>0 && buf) {
d = _exiReg[chan*5+4];
if(d>0) {
for(cnt=0;cnt<len;cnt++) ((u8*)buf)[cnt] = (d>>((3-cnt)*8))&0xFF;
}
len = exi->imm_len;
if(len>0) {
val = _exiReg[chan*5+4];
__stswx(buf,len,val);
}
}
exi->flags &= ~(EXI_FLAG_DMA|EXI_FLAG_IMM);
Expand Down
14 changes: 9 additions & 5 deletions libogc/si.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void __si_alarmhandler(syswd_t thealarm,void *cbarg)

static u32 __si_completetransfer(void)
{
u32 val,sisr,cnt,i;
u32 sisr,val,cnt,i;
u32 *in;

#ifdef _SI_DEBUG
Expand All @@ -183,7 +183,7 @@ static u32 __si_completetransfer(void)
for(i=0;i<cnt;i++) in[i] = _siReg[32+i];
if(sicntrl.in_bytes&0x03) {
val = _siReg[32+cnt];
for(i=0;i<(sicntrl.in_bytes&0x03);i++) ((u8*)in)[(cnt*4)+i] = (val>>((3-i)*8))&0xff;
__stswx(in+cnt,(sicntrl.in_bytes&0x03),val);
}
#ifdef _SI_DEBUG
printf("__si_completetransfer(csr = %08x)\n",_siReg[13]);
Expand All @@ -203,7 +203,7 @@ static u32 __si_completetransfer(void)

static u32 __si_transfer(s32 chan,void *out,u32 out_len,void *in,u32 in_len,SICallback cb)
{
u32 level,cnt,i;
u32 level,val,cnt,i;
sicomcsr csr;
#ifdef _SI_DEBUG
printf("__si_transfer(%d,%p,%d,%p,%d,%p)\n",chan,out,out_len,in,in_len,cb);
Expand All @@ -225,8 +225,12 @@ static u32 __si_transfer(s32 chan,void *out,u32 out_len,void *in,u32 in_len,SICa
#ifdef _SI_DEBUG
printf("__si_transfer(csr = %08x,sr = %08x)\n",_siReg[13],_siReg[14]);
#endif
cnt = ((out_len+3)/4);
for(i=0;i<cnt;i++) _siReg[32+i] = ((u32*)out)[i];
cnt = (out_len/4);
for(i=0;i<cnt;i++) _siReg[32+i] = ((u32*)out)[i];
if(out_len&0x03) {
val = __lswx((u32*)out+cnt,(out_len&0x03));
_siReg[32+cnt] = val;
}

csr.val = _siReg[13];
csr.csrmap.tcint = 1;
Expand Down

0 comments on commit bf67b31

Please sign in to comment.