28#define ExitHandler() asm volatile("sync\nei\n")
31#define EE_SYNC() __asm__ volatile("sync")
32#define EE_SYNCL() __asm__ volatile("sync.l")
33#define EE_SYNCP() __asm__ volatile("sync.p")
35#define UNCACHED_SEG(x) \
36 ((void *)(((u32)(x)) | 0x20000000))
38#define IS_UNCACHED_SEG(x) \
39 (((u32)(x)) & 0x20000000)
42 ((void *)(((u32)(x)) | 0x30000000))
44#define PUSHDATA(t, x, v, l) \
48#define POPDATA(t, x, v, l) \
52#define ALIGNED(x) __attribute__((aligned((x))))
55void *ChangeGP(
void *gp);
60#define SetModuleGP() ChangeGP(&_gp)
70#define MAX_THREADS 256
71#define MAX_SEMAPHORES 256
72#define MAX_PRIORITY 128
73#define MAX_HANDLERS 128
77#define WRITEBACK_DCACHE 0
78#define INVALIDATE_DCACHE 1
79#define INVALIDATE_ICACHE 2
80#define INVALIDATE_CACHE 3
102#define kINTC_GS INTC_GS
103#define kINTC_SBUS INTC_SBUS
104#define kINTC_VBLANK_START INTC_VBLANK_S
105#define kINTC_VBLANK_END INTC_VBLANK_E
106#define kINTC_VIF0 INTC_VIF0
107#define kINTC_VIF1 INTC_VIF1
108#define kINTC_VU0 INTC_VU0
109#define kINTC_VU1 INTC_VU1
110#define kINTC_IPU INTC_IPU
111#define kINTC_TIMER0 INTC_TIM0
112#define kINTC_TIMER1 INTC_TIM1
133#define INIT_DMAC 0x01
135#define INIT_VIF1 0x04
138#define INIT_VIF0 0x20
141static inline void nopdelay(
void)
146 __asm__(
"nop\nnop\nnop\nnop\nnop\n");
150static inline int ee_get_opmode(
void)
156 ".set\tnoreorder\n\t"
161 return ((status >> 3) & 3);
164static inline int ee_set_opmode(u32 opmode)
170 ".set\tnoreorder\n\t"
172 "li\t%1, 0xffffffe7\n\t"
178 :
"=r"(status),
"=r"(mask)
181 return ((status >> 3) & 3);
184static inline int ee_kmode_enter()
190 ".set\tnoreorder\n\t"
192 "li\t%1, 0xffffffe7\n\t"
197 :
"=r"(status),
"=r"(mask));
202static inline int ee_kmode_exit()
208 ".set\tnoreorder\n\t"
236 int initial_priority;
237 int current_priority;
245#define THS_READY 0x02
247#define THS_SUSPEND 0x08
248#define THS_WAITSUSPEND 0x0c
249#define THS_DORMANT 0x10
264 int initial_priority;
265 int current_priority;
275 CPU_CONFIG_ENABLE_DIE = 0,
276 CPU_CONFIG_ENABLE_ICE,
277 CPU_CONFIG_ENABLE_DCE,
278 CPU_CONFIG_DISBLE_DIE,
279 CPU_CONFIG_DISBLE_ICE,
280 CPU_CONFIG_DISBLE_DCE
284#define CPU_DATA_CACHE 1
285#define CPU_INSTRUCTION_CACHE 2
323void TerminateLibrary(
void);
328s32 iWakeupThread(s32 thread_id);
329s32 iRotateThreadReadyQueue(s32 priority);
330s32 iSuspendThread(s32 thread_id);
333void InitTLBFunctions(
void);
337s32 ExecPS2(
void *entry,
void *gp,
int num_args,
char *args[]);
338void LoadExecPS2(
const char *filename, s32 num_args,
char *args[])
__attribute__((noreturn));
339void ExecOSD(
int num_args,
char *args[])
__attribute__((noreturn));
345void InitExecPS2(
void);
348int PatchIsNeeded(
void);
357int EnableIntc(
int intc);
358int DisableIntc(
int intc);
359int EnableDmac(
int dmac);
360int DisableDmac(
int dmac);
362int iEnableIntc(
int intc);
363int iDisableIntc(
int intc);
364int iEnableDmac(
int dmac);
365int iDisableDmac(
int dmac);
367void SyncDCache(
void *start,
void *end);
368void iSyncDCache(
void *start,
void *end);
369void InvalidDCache(
void *start,
void *end);
370void iInvalidDCache(
void *start,
void *end);
373void ResetEE(u32 init_bitfield);
374void SetGsCrt(s16 interlace, s16 pal_ntsc, s16 field);
376void _LoadExecPS2(
const char *filename, s32 num_args,
char *args[])
__attribute__((noreturn));
377s32 _ExecPS2(
void *entry,
void *gp,
int num_args,
char *args[]);
378void RFU009(u32 arg0, u32 arg1);
379s32 AddSbusIntcHandler(s32 cause,
void (*handler)(
int call));
380s32 RemoveSbusIntcHandler(s32 cause);
381s32 Interrupt2Iop(s32 cause);
382void SetVTLBRefillHandler(s32 handler_num,
void *handler_func);
383void SetVCommonHandler(s32 handler_num,
void *handler_func);
384void SetVInterruptHandler(s32 handler_num,
void *handler_func);
385s32 AddIntcHandler(s32 cause, s32 (*handler_func)(s32 cause), s32 next);
386s32 AddIntcHandler2(s32 cause, s32 (*handler_func)(s32 cause,
void *arg,
void *addr), s32 next,
void *arg);
387s32 RemoveIntcHandler(s32 cause, s32 handler_id);
388s32 AddDmacHandler(s32 channel, s32 (*handler)(s32 channel), s32 next);
389s32 AddDmacHandler2(s32 channel, s32 (*handler)(s32 channel,
void *arg,
void *addr), s32 next,
void *arg);
390s32 RemoveDmacHandler(s32 channel, s32 handler_id);
391s32 _EnableIntc(s32 cause);
392s32 _DisableIntc(s32 cause);
393s32 _EnableDmac(s32 channel);
394s32 _DisableDmac(s32 channel);
397s32 SetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
398s32 _SetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
399s32 ReleaseAlarm(s32 alarm_id);
400s32 _ReleaseAlarm(s32 alarm_id);
402s32 _iEnableIntc(s32 cause);
403s32 _iDisableIntc(s32 cause);
404s32 _iEnableDmac(s32 channel);
405s32 _iDisableDmac(s32 channel);
407s32 iSetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
408s32 _iSetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
409s32 iReleaseAlarm(s32 alarm_id);
410s32 _iReleaseAlarm(s32 alarm_id);
413s32 DeleteThread(s32 thread_id);
414s32 StartThread(s32 thread_id,
void *args);
415void ExitThread(
void);
416void ExitDeleteThread(
void);
417s32 TerminateThread(s32 thread_id);
418s32 iTerminateThread(s32 thread_id);
421s32 ChangeThreadPriority(s32 thread_id, s32 priority);
422s32 iChangeThreadPriority(s32 thread_id, s32 priority);
423s32 RotateThreadReadyQueue(s32 priority);
424s32 _iRotateThreadReadyQueue(s32 priority);
425s32 ReleaseWaitThread(s32 thread_id);
426s32 iReleaseWaitThread(s32 thread_id);
427s32 GetThreadId(
void);
428s32 _iGetThreadId(
void);
431s32 SleepThread(
void);
432s32 WakeupThread(s32 thread_id);
433s32 _iWakeupThread(s32 thread_id);
434s32 CancelWakeupThread(s32 thread_id);
435s32 iCancelWakeupThread(s32 thread_id);
436s32 SuspendThread(s32 thread_id);
437s32 _iSuspendThread(s32 thread_id);
438s32 ResumeThread(s32 thread_id);
439s32 iResumeThread(s32 thread_id);
443void *SetupThread(
void *gp,
void *stack, s32 stack_size,
void *args,
void *root_func);
444void SetupHeap(
void *heap_start, s32 heap_size);
445void *EndOfHeap(
void);
448s32 DeleteSema(s32 sema_id);
449s32 SignalSema(s32 sema_id);
450s32 iSignalSema(s32 sema_id);
451s32 WaitSema(s32 sema_id);
452s32 PollSema(s32 sema_id);
453s32 iPollSema(s32 sema_id);
454s32 ReferSemaStatus(s32 sema_id,
ee_sema_t *sema);
455s32 iReferSemaStatus(s32 sema_id,
ee_sema_t *sema);
456s32 iDeleteSema(s32 sema_id);
457void SetOsdConfigParam(
void *addr);
458void GetOsdConfigParam(
void *addr);
459void GetGsHParam(
void *addr1,
void *addr2,
void *addr3);
460s32 GetGsVParam(
void);
461void SetGsHParam(
void *addr1,
void *addr2,
void *addr3,
void *addr4);
462void SetGsVParam(s32 arg1);
465int PutTLBEntry(
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
466int iPutTLBEntry(
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
467int _SetTLBEntry(
unsigned int index,
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
468int iSetTLBEntry(
unsigned int index,
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
469int GetTLBEntry(
unsigned int index,
unsigned int *PageMask,
unsigned int *EntryHi,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
470int iGetTLBEntry(
unsigned int index,
unsigned int *PageMask,
unsigned int *EntryHi,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
471int ProbeTLBEntry(
unsigned int EntryHi,
unsigned int *PageMask,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
472int iProbeTLBEntry(
unsigned int EntryHi,
unsigned int *PageMask,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
473int ExpandScratchPad(
unsigned int page);
475void EnableIntcHandler(u32 cause);
476void iEnableIntcHandler(u32 cause);
477void DisableIntcHandler(u32 cause);
478void iDisableIntcHandler(u32 cause);
479void EnableDmacHandler(u32 channel);
480void iEnableDmacHandler(u32 channel);
481void DisableDmacHandler(u32 channel);
482void iDisableDmacHandler(u32 channel);
484s32 EnableCache(s32 cache);
485s32 DisableCache(s32 cache);
486u32 GetCop0(s32 reg_id);
487void FlushCache(s32 operation);
488u32 CpuConfig(u32 config);
489u32 iGetCop0(s32 reg_id);
490void iFlushCache(s32 operation);
491u32 iCpuConfig(u32 config);
492void SetCPUTimerHandler(
void (*handler)(
void));
493void SetCPUTimer(s32 compval);
496void SetOsdConfigParam2(
void *config, s32 size, s32 offset);
497void GetOsdConfigParam2(
void *config, s32 size, s32 offset);
501u64 GsPutIMR(u64 imr);
502u64 iGsPutIMR(u64 imr);
503void SetPgifHandler(
void *handler);
504void SetVSyncFlag(u32 *, u64 *);
505void SetSyscall(s32 syscall_num,
void *handler);
506void _print(
const char *fmt, ...);
508void SifStopDma(
void);
510s32 SifDmaStat(u32
id);
511s32 iSifDmaStat(u32
id);
516void SifSetDChain(
void);
517void iSifSetDChain(
void);
520int SifSetReg(u32 register_num,
int register_value);
521int SifGetReg(u32 register_num);
523void _ExecOSD(
int num_args,
char *args[])
__attribute__((noreturn));
524s32 Deci2Call(s32, u32 *);
526s32 MachineType(
void);
527s32 GetMemorySize(
void);
530void _GetGsDxDyOffset(
int mode,
int *dx,
int *dy,
int *dw,
int *dh);
536int SetMemoryMode(
int mode);
538void _SyncDCache(
void *start,
void *end);
539void _InvalidDCache(
void *start,
void *end);
541void *GetSyscallHandler(
int syscall_no);
542void *GetExceptionHandler(
int except_no);
543void *GetInterruptHandler(
int intr_no);
546int kCopy(
void *dest,
const void *src,
int size);
547int kCopyBytes(
void *dest,
const void *src,
int size);
548int Copy(
void *dest,
const void *src,
int size);
549void setup(
int syscall_num,
void *handler);
550void *GetEntryAddress(
int syscall);
554#define DISABLE_PATCHED_Exit() \
555 void Exit(s32 exit_code) { KExit(exit_code); }
557#define DISABLE_PATCHED_LoadExecPS2() \
558 void LoadExecPS2(const char *filename, s32 num_args, char *args[]) { _LoadExecPS2(filename, num_args, args); }
560#define NO_PATCHED_ExecOSD() \
561 void ExecOSD(int num_args, char *args[]) { _ExecOSD(num_args, args); }
563#define DISABLE_TimerSystemTime() \
564 s32 InitTimer(s32 in_mode) {(void)in_mode; return 0;} \
565 s32 EndTimer(void) {return 0;} \
566 s32 StartTimerSystemTime(void) {return 0;} \
567 s32 StopTimerSystemTime(void) {return 0;}
569#define DISABLE_TimerAlarm() \
570 void ForTimer_InitAlarm(void) {}
572#define DISABLE_PATCHED_ALARMS() \
573 void InitAlarm(void) {}
575#define DISABLE_PATCHED_THREADS() \
576 int InitThread(void) { return 0; } \
577 s32 iRotateThreadReadyQueue(s32 priority) { return _iRotateThreadReadyQueue(priority); } \
578 s32 iWakeupThread(s32 thread_id) { return _iWakeupThread(thread_id); } \
579 s32 iSuspendThread(s32 thread_id) { return _iSuspendThread(thread_id); }
581#define DISABLE_PATCHED_ExecPS2() \
582 void InitExecPS2(void) {} \
583 s32 ExecPS2(void *entry, void *gp, int num_args, char *args[]) { return _ExecPS2(entry, gp, num_args, args); }
585#define DISABLE_PATCHED_TLBFunctions() \
586 void InitTLBFunctions(void) {} \
587 void InitTLB(void) {}
589#define DISABLE_PATCHED_FUNCTIONS() \
590 DISABLE_PATCHED_ALARMS() \
591 DISABLE_PATCHED_THREADS() \
592 DISABLE_PATCHED_ExecPS2() \
593 DISABLE_PATCHED_TLBFunctions() \
594 DISABLE_PATCHED_Exit() \
595 DISABLE_PATCHED_LoadExecPS2()
597#define DISABLE_EXTRA_TIMERS_FUNCTIONS() \
598 DISABLE_TimerSystemTime() \