Skip to content

Move shift & mask macros to gcutil.h #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion gc/gcutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
# define ATTRIBUTE_PACKED __attribute__((packed))
#endif

#endif /* _GCUTIL_H */
#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) //mask the first w bits of v before lshifting
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) //rshift v and mask the first w bits afterwards

#define _ROTL(v,s) \
(((u32)v<<s)|((u32)v>>(0x20-s)))

#endif /* _GCUTIL_H */
7 changes: 1 addition & 6 deletions libdb/geckousb.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

#include "geckousb.h"

#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))

static struct dbginterface usb_device;

static __inline__ int __send_command(s32 chn,u16 *cmd)
Expand Down Expand Up @@ -81,7 +76,7 @@ static int __usb_checkrecv(s32 chn)
static void __usb_flush(s32 chn)
{
char tmp;

if(!EXI_Lock(chn,EXI_DEVICE_0,NULL)) return;

while(__usb_recvbyte(chn,&tmp));
Expand Down
54 changes: 25 additions & 29 deletions libdb/uIP/bba.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gcutil.h"
#include "asm.h"
#include "processor.h"
#include "exi.h"
Expand All @@ -16,7 +17,7 @@
#define BBA_MINPKTSIZE 60

#define BBA_CID 0x04020200

#define BBA_CMD_IRMASKALL 0x00
#define BBA_CMD_IRMASKNONE 0xF8

Expand Down Expand Up @@ -187,11 +188,6 @@ struct bba_descr {
u32 X(X(next_packet_ptr:12, packet_len:12), status:8);
} __attribute((packed));

#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))

/* new functions */
#define bba_select() EXI_Select(EXI_CHANNEL_0,EXI_DEVICE_2,EXI_SPEED32MHZ)
#define bba_deselect() EXI_Deselect(EXI_CHANNEL_0)
Expand Down Expand Up @@ -344,7 +340,7 @@ static inline void bba_insregister(u32 reg)
static inline void bba_insdata(void *val,u32 len)
{
EXI_ImmEx(EXI_CHANNEL_0,val,len,EXI_READ);
}
}


static inline void bba_outsregister(u32 reg)
Expand Down Expand Up @@ -452,7 +448,7 @@ static s8_t bba_start_rx(struct uip_netif *dev,u32 budget)
struct uip_pbuf *p,*q;

UIP_LOG("bba_start_rx()\n");

recvd = 0;
rwp = bba_in12(BBA_RWP);
rrp = bba_in12(BBA_RRP);
Expand All @@ -473,10 +469,10 @@ static s8_t bba_start_rx(struct uip_netif *dev,u32 budget)
rrp = bba_in12(BBA_RRP);
continue;
}

pos = (rrp<<8)+4;
top = (BBA_INIT_RHBP+1)<<8;

p = uip_pbuf_alloc(UIP_PBUF_RAW,size,UIP_PBUF_POOL);
if(p) {
for(q=p;q!=NULL;q=q->next) {
Expand All @@ -486,7 +482,7 @@ static s8_t bba_start_rx(struct uip_netif *dev,u32 budget)
bba_insdata(q->payload,size);
} else {
s32 chunk = top-pos;

size -= chunk;
pos = BBA_INIT_RRP<<8;
bba_insdata(q->payload,chunk);
Expand All @@ -499,15 +495,15 @@ static s8_t bba_start_rx(struct uip_netif *dev,u32 budget)
bba_deselect();
pos += size;
}

EXI_Unlock(EXI_CHANNEL_0);
bba_process(p,dev);
EXI_Lock(EXI_CHANNEL_0,EXI_DEVICE_2,NULL);
} else
break;

recvd++;

bba_out12(BBA_RRP,(rrp=cur_descr.next_packet_ptr));
rwp = bba_in12(BBA_RWP);
}
Expand All @@ -517,7 +513,7 @@ static s8_t bba_start_rx(struct uip_netif *dev,u32 budget)
static inline void bba_interrupt(u16 *pstatus)
{
u8 ir,imr,status;

ir = bba_in8(BBA_IR);
imr = bba_in8(BBA_IMR);
status = ir&imr;
Expand Down Expand Up @@ -555,7 +551,7 @@ static s8_t bba_dochallengeresponse(void)
{
u16 status;
s32 cnt;

UIP_LOG("bba_dochallengeresponse()\n");
/* as we do not have interrupts we've to poll the irqs */
cnt = 0;
Expand All @@ -564,7 +560,7 @@ static s8_t bba_dochallengeresponse(void)
bba_devpoll(&status);
if(status==0x1000) cnt = 0;
} while(cnt<100 && !(status&0x0800));

if(cnt>=1000) return UIP_ERR_IF;
return UIP_ERR_OK;
}
Expand All @@ -577,7 +573,7 @@ static s8_t __bba_init(struct uip_netif *dev)
__bba_reset();

priv->revid = bba_cmd_in8(0x01);

bba_cmd_outs(0x04,&priv->devid,2);
bba_cmd_out8(0x05,priv->acstart);

Expand All @@ -586,7 +582,7 @@ static s8_t __bba_init(struct uip_netif *dev)
bba_out8(0x5c, (bba_in8(0x5c)|0x04));

__bba_recv_init();

bba_ins(BBA_NAFR_PAR0,priv->ethaddr->addr, 6);

bba_out8(BBA_IR,0xFF);
Expand All @@ -607,9 +603,9 @@ static s8_t bba_init_one(struct uip_netif *dev)
priv->revid = 0x00;
priv->devid = 0xD107;
priv->acstart = 0x4E;

ret = __bba_init(dev);

return ret;
}

Expand Down Expand Up @@ -668,7 +664,7 @@ static void bba_devpoll(u16 *pstatus)
s64 now;

UIP_LOG("bba_devpoll()\n");

now = gettime();
if(diff_msec(bba_arp_tmr,now)>=UIP_ARP_TMRINTERVAL) {
uip_arp_timer();
Expand Down Expand Up @@ -743,15 +739,15 @@ static s8_t __bba_link_tx(struct uip_netif *dev,struct uip_pbuf *p)
u8 pad[60];
u32 len;
struct uip_pbuf *tmp;

if(EXI_Lock(EXI_CHANNEL_0,EXI_DEVICE_2,NULL)==0) return UIP_ERR_IF;

if(p->tot_len>BBA_TX_MAX_PACKET_SIZE) {
UIP_LOG("__bba_link_tx: packet dropped due to big buffer.\n");
EXI_Unlock(EXI_CHANNEL_0);
return UIP_ERR_PKTSIZE;
}

if(!__linkstate()) {
EXI_Unlock(EXI_CHANNEL_0);
return UIP_ERR_ABRT;
Expand Down Expand Up @@ -796,27 +792,27 @@ s8_t uip_bba_init(struct uip_netif *dev)
} while((ret=__bba_getlink_state_async())==0 && cnt<10000);
if(!ret) return UIP_ERR_IF;

dev->flags |= UIP_NETIF_FLAG_LINK_UP;
dev->flags |= UIP_NETIF_FLAG_LINK_UP;
uip_netif_setup(dev);
uip_arp_init();

bba_recv_pbufs = NULL;
bba_arp_tmr = gettime();

return UIP_ERR_OK;
}

uipdev_s uip_bba_create(struct uip_netif *dev)
{
dev->name[0] = IFNAME0;
dev->name[1] = IFNAME1;

dev->output = __bba_start_tx;
dev->linkoutput = __bba_link_tx;
dev->mtu = 1500;
dev->flags = UIP_NETIF_FLAG_BROADCAST;
dev->hwaddr_len = 6;

bba_device.ethaddr = (struct uip_eth_addr*)dev->hwaddr;
bba_device.state = UIP_ERR_OK;

Expand All @@ -829,7 +825,7 @@ void uip_bba_poll(struct uip_netif *dev)
u16 status;

UIP_LOG("uip_bba_poll()\n");

bba_devpoll(&status);

}
6 changes: 1 addition & 5 deletions libogc/aram.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ distribution.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "gcutil.h"
#include "asm.h"
#include "processor.h"
#include "aram.h"
Expand All @@ -54,11 +55,6 @@ distribution.

#define AR_ARAMEXPANSION 2

#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))

static vu16* const _dspReg = (u16*)0xCC005000;

static ARCallback __ARDmaCallback = NULL;
Expand Down
6 changes: 1 addition & 5 deletions libogc/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ distribution.


#include <stdlib.h>
#include "gcutil.h"
#include "asm.h"
#include "processor.h"
#include "irq.h"
Expand Down Expand Up @@ -65,11 +66,6 @@ distribution.
#define AI_SCRESET 0x20
#define AI_DMAFR 0x40

#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))

#if defined(HW_DOL)
static vu32* const _aiReg = (u32*)0xCC006C00;
#elif defined(HW_RVL)
Expand Down
10 changes: 3 additions & 7 deletions libogc/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ distribution.
-------------------------------------------------------------*/


#include <asm.h>
#include <processor.h>
#include "gcutil.h"
#include "asm.h"
#include "processor.h"
#include "cache.h"

#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))

extern void __LCEnable(void);
extern void L2GlobalInvalidate(void);
extern void L2Enable(void);
Expand Down
Loading