Skip to content

Commit 7b2fac7

Browse files
committed
Merge branch 'master' of github.com:devkitPro/libogc into ascii-keyboard-controller
2 parents ef7e344 + df5c999 commit 7b2fac7

9 files changed

Lines changed: 65 additions & 43 deletions

File tree

gc/ogc/lwp_watchdog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#define ticks_to_microsecs(ticks) PPCTicksToUs(ticks)
1616
#define ticks_to_nanosecs(ticks) PPCTicksToNs(ticks)
1717

18-
#define tick_microsecs(ticks) (PPCTicksToUs(ticks)%TB_USPERSEC)
19-
#define tick_nanosecs(ticks) (PPCTicksToNs(ticks)%TB_NSPERSEC)
18+
#define tick_microsecs(ticks) PPCTicksToUs((ticks)%PPC_TIMER_CLOCK)
19+
#define tick_nanosecs(ticks) PPCTicksToNs((ticks)%PPC_TIMER_CLOCK)
2020

2121
#define secs_to_ticks(sec) ((u64)(sec)*PPC_TIMER_CLOCK)
2222
#define millisecs_to_ticks(msec) PPCMsToTicks(msec)

gc/tuxedo/ppc/intrinsics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ MK_INLINE u32 PPCMfmsr(void)
6161
return ret;
6262
}
6363

64-
MK_INLINE void PPCMtspr(unsigned spr, u32 value)
64+
MK_INLINE void PPCMtspr(const unsigned spr, u32 value)
6565
{
6666
__asm__ __volatile__("mtspr %0, %1" :: "I"(spr), "r"(value) : "memory");
6767
}
6868

69-
MK_INLINE u32 PPCMfspr(unsigned spr)
69+
MK_INLINE u32 PPCMfspr(const unsigned spr)
7070
{
7171
u32 ret;
7272
__asm__ __volatile__("mfspr %0, %1" : "=r"(ret) : "I"(spr));

libogc/gx.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ static void __GXOverflowHandler(void)
389389
_gxoverflowsuspend = 1;
390390
_gxoverflowcount++;
391391
__GX_WriteFifoIntEnable(GX_DISABLE,GX_ENABLE);
392-
__GX_WriteFifoIntReset(GX_TRUE,GX_FALSE);
393392
LWP_SuspendThread(_gxcurrentlwp);
394393
}
395394
}
@@ -399,22 +398,26 @@ static void __GXUnderflowHandler(void)
399398
if(_gxoverflowsuspend) {
400399
_gxoverflowsuspend = 0;
401400
LWP_ResumeThread(_gxcurrentlwp);
402-
__GX_WriteFifoIntReset(GX_TRUE,GX_TRUE);
403401
__GX_WriteFifoIntEnable(GX_ENABLE,GX_DISABLE);
404402
}
405403
}
406404

407405
static void __GXCPInterruptHandler(u32 irq,void *ctx)
408406
{
407+
// Clear spurious pending underflow/overflow IRQs before reading the status register.
408+
// Note that legitimate IRQs are sticky & can't be cleared until the CPU produces or
409+
// the GPU retires commands, respectively.
410+
__GX_WriteFifoIntReset(GX_TRUE, GX_TRUE);
409411
__gx->cpSRreg = _cpReg[0];
410412

411-
if((__gx->cpCRreg&0x08) && (__gx->cpSRreg&0x02))
413+
// Check for underflow/overflow (only one can be active at a time)
414+
if (__gx->cpSRreg & 0x02)
412415
__GXUnderflowHandler();
413-
414-
if((__gx->cpCRreg&0x04) && (__gx->cpSRreg&0x01))
416+
else if (__gx->cpSRreg & 0x01)
415417
__GXOverflowHandler();
416418

417-
if((__gx->cpCRreg&0x20) && (__gx->cpSRreg&0x10)) {
419+
// Check for breakpoint
420+
if ((__gx->cpSRreg & 0x10) && (__gx->cpCRreg & 0x20)) {
418421
__gx->cpCRreg &= ~0x20;
419422
_cpReg[1] = __gx->cpCRreg;
420423
if(breakPtCB)

libogc/kprintf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ static void _dietPrintDefaultFunc(const char* buf, size_t size)
88
{
99
if(buf)
1010
{
11-
write(STDOUT_FILENO, buf, size);
11+
write(STDERR_FILENO, buf, size);
1212
}
1313
else
1414
{
1515
for (size_t i= 0; i < size; i ++)
1616
{
1717
char space = ' ';
18-
write(STDOUT_FILENO,&space,1);
18+
write(STDERR_FILENO,&space,1);
1919
}
2020
}
2121
}
@@ -434,4 +434,4 @@ void kprintf(const char* fmt, ...)
434434
va_start(va, fmt);
435435
dietPrintV(fmt, va);
436436
va_end(va);
437-
}
437+
}

libogc/lwpcompat/lwpc_sem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ s32 LWP_SemPost(sem_t sem)
7070
}
7171

7272
PPCIrqUnlockByMsr(st);
73-
return -1;
73+
return 0;
7474
}

libwiikeyboard/wskbdutil.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ keysym_t ksym_upcase(keysym_t);
183183
void fillmapentry(const keysym_t *, int, struct wscons_keymap *);
184184

185185
inline int
186-
compose_tab_cmp(i, j)
187-
struct compose_tab_s *i, *j;
186+
compose_tab_cmp(struct compose_tab_s *i, struct compose_tab_s *j)
188187
{
189188
if (i->elem[0] == j->elem[0])
190189
return(i->elem[1] - j->elem[1]);
@@ -193,8 +192,7 @@ compose_tab_cmp(i, j)
193192
}
194193

195194
keysym_t
196-
wskbd_compose_value(compose_buf)
197-
keysym_t *compose_buf;
195+
wskbd_compose_value(keysym_t *compose_buf)
198196
{
199197
int i, j, r;
200198
struct compose_tab_s v;
@@ -264,8 +262,7 @@ static const u_char latin1_to_upper[256] = {
264262
};
265263

266264
keysym_t
267-
ksym_upcase(ksym)
268-
keysym_t ksym;
265+
ksym_upcase(keysym_t ksym)
269266
{
270267
if (ksym >= KS_f1 && ksym <= KS_f20)
271268
return(KS_F1 - KS_f1 + ksym);
@@ -278,10 +275,8 @@ ksym_upcase(ksym)
278275
}
279276

280277
void
281-
fillmapentry(kp, len, mapentry)
282-
const keysym_t *kp;
283-
int len;
284-
struct wscons_keymap *mapentry;
278+
fillmapentry(const keysym_t *kp, int len,
279+
struct wscons_keymap *mapentry)
285280
{
286281
switch (len) {
287282
case 0:
@@ -323,10 +318,9 @@ fillmapentry(kp, len, mapentry)
323318
}
324319

325320
void
326-
wskbd_get_mapentry(mapdata, kc, mapentry)
327-
const struct wskbd_mapdata *mapdata;
328-
int kc;
329-
struct wscons_keymap *mapentry;
321+
wskbd_get_mapentry(
322+
const struct wskbd_mapdata *mapdata,
323+
int kc, struct wscons_keymap *mapentry)
330324
{
331325
kbd_t cur;
332326
const keysym_t *kp;
@@ -383,10 +377,10 @@ wskbd_get_mapentry(mapdata, kc, mapentry)
383377
}
384378

385379
void
386-
wskbd_init_keymap(newlen, map, maplen)
387-
int newlen;
388-
struct wscons_keymap **map;
389-
int *maplen;
380+
wskbd_init_keymap(
381+
int newlen,
382+
struct wscons_keymap **map,
383+
int *maplen)
390384
{
391385
int i;
392386

@@ -407,10 +401,10 @@ wskbd_init_keymap(newlen, map, maplen)
407401
}
408402

409403
int
410-
wskbd_load_keymap(mapdata, map, maplen)
411-
const struct wskbd_mapdata *mapdata;
412-
struct wscons_keymap **map;
413-
int *maplen;
404+
wskbd_load_keymap(
405+
const struct wskbd_mapdata *mapdata,
406+
struct wscons_keymap **map,
407+
int *maplen)
414408
{
415409
int i, s, kc, stack_ptr;
416410
const keysym_t *kp;

tuxedo/early_init.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ FUNC_START PPCEarlyInitImpl, text, local
5151
#endif
5252

5353
// Start invalidating the L2 cache
54-
lis r3, L2CR_L2CE>>16
54+
lis r3, L2CR_L2I>>16
5555
mtspr L2CR, r3
5656

5757
// Clear all BATs

tuxedo/newlib_syscalls.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ void __SYSCALL(lock_acquire)(_LOCK_T* lock)
1919
KMutexLock((KMutex*)lock);
2020
}
2121

22+
int __SYSCALL(lock_try_acquire)(_LOCK_T* lock)
23+
{
24+
return KMutexTryLock((KMutex*)lock) ? 0 : 1;
25+
}
26+
2227
void __SYSCALL(lock_release)(_LOCK_T* lock)
2328
{
2429
KMutexUnlock((KMutex*)lock);
@@ -29,6 +34,11 @@ void __SYSCALL(lock_acquire_recursive)(_LOCK_RECURSIVE_T* lock)
2934
KRMutexLock((KRMutex*)lock);
3035
}
3136

37+
int __SYSCALL(lock_try_acquire_recursive)(_LOCK_RECURSIVE_T* lock)
38+
{
39+
return KRMutexTryLock((KRMutex*)lock) ? 0 : 1;
40+
}
41+
3242
void __SYSCALL(lock_release_recursive)(_LOCK_RECURSIVE_T* lock)
3343
{
3444
KRMutexUnlock((KRMutex*)lock);

tuxedo/thread.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,24 @@ MK_NOINLINE void KThreadSwitchTo(KThread* t, PPCIrqState st)
9898

9999
void KThreadResume(KThread* t)
100100
{
101+
KThread* self = KThreadGetSelf();
101102
PPCIrqState st = PPCIrqLockByMsr();
102103

103-
if (!t->suspend || (--t->suspend)) {
104+
if (!t->suspend || (--t->suspend) || t->wait.queue) {
104105
PPCIrqUnlockByMsr(st);
105106
return;
106107
}
107108

108-
if (!t->wait.queue) {
109-
t->state = KTHR_STATE_RUNNING;
109+
t->state = KTHR_STATE_RUNNING;
110+
111+
if (t != self) {
110112
KThreadReschedule(t, st);
111113
} else {
114+
// We are assuming 1) PPCIsInExcpt, 2) KThreadSuspend(self) was called before, and thus 3) __ppc_next_ctx != NULL
115+
if (t->prio < __ppc_next_ctx->prio) {
116+
__ppc_next_ctx = NULL;
117+
}
118+
112119
PPCIrqUnlockByMsr(st);
113120
}
114121
}
@@ -126,10 +133,18 @@ void KThreadSuspend(KThread* t)
126133
t->state = KTHR_STATE_WAITING;
127134
t->wait.queue = NULL;
128135

129-
if (self == t) {
130-
KThread* next = KThreadFindRunnable(s_firstThread);
136+
KThread* next = NULL;
137+
if (t == self || t == __ppc_next_ctx) {
138+
next = KThreadFindRunnable(s_firstThread);
139+
}
140+
141+
if (t == self) {
131142
KThreadSwitchTo(next, st);
132143
} else {
144+
if (t == __ppc_next_ctx) {
145+
__ppc_next_ctx = next != self ? next : NULL;
146+
}
147+
133148
PPCIrqUnlockByMsr(st);
134149
}
135150
}
@@ -174,7 +189,7 @@ void KThreadYield(void)
174189
PPCIrqState st = PPCIrqLockByMsr();
175190

176191
KThread* t = KThreadFindRunnable(self->next);
177-
if (t->prio > self->prio) {
192+
if (!t || t->prio > self->prio) {
178193
t = KThreadFindRunnable(s_firstThread);
179194
}
180195

0 commit comments

Comments
 (0)